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/crashes_ui.h" | 5 #include "chrome/browser/ui/webui/crashes_ui.h" |
6 | 6 |
7 #include <vector> | |
8 | |
9 #include "base/bind.h" | 7 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
11 #include "base/i18n/time_formatting.h" | |
12 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
13 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 11 #include "base/values.h" |
15 #include "chrome/browser/crash_upload_list.h" | 12 #include "chrome/browser/crash_upload_list.h" |
16 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 13 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
17 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
19 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
20 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
21 #include "chrome/grit/google_chrome_strings.h" | 18 #include "chrome/grit/google_chrome_strings.h" |
| 19 #include "components/crash/core/browser/crashes_ui_util.h" |
22 #include "components/version_info/version_info.h" | 20 #include "components/version_info/version_info.h" |
23 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
24 #include "content/public/browser/web_ui.h" | 22 #include "content/public/browser/web_ui.h" |
25 #include "content/public/browser/web_ui_data_source.h" | 23 #include "content/public/browser/web_ui_data_source.h" |
26 #include "content/public/browser/web_ui_message_handler.h" | 24 #include "content/public/browser/web_ui_message_handler.h" |
27 #include "grit/browser_resources.h" | 25 #include "grit/browser_resources.h" |
28 #include "grit/components_chromium_strings.h" | 26 #include "grit/components_chromium_strings.h" |
29 #include "grit/components_google_chrome_strings.h" | 27 #include "grit/components_google_chrome_strings.h" |
30 #include "grit/components_resources.h" | 28 #include "grit/components_resources.h" |
| 29 #include "grit/components_scaled_resources.h" |
31 #include "grit/components_strings.h" | 30 #include "grit/components_strings.h" |
32 #include "grit/theme_resources.h" | |
33 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
34 | 32 |
35 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
36 #include "chromeos/dbus/dbus_thread_manager.h" | 34 #include "chromeos/dbus/dbus_thread_manager.h" |
37 #include "chromeos/dbus/debug_daemon_client.h" | 35 #include "chromeos/dbus/debug_daemon_client.h" |
38 #endif | 36 #endif |
39 | 37 |
40 using content::WebContents; | 38 using content::WebContents; |
41 using content::WebUIMessageHandler; | 39 using content::WebUIMessageHandler; |
42 | 40 |
43 namespace { | 41 namespace { |
44 | 42 |
45 content::WebUIDataSource* CreateCrashesUIHTMLSource() { | 43 content::WebUIDataSource* CreateCrashesUIHTMLSource() { |
46 content::WebUIDataSource* source = | 44 content::WebUIDataSource* source = |
47 content::WebUIDataSource::Create(chrome::kChromeUICrashesHost); | 45 content::WebUIDataSource::Create(chrome::kChromeUICrashesHost); |
48 | 46 |
49 source->AddLocalizedString("shortProductName", IDS_SHORT_PRODUCT_NAME); | 47 for (size_t i = 0; i < crash::kCrashesUILocalizedStringsCount; ++i) { |
50 source->AddLocalizedString("crashesTitle", IDS_CRASH_TITLE); | 48 source->AddLocalizedString( |
51 source->AddLocalizedString("crashCountFormat", | 49 crash::kCrashesUILocalizedStrings[i].name, |
52 IDS_CRASH_CRASH_COUNT_BANNER_FORMAT); | 50 crash::kCrashesUILocalizedStrings[i].resource_id); |
53 source->AddLocalizedString("crashHeaderFormat", | 51 } |
54 IDS_CRASH_CRASH_HEADER_FORMAT); | 52 |
55 source->AddLocalizedString("crashTimeFormat", IDS_CRASH_CRASH_TIME_FORMAT); | 53 source->AddLocalizedString(crash::kCrashesUIShortProductName, |
56 source->AddLocalizedString("bugLinkText", IDS_CRASH_BUG_LINK_LABEL); | 54 IDS_SHORT_PRODUCT_NAME); |
57 source->AddLocalizedString("noCrashesMessage", | |
58 IDS_CRASH_NO_CRASHES_MESSAGE); | |
59 source->AddLocalizedString("disabledHeader", IDS_CRASH_DISABLED_HEADER); | |
60 source->AddLocalizedString("disabledMessage", IDS_CRASH_DISABLED_MESSAGE); | |
61 source->AddLocalizedString("uploadCrashesLinkText", | |
62 IDS_CRASH_UPLOAD_MESSAGE); | |
63 source->SetJsonPath("strings.js"); | 55 source->SetJsonPath("strings.js"); |
64 source->AddResourcePath("crashes.js", IDR_CRASH_CRASHES_JS); | 56 source->AddResourcePath(crash::kCrashesUICrashesJS, IDR_CRASH_CRASHES_JS); |
65 source->SetDefaultResource(IDR_CRASH_CRASHES_HTML); | 57 source->SetDefaultResource(IDR_CRASH_CRASHES_HTML); |
66 return source; | 58 return source; |
67 } | 59 } |
68 | 60 |
69 //////////////////////////////////////////////////////////////////////////////// | 61 //////////////////////////////////////////////////////////////////////////////// |
70 // | 62 // |
71 // CrashesDOMHandler | 63 // CrashesDOMHandler |
72 // | 64 // |
73 //////////////////////////////////////////////////////////////////////////////// | 65 //////////////////////////////////////////////////////////////////////////////// |
74 | 66 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 : list_available_(false), first_load_(true) { | 100 : list_available_(false), first_load_(true) { |
109 upload_list_ = CreateCrashUploadList(this); | 101 upload_list_ = CreateCrashUploadList(this); |
110 } | 102 } |
111 | 103 |
112 CrashesDOMHandler::~CrashesDOMHandler() { | 104 CrashesDOMHandler::~CrashesDOMHandler() { |
113 upload_list_->ClearDelegate(); | 105 upload_list_->ClearDelegate(); |
114 } | 106 } |
115 | 107 |
116 void CrashesDOMHandler::RegisterMessages() { | 108 void CrashesDOMHandler::RegisterMessages() { |
117 upload_list_->LoadUploadListAsynchronously(); | 109 upload_list_->LoadUploadListAsynchronously(); |
118 web_ui()->RegisterMessageCallback("requestCrashList", | 110 web_ui()->RegisterMessageCallback( |
| 111 crash::kCrashesUIRequestCrashList, |
119 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, | 112 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, |
120 base::Unretained(this))); | 113 base::Unretained(this))); |
121 | 114 |
122 #if defined(OS_CHROMEOS) | 115 #if defined(OS_CHROMEOS) |
123 web_ui()->RegisterMessageCallback("requestCrashUpload", | 116 web_ui()->RegisterMessageCallback( |
| 117 crash::kCrashesUIRequestCrashUpload, |
124 base::Bind(&CrashesDOMHandler::HandleRequestUploads, | 118 base::Bind(&CrashesDOMHandler::HandleRequestUploads, |
125 base::Unretained(this))); | 119 base::Unretained(this))); |
126 #endif | 120 #endif |
127 } | 121 } |
128 | 122 |
129 void CrashesDOMHandler::HandleRequestCrashes(const base::ListValue* args) { | 123 void CrashesDOMHandler::HandleRequestCrashes(const base::ListValue* args) { |
130 if (first_load_) { | 124 if (first_load_) { |
131 first_load_ = false; | 125 first_load_ = false; |
132 if (list_available_) | 126 if (list_available_) |
133 UpdateUI(); | 127 UpdateUI(); |
(...skipping 15 matching lines...) Expand all Loading... |
149 | 143 |
150 void CrashesDOMHandler::OnUploadListAvailable() { | 144 void CrashesDOMHandler::OnUploadListAvailable() { |
151 list_available_ = true; | 145 list_available_ = true; |
152 if (!first_load_) | 146 if (!first_load_) |
153 UpdateUI(); | 147 UpdateUI(); |
154 } | 148 } |
155 | 149 |
156 void CrashesDOMHandler::UpdateUI() { | 150 void CrashesDOMHandler::UpdateUI() { |
157 bool crash_reporting_enabled = | 151 bool crash_reporting_enabled = |
158 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 152 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
159 base::ListValue crash_list; | 153 |
160 bool system_crash_reporter = false; | 154 bool system_crash_reporter = false; |
161 | |
162 #if defined(OS_CHROMEOS) | 155 #if defined(OS_CHROMEOS) |
163 // Chrome OS has a system crash reporter. | 156 // Chrome OS has a system crash reporter. |
164 system_crash_reporter = true; | 157 system_crash_reporter = true; |
165 #endif | 158 #endif |
166 | 159 |
167 if (crash_reporting_enabled) { | 160 base::ListValue crash_list; |
168 std::vector<CrashUploadList::UploadInfo> crashes; | 161 if (crash_reporting_enabled) |
169 upload_list_->GetUploads(50, &crashes); | 162 crash::UploadListToValue(upload_list_.get(), &crash_list); |
170 | |
171 for (std::vector<CrashUploadList::UploadInfo>::iterator i = crashes.begin(); | |
172 i != crashes.end(); ++i) { | |
173 base::DictionaryValue* crash = new base::DictionaryValue(); | |
174 crash->SetString("id", i->id); | |
175 crash->SetString("time", base::TimeFormatFriendlyDateAndTime(i->time)); | |
176 crash->SetString("local_id", i->local_id); | |
177 crash_list.Append(crash); | |
178 } | |
179 } | |
180 | 163 |
181 base::FundamentalValue enabled(crash_reporting_enabled); | 164 base::FundamentalValue enabled(crash_reporting_enabled); |
182 base::FundamentalValue dynamic_backend(system_crash_reporter); | 165 base::FundamentalValue dynamic_backend(system_crash_reporter); |
183 | |
184 base::StringValue version(version_info::GetVersionNumber()); | 166 base::StringValue version(version_info::GetVersionNumber()); |
185 | 167 web_ui()->CallJavascriptFunction(crash::kCrashesUIUpdateCrashList, enabled, |
186 web_ui()->CallJavascriptFunction("updateCrashList", enabled, dynamic_backend, | 168 dynamic_backend, crash_list, version); |
187 crash_list, version); | |
188 } | 169 } |
189 | 170 |
190 } // namespace | 171 } // namespace |
191 | 172 |
192 /////////////////////////////////////////////////////////////////////////////// | 173 /////////////////////////////////////////////////////////////////////////////// |
193 // | 174 // |
194 // CrashesUI | 175 // CrashesUI |
195 // | 176 // |
196 /////////////////////////////////////////////////////////////////////////////// | 177 /////////////////////////////////////////////////////////////////////////////// |
197 | 178 |
198 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 179 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
199 web_ui->AddMessageHandler(new CrashesDOMHandler()); | 180 web_ui->AddMessageHandler(new CrashesDOMHandler()); |
200 | 181 |
201 // Set up the chrome://crashes/ source. | 182 // Set up the chrome://crashes/ source. |
202 Profile* profile = Profile::FromWebUI(web_ui); | 183 Profile* profile = Profile::FromWebUI(web_ui); |
203 content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); | 184 content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); |
204 } | 185 } |
205 | 186 |
206 // static | 187 // static |
207 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( | 188 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( |
208 ui::ScaleFactor scale_factor) { | 189 ui::ScaleFactor scale_factor) { |
209 return ResourceBundle::GetSharedInstance(). | 190 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
210 LoadDataResourceBytesForScale(IDR_SAD_FAVICON, scale_factor); | 191 IDR_CRASH_SAD_FAVICON, scale_factor); |
211 } | 192 } |
OLD | NEW |