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

Unified Diff: extensions/renderer/api_bindings_system.cc

Issue 2552343006: [Extensions Binding] Allow for registering custom hooks (Closed)
Patch Set: . 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_bindings_system.h ('k') | extensions/renderer/api_bindings_system_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_bindings_system.cc
diff --git a/extensions/renderer/api_bindings_system.cc b/extensions/renderer/api_bindings_system.cc
index 14ec34115f61085598c5fd4f22f26c85fbd3bb00..b9879fbb0968629055b60d4116849dfe7dc2d709 100644
--- a/extensions/renderer/api_bindings_system.cc
+++ b/extensions/renderer/api_bindings_system.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/values.h"
+#include "extensions/renderer/api_binding_hooks.h"
namespace extensions {
@@ -47,10 +48,18 @@ std::unique_ptr<APIBinding> APIBindingsSystem::CreateNewAPIBinding(
const base::ListValue* event_definitions = nullptr;
api_schema.GetList("events", &event_definitions);
+ // Find the hooks for the API, if any exist.
+ std::unique_ptr<APIBindingHooks> hooks;
+ auto iter = binding_hooks_.find(api_name);
+ if (iter != binding_hooks_.end()) {
+ hooks = std::move(iter->second);
+ binding_hooks_.erase(iter);
+ }
+
return base::MakeUnique<APIBinding>(
api_name, *function_definitions, type_definitions, event_definitions,
base::Bind(&APIBindingsSystem::OnAPICall, base::Unretained(this)),
- &type_reference_map_);
+ std::move(hooks), &type_reference_map_);
}
void APIBindingsSystem::CompleteRequest(int request_id,
@@ -64,6 +73,16 @@ void APIBindingsSystem::FireEventInContext(const std::string& event_name,
event_handler_.FireEventInContext(event_name, context, response);
}
+APIBindingHooks* APIBindingsSystem::GetHooksForAPI(
+ const std::string& api_name) {
+ DCHECK(api_bindings_.empty())
+ << "Hook registration must happen before creating any binding instances.";
+ std::unique_ptr<APIBindingHooks>& hooks = binding_hooks_[api_name];
+ if (!hooks)
+ hooks = base::MakeUnique<APIBindingHooks>();
+ return hooks.get();
+}
+
void APIBindingsSystem::OnAPICall(const std::string& name,
std::unique_ptr<base::ListValue> arguments,
v8::Isolate* isolate,
« no previous file with comments | « extensions/renderer/api_bindings_system.h ('k') | extensions/renderer/api_bindings_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698