| 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 #ifndef CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/linked_ptr.h" | |
| 10 #include "v8/include/v8.h" | 9 #include "v8/include/v8.h" |
| 11 | 10 |
| 12 #include <string> | 11 #include <string> |
| 13 #include <vector> | |
| 14 | 12 |
| 15 namespace extensions { | 13 namespace extensions { |
| 16 | 14 |
| 17 // A NativeHandler is a factory for JS objects with functions on them that map | 15 // A NativeHandler is a factory for JS objects with functions on them that map |
| 18 // to native C++ functions. Subclasses should call RouteFunction() in their | 16 // to native C++ functions. Subclasses should call RouteFunction() in their |
| 19 // constructor to define functions on the created JS objects. | 17 // constructor to define functions on the created JS objects. |
| 20 // | 18 // |
| 21 // NativeHandlers are intended to be used with a ModuleSystem. The ModuleSystem | 19 // NativeHandlers are intended to be used with a ModuleSystem. The ModuleSystem |
| 22 // will assume ownership of the NativeHandler, and as a ModuleSystem is tied to | 20 // will assume ownership of the NativeHandler, and as a ModuleSystem is tied to |
| 23 // a single v8::Context, this implies that NativeHandlers will also be tied to | 21 // a single v8::Context, this implies that NativeHandlers will also be tied to |
| (...skipping 17 matching lines...) Expand all Loading... |
| 41 // NewInstance()s of this NativeHandler will have a property |name| which | 39 // NewInstance()s of this NativeHandler will have a property |name| which |
| 42 // will be handled by |handler_function|. | 40 // will be handled by |handler_function|. |
| 43 void RouteFunction(const std::string& name, | 41 void RouteFunction(const std::string& name, |
| 44 const HandlerFunction& handler_function); | 42 const HandlerFunction& handler_function); |
| 45 | 43 |
| 46 void RouteStaticFunction(const std::string& name, | 44 void RouteStaticFunction(const std::string& name, |
| 47 const HandlerFunc handler_func); | 45 const HandlerFunc handler_func); |
| 48 | 46 |
| 49 private: | 47 private: |
| 50 static v8::Handle<v8::Value> Router(const v8::Arguments& args); | 48 static v8::Handle<v8::Value> Router(const v8::Arguments& args); |
| 49 static void DisposeFunction(v8::Persistent<v8::Value> object, |
| 50 void* parameter); |
| 51 | 51 |
| 52 std::vector<linked_ptr<HandlerFunction> > handler_functions_; | |
| 53 v8::Persistent<v8::ObjectTemplate> object_template_; | 52 v8::Persistent<v8::ObjectTemplate> object_template_; |
| 54 | 53 |
| 55 DISALLOW_COPY_AND_ASSIGN(NativeHandler); | 54 DISALLOW_COPY_AND_ASSIGN(NativeHandler); |
| 56 }; | 55 }; |
| 57 | 56 |
| 58 } // extensions | 57 } // extensions |
| 59 | 58 |
| 60 #endif // CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ | 59 #endif // CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ |
| OLD | NEW |