Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: extensions/renderer/module_system.h

Issue 2556153002: [Extensions] Convert more callers of CallModuleMethod (Closed)
Patch Set: revertdoc Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 26
26 // A module system for JS similar to node.js' require() function. 27 // A module system for JS similar to node.js' require() function.
27 // Each module has three variables in the global scope: 28 // Each module has three variables in the global scope:
28 // - exports, an object returned to dependencies who require() this 29 // - exports, an object returned to dependencies who require() this
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 87
87 // Run |code| in the current context with the name |name| used for stack 88 // Run |code| in the current context with the name |name| used for stack
88 // traces. 89 // traces.
89 v8::Local<v8::Value> RunString(v8::Local<v8::String> code, 90 v8::Local<v8::Value> RunString(v8::Local<v8::String> code,
90 v8::Local<v8::String> name); 91 v8::Local<v8::String> name);
91 92
92 // Calls the specified method exported by the specified module. This is 93 // Calls the specified method exported by the specified module. This is
93 // equivalent to calling require('module_name').method_name() from JS. 94 // equivalent to calling require('module_name').method_name() from JS.
94 // DEPRECATED: see crbug.com/629431 95 // DEPRECATED: see crbug.com/629431
95 // TODO(devlin): Remove these. 96 // TODO(devlin): Remove these.
96 v8::Local<v8::Value> CallModuleMethod(
97 const std::string& module_name,
98 const std::string& method_name);
99 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name, 97 v8::Local<v8::Value> CallModuleMethod(const std::string& module_name,
100 const std::string& method_name, 98 const std::string& method_name,
101 int argc, 99 int argc,
102 v8::Local<v8::Value> argv[]); 100 v8::Local<v8::Value> argv[]);
103 101
104 // Same as the above, but allows for blocking execution. 102 // Same as the above, but allows for blocking execution.
105 void CallModuleMethodSafe(const std::string& module_name, 103 void CallModuleMethodSafe(const std::string& module_name,
106 const std::string& method_name); 104 const std::string& method_name);
107 void CallModuleMethodSafe(const std::string& module_name, 105 void CallModuleMethodSafe(const std::string& module_name,
108 const std::string& method_name, 106 const std::string& method_name,
109 std::vector<v8::Local<v8::Value>>* args); 107 std::vector<v8::Local<v8::Value>>* args);
110 void CallModuleMethodSafe(const std::string& module_name, 108 void CallModuleMethodSafe(const std::string& module_name,
111 const std::string& method_name, 109 const std::string& method_name,
112 int argc, 110 int argc,
113 v8::Local<v8::Value> argv[]); 111 v8::Local<v8::Value> argv[]);
112 void CallModuleMethodSafe(
113 const std::string& module_name,
114 const std::string& method_name,
115 int argc,
116 v8::Local<v8::Value> argv[],
117 const ScriptInjectionCallback::CompleteCallback& callback);
114 118
115 // Register |native_handler| as a potential target for requireNative(), so 119 // Register |native_handler| as a potential target for requireNative(), so
116 // 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
117 // |native_handler|. 121 // |native_handler|.
118 void RegisterNativeHandler(const std::string& name, 122 void RegisterNativeHandler(const std::string& name,
119 std::unique_ptr<NativeHandler> native_handler); 123 std::unique_ptr<NativeHandler> native_handler);
120 124
121 // Causes requireNative(|name|) to look for its module in |source_map_| 125 // Causes requireNative(|name|) to look for its module in |source_map_|
122 // 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
123 // tests to mock out native modules. 127 // tests to mock out native modules.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 std::vector<std::unique_ptr<NativeHandler>> clobbered_native_handlers_; 264 std::vector<std::unique_ptr<NativeHandler>> clobbered_native_handlers_;
261 265
262 base::WeakPtrFactory<ModuleSystem> weak_factory_; 266 base::WeakPtrFactory<ModuleSystem> weak_factory_;
263 267
264 DISALLOW_COPY_AND_ASSIGN(ModuleSystem); 268 DISALLOW_COPY_AND_ASSIGN(ModuleSystem);
265 }; 269 };
266 270
267 } // namespace extensions 271 } // namespace extensions
268 272
269 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_ 273 #endif // EXTENSIONS_RENDERER_MODULE_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698