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

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

Issue 934763003: Refactoring: de-couple Extensions from "script injection System" [render side]:3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_brower_isolated_world_routingid_user_script_1
Patch Set: Rebase. Created 5 years, 9 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/common/extension_set.h"
5 #include "extensions/common/manifest_handlers/csp_info.h" 6 #include "extensions/common/manifest_handlers/csp_info.h"
6 #include "extensions/renderer/extension_injection_host.h" 7 #include "extensions/renderer/extension_injection_host.h"
7 8
8 namespace extensions { 9 namespace extensions {
9 10
10 ExtensionInjectionHost::ExtensionInjectionHost( 11 ExtensionInjectionHost::ExtensionInjectionHost(
11 const scoped_refptr<const Extension>& extension) 12 const Extension* extension)
12 : InjectionHost(HostID(HostID::EXTENSIONS, extension->id())), 13 : InjectionHost(HostID(HostID::EXTENSIONS, extension->id())),
13 extension_(extension) { 14 extension_(extension) {
14 } 15 }
15 16
16 ExtensionInjectionHost::~ExtensionInjectionHost() { 17 ExtensionInjectionHost::~ExtensionInjectionHost() {
17 } 18 }
18 19
19 const std::string& ExtensionInjectionHost::GetContentSecurityPolicy() const { 20 // static
20 return CSPInfo::GetContentSecurityPolicy(extension_.get()); 21 scoped_ptr<const ExtensionInjectionHost> ExtensionInjectionHost::Create(
22 const std::string& extension_id, const ExtensionSet* extensions) {
23 const Extension* extension = extensions->GetByID(extension_id);
24 if (!extension)
25 return scoped_ptr<const ExtensionInjectionHost>();
26 return scoped_ptr<const ExtensionInjectionHost>(
27 new ExtensionInjectionHost(extension));
28 }
29
30 std::string ExtensionInjectionHost::GetContentSecurityPolicy() const {
31 return CSPInfo::GetContentSecurityPolicy(extension_);
21 } 32 }
22 33
23 const GURL& ExtensionInjectionHost::url() const { 34 const GURL& ExtensionInjectionHost::url() const {
24 return extension_->url(); 35 return extension_->url();
25 } 36 }
26 37
27 const std::string& ExtensionInjectionHost::name() const { 38 const std::string& ExtensionInjectionHost::name() const {
28 return extension_->name(); 39 return extension_->name();
29 } 40 }
30 41
31 PermissionsData::AccessType ExtensionInjectionHost::CanExecuteOnFrame( 42 PermissionsData::AccessType ExtensionInjectionHost::CanExecuteOnFrame(
32 const GURL& document_url, 43 const GURL& document_url,
33 const GURL& top_frame_url, 44 const GURL& top_frame_url,
34 int tab_id, 45 int tab_id,
35 bool is_declarative) const { 46 bool is_declarative) const {
36 // If we don't have a tab id, we have no UI surface to ask for user consent. 47 // If we don't have a tab id, we have no UI surface to ask for user consent.
37 // For now, we treat this as an automatic allow. 48 // For now, we treat this as an automatic allow.
38 if (tab_id == -1) 49 if (tab_id == -1)
39 return PermissionsData::ACCESS_ALLOWED; 50 return PermissionsData::ACCESS_ALLOWED;
40 51
41 // Declarative user scripts use "page access" (from "permissions" section in 52 // Declarative user scripts use "page access" (from "permissions" section in
42 // manifest) whereas non-declarative user scripts use custom 53 // manifest) whereas non-declarative user scripts use custom
43 // "content script access" logic. 54 // "content script access" logic.
44 if (is_declarative) { 55 if (is_declarative) {
45 return extension_->permissions_data()->GetPageAccess( 56 return extension_->permissions_data()->GetPageAccess(
46 extension_.get(), 57 extension_,
47 document_url, 58 document_url,
48 top_frame_url, 59 top_frame_url,
49 tab_id, 60 tab_id,
50 -1, // no process id 61 -1, // no process id
51 nullptr /* ignore error */); 62 nullptr /* ignore error */);
52 } else { 63 } else {
53 return extension_->permissions_data()->GetContentScriptAccess( 64 return extension_->permissions_data()->GetContentScriptAccess(
54 extension_.get(), 65 extension_,
55 document_url, 66 document_url,
56 top_frame_url, 67 top_frame_url,
57 tab_id, 68 tab_id,
58 -1, // no process id 69 -1, // no process id
59 nullptr /* ignore error */); 70 nullptr /* ignore error */);
60 } 71 }
61 } 72 }
62 73
63 bool ExtensionInjectionHost::ShouldNotifyBrowserOfInjection() const { 74 bool ExtensionInjectionHost::ShouldNotifyBrowserOfInjection() const {
64 // We notify the browser of any injection if the extension has no withheld 75 // We notify the browser of any injection if the extension has no withheld
65 // permissions (i.e., the permissions weren't restricted), but would have 76 // permissions (i.e., the permissions weren't restricted), but would have
66 // otherwise been affected by the scripts-require-action feature. 77 // otherwise been affected by the scripts-require-action feature.
67 return extension_->permissions_data()->withheld_permissions()->IsEmpty() && 78 return extension_->permissions_data()->withheld_permissions()->IsEmpty() &&
68 PermissionsData::ScriptsMayRequireActionForExtension( 79 PermissionsData::ScriptsMayRequireActionForExtension(
69 extension_.get(), 80 extension_,
70 extension_->permissions_data()->active_permissions().get()); 81 extension_->permissions_data()->active_permissions().get());
71 } 82 }
72 83
73 } // namespace extensions 84 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698