Chromium Code Reviews| Index: chrome/renderer/extensions/dispatcher.cc |
| diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc |
| index ddb1086b0ccedf286f5d498dd7d0df8205da92c4..4c4ee06fa4958a5a221787ae961cec848ab9509a 100644 |
| --- a/chrome/renderer/extensions/dispatcher.cc |
| +++ b/chrome/renderer/extensions/dispatcher.cc |
| @@ -722,17 +722,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(); |
| + 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; |
| - if (!context->IsAnyFeatureAvailableToContext(api_name)) |
| + |
| + Feature* feature = feature_provider->GetFeature(api_name); |
| + DCHECK(feature); |
| + if (feature->HasParent() || feature->IsInternal()) |
| continue; |
| - Feature* feature = |
| - BaseFeatureProvider::GetByName("api")->GetFeature(api_name); |
| - if (feature && feature->IsInternal()) |
| + if (!context->IsAnyFeatureAvailableToContext(api_name)) |
| continue; |
|
not at google - send to devlin
2013/05/30 16:38:52
without the parent this is going to get trickier.
cduvall
2013/06/12 01:22:19
I ended up keeping the HasParent(), and just using
|
| std::vector<std::string> split; |
| @@ -755,7 +756,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; |
| @@ -1426,28 +1427,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(); |
| @@ -1462,7 +1441,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(); |
| } |
| } // namespace extensions |