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

Unified Diff: chrome/renderer/extensions/dispatcher.cc

Issue 15091002: Lazily load API schemas from resource files and convert all APIs to features (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 7 years, 6 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
Index: chrome/renderer/extensions/dispatcher.cc
diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc
index cdcbcfefcb22905a7c3d3e64f42669151f7a2a51..e813001e5b895309146e44413cf21152ca721d64 100644
--- a/chrome/renderer/extensions/dispatcher.cc
+++ b/chrome/renderer/extensions/dispatcher.cc
@@ -624,21 +624,21 @@ void Dispatcher::AddOrRemoveBindings(ChromeV8Context* context) {
v8::HandleScope handle_scope;
v8::Context::Scope context_scope(context->v8_context());
- std::set<std::string> apis =
- ExtensionAPI::GetSharedInstance()->GetAllAPINames();
- for (std::set<std::string>::iterator it = apis.begin();
+ FeatureProvider* feature_provider = BaseFeatureProvider::GetByName("api");
+ const std::vector<std::string>& apis = feature_provider->GetAllFeatureNames();
+ for (std::vector<std::string>::const_iterator it = apis.begin();
it != apis.end(); ++it) {
const std::string& api_name = *it;
+ Feature* feature = feature_provider->GetFeature(api_name);
+ DCHECK(feature);
+ if (feature->HasParent() || feature->IsInternal())
+ continue;
+
if (!context->IsAnyFeatureAvailableToContext(api_name)) {
not at google - send to devlin 2013/06/12 22:34:18 see comment in base_feature_provider.cc
DeregisterBinding(api_name, context);
continue;
}
- Feature* feature =
- BaseFeatureProvider::GetByName("api")->GetFeature(api_name);
- if (feature && feature->IsInternal())
- continue;
-
RegisterBinding(api_name, context);
}
}
@@ -672,12 +672,13 @@ v8::Handle<v8::Object> Dispatcher::GetOrCreateBindObjectIfAvailable(
// If app is available and app.window is not, just install app.
// If app.window is available and app is not, delete app and install
// app.window on a new object so app does not have to be loaded.
+ FeatureProvider* feature_provider = BaseFeatureProvider::GetByName("api");
std::string ancestor_name;
bool only_ancestor_available = false;
for (size_t i = 0; i < split.size() - 1; ++i) {
ancestor_name += (i ? ".": "") + split[i];
- if (!ancestor_name.empty() &&
+ if (feature_provider->GetFeature(ancestor_name) &&
context->GetAvailability(ancestor_name).is_available() &&
!context->GetAvailability(api_name).is_available()) {
only_ancestor_available = true;
@@ -1363,28 +1364,6 @@ bool Dispatcher::CheckContextAccessToExtensionAPI(
return false;
}
- if (!context->extension()->HasAPIPermission(function_name)) {
- static const char kMessage[] =
- "You do not have permission to use '%s'. Be sure to declare"
- " in your manifest what permissions you need.";
- std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
- APIActivityLogger::LogBlockedCall(context->extension()->id(),
- function_name);
- v8::ThrowException(
- v8::Exception::Error(v8::String::New(error_msg.c_str())));
- return false;
- }
-
- if (ExtensionAPI::GetSharedInstance()->IsPrivileged(function_name) &&
- context->context_type() != Feature::BLESSED_EXTENSION_CONTEXT) {
- static const char kMessage[] =
- "%s can only be used in an extension process.";
- std::string error_msg = base::StringPrintf(kMessage, function_name.c_str());
- v8::ThrowException(
- v8::Exception::Error(v8::String::New(error_msg.c_str())));
- return false;
- }
-
// Theoretically we could end up with bindings being injected into sandboxed
// frames, for example content scripts. Don't let them execute API functions.
WebKit::WebFrame* frame = context->web_frame();
@@ -1399,7 +1378,13 @@ bool Dispatcher::CheckContextAccessToExtensionAPI(
return false;
}
- return true;
+ Feature::Availability availability = context->GetAvailability(function_name);
+ if (!availability.is_available()) {
+ v8::ThrowException(v8::Exception::Error(
+ v8::String::New(availability.message().c_str())));
+ }
+
+ return availability.is_available();
}
void Dispatcher::DispatchEvent(const std::string& extension_id,

Powered by Google App Engine
This is Rietveld 408576698