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

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

Issue 315573003: Remove PermissionsData::ForExtension() completely (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/user_script_scheduler.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/script_injection.h" 5 #include "extensions/renderer/script_injection.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 "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 int tab_id = ExtensionHelper::Get(top_render_view)->tab_id(); 148 int tab_id = ExtensionHelper::Get(top_render_view)->tab_id();
149 149
150 // By default, we allow injection. 150 // By default, we allow injection.
151 bool should_inject = true; 151 bool should_inject = true;
152 152
153 // Check if the extension requires user consent for injection *and* we have a 153 // Check if the extension requires user consent for injection *and* we have a
154 // valid tab id (if we don't have a tab id, we have no UI surface to ask for 154 // valid tab id (if we don't have a tab id, we have no UI surface to ask for
155 // user consent). 155 // user consent).
156 if (tab_id != -1 && 156 if (tab_id != -1 &&
157 PermissionsData::ForExtension(extension) 157 extension->permissions_data()->RequiresActionForScriptExecution(
158 ->RequiresActionForScriptExecution(extension, 158 extension, tab_id, frame->top()->document().url())) {
159 tab_id,
160 frame->top()->document().url())) {
161 int64 request_id = kInvalidRequestId; 159 int64 request_id = kInvalidRequestId;
162 int page_id = top_render_view->GetPageId(); 160 int page_id = top_render_view->GetPageId();
163 161
164 // We only delay the injection if the feature is enabled. 162 // We only delay the injection if the feature is enabled.
165 // Otherwise, we simply treat this as a notification by passing an invalid 163 // Otherwise, we simply treat this as a notification by passing an invalid
166 // id. 164 // id.
167 if (FeatureSwitch::scripts_require_action()->IsEnabled()) { 165 if (FeatureSwitch::scripts_require_action()->IsEnabled()) {
168 should_inject = false; 166 should_inject = false;
169 ScopedVector<PendingInjection>::iterator pending_injection = 167 ScopedVector<PendingInjection>::iterator pending_injection =
170 pending_injections_.insert( 168 pending_injections_.insert(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 return false; 247 return false;
250 248
251 // Content scripts are not tab-specific. 249 // Content scripts are not tab-specific.
252 static const int kNoTabId = -1; 250 static const int kNoTabId = -1;
253 // We don't have a process id in this context. 251 // We don't have a process id in this context.
254 static const int kNoProcessId = -1; 252 static const int kNoProcessId = -1;
255 253
256 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 254 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
257 frame, document_url, script_->match_about_blank()); 255 frame, document_url, script_->match_about_blank());
258 256
259 if (!PermissionsData::ForExtension(extension) 257 if (!extension->permissions_data()->CanExecuteScriptOnPage(
260 ->CanExecuteScriptOnPage(extension, 258 extension,
261 effective_document_url, 259 effective_document_url,
262 frame->top()->document().url(), 260 frame->top()->document().url(),
263 kNoTabId, 261 kNoTabId,
264 script_.get(), 262 script_.get(),
265 kNoProcessId, 263 kNoProcessId,
266 NULL /* ignore error */)) { 264 NULL /* ignore error */)) {
267 return false; 265 return false;
268 } 266 }
269 267
270 return ShouldInjectCSS(run_location) || ShouldInjectJS(run_location); 268 return ShouldInjectCSS(run_location) || ShouldInjectJS(run_location);
271 } 269 }
272 270
273 void ScriptInjection::Inject(blink::WebFrame* frame, 271 void ScriptInjection::Inject(blink::WebFrame* frame,
274 UserScript::RunLocation run_location, 272 UserScript::RunLocation run_location,
275 ScriptsRunInfo* scripts_run_info) const { 273 ScriptsRunInfo* scripts_run_info) const {
276 DCHECK(frame); 274 DCHECK(frame);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 scripts_run_info->num_css += css_scripts.size(); 347 scripts_run_info->num_css += css_scripts.size();
350 for (UserScript::FileList::const_iterator iter = css_scripts.begin(); 348 for (UserScript::FileList::const_iterator iter = css_scripts.begin();
351 iter != css_scripts.end(); 349 iter != css_scripts.end();
352 ++iter) { 350 ++iter) {
353 frame->document().insertStyleSheet( 351 frame->document().insertStyleSheet(
354 blink::WebString::fromUTF8(iter->GetContent().as_string())); 352 blink::WebString::fromUTF8(iter->GetContent().as_string()));
355 } 353 }
356 } 354 }
357 355
358 } // namespace extensions 356 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | extensions/renderer/user_script_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698