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

Unified Diff: extensions/renderer/script_context.cc

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 side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/script_context.cc
diff --git a/extensions/renderer/script_context.cc b/extensions/renderer/script_context.cc
index 77dc80cca73b0a64b7b4fd158157b5cdf7494fb7..40a7ce7f23e9603bb0b6290d07235369bccf335f 100644
--- a/extensions/renderer/script_context.cc
+++ b/extensions/renderer/script_context.cc
@@ -205,17 +205,36 @@ v8::Local<v8::Value> ScriptContext::CallFunction(
void ScriptContext::SafeCallFunction(const v8::Local<v8::Function>& function,
int argc,
v8::Local<v8::Value> argv[]) {
+ SafeCallFunction(function, argc, argv,
+ ScriptInjectionCallback::CompleteCallback());
+}
+
+void ScriptContext::SafeCallFunction(
+ const v8::Local<v8::Function>& function,
+ int argc,
+ v8::Local<v8::Value> argv[],
+ const ScriptInjectionCallback::CompleteCallback& callback) {
+ DCHECK(thread_checker_.CalledOnValidThread());
v8::HandleScope handle_scope(isolate());
v8::Context::Scope scope(v8_context());
v8::MicrotasksScope microtasks(isolate(),
v8::MicrotasksScope::kDoNotRunMicrotasks);
v8::Local<v8::Object> global = v8_context()->Global();
if (web_frame_) {
+ ScriptInjectionCallback* wrapper_callback = nullptr;
+ if (!callback.is_null()) {
+ // ScriptInjectionCallback manages its own lifetime.
+ wrapper_callback = new ScriptInjectionCallback(callback);
+ }
web_frame_->requestExecuteV8Function(v8_context(), function, global, argc,
- argv, nullptr);
+ argv, wrapper_callback);
} else {
// TODO(devlin): This probably isn't safe.
- function->Call(global, argc, argv);
+ v8::Local<v8::Value> result = function->Call(global, argc, argv);
+ if (!callback.is_null()) {
+ std::vector<v8::Local<v8::Value>> results(1, result);
+ callback.Run(results);
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698