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