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

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 more 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
« no previous file with comments | « extensions/renderer/dispatcher.h ('k') | extensions/renderer/dispatcher_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/dispatcher.cc
diff --git a/extensions/renderer/dispatcher.cc b/extensions/renderer/dispatcher.cc
index d52d1505c06bfe2a7da38acde2639c831bf5fa29..a9df678da87d438d53d443a23442f1331f1ca820 100644
--- a/extensions/renderer/dispatcher.cc
+++ b/extensions/renderer/dispatcher.cc
@@ -219,32 +219,24 @@ 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) {
+ std::string extension_id;
if (world_id != 0) {
// Isolated worlds (content script).
- return ScriptInjection::GetExtensionIdForIsolatedWorld(world_id);
+ extension_id = ScriptInjection::GetExtensionIdForIsolatedWorld(world_id);
+ } else if (!frame->document().securityOrigin().isUnique()) {
+ // TODO(kalman): Delete the above check.
+
+ // Extension pages (chrome-extension:// URLs).
+ GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
+ frame_url = ScriptContext::GetEffectiveDocumentURL(
+ frame, frame_url, use_effective_url);
+ extension_id = extensions_.GetExtensionOrAppIDByURL(frame_url);
}
- // TODO(kalman): Delete this check.
- if (frame->document().securityOrigin().isUnique())
- return std::string();
-
- // Extension pages (chrome-extension:// URLs).
- GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame);
- return extensions_.GetExtensionOrAppIDByURL(frame_url);
-}
-
-void Dispatcher::DidCreateScriptContext(
- WebFrame* frame,
- const v8::Handle<v8::Context>& v8_context,
- int extension_group,
- int world_id) {
-#if !defined(ENABLE_EXTENSIONS)
- 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
@@ -256,19 +248,43 @@ void Dispatcher::DidCreateScriptContext(
RenderThread::Get()->RecordAction(
UserMetricsAction("ExtensionNotFound_ED"));
}
-
- extension_id = "";
}
+ return extension;
+}
+
+void Dispatcher::DidCreateScriptContext(
+ WebFrame* frame,
+ const v8::Handle<v8::Context>& v8_context,
+ int extension_group,
+ int world_id) {
+#if !defined(ENABLE_EXTENSIONS)
+ return;
+#endif
+ 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
« no previous file with comments | « extensions/renderer/dispatcher.h ('k') | extensions/renderer/dispatcher_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698