OLD | NEW |
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/scripts_run_info.h" | 5 #include "extensions/renderer/scripts_run_info.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "content/public/renderer/render_frame.h" | 8 #include "content/public/renderer/render_frame.h" |
| 9 #include "content/public/renderer/render_thread.h" |
9 #include "extensions/common/extension_messages.h" | 10 #include "extensions/common/extension_messages.h" |
10 #include "extensions/renderer/script_context.h" | 11 #include "extensions/renderer/script_context.h" |
11 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 12 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 | 15 |
15 ScriptsRunInfo::ScriptsRunInfo() | 16 ScriptsRunInfo::ScriptsRunInfo(content::RenderFrame* render_frame, |
16 : num_css(0u), num_js(0u), num_blocking_js(0u) { | 17 UserScript::RunLocation location) |
| 18 : num_css(0u), |
| 19 num_js(0u), |
| 20 num_blocking_js(0u), |
| 21 routing_id_(render_frame->GetRoutingID()), |
| 22 run_location_(location), |
| 23 frame_url_(ScriptContext::GetDataSourceURLForFrame( |
| 24 render_frame->GetWebFrame())) { |
17 } | 25 } |
18 | 26 |
19 ScriptsRunInfo::~ScriptsRunInfo() { | 27 ScriptsRunInfo::~ScriptsRunInfo() { |
20 } | 28 } |
21 | 29 |
22 void ScriptsRunInfo::LogRun(blink::WebLocalFrame* frame, | 30 void ScriptsRunInfo::LogRun() { |
23 UserScript::RunLocation location) { | |
24 // Notify the browser if any extensions are now executing scripts. | 31 // Notify the browser if any extensions are now executing scripts. |
25 if (!executing_scripts.empty()) { | 32 if (!executing_scripts.empty()) { |
26 content::RenderFrame* render_frame = | 33 content::RenderThread::Get()->Send( |
27 content::RenderFrame::FromWebFrame(frame); | 34 new ExtensionHostMsg_ContentScriptsExecuting( |
28 render_frame->Send(new ExtensionHostMsg_ContentScriptsExecuting( | 35 routing_id_, executing_scripts, frame_url_)); |
29 render_frame->GetRoutingID(), | |
30 executing_scripts, | |
31 ScriptContext::GetDataSourceURLForFrame(frame))); | |
32 } | 36 } |
33 | 37 |
34 switch (location) { | 38 switch (run_location_) { |
35 case UserScript::DOCUMENT_START: | 39 case UserScript::DOCUMENT_START: |
36 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_CssCount", num_css); | 40 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_CssCount", num_css); |
37 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_ScriptCount", num_js); | 41 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_ScriptCount", num_js); |
38 if (num_blocking_js) { | 42 if (num_blocking_js) { |
39 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_BlockingScriptCount", | 43 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectStart_BlockingScriptCount", |
40 num_blocking_js); | 44 num_blocking_js); |
41 } else if (num_css || num_js) { | 45 } else if (num_css || num_js) { |
42 UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer.Elapsed()); | 46 UMA_HISTOGRAM_TIMES("Extensions.InjectStart_Time", timer.Elapsed()); |
43 } | 47 } |
44 break; | 48 break; |
(...skipping 19 matching lines...) Expand all Loading... |
64 case UserScript::BROWSER_DRIVEN: | 68 case UserScript::BROWSER_DRIVEN: |
65 // TODO(rdevlin.cronin): Add histograms. | 69 // TODO(rdevlin.cronin): Add histograms. |
66 break; | 70 break; |
67 case UserScript::UNDEFINED: | 71 case UserScript::UNDEFINED: |
68 case UserScript::RUN_LOCATION_LAST: | 72 case UserScript::RUN_LOCATION_LAST: |
69 NOTREACHED(); | 73 NOTREACHED(); |
70 } | 74 } |
71 } | 75 } |
72 | 76 |
73 } // namespace extensions | 77 } // namespace extensions |
OLD | NEW |