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

Unified Diff: extensions/renderer/dispatcher.cc

Issue 2494653005: Support API aliases (Closed)
Patch Set: update docs 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
Index: extensions/renderer/dispatcher.cc
diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc
index fe1cff9c125c395142fc73e8489cfdee47110f17..310fc72696fd3f5c2b8a6daad7f4531cfdceca23 100644
--- a/extensions/renderer/dispatcher.cc
+++ b/extensions/renderer/dispatcher.cc
@@ -1360,13 +1360,13 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) {
// contexts, because it's too expensive to run the full bindings code.
// All of the same permission checks will still apply.
if (context->GetAvailability("app").is_available())
- RegisterBinding("app", context);
+ RegisterBinding("app", "app", context);
if (context->GetAvailability("webstore").is_available())
- RegisterBinding("webstore", context);
+ RegisterBinding("webstore", "webstore", context);
if (context->GetAvailability("dashboardPrivate").is_available())
- RegisterBinding("dashboardPrivate", context);
+ RegisterBinding("dashboardPrivate", "dashboardPrivate", context);
if (IsRuntimeAvailableToContext(context))
- RegisterBinding("runtime", context);
+ RegisterBinding("runtime", "runtime", context);
UpdateContentCapabilities(context);
break;
@@ -1400,10 +1400,15 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) {
continue;
}
- if (context->IsAnyFeatureAvailableToContext(*map_entry.second)) {
+ if (context->IsAnyFeatureAvailableToContext(
+ *map_entry.second, CheckAliasStatus::NOT_ALLOWED)) {
+ // Check if the API feature is indeed an alias. If it is, the API
+ // should use source API bindings as its own.
+ const std::string& source = map_entry.second->source();
// TODO(lazyboy): RegisterBinding() uses |source_map_|, any thread
// safety issue?
- RegisterBinding(map_entry.first, context);
+ RegisterBinding(source.empty() ? map_entry.first : source,
+ map_entry.first, context);
}
}
break;
@@ -1412,10 +1417,11 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) {
}
void Dispatcher::RegisterBinding(const std::string& api_name,
+ const std::string& api_bind_name,
ScriptContext* context) {
std::string bind_name;
v8::Local<v8::Object> bind_object =
- GetOrCreateBindObjectIfAvailable(api_name, &bind_name, context);
+ GetOrCreateBindObjectIfAvailable(api_bind_name, &bind_name, context);
// Empty if the bind object failed to be created, probably because the
// extension overrode chrome with a non-object, e.g. window.chrome = true.
@@ -1443,11 +1449,11 @@ void Dispatcher::RegisterBinding(const std::string& api_name,
ModuleSystem* module_system = context->module_system();
if (!source_map_.Contains(api_name)) {
module_system->RegisterNativeHandler(
- api_name,
+ api_bind_name,
std::unique_ptr<NativeHandler>(
new BindingGeneratingNativeHandler(context, api_name, "binding")));
- module_system->SetNativeLazyField(
- bind_object, bind_name, api_name, "binding");
+ module_system->SetNativeLazyField(bind_object, bind_name, api_bind_name,
+ "binding");
} else {
module_system->SetLazyField(bind_object, bind_name, api_name, "binding");
}
@@ -1583,8 +1589,10 @@ v8::Local<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable(
for (size_t i = 0; i < split.size() - 1; ++i) {
ancestor_name += (i ? "." : "") + split[i];
if (api_feature_provider->GetFeature(ancestor_name) &&
- context->GetAvailability(ancestor_name).is_available() &&
- !context->GetAvailability(api_name).is_available()) {
+ context->GetAvailability(ancestor_name, CheckAliasStatus::NOT_ALLOWED)
+ .is_available() &&
+ !context->GetAvailability(api_name, CheckAliasStatus::NOT_ALLOWED)
+ .is_available()) {
only_ancestor_available = true;
break;
}

Powered by Google App Engine
This is Rietveld 408576698