OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/bug_report_ui.h" | 5 #include "chrome/browser/dom_ui/bug_report_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
49 #include "base/file_util.h" | 49 #include "base/file_util.h" |
50 #include "base/path_service.h" | 50 #include "base/path_service.h" |
51 #include "base/waitable_event.h" | 51 #include "base/waitable_event.h" |
52 #include "chrome/browser/chromeos/cros/cros_library.h" | 52 #include "chrome/browser/chromeos/cros/cros_library.h" |
53 #include "chrome/browser/chromeos/cros/syslogs_library.h" | 53 #include "chrome/browser/chromeos/cros/syslogs_library.h" |
54 #include "chrome/browser/chromeos/login/user_manager.h" | 54 #include "chrome/browser/chromeos/login/user_manager.h" |
55 #endif | 55 #endif |
56 | 56 |
57 static const char kScreenshotBaseUrl[] = "chrome://screenshots/"; | 57 const char kScreenshotBaseUrl[] = "chrome://screenshots/"; |
oshima
2010/11/29 23:00:22
Sorry i wasn't clear. please move this into anonym
rkc
2010/11/29 23:15:59
Done.
| |
58 static const char kCurrentScreenshotUrl[] = "chrome://screenshots/current"; | 58 const char kCurrentScreenshotUrl[] = "chrome://screenshots/current"; |
59 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
60 static const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/"; | 60 const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/"; |
61 | 61 |
62 static const char kScreenshotPattern[] = "*.png"; | 62 const char kScreenshotPattern[] = "*.png"; |
63 static const char kScreenshotsRelativePath[] = "/Screenshots"; | 63 const char kScreenshotsRelativePath[] = "/Screenshots"; |
64 | |
65 const size_t kMaxSavedScreenshots = 2; | |
64 #endif | 66 #endif |
65 | 67 |
66 namespace { | 68 namespace { |
67 #if defined(OS_CHROMEOS) | 69 #if defined(OS_CHROMEOS) |
68 | 70 |
69 void GetSavedScreenshots(std::vector<std::string>* saved_screenshots, | 71 void GetSavedScreenshots(std::vector<std::string>* saved_screenshots, |
70 base::WaitableEvent* done) { | 72 base::WaitableEvent* done) { |
71 saved_screenshots->clear(); | 73 saved_screenshots->clear(); |
72 | 74 |
73 FilePath fileshelf_path; | 75 FilePath fileshelf_path; |
74 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, | 76 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
75 &fileshelf_path)) { | 77 &fileshelf_path)) { |
76 done->Signal(); | 78 done->Signal(); |
77 return; | 79 return; |
78 } | 80 } |
79 | 81 |
80 // TODO(rkc): Change this to use FilePath.Append() once the cros | 82 // TODO(rkc): Change this to use FilePath.Append() once the cros |
81 // issue with it is fixed | 83 // issue with it is fixed |
82 FilePath screenshots_path(fileshelf_path.value() + | 84 FilePath screenshots_path(fileshelf_path.value() + |
83 std::string(kScreenshotsRelativePath)); | 85 std::string(kScreenshotsRelativePath)); |
84 file_util::FileEnumerator screenshots(screenshots_path, false, | 86 file_util::FileEnumerator screenshots(screenshots_path, false, |
85 file_util::FileEnumerator::FILES, | 87 file_util::FileEnumerator::FILES, |
86 std::string(kScreenshotPattern)); | 88 std::string(kScreenshotPattern)); |
87 FilePath screenshot = screenshots.Next(); | 89 FilePath screenshot = screenshots.Next(); |
88 while (!screenshot.empty()) { | 90 while (!screenshot.empty()) { |
89 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + | 91 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + |
90 screenshot.BaseName().value()); | 92 screenshot.BaseName().value()); |
93 if (saved_screenshots->size() >= kMaxSavedScreenshots) | |
94 break; | |
95 | |
91 screenshot = screenshots.Next(); | 96 screenshot = screenshots.Next(); |
92 } | 97 } |
93 done->Signal(); | 98 done->Signal(); |
94 } | 99 } |
95 | 100 |
96 // This fuction posts a task to the file thread to create/list all the current | 101 // This fuction posts a task to the file thread to create/list all the current |
97 // and saved screenshots. | 102 // and saved screenshots. |
98 void GetScreenshotUrls(std::vector<std::string>* saved_screenshots) { | 103 void GetScreenshotUrls(std::vector<std::string>* saved_screenshots) { |
99 base::WaitableEvent done(true, false); | 104 base::WaitableEvent done(true, false); |
100 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 105 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 | 188 |
184 // Init work after Attach. | 189 // Init work after Attach. |
185 base::StringPiece Init(); | 190 base::StringPiece Init(); |
186 | 191 |
187 // DOMMessageHandler implementation. | 192 // DOMMessageHandler implementation. |
188 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); | 193 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
189 virtual void RegisterMessages(); | 194 virtual void RegisterMessages(); |
190 | 195 |
191 private: | 196 private: |
192 void HandleGetDialogDefaults(const ListValue* args); | 197 void HandleGetDialogDefaults(const ListValue* args); |
193 void HandleRefreshScreenshots(const ListValue* args); | 198 void HandleRefreshCurrentScreenshot(const ListValue* args); |
199 #if defined(OS_CHROMEOS) | |
200 void HandleRefreshSavedScreenshots(const ListValue* args); | |
201 #endif | |
194 void HandleSendReport(const ListValue* args); | 202 void HandleSendReport(const ListValue* args); |
195 void HandleCancel(const ListValue* args); | 203 void HandleCancel(const ListValue* args); |
196 void HandleOpenSystemTab(const ListValue* args); | 204 void HandleOpenSystemTab(const ListValue* args); |
197 | 205 |
198 void SetupScreenshotsSource(); | 206 void SetupScreenshotsSource(); |
199 void ClobberScreenshotsSource(); | 207 void ClobberScreenshotsSource(); |
200 | 208 |
201 void CancelFeedbackCollection(); | 209 void CancelFeedbackCollection(); |
202 void CloseFeedbackTab(); | 210 void CloseFeedbackTab(); |
203 | 211 |
(...skipping 22 matching lines...) Expand all Loading... | |
226 : DataSource(chrome::kChromeUIBugReportHost, MessageLoop::current()) { | 234 : DataSource(chrome::kChromeUIBugReportHost, MessageLoop::current()) { |
227 bug_report_html_ = html; | 235 bug_report_html_ = html; |
228 } | 236 } |
229 | 237 |
230 void BugReportUIHTMLSource::StartDataRequest(const std::string& path, | 238 void BugReportUIHTMLSource::StartDataRequest(const std::string& path, |
231 bool is_off_the_record, | 239 bool is_off_the_record, |
232 int request_id) { | 240 int request_id) { |
233 DictionaryValue localized_strings; | 241 DictionaryValue localized_strings; |
234 localized_strings.SetString(std::string("title"), | 242 localized_strings.SetString(std::string("title"), |
235 l10n_util::GetStringUTF8(IDS_BUGREPORT_TITLE)); | 243 l10n_util::GetStringUTF8(IDS_BUGREPORT_TITLE)); |
244 localized_strings.SetString(std::string("page-title"), | |
245 l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_PAGE_TITLE)); | |
236 localized_strings.SetString(std::string("issue-with"), | 246 localized_strings.SetString(std::string("issue-with"), |
237 l10n_util::GetStringUTF8(IDS_BUGREPORT_ISSUE_WITH)); | 247 l10n_util::GetStringUTF8(IDS_BUGREPORT_ISSUE_WITH)); |
238 localized_strings.SetString(std::string("page-url"), | 248 localized_strings.SetString(std::string("page-url"), |
239 l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_URL_LABEL)); | 249 l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_URL_LABEL)); |
240 localized_strings.SetString(std::string("description"), | 250 localized_strings.SetString(std::string("description"), |
241 l10n_util::GetStringUTF8(IDS_BUGREPORT_DESCRIPTION_LABEL)); | 251 l10n_util::GetStringUTF8(IDS_BUGREPORT_DESCRIPTION_LABEL)); |
242 localized_strings.SetString(std::string("screenshot"), | 252 localized_strings.SetString(std::string("current-screenshot"), |
243 l10n_util::GetStringUTF8(IDS_BUGREPORT_SCREENSHOT_LABEL)); | 253 l10n_util::GetStringUTF8(IDS_BUGREPORT_SCREENSHOT_LABEL)); |
254 localized_strings.SetString(std::string("saved-screenshot"), | |
255 l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOT_LABEL)); | |
244 #if defined(OS_CHROMEOS) | 256 #if defined(OS_CHROMEOS) |
245 localized_strings.SetString(std::string("user-email"), | 257 localized_strings.SetString(std::string("user-email"), |
246 l10n_util::GetStringUTF8(IDS_BUGREPORT_USER_EMAIL_LABEL)); | 258 l10n_util::GetStringUTF8(IDS_BUGREPORT_USER_EMAIL_LABEL)); |
259 localized_strings.SetString(std::string("sysinfo"), | |
260 l10n_util::GetStringUTF8( | |
261 IDS_BUGREPORT_INCLUDE_SYSTEM_INFORMATION_CHKBOX)); | |
262 | |
247 localized_strings.SetString(std::string("currentscreenshots"), | 263 localized_strings.SetString(std::string("currentscreenshots"), |
248 l10n_util::GetStringUTF8(IDS_BUGREPORT_CURRENT_SCREENSHOTS)); | 264 l10n_util::GetStringUTF8(IDS_BUGREPORT_CURRENT_SCREENSHOTS)); |
249 localized_strings.SetString(std::string("savedscreenshots"), | 265 localized_strings.SetString(std::string("savedscreenshots"), |
250 l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOTS)); | 266 l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOTS)); |
251 localized_strings.SetString(std::string("sysinfo"), | 267 |
268 localized_strings.SetString(std::string("choose-different-screenshot"), | |
252 l10n_util::GetStringUTF8( | 269 l10n_util::GetStringUTF8( |
253 IDS_BUGREPORT_INCLUDE_SYSTEM_INFORMATION_CHKBOX)); | 270 IDS_BUGREPORT_CHOOSE_DIFFERENT_SCREENSHOT)); |
271 localized_strings.SetString(std::string("choose-original-screenshot"), | |
272 l10n_util::GetStringUTF8( | |
273 IDS_BUGREPORT_CHOOSE_ORIGINAL_SCREENSHOT)); | |
254 #else | 274 #else |
255 localized_strings.SetString(std::string("currentscreenshots"), | 275 localized_strings.SetString(std::string("currentscreenshots"), |
256 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NEW_SCREEN_IMAGE)); | 276 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NEW_SCREEN_IMAGE)); |
257 #endif | 277 #endif |
258 localized_strings.SetString(std::string("noscreenshot"), | 278 localized_strings.SetString(std::string("noscreenshot"), |
259 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NO_SCREENSHOT)); | 279 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NO_SCREENSHOT)); |
260 | 280 |
261 localized_strings.SetString(std::string("send-report"), | 281 localized_strings.SetString(std::string("send-report"), |
262 l10n_util::GetStringUTF8(IDS_BUGREPORT_SEND_REPORT)); | 282 l10n_util::GetStringUTF8(IDS_BUGREPORT_SEND_REPORT)); |
263 localized_strings.SetString(std::string("cancel"), | 283 localized_strings.SetString(std::string("cancel"), |
264 l10n_util::GetStringUTF8(IDS_CANCEL)); | 284 l10n_util::GetStringUTF8(IDS_CANCEL)); |
265 | 285 |
266 // Option strings for the "issue with" drop-down. | 286 // Option strings for the "issue with" drop-down. |
267 localized_strings.SetString(std::string("issue-choose"), | 287 localized_strings.SetString(std::string("issue-choose"), |
268 l10n_util::GetStringUTF8(IDS_BUGREPORT_CHOOSE_ISSUE)); | 288 l10n_util::GetStringUTF8(IDS_BUGREPORT_CHOOSE_ISSUE)); |
269 | 289 |
270 localized_strings.SetString(std::string("no-issue-selected"), | 290 localized_strings.SetString(std::string("no-issue-selected"), |
271 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_ISSUE_SELECTED)); | 291 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_ISSUE_SELECTED)); |
272 | 292 |
293 localized_strings.SetString(std::string("no-description"), | |
294 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_DESCRIPTION)); | |
295 | |
296 localized_strings.SetString(std::string("no-saved-screenshots"), | |
297 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_SAVED_SCREENSHOTS_HELP)); | |
298 | |
299 localized_strings.SetString(std::string("privacy-note"), | |
300 l10n_util::GetStringUTF8(IDS_BUGREPORT_PRIVACY_NOTE)); | |
273 | 301 |
274 // TODO(rkc): Find some way to ensure this order of dropdowns is in sync | 302 // TODO(rkc): Find some way to ensure this order of dropdowns is in sync |
275 // with the order in the userfeedback ChromeData proto buffer | 303 // with the order in the userfeedback ChromeData proto buffer |
276 #if defined(OS_CHROMEOS) | 304 #if defined(OS_CHROMEOS) |
277 // Dropdown for ChromeOS: | 305 // Dropdown for ChromeOS: |
278 // | 306 // |
279 // Connectivity | 307 // Connectivity |
280 // Sync | 308 // Sync |
281 // Crash | 309 // Crash |
282 // Page Formatting | 310 // Page Formatting |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 SetupScreenshotsSource(); | 518 SetupScreenshotsSource(); |
491 | 519 |
492 return base::StringPiece( | 520 return base::StringPiece( |
493 ResourceBundle::GetSharedInstance().GetRawDataResource( | 521 ResourceBundle::GetSharedInstance().GetRawDataResource( |
494 IDR_BUGREPORT_HTML)); | 522 IDR_BUGREPORT_HTML)); |
495 } | 523 } |
496 | 524 |
497 void BugReportHandler::RegisterMessages() { | 525 void BugReportHandler::RegisterMessages() { |
498 dom_ui_->RegisterMessageCallback("getDialogDefaults", | 526 dom_ui_->RegisterMessageCallback("getDialogDefaults", |
499 NewCallback(this, &BugReportHandler::HandleGetDialogDefaults)); | 527 NewCallback(this, &BugReportHandler::HandleGetDialogDefaults)); |
500 dom_ui_->RegisterMessageCallback("refreshScreenshots", | 528 dom_ui_->RegisterMessageCallback("refreshCurrentScreenshot", |
501 NewCallback(this, &BugReportHandler::HandleRefreshScreenshots)); | 529 NewCallback(this, &BugReportHandler::HandleRefreshCurrentScreenshot)); |
530 #if defined(OS_CHROMEOS) | |
531 dom_ui_->RegisterMessageCallback("refreshSavedScreenshots", | |
532 NewCallback(this, &BugReportHandler::HandleRefreshSavedScreenshots)); | |
533 #endif | |
502 dom_ui_->RegisterMessageCallback("sendReport", | 534 dom_ui_->RegisterMessageCallback("sendReport", |
503 NewCallback(this, &BugReportHandler::HandleSendReport)); | 535 NewCallback(this, &BugReportHandler::HandleSendReport)); |
504 dom_ui_->RegisterMessageCallback("cancel", | 536 dom_ui_->RegisterMessageCallback("cancel", |
505 NewCallback(this, &BugReportHandler::HandleCancel)); | 537 NewCallback(this, &BugReportHandler::HandleCancel)); |
506 dom_ui_->RegisterMessageCallback("openSystemTab", | 538 dom_ui_->RegisterMessageCallback("openSystemTab", |
507 NewCallback(this, &BugReportHandler::HandleOpenSystemTab)); | 539 NewCallback(this, &BugReportHandler::HandleOpenSystemTab)); |
508 } | 540 } |
509 | 541 |
510 void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { | 542 void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { |
511 bug_report_ = new BugReportData(); | 543 bug_report_ = new BugReportData(); |
(...skipping 18 matching lines...) Expand all Loading... | |
530 true, true, &syslogs_consumer_, | 562 true, true, &syslogs_consumer_, |
531 NewCallback(bug_report_, &BugReportData::SyslogsComplete)); | 563 NewCallback(bug_report_, &BugReportData::SyslogsComplete)); |
532 } | 564 } |
533 // 2: user e-mail | 565 // 2: user e-mail |
534 dialog_defaults.Append(new StringValue(GetUserEmail())); | 566 dialog_defaults.Append(new StringValue(GetUserEmail())); |
535 #endif | 567 #endif |
536 | 568 |
537 dom_ui_->CallJavascriptFunction(L"setupDialogDefaults", dialog_defaults); | 569 dom_ui_->CallJavascriptFunction(L"setupDialogDefaults", dialog_defaults); |
538 } | 570 } |
539 | 571 |
540 void BugReportHandler::HandleRefreshScreenshots(const ListValue*) { | 572 void BugReportHandler::HandleRefreshCurrentScreenshot(const ListValue*) { |
541 ListValue screenshots; | 573 std::string current_screenshot(kCurrentScreenshotUrl); |
542 screenshots.Append(new StringValue(std::string(kCurrentScreenshotUrl))); | 574 StringValue screenshot(current_screenshot); |
575 dom_ui_->CallJavascriptFunction(L"setupCurrentScreenshot", screenshot); | |
576 } | |
543 | 577 |
544 | 578 |
545 #if defined(OS_CHROMEOS) | 579 #if defined(OS_CHROMEOS) |
580 void BugReportHandler::HandleRefreshSavedScreenshots(const ListValue*) { | |
546 std::vector<std::string> saved_screenshots; | 581 std::vector<std::string> saved_screenshots; |
547 GetScreenshotUrls(&saved_screenshots); | 582 GetScreenshotUrls(&saved_screenshots); |
548 | 583 |
549 ListValue* saved_screenshot_list = new ListValue(); | 584 ListValue screenshots_list; |
550 for (size_t i = 0; i < saved_screenshots.size(); ++i) | 585 for (size_t i = 0; i < saved_screenshots.size(); ++i) |
551 saved_screenshot_list->Append(new StringValue(saved_screenshots[i])); | 586 screenshots_list.Append(new StringValue(saved_screenshots[i])); |
552 screenshots.Append(saved_screenshot_list); | 587 dom_ui_->CallJavascriptFunction(L"setupSavedScreenshots", screenshots_list); |
588 } | |
553 #endif | 589 #endif |
554 dom_ui_->CallJavascriptFunction(L"setupScreenshots", screenshots); | 590 |
555 } | |
556 | 591 |
557 void BugReportHandler::HandleSendReport(const ListValue* list_value) { | 592 void BugReportHandler::HandleSendReport(const ListValue* list_value) { |
558 ListValue::const_iterator i = list_value->begin(); | 593 ListValue::const_iterator i = list_value->begin(); |
559 if (i == list_value->end()) { | 594 if (i == list_value->end()) { |
560 LOG(ERROR) << "Incorrect data passed to sendReport."; | 595 LOG(ERROR) << "Incorrect data passed to sendReport."; |
561 return; | 596 return; |
562 } | 597 } |
563 | 598 |
564 // #0 - Problem type. | 599 // #0 - Problem type. |
565 int problem_type; | 600 int problem_type; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 BugReportUIHTMLSource* html_source = | 740 BugReportUIHTMLSource* html_source = |
706 new BugReportUIHTMLSource(handler->Init()); | 741 new BugReportUIHTMLSource(handler->Init()); |
707 // Set up the chrome://bugreport/ source. | 742 // Set up the chrome://bugreport/ source. |
708 BrowserThread::PostTask( | 743 BrowserThread::PostTask( |
709 BrowserThread::IO, FROM_HERE, | 744 BrowserThread::IO, FROM_HERE, |
710 NewRunnableMethod( | 745 NewRunnableMethod( |
711 Singleton<ChromeURLDataManager>::get(), | 746 Singleton<ChromeURLDataManager>::get(), |
712 &ChromeURLDataManager::AddDataSource, | 747 &ChromeURLDataManager::AddDataSource, |
713 make_scoped_refptr(html_source))); | 748 make_scoped_refptr(html_source))); |
714 } | 749 } |
OLD | NEW |