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

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

Issue 2213603002: Prevent duplicate content script injection defined in manifest.json (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed lgtm nits Created 4 years, 3 months 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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 bool ProgrammaticScriptInjector::IsUserGesture() const { 53 bool ProgrammaticScriptInjector::IsUserGesture() const {
54 return params_->user_gesture; 54 return params_->user_gesture;
55 } 55 }
56 56
57 bool ProgrammaticScriptInjector::ExpectsResults() const { 57 bool ProgrammaticScriptInjector::ExpectsResults() const {
58 return params_->wants_result; 58 return params_->wants_result;
59 } 59 }
60 60
61 bool ProgrammaticScriptInjector::ShouldInjectJs( 61 bool ProgrammaticScriptInjector::ShouldInjectJs(
62 UserScript::RunLocation run_location) const { 62 UserScript::RunLocation run_location,
63 const std::set<std::string>& executing_scripts) const {
63 return GetRunLocation() == run_location && params_->is_javascript; 64 return GetRunLocation() == run_location && params_->is_javascript;
64 } 65 }
65 66
66 bool ProgrammaticScriptInjector::ShouldInjectCss( 67 bool ProgrammaticScriptInjector::ShouldInjectCss(
67 UserScript::RunLocation run_location) const { 68 UserScript::RunLocation run_location,
69 const std::set<std::string>& injected_stylesheets) const {
68 return GetRunLocation() == run_location && !params_->is_javascript; 70 return GetRunLocation() == run_location && !params_->is_javascript;
69 } 71 }
70 72
71 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( 73 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame(
72 const InjectionHost* injection_host, 74 const InjectionHost* injection_host,
73 blink::WebLocalFrame* frame, 75 blink::WebLocalFrame* frame,
74 int tab_id) const { 76 int tab_id) const {
75 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 77 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
76 frame, frame->document().url(), params_->match_about_blank); 78 frame, frame->document().url(), params_->match_about_blank);
77 if (params_->is_web_view) { 79 if (params_->is_web_view) {
78 if (frame->parent()) { 80 if (frame->parent()) {
79 // This is a subframe inside <webview>, so allow it. 81 // This is a subframe inside <webview>, so allow it.
80 return PermissionsData::ACCESS_ALLOWED; 82 return PermissionsData::ACCESS_ALLOWED;
81 } 83 }
82 84
83 return effective_document_url == params_->webview_src 85 return effective_document_url == params_->webview_src
84 ? PermissionsData::ACCESS_ALLOWED 86 ? PermissionsData::ACCESS_ALLOWED
85 : PermissionsData::ACCESS_DENIED; 87 : PermissionsData::ACCESS_DENIED;
86 } 88 }
87 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS); 89 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS);
88 90
89 return injection_host->CanExecuteOnFrame( 91 return injection_host->CanExecuteOnFrame(
90 effective_document_url, 92 effective_document_url,
91 content::RenderFrame::FromWebFrame(frame), 93 content::RenderFrame::FromWebFrame(frame),
92 tab_id, 94 tab_id,
93 true /* is_declarative */); 95 true /* is_declarative */);
94 } 96 }
95 97
96 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( 98 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources(
97 UserScript::RunLocation run_location) const { 99 UserScript::RunLocation run_location,
100 std::set<std::string>* executing_scripts,
101 size_t* num_injected_js_scripts) const {
98 DCHECK_EQ(GetRunLocation(), run_location); 102 DCHECK_EQ(GetRunLocation(), run_location);
99 DCHECK(params_->is_javascript); 103 DCHECK(params_->is_javascript);
100 104
101 return std::vector<blink::WebScriptSource>( 105 return std::vector<blink::WebScriptSource>(
102 1, 106 1,
103 blink::WebScriptSource( 107 blink::WebScriptSource(
104 blink::WebString::fromUTF8(params_->code), params_->file_url)); 108 blink::WebString::fromUTF8(params_->code), params_->file_url));
105 } 109 }
106 110
107 std::vector<blink::WebString> ProgrammaticScriptInjector::GetCssSources( 111 std::vector<blink::WebString> ProgrammaticScriptInjector::GetCssSources(
108 UserScript::RunLocation run_location) const { 112 UserScript::RunLocation run_location,
113 std::set<std::string>* injected_stylesheets,
114 size_t* num_injected_stylesheets) const {
109 DCHECK_EQ(GetRunLocation(), run_location); 115 DCHECK_EQ(GetRunLocation(), run_location);
110 DCHECK(!params_->is_javascript); 116 DCHECK(!params_->is_javascript);
111 117
112 return std::vector<blink::WebString>( 118 return std::vector<blink::WebString>(
113 1, blink::WebString::fromUTF8(params_->code)); 119 1, blink::WebString::fromUTF8(params_->code));
114 } 120 }
115 121
116 void ProgrammaticScriptInjector::GetRunInfo(
117 ScriptsRunInfo* scripts_run_info,
118 UserScript::RunLocation run_location) const {
119 }
120
121 void ProgrammaticScriptInjector::OnInjectionComplete( 122 void ProgrammaticScriptInjector::OnInjectionComplete(
122 std::unique_ptr<base::Value> execution_result, 123 std::unique_ptr<base::Value> execution_result,
123 UserScript::RunLocation run_location, 124 UserScript::RunLocation run_location,
124 content::RenderFrame* render_frame) { 125 content::RenderFrame* render_frame) {
125 DCHECK(results_.empty()); 126 DCHECK(results_.empty());
126 if (execution_result) 127 if (execution_result)
127 results_.Append(std::move(execution_result)); 128 results_.Append(std::move(execution_result));
128 Finish(std::string(), render_frame); 129 Finish(std::string(), render_frame);
129 } 130 }
130 131
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // frame deletions so nothing is left hanging). 178 // frame deletions so nothing is left hanging).
178 if (render_frame) { 179 if (render_frame) {
179 render_frame->Send( 180 render_frame->Send(
180 new ExtensionHostMsg_ExecuteCodeFinished( 181 new ExtensionHostMsg_ExecuteCodeFinished(
181 render_frame->GetRoutingID(), params_->request_id, 182 render_frame->GetRoutingID(), params_->request_id,
182 error, url_, results_)); 183 error, url_, results_));
183 } 184 }
184 } 185 }
185 186
186 } // namespace extensions 187 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/programmatic_script_injector.h ('k') | extensions/renderer/script_injection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698