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 WEBKIT_RENDERER_CPP_BOUND_CLASS_H_ |
19 #define WEBKIT_RENDERER_CPP_BOUND_CLASS_H_ | 19 #define WEBKIT_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 "webkit/renderer/cpp_variant.h" |
26 #include "webkit/renderer/webkit_renderer_export.h" | 26 #include "webkit/renderer/webkit_renderer_export.h" |
27 | 27 |
28 namespace WebKit { | 28 namespace blink { |
29 class WebFrame; | 29 class WebFrame; |
30 } | 30 } |
31 | 31 |
32 namespace webkit_glue { | 32 namespace webkit_glue { |
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 WEBKIT_RENDERER_EXPORT CppBoundClass { |
(...skipping 20 matching lines...) Expand all Loading... |
59 // The variant type is guaranteed to be NPVariantType_Object. | 59 // The variant type is guaranteed to be NPVariantType_Object. |
60 CppVariant* GetAsCppVariant(); | 60 CppVariant* GetAsCppVariant(); |
61 | 61 |
62 // Given a WebFrame, BindToJavascript builds the NPObject that will represent | 62 // Given a WebFrame, BindToJavascript builds the NPObject that will represent |
63 // this CppBoundClass object and binds it to the frame's window under the | 63 // this CppBoundClass object and binds it to the frame's window under the |
64 // given name. This should generally be called from the WebView delegate's | 64 // given name. This should generally be called from the WebView delegate's |
65 // WindowObjectCleared(). This CppBoundClass object will be accessible to | 65 // WindowObjectCleared(). This CppBoundClass object will be accessible to |
66 // JavaScript as window.<classname>. The owner of this CppBoundClass object is | 66 // JavaScript as window.<classname>. The owner of this CppBoundClass object is |
67 // responsible for keeping it around while the frame is alive, and for | 67 // responsible for keeping it around while the frame is alive, and for |
68 // destroying it afterwards. | 68 // destroying it afterwards. |
69 void BindToJavascript(WebKit::WebFrame* frame, const std::string& classname); | 69 void BindToJavascript(blink::WebFrame* frame, const std::string& classname); |
70 | 70 |
71 // The type of callbacks. | 71 // The type of callbacks. |
72 typedef base::Callback<void(const CppArgumentList&, CppVariant*)> Callback; | 72 typedef base::Callback<void(const CppArgumentList&, CppVariant*)> Callback; |
73 typedef base::Callback<void(CppVariant*)> GetterCallback; | 73 typedef base::Callback<void(CppVariant*)> GetterCallback; |
74 | 74 |
75 // Used by a test. Returns true if a method with name |name| exists, | 75 // Used by a test. Returns true if a method with name |name| exists, |
76 // regardless of whether a fallback is registered. | 76 // regardless of whether a fallback is registered. |
77 bool IsMethodRegistered(const std::string& name) const; | 77 bool IsMethodRegistered(const std::string& name) const; |
78 | 78 |
79 protected: | 79 protected: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 // Dummy NPP to use to register as owner for NPObjects. | 139 // Dummy NPP to use to register as owner for NPObjects. |
140 scoped_ptr<NPP_t> npp_; | 140 scoped_ptr<NPP_t> npp_; |
141 | 141 |
142 DISALLOW_COPY_AND_ASSIGN(CppBoundClass); | 142 DISALLOW_COPY_AND_ASSIGN(CppBoundClass); |
143 }; | 143 }; |
144 | 144 |
145 } // namespace webkit_glue | 145 } // namespace webkit_glue |
146 | 146 |
147 #endif // WEBKIT_RENDERER_CPP_BOUND_CLASS_H_ | 147 #endif // WEBKIT_RENDERER_CPP_BOUND_CLASS_H_ |
OLD | NEW |