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 43 matching lines...) Loading... | |
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 static const char kScreenshotBaseUrl[] = "chrome://screenshots/"; |
58 static const char kCurrentScreenshotUrl[] = "chrome://screenshots/current"; | 58 static 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 static const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/"; |
61 | 61 |
62 static const char kScreenshotPattern[] = "*.png"; | 62 static const char kScreenshotPattern[] = "*.png"; |
63 static const char kScreenshotsRelativePath[] = "/Screenshots"; | 63 static const char kScreenshotsRelativePath[] = "/Screenshots"; |
64 | |
65 static const size_t kMaxSavedScreenshots = 2; | |
oshima
2010/11/29 19:09:22
while we're at it,can you change the above static
rkc
2010/11/29 22:41:08
Done.
| |
66 | |
64 #endif | 67 #endif |
65 | 68 |
66 namespace { | 69 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...) 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 void HandleRefreshSavedScreenshots(const ListValue* args); | |
194 void HandleSendReport(const ListValue* args); | 201 void HandleSendReport(const ListValue* args); |
195 void HandleCancel(const ListValue* args); | 202 void HandleCancel(const ListValue* args); |
196 void HandleOpenSystemTab(const ListValue* args); | 203 void HandleOpenSystemTab(const ListValue* args); |
197 | 204 |
198 void SetupScreenshotsSource(); | 205 void SetupScreenshotsSource(); |
199 void ClobberScreenshotsSource(); | 206 void ClobberScreenshotsSource(); |
200 | 207 |
201 void CancelFeedbackCollection(); | 208 void CancelFeedbackCollection(); |
202 void CloseFeedbackTab(); | 209 void CloseFeedbackTab(); |
203 | 210 |
(...skipping 22 matching lines...) Loading... | |
226 : DataSource(chrome::kChromeUIBugReportHost, MessageLoop::current()) { | 233 : DataSource(chrome::kChromeUIBugReportHost, MessageLoop::current()) { |
227 bug_report_html_ = html; | 234 bug_report_html_ = html; |
228 } | 235 } |
229 | 236 |
230 void BugReportUIHTMLSource::StartDataRequest(const std::string& path, | 237 void BugReportUIHTMLSource::StartDataRequest(const std::string& path, |
231 bool is_off_the_record, | 238 bool is_off_the_record, |
232 int request_id) { | 239 int request_id) { |
233 DictionaryValue localized_strings; | 240 DictionaryValue localized_strings; |
234 localized_strings.SetString(std::string("title"), | 241 localized_strings.SetString(std::string("title"), |
235 l10n_util::GetStringUTF8(IDS_BUGREPORT_TITLE)); | 242 l10n_util::GetStringUTF8(IDS_BUGREPORT_TITLE)); |
243 localized_strings.SetString(std::string("page-title"), | |
244 l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_PAGE_TITLE)); | |
236 localized_strings.SetString(std::string("issue-with"), | 245 localized_strings.SetString(std::string("issue-with"), |
237 l10n_util::GetStringUTF8(IDS_BUGREPORT_ISSUE_WITH)); | 246 l10n_util::GetStringUTF8(IDS_BUGREPORT_ISSUE_WITH)); |
238 localized_strings.SetString(std::string("page-url"), | 247 localized_strings.SetString(std::string("page-url"), |
239 l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_URL_LABEL)); | 248 l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_URL_LABEL)); |
240 localized_strings.SetString(std::string("description"), | 249 localized_strings.SetString(std::string("description"), |
241 l10n_util::GetStringUTF8(IDS_BUGREPORT_DESCRIPTION_LABEL)); | 250 l10n_util::GetStringUTF8(IDS_BUGREPORT_DESCRIPTION_LABEL)); |
242 localized_strings.SetString(std::string("screenshot"), | 251 localized_strings.SetString(std::string("current-screenshot"), |
243 l10n_util::GetStringUTF8(IDS_BUGREPORT_SCREENSHOT_LABEL)); | 252 l10n_util::GetStringUTF8(IDS_BUGREPORT_SCREENSHOT_LABEL)); |
253 localized_strings.SetString(std::string("saved-screenshot"), | |
254 l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOT_LABEL)); | |
244 #if defined(OS_CHROMEOS) | 255 #if defined(OS_CHROMEOS) |
245 localized_strings.SetString(std::string("user-email"), | 256 localized_strings.SetString(std::string("user-email"), |
246 l10n_util::GetStringUTF8(IDS_BUGREPORT_USER_EMAIL_LABEL)); | 257 l10n_util::GetStringUTF8(IDS_BUGREPORT_USER_EMAIL_LABEL)); |
258 localized_strings.SetString(std::string("sysinfo"), | |
259 l10n_util::GetStringUTF8( | |
260 IDS_BUGREPORT_INCLUDE_SYSTEM_INFORMATION_CHKBOX)); | |
261 | |
247 localized_strings.SetString(std::string("currentscreenshots"), | 262 localized_strings.SetString(std::string("currentscreenshots"), |
248 l10n_util::GetStringUTF8(IDS_BUGREPORT_CURRENT_SCREENSHOTS)); | 263 l10n_util::GetStringUTF8(IDS_BUGREPORT_CURRENT_SCREENSHOTS)); |
249 localized_strings.SetString(std::string("savedscreenshots"), | 264 localized_strings.SetString(std::string("savedscreenshots"), |
250 l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOTS)); | 265 l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOTS)); |
251 localized_strings.SetString(std::string("sysinfo"), | 266 |
267 localized_strings.SetString(std::string("choose-different-screenshot"), | |
252 l10n_util::GetStringUTF8( | 268 l10n_util::GetStringUTF8( |
253 IDS_BUGREPORT_INCLUDE_SYSTEM_INFORMATION_CHKBOX)); | 269 IDS_BUGREPORT_CHOOSE_DIFFERENT_SCREENSHOT)); |
270 localized_strings.SetString(std::string("choose-original-screenshot"), | |
271 l10n_util::GetStringUTF8( | |
272 IDS_BUGREPORT_CHOOSE_ORIGINAL_SCREENSHOT)); | |
254 #else | 273 #else |
255 localized_strings.SetString(std::string("currentscreenshots"), | 274 localized_strings.SetString(std::string("currentscreenshots"), |
256 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NEW_SCREEN_IMAGE)); | 275 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NEW_SCREEN_IMAGE)); |
257 #endif | 276 #endif |
258 localized_strings.SetString(std::string("noscreenshot"), | 277 localized_strings.SetString(std::string("noscreenshot"), |
259 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NO_SCREENSHOT)); | 278 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NO_SCREENSHOT)); |
260 | 279 |
261 localized_strings.SetString(std::string("send-report"), | 280 localized_strings.SetString(std::string("send-report"), |
262 l10n_util::GetStringUTF8(IDS_BUGREPORT_SEND_REPORT)); | 281 l10n_util::GetStringUTF8(IDS_BUGREPORT_SEND_REPORT)); |
263 localized_strings.SetString(std::string("cancel"), | 282 localized_strings.SetString(std::string("cancel"), |
264 l10n_util::GetStringUTF8(IDS_CANCEL)); | 283 l10n_util::GetStringUTF8(IDS_CANCEL)); |
265 | 284 |
266 // Option strings for the "issue with" drop-down. | 285 // Option strings for the "issue with" drop-down. |
267 localized_strings.SetString(std::string("issue-choose"), | 286 localized_strings.SetString(std::string("issue-choose"), |
268 l10n_util::GetStringUTF8(IDS_BUGREPORT_CHOOSE_ISSUE)); | 287 l10n_util::GetStringUTF8(IDS_BUGREPORT_CHOOSE_ISSUE)); |
269 | 288 |
270 localized_strings.SetString(std::string("no-issue-selected"), | 289 localized_strings.SetString(std::string("no-issue-selected"), |
271 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_ISSUE_SELECTED)); | 290 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_ISSUE_SELECTED)); |
272 | 291 |
292 localized_strings.SetString(std::string("no-description"), | |
293 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_DESCRIPTION)); | |
294 | |
295 localized_strings.SetString(std::string("no-saved-screenshots"), | |
296 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_SAVED_SCREENSHOTS_HELP)); | |
297 | |
298 localized_strings.SetString(std::string("privacy-note"), | |
299 l10n_util::GetStringUTF8(IDS_BUGREPORT_PRIVACY_NOTE)); | |
273 | 300 |
274 // TODO(rkc): Find some way to ensure this order of dropdowns is in sync | 301 // TODO(rkc): Find some way to ensure this order of dropdowns is in sync |
275 // with the order in the userfeedback ChromeData proto buffer | 302 // with the order in the userfeedback ChromeData proto buffer |
276 #if defined(OS_CHROMEOS) | 303 #if defined(OS_CHROMEOS) |
277 // Dropdown for ChromeOS: | 304 // Dropdown for ChromeOS: |
278 // | 305 // |
279 // Connectivity | 306 // Connectivity |
280 // Sync | 307 // Sync |
281 // Crash | 308 // Crash |
282 // Page Formatting | 309 // Page Formatting |
(...skipping 207 matching lines...) Loading... | |
490 SetupScreenshotsSource(); | 517 SetupScreenshotsSource(); |
491 | 518 |
492 return base::StringPiece( | 519 return base::StringPiece( |
493 ResourceBundle::GetSharedInstance().GetRawDataResource( | 520 ResourceBundle::GetSharedInstance().GetRawDataResource( |
494 IDR_BUGREPORT_HTML)); | 521 IDR_BUGREPORT_HTML)); |
495 } | 522 } |
496 | 523 |
497 void BugReportHandler::RegisterMessages() { | 524 void BugReportHandler::RegisterMessages() { |
498 dom_ui_->RegisterMessageCallback("getDialogDefaults", | 525 dom_ui_->RegisterMessageCallback("getDialogDefaults", |
499 NewCallback(this, &BugReportHandler::HandleGetDialogDefaults)); | 526 NewCallback(this, &BugReportHandler::HandleGetDialogDefaults)); |
500 dom_ui_->RegisterMessageCallback("refreshScreenshots", | 527 dom_ui_->RegisterMessageCallback("refreshCurrentScreenshot", |
501 NewCallback(this, &BugReportHandler::HandleRefreshScreenshots)); | 528 NewCallback(this, &BugReportHandler::HandleRefreshCurrentScreenshot)); |
529 dom_ui_->RegisterMessageCallback("refreshSavedScreenshots", | |
530 NewCallback(this, &BugReportHandler::HandleRefreshSavedScreenshots)); | |
502 dom_ui_->RegisterMessageCallback("sendReport", | 531 dom_ui_->RegisterMessageCallback("sendReport", |
503 NewCallback(this, &BugReportHandler::HandleSendReport)); | 532 NewCallback(this, &BugReportHandler::HandleSendReport)); |
504 dom_ui_->RegisterMessageCallback("cancel", | 533 dom_ui_->RegisterMessageCallback("cancel", |
505 NewCallback(this, &BugReportHandler::HandleCancel)); | 534 NewCallback(this, &BugReportHandler::HandleCancel)); |
506 dom_ui_->RegisterMessageCallback("openSystemTab", | 535 dom_ui_->RegisterMessageCallback("openSystemTab", |
507 NewCallback(this, &BugReportHandler::HandleOpenSystemTab)); | 536 NewCallback(this, &BugReportHandler::HandleOpenSystemTab)); |
508 } | 537 } |
509 | 538 |
510 void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { | 539 void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { |
511 bug_report_ = new BugReportData(); | 540 bug_report_ = new BugReportData(); |
(...skipping 18 matching lines...) Loading... | |
530 true, true, &syslogs_consumer_, | 559 true, true, &syslogs_consumer_, |
531 NewCallback(bug_report_, &BugReportData::SyslogsComplete)); | 560 NewCallback(bug_report_, &BugReportData::SyslogsComplete)); |
532 } | 561 } |
533 // 2: user e-mail | 562 // 2: user e-mail |
534 dialog_defaults.Append(new StringValue(GetUserEmail())); | 563 dialog_defaults.Append(new StringValue(GetUserEmail())); |
535 #endif | 564 #endif |
536 | 565 |
537 dom_ui_->CallJavascriptFunction(L"setupDialogDefaults", dialog_defaults); | 566 dom_ui_->CallJavascriptFunction(L"setupDialogDefaults", dialog_defaults); |
538 } | 567 } |
539 | 568 |
540 void BugReportHandler::HandleRefreshScreenshots(const ListValue*) { | 569 void BugReportHandler::HandleRefreshCurrentScreenshot(const ListValue*) { |
541 ListValue screenshots; | 570 std::string current_screenshot(kCurrentScreenshotUrl); |
542 screenshots.Append(new StringValue(std::string(kCurrentScreenshotUrl))); | 571 StringValue screenshot(current_screenshot); |
572 dom_ui_->CallJavascriptFunction(L"setupCurrentScreenshot", screenshot); | |
573 } | |
543 | 574 |
544 | 575 |
545 #if defined(OS_CHROMEOS) | 576 #if defined(OS_CHROMEOS) |
oshima
2010/11/29 19:09:22
Don't you have to "ifdefined" the declaration and
rkc
2010/11/29 22:41:08
Fixed (all other places)
Done.
| |
577 void BugReportHandler::HandleRefreshSavedScreenshots(const ListValue*) { | |
546 std::vector<std::string> saved_screenshots; | 578 std::vector<std::string> saved_screenshots; |
547 GetScreenshotUrls(&saved_screenshots); | 579 GetScreenshotUrls(&saved_screenshots); |
548 | 580 |
549 ListValue* saved_screenshot_list = new ListValue(); | 581 ListValue screenshots_list; |
550 for (size_t i = 0; i < saved_screenshots.size(); ++i) | 582 for (size_t i = 0; i < saved_screenshots.size(); ++i) |
551 saved_screenshot_list->Append(new StringValue(saved_screenshots[i])); | 583 screenshots_list.Append(new StringValue(saved_screenshots[i])); |
552 screenshots.Append(saved_screenshot_list); | 584 dom_ui_->CallJavascriptFunction(L"setupSavedScreenshots", screenshots_list); |
585 } | |
553 #endif | 586 #endif |
554 dom_ui_->CallJavascriptFunction(L"setupScreenshots", screenshots); | 587 |
555 } | |
556 | 588 |
557 void BugReportHandler::HandleSendReport(const ListValue* list_value) { | 589 void BugReportHandler::HandleSendReport(const ListValue* list_value) { |
558 ListValue::const_iterator i = list_value->begin(); | 590 ListValue::const_iterator i = list_value->begin(); |
559 if (i == list_value->end()) { | 591 if (i == list_value->end()) { |
560 LOG(ERROR) << "Incorrect data passed to sendReport."; | 592 LOG(ERROR) << "Incorrect data passed to sendReport."; |
561 return; | 593 return; |
562 } | 594 } |
563 | 595 |
564 // #0 - Problem type. | 596 // #0 - Problem type. |
565 int problem_type; | 597 int problem_type; |
(...skipping 139 matching lines...) Loading... | |
705 BugReportUIHTMLSource* html_source = | 737 BugReportUIHTMLSource* html_source = |
706 new BugReportUIHTMLSource(handler->Init()); | 738 new BugReportUIHTMLSource(handler->Init()); |
707 // Set up the chrome://bugreport/ source. | 739 // Set up the chrome://bugreport/ source. |
708 BrowserThread::PostTask( | 740 BrowserThread::PostTask( |
709 BrowserThread::IO, FROM_HERE, | 741 BrowserThread::IO, FROM_HERE, |
710 NewRunnableMethod( | 742 NewRunnableMethod( |
711 Singleton<ChromeURLDataManager>::get(), | 743 Singleton<ChromeURLDataManager>::get(), |
712 &ChromeURLDataManager::AddDataSource, | 744 &ChromeURLDataManager::AddDataSource, |
713 make_scoped_refptr(html_source))); | 745 make_scoped_refptr(html_source))); |
714 } | 746 } |
OLD | NEW |