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 "extensions/renderer/scripts_run_info.h" | |
| 21 #include "third_party/WebKit/public/platform/WebString.h" | 22 #include "third_party/WebKit/public/platform/WebString.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 24 #include "third_party/WebKit/public/web/WebScriptSource.h" | 25 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| 27 | 28 |
| 28 ProgrammaticScriptInjector::ProgrammaticScriptInjector( | 29 ProgrammaticScriptInjector::ProgrammaticScriptInjector( |
| 29 const ExtensionMsg_ExecuteCode_Params& params, | 30 const ExtensionMsg_ExecuteCode_Params& params, |
| 30 content::RenderFrame* render_frame) | 31 content::RenderFrame* render_frame) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 52 | 53 |
| 53 bool ProgrammaticScriptInjector::IsUserGesture() const { | 54 bool ProgrammaticScriptInjector::IsUserGesture() const { |
| 54 return params_->user_gesture; | 55 return params_->user_gesture; |
| 55 } | 56 } |
| 56 | 57 |
| 57 bool ProgrammaticScriptInjector::ExpectsResults() const { | 58 bool ProgrammaticScriptInjector::ExpectsResults() const { |
| 58 return params_->wants_result; | 59 return params_->wants_result; |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool ProgrammaticScriptInjector::ShouldInjectJs( | 62 bool ProgrammaticScriptInjector::ShouldInjectJs( |
| 62 UserScript::RunLocation run_location) const { | 63 UserScript::RunLocation run_location, |
| 63 return GetRunLocation() == run_location && params_->is_javascript; | 64 ScriptsRunInfo* scripts_run_info) const { |
| 65 return GetRunLocation() == run_location && params_->is_javascript && | |
| 66 !scripts_run_info->injected_scripts.empty(); | |
|
Devlin
2016/08/03 23:34:44
This line means that we only inject js if there's
| |
| 64 } | 67 } |
| 65 | 68 |
| 66 bool ProgrammaticScriptInjector::ShouldInjectCss( | 69 bool ProgrammaticScriptInjector::ShouldInjectCss( |
| 67 UserScript::RunLocation run_location) const { | 70 UserScript::RunLocation run_location, |
| 68 return GetRunLocation() == run_location && !params_->is_javascript; | 71 ScriptsRunInfo* scripts_run_info) const { |
| 72 return GetRunLocation() == run_location && !params_->is_javascript && | |
| 73 !scripts_run_info->injected_scripts.empty(); | |
| 69 } | 74 } |
| 70 | 75 |
| 71 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( | 76 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( |
| 72 const InjectionHost* injection_host, | 77 const InjectionHost* injection_host, |
| 73 blink::WebLocalFrame* frame, | 78 blink::WebLocalFrame* frame, |
| 74 int tab_id) const { | 79 int tab_id) const { |
| 75 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 80 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
| 76 frame, frame->document().url(), params_->match_about_blank); | 81 frame, frame->document().url(), params_->match_about_blank); |
| 77 if (params_->is_web_view) { | 82 if (params_->is_web_view) { |
| 78 if (frame->parent()) { | 83 if (frame->parent()) { |
| 79 // This is a subframe inside <webview>, so allow it. | 84 // This is a subframe inside <webview>, so allow it. |
| 80 return PermissionsData::ACCESS_ALLOWED; | 85 return PermissionsData::ACCESS_ALLOWED; |
| 81 } | 86 } |
| 82 | 87 |
| 83 return effective_document_url == params_->webview_src | 88 return effective_document_url == params_->webview_src |
| 84 ? PermissionsData::ACCESS_ALLOWED | 89 ? PermissionsData::ACCESS_ALLOWED |
| 85 : PermissionsData::ACCESS_DENIED; | 90 : PermissionsData::ACCESS_DENIED; |
| 86 } | 91 } |
| 87 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS); | 92 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS); |
| 88 | 93 |
| 89 return injection_host->CanExecuteOnFrame( | 94 return injection_host->CanExecuteOnFrame( |
| 90 effective_document_url, | 95 effective_document_url, |
| 91 content::RenderFrame::FromWebFrame(frame), | 96 content::RenderFrame::FromWebFrame(frame), |
| 92 tab_id, | 97 tab_id, |
| 93 true /* is_declarative */); | 98 true /* is_declarative */); |
| 94 } | 99 } |
| 95 | 100 |
| 96 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( | 101 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( |
| 97 UserScript::RunLocation run_location) const { | 102 UserScript::RunLocation run_location, |
| 103 ScriptsRunInfo* scripts_run_info) const { | |
| 98 DCHECK_EQ(GetRunLocation(), run_location); | 104 DCHECK_EQ(GetRunLocation(), run_location); |
| 99 DCHECK(params_->is_javascript); | 105 DCHECK(params_->is_javascript); |
| 100 | 106 |
| 101 return std::vector<blink::WebScriptSource>( | 107 return std::vector<blink::WebScriptSource>( |
| 102 1, | 108 1, |
| 103 blink::WebScriptSource( | 109 blink::WebScriptSource( |
| 104 blink::WebString::fromUTF8(params_->code), params_->file_url)); | 110 blink::WebString::fromUTF8(params_->code), params_->file_url)); |
| 105 } | 111 } |
| 106 | 112 |
| 107 std::vector<std::string> ProgrammaticScriptInjector::GetCssSources( | 113 std::vector<std::string> ProgrammaticScriptInjector::GetCssSources( |
| 108 UserScript::RunLocation run_location) const { | 114 UserScript::RunLocation run_location, |
| 115 ScriptsRunInfo* scripts_run_info) const { | |
| 109 DCHECK_EQ(GetRunLocation(), run_location); | 116 DCHECK_EQ(GetRunLocation(), run_location); |
| 110 DCHECK(!params_->is_javascript); | 117 DCHECK(!params_->is_javascript); |
| 111 | 118 |
| 112 return std::vector<std::string>(1, params_->code); | 119 return std::vector<std::string>(1, params_->code); |
| 113 } | 120 } |
| 114 | 121 |
| 115 void ProgrammaticScriptInjector::GetRunInfo( | 122 void ProgrammaticScriptInjector::GetRunInfo( |
| 116 ScriptsRunInfo* scripts_run_info, | 123 ScriptsRunInfo* scripts_run_info, |
| 117 UserScript::RunLocation run_location) const { | 124 UserScript::RunLocation run_location) const { |
| 118 } | 125 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 // frame deletions so nothing is left hanging). | 183 // frame deletions so nothing is left hanging). |
| 177 if (render_frame) { | 184 if (render_frame) { |
| 178 render_frame->Send( | 185 render_frame->Send( |
| 179 new ExtensionHostMsg_ExecuteCodeFinished( | 186 new ExtensionHostMsg_ExecuteCodeFinished( |
| 180 render_frame->GetRoutingID(), params_->request_id, | 187 render_frame->GetRoutingID(), params_->request_id, |
| 181 error, url_, results_)); | 188 error, url_, results_)); |
| 182 } | 189 } |
| 183 } | 190 } |
| 184 | 191 |
| 185 } // namespace extensions | 192 } // namespace extensions |
| OLD | NEW |