| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_ | 5 #ifndef EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_ |
| 6 #define EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_ | 6 #define EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // An ObjectBackedNativeHandler is a factory for JS objects with functions on | 21 // An ObjectBackedNativeHandler is a factory for JS objects with functions on |
| 22 // them that map to native C++ functions. Subclasses should call RouteFunction() | 22 // them that map to native C++ functions. Subclasses should call RouteFunction() |
| 23 // in their constructor to define functions on the created JS objects. | 23 // in their constructor to define functions on the created JS objects. |
| 24 class ObjectBackedNativeHandler : public NativeHandler { | 24 class ObjectBackedNativeHandler : public NativeHandler { |
| 25 public: | 25 public: |
| 26 explicit ObjectBackedNativeHandler(ScriptContext* context); | 26 explicit ObjectBackedNativeHandler(ScriptContext* context); |
| 27 virtual ~ObjectBackedNativeHandler(); | 27 virtual ~ObjectBackedNativeHandler(); |
| 28 | 28 |
| 29 // Create an object with bindings to the native functions defined through | 29 // Create an object with bindings to the native functions defined through |
| 30 // RouteFunction(). | 30 // RouteFunction(). |
| 31 virtual v8::Handle<v8::Object> NewInstance() OVERRIDE; | 31 virtual v8::Handle<v8::Object> NewInstance() override; |
| 32 | 32 |
| 33 v8::Isolate* GetIsolate() const; | 33 v8::Isolate* GetIsolate() const; |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 typedef base::Callback<void(const v8::FunctionCallbackInfo<v8::Value>&)> | 36 typedef base::Callback<void(const v8::FunctionCallbackInfo<v8::Value>&)> |
| 37 HandlerFunction; | 37 HandlerFunction; |
| 38 | 38 |
| 39 // Installs a new 'route' from |name| to |handler_function|. This means that | 39 // Installs a new 'route' from |name| to |handler_function|. This means that |
| 40 // NewInstance()s of this ObjectBackedNativeHandler will have a property | 40 // NewInstance()s of this ObjectBackedNativeHandler will have a property |
| 41 // |name| which will be handled by |handler_function|. | 41 // |name| which will be handled by |handler_function|. |
| 42 void RouteFunction(const std::string& name, | 42 void RouteFunction(const std::string& name, |
| 43 const HandlerFunction& handler_function); | 43 const HandlerFunction& handler_function); |
| 44 | 44 |
| 45 ScriptContext* context() const { return context_; } | 45 ScriptContext* context() const { return context_; } |
| 46 | 46 |
| 47 virtual void Invalidate() OVERRIDE; | 47 virtual void Invalidate() override; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 // Callback for RouteFunction which routes the V8 call to the correct | 50 // Callback for RouteFunction which routes the V8 call to the correct |
| 51 // base::Bound callback. | 51 // base::Bound callback. |
| 52 static void Router(const v8::FunctionCallbackInfo<v8::Value>& args); | 52 static void Router(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 53 | 53 |
| 54 // When RouteFunction is called we create a v8::Object to hold the data we | 54 // When RouteFunction is called we create a v8::Object to hold the data we |
| 55 // need when handling it in Router() - this is the base::Bound function to | 55 // need when handling it in Router() - this is the base::Bound function to |
| 56 // route to. | 56 // route to. |
| 57 // | 57 // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 ScriptContext* context_; | 70 ScriptContext* context_; |
| 71 | 71 |
| 72 ScopedPersistent<v8::ObjectTemplate> object_template_; | 72 ScopedPersistent<v8::ObjectTemplate> object_template_; |
| 73 | 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler); | 74 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 } // namespace extensions | 77 } // namespace extensions |
| 78 | 78 |
| 79 #endif // EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_ | 79 #endif // EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_ |
| OLD | NEW |