Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: extensions/renderer/programmatic_script_injector.cc

Issue 2471553003: Fix content script injection not working with PlzNavigate because of different navigation timings. (Closed)
Patch Set: review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 17 matching lines...) Expand all
66 59
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) {
70 // Note: we calculate url_ now and not in the constructor because with
71 // PlzNavigate we won't have the URL at that point if the location is
72 // UserScript::DOCUMENT_START. It needs to be at least past
73 // UserScript::DOCUMENT_END.
Devlin 2016/11/02 00:02:57 I'm confused - how would we inject at document sta
jam 2016/11/02 00:14:43 I was trying to mean that on construction of this
74 url_ = ScriptContext::GetDataSourceURLForFrame(frame);
75 if (url_.SchemeIs(url::kAboutScheme)) {
76 origin_for_about_error_ = frame->getSecurityOrigin().toString().utf8();
77 }
77 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 78 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
78 frame, frame->document().url(), params_->match_about_blank); 79 frame, frame->document().url(), params_->match_about_blank);
79 if (params_->is_web_view) { 80 if (params_->is_web_view) {
80 if (frame->parent()) { 81 if (frame->parent()) {
81 // This is a subframe inside <webview>, so allow it. 82 // This is a subframe inside <webview>, so allow it.
82 return PermissionsData::ACCESS_ALLOWED; 83 return PermissionsData::ACCESS_ALLOWED;
83 } 84 }
84 85
85 return effective_document_url == params_->webview_src 86 return effective_document_url == params_->webview_src
86 ? PermissionsData::ACCESS_ALLOWED 87 ? PermissionsData::ACCESS_ALLOWED
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // frame deletions so nothing is left hanging). 179 // frame deletions so nothing is left hanging).
179 if (render_frame) { 180 if (render_frame) {
180 render_frame->Send( 181 render_frame->Send(
181 new ExtensionHostMsg_ExecuteCodeFinished( 182 new ExtensionHostMsg_ExecuteCodeFinished(
182 render_frame->GetRoutingID(), params_->request_id, 183 render_frame->GetRoutingID(), params_->request_id,
183 error, url_, results_)); 184 error, url_, results_));
184 } 185 }
185 } 186 }
186 187
187 } // namespace extensions 188 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/programmatic_script_injector.h ('k') | extensions/renderer/script_injection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698