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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/browser/crash_upload_list/crash_upload_list.h" | 17 #include "chrome/browser/crash_upload_list/crash_upload_list.h" |
18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 19 #include "chrome/browser/metrics/metrics_reporting_state.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
21 #include "chrome/grit/chromium_strings.h" | 22 #include "chrome/grit/chromium_strings.h" |
22 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
23 #include "components/crash/core/browser/crashes_ui_util.h" | 24 #include "components/crash/core/browser/crashes_ui_util.h" |
24 #include "components/version_info/version_info.h" | 25 #include "components/version_info/version_info.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
27 #include "content/public/browser/web_ui_data_source.h" | 28 #include "content/public/browser/web_ui_data_source.h" |
28 #include "content/public/browser/web_ui_message_handler.h" | 29 #include "content/public/browser/web_ui_message_handler.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 void HandleRequestCrashes(const base::ListValue* args); | 86 void HandleRequestCrashes(const base::ListValue* args); |
86 | 87 |
87 #if defined(OS_CHROMEOS) | 88 #if defined(OS_CHROMEOS) |
88 // Asynchronously triggers crash uploading. Called from JS. | 89 // Asynchronously triggers crash uploading. Called from JS. |
89 void HandleRequestUploads(const base::ListValue* args); | 90 void HandleRequestUploads(const base::ListValue* args); |
90 #endif | 91 #endif |
91 | 92 |
92 // Sends the recent crashes list JS. | 93 // Sends the recent crashes list JS. |
93 void UpdateUI(); | 94 void UpdateUI(); |
94 | 95 |
| 96 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 97 // Asynchronously requests a user triggered upload. Called from JS. |
| 98 void HandleRequestSingleCrashUpload(const base::ListValue* args); |
| 99 #endif |
| 100 |
95 scoped_refptr<CrashUploadList> upload_list_; | 101 scoped_refptr<CrashUploadList> upload_list_; |
96 bool list_available_; | 102 bool list_available_; |
97 bool first_load_; | 103 bool first_load_; |
98 | 104 |
99 DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); | 105 DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); |
100 }; | 106 }; |
101 | 107 |
102 CrashesDOMHandler::CrashesDOMHandler() | 108 CrashesDOMHandler::CrashesDOMHandler() |
103 : list_available_(false), first_load_(true) { | 109 : list_available_(false), first_load_(true) { |
104 upload_list_ = CreateCrashUploadList(this); | 110 upload_list_ = CreateCrashUploadList(this); |
105 } | 111 } |
106 | 112 |
107 CrashesDOMHandler::~CrashesDOMHandler() { | 113 CrashesDOMHandler::~CrashesDOMHandler() { |
108 upload_list_->ClearDelegate(); | 114 upload_list_->ClearDelegate(); |
109 } | 115 } |
110 | 116 |
111 void CrashesDOMHandler::RegisterMessages() { | 117 void CrashesDOMHandler::RegisterMessages() { |
112 upload_list_->LoadUploadListAsynchronously(); | 118 upload_list_->LoadUploadListAsynchronously(); |
113 web_ui()->RegisterMessageCallback( | 119 web_ui()->RegisterMessageCallback( |
114 crash::kCrashesUIRequestCrashList, | 120 crash::kCrashesUIRequestCrashList, |
115 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, | 121 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, |
116 base::Unretained(this))); | 122 base::Unretained(this))); |
117 | 123 |
118 #if defined(OS_CHROMEOS) | 124 #if defined(OS_CHROMEOS) |
119 web_ui()->RegisterMessageCallback( | 125 web_ui()->RegisterMessageCallback( |
120 crash::kCrashesUIRequestCrashUpload, | 126 crash::kCrashesUIRequestCrashUpload, |
121 base::Bind(&CrashesDOMHandler::HandleRequestUploads, | 127 base::Bind(&CrashesDOMHandler::HandleRequestUploads, |
122 base::Unretained(this))); | 128 base::Unretained(this))); |
123 #endif | 129 #endif |
| 130 |
| 131 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 132 web_ui()->RegisterMessageCallback( |
| 133 crash::kCrashesUIRequestSingleCrashUpload, |
| 134 base::Bind(&CrashesDOMHandler::HandleRequestSingleCrashUpload, |
| 135 base::Unretained(this))); |
| 136 #endif |
124 } | 137 } |
125 | 138 |
126 void CrashesDOMHandler::HandleRequestCrashes(const base::ListValue* args) { | 139 void CrashesDOMHandler::HandleRequestCrashes(const base::ListValue* args) { |
127 if (first_load_) { | 140 if (first_load_) { |
128 first_load_ = false; | 141 first_load_ = false; |
129 if (list_available_) | 142 if (list_available_) |
130 UpdateUI(); | 143 UpdateUI(); |
131 } else { | 144 } else { |
132 list_available_ = false; | 145 list_available_ = false; |
133 upload_list_->LoadUploadListAsynchronously(); | 146 upload_list_->LoadUploadListAsynchronously(); |
(...skipping 19 matching lines...) Expand all Loading... |
153 void CrashesDOMHandler::UpdateUI() { | 166 void CrashesDOMHandler::UpdateUI() { |
154 bool crash_reporting_enabled = | 167 bool crash_reporting_enabled = |
155 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 168 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
156 | 169 |
157 bool system_crash_reporter = false; | 170 bool system_crash_reporter = false; |
158 #if defined(OS_CHROMEOS) | 171 #if defined(OS_CHROMEOS) |
159 // Chrome OS has a system crash reporter. | 172 // Chrome OS has a system crash reporter. |
160 system_crash_reporter = true; | 173 system_crash_reporter = true; |
161 #endif | 174 #endif |
162 | 175 |
| 176 bool upload_list = crash_reporting_enabled; |
| 177 bool support_manual_uploads = false; |
| 178 |
| 179 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 180 // Maunal uploads currently are supported only for Crashpad-using platforms |
| 181 // and only if crash uploads are not disabled by policy. |
| 182 support_manual_uploads = |
| 183 crash_reporting_enabled || !IsMetricsReportingPolicyManaged(); |
| 184 |
| 185 // Show crash reports regardless of |crash_reporting_enabled| so that users |
| 186 // can manually upload those reports. |
| 187 upload_list = true; |
| 188 #endif |
| 189 |
163 base::ListValue crash_list; | 190 base::ListValue crash_list; |
164 if (crash_reporting_enabled) | 191 if (upload_list) |
165 crash::UploadListToValue(upload_list_.get(), &crash_list); | 192 crash::UploadListToValue(upload_list_.get(), &crash_list); |
166 | 193 |
167 base::FundamentalValue enabled(crash_reporting_enabled); | 194 base::FundamentalValue enabled(crash_reporting_enabled); |
168 base::FundamentalValue dynamic_backend(system_crash_reporter); | 195 base::FundamentalValue dynamic_backend(system_crash_reporter); |
| 196 base::FundamentalValue manual_uploads(support_manual_uploads); |
169 base::StringValue version(version_info::GetVersionNumber()); | 197 base::StringValue version(version_info::GetVersionNumber()); |
170 base::StringValue os_string(base::SysInfo::OperatingSystemName() + " " + | 198 base::StringValue os_string(base::SysInfo::OperatingSystemName() + " " + |
171 base::SysInfo::OperatingSystemVersion()); | 199 base::SysInfo::OperatingSystemVersion()); |
172 | 200 |
173 std::vector<const base::Value*> args; | 201 std::vector<const base::Value*> args; |
174 args.push_back(&enabled); | 202 args.push_back(&enabled); |
175 args.push_back(&dynamic_backend); | 203 args.push_back(&dynamic_backend); |
| 204 args.push_back(&manual_uploads); |
176 args.push_back(&crash_list); | 205 args.push_back(&crash_list); |
177 args.push_back(&version); | 206 args.push_back(&version); |
178 args.push_back(&os_string); | 207 args.push_back(&os_string); |
179 web_ui()->CallJavascriptFunctionUnsafe(crash::kCrashesUIUpdateCrashList, | 208 web_ui()->CallJavascriptFunctionUnsafe(crash::kCrashesUIUpdateCrashList, |
180 args); | 209 args); |
181 } | 210 } |
182 | 211 |
| 212 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 213 void CrashesDOMHandler::HandleRequestSingleCrashUpload( |
| 214 const base::ListValue* args) { |
| 215 DCHECK(args); |
| 216 |
| 217 std::string local_id; |
| 218 bool success = args->GetString(0, &local_id); |
| 219 DCHECK(success); |
| 220 |
| 221 // Only allow manual uploads if crash uploads aren’t disabled by policy. |
| 222 if (!ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled() && |
| 223 IsMetricsReportingPolicyManaged()) { |
| 224 return; |
| 225 } |
| 226 upload_list_->RequestSingleCrashUploadAsync(local_id); |
| 227 } |
| 228 #endif |
| 229 |
183 } // namespace | 230 } // namespace |
184 | 231 |
185 /////////////////////////////////////////////////////////////////////////////// | 232 /////////////////////////////////////////////////////////////////////////////// |
186 // | 233 // |
187 // CrashesUI | 234 // CrashesUI |
188 // | 235 // |
189 /////////////////////////////////////////////////////////////////////////////// | 236 /////////////////////////////////////////////////////////////////////////////// |
190 | 237 |
191 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 238 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
192 web_ui->AddMessageHandler(new CrashesDOMHandler()); | 239 web_ui->AddMessageHandler(new CrashesDOMHandler()); |
193 | 240 |
194 // Set up the chrome://crashes/ source. | 241 // Set up the chrome://crashes/ source. |
195 Profile* profile = Profile::FromWebUI(web_ui); | 242 Profile* profile = Profile::FromWebUI(web_ui); |
196 content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); | 243 content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); |
197 } | 244 } |
198 | 245 |
199 // static | 246 // static |
200 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( | 247 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( |
201 ui::ScaleFactor scale_factor) { | 248 ui::ScaleFactor scale_factor) { |
202 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( | 249 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
203 IDR_CRASH_SAD_FAVICON, scale_factor); | 250 IDR_CRASH_SAD_FAVICON, scale_factor); |
204 } | 251 } |
OLD | NEW |