Chromium Code Reviews| 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..4477a98761c867705b16abaf89d39327103d9826 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 none are registered, we create one. |
|
lazyboy
2016/12/13 01:52:32
"we create one" is probably obsolete in the final
Devlin
2016/12/13 18:41:30
Good catch; done.
|
| + 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, |