OLD | NEW |
| (Empty) |
1 // Copyright 2010 The Ginsu Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can | |
3 // be found in the LICENSE file. | |
4 | |
5 #ifndef C_SALT_NPAPI_JAVASCRIPT_OBJECT_PROXY_H_ | |
6 #define C_SALT_NPAPI_JAVASCRIPT_OBJECT_PROXY_H_ | |
7 | |
8 #include <nacl/npruntime.h> | |
9 | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "c_salt/instance.h" | |
14 #include "c_salt/npapi/variant_converter.h" | |
15 #include "c_salt/scripting_interface.h" | |
16 #include "c_salt/variant_ptrs.h" | |
17 | |
18 namespace c_salt { | |
19 namespace npapi { | |
20 | |
21 // npapi::JavaScriptObjectProxy is a proxy to allow us to communicate with | |
22 // JavaScript objects via NPAPI. | |
23 class JavaScriptObjectProxy : public ScriptingInterface { | |
24 public: | |
25 JavaScriptObjectProxy(NPObject* object, NPP instance); | |
26 virtual ~JavaScriptObjectProxy(); | |
27 | |
28 virtual bool HasScriptMethod(const std::string& name); | |
29 virtual bool InvokeScriptMethod(const std::string& method_name, | |
30 const SharedVariant* params_begin, | |
31 const SharedVariant* params_end, | |
32 SharedVariant* return_value_var); | |
33 // Support for browser-exposed properties. The browser proxy (which is | |
34 // platform-specific) first calls HasProperty() before getting or setting; | |
35 // the Get or Set is performed only if HasProperty() returns |true|. The | |
36 // brwoser proxy is responsible for all the variant marshaling. | |
37 virtual bool HasScriptProperty(const std::string& name); | |
38 // Set |return_value| to the value associated with property |name|. If | |
39 // property |name| doesn't exist, then set |return_value| to the null type | |
40 // and return |false|. | |
41 virtual bool GetScriptProperty(const std::string& name, | |
42 SharedVariant* return_value) const; | |
43 // If |name| is associated with a static property, return that value. Else, | |
44 // if there is no property associated with |name|, add it as a dynamic | |
45 // property. See property.h for definitions and more details. | |
46 virtual bool SetScriptProperty(const std::string& name, | |
47 const SharedVariant& value); | |
48 // This succeeds only if |name| is associated with a dynamic property. | |
49 virtual bool RemoveScriptProperty(const std::string& name); | |
50 | |
51 // Return the names of all enumerable properties in to the provided vector. | |
52 virtual void GetAllPropertyNames(std::vector<std::string>* prop_names) const; | |
53 | |
54 // This is called by some browser proxies when all references to a proxy | |
55 // object have been deallocated, but the proxy's ref count has not gone to 0. | |
56 // It's kind of an anti-leak clean-up mechanism. | |
57 virtual void Invalidate(); | |
58 | |
59 virtual bool IsNative() const { return false; } | |
60 | |
61 // Returns true iff the object is valid (i.e., instance_ and np_object_ are | |
62 // non-null). | |
63 bool Valid() const; | |
64 | |
65 NPObject* np_object() { | |
66 return np_object_; | |
67 } | |
68 NPP instance() { | |
69 return instance_; | |
70 } | |
71 | |
72 private: | |
73 NPP instance_; | |
74 NPObject* np_object_; | |
75 VariantConverter variant_converter_; | |
76 }; | |
77 | |
78 } // namespace npapi | |
79 } // namespace c_salt | |
80 | |
81 #endif // C_SALT_NPAPI_JAVASCRIPT_OBJECT_PROXY_H_ | |
OLD | NEW |