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

Unified Diff: extensions/renderer/api_binding.cc

Issue 2438623002: [Extensions Bindings] Add APIBindingsSystem (Closed)
Patch Set: lazyboy's Created 4 years, 1 month 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.h ('k') | extensions/renderer/api_binding_unittest.cc » ('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 6459365510484864dd4a7974a61f843c5aca51ed..2a8335bfa6049c821213a2842498d4d3a8d09529 100644
--- a/extensions/renderer/api_binding.cc
+++ b/extensions/renderer/api_binding.cc
@@ -160,12 +160,15 @@ void CallbackHelper(const v8::FunctionCallbackInfo<v8::Value>& info) {
APIBinding::APIPerContextData::APIPerContextData() {}
APIBinding::APIPerContextData::~APIPerContextData() {}
-APIBinding::APIBinding(const std::string& name,
+APIBinding::APIBinding(const std::string& api_name,
const base::ListValue& function_definitions,
- const base::ListValue& type_definitions,
+ const base::ListValue* type_definitions,
const APIMethodCallback& callback,
ArgumentSpec::RefMap* type_refs)
- : method_callback_(callback), type_refs_(type_refs), weak_factory_(this) {
+ : api_name_(api_name),
+ method_callback_(callback),
+ type_refs_(type_refs),
+ weak_factory_(this) {
DCHECK(!method_callback_.is_null());
for (const auto& func : function_definitions) {
const base::DictionaryValue* func_dict = nullptr;
@@ -175,15 +178,17 @@ APIBinding::APIBinding(const std::string& name,
std::unique_ptr<APISignature> spec = GetAPISignature(*func_dict);
signatures_[name] = std::move(spec);
}
- for (const auto& type : type_definitions) {
- const base::DictionaryValue* type_dict = nullptr;
- CHECK(type->GetAsDictionary(&type_dict));
- std::string id;
- CHECK(type_dict->GetString("id", &id));
- DCHECK(type_refs->find(id) == type_refs->end());
- // TODO(devlin): refs are sometimes preceeded by the API namespace; we might
- // need to take that into account.
- (*type_refs)[id] = base::MakeUnique<ArgumentSpec>(*type_dict);
+ if (type_definitions) {
+ for (const auto& type : *type_definitions) {
+ const base::DictionaryValue* type_dict = nullptr;
+ CHECK(type->GetAsDictionary(&type_dict));
+ std::string id;
+ CHECK(type_dict->GetString("id", &id));
+ DCHECK(type_refs->find(id) == type_refs->end());
+ // TODO(devlin): refs are sometimes preceeded by the API namespace; we
+ // might need to take that into account.
+ (*type_refs)[id] = base::MakeUnique<ArgumentSpec>(*type_dict);
+ }
}
}
@@ -206,9 +211,11 @@ v8::Local<v8::Object> APIBinding::CreateInstance(v8::Local<v8::Context> context,
api_data.release());
}
for (const auto& sig : signatures_) {
+ std::string full_method_name =
+ base::StringPrintf("%s.%s", api_name_.c_str(), sig.first.c_str());
auto handler_callback = base::MakeUnique<HandlerCallback>(
base::Bind(&APIBinding::HandleCall, weak_factory_.GetWeakPtr(),
- sig.first, sig.second.get()));
+ full_method_name, sig.second.get()));
// TODO(devlin): We should be able to cache these in a function template.
v8::MaybeLocal<v8::Function> maybe_function =
v8::Function::New(context, &CallbackHelper,
« no previous file with comments | « extensions/renderer/api_binding.h ('k') | extensions/renderer/api_binding_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698