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> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "extensions/renderer/native_handler.h" | 17 #include "extensions/renderer/native_handler.h" |
18 #include "extensions/renderer/object_backed_native_handler.h" | 18 #include "extensions/renderer/object_backed_native_handler.h" |
| 19 #include "extensions/renderer/script_injection_callback.h" |
19 #include "gin/modules/module_registry_observer.h" | 20 #include "gin/modules/module_registry_observer.h" |
20 #include "v8/include/v8.h" | 21 #include "v8/include/v8.h" |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 class ScriptContext; | 25 class ScriptContext; |
25 class SourceMap; | 26 class SourceMap; |
26 | 27 |
27 // A module system for JS similar to node.js' require() function. | 28 // A module system for JS similar to node.js' require() function. |
28 // Each module has three variables in the global scope: | 29 // Each module has three variables in the global scope: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 80 |
80 // Run |code| in the current context with the name |name| used for stack | 81 // Run |code| in the current context with the name |name| used for stack |
81 // traces. | 82 // traces. |
82 v8::Local<v8::Value> RunString(v8::Local<v8::String> code, | 83 v8::Local<v8::Value> RunString(v8::Local<v8::String> code, |
83 v8::Local<v8::String> name); | 84 v8::Local<v8::String> name); |
84 | 85 |
85 // Calls the specified method exported by the specified module. This is | 86 // Calls the specified method exported by the specified module. This is |
86 // equivalent to calling require('module_name').method_name() from JS. | 87 // equivalent to calling require('module_name').method_name() from JS. |
87 // DEPRECATED: see crbug.com/629431 | 88 // DEPRECATED: see crbug.com/629431 |
88 // TODO(devlin): Remove these. | 89 // TODO(devlin): Remove these. |
89 v8::Local<v8::Value> CallModuleMethod( | |
90 const std::string& module_name, | |
91 const std::string& method_name); | |
92 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name, | 90 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name, |
93 const std::string& method_name, | 91 const std::string& method_name, |
94 int argc, | 92 int argc, |
95 v8::Local<v8::Value> argv[]); | 93 v8::Local<v8::Value> argv[]); |
96 | 94 |
97 // Same as the above, but allows for blocking execution. | 95 // Same as the above, but allows for blocking execution. |
98 void CallModuleMethodSafe(const std::string& module_name, | 96 void CallModuleMethodSafe(const std::string& module_name, |
99 const std::string& method_name); | 97 const std::string& method_name); |
100 void CallModuleMethodSafe(const std::string& module_name, | 98 void CallModuleMethodSafe(const std::string& module_name, |
101 const std::string& method_name, | 99 const std::string& method_name, |
102 std::vector<v8::Local<v8::Value>>* args); | 100 std::vector<v8::Local<v8::Value>>* args); |
103 void CallModuleMethodSafe(const std::string& module_name, | 101 void CallModuleMethodSafe(const std::string& module_name, |
104 const std::string& method_name, | 102 const std::string& method_name, |
105 int argc, | 103 int argc, |
106 v8::Local<v8::Value> argv[]); | 104 v8::Local<v8::Value> argv[]); |
| 105 void CallModuleMethodSafe( |
| 106 const std::string& module_name, |
| 107 const std::string& method_name, |
| 108 int argc, |
| 109 v8::Local<v8::Value> argv[], |
| 110 const ScriptInjectionCallback::CompleteCallback& callback); |
107 | 111 |
108 // Register |native_handler| as a potential target for requireNative(), so | 112 // Register |native_handler| as a potential target for requireNative(), so |
109 // calls to requireNative(|name|) from JS will return a new object created by | 113 // calls to requireNative(|name|) from JS will return a new object created by |
110 // |native_handler|. | 114 // |native_handler|. |
111 void RegisterNativeHandler(const std::string& name, | 115 void RegisterNativeHandler(const std::string& name, |
112 std::unique_ptr<NativeHandler> native_handler); | 116 std::unique_ptr<NativeHandler> native_handler); |
113 | 117 |
114 // Causes requireNative(|name|) to look for its module in |source_map_| | 118 // Causes requireNative(|name|) to look for its module in |source_map_| |
115 // instead of using a registered native handler. This can be used in unit | 119 // instead of using a registered native handler. This can be used in unit |
116 // tests to mock out native modules. | 120 // tests to mock out native modules. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 std::vector<std::unique_ptr<NativeHandler>> clobbered_native_handlers_; | 257 std::vector<std::unique_ptr<NativeHandler>> clobbered_native_handlers_; |
254 | 258 |
255 base::WeakPtrFactory<ModuleSystem> weak_factory_; | 259 base::WeakPtrFactory<ModuleSystem> weak_factory_; |
256 | 260 |
257 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); | 261 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); |
258 }; | 262 }; |
259 | 263 |
260 } // namespace extensions | 264 } // namespace extensions |
261 | 265 |
262 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ | 266 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ |
OLD | NEW |