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

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

Issue 2089333002: [Extensions] Add renderer-side logic to short circuit activity logging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/user_script_set.h" 5 #include "extensions/renderer/user_script_set.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 continue; 63 continue;
64 DCHECK(!script->extension_id().empty()); 64 DCHECK(!script->extension_id().empty());
65 ids->insert(script->extension_id()); 65 ids->insert(script->extension_id());
66 } 66 }
67 } 67 }
68 68
69 void UserScriptSet::GetInjections( 69 void UserScriptSet::GetInjections(
70 std::vector<std::unique_ptr<ScriptInjection>>* injections, 70 std::vector<std::unique_ptr<ScriptInjection>>* injections,
71 content::RenderFrame* render_frame, 71 content::RenderFrame* render_frame,
72 int tab_id, 72 int tab_id,
73 UserScript::RunLocation run_location) { 73 UserScript::RunLocation run_location,
74 bool log_activity) {
74 GURL document_url = GetDocumentUrlForFrame(render_frame->GetWebFrame()); 75 GURL document_url = GetDocumentUrlForFrame(render_frame->GetWebFrame());
75 for (const UserScript* script : scripts_) { 76 for (const UserScript* script : scripts_) {
76 std::unique_ptr<ScriptInjection> injection = 77 std::unique_ptr<ScriptInjection> injection = GetInjectionForScript(
77 GetInjectionForScript(script, render_frame, tab_id, run_location, 78 script, render_frame, tab_id, run_location, document_url,
78 document_url, false /* is_declarative */); 79 false /* is_declarative */, log_activity);
79 if (injection.get()) 80 if (injection.get())
80 injections->push_back(std::move(injection)); 81 injections->push_back(std::move(injection));
81 } 82 }
82 } 83 }
83 84
84 bool UserScriptSet::UpdateUserScripts(base::SharedMemoryHandle shared_memory, 85 bool UserScriptSet::UpdateUserScripts(base::SharedMemoryHandle shared_memory,
85 const std::set<HostID>& changed_hosts, 86 const std::set<HostID>& changed_hosts,
86 bool whitelisted_only) { 87 bool whitelisted_only) {
87 bool only_inject_incognito = 88 bool only_inject_incognito =
88 ExtensionsRendererClient::Get()->IsIncognitoProcess(); 89 ExtensionsRendererClient::Get()->IsIncognitoProcess();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 observers_, 154 observers_,
154 OnUserScriptsUpdated(changed_hosts, scripts_.get())); 155 OnUserScriptsUpdated(changed_hosts, scripts_.get()));
155 return true; 156 return true;
156 } 157 }
157 158
158 std::unique_ptr<ScriptInjection> UserScriptSet::GetDeclarativeScriptInjection( 159 std::unique_ptr<ScriptInjection> UserScriptSet::GetDeclarativeScriptInjection(
159 int script_id, 160 int script_id,
160 content::RenderFrame* render_frame, 161 content::RenderFrame* render_frame,
161 int tab_id, 162 int tab_id,
162 UserScript::RunLocation run_location, 163 UserScript::RunLocation run_location,
163 const GURL& document_url) { 164 const GURL& document_url,
165 bool log_activity) {
164 for (const UserScript* script : scripts_) { 166 for (const UserScript* script : scripts_) {
165 if (script->id() == script_id) { 167 if (script->id() == script_id) {
166 return GetInjectionForScript(script, 168 return GetInjectionForScript(script, render_frame, tab_id, run_location,
167 render_frame, 169 document_url, true /* is_declarative */,
168 tab_id, 170 log_activity);
169 run_location,
170 document_url,
171 true /* is_declarative */);
172 } 171 }
173 } 172 }
174 return std::unique_ptr<ScriptInjection>(); 173 return std::unique_ptr<ScriptInjection>();
175 } 174 }
176 175
177 std::unique_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript( 176 std::unique_ptr<ScriptInjection> UserScriptSet::GetInjectionForScript(
178 const UserScript* script, 177 const UserScript* script,
179 content::RenderFrame* render_frame, 178 content::RenderFrame* render_frame,
180 int tab_id, 179 int tab_id,
181 UserScript::RunLocation run_location, 180 UserScript::RunLocation run_location,
182 const GURL& document_url, 181 const GURL& document_url,
183 bool is_declarative) { 182 bool is_declarative,
183 bool log_activity) {
184 std::unique_ptr<ScriptInjection> injection; 184 std::unique_ptr<ScriptInjection> injection;
185 std::unique_ptr<const InjectionHost> injection_host; 185 std::unique_ptr<const InjectionHost> injection_host;
186 blink::WebLocalFrame* web_frame = render_frame->GetWebFrame(); 186 blink::WebLocalFrame* web_frame = render_frame->GetWebFrame();
187 187
188 const HostID& host_id = script->host_id(); 188 const HostID& host_id = script->host_id();
189 if (host_id.type() == HostID::EXTENSIONS) { 189 if (host_id.type() == HostID::EXTENSIONS) {
190 injection_host = ExtensionInjectionHost::Create(host_id.id()); 190 injection_host = ExtensionInjectionHost::Create(host_id.id());
191 if (!injection_host) 191 if (!injection_host)
192 return injection; 192 return injection;
193 } else { 193 } else {
(...skipping 20 matching lines...) Expand all
214 PermissionsData::ACCESS_DENIED) { 214 PermissionsData::ACCESS_DENIED) {
215 return injection; 215 return injection;
216 } 216 }
217 217
218 bool inject_css = !script->css_scripts().empty() && 218 bool inject_css = !script->css_scripts().empty() &&
219 run_location == UserScript::DOCUMENT_START; 219 run_location == UserScript::DOCUMENT_START;
220 bool inject_js = 220 bool inject_js =
221 !script->js_scripts().empty() && script->run_location() == run_location; 221 !script->js_scripts().empty() && script->run_location() == run_location;
222 if (inject_css || inject_js) { 222 if (inject_css || inject_js) {
223 injection.reset(new ScriptInjection(std::move(injector), render_frame, 223 injection.reset(new ScriptInjection(std::move(injector), render_frame,
224 std::move(injection_host), 224 std::move(injection_host), run_location,
225 run_location)); 225 log_activity));
226 } 226 }
227 return injection; 227 return injection;
228 } 228 }
229 229
230 } // namespace extensions 230 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698