| 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_MODULE_SYSTEM_H_ | 5 #ifndef EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
| 6 #define EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ | 6 #define EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 v8::MaybeLocal<v8::Object> Require(const std::string& module_name); | 84 v8::MaybeLocal<v8::Object> Require(const std::string& module_name); |
| 85 void Require(const v8::FunctionCallbackInfo<v8::Value>& args); | 85 void Require(const v8::FunctionCallbackInfo<v8::Value>& args); |
| 86 | 86 |
| 87 // Run |code| in the current context with the name |name| used for stack | 87 // Run |code| in the current context with the name |name| used for stack |
| 88 // traces. | 88 // traces. |
| 89 v8::Local<v8::Value> RunString(v8::Local<v8::String> code, | 89 v8::Local<v8::Value> RunString(v8::Local<v8::String> code, |
| 90 v8::Local<v8::String> name); | 90 v8::Local<v8::String> name); |
| 91 | 91 |
| 92 // Calls the specified method exported by the specified module. This is | 92 // Calls the specified method exported by the specified module. This is |
| 93 // equivalent to calling require('module_name').method_name() from JS. | 93 // equivalent to calling require('module_name').method_name() from JS. |
| 94 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name, | 94 // DEPRECATED: see crbug.com/629431 |
| 95 const std::string& method_name); | 95 // TODO(devlin): Remove these. |
| 96 v8::Local<v8::Value> CallModuleMethod( |
| 97 const std::string& module_name, |
| 98 const std::string& method_name); |
| 96 v8::Local<v8::Value> CallModuleMethod( | 99 v8::Local<v8::Value> CallModuleMethod( |
| 97 const std::string& module_name, | 100 const std::string& module_name, |
| 98 const std::string& method_name, | 101 const std::string& method_name, |
| 99 std::vector<v8::Local<v8::Value>>* args); | 102 std::vector<v8::Local<v8::Value>>* args); |
| 100 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name, | 103 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name, |
| 101 const std::string& method_name, | 104 const std::string& method_name, |
| 102 int argc, | 105 int argc, |
| 103 v8::Local<v8::Value> argv[]); | 106 v8::Local<v8::Value> argv[]); |
| 104 | 107 |
| 108 // Same as the above, but allows for blocking execution. |
| 109 void CallModuleMethodSafe(const std::string& module_name, |
| 110 const std::string& method_name); |
| 111 void CallModuleMethodSafe(const std::string& module_name, |
| 112 const std::string& method_name, |
| 113 std::vector<v8::Local<v8::Value>>* args); |
| 114 void CallModuleMethodSafe(const std::string& module_name, |
| 115 const std::string& method_name, |
| 116 int argc, |
| 117 v8::Local<v8::Value> argv[]); |
| 118 |
| 105 // Register |native_handler| as a potential target for requireNative(), so | 119 // Register |native_handler| as a potential target for requireNative(), so |
| 106 // calls to requireNative(|name|) from JS will return a new object created by | 120 // calls to requireNative(|name|) from JS will return a new object created by |
| 107 // |native_handler|. | 121 // |native_handler|. |
| 108 void RegisterNativeHandler(const std::string& name, | 122 void RegisterNativeHandler(const std::string& name, |
| 109 std::unique_ptr<NativeHandler> native_handler); | 123 std::unique_ptr<NativeHandler> native_handler); |
| 110 | 124 |
| 111 // Causes requireNative(|name|) to look for its module in |source_map_| | 125 // Causes requireNative(|name|) to look for its module in |source_map_| |
| 112 // instead of using a registered native handler. This can be used in unit | 126 // instead of using a registered native handler. This can be used in unit |
| 113 // tests to mock out native modules. | 127 // tests to mock out native modules. |
| 114 void OverrideNativeHandlerForTest(const std::string& name); | 128 void OverrideNativeHandlerForTest(const std::string& name); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 225 |
| 212 // gin::ModuleRegistryObserver overrides. | 226 // gin::ModuleRegistryObserver overrides. |
| 213 void OnDidAddPendingModule( | 227 void OnDidAddPendingModule( |
| 214 const std::string& id, | 228 const std::string& id, |
| 215 const std::vector<std::string>& dependencies) override; | 229 const std::vector<std::string>& dependencies) override; |
| 216 | 230 |
| 217 // Marks any existing NativeHandler named |name| as clobbered. | 231 // Marks any existing NativeHandler named |name| as clobbered. |
| 218 // See |clobbered_native_handlers_|. | 232 // See |clobbered_native_handlers_|. |
| 219 void ClobberExistingNativeHandler(const std::string& name); | 233 void ClobberExistingNativeHandler(const std::string& name); |
| 220 | 234 |
| 235 // Returns the v8::Function associated with the given module and method name. |
| 236 v8::Local<v8::Function> GetModuleFunction(const std::string& module_name, |
| 237 const std::string& method_name); |
| 238 |
| 221 ScriptContext* context_; | 239 ScriptContext* context_; |
| 222 | 240 |
| 223 // A map from module names to the JS source for that module. GetSource() | 241 // A map from module names to the JS source for that module. GetSource() |
| 224 // performs a lookup on this map. | 242 // performs a lookup on this map. |
| 225 const SourceMap* const source_map_; | 243 const SourceMap* const source_map_; |
| 226 | 244 |
| 227 // A map from native handler names to native handlers. | 245 // A map from native handler names to native handlers. |
| 228 NativeHandlerMap native_handler_map_; | 246 NativeHandlerMap native_handler_map_; |
| 229 | 247 |
| 230 // When 0, natives are disabled, otherwise indicates how many callers have | 248 // When 0, natives are disabled, otherwise indicates how many callers have |
| (...skipping 15 matching lines...) Expand all Loading... |
| 246 std::vector<std::unique_ptr<NativeHandler>> clobbered_native_handlers_; | 264 std::vector<std::unique_ptr<NativeHandler>> clobbered_native_handlers_; |
| 247 | 265 |
| 248 base::WeakPtrFactory<ModuleSystem> weak_factory_; | 266 base::WeakPtrFactory<ModuleSystem> weak_factory_; |
| 249 | 267 |
| 250 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); | 268 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); |
| 251 }; | 269 }; |
| 252 | 270 |
| 253 } // namespace extensions | 271 } // namespace extensions |
| 254 | 272 |
| 255 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ | 273 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
| OLD | NEW |