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

Unified Diff: extensions/renderer/dispatcher.cc

Issue 498513002: Respect the clipboardRead and clipboardWrite permissions in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 3 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: extensions/renderer/dispatcher.cc
diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc
index d52d1505c06bfe2a7da38acde2639c831bf5fa29..945160bda1e1ebc04849b94eea59d80bf688fd7f 100644
--- a/extensions/renderer/dispatcher.cc
+++ b/extensions/renderer/dispatcher.cc
@@ -219,19 +219,38 @@ bool Dispatcher::IsExtensionActive(const std::string& extension_id) const {
return is_active;
}
-std::string Dispatcher::GetExtensionID(const WebFrame* frame, int world_id) {
+const Extension* Dispatcher::GetExtensionFromFrameAndWorld(
+ const WebFrame* frame,
+ int world_id,
+ bool use_effective_url) {
if (world_id != 0) {
// Isolated worlds (content script).
- return ScriptInjection::GetExtensionIdForIsolatedWorld(world_id);
+ std::string extension_id =
+ ScriptInjection::GetExtensionIdForIsolatedWorld(world_id);
+ const Extension* extension = extensions_.GetByID(extension_id);
+ if (!extension && !extension_id.empty()) {
+ // There are conditions where despite a context being associated with an
+ // extension, no extension actually gets found. Ignore "invalid" because
+ // CSP blocks extension page loading by switching the extension ID to
+ // "invalid". This isn't interesting.
+ if (extension_id != "invalid") {
+ LOG(ERROR) << "Extension \"" << extension_id << "\" not found";
+ RenderThread::Get()->RecordAction(
+ UserMetricsAction("ExtensionNotFound_ED"));
+ }
+ }
+ return extension;
}
// TODO(kalman): Delete this check.
if (frame->document().securityOrigin().isUnique())
- return std::string();
+ return 0;
// Extension pages (chrome-extension:// URLs).
GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
- return extensions_.GetExtensionOrAppIDByURL(frame_url);
+ frame_url = ScriptContext::GetEffectiveDocumentURL(
+ frame, frame_url, use_effective_url);
+ return extensions_.GetExtensionOrAppByURL(frame_url);
}
void Dispatcher::DidCreateScriptContext(
@@ -243,32 +262,30 @@ void Dispatcher::DidCreateScriptContext(
return;
#endif
- std::string extension_id = GetExtensionID(frame, world_id);
-
- const Extension* extension = extensions_.GetByID(extension_id);
- if (!extension && !extension_id.empty()) {
- // There are conditions where despite a context being associated with an
- // extension, no extension actually gets found. Ignore "invalid" because
- // CSP blocks extension page loading by switching the extension ID to
- // "invalid". This isn't interesting.
- if (extension_id != "invalid") {
- LOG(ERROR) << "Extension \"" << extension_id << "\" not found";
- RenderThread::Get()->RecordAction(
- UserMetricsAction("ExtensionNotFound_ED"));
- }
-
- extension_id = "";
- }
+ const Extension* extension =
+ GetExtensionFromFrameAndWorld(frame, world_id, false);
+ const Extension* effective_extension =
+ GetExtensionFromFrameAndWorld(frame, world_id, true);
+ GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
Feature::Context context_type =
ClassifyJavaScriptContext(extension,
extension_group,
- ScriptContext::GetDataSourceURLForFrame(frame),
+ frame_url,
frame->document().securityOrigin());
+ Feature::Context effective_context_type = ClassifyJavaScriptContext(
+ effective_extension,
+ extension_group,
+ ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true),
+ frame->document().securityOrigin());
ScriptContext* context =
- delegate_->CreateScriptContext(v8_context, frame, extension, context_type)
- .release();
+ delegate_->CreateScriptContext(v8_context,
+ frame,
+ extension,
+ context_type,
+ effective_extension,
+ effective_context_type).release();
script_context_set_.Add(context);
// Initialize origin permissions for content scripts, which can't be

Powered by Google App Engine
This is Rietveld 408576698