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

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

Issue 8659009: Consider the origin when computing extension permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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
« no previous file with comments | « chrome/renderer/extensions/user_script_slave.h ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 script->match_all_frames() ? 223 script->match_all_frames() ?
224 WebView::UserContentInjectInAllFrames : 224 WebView::UserContentInjectInAllFrames :
225 WebView::UserContentInjectInTopFrameOnly, 225 WebView::UserContentInjectInTopFrameOnly,
226 WebView::UserStyleInjectInExistingDocuments); 226 WebView::UserStyleInjectInExistingDocuments);
227 } 227 }
228 } 228 }
229 229
230 return true; 230 return true;
231 } 231 }
232 232
233 GURL UserScriptSlave::GetLatestURLForFrame(WebFrame* frame) { 233 GURL UserScriptSlave::GetDataSourceURLForFrame(WebFrame* frame) {
234 // Normally we would use frame->document().url() to determine the document's 234 // Normally we would use frame->document().url() to determine the document's
235 // URL, but to decide whether to inject a content script, we use the URL from 235 // URL, but to decide whether to inject a content script, we use the URL from
236 // the data source. This "quirk" helps prevents content scripts from 236 // the data source. This "quirk" helps prevents content scripts from
237 // inadvertently adding DOM elements to the compose iframe in Gmail because 237 // inadvertently adding DOM elements to the compose iframe in Gmail because
238 // the compose iframe's dataSource URL is about:blank, but the document URL 238 // the compose iframe's dataSource URL is about:blank, but the document URL
239 // changes to match the parent document after Gmail document.writes into 239 // changes to match the parent document after Gmail document.writes into
240 // it to create the editor. 240 // it to create the editor.
241 // http://code.google.com/p/chromium/issues/detail?id=86742 241 // http://code.google.com/p/chromium/issues/detail?id=86742
242 WebKit::WebDataSource* data_source = frame->provisionalDataSource() ? 242 WebKit::WebDataSource* data_source = frame->provisionalDataSource() ?
243 frame->provisionalDataSource() : frame->dataSource(); 243 frame->provisionalDataSource() : frame->dataSource();
244 CHECK(data_source); 244 CHECK(data_source);
245 return GURL(data_source->request().url()); 245 return GURL(data_source->request().url());
246 } 246 }
247 247
248 void UserScriptSlave::InjectScripts(WebFrame* frame, 248 void UserScriptSlave::InjectScripts(WebFrame* frame,
249 UserScript::RunLocation location) { 249 UserScript::RunLocation location) {
250 GURL data_source_url = GetLatestURLForFrame(frame); 250 GURL data_source_url = GetDataSourceURLForFrame(frame);
251 if (data_source_url.is_empty()) 251 if (data_source_url.is_empty())
252 return; 252 return;
253 253
254 if (frame->isViewSourceModeEnabled()) 254 if (frame->isViewSourceModeEnabled())
255 data_source_url = GURL(chrome::kViewSourceScheme + std::string(":") + 255 data_source_url = GURL(chrome::kViewSourceScheme + std::string(":") +
256 data_source_url.spec()); 256 data_source_url.spec());
257 257
258 PerfTimer timer; 258 PerfTimer timer;
259 int num_css = 0; 259 int num_css = 0;
260 int num_scripts = 0; 260 int num_scripts = 0;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (num_scripts) 335 if (num_scripts)
336 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); 336 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed());
337 } else if (location == UserScript::DOCUMENT_IDLE) { 337 } else if (location == UserScript::DOCUMENT_IDLE) {
338 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); 338 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts);
339 if (num_scripts) 339 if (num_scripts)
340 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); 340 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
341 } else { 341 } else {
342 NOTREACHED(); 342 NOTREACHED();
343 } 343 }
344 } 344 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/user_script_slave.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698