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

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

Issue 1030323003: [Extensions] Don't inject scripts into remote frames, null documents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « extensions/renderer/programmatic_script_injector.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "content/public/common/url_constants.h" 8 #include "content/public/common/url_constants.h"
9 #include "content/public/renderer/render_thread.h" 9 #include "content/public/renderer/render_thread.h"
10 #include "extensions/common/extension.h" 10 #include "extensions/common/extension.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 198 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
199 web_frame, document_url, script->match_about_blank()); 199 web_frame, document_url, script->match_about_blank());
200 200
201 if (!script->MatchesURL(effective_document_url)) 201 if (!script->MatchesURL(effective_document_url))
202 return injection.Pass(); 202 return injection.Pass();
203 203
204 scoped_ptr<ScriptInjector> injector(new UserScriptInjector(script, 204 scoped_ptr<ScriptInjector> injector(new UserScriptInjector(script,
205 this, 205 this,
206 is_declarative)); 206 is_declarative));
207 207
208 blink::WebDocument top_document = web_frame->top()->document(); 208 blink::WebFrame* top_frame = web_frame->top();
209 // This can be null if site isolation is turned on. The best we can do is to 209 // It doesn't make sense to do script injection for remote frames, since they
210 // just give up - generally the wrong behavior, but better than crashing. 210 // cannot host any documents or content.
211 // TODO(kalman): Fix this properly by moving all security checks into the 211 // TODO(kalman): Fix this properly by moving all security checks into the
212 // browser. See http://crbug.com/466373 for ongoing work here. 212 // browser. See http://crbug.com/466373 for ongoing work here.
213 if (top_document.isNull()) 213 if (top_frame->isWebRemoteFrame())
214 return injection.Pass(); 214 return injection.Pass();
215 215
216 if (injector->CanExecuteOnFrame(injection_host.get(), web_frame, 216 if (injector->CanExecuteOnFrame(injection_host.get(), web_frame,
217 -1, // Content scripts are not tab-specific. 217 -1, // Content scripts are not tab-specific.
218 top_document.url()) == 218 top_frame->document().url()) ==
219 PermissionsData::ACCESS_DENIED) { 219 PermissionsData::ACCESS_DENIED) {
220 return injection.Pass(); 220 return injection.Pass();
221 } 221 }
222 222
223 bool inject_css = !script->css_scripts().empty() && 223 bool inject_css = !script->css_scripts().empty() &&
224 run_location == UserScript::DOCUMENT_START; 224 run_location == UserScript::DOCUMENT_START;
225 bool inject_js = 225 bool inject_js =
226 !script->js_scripts().empty() && script->run_location() == run_location; 226 !script->js_scripts().empty() && script->run_location() == run_location;
227 if (inject_css || inject_js) { 227 if (inject_css || inject_js) {
228 injection.reset(new ScriptInjection( 228 injection.reset(new ScriptInjection(
229 injector.Pass(), 229 injector.Pass(),
230 web_frame->toWebLocalFrame(), 230 web_frame->toWebLocalFrame(),
231 injection_host.Pass(), 231 injection_host.Pass(),
232 run_location, 232 run_location,
233 tab_id)); 233 tab_id));
234 } 234 }
235 return injection.Pass(); 235 return injection.Pass();
236 } 236 }
237 237
238 } // namespace extensions 238 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/programmatic_script_injector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698