OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 // This implements the JavaScript class entrypoint for the plugin. |
| 6 // The Javascript API is defined as follows. |
| 7 // |
| 8 // interface ChromotingScriptableObject { |
| 9 // // Called when the Chromoting plugin has had a state change such as |
| 10 // // connection completed. |
| 11 // attribute Function onreadystatechange; |
| 12 // |
| 13 // // Constants for states, etc. |
| 14 // const unsigned short NOT_CONNECTED = 0; |
| 15 // const unsigned short CONNECTED = 1; |
| 16 // |
| 17 // // Methods on the object. |
| 18 // void connect(string username, string host_jid, string auth_token); |
| 19 // |
| 20 // // Attributes. |
| 21 // readonly attribute unsigned short status; |
| 22 // } |
| 23 // |
| 24 // onreadystatechange |
| 25 // |
| 26 // Methods: |
| 27 // Connect(username, auth_token, host_jid, onstatechange); |
| 28 |
| 29 #ifndef REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_ |
| 30 #define REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_ |
| 31 |
| 32 #include <map> |
| 33 #include <string> |
| 34 #include <vector> |
| 35 |
| 36 #include "third_party/ppapi/cpp/scriptable_object.h" |
| 37 #include "third_party/ppapi/cpp/var.h" |
| 38 |
| 39 namespace remoting { |
| 40 |
| 41 class ChromotingPlugin; |
| 42 |
| 43 class ChromotingScriptableObject : public pp::ScriptableObject { |
| 44 public: |
| 45 explicit ChromotingScriptableObject(ChromotingPlugin* instance); |
| 46 virtual ~ChromotingScriptableObject(); |
| 47 |
| 48 virtual void Init(); |
| 49 |
| 50 // Override the ScriptableObject functions. |
| 51 virtual bool HasProperty(const pp::Var& name, pp::Var* exception); |
| 52 virtual bool HasMethod(const pp::Var& name, pp::Var* exception); |
| 53 virtual pp::Var GetProperty(const pp::Var& name, pp::Var* exception); |
| 54 virtual void GetAllPropertyNames(std::vector<pp::Var>* properties, |
| 55 pp::Var* exception); |
| 56 virtual void SetProperty(const pp::Var& name, |
| 57 const pp::Var& value, |
| 58 pp::Var* exception); |
| 59 virtual pp::Var Call(const pp::Var& method_name, |
| 60 const std::vector<pp::Var>& args, |
| 61 pp::Var* exception); |
| 62 |
| 63 private: |
| 64 typedef std::map<std::string, int> PropertyNameMap; |
| 65 typedef pp::Var (ChromotingScriptableObject::*MethodHandler)( |
| 66 const std::vector<pp::Var>& args, pp::Var* exception); |
| 67 struct PropertyDescriptor { |
| 68 explicit PropertyDescriptor(const std::string& n, pp::Var a) |
| 69 : name(n), attribute(a), method(NULL) { |
| 70 } |
| 71 |
| 72 explicit PropertyDescriptor(const std::string& n, MethodHandler m) |
| 73 : name(n), method(m) { |
| 74 } |
| 75 |
| 76 enum Type { |
| 77 ATTRIBUTE, |
| 78 METHOD, |
| 79 } type; |
| 80 |
| 81 std::string name; |
| 82 pp::Var attribute; |
| 83 MethodHandler method; |
| 84 }; |
| 85 |
| 86 |
| 87 void AddAttribute(const std::string& name, pp::Var attribute); |
| 88 void AddMethod(const std::string& name, MethodHandler handler); |
| 89 |
| 90 pp::Var DoConnect(const std::vector<pp::Var>& args, pp::Var* exception); |
| 91 |
| 92 PropertyNameMap property_names_; |
| 93 std::vector<PropertyDescriptor> properties_; |
| 94 |
| 95 ChromotingPlugin* instance_; |
| 96 }; |
| 97 |
| 98 } // namespace remoting |
| 99 |
| 100 #endif // REMOTING_CLIENT_PLUGIN_CHROMOTING_SCRIPTABLE_OBJECT_H_ |
OLD | NEW |