Chromium Code Reviews| 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/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 "content/public/renderer/render_view.h" | |
| 11 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
| 12 #include "extensions/common/permissions/permissions_data.h" | 13 #include "extensions/common/permissions/permissions_data.h" |
| 13 #include "extensions/renderer/injection_host.h" | 14 #include "extensions/renderer/injection_host.h" |
| 14 #include "extensions/renderer/script_context.h" | 15 #include "extensions/renderer/script_context.h" |
| 15 #include "extensions/renderer/scripts_run_info.h" | 16 #include "extensions/renderer/scripts_run_info.h" |
| 16 #include "grit/extensions_renderer_resources.h" | 17 #include "grit/extensions_renderer_resources.h" |
| 17 #include "third_party/WebKit/public/web/WebDocument.h" | 18 #include "third_party/WebKit/public/web/WebDocument.h" |
| 18 #include "third_party/WebKit/public/web/WebFrame.h" | 19 #include "third_party/WebKit/public/web/WebFrame.h" |
| 19 #include "third_party/WebKit/public/web/WebScriptSource.h" | 20 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 UserScript::RunLocation run_location) const { | 121 UserScript::RunLocation run_location) const { |
| 121 return run_location == UserScript::DOCUMENT_START && | 122 return run_location == UserScript::DOCUMENT_START && |
| 122 !script_->css_scripts().empty(); | 123 !script_->css_scripts().empty(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( | 126 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( |
| 126 const InjectionHost* injection_host, | 127 const InjectionHost* injection_host, |
| 127 blink::WebFrame* web_frame, | 128 blink::WebFrame* web_frame, |
| 128 int tab_id, | 129 int tab_id, |
| 129 const GURL& top_url) const { | 130 const GURL& top_url) const { |
| 130 // If we don't have a tab id, we have no UI surface to ask for user consent. | |
| 131 // For now, we treat this as an automatic allow. | |
| 132 if (tab_id == -1) | |
| 133 return PermissionsData::ACCESS_ALLOWED; | |
| 134 | |
| 135 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 131 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
| 136 web_frame, web_frame->document().url(), script_->match_about_blank()); | 132 web_frame, web_frame->document().url(), script_->match_about_blank()); |
| 137 return injection_host->CanExecuteOnFrame( | 133 PermissionsData::AccessType can_execute = injection_host->CanExecuteOnFrame( |
| 138 effective_document_url, top_url, tab_id, is_declarative_); | 134 effective_document_url, top_url, tab_id, is_declarative_); |
| 135 | |
| 136 if (script_->consumer_instance_type() != | |
| 137 UserScript::ConsumerInstanceType::WEBVIEW || | |
|
Devlin
2015/03/02 20:22:42
This seems very wrong. Why are we automatically d
Xi Han
2015/03/02 20:30:17
Hmm? We didn't deny all extensions injection. The
Devlin
2015/03/02 21:08:14
Huh. I have no idea how I read that so wrong (for
| |
| 138 can_execute == PermissionsData::ACCESS_DENIED) | |
| 139 return can_execute; | |
| 140 | |
| 141 int routing_id = content::RenderView::FromWebView(web_frame->top()->view()) | |
| 142 ->GetRoutingID(); | |
| 143 return script_->routing_info().render_view_id == routing_id | |
| 144 ? PermissionsData::ACCESS_ALLOWED | |
| 145 : PermissionsData::ACCESS_DENIED; | |
| 139 } | 146 } |
| 140 | 147 |
| 141 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( | 148 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |
| 142 UserScript::RunLocation run_location) const { | 149 UserScript::RunLocation run_location) const { |
| 143 DCHECK_EQ(script_->run_location(), run_location); | 150 DCHECK_EQ(script_->run_location(), run_location); |
| 144 | 151 |
| 145 std::vector<blink::WebScriptSource> sources; | 152 std::vector<blink::WebScriptSource> sources; |
| 146 const UserScript::FileList& js_scripts = script_->js_scripts(); | 153 const UserScript::FileList& js_scripts = script_->js_scripts(); |
| 147 bool is_standalone_or_emulate_greasemonkey = | 154 bool is_standalone_or_emulate_greasemonkey = |
| 148 script_->is_standalone() || script_->emulate_greasemonkey(); | 155 script_->is_standalone() || script_->emulate_greasemonkey(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 } | 209 } |
| 203 | 210 |
| 204 if (ShouldInjectCss(run_location)) | 211 if (ShouldInjectCss(run_location)) |
| 205 scripts_run_info->num_css += script_->css_scripts().size(); | 212 scripts_run_info->num_css += script_->css_scripts().size(); |
| 206 } | 213 } |
| 207 | 214 |
| 208 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { | 215 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { |
| 209 } | 216 } |
| 210 | 217 |
| 211 } // namespace extensions | 218 } // namespace extensions |
| OLD | NEW |