| 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" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 bool UserScriptInjector::ShouldInjectCss( | 147 bool UserScriptInjector::ShouldInjectCss( |
| 148 UserScript::RunLocation run_location) const { | 148 UserScript::RunLocation run_location) const { |
| 149 return run_location == UserScript::DOCUMENT_START && | 149 return run_location == UserScript::DOCUMENT_START && |
| 150 !script_->css_scripts().empty(); | 150 !script_->css_scripts().empty(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( | 153 PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( |
| 154 const InjectionHost* injection_host, | 154 const InjectionHost* injection_host, |
| 155 blink::WebLocalFrame* web_frame, | 155 blink::WebLocalFrame* web_frame, |
| 156 int tab_id) const { | 156 int tab_id) const { |
| 157 if (script_->consumer_instance_type() == |
| 158 UserScript::ConsumerInstanceType::WEBVIEW) { |
| 159 int routing_id = content::RenderView::FromWebView(web_frame->top()->view()) |
| 160 ->GetRoutingID(); |
| 161 |
| 162 RoutingInfoKey key(routing_id, script_->id()); |
| 163 |
| 164 RoutingInfoMap& map = g_routing_info_map.Get(); |
| 165 auto iter = map.find(key); |
| 166 |
| 167 bool allowed = false; |
| 168 if (iter != map.end()) { |
| 169 allowed = iter->second; |
| 170 } else { |
| 171 // Send a SYNC IPC message to the browser to check if this is allowed. |
| 172 // This is not ideal, but is mitigated by the fact that this is only done |
| 173 // for webviews, and then only once per host. |
| 174 // TODO(hanxi): Find a more efficient way to do this. |
| 175 content::RenderThread::Get()->Send( |
| 176 new ExtensionsGuestViewHostMsg_CanExecuteContentScriptSync( |
| 177 routing_id, script_->id(), &allowed)); |
| 178 map.insert(std::pair<RoutingInfoKey, bool>(key, allowed)); |
| 179 } |
| 180 |
| 181 return allowed ? PermissionsData::ACCESS_ALLOWED |
| 182 : PermissionsData::ACCESS_DENIED; |
| 183 } |
| 184 |
| 157 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 185 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
| 158 web_frame, web_frame->document().url(), script_->match_about_blank()); | 186 web_frame, web_frame->document().url(), script_->match_about_blank()); |
| 159 PermissionsData::AccessType can_execute = injection_host->CanExecuteOnFrame( | 187 |
| 188 return injection_host->CanExecuteOnFrame( |
| 160 effective_document_url, | 189 effective_document_url, |
| 161 content::RenderFrame::FromWebFrame(web_frame), | 190 content::RenderFrame::FromWebFrame(web_frame), |
| 162 tab_id, | 191 tab_id, |
| 163 is_declarative_); | 192 is_declarative_); |
| 164 if (script_->consumer_instance_type() != | |
| 165 UserScript::ConsumerInstanceType::WEBVIEW || | |
| 166 can_execute == PermissionsData::ACCESS_DENIED) | |
| 167 return can_execute; | |
| 168 | |
| 169 int routing_id = content::RenderView::FromWebView(web_frame->top()->view()) | |
| 170 ->GetRoutingID(); | |
| 171 | |
| 172 RoutingInfoKey key(routing_id, script_->id()); | |
| 173 | |
| 174 RoutingInfoMap& map = g_routing_info_map.Get(); | |
| 175 auto iter = map.find(key); | |
| 176 | |
| 177 bool allowed = false; | |
| 178 if (iter != map.end()) { | |
| 179 allowed = iter->second; | |
| 180 } else { | |
| 181 // Send a SYNC IPC message to the browser to check if this is allowed. This | |
| 182 // is not ideal, but is mitigated by the fact that this is only done for | |
| 183 // webviews, and then only once per host. | |
| 184 // TODO(hanxi): Find a more efficient way to do this. | |
| 185 content::RenderThread::Get()->Send( | |
| 186 new ExtensionsGuestViewHostMsg_CanExecuteContentScriptSync( | |
| 187 routing_id, script_->id(), &allowed)); | |
| 188 map.insert(std::pair<RoutingInfoKey, bool>(key, allowed)); | |
| 189 } | |
| 190 | |
| 191 return allowed ? PermissionsData::ACCESS_ALLOWED | |
| 192 : PermissionsData::ACCESS_DENIED; | |
| 193 } | 193 } |
| 194 | 194 |
| 195 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( | 195 std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |
| 196 UserScript::RunLocation run_location) const { | 196 UserScript::RunLocation run_location) const { |
| 197 DCHECK_EQ(script_->run_location(), run_location); | 197 DCHECK_EQ(script_->run_location(), run_location); |
| 198 | 198 |
| 199 std::vector<blink::WebScriptSource> sources; | 199 std::vector<blink::WebScriptSource> sources; |
| 200 const UserScript::FileList& js_scripts = script_->js_scripts(); | 200 const UserScript::FileList& js_scripts = script_->js_scripts(); |
| 201 bool is_standalone_or_emulate_greasemonkey = | 201 bool is_standalone_or_emulate_greasemonkey = |
| 202 script_->is_standalone() || script_->emulate_greasemonkey(); | 202 script_->is_standalone() || script_->emulate_greasemonkey(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 260 |
| 261 void UserScriptInjector::OnInjectionComplete( | 261 void UserScriptInjector::OnInjectionComplete( |
| 262 scoped_ptr<base::Value> execution_result, | 262 scoped_ptr<base::Value> execution_result, |
| 263 UserScript::RunLocation run_location) { | 263 UserScript::RunLocation run_location) { |
| 264 } | 264 } |
| 265 | 265 |
| 266 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { | 266 void UserScriptInjector::OnWillNotInject(InjectFailureReason reason) { |
| 267 } | 267 } |
| 268 | 268 |
| 269 } // namespace extensions | 269 } // namespace extensions |
| OLD | NEW |