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

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: comments Created 7 years, 7 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 eeed3250898818bbcea6f1e6e22804521e8909a0..ef633d7a84b93797893c93e834627007cb761768 100644
--- a/chrome/renderer/extensions/dispatcher.cc
+++ b/chrome/renderer/extensions/dispatcher.cc
@@ -718,17 +718,18 @@ v8::Handle<v8::Object> Dispatcher::GetOrCreateObject(
void Dispatcher::RegisterSchemaGeneratedBindings(
ModuleSystem* module_system,
ChromeV8Context* context) {
- std::set<std::string> apis =
- ExtensionAPI::GetSharedInstance()->GetAllAPINames();
- for (std::set<std::string>::iterator it = apis.begin();
+ std::vector<std::string> apis =
not at google - send to devlin 2013/05/24 19:09:18 also const&
cduvall 2013/05/30 00:50:51 Done.
+ BaseFeatureProvider::GetByName("api")->GetAllFeatureNames();
+ for (std::vector<std::string>::iterator it = apis.begin();
it != apis.end(); ++it) {
const std::string& api_name = *it;
- if (!context->IsAnyFeatureAvailableToContext(api_name))
- continue;
Feature* feature =
BaseFeatureProvider::GetByName("api")->GetFeature(api_name);
not at google - send to devlin 2013/05/24 19:09:18 maybe save a reference to this.
cduvall 2013/05/30 00:50:51 Done.
- if (feature && feature->IsInternal())
+ if (feature && (feature->HasParent() || feature->IsInternal()))
not at google - send to devlin 2013/05/24 19:09:18 there should always be a feature here since we're
cduvall 2013/05/30 00:50:51 Done.
+ continue;
+
+ if (!context->IsAnyFeatureAvailableToContext(api_name))
continue;
std::vector<std::string> split;
@@ -751,7 +752,7 @@ void Dispatcher::RegisterSchemaGeneratedBindings(
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 (ancestor_name == "app" &&
context->GetAvailability(ancestor_name).is_available() &&
!context->GetAvailability(api_name).is_available()) {
only_ancestor_available = true;
@@ -1422,28 +1423,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();
@@ -1458,7 +1437,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())));
not at google - send to devlin 2013/05/24 19:09:18 nice
cduvall 2013/05/30 00:50:51 So a side effect of this is that API methods with
not at google - send to devlin 2013/05/30 16:38:51 Cool. That's fine, the right thing to do for now -
+ }
+
+ return availability.is_available();
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698