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

Unified Diff: extensions/renderer/api_binding.cc

Issue 2563093002: [Extension Bindings] Add JS custom hook support (Closed)
Patch Set: nits 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
« no previous file with comments | « no previous file | extensions/renderer/api_binding_hooks.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_binding.cc
diff --git a/extensions/renderer/api_binding.cc b/extensions/renderer/api_binding.cc
index 2f585a0f6bb291223cec129a1a38c375ea57156d..9b6b6091a35221300514713e9bad47a69d22f43d 100644
--- a/extensions/renderer/api_binding.cc
+++ b/extensions/renderer/api_binding.cc
@@ -290,6 +290,9 @@ v8::Local<v8::Object> APIBinding::CreateInstance(
DCHECK(success.FromJust());
}
+ if (binding_hooks_)
+ binding_hooks_->InitializeInContext(context, api_name_);
+
return object;
}
@@ -300,14 +303,15 @@ void APIBinding::HandleCall(const std::string& name,
v8::Isolate* isolate = arguments->isolate();
v8::HandleScope handle_scope(isolate);
- if (binding_hooks_) {
- // Check for a custom hook to handle the method.
- APIBindingHooks::HandleRequestHook handler =
- binding_hooks_->GetHandleRequest(name);
- if (!handler.is_null()) {
- handler.Run(signature, arguments);
- return;
- }
+ // Since this is called synchronously from the JS entry point,
+ // GetCurrentContext() should always be correct.
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+
+ // Check for a custom hook to handle the method.
+ if (binding_hooks_ &&
+ binding_hooks_->HandleRequest(api_name_, name, context,
+ signature, arguments)) {
+ return; // Handled by a custom hook.
}
std::unique_ptr<base::ListValue> parsed_arguments;
@@ -327,10 +331,8 @@ void APIBinding::HandleCall(const std::string& name,
return;
}
- // Since this is called synchronously from the JS entry point,
- // GetCurrentContext() should always be correct.
method_callback_.Run(name, std::move(parsed_arguments), isolate,
- isolate->GetCurrentContext(), callback);
+ context, callback);
}
} // namespace extensions
« no previous file with comments | « no previous file | extensions/renderer/api_binding_hooks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698