OLD | NEW |
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/browser/ui/webui/chromeos/system_info_ui.h" | 5 #include "chrome/browser/ui/webui/chromeos/system_info_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/string_piece.h" | 14 #include "base/string_piece.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/chromeos/cros/cros_library.h" | 21 #include "chrome/browser/chromeos/cros/cros_library.h" |
22 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h" | 22 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
26 #include "chrome/common/jstemplate_builder.h" | 26 #include "chrome/common/jstemplate_builder.h" |
27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "content/public/browser/url_data_source_delegate.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
30 #include "content/public/browser/web_ui_message_handler.h" | 31 #include "content/public/browser/web_ui_message_handler.h" |
31 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
32 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
33 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
34 #include "grit/locale_settings.h" | 35 #include "grit/locale_settings.h" |
35 #include "net/base/directory_lister.h" | 36 #include "net/base/directory_lister.h" |
36 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
37 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
39 | 40 |
40 using content::WebContents; | 41 using content::WebContents; |
41 using content::WebUIMessageHandler; | 42 using content::WebUIMessageHandler; |
42 | 43 |
43 namespace chromeos { | 44 namespace chromeos { |
44 | 45 |
45 class SystemInfoUIHTMLSource : public ChromeURLDataManager::DataSource { | 46 class SystemInfoUIHTMLSource : public content::URLDataSourceDelegate { |
46 public: | 47 public: |
47 SystemInfoUIHTMLSource(); | 48 SystemInfoUIHTMLSource(); |
48 | 49 |
49 // Called when the network layer has requested a resource underneath | 50 // content::URLDataSourceDelegate implementation. |
50 // the path we registered. | 51 virtual std::string GetSource() OVERRIDE; |
51 virtual void StartDataRequest(const std::string& path, | 52 virtual void StartDataRequest(const std::string& path, |
52 bool is_incognito, | 53 bool is_incognito, |
53 int request_id) OVERRIDE; | 54 int request_id) OVERRIDE; |
54 virtual std::string GetMimeType(const std::string&) const OVERRIDE { | 55 virtual std::string GetMimeType(const std::string&) const OVERRIDE { |
55 return "text/html"; | 56 return "text/html"; |
56 } | 57 } |
57 | 58 |
58 private: | 59 private: |
59 ~SystemInfoUIHTMLSource() {} | 60 ~SystemInfoUIHTMLSource() {} |
60 | 61 |
(...skipping 24 matching lines...) Expand all Loading... |
85 DISALLOW_COPY_AND_ASSIGN(SystemInfoHandler); | 86 DISALLOW_COPY_AND_ASSIGN(SystemInfoHandler); |
86 }; | 87 }; |
87 | 88 |
88 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
89 // | 90 // |
90 // SystemInfoUIHTMLSource | 91 // SystemInfoUIHTMLSource |
91 // | 92 // |
92 //////////////////////////////////////////////////////////////////////////////// | 93 //////////////////////////////////////////////////////////////////////////////// |
93 | 94 |
94 SystemInfoUIHTMLSource::SystemInfoUIHTMLSource() | 95 SystemInfoUIHTMLSource::SystemInfoUIHTMLSource() |
95 : DataSource(chrome::kChromeUISystemInfoHost, MessageLoop::current()), | 96 : request_id_(0), |
96 request_id_(0), | |
97 response_(NULL), | 97 response_(NULL), |
98 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 98 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
99 } | 99 } |
100 | 100 |
| 101 std::string SystemInfoUIHTMLSource::GetSource() { |
| 102 return chrome::kChromeUISystemInfoHost; |
| 103 } |
| 104 |
101 void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path, | 105 void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path, |
102 bool is_incognito, | 106 bool is_incognito, |
103 int request_id) { | 107 int request_id) { |
104 path_ = path; | 108 path_ = path; |
105 request_id_ = request_id; | 109 request_id_ = request_id; |
106 | 110 |
107 SystemLogsFetcher* fetcher = new SystemLogsFetcher(); | 111 SystemLogsFetcher* fetcher = new SystemLogsFetcher(); |
108 fetcher->Fetch(base::Bind(&SystemInfoUIHTMLSource::SysInfoComplete, | 112 fetcher->Fetch(base::Bind(&SystemInfoUIHTMLSource::SysInfoComplete, |
109 weak_ptr_factory_.GetWeakPtr())); | 113 weak_ptr_factory_.GetWeakPtr())); |
110 } | 114 } |
(...skipping 13 matching lines...) Expand all Loading... |
124 strings.SetString("table_title", | 128 strings.SetString("table_title", |
125 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TABLE_TITLE)); | 129 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_TABLE_TITLE)); |
126 strings.SetString("expand_all_btn", | 130 strings.SetString("expand_all_btn", |
127 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND_ALL)); | 131 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND_ALL)); |
128 strings.SetString("collapse_all_btn", | 132 strings.SetString("collapse_all_btn", |
129 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE_ALL)); | 133 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE_ALL)); |
130 strings.SetString("expand_btn", | 134 strings.SetString("expand_btn", |
131 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND)); | 135 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_EXPAND)); |
132 strings.SetString("collapse_btn", | 136 strings.SetString("collapse_btn", |
133 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE)); | 137 l10n_util::GetStringUTF16(IDS_ABOUT_SYS_COLLAPSE)); |
134 SetFontAndTextDirection(&strings); | 138 URLDataSource::SetFontAndTextDirection(&strings); |
135 if (response_.get()) { | 139 if (response_.get()) { |
136 ListValue* details = new ListValue(); | 140 ListValue* details = new ListValue(); |
137 strings.Set("details", details); | 141 strings.Set("details", details); |
138 for (SystemLogsResponse::const_iterator it = response_->begin(); | 142 for (SystemLogsResponse::const_iterator it = response_->begin(); |
139 it != response_->end(); | 143 it != response_->end(); |
140 ++it) { | 144 ++it) { |
141 DictionaryValue* val = new DictionaryValue; | 145 DictionaryValue* val = new DictionaryValue; |
142 val->SetString("stat_name", it->first); | 146 val->SetString("stat_name", it->first); |
143 val->SetString("stat_value", it->second); | 147 val->SetString("stat_value", it->second); |
144 details->Append(val); | 148 details->Append(val); |
145 } | 149 } |
146 strings.SetString("anchor", path_); | 150 strings.SetString("anchor", path_); |
147 } | 151 } |
148 static const base::StringPiece systeminfo_html( | 152 static const base::StringPiece systeminfo_html( |
149 ResourceBundle::GetSharedInstance().GetRawDataResource( | 153 ResourceBundle::GetSharedInstance().GetRawDataResource( |
150 IDR_ABOUT_SYS_HTML)); | 154 IDR_ABOUT_SYS_HTML)); |
151 std::string full_html = jstemplate_builder::GetTemplatesHtml( | 155 std::string full_html = jstemplate_builder::GetTemplatesHtml( |
152 systeminfo_html, &strings, "t" /* template root node id */); | 156 systeminfo_html, &strings, "t" /* template root node id */); |
153 SendResponse(request_id_, base::RefCountedString::TakeString(&full_html)); | 157 url_data_source()->SendResponse( |
| 158 request_id_, base::RefCountedString::TakeString(&full_html)); |
154 } | 159 } |
155 | 160 |
156 //////////////////////////////////////////////////////////////////////////////// | 161 //////////////////////////////////////////////////////////////////////////////// |
157 // | 162 // |
158 // SystemInfoHandler | 163 // SystemInfoHandler |
159 // | 164 // |
160 //////////////////////////////////////////////////////////////////////////////// | 165 //////////////////////////////////////////////////////////////////////////////// |
161 SystemInfoHandler::SystemInfoHandler() { | 166 SystemInfoHandler::SystemInfoHandler() { |
162 } | 167 } |
163 | 168 |
(...skipping 14 matching lines...) Expand all Loading... |
178 SystemInfoHandler* handler = new SystemInfoHandler(); | 183 SystemInfoHandler* handler = new SystemInfoHandler(); |
179 web_ui->AddMessageHandler(handler); | 184 web_ui->AddMessageHandler(handler); |
180 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); | 185 SystemInfoUIHTMLSource* html_source = new SystemInfoUIHTMLSource(); |
181 | 186 |
182 // Set up the chrome://system/ source. | 187 // Set up the chrome://system/ source. |
183 Profile* profile = Profile::FromWebUI(web_ui); | 188 Profile* profile = Profile::FromWebUI(web_ui); |
184 ChromeURLDataManager::AddDataSource(profile, html_source); | 189 ChromeURLDataManager::AddDataSource(profile, html_source); |
185 } | 190 } |
186 | 191 |
187 } // namespace chromeos | 192 } // namespace chromeos |
OLD | NEW |