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

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

Issue 63273002: Rename WebKit namespace to blink (part 4) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 19 matching lines...) Expand all
30 #include "third_party/WebKit/public/platform/WebVector.h" 30 #include "third_party/WebKit/public/platform/WebVector.h"
31 #include "third_party/WebKit/public/web/WebDataSource.h" 31 #include "third_party/WebKit/public/web/WebDataSource.h"
32 #include "third_party/WebKit/public/web/WebDocument.h" 32 #include "third_party/WebKit/public/web/WebDocument.h"
33 #include "third_party/WebKit/public/web/WebFrame.h" 33 #include "third_party/WebKit/public/web/WebFrame.h"
34 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 34 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
35 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 35 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
36 #include "third_party/WebKit/public/web/WebView.h" 36 #include "third_party/WebKit/public/web/WebView.h"
37 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
38 #include "url/gurl.h" 38 #include "url/gurl.h"
39 39
40 using WebKit::WebFrame; 40 using blink::WebFrame;
41 using WebKit::WebSecurityOrigin; 41 using blink::WebSecurityOrigin;
42 using WebKit::WebSecurityPolicy; 42 using blink::WebSecurityPolicy;
43 using WebKit::WebString; 43 using blink::WebString;
44 using WebKit::WebVector; 44 using blink::WebVector;
45 using WebKit::WebView; 45 using blink::WebView;
46 using content::RenderThread; 46 using content::RenderThread;
47 47
48 namespace extensions { 48 namespace extensions {
49 49
50 // These two strings are injected before and after the Greasemonkey API and 50 // These two strings are injected before and after the Greasemonkey API and
51 // user script to wrap it in an anonymous scope. 51 // user script to wrap it in an anonymous scope.
52 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n"; 52 static const char kUserScriptHead[] = "(function (unsafeWindow) {\n";
53 static const char kUserScriptTail[] = "\n})(window);"; 53 static const char kUserScriptTail[] = "\n})(window);";
54 54
55 int UserScriptSlave::GetIsolatedWorldIdForExtension(const Extension* extension, 55 int UserScriptSlave::GetIsolatedWorldIdForExtension(const Extension* extension,
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 GURL UserScriptSlave::GetDataSourceURLForFrame(const WebFrame* frame) { 242 GURL UserScriptSlave::GetDataSourceURLForFrame(const WebFrame* frame) {
243 // Normally we would use frame->document().url() to determine the document's 243 // Normally we would use frame->document().url() to determine the document's
244 // URL, but to decide whether to inject a content script, we use the URL from 244 // URL, but to decide whether to inject a content script, we use the URL from
245 // the data source. This "quirk" helps prevents content scripts from 245 // the data source. This "quirk" helps prevents content scripts from
246 // inadvertently adding DOM elements to the compose iframe in Gmail because 246 // inadvertently adding DOM elements to the compose iframe in Gmail because
247 // the compose iframe's dataSource URL is about:blank, but the document URL 247 // the compose iframe's dataSource URL is about:blank, but the document URL
248 // changes to match the parent document after Gmail document.writes into 248 // changes to match the parent document after Gmail document.writes into
249 // it to create the editor. 249 // it to create the editor.
250 // http://code.google.com/p/chromium/issues/detail?id=86742 250 // http://code.google.com/p/chromium/issues/detail?id=86742
251 WebKit::WebDataSource* data_source = frame->provisionalDataSource() ? 251 blink::WebDataSource* data_source = frame->provisionalDataSource() ?
252 frame->provisionalDataSource() : frame->dataSource(); 252 frame->provisionalDataSource() : frame->dataSource();
253 CHECK(data_source); 253 CHECK(data_source);
254 return GURL(data_source->request().url()); 254 return GURL(data_source->request().url());
255 } 255 }
256 256
257 void UserScriptSlave::InjectScripts(WebFrame* frame, 257 void UserScriptSlave::InjectScripts(WebFrame* frame,
258 UserScript::RunLocation location) { 258 UserScript::RunLocation location) {
259 GURL data_source_url = GetDataSourceURLForFrame(frame); 259 GURL data_source_url = GetDataSourceURLForFrame(frame);
260 if (data_source_url.is_empty()) 260 if (data_source_url.is_empty())
261 return; 261 return;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 for (std::vector<WebScriptSource>::const_iterator iter = sources.begin(); 342 for (std::vector<WebScriptSource>::const_iterator iter = sources.begin();
343 iter != sources.end(); ++iter) { 343 iter != sources.end(); ++iter) {
344 extensions_executing_scripts[extension->id()].insert( 344 extensions_executing_scripts[extension->id()].insert(
345 GURL(iter->url).path()); 345 GURL(iter->url).path());
346 } 346 }
347 } 347 }
348 } 348 }
349 349
350 // Notify the browser if any extensions are now executing scripts. 350 // Notify the browser if any extensions are now executing scripts.
351 if (!extensions_executing_scripts.empty()) { 351 if (!extensions_executing_scripts.empty()) {
352 WebKit::WebFrame* top_frame = frame->top(); 352 blink::WebFrame* top_frame = frame->top();
353 content::RenderView* render_view = 353 content::RenderView* render_view =
354 content::RenderView::FromWebView(top_frame->view()); 354 content::RenderView::FromWebView(top_frame->view());
355 render_view->Send(new ExtensionHostMsg_ContentScriptsExecuting( 355 render_view->Send(new ExtensionHostMsg_ContentScriptsExecuting(
356 render_view->GetRoutingID(), 356 render_view->GetRoutingID(),
357 extensions_executing_scripts, 357 extensions_executing_scripts,
358 render_view->GetPageId(), 358 render_view->GetPageId(),
359 GetDataSourceURLForFrame(top_frame))); 359 GetDataSourceURLForFrame(top_frame)));
360 } 360 }
361 361
362 // Log debug info. 362 // Log debug info.
363 if (location == UserScript::DOCUMENT_START) { 363 if (location == UserScript::DOCUMENT_START) {
364 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_CssCount", num_css); 364 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_CssCount", num_css);
365 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_ScriptCount", num_scripts); 365 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_ScriptCount", num_scripts);
366 if (num_css || num_scripts) 366 if (num_css || num_scripts)
367 UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer.Elapsed()); 367 UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer.Elapsed());
368 } else if (location == UserScript::DOCUMENT_END) { 368 } else if (location == UserScript::DOCUMENT_END) {
369 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_ScriptCount", num_scripts); 369 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectEnd_ScriptCount", num_scripts);
370 if (num_scripts) 370 if (num_scripts)
371 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); 371 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed());
372 } else if (location == UserScript::DOCUMENT_IDLE) { 372 } else if (location == UserScript::DOCUMENT_IDLE) {
373 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); 373 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts);
374 if (num_scripts) 374 if (num_scripts)
375 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); 375 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed());
376 } else { 376 } else {
377 NOTREACHED(); 377 NOTREACHED();
378 } 378 }
379 } 379 }
380 380
381 } // namespace extensions 381 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/user_script_slave.h ('k') | chrome/renderer/extensions/webstore_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698