Add debug logging to Chromoting client UI.
[chromium-blink-merge.git] / remoting / client / plugin / chromoting_scriptable_object.h
blobe5c57b5eb648e54788a9b6454777a1164d364ee3
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This implements the JavaScript class entrypoint for the plugin instance.
6 // The Javascript API is defined as follows.
7 //
8 // interface ChromotingScriptableObject {
9 //
10 // // Dimension of the desktop area.
11 // readonly attribute int desktopWidth;
12 // readonly attribute int desktopHeight;
14 // // Debug info.
15 // readonly attribute string debugInfo;
17 // // Connection status.
18 // readonly attribute unsigned short status;
19 // // Constants for connection status.
20 // const unsigned short STATUS_UNKNOWN = 0;
21 // const unsigned short STATUS_CONNECTING = 1;
22 // const unsigned short STATUS_INITIALIZING = 2;
23 // const unsigned short STATUS_CONNECTED = 3;
24 // const unsigned short STATUS_CLOSED = 4;
25 // const unsigned short STATUS_FAILED = 5;
27 // // Connection quality.
28 // readonly attribute unsigned short quality;
29 // // Constants for connection quality
30 // const unsigned short QUALITY_UNKNOWN = 0;
31 // const unsigned short QUALITY_GOOD = 1;
32 // const unsigned short QUALITY_BAD = 2;
34 // // JS callback function so we can signal the JS UI when the connection
35 // // status has been updated.
36 // attribute Function connectionInfoUpdate;
38 // // JS callback function to call when there is new debug info to display
39 // // in the client UI.
40 // attribute Function debugInfoUpdate;
42 // // This function is called when login information for the host machine is
43 // // needed.
44 // //
45 // // User of this object should respond with calling submitLoginInfo() when
46 // // username and password is available.
47 // //
48 // // This function will be called multiple times until login was successful
49 // // or the maximum number of login attempts has been reached. In the
50 // // later case |connection_status| is changed to STATUS_FAILED.
51 // attribute Function loginChallenge;
53 // // Methods on the object.
54 // void connect(string username, string host_jid, string auth_token);
55 // void disconnect();
57 // // Method for submitting login information.
58 // void submitLoginInfo(string username, string password);
59 // }
61 #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_
62 #define REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_
64 #include <map>
65 #include <string>
66 #include <vector>
68 #include "ppapi/cpp/dev/scriptable_object_deprecated.h"
69 #include "ppapi/cpp/var.h"
71 namespace remoting {
73 class ChromotingInstance;
75 extern const char kStatusAttribute[];
77 enum ConnectionStatus {
78 STATUS_UNKNOWN = 0,
79 STATUS_CONNECTING,
80 STATUS_INITIALIZING,
81 STATUS_CONNECTED,
82 STATUS_CLOSED,
83 STATUS_FAILED,
86 extern const char kQualityAttribute[];
88 enum ConnectionQuality {
89 QUALITY_UNKNOWN = 0,
90 QUALITY_GOOD,
91 QUALITY_BAD,
94 class ChromotingScriptableObject : public pp::deprecated::ScriptableObject {
95 public:
96 explicit ChromotingScriptableObject(ChromotingInstance* instance);
97 virtual ~ChromotingScriptableObject();
99 virtual void Init();
101 // Override the ScriptableObject functions.
102 virtual bool HasProperty(const pp::Var& name, pp::Var* exception);
103 virtual bool HasMethod(const pp::Var& name, pp::Var* exception);
104 virtual pp::Var GetProperty(const pp::Var& name, pp::Var* exception);
105 virtual void GetAllPropertyNames(std::vector<pp::Var>* properties,
106 pp::Var* exception);
107 virtual void SetProperty(const pp::Var& name,
108 const pp::Var& value,
109 pp::Var* exception);
110 virtual pp::Var Call(const pp::Var& method_name,
111 const std::vector<pp::Var>& args,
112 pp::Var* exception);
114 void SetConnectionInfo(ConnectionStatus status, ConnectionQuality quality);
115 void LogDebugInfo(const std::string& info);
116 void SetDesktopSize(int width, int height);
118 // This should be called to signal JS code to provide login information.
119 void SignalLoginChallenge();
121 private:
122 typedef std::map<std::string, int> PropertyNameMap;
123 typedef pp::Var (ChromotingScriptableObject::*MethodHandler)(
124 const std::vector<pp::Var>& args, pp::Var* exception);
125 struct PropertyDescriptor {
126 explicit PropertyDescriptor(const std::string& n, pp::Var a)
127 : name(n), attribute(a), method(NULL) {
130 explicit PropertyDescriptor(const std::string& n, MethodHandler m)
131 : name(n), method(m) {
134 enum Type {
135 ATTRIBUTE,
136 METHOD,
137 } type;
139 std::string name;
140 pp::Var attribute;
141 MethodHandler method;
145 // Routines to add new attribute, method properties.
146 void AddAttribute(const std::string& name, pp::Var attribute);
147 void AddMethod(const std::string& name, MethodHandler handler);
149 // This should be called to signal the JS code that the connection status has
150 // changed.
151 void SignalConnectionInfoChange();
153 // Call this to signal that there is new debug info to display.
154 void SignalDebugInfoChange();
156 pp::Var DoConnect(const std::vector<pp::Var>& args, pp::Var* exception);
157 pp::Var DoDisconnect(const std::vector<pp::Var>& args, pp::Var* exception);
159 // This method is called by JS to provide login information.
160 pp::Var DoSubmitLogin(const std::vector<pp::Var>& args, pp::Var* exception);
162 PropertyNameMap property_names_;
163 std::vector<PropertyDescriptor> properties_;
165 ChromotingInstance* instance_;
168 } // namespace remoting
170 #endif // REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_