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/programmatic_script_injector.h" | 5 #include "extensions/renderer/programmatic_script_injector.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
| 12 #include "content/public/renderer/render_frame.h" | 12 #include "content/public/renderer/render_frame.h" |
| 13 #include "extensions/common/error_utils.h" | 13 #include "extensions/common/error_utils.h" |
| 14 #include "extensions/common/extension_messages.h" | 14 #include "extensions/common/extension_messages.h" |
| 15 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
| 16 #include "extensions/common/permissions/api_permission.h" | 16 #include "extensions/common/permissions/api_permission.h" |
| 17 #include "extensions/common/permissions/permissions_data.h" | 17 #include "extensions/common/permissions/permissions_data.h" |
| 18 #include "extensions/renderer/injection_host.h" | 18 #include "extensions/renderer/injection_host.h" |
| 19 #include "extensions/renderer/renderer_extension_registry.h" | 19 #include "extensions/renderer/renderer_extension_registry.h" |
| 20 #include "extensions/renderer/script_context.h" | 20 #include "extensions/renderer/script_context.h" |
| 21 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 22 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 24 #include "third_party/WebKit/public/web/WebScriptSource.h" | 24 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 ProgrammaticScriptInjector::ProgrammaticScriptInjector( | 28 ProgrammaticScriptInjector::ProgrammaticScriptInjector( |
| 29 const ExtensionMsg_ExecuteCode_Params& params, | 29 const ExtensionMsg_ExecuteCode_Params& params) |
| 30 content::RenderFrame* render_frame) | |
| 31 : params_(new ExtensionMsg_ExecuteCode_Params(params)), | 30 : params_(new ExtensionMsg_ExecuteCode_Params(params)), |
| 32 url_( | |
| 33 ScriptContext::GetDataSourceURLForFrame(render_frame->GetWebFrame())), | |
| 34 finished_(false) { | 31 finished_(false) { |
| 35 if (url_.SchemeIs(url::kAboutScheme)) { | |
| 36 origin_for_about_error_ = | |
| 37 render_frame->GetWebFrame()->getSecurityOrigin().toString().utf8(); | |
| 38 } | |
| 39 } | 32 } |
| 40 | 33 |
| 41 ProgrammaticScriptInjector::~ProgrammaticScriptInjector() { | 34 ProgrammaticScriptInjector::~ProgrammaticScriptInjector() { |
| 42 } | 35 } |
| 43 | 36 |
| 44 UserScript::InjectionType ProgrammaticScriptInjector::script_type() | 37 UserScript::InjectionType ProgrammaticScriptInjector::script_type() |
| 45 const { | 38 const { |
| 46 return UserScript::PROGRAMMATIC_SCRIPT; | 39 return UserScript::PROGRAMMATIC_SCRIPT; |
| 47 } | 40 } |
| 48 | 41 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 67 bool ProgrammaticScriptInjector::ShouldInjectCss( | 60 bool ProgrammaticScriptInjector::ShouldInjectCss( |
| 68 UserScript::RunLocation run_location, | 61 UserScript::RunLocation run_location, |
| 69 const std::set<std::string>& injected_stylesheets) const { | 62 const std::set<std::string>& injected_stylesheets) const { |
| 70 return GetRunLocation() == run_location && !params_->is_javascript; | 63 return GetRunLocation() == run_location && !params_->is_javascript; |
| 71 } | 64 } |
| 72 | 65 |
| 73 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( | 66 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( |
| 74 const InjectionHost* injection_host, | 67 const InjectionHost* injection_host, |
| 75 blink::WebLocalFrame* frame, | 68 blink::WebLocalFrame* frame, |
| 76 int tab_id) const { | 69 int tab_id) const { |
| 70 // Note: we calculate url_ now and not in the constructor because with | |
| 71 // PlzNavigate we won't have the URL at that point. | |
| 72 url_ = ScriptContext::GetDataSourceURLForFrame(frame); | |
|
Devlin
2016/11/01 23:39:32
Do we document anywhere at which point we *do* hav
jam
2016/11/01 23:47:03
Sure I'll add a comment here.
| |
| 73 if (url_.SchemeIs(url::kAboutScheme)) { | |
| 74 origin_for_about_error_ = frame->getSecurityOrigin().toString().utf8(); | |
| 75 } | |
| 77 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 76 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
| 78 frame, frame->document().url(), params_->match_about_blank); | 77 frame, frame->document().url(), params_->match_about_blank); |
| 79 if (params_->is_web_view) { | 78 if (params_->is_web_view) { |
| 80 if (frame->parent()) { | 79 if (frame->parent()) { |
| 81 // This is a subframe inside <webview>, so allow it. | 80 // This is a subframe inside <webview>, so allow it. |
| 82 return PermissionsData::ACCESS_ALLOWED; | 81 return PermissionsData::ACCESS_ALLOWED; |
| 83 } | 82 } |
| 84 | 83 |
| 85 return effective_document_url == params_->webview_src | 84 return effective_document_url == params_->webview_src |
| 86 ? PermissionsData::ACCESS_ALLOWED | 85 ? PermissionsData::ACCESS_ALLOWED |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 // frame deletions so nothing is left hanging). | 177 // frame deletions so nothing is left hanging). |
| 179 if (render_frame) { | 178 if (render_frame) { |
| 180 render_frame->Send( | 179 render_frame->Send( |
| 181 new ExtensionHostMsg_ExecuteCodeFinished( | 180 new ExtensionHostMsg_ExecuteCodeFinished( |
| 182 render_frame->GetRoutingID(), params_->request_id, | 181 render_frame->GetRoutingID(), params_->request_id, |
| 183 error, url_, results_)); | 182 error, url_, results_)); |
| 184 } | 183 } |
| 185 } | 184 } |
| 186 | 185 |
| 187 } // namespace extensions | 186 } // namespace extensions |
| OLD | NEW |