| 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 14 matching lines...) Expand all Loading... |
| 25 public: | 25 public: |
| 26 explicit ObjectBackedNativeHandler(ScriptContext* context); | 26 explicit ObjectBackedNativeHandler(ScriptContext* context); |
| 27 ~ObjectBackedNativeHandler() override; | 27 ~ObjectBackedNativeHandler() override; |
| 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 v8::Local<v8::Object> NewInstance() override; | 31 v8::Local<v8::Object> NewInstance() override; |
| 32 | 32 |
| 33 v8::Isolate* GetIsolate() const; | 33 v8::Isolate* GetIsolate() const; |
| 34 | 34 |
| 35 protected: |
| 35 typedef base::Callback<void(const v8::FunctionCallbackInfo<v8::Value>&)> | 36 typedef base::Callback<void(const v8::FunctionCallbackInfo<v8::Value>&)> |
| 36 HandlerFunction; | 37 HandlerFunction; |
| 37 | 38 |
| 38 protected: | |
| 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 // | 42 // |
| 43 // Routed functions are destroyed along with the destruction of this class, | 43 // Routed functions are destroyed along with the destruction of this class, |
| 44 // and are never called back into, therefore it's safe for |handler_function| | 44 // and are never called back into, therefore it's safe for |handler_function| |
| 45 // to bind to base::Unretained. | 45 // to bind to base::Unretained. |
| 46 // | 46 // |
| 47 // |feature_name[s]| corresponds to the api feature the native handler is used | 47 // |feature_name| corresponds to the api feature the native handler is used |
| 48 // for. If the associated ScriptContext does not have access to that feature, | 48 // for. If the associated ScriptContext does not have access to that feature, |
| 49 // the |handler_function| is not invoked. | 49 // the |handler_function| is not invoked. |
| 50 // TODO(devlin): Deprecate the version that doesn't take a |feature_name|. | 50 // TODO(devlin): Deprecate the version that doesn't take a |feature_name|. |
| 51 void RouteFunction(const std::string& name, | 51 void RouteFunction(const std::string& name, |
| 52 const HandlerFunction& handler_function); | 52 const HandlerFunction& handler_function); |
| 53 void RouteFunction(const std::string& name, | 53 void RouteFunction(const std::string& name, |
| 54 const std::string& feature_name, | 54 const std::string& feature_name, |
| 55 const HandlerFunction& handler_function); | 55 const HandlerFunction& handler_function); |
| 56 void RouteFunction(const std::string& name, | |
| 57 const std::vector<std::string>& feature_names, | |
| 58 const HandlerFunction& handler_function); | |
| 59 | 56 |
| 60 ScriptContext* context() const { return context_; } | 57 ScriptContext* context() const { return context_; } |
| 61 | 58 |
| 62 void Invalidate() override; | 59 void Invalidate() override; |
| 63 | 60 |
| 64 // Returns true if the given |context| is allowed to access the given | 61 // Returns true if the given |context| is allowed to access the given |
| 65 // |object|. This should be checked before returning any objects from another | 62 // |object|. This should be checked before returning any objects from another |
| 66 // context. | 63 // context. |
| 67 // |allow_null_context| indicates that if there is no ScriptContext associated | 64 // |allow_null_context| indicates that if there is no ScriptContext associated |
| 68 // with the |object|, it should be allowed. | 65 // with the |object|, it should be allowed. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 ScriptContext* context_; | 114 ScriptContext* context_; |
| 118 | 115 |
| 119 v8::Global<v8::ObjectTemplate> object_template_; | 116 v8::Global<v8::ObjectTemplate> object_template_; |
| 120 | 117 |
| 121 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler); | 118 DISALLOW_COPY_AND_ASSIGN(ObjectBackedNativeHandler); |
| 122 }; | 119 }; |
| 123 | 120 |
| 124 } // namespace extensions | 121 } // namespace extensions |
| 125 | 122 |
| 126 #endif // EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_ | 123 #endif // EXTENSIONS_RENDERER_OBJECT_BACKED_NATIVE_HANDLER_H_ |
| OLD | NEW |