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: Rebased with origin 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"
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"
Devlin 2016/09/08 17:47:31 not needed
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
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,
64 const std::set<std::string>& executing_scripts) const {
63 return GetRunLocation() == run_location && params_->is_javascript; 65 return GetRunLocation() == run_location && params_->is_javascript;
64 } 66 }
65 67
66 bool ProgrammaticScriptInjector::ShouldInjectCss( 68 bool ProgrammaticScriptInjector::ShouldInjectCss(
67 UserScript::RunLocation run_location) const { 69 UserScript::RunLocation run_location,
70 const std::set<std::string>& injected_stylesheets) const {
68 return GetRunLocation() == run_location && !params_->is_javascript; 71 return GetRunLocation() == run_location && !params_->is_javascript;
69 } 72 }
70 73
71 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame( 74 PermissionsData::AccessType ProgrammaticScriptInjector::CanExecuteOnFrame(
72 const InjectionHost* injection_host, 75 const InjectionHost* injection_host,
73 blink::WebLocalFrame* frame, 76 blink::WebLocalFrame* frame,
74 int tab_id) const { 77 int tab_id) const {
75 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 78 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
76 frame, frame->document().url(), params_->match_about_blank); 79 frame, frame->document().url(), params_->match_about_blank);
77 if (params_->is_web_view) { 80 if (params_->is_web_view) {
78 if (frame->parent()) { 81 if (frame->parent()) {
79 // This is a subframe inside <webview>, so allow it. 82 // This is a subframe inside <webview>, so allow it.
80 return PermissionsData::ACCESS_ALLOWED; 83 return PermissionsData::ACCESS_ALLOWED;
81 } 84 }
82 85
83 return effective_document_url == params_->webview_src 86 return effective_document_url == params_->webview_src
84 ? PermissionsData::ACCESS_ALLOWED 87 ? PermissionsData::ACCESS_ALLOWED
85 : PermissionsData::ACCESS_DENIED; 88 : PermissionsData::ACCESS_DENIED;
86 } 89 }
87 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS); 90 DCHECK_EQ(injection_host->id().type(), HostID::EXTENSIONS);
88 91
89 return injection_host->CanExecuteOnFrame( 92 return injection_host->CanExecuteOnFrame(
90 effective_document_url, 93 effective_document_url,
91 content::RenderFrame::FromWebFrame(frame), 94 content::RenderFrame::FromWebFrame(frame),
92 tab_id, 95 tab_id,
93 true /* is_declarative */); 96 true /* is_declarative */);
94 } 97 }
95 98
96 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources( 99 std::vector<blink::WebScriptSource> ProgrammaticScriptInjector::GetJsSources(
97 UserScript::RunLocation run_location) const { 100 UserScript::RunLocation run_location,
101 std::set<std::string>* executing_scripts,
102 size_t* num_injected_js_scripts) const {
98 DCHECK_EQ(GetRunLocation(), run_location); 103 DCHECK_EQ(GetRunLocation(), run_location);
99 DCHECK(params_->is_javascript); 104 DCHECK(params_->is_javascript);
100 105
101 return std::vector<blink::WebScriptSource>( 106 return std::vector<blink::WebScriptSource>(
102 1, 107 1,
103 blink::WebScriptSource( 108 blink::WebScriptSource(
104 blink::WebString::fromUTF8(params_->code), params_->file_url)); 109 blink::WebString::fromUTF8(params_->code), params_->file_url));
105 } 110 }
106 111
107 std::vector<blink::WebString> ProgrammaticScriptInjector::GetCssSources( 112 std::vector<blink::WebString> ProgrammaticScriptInjector::GetCssSources(
108 UserScript::RunLocation run_location) const { 113 UserScript::RunLocation run_location,
114 std::set<std::string>* injected_stylesheets,
115 size_t* num_injected_stylesheets) 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<blink::WebString>( 119 return std::vector<blink::WebString>(
113 1, blink::WebString::fromUTF8(params_->code)); 120 1, blink::WebString::fromUTF8(params_->code));
114 } 121 }
115 122
116 void ProgrammaticScriptInjector::GetRunInfo(
117 ScriptsRunInfo* scripts_run_info,
118 UserScript::RunLocation run_location) const {
119 }
120
121 void ProgrammaticScriptInjector::OnInjectionComplete( 123 void ProgrammaticScriptInjector::OnInjectionComplete(
122 std::unique_ptr<base::Value> execution_result, 124 std::unique_ptr<base::Value> execution_result,
123 UserScript::RunLocation run_location, 125 UserScript::RunLocation run_location,
124 content::RenderFrame* render_frame) { 126 content::RenderFrame* render_frame) {
125 DCHECK(results_.empty()); 127 DCHECK(results_.empty());
126 if (execution_result) 128 if (execution_result)
127 results_.Append(std::move(execution_result)); 129 results_.Append(std::move(execution_result));
128 Finish(std::string(), render_frame); 130 Finish(std::string(), render_frame);
129 } 131 }
130 132
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // frame deletions so nothing is left hanging). 179 // frame deletions so nothing is left hanging).
178 if (render_frame) { 180 if (render_frame) {
179 render_frame->Send( 181 render_frame->Send(
180 new ExtensionHostMsg_ExecuteCodeFinished( 182 new ExtensionHostMsg_ExecuteCodeFinished(
181 render_frame->GetRoutingID(), params_->request_id, 183 render_frame->GetRoutingID(), params_->request_id,
182 error, url_, results_)); 184 error, url_, results_));
183 } 185 }
184 } 186 }
185 187
186 } // namespace extensions 188 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698