OLD | NEW |
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 Loading... |
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::RequiresActionForScriptExecution( | 157 PermissionsData::ForExtension(extension) |
158 extension, | 158 ->RequiresActionForScriptExecution(extension, |
159 tab_id, | 159 tab_id, |
160 frame->top()->document().url())) { | 160 frame->top()->document().url())) { |
161 int64 request_id = kInvalidRequestId; | 161 int64 request_id = kInvalidRequestId; |
162 int page_id = top_render_view->GetPageId(); | 162 int page_id = top_render_view->GetPageId(); |
163 | 163 |
164 // We only delay the injection if the feature is enabled. | 164 // We only delay the injection if the feature is enabled. |
165 // Otherwise, we simply treat this as a notification by passing an invalid | 165 // Otherwise, we simply treat this as a notification by passing an invalid |
166 // id. | 166 // id. |
167 if (FeatureSwitch::scripts_require_action()->IsEnabled()) { | 167 if (FeatureSwitch::scripts_require_action()->IsEnabled()) { |
168 should_inject = false; | 168 should_inject = false; |
169 ScopedVector<PendingInjection>::iterator pending_injection = | 169 ScopedVector<PendingInjection>::iterator pending_injection = |
170 pending_injections_.insert( | 170 pending_injections_.insert( |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 return false; | 249 return false; |
250 | 250 |
251 // Content scripts are not tab-specific. | 251 // Content scripts are not tab-specific. |
252 static const int kNoTabId = -1; | 252 static const int kNoTabId = -1; |
253 // We don't have a process id in this context. | 253 // We don't have a process id in this context. |
254 static const int kNoProcessId = -1; | 254 static const int kNoProcessId = -1; |
255 | 255 |
256 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 256 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
257 frame, document_url, script_->match_about_blank()); | 257 frame, document_url, script_->match_about_blank()); |
258 | 258 |
259 if (!PermissionsData::CanExecuteScriptOnPage(extension, | 259 if (!PermissionsData::ForExtension(extension) |
260 effective_document_url, | 260 ->CanExecuteScriptOnPage(extension, |
261 frame->top()->document().url(), | 261 effective_document_url, |
262 kNoTabId, | 262 frame->top()->document().url(), |
263 script_.get(), | 263 kNoTabId, |
264 kNoProcessId, | 264 script_.get(), |
265 NULL /* ignore error */)) { | 265 kNoProcessId, |
| 266 NULL /* ignore error */)) { |
266 return false; | 267 return false; |
267 } | 268 } |
268 | 269 |
269 return ShouldInjectCSS(run_location) || ShouldInjectJS(run_location); | 270 return ShouldInjectCSS(run_location) || ShouldInjectJS(run_location); |
270 } | 271 } |
271 | 272 |
272 void ScriptInjection::Inject(blink::WebFrame* frame, | 273 void ScriptInjection::Inject(blink::WebFrame* frame, |
273 UserScript::RunLocation run_location, | 274 UserScript::RunLocation run_location, |
274 ScriptsRunInfo* scripts_run_info) const { | 275 ScriptsRunInfo* scripts_run_info) const { |
275 DCHECK(frame); | 276 DCHECK(frame); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 scripts_run_info->num_css += css_scripts.size(); | 349 scripts_run_info->num_css += css_scripts.size(); |
349 for (UserScript::FileList::const_iterator iter = css_scripts.begin(); | 350 for (UserScript::FileList::const_iterator iter = css_scripts.begin(); |
350 iter != css_scripts.end(); | 351 iter != css_scripts.end(); |
351 ++iter) { | 352 ++iter) { |
352 frame->document().insertStyleSheet( | 353 frame->document().insertStyleSheet( |
353 blink::WebString::fromUTF8(iter->GetContent().as_string())); | 354 blink::WebString::fromUTF8(iter->GetContent().as_string())); |
354 } | 355 } |
355 } | 356 } |
356 | 357 |
357 } // namespace extensions | 358 } // namespace extensions |
OLD | NEW |