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.
8 // interface ChromotingScriptableObject {
10 // // Dimension of the desktop area.
11 // readonly attribute int desktopWidth;
12 // readonly attribute int desktopHeight;
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
45 // // User of this object should respond with calling submitLoginInfo() when
46 // // username and password is available.
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);
57 // // Method for submitting login information.
58 // void submitLoginInfo(string username, string password);
61 #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_
62 #define REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_
68 #include "ppapi/cpp/dev/scriptable_object_deprecated.h"
69 #include "ppapi/cpp/var.h"
73 class ChromotingInstance
;
75 extern const char kStatusAttribute
[];
77 enum ConnectionStatus
{
86 extern const char kQualityAttribute
[];
88 enum ConnectionQuality
{
94 class ChromotingScriptableObject
: public pp::deprecated::ScriptableObject
{
96 explicit ChromotingScriptableObject(ChromotingInstance
* instance
);
97 virtual ~ChromotingScriptableObject();
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
,
107 virtual void SetProperty(const pp::Var
& name
,
108 const pp::Var
& value
,
110 virtual pp::Var
Call(const pp::Var
& method_name
,
111 const std::vector
<pp::Var
>& args
,
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();
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
) {
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
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_