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 11 matching lines...) Expand all Loading... |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/io_thread.h" | 24 #include "chrome/browser/io_thread.h" |
25 #include "chrome/browser/net/chrome_net_log.h" | 25 #include "chrome/browser/net/chrome_net_log.h" |
26 #include "chrome/browser/net/connection_tester.h" | 26 #include "chrome/browser/net/connection_tester.h" |
27 #include "chrome/browser/net/passive_log_collector.h" | 27 #include "chrome/browser/net/passive_log_collector.h" |
28 #include "chrome/browser/net/url_fixer_upper.h" | 28 #include "chrome/browser/net/url_fixer_upper.h" |
29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/ui/shell_dialogs.h" | 30 #include "chrome/browser/ui/shell_dialogs.h" |
31 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 31 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 32 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
32 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
33 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
34 #include "chrome/common/jstemplate_builder.h" | 35 #include "chrome/common/jstemplate_builder.h" |
35 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
36 #include "content/browser/browser_thread.h" | 37 #include "content/browser/browser_thread.h" |
37 #include "content/browser/gpu/gpu_data_manager.h" | 38 #include "content/browser/gpu/gpu_data_manager.h" |
38 #include "content/browser/gpu/gpu_process_host.h" | 39 #include "content/browser/gpu/gpu_process_host.h" |
39 #include "content/browser/renderer_host/render_view_host.h" | 40 #include "content/browser/renderer_host/render_view_host.h" |
40 #include "content/browser/tab_contents/tab_contents.h" | 41 #include "content/browser/tab_contents/tab_contents.h" |
41 #include "content/browser/tab_contents/tab_contents_view.h" | 42 #include "content/browser/tab_contents/tab_contents_view.h" |
42 #include "content/browser/trace_controller.h" | 43 #include "content/browser/trace_controller.h" |
43 #include "grit/browser_resources.h" | 44 #include "grit/browser_resources.h" |
44 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
45 #include "net/base/escape.h" | 46 #include "net/base/escape.h" |
46 #include "net/url_request/url_request_context_getter.h" | 47 #include "net/url_request/url_request_context_getter.h" |
47 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
48 #include "ui/base/resource/resource_bundle.h" | 49 #include "ui/base/resource/resource_bundle.h" |
49 | 50 |
50 namespace { | 51 namespace { |
51 | 52 |
52 class GpuHTMLSource : public ChromeURLDataManager::DataSource { | 53 ChromeWebUIDataSource* CreateGpuHTMLSource() { |
53 public: | 54 ChromeWebUIDataSource* source = |
54 GpuHTMLSource(); | 55 new ChromeWebUIDataSource(chrome::kChromeUIGpuInternalsHost); |
55 | 56 |
56 // Called when the network layer has requested a resource underneath | 57 source->set_json_path("strings.js"); |
57 // the path we registered. | 58 source->add_resource_path("gpu_internals.js", IDR_GPU_INTERNALS_JS); |
58 virtual void StartDataRequest(const std::string& path, | 59 source->set_default_resource(IDR_GPU_INTERNALS_HTML); |
59 bool is_incognito, | 60 return source; |
60 int request_id); | 61 } |
61 virtual std::string GetMimeType(const std::string&) const; | |
62 | |
63 private: | |
64 ~GpuHTMLSource() {} | |
65 DISALLOW_COPY_AND_ASSIGN(GpuHTMLSource); | |
66 }; | |
67 | 62 |
68 // This class receives javascript messages from the renderer. | 63 // This class receives javascript messages from the renderer. |
69 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 64 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
70 // this class's methods are expected to run on the UI thread. | 65 // this class's methods are expected to run on the UI thread. |
71 class GpuMessageHandler | 66 class GpuMessageHandler |
72 : public WebUIMessageHandler, | 67 : public WebUIMessageHandler, |
73 public SelectFileDialog::Listener, | 68 public SelectFileDialog::Listener, |
74 public base::SupportsWeakPtr<GpuMessageHandler>, | 69 public base::SupportsWeakPtr<GpuMessageHandler>, |
75 public TraceSubscriber { | 70 public TraceSubscriber { |
76 public: | 71 public: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 139 } |
145 | 140 |
146 private: | 141 private: |
147 base::WeakPtr<GpuMessageHandler> handler_; | 142 base::WeakPtr<GpuMessageHandler> handler_; |
148 friend class base::RefCountedThreadSafe<TaskProxy>; | 143 friend class base::RefCountedThreadSafe<TaskProxy>; |
149 DISALLOW_COPY_AND_ASSIGN(TaskProxy); | 144 DISALLOW_COPY_AND_ASSIGN(TaskProxy); |
150 }; | 145 }; |
151 | 146 |
152 //////////////////////////////////////////////////////////////////////////////// | 147 //////////////////////////////////////////////////////////////////////////////// |
153 // | 148 // |
154 // GpuHTMLSource | |
155 // | |
156 //////////////////////////////////////////////////////////////////////////////// | |
157 | |
158 GpuHTMLSource::GpuHTMLSource() | |
159 : DataSource(chrome::kChromeUIGpuInternalsHost, MessageLoop::current()) { | |
160 } | |
161 | |
162 void GpuHTMLSource::StartDataRequest(const std::string& path, | |
163 bool is_incognito, | |
164 int request_id) { | |
165 DictionaryValue localized_strings; | |
166 SetFontAndTextDirection(&localized_strings); | |
167 | |
168 base::StringPiece gpu_html( | |
169 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
170 IDR_GPU_INTERNALS_HTML)); | |
171 std::string full_html(gpu_html.data(), gpu_html.size()); | |
172 jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html); | |
173 jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html); | |
174 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html); | |
175 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); | |
176 | |
177 | |
178 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | |
179 } | |
180 | |
181 std::string GpuHTMLSource::GetMimeType(const std::string&) const { | |
182 return "text/html"; | |
183 } | |
184 | |
185 //////////////////////////////////////////////////////////////////////////////// | |
186 // | |
187 // GpuMessageHandler | 149 // GpuMessageHandler |
188 // | 150 // |
189 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
190 | 152 |
191 GpuMessageHandler::GpuMessageHandler() | 153 GpuMessageHandler::GpuMessageHandler() |
192 : gpu_info_update_callback_(NULL), | 154 : gpu_info_update_callback_(NULL), |
193 select_trace_file_dialog_type_(SelectFileDialog::SELECT_NONE), | 155 select_trace_file_dialog_type_(SelectFileDialog::SELECT_NONE), |
194 trace_enabled_(false) { | 156 trace_enabled_(false) { |
195 gpu_data_manager_ = GpuDataManager::GetInstance(); | 157 gpu_data_manager_ = GpuDataManager::GetInstance(); |
196 DCHECK(gpu_data_manager_); | 158 DCHECK(gpu_data_manager_); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 | 594 |
633 //////////////////////////////////////////////////////////////////////////////// | 595 //////////////////////////////////////////////////////////////////////////////// |
634 // | 596 // |
635 // GpuInternalsUI | 597 // GpuInternalsUI |
636 // | 598 // |
637 //////////////////////////////////////////////////////////////////////////////// | 599 //////////////////////////////////////////////////////////////////////////////// |
638 | 600 |
639 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : ChromeWebUI(contents) { | 601 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : ChromeWebUI(contents) { |
640 AddMessageHandler((new GpuMessageHandler())->Attach(this)); | 602 AddMessageHandler((new GpuMessageHandler())->Attach(this)); |
641 | 603 |
642 GpuHTMLSource* html_source = new GpuHTMLSource(); | 604 // Set up the chrome://gpu-internals/ source. |
643 | 605 contents->profile()->GetChromeURLDataManager()->AddDataSource( |
644 // Set up the chrome://gpu/ source. | 606 CreateGpuHTMLSource()); |
645 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | |
646 } | 607 } |
OLD | NEW |