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

Unified Diff: extensions/renderer/dispatcher.cc

Issue 789063002: Implement clipboardRead/Write content capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 984a48deae46d84624e417a790503599333b2069..f7eefdfba0832769056b28cd5762682bc7b6fbb2 100644
--- a/extensions/renderer/dispatcher.cc
+++ b/extensions/renderer/dispatcher.cc
@@ -31,6 +31,7 @@
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/background_info.h"
+#include "extensions/common/manifest_handlers/content_capabilities_handler.h"
#include "extensions/common/manifest_handlers/externally_connectable.h"
#include "extensions/common/manifest_handlers/options_page_info.h"
#include "extensions/common/manifest_handlers/sandboxed_page_info.h"
@@ -1094,33 +1095,17 @@ void Dispatcher::UpdateBindingsForContext(ScriptContext* context) {
switch (context->context_type()) {
case Feature::UNSPECIFIED_CONTEXT:
case Feature::WEB_PAGE_CONTEXT:
- case Feature::BLESSED_WEB_PAGE_CONTEXT: {
+ case Feature::BLESSED_WEB_PAGE_CONTEXT:
// Web page context; it's too expensive to run the full bindings code.
// Hard-code that the app and webstore APIs are available...
if (context->GetAvailability("app").is_available())
RegisterBinding("app", context);
-
if (context->GetAvailability("webstore").is_available())
RegisterBinding("webstore", context);
-
- // ... and that the runtime API might be available if any extension can
- // connect to it.
- bool runtime_is_available = false;
- for (ExtensionSet::const_iterator it = extensions_.begin();
- it != extensions_.end();
- ++it) {
- ExternallyConnectableInfo* info =
- static_cast<ExternallyConnectableInfo*>(
- (*it)->GetManifestData(manifest_keys::kExternallyConnectable));
- if (info && info->matches.MatchesURL(context->GetURL())) {
- runtime_is_available = true;
- break;
- }
- }
- if (runtime_is_available)
+ if (IsRuntimeAvailableToContext(context))
RegisterBinding("runtime", context);
+ UpdateContentCapabilities(context);
break;
- }
case Feature::BLESSED_EXTENSION_CONTEXT:
case Feature::UNBLESSED_EXTENSION_CONTEXT:
@@ -1232,6 +1217,31 @@ void Dispatcher::RegisterNativeHandlers(ModuleSystem* module_system,
delegate_->RegisterNativeHandlers(this, module_system, context);
}
+bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) {
+ for (const auto& extension : extensions_) {
+ ExternallyConnectableInfo* info =
+ static_cast<ExternallyConnectableInfo*>(
+ extension->GetManifestData(manifest_keys::kExternallyConnectable));
+ if (info && info->matches.MatchesURL(context->GetURL()))
+ return true;
+ }
+ return false;
+}
+
+void Dispatcher::UpdateContentCapabilities(ScriptContext* context) {
+ APIPermissionSet permissions;
+ for (const auto& extension : extensions_) {
+ const ContentCapabilitiesInfo& info = ContentCapabilitiesInfo::Get(
+ extension.get());
+ if (info.url_patterns.MatchesURL(context->GetURL())) {
+ APIPermissionSet new_permissions;
+ APIPermissionSet::Union(permissions, info.permissions, &new_permissions);
+ permissions = new_permissions;
+ }
+ }
+ context->SetContentCapabilities(permissions);
+}
+
void Dispatcher::PopulateSourceMap() {
const std::vector<std::pair<std::string, int> > resources = GetJsResources();
for (std::vector<std::pair<std::string, int> >::const_iterator resource =

Powered by Google App Engine
This is Rietveld 408576698