OLD | NEW |
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/browser/ui/webui/gpu_internals_ui.h" | 5 #include "chrome/browser/ui/webui/gpu_internals_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chrome/browser/platform_util.h" | 28 #include "chrome/browser/platform_util.h" |
29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/chrome_version_info.h" | 32 #include "chrome/common/chrome_version_info.h" |
33 #include "chrome/common/jstemplate_builder.h" | 33 #include "chrome/common/jstemplate_builder.h" |
34 #include "chrome/common/net/url_request_context_getter.h" | 34 #include "chrome/common/net/url_request_context_getter.h" |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
36 #include "content/browser/browser_thread.h" | 36 #include "content/browser/browser_thread.h" |
37 #include "content/browser/gpu_process_host.h" | 37 #include "content/browser/gpu_process_host.h" |
| 38 #include "content/browser/renderer_host/render_view_host.h" |
38 #include "content/browser/tab_contents/tab_contents.h" | 39 #include "content/browser/tab_contents/tab_contents.h" |
39 #include "grit/browser_resources.h" | 40 #include "grit/browser_resources.h" |
40 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
41 #include "net/base/escape.h" | 42 #include "net/base/escape.h" |
42 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
43 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 class GpuHTMLSource : public ChromeURLDataManager::DataSource { | 48 class GpuHTMLSource : public ChromeURLDataManager::DataSource { |
(...skipping 20 matching lines...) Expand all Loading... |
68 public base::SupportsWeakPtr<GpuMessageHandler> { | 69 public base::SupportsWeakPtr<GpuMessageHandler> { |
69 public: | 70 public: |
70 GpuMessageHandler(); | 71 GpuMessageHandler(); |
71 virtual ~GpuMessageHandler(); | 72 virtual ~GpuMessageHandler(); |
72 | 73 |
73 // WebUIMessageHandler implementation. | 74 // WebUIMessageHandler implementation. |
74 virtual WebUIMessageHandler* Attach(WebUI* web_ui); | 75 virtual WebUIMessageHandler* Attach(WebUI* web_ui); |
75 virtual void RegisterMessages(); | 76 virtual void RegisterMessages(); |
76 | 77 |
77 // Mesages | 78 // Mesages |
| 79 void OnBeginTracing(const ListValue* list); |
| 80 void OnEndTracingAsync(const ListValue* list); |
78 void OnBrowserBridgeInitialized(const ListValue* list); | 81 void OnBrowserBridgeInitialized(const ListValue* list); |
79 void OnCallAsync(const ListValue* list); | 82 void OnCallAsync(const ListValue* list); |
80 | 83 |
81 // Submessages dispatched from OnCallAsync | 84 // Submessages dispatched from OnCallAsync |
82 Value* OnRequestClientInfo(const ListValue* list); | 85 Value* OnRequestClientInfo(const ListValue* list); |
83 Value* OnRequestLogMessages(const ListValue* list); | 86 Value* OnRequestLogMessages(const ListValue* list); |
84 | 87 |
| 88 // Callbacks. |
| 89 void OnTraceDataCollected(const std::string& json_events); |
85 void OnGpuInfoUpdate(); | 90 void OnGpuInfoUpdate(); |
86 | 91 |
87 // Executes the javascript function |function_name| in the renderer, passing | 92 // Executes the javascript function |function_name| in the renderer, passing |
88 // it the argument |value|. | 93 // it the argument |value|. |
89 void CallJavascriptFunction(const std::wstring& function_name, | 94 void CallJavascriptFunction(const std::wstring& function_name, |
90 const Value* value); | 95 const Value* value); |
91 | 96 |
92 private: | 97 private: |
93 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); | 98 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); |
94 | 99 |
95 // Cache the Singleton for efficiency. | 100 // Cache the Singleton for efficiency. |
96 GpuDataManager* gpu_data_manager_; | 101 GpuDataManager* gpu_data_manager_; |
97 | 102 |
| 103 void OnEndTracingComplete(); |
| 104 |
98 Callback0::Type* gpu_info_update_callback_; | 105 Callback0::Type* gpu_info_update_callback_; |
| 106 |
| 107 bool trace_enabled_; |
99 }; | 108 }; |
100 | 109 |
101 //////////////////////////////////////////////////////////////////////////////// | 110 //////////////////////////////////////////////////////////////////////////////// |
102 // | 111 // |
103 // GpuHTMLSource | 112 // GpuHTMLSource |
104 // | 113 // |
105 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
106 | 115 |
107 GpuHTMLSource::GpuHTMLSource() | 116 GpuHTMLSource::GpuHTMLSource() |
108 : DataSource(chrome::kChromeUIGpuInternalsHost, MessageLoop::current()) { | 117 : DataSource(chrome::kChromeUIGpuInternalsHost, MessageLoop::current()) { |
(...skipping 25 matching lines...) Expand all Loading... |
134 std::string GpuHTMLSource::GetMimeType(const std::string&) const { | 143 std::string GpuHTMLSource::GetMimeType(const std::string&) const { |
135 return "text/html"; | 144 return "text/html"; |
136 } | 145 } |
137 | 146 |
138 //////////////////////////////////////////////////////////////////////////////// | 147 //////////////////////////////////////////////////////////////////////////////// |
139 // | 148 // |
140 // GpuMessageHandler | 149 // GpuMessageHandler |
141 // | 150 // |
142 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
143 | 152 |
144 GpuMessageHandler::GpuMessageHandler() : gpu_info_update_callback_(NULL) { | 153 GpuMessageHandler::GpuMessageHandler() |
| 154 : gpu_info_update_callback_(NULL) |
| 155 , trace_enabled_(false) { |
145 gpu_data_manager_ = GpuDataManager::GetInstance(); | 156 gpu_data_manager_ = GpuDataManager::GetInstance(); |
146 DCHECK(gpu_data_manager_); | 157 DCHECK(gpu_data_manager_); |
147 } | 158 } |
148 | 159 |
149 GpuMessageHandler::~GpuMessageHandler() { | 160 GpuMessageHandler::~GpuMessageHandler() { |
150 if (gpu_info_update_callback_) { | 161 if (gpu_info_update_callback_) { |
151 gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); | 162 gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); |
152 delete gpu_info_update_callback_; | 163 delete gpu_info_update_callback_; |
153 } | 164 } |
| 165 |
| 166 if (trace_enabled_) |
| 167 OnEndTracingAsync(NULL); |
154 } | 168 } |
155 | 169 |
156 WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { | 170 WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
158 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); | 172 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); |
159 return result; | 173 return result; |
160 } | 174 } |
161 | 175 |
162 /* BrowserBridge.callAsync prepends a requestID to these messages. */ | 176 /* BrowserBridge.callAsync prepends a requestID to these messages. */ |
163 void GpuMessageHandler::RegisterMessages() { | 177 void GpuMessageHandler::RegisterMessages() { |
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
165 | 179 |
166 web_ui_->RegisterMessageCallback( | 180 web_ui_->RegisterMessageCallback( |
| 181 "beginTracing", |
| 182 NewCallback(this, &GpuMessageHandler::OnBeginTracing)); |
| 183 web_ui_->RegisterMessageCallback( |
| 184 "endTracingAsync", |
| 185 NewCallback(this, &GpuMessageHandler::OnEndTracingAsync)); |
| 186 web_ui_->RegisterMessageCallback( |
167 "browserBridgeInitialized", | 187 "browserBridgeInitialized", |
168 NewCallback(this, &GpuMessageHandler::OnBrowserBridgeInitialized)); | 188 NewCallback(this, &GpuMessageHandler::OnBrowserBridgeInitialized)); |
169 web_ui_->RegisterMessageCallback( | 189 web_ui_->RegisterMessageCallback( |
170 "callAsync", | 190 "callAsync", |
171 NewCallback(this, &GpuMessageHandler::OnCallAsync)); | 191 NewCallback(this, &GpuMessageHandler::OnCallAsync)); |
172 } | 192 } |
173 | 193 |
174 void GpuMessageHandler::OnCallAsync(const ListValue* args) { | 194 void GpuMessageHandler::OnCallAsync(const ListValue* args) { |
175 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); | 195 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); |
176 // unpack args into requestId, submessage and submessageArgs | 196 // unpack args into requestId, submessage and submessageArgs |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 if (blacklisting_reasons) | 381 if (blacklisting_reasons) |
362 gpu_info_val->Set("blacklistingReasons", blacklisting_reasons); | 382 gpu_info_val->Set("blacklistingReasons", blacklisting_reasons); |
363 | 383 |
364 // Send GPU Info to javascript. | 384 // Send GPU Info to javascript. |
365 web_ui_->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", | 385 web_ui_->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", |
366 *gpu_info_val); | 386 *gpu_info_val); |
367 | 387 |
368 delete gpu_info_val; | 388 delete gpu_info_val; |
369 } | 389 } |
370 | 390 |
| 391 void GpuMessageHandler::OnBeginTracing(const ListValue* args) { |
| 392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 393 |
| 394 trace_enabled_ = true; |
| 395 // TODO(jbates): TracingController::BeginTracing() |
| 396 } |
| 397 |
| 398 void GpuMessageHandler::OnEndTracingAsync(const ListValue* list) { |
| 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 400 DCHECK(traceEnabled_); |
| 401 |
| 402 // TODO(jbates): TracingController::OnEndTracingAsync(new |
| 403 // Callback(this, GpuMessageHandler::OnEndTracingComplete)) |
| 404 } |
| 405 |
| 406 void GpuMessageHandler::OnEndTracingComplete() { |
| 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 408 traceEnabled_ = false; |
| 409 web_ui_->CallJavascriptFunction("tracingController.onEndTracingComplete"); |
| 410 } |
| 411 |
| 412 void GpuMessageHandler::OnTraceDataCollected(const std::string& json_events) { |
| 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 414 std::wstring javascript; |
| 415 javascript += L"tracingController.onTraceDataCollected("; |
| 416 javascript += UTF8ToWide(json_events); |
| 417 javascript += L");"; |
| 418 |
| 419 web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), |
| 420 WideToUTF16Hack(javascript)); |
| 421 } |
| 422 |
371 } // namespace | 423 } // namespace |
372 | 424 |
373 | 425 |
374 //////////////////////////////////////////////////////////////////////////////// | 426 //////////////////////////////////////////////////////////////////////////////// |
375 // | 427 // |
376 // GpuInternalsUI | 428 // GpuInternalsUI |
377 // | 429 // |
378 //////////////////////////////////////////////////////////////////////////////// | 430 //////////////////////////////////////////////////////////////////////////////// |
379 | 431 |
380 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : WebUI(contents) { | 432 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : WebUI(contents) { |
381 AddMessageHandler((new GpuMessageHandler())->Attach(this)); | 433 AddMessageHandler((new GpuMessageHandler())->Attach(this)); |
382 | 434 |
383 GpuHTMLSource* html_source = new GpuHTMLSource(); | 435 GpuHTMLSource* html_source = new GpuHTMLSource(); |
384 | 436 |
385 // Set up the chrome://gpu/ source. | 437 // Set up the chrome://gpu/ source. |
386 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | 438 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); |
387 } | 439 } |
388 | |
OLD | NEW |