| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 CppBoundClass class: | 6 CppBoundClass class: |
| 7 This base class serves as a parent for C++ classes designed to be bound to | 7 This base class serves as a parent for C++ classes designed to be bound to |
| 8 JavaScript objects. | 8 JavaScript objects. |
| 9 | 9 |
| 10 Subclasses should define the constructor to build the property and method | 10 Subclasses should define the constructor to build the property and method |
| 11 lists needed to bind this class to a JS object. They should also declare | 11 lists needed to bind this class to a JS object. They should also declare |
| 12 and define member variables and methods to be exposed to JS through | 12 and define member variables and methods to be exposed to JS through |
| 13 that object. | 13 that object. |
| 14 | 14 |
| 15 See cpp_binding_example.{h|cc} for an example. | 15 See cpp_binding_example.{h|cc} for an example. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #ifndef WEBKIT_RENDERER_CPP_BOUND_CLASS_H_ | 18 #ifndef CONTENT_RENDERER_CPP_BOUND_CLASS_H_ |
| 19 #define WEBKIT_RENDERER_CPP_BOUND_CLASS_H_ | 19 #define CONTENT_RENDERER_CPP_BOUND_CLASS_H_ |
| 20 | 20 |
| 21 #include <map> | 21 #include <map> |
| 22 #include <vector> | 22 #include <vector> |
| 23 | 23 |
| 24 #include "base/callback.h" | 24 #include "base/callback.h" |
| 25 #include "webkit/renderer/cpp_variant.h" | 25 #include "content/common/content_export.h" |
| 26 #include "webkit/renderer/webkit_renderer_export.h" | 26 #include "content/renderer/cpp_variant.h" |
| 27 | 27 |
| 28 namespace WebKit { | 28 namespace WebKit { |
| 29 class WebFrame; | 29 class WebFrame; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace webkit_glue { | 32 namespace content { |
| 33 | 33 |
| 34 typedef std::vector<CppVariant> CppArgumentList; | 34 typedef std::vector<CppVariant> CppArgumentList; |
| 35 | 35 |
| 36 // CppBoundClass lets you map Javascript method calls and property accesses | 36 // CppBoundClass lets you map Javascript method calls and property accesses |
| 37 // directly to C++ method calls and CppVariant* variable access. | 37 // directly to C++ method calls and CppVariant* variable access. |
| 38 class WEBKIT_RENDERER_EXPORT CppBoundClass { | 38 class CONTENT_EXPORT CppBoundClass { |
| 39 public: | 39 public: |
| 40 class PropertyCallback { | 40 class PropertyCallback { |
| 41 public: | 41 public: |
| 42 virtual ~PropertyCallback() { } | 42 virtual ~PropertyCallback() { } |
| 43 | 43 |
| 44 // Sets |value| to the value of the property. Returns false in case of | 44 // Sets |value| to the value of the property. Returns false in case of |
| 45 // failure. |value| is always non-NULL. | 45 // failure. |value| is always non-NULL. |
| 46 virtual bool GetValue(CppVariant* value) = 0; | 46 virtual bool GetValue(CppVariant* value) = 0; |
| 47 | 47 |
| 48 // sets the property value to |value|. Returns false in case of failure. | 48 // sets the property value to |value|. Returns false in case of failure. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 PropertyList properties_; | 116 PropertyList properties_; |
| 117 MethodList methods_; | 117 MethodList methods_; |
| 118 | 118 |
| 119 // The callback gets invoked when a call is made to an nonexistent method. | 119 // The callback gets invoked when a call is made to an nonexistent method. |
| 120 Callback fallback_callback_; | 120 Callback fallback_callback_; |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 // NPObject callbacks. | 123 // NPObject callbacks. |
| 124 friend struct CppNPObject; | 124 friend struct CppNPObject; |
| 125 bool HasMethod(NPIdentifier ident) const; | 125 bool HasMethod(NPIdentifier ident) const; |
| 126 bool Invoke(NPIdentifier ident, const NPVariant* args, size_t arg_count, | 126 bool Invoke(NPIdentifier ident, |
| 127 const NPVariant* args, |
| 128 size_t arg_count, |
| 127 NPVariant* result); | 129 NPVariant* result); |
| 128 bool HasProperty(NPIdentifier ident) const; | 130 bool HasProperty(NPIdentifier ident) const; |
| 129 bool GetProperty(NPIdentifier ident, NPVariant* result) const; | 131 bool GetProperty(NPIdentifier ident, NPVariant* result) const; |
| 130 bool SetProperty(NPIdentifier ident, const NPVariant* value); | 132 bool SetProperty(NPIdentifier ident, const NPVariant* value); |
| 131 | 133 |
| 132 // A lazily-initialized CppVariant representing this class. We retain 1 | 134 // A lazily-initialized CppVariant representing this class. We retain 1 |
| 133 // reference to this object, and it is released on deletion. | 135 // reference to this object, and it is released on deletion. |
| 134 CppVariant self_variant_; | 136 CppVariant self_variant_; |
| 135 | 137 |
| 136 // TODO(wez): Remove once crrev.com/14019005 lands. | 138 // TODO(wez): Remove once crrev.com/14019005 lands. |
| 137 bool bound_to_frame_; | 139 bool bound_to_frame_; |
| 138 | 140 |
| 139 // Dummy NPP to use to register as owner for NPObjects. | 141 // Dummy NPP to use to register as owner for NPObjects. |
| 140 scoped_ptr<NPP_t> npp_; | 142 scoped_ptr<NPP_t> npp_; |
| 141 | 143 |
| 142 DISALLOW_COPY_AND_ASSIGN(CppBoundClass); | 144 DISALLOW_COPY_AND_ASSIGN(CppBoundClass); |
| 143 }; | 145 }; |
| 144 | 146 |
| 145 } // namespace webkit_glue | 147 } // namespace content |
| 146 | 148 |
| 147 #endif // WEBKIT_RENDERER_CPP_BOUND_CLASS_H_ | 149 #endif // CONTENT_RENDERER_CPP_BOUND_CLASS_H_ |
| OLD | NEW |