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

Unified Diff: extensions/renderer/api_bindings_system.cc

Issue 2704823002: [Extensions Bindings] Add support for custom property types (Closed)
Patch Set: asan fix Created 3 years, 10 months 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/native_extension_bindings_system.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 b90483bcb1ae33ed74a0142f002f31784b217c19..02680c4d05e1b2c2197d6b44b1b9a22103c8db9b 100644
--- a/extensions/renderer/api_bindings_system.cc
+++ b/extensions/renderer/api_bindings_system.cc
@@ -70,8 +70,10 @@ std::unique_ptr<APIBinding> APIBindingsSystem::CreateNewAPIBinding(
return base::MakeUnique<APIBinding>(
api_name, function_definitions, type_definitions, event_definitions,
- property_definitions, std::move(hooks), &type_reference_map_,
- &request_handler_, &event_handler_);
+ property_definitions,
+ base::Bind(&APIBindingsSystem::CreateCustomType, base::Unretained(this)),
+ std::move(hooks), &type_reference_map_, &request_handler_,
+ &event_handler_);
}
void APIBindingsSystem::InitializeType(const std::string& type_name) {
@@ -115,4 +117,21 @@ APIBindingHooks* APIBindingsSystem::GetHooksForAPI(
return hooks.get();
}
+void APIBindingsSystem::RegisterCustomType(const std::string& type_name,
+ const CustomTypeHandler& function) {
+ DCHECK(custom_types_.find(type_name) == custom_types_.end())
+ << "Custom type already registered: " << type_name;
+ custom_types_[type_name] = function;
+}
+
+v8::Local<v8::Object> APIBindingsSystem::CreateCustomType(
+ v8::Local<v8::Context> context,
+ const std::string& type_name,
+ const std::string& property_name) {
+ auto iter = custom_types_.find(type_name);
+ DCHECK(iter != custom_types_.end()) << "Custom type not found: " << type_name;
+ return iter->second.Run(context, property_name, &request_handler_,
+ &type_reference_map_);
+}
+
} // namespace extensions
« no previous file with comments | « extensions/renderer/api_bindings_system.h ('k') | extensions/renderer/native_extension_bindings_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698