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

Side by Side Diff: extensions/renderer/extension_injection_host.cc

Issue 1335083004: [Extensions] Don't allow extensions to inject scripts into extension pages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/extension_injection_host.h" 5 #include "extensions/renderer/extension_injection_host.h"
6 6
7 #include "content/public/renderer/render_frame.h" 7 #include "content/public/renderer/render_frame.h"
8 #include "extensions/common/constants.h" 8 #include "extensions/common/constants.h"
9 #include "extensions/common/manifest_handlers/csp_info.h" 9 #include "extensions/common/manifest_handlers/csp_info.h"
10 #include "extensions/renderer/renderer_extension_registry.h" 10 #include "extensions/renderer/renderer_extension_registry.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 const std::string& ExtensionInjectionHost::name() const { 44 const std::string& ExtensionInjectionHost::name() const {
45 return extension_->name(); 45 return extension_->name();
46 } 46 }
47 47
48 PermissionsData::AccessType ExtensionInjectionHost::CanExecuteOnFrame( 48 PermissionsData::AccessType ExtensionInjectionHost::CanExecuteOnFrame(
49 const GURL& document_url, 49 const GURL& document_url,
50 content::RenderFrame* render_frame, 50 content::RenderFrame* render_frame,
51 int tab_id, 51 int tab_id,
52 bool is_declarative) const { 52 bool is_declarative) const {
53 // If we don't have a tab id, we have no UI surface to ask for user consent.
54 // For now, we treat this as an automatic allow.
55 if (tab_id == -1)
56 return PermissionsData::ACCESS_ALLOWED;
57
58 blink::WebSecurityOrigin top_frame_security_origin = 53 blink::WebSecurityOrigin top_frame_security_origin =
59 render_frame->GetWebFrame()->top()->securityOrigin(); 54 render_frame->GetWebFrame()->top()->securityOrigin();
60 // Only whitelisted extensions may run scripts on another extension's page. 55 // Only whitelisted extensions may run scripts on another extension's page.
61 if (top_frame_security_origin.protocol().utf8() == kExtensionScheme && 56 if (top_frame_security_origin.protocol().utf8() == kExtensionScheme &&
62 top_frame_security_origin.host().utf8() != extension_->id() && 57 top_frame_security_origin.host().utf8() != extension_->id() &&
63 !PermissionsData::CanExecuteScriptEverywhere(extension_)) 58 !PermissionsData::CanExecuteScriptEverywhere(extension_))
64 return PermissionsData::ACCESS_DENIED; 59 return PermissionsData::ACCESS_DENIED;
65 60
66 // Declarative user scripts use "page access" (from "permissions" section in 61 // Declarative user scripts use "page access" (from "permissions" section in
67 // manifest) whereas non-declarative user scripts use custom 62 // manifest) whereas non-declarative user scripts use custom
68 // "content script access" logic. 63 // "content script access" logic.
64 PermissionsData::AccessType access = PermissionsData::ACCESS_ALLOWED;
69 if (is_declarative) { 65 if (is_declarative) {
70 return extension_->permissions_data()->GetPageAccess( 66 access = extension_->permissions_data()->GetPageAccess(
71 extension_, 67 extension_,
72 document_url, 68 document_url,
73 tab_id, 69 tab_id,
74 -1, // no process id 70 -1, // no process id
75 nullptr /* ignore error */); 71 nullptr /* ignore error */);
76 } else { 72 } else {
77 return extension_->permissions_data()->GetContentScriptAccess( 73 access = extension_->permissions_data()->GetContentScriptAccess(
78 extension_, 74 extension_,
79 document_url, 75 document_url,
80 tab_id, 76 tab_id,
81 -1, // no process id 77 -1, // no process id
82 nullptr /* ignore error */); 78 nullptr /* ignore error */);
83 } 79 }
80 if (access == PermissionsData::ACCESS_WITHHELD &&
81 (tab_id == -1 || render_frame->GetWebFrame()->parent())) {
82 // Note: we don't consider ACCESS_WITHHELD for child frames or for frames
83 // outside of tabs because there is nowhere to surface a request.
84 // TODO(devlin): We should ask for permission somehow. crbug.com/491402.
85 access = PermissionsData::ACCESS_DENIED;
86 }
87 return access;
84 } 88 }
85 89
86 bool ExtensionInjectionHost::ShouldNotifyBrowserOfInjection() const { 90 bool ExtensionInjectionHost::ShouldNotifyBrowserOfInjection() const {
87 // We notify the browser of any injection if the extension has no withheld 91 // We notify the browser of any injection if the extension has no withheld
88 // permissions (i.e., the permissions weren't restricted), but would have 92 // permissions (i.e., the permissions weren't restricted), but would have
89 // otherwise been affected by the scripts-require-action feature. 93 // otherwise been affected by the scripts-require-action feature.
90 return extension_->permissions_data()->withheld_permissions()->IsEmpty() && 94 return extension_->permissions_data()->withheld_permissions()->IsEmpty() &&
91 PermissionsData::ScriptsMayRequireActionForExtension( 95 PermissionsData::ScriptsMayRequireActionForExtension(
92 extension_, 96 extension_,
93 extension_->permissions_data()->active_permissions().get()); 97 extension_->permissions_data()->active_permissions().get());
94 } 98 }
95 99
96 } // namespace extensions 100 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/content_scripts/script_a_com/script.js ('k') | extensions/renderer/script_injection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698