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

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

Issue 885493007: Refactoring: de-couple Extensions from "script injection System" [render side] : 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « extensions/renderer/user_script_injector.h ('k') | extensions/renderer/user_script_set.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/user_script_injector.h" 5 #include "extensions/renderer/user_script_injector.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
11 #include "extensions/common/extension.h" 11 #include "extensions/common/extension.h"
12 #include "extensions/common/permissions/permissions_data.h" 12 #include "extensions/common/permissions/permissions_data.h"
13 #include "extensions/renderer/injection_host.h"
13 #include "extensions/renderer/script_context.h" 14 #include "extensions/renderer/script_context.h"
14 #include "extensions/renderer/scripts_run_info.h" 15 #include "extensions/renderer/scripts_run_info.h"
15 #include "grit/extensions_renderer_resources.h" 16 #include "grit/extensions_renderer_resources.h"
16 #include "third_party/WebKit/public/web/WebDocument.h" 17 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebFrame.h" 18 #include "third_party/WebKit/public/web/WebFrame.h"
18 #include "third_party/WebKit/public/web/WebScriptSource.h" 19 #include "third_party/WebKit/public/web/WebScriptSource.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 namespace extensions { 23 namespace extensions {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 !script_->js_scripts().empty(); 116 !script_->js_scripts().empty();
116 } 117 }
117 118
118 bool UserScriptInjector::ShouldInjectCss( 119 bool UserScriptInjector::ShouldInjectCss(
119 UserScript::RunLocation run_location) const { 120 UserScript::RunLocation run_location) const {
120 return run_location == UserScript::DOCUMENT_START && 121 return run_location == UserScript::DOCUMENT_START &&
121 !script_->css_scripts().empty(); 122 !script_->css_scripts().empty();
122 } 123 }
123 124
124 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( 125 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame(
125 const Extension* extension, 126 const InjectionHost* injection_host,
126 blink::WebFrame* web_frame, 127 blink::WebFrame* web_frame,
127 int tab_id, 128 int tab_id,
128 const GURL& top_url) const { 129 const GURL& top_url) const {
129 // If we don't have a tab id, we have no UI surface to ask for user consent. 130 // If we don't have a tab id, we have no UI surface to ask for user consent.
130 // For now, we treat this as an automatic allow. 131 // For now, we treat this as an automatic allow.
131 if (tab_id == -1) 132 if (tab_id == -1)
132 return PermissionsData::ACCESS_ALLOWED; 133 return PermissionsData::ACCESS_ALLOWED;
133 134
134 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 135 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
135 web_frame, web_frame->document().url(), script_->match_about_blank()); 136 web_frame, web_frame->document().url(), script_->match_about_blank());
136 137 return injection_host->CanExecuteOnFrame(
137 // Declarative user scripts use "page access" (from "permissions" section in 138 effective_document_url, top_url, tab_id, is_declarative_);
138 // manifest) whereas non-declarative user scripts use custom
139 // "content script access" logic.
140 if (is_declarative_) {
141 return extension->permissions_data()->GetPageAccess(
142 extension,
143 effective_document_url,
144 top_url,
145 tab_id,
146 -1, // no process id
147 NULL /* ignore error */);
148 } else {
149 return extension->permissions_data()->GetContentScriptAccess(
150 extension,
151 effective_document_url,
152 top_url,
153 tab_id,
154 -1, // no process id
155 NULL /* ignore error */);
156 }
157 } 139 }
158 140
159 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( 141 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
160 UserScript::RunLocation run_location) const { 142 UserScript::RunLocation run_location) const {
161 DCHECK_EQ(script_->run_location(), run_location); 143 DCHECK_EQ(script_->run_location(), run_location);
162 144
163 std::vector<blink::WebScriptSource> sources; 145 std::vector<blink::WebScriptSource> sources;
164 const UserScript::FileList& js_scripts = script_->js_scripts(); 146 const UserScript::FileList& js_scripts = script_->js_scripts();
165 bool is_standalone_or_emulate_greasemonkey = 147 bool is_standalone_or_emulate_greasemonkey =
166 script_->is_standalone() || script_->emulate_greasemonkey(); 148 script_->is_standalone() || script_->emulate_greasemonkey();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 202 }
221 203
222 if (ShouldInjectCss(run_location)) 204 if (ShouldInjectCss(run_location))
223 scripts_run_info->num_css += script_->css_scripts().size(); 205 scripts_run_info->num_css += script_->css_scripts().size();
224 } 206 }
225 207
226 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { 208 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) {
227 } 209 }
228 210
229 } // namespace extensions 211 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/user_script_injector.h ('k') | extensions/renderer/user_script_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698