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

Side by Side Diff: chrome/renderer/extensions/user_script_slave.cc

Issue 10863002: Added check to prevent extensions from injecting scrips into other extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added test cases for self injection... and failed injection attempt Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/user_script_slave.h" 5 #include "chrome/renderer/extensions/user_script_slave.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 264
265 std::set<std::string> extensions_executing_scripts; 265 std::set<std::string> extensions_executing_scripts;
266 266
267 for (size_t i = 0; i < scripts_.size(); ++i) { 267 for (size_t i = 0; i < scripts_.size(); ++i) {
268 std::vector<WebScriptSource> sources; 268 std::vector<WebScriptSource> sources;
269 UserScript* script = scripts_[i]; 269 UserScript* script = scripts_[i];
270 270
271 if (frame->parent() && !script->match_all_frames()) 271 if (frame->parent() && !script->match_all_frames())
272 continue; // Only match subframes if the script declared it wanted to. 272 continue; // Only match subframes if the script declared it wanted to.
273 273
274 WebFrame* parent_frame = frame;
275 while (parent_frame->parent())
276 parent_frame = parent_frame->parent();
abarth-chromium 2012/08/22 00:54:19 Does WebFrame really not have a top() accessor?
zel 2012/08/22 01:39:20 Done.
277
274 const Extension* extension = extensions_->GetByID(script->extension_id()); 278 const Extension* extension = extensions_->GetByID(script->extension_id());
275 279
276 // Since extension info is sent separately from user script info, they can 280 // Since extension info is sent separately from user script info, they can
277 // be out of sync. We just ignore this situation. 281 // be out of sync. We just ignore this situation.
278 if (!extension) 282 if (!extension)
279 continue; 283 continue;
280 284
281 // Content scripts are not tab-specific. 285 // Content scripts are not tab-specific.
282 int kNoTabId = -1; 286 int kNoTabId = -1;
283 if (!extension->CanExecuteScriptOnPage(data_source_url, 287 if (!extension->CanExecuteScriptOnPage(data_source_url,
288 parent_frame->document().url(),
abarth-chromium 2012/08/22 00:54:19 parent_frame is really the top_frame or what we ca
zel 2012/08/22 01:39:20 used frame->top() accessor instead. done.
284 kNoTabId, 289 kNoTabId,
285 script, 290 script,
286 NULL)) { 291 NULL)) {
287 continue; 292 continue;
288 } 293 }
289 294
290 // We rely on WebCore for CSS injection, but it's still useful to know how 295 // We rely on WebCore for CSS injection, but it's still useful to know how
291 // many css files there are. 296 // many css files there are.
292 if (location == UserScript::DOCUMENT_START) 297 if (location == UserScript::DOCUMENT_START)
293 num_css += script->css_scripts().size(); 298 num_css += script->css_scripts().size();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } else if (location == UserScript::DOCUMENT_IDLE) { 365 } else if (location == UserScript::DOCUMENT_IDLE) {
361 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); 366 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts);
362 if (num_scripts) 367 if (num_scripts)
363 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); 368 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
364 } else { 369 } else {
365 NOTREACHED(); 370 NOTREACHED();
366 } 371 }
367 } 372 }
368 373
369 } // namespace extensions 374 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698