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

Unified Diff: extensions/renderer/api_binding_hooks.h

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 | « extensions/renderer/api_binding.cc ('k') | extensions/renderer/api_binding_hooks.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_binding_hooks.h
diff --git a/extensions/renderer/api_binding_hooks.h b/extensions/renderer/api_binding_hooks.h
index c075c1d175edf4de4239d73b6c1a42f9c9061816..249a3390204f3e3614e8ada363ff7d8d6c0685b2 100644
--- a/extensions/renderer/api_binding_hooks.h
+++ b/extensions/renderer/api_binding_hooks.h
@@ -38,16 +38,29 @@ class APIBindingHooks {
using HandleRequestHook =
base::Callback<void(const binding::APISignature*, gin::Arguments*)>;
- APIBindingHooks();
+ explicit APIBindingHooks(const binding::RunJSFunction& run_js);
~APIBindingHooks();
// Register a custom binding to handle requests.
void RegisterHandleRequest(const std::string& method_name,
const HandleRequestHook& hook);
- // Returns the custom hook for the given method, or a null callback if none
- // exists.
- HandleRequestHook GetHandleRequest(const std::string& method_name);
+ // Registers a JS script to be compiled and run in order to initialize any JS
+ // hooks within a v8 context.
+ void RegisterJsSource(v8::Global<v8::String> source,
+ v8::Global<v8::String> resource_name);
+
+ // Initializes JS hooks within a context.
+ void InitializeInContext(v8::Local<v8::Context> context,
+ const std::string& api_name);
+
+ // Looks for a custom hook to handle the given request and, if one exists,
+ // runs it. Returns true if a hook was found and run.
+ bool HandleRequest(const std::string& api_name,
+ const std::string& method_name,
+ v8::Local<v8::Context> context,
+ const binding::APISignature* signature,
+ gin::Arguments* arguments);
private:
// Whether we've tried to use any hooks associated with this object.
@@ -56,6 +69,15 @@ class APIBindingHooks {
// All registered request handlers.
std::map<std::string, HandleRequestHook> request_hooks_;
+ // The script to run to initialize JS hooks, if any.
+ v8::Global<v8::String> js_hooks_source_;
+
+ // The name of the JS resource for the hooks. Used to create a ScriptOrigin
+ // to make exception stack traces more readable.
+ v8::Global<v8::String> js_resource_name_;
+
+ binding::RunJSFunction run_js_;
+
DISALLOW_COPY_AND_ASSIGN(APIBindingHooks);
};
« no previous file with comments | « extensions/renderer/api_binding.cc ('k') | extensions/renderer/api_binding_hooks.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698