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/feedback_ui.h" | 5 #include "chrome/browser/ui/webui/feedback_ui.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
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/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/download/download_prefs.h" | 20 #include "chrome/browser/download/download_prefs.h" |
21 #include "chrome/browser/feedback/feedback_data.h" | 21 #include "chrome/browser/feedback/feedback_data.h" |
22 #include "chrome/browser/feedback/feedback_util.h" | 22 #include "chrome/browser/feedback/feedback_util.h" |
23 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/signin/signin_manager.h" |
| 27 #include "chrome/browser/signin/signin_manager_factory.h" |
25 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/browser_tabstrip.h" | 30 #include "chrome/browser/ui/browser_tabstrip.h" |
28 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
29 #include "chrome/browser/ui/singleton_tabs.h" | 32 #include "chrome/browser/ui/singleton_tabs.h" |
30 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 33 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
31 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 34 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
32 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 35 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
33 #include "chrome/browser/ui/webui/screenshot_source.h" | 36 #include "chrome/browser/ui/webui/screenshot_source.h" |
34 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | 37 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 110 } |
108 | 111 |
109 std::string GetUserEmail() { | 112 std::string GetUserEmail() { |
110 chromeos::UserManager* manager = chromeos::UserManager::Get(); | 113 chromeos::UserManager* manager = chromeos::UserManager::Get(); |
111 if (!manager) | 114 if (!manager) |
112 return std::string(); | 115 return std::string(); |
113 else | 116 else |
114 return manager->GetLoggedInUser().display_email(); | 117 return manager->GetLoggedInUser().display_email(); |
115 } | 118 } |
116 | 119 |
| 120 #else |
| 121 |
| 122 std::string GetUserEmail() { |
| 123 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 124 if (!profile) |
| 125 return std::string(); |
| 126 |
| 127 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); |
| 128 if (!signin) |
| 129 return std::string(); |
| 130 |
| 131 return signin->GetAuthenticatedUsername(); |
| 132 } |
| 133 |
117 #endif // OS_CHROMEOS | 134 #endif // OS_CHROMEOS |
118 | 135 |
119 // Returns the index of the feedback tab if already open, -1 otherwise | 136 // Returns the index of the feedback tab if already open, -1 otherwise |
120 int GetIndexOfFeedbackTab(Browser* browser) { | 137 int GetIndexOfFeedbackTab(Browser* browser) { |
121 GURL feedback_url(chrome::kChromeUIFeedbackURL); | 138 GURL feedback_url(chrome::kChromeUIFeedbackURL); |
122 for (int i = 0; i < browser->tab_count(); ++i) { | 139 for (int i = 0; i < browser->tab_count(); ++i) { |
123 WebContents* tab = chrome::GetWebContentsAt(browser, i); | 140 WebContents* tab = chrome::GetWebContentsAt(browser, i); |
124 if (tab && tab->GetURL().GetWithEmptyPath() == feedback_url) | 141 if (tab && tab->GetURL().GetWithEmptyPath() == feedback_url) |
125 return i; | 142 return i; |
126 } | 143 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 source->set_use_json_js_format_v2(); | 262 source->set_use_json_js_format_v2(); |
246 | 263 |
247 source->AddLocalizedString("title", IDS_FEEDBACK_TITLE); | 264 source->AddLocalizedString("title", IDS_FEEDBACK_TITLE); |
248 source->AddLocalizedString("page-title", IDS_FEEDBACK_REPORT_PAGE_TITLE); | 265 source->AddLocalizedString("page-title", IDS_FEEDBACK_REPORT_PAGE_TITLE); |
249 source->AddLocalizedString("page-url", IDS_FEEDBACK_REPORT_URL_LABEL); | 266 source->AddLocalizedString("page-url", IDS_FEEDBACK_REPORT_URL_LABEL); |
250 source->AddLocalizedString("description", IDS_FEEDBACK_DESCRIPTION_LABEL); | 267 source->AddLocalizedString("description", IDS_FEEDBACK_DESCRIPTION_LABEL); |
251 source->AddLocalizedString("current-screenshot", | 268 source->AddLocalizedString("current-screenshot", |
252 IDS_FEEDBACK_SCREENSHOT_LABEL); | 269 IDS_FEEDBACK_SCREENSHOT_LABEL); |
253 source->AddLocalizedString("saved-screenshot", | 270 source->AddLocalizedString("saved-screenshot", |
254 IDS_FEEDBACK_SAVED_SCREENSHOT_LABEL); | 271 IDS_FEEDBACK_SAVED_SCREENSHOT_LABEL); |
| 272 source->AddLocalizedString("user-email", IDS_FEEDBACK_USER_EMAIL_LABEL); |
| 273 |
255 #if defined(OS_CHROMEOS) | 274 #if defined(OS_CHROMEOS) |
256 source->AddLocalizedString("user-email", IDS_FEEDBACK_USER_EMAIL_LABEL); | |
257 source->AddLocalizedString("sysinfo", | 275 source->AddLocalizedString("sysinfo", |
258 IDS_FEEDBACK_INCLUDE_SYSTEM_INFORMATION_CHKBOX); | 276 IDS_FEEDBACK_INCLUDE_SYSTEM_INFORMATION_CHKBOX); |
259 source->AddLocalizedString("currentscreenshots", | 277 source->AddLocalizedString("currentscreenshots", |
260 IDS_FEEDBACK_CURRENT_SCREENSHOTS); | 278 IDS_FEEDBACK_CURRENT_SCREENSHOTS); |
261 source->AddLocalizedString("savedscreenshots", | 279 source->AddLocalizedString("savedscreenshots", |
262 IDS_FEEDBACK_SAVED_SCREENSHOTS); | 280 IDS_FEEDBACK_SAVED_SCREENSHOTS); |
263 source->AddLocalizedString("choose-different-screenshot", | 281 source->AddLocalizedString("choose-different-screenshot", |
264 IDS_FEEDBACK_CHOOSE_DIFFERENT_SCREENSHOT); | 282 IDS_FEEDBACK_CHOOSE_DIFFERENT_SCREENSHOT); |
265 source->AddLocalizedString("choose-original-screenshot", | 283 source->AddLocalizedString("choose-original-screenshot", |
266 IDS_FEEDBACK_CHOOSE_ORIGINAL_SCREENSHOT); | 284 IDS_FEEDBACK_CHOOSE_ORIGINAL_SCREENSHOT); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 DictionaryValue dialog_defaults; | 464 DictionaryValue dialog_defaults; |
447 | 465 |
448 // Current url. | 466 // Current url. |
449 dialog_defaults.SetString("currentUrl", target_tab_url_); | 467 dialog_defaults.SetString("currentUrl", target_tab_url_); |
450 | 468 |
451 // Are screenshots disabled? | 469 // Are screenshots disabled? |
452 dialog_defaults.SetBoolean( | 470 dialog_defaults.SetBoolean( |
453 "disableScreenshots", | 471 "disableScreenshots", |
454 g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots)); | 472 g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots)); |
455 | 473 |
| 474 // User e-mail |
| 475 std::string user_email = GetUserEmail(); |
| 476 dialog_defaults.SetString("userEmail", user_email); |
| 477 |
456 #if defined(OS_CHROMEOS) | 478 #if defined(OS_CHROMEOS) |
457 // Trigger the request for system information here. | 479 // Trigger the request for system information here. |
458 chromeos::system::SyslogsProvider* provider = | 480 chromeos::system::SyslogsProvider* provider = |
459 chromeos::system::SyslogsProvider::GetInstance(); | 481 chromeos::system::SyslogsProvider::GetInstance(); |
460 if (provider) { | 482 if (provider) { |
461 syslogs_handle_ = provider->RequestSyslogs( | 483 syslogs_handle_ = provider->RequestSyslogs( |
462 true, // don't compress. | 484 true, // don't compress. |
463 chromeos::system::SyslogsProvider::SYSLOGS_FEEDBACK, | 485 chromeos::system::SyslogsProvider::SYSLOGS_FEEDBACK, |
464 &syslogs_consumer_, | 486 &syslogs_consumer_, |
465 base::Bind(&FeedbackData::SyslogsComplete, | 487 base::Bind(&FeedbackData::SyslogsComplete, |
466 base::Unretained(feedback_data_))); | 488 base::Unretained(feedback_data_))); |
467 } | 489 } |
468 // User e-mail | 490 |
469 dialog_defaults.SetString("userEmail", GetUserEmail()); | 491 // On ChromeOS if the user's email is blank, it means we don't |
| 492 // have a logged in user, hence don't use saved screenshots. |
| 493 dialog_defaults.SetBoolean("useSaved", !user_email.empty()); |
470 #endif | 494 #endif |
471 | 495 |
472 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults); | 496 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults); |
473 } | 497 } |
474 | 498 |
475 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) { | 499 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) { |
476 std::string current_screenshot(kCurrentScreenshotUrl); | 500 std::string current_screenshot(kCurrentScreenshotUrl); |
477 StringValue screenshot(current_screenshot); | 501 StringValue screenshot(current_screenshot); |
478 web_ui()->CallJavascriptFunction("setupCurrentScreenshot", screenshot); | 502 web_ui()->CallJavascriptFunction("setupCurrentScreenshot", screenshot); |
479 } | 503 } |
(...skipping 21 matching lines...) Expand all Loading... |
501 | 525 |
502 void FeedbackHandler::HandleSendReport(const ListValue* list_value) { | 526 void FeedbackHandler::HandleSendReport(const ListValue* list_value) { |
503 if (!feedback_data_) { | 527 if (!feedback_data_) { |
504 LOG(ERROR) << "Bug report hasn't been intialized yet."; | 528 LOG(ERROR) << "Bug report hasn't been intialized yet."; |
505 return; | 529 return; |
506 } | 530 } |
507 // TODO(rkc): Find a better way to do this check. | 531 // TODO(rkc): Find a better way to do this check. |
508 #if defined(OS_CHROMEOS) | 532 #if defined(OS_CHROMEOS) |
509 if (list_value->GetSize() != 6) { | 533 if (list_value->GetSize() != 6) { |
510 #else | 534 #else |
511 if (list_value->GetSize() != 4) { | 535 if (list_value->GetSize() != 5) { |
512 #endif | 536 #endif |
513 LOG(ERROR) << "Feedback data corrupt! Feedback not sent."; | 537 LOG(ERROR) << "Feedback data corrupt! Feedback not sent."; |
514 return; | 538 return; |
515 } | 539 } |
516 | 540 |
517 ListValue::const_iterator i = list_value->begin(); | 541 ListValue::const_iterator i = list_value->begin(); |
518 std::string page_url; | 542 std::string page_url; |
519 (*i++)->GetAsString(&page_url); | 543 (*i++)->GetAsString(&page_url); |
520 std::string category_tag; | 544 std::string category_tag; |
521 (*i++)->GetAsString(&category_tag); | 545 (*i++)->GetAsString(&category_tag); |
522 std::string description; | 546 std::string description; |
523 (*i++)->GetAsString(&description); | 547 (*i++)->GetAsString(&description); |
| 548 std::string user_email; |
| 549 (*i++)->GetAsString(&user_email); |
524 std::string screenshot_path; | 550 std::string screenshot_path; |
525 (*i++)->GetAsString(&screenshot_path); | 551 (*i++)->GetAsString(&screenshot_path); |
526 screenshot_path.erase(0, strlen(kScreenshotBaseUrl)); | 552 screenshot_path.erase(0, strlen(kScreenshotBaseUrl)); |
527 | 553 |
528 // Get the image to send in the report. | 554 // Get the image to send in the report. |
529 ScreenshotDataPtr image_ptr; | 555 ScreenshotDataPtr image_ptr; |
530 if (!screenshot_path.empty() && screenshot_source_) | 556 if (!screenshot_path.empty() && screenshot_source_) |
531 image_ptr = screenshot_source_->GetCachedScreenshot(screenshot_path); | 557 image_ptr = screenshot_source_->GetCachedScreenshot(screenshot_path); |
532 | 558 |
533 #if defined(OS_CHROMEOS) | 559 #if defined(OS_CHROMEOS) |
534 std::string user_email; | |
535 (*i++)->GetAsString(&user_email); | |
536 std::string sys_info_checkbox; | 560 std::string sys_info_checkbox; |
537 (*i++)->GetAsString(&sys_info_checkbox); | 561 (*i++)->GetAsString(&sys_info_checkbox); |
538 bool send_sys_info = (sys_info_checkbox == "true"); | 562 bool send_sys_info = (sys_info_checkbox == "true"); |
539 | 563 |
540 // If we aren't sending the sys_info, cancel the gathering of the syslogs. | 564 // If we aren't sending the sys_info, cancel the gathering of the syslogs. |
541 if (!send_sys_info) | 565 if (!send_sys_info) |
542 CancelFeedbackCollection(); | 566 CancelFeedbackCollection(); |
543 #endif | 567 #endif |
544 | 568 |
545 // Update the data in feedback_data_ so it can be sent | 569 // Update the data in feedback_data_ so it can be sent |
546 feedback_data_->UpdateData(Profile::FromWebUI(web_ui()) | 570 feedback_data_->UpdateData(Profile::FromWebUI(web_ui()) |
547 , target_tab_url_ | 571 , target_tab_url_ |
548 , std::string() | 572 , std::string() |
549 , page_url | 573 , page_url |
550 , description | 574 , description |
| 575 , user_email |
551 , image_ptr | 576 , image_ptr |
552 #if defined(OS_CHROMEOS) | 577 #if defined(OS_CHROMEOS) |
553 , user_email | |
554 , send_sys_info | 578 , send_sys_info |
555 , false // sent_report | 579 , false // sent_report |
556 , timestamp_ | 580 , timestamp_ |
557 #endif | 581 #endif |
558 ); | 582 ); |
559 | 583 |
560 #if defined(OS_CHROMEOS) | 584 #if defined(OS_CHROMEOS) |
561 // If we don't require sys_info, or we have it, or we never requested it | 585 // If we don't require sys_info, or we have it, or we never requested it |
562 // (because libcros failed to load), then send the report now. | 586 // (because libcros failed to load), then send the report now. |
563 // Otherwise, the report will get sent when we receive sys_info. | 587 // Otherwise, the report will get sent when we receive sys_info. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); | 673 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); |
650 std::partial_sort(screenshot_filepaths.begin(), | 674 std::partial_sort(screenshot_filepaths.begin(), |
651 screenshot_filepaths.begin() + sort_size, | 675 screenshot_filepaths.begin() + sort_size, |
652 screenshot_filepaths.end(), | 676 screenshot_filepaths.end(), |
653 ScreenshotTimestampComp); | 677 ScreenshotTimestampComp); |
654 for (size_t i = 0; i < sort_size; ++i) | 678 for (size_t i = 0; i < sort_size; ++i) |
655 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + | 679 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + |
656 screenshot_filepaths[i]); | 680 screenshot_filepaths[i]); |
657 } | 681 } |
658 #endif | 682 #endif |
OLD | NEW |