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 <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "ui/aura/window.h" | 69 #include "ui/aura/window.h" |
70 #endif | 70 #endif |
71 | 71 |
72 using content::BrowserThread; | 72 using content::BrowserThread; |
73 using content::WebContents; | 73 using content::WebContents; |
74 using content::WebUIMessageHandler; | 74 using content::WebUIMessageHandler; |
75 using ui::WebDialogUI; | 75 using ui::WebDialogUI; |
76 | 76 |
77 namespace { | 77 namespace { |
78 | 78 |
79 const char kScreenshotBaseUrl[] = "chrome://screenshots/"; | |
80 const char kCurrentScreenshotUrl[] = "chrome://screenshots/current"; | |
81 | |
82 const char kCategoryTagParameter[] = "categoryTag="; | 79 const char kCategoryTagParameter[] = "categoryTag="; |
83 const char kDescriptionParameter[] = "description="; | 80 const char kDescriptionParameter[] = "description="; |
84 const char kSessionIDParameter[] = "session_id="; | 81 const char kSessionIDParameter[] = "session_id="; |
85 const char kTabIndexParameter[] = "tab_index="; | 82 const char kTabIndexParameter[] = "tab_index="; |
86 const char kCustomPageUrlParameter[] = "customPageUrl="; | 83 const char kCustomPageUrlParameter[] = "customPageUrl="; |
87 | 84 |
88 #if defined(OS_CHROMEOS) | 85 #if defined(OS_CHROMEOS) |
89 const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/"; | |
90 const char kScreenshotPrefix[] = "Screenshot "; | |
91 const char kScreenshotSuffix[] = ".png"; | |
92 | 86 |
93 const char kTimestampParameter[] = "timestamp="; | 87 const char kTimestampParameter[] = "timestamp="; |
94 | 88 |
95 const size_t kMaxSavedScreenshots = 2; | 89 const size_t kMaxSavedScreenshots = 2; |
96 #endif | |
97 | |
98 #if defined(OS_CHROMEOS) | |
99 size_t kMaxNumScanFiles = 1000; | 90 size_t kMaxNumScanFiles = 1000; |
100 | 91 |
101 // Compare two screenshot filepaths, which include the screenshot timestamp | 92 // Compare two screenshot filepaths, which include the screenshot timestamp |
102 // in the format of screenshot-yyyymmdd-hhmmss.png. Return true if |filepath1| | 93 // in the format of screenshot-yyyymmdd-hhmmss.png. Return true if |filepath1| |
103 // is more recent |filepath2|. | 94 // is more recent |filepath2|. |
104 bool ScreenshotTimestampComp(const std::string& filepath1, | 95 bool ScreenshotTimestampComp(const std::string& filepath1, |
105 const std::string& filepath2) { | 96 const std::string& filepath2) { |
106 return filepath1 > filepath2; | 97 return filepath1 > filepath2; |
107 } | 98 } |
108 | 99 |
(...skipping 19 matching lines...) Expand all Loading... |
128 scoped_ptr<gdata::DriveEntryProtoVector> entries) { | 119 scoped_ptr<gdata::DriveEntryProtoVector> entries) { |
129 if (error != gdata::DRIVE_FILE_OK) { | 120 if (error != gdata::DRIVE_FILE_OK) { |
130 callback.Run(); | 121 callback.Run(); |
131 return; | 122 return; |
132 } | 123 } |
133 | 124 |
134 size_t max_scan = std::min(kMaxNumScanFiles, entries->size()); | 125 size_t max_scan = std::min(kMaxNumScanFiles, entries->size()); |
135 std::vector<gdata::DriveEntryProto> screenshot_entries; | 126 std::vector<gdata::DriveEntryProto> screenshot_entries; |
136 for (size_t i = 0; i < max_scan; ++i) { | 127 for (size_t i = 0; i < max_scan; ++i) { |
137 const gdata::DriveEntryProto& entry = (*entries)[i]; | 128 const gdata::DriveEntryProto& entry = (*entries)[i]; |
138 if (StartsWithASCII(entry.base_name(), kScreenshotPrefix, true) && | 129 if (StartsWithASCII(entry.base_name(), |
139 EndsWith(entry.base_name(), kScreenshotSuffix, true)) { | 130 ScreenshotSource::kScreenshotPrefix, true) && |
| 131 EndsWith(entry.base_name(), |
| 132 ScreenshotSource::kScreenshotSuffix, true)) { |
140 screenshot_entries.push_back(entry); | 133 screenshot_entries.push_back(entry); |
141 } | 134 } |
142 } | 135 } |
143 | 136 |
144 size_t sort_size = std::min(max_saved, screenshot_entries.size()); | 137 size_t sort_size = std::min(max_saved, screenshot_entries.size()); |
145 std::partial_sort(screenshot_entries.begin(), | 138 std::partial_sort(screenshot_entries.begin(), |
146 screenshot_entries.begin() + sort_size, | 139 screenshot_entries.begin() + sort_size, |
147 screenshot_entries.end(), | 140 screenshot_entries.end(), |
148 ScreenshotDriveTimestampComp); | 141 ScreenshotDriveTimestampComp); |
149 for (size_t i = 0; i < sort_size; ++i) { | 142 for (size_t i = 0; i < sort_size; ++i) { |
150 const gdata::DriveEntryProto& entry = screenshot_entries[i]; | 143 const gdata::DriveEntryProto& entry = screenshot_entries[i]; |
151 saved_screenshots->push_back( | 144 saved_screenshots->push_back( |
152 std::string(kSavedScreenshotsUrl) + entry.resource_id()); | 145 std::string(ScreenshotSource::kScreenshotUrlRoot) + |
| 146 std::string(ScreenshotSource::kScreenshotSaved) + |
| 147 entry.resource_id()); |
153 } | 148 } |
154 callback.Run(); | 149 callback.Run(); |
155 } | 150 } |
156 | 151 |
157 #else | 152 #else |
158 | 153 |
159 std::string GetUserEmail() { | 154 std::string GetUserEmail() { |
160 Profile* profile = ProfileManager::GetLastUsedProfile(); | 155 Profile* profile = ProfileManager::GetLastUsedProfile(); |
161 if (!profile) | 156 if (!profile) |
162 return std::string(); | 157 return std::string(); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 536 |
542 // On ChromeOS if the user's email is blank, it means we don't | 537 // On ChromeOS if the user's email is blank, it means we don't |
543 // have a logged in user, hence don't use saved screenshots. | 538 // have a logged in user, hence don't use saved screenshots. |
544 dialog_defaults.SetBoolean("useSaved", !user_email.empty()); | 539 dialog_defaults.SetBoolean("useSaved", !user_email.empty()); |
545 #endif | 540 #endif |
546 | 541 |
547 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults); | 542 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults); |
548 } | 543 } |
549 | 544 |
550 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) { | 545 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) { |
551 std::string current_screenshot(kCurrentScreenshotUrl); | 546 std::string current_screenshot( |
| 547 std::string(ScreenshotSource::kScreenshotUrlRoot) + |
| 548 std::string(ScreenshotSource::kScreenshotCurrent)); |
552 StringValue screenshot(current_screenshot); | 549 StringValue screenshot(current_screenshot); |
553 web_ui()->CallJavascriptFunction("setupCurrentScreenshot", screenshot); | 550 web_ui()->CallJavascriptFunction("setupCurrentScreenshot", screenshot); |
554 } | 551 } |
555 | 552 |
556 #if defined(OS_CHROMEOS) | 553 #if defined(OS_CHROMEOS) |
557 void FeedbackHandler::HandleRefreshSavedScreenshots(const ListValue*) { | 554 void FeedbackHandler::HandleRefreshSavedScreenshots(const ListValue*) { |
558 std::vector<std::string>* saved_screenshots = new std::vector<std::string>; | 555 std::vector<std::string>* saved_screenshots = new std::vector<std::string>; |
559 FilePath filepath = DownloadPrefs::FromBrowserContext( | 556 FilePath filepath = DownloadPrefs::FromBrowserContext( |
560 tab_->GetBrowserContext())->DownloadPath(); | 557 tab_->GetBrowserContext())->DownloadPath(); |
561 base::Closure refresh_callback = base::Bind( | 558 base::Closure refresh_callback = base::Bind( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 std::string page_url; | 611 std::string page_url; |
615 (*i++)->GetAsString(&page_url); | 612 (*i++)->GetAsString(&page_url); |
616 std::string category_tag; | 613 std::string category_tag; |
617 (*i++)->GetAsString(&category_tag); | 614 (*i++)->GetAsString(&category_tag); |
618 std::string description; | 615 std::string description; |
619 (*i++)->GetAsString(&description); | 616 (*i++)->GetAsString(&description); |
620 std::string user_email; | 617 std::string user_email; |
621 (*i++)->GetAsString(&user_email); | 618 (*i++)->GetAsString(&user_email); |
622 std::string screenshot_path; | 619 std::string screenshot_path; |
623 (*i++)->GetAsString(&screenshot_path); | 620 (*i++)->GetAsString(&screenshot_path); |
624 screenshot_path.erase(0, strlen(kScreenshotBaseUrl)); | 621 screenshot_path.erase(0, strlen(ScreenshotSource::kScreenshotUrlRoot)); |
625 | 622 |
626 // Get the image to send in the report. | 623 // Get the image to send in the report. |
627 ScreenshotDataPtr image_ptr; | 624 ScreenshotDataPtr image_ptr; |
628 if (!screenshot_path.empty() && screenshot_source_) | 625 if (!screenshot_path.empty() && screenshot_source_) |
629 image_ptr = screenshot_source_->GetCachedScreenshot(screenshot_path); | 626 image_ptr = screenshot_source_->GetCachedScreenshot(screenshot_path); |
630 | 627 |
631 #if defined(OS_CHROMEOS) | 628 #if defined(OS_CHROMEOS) |
632 std::string sys_info_checkbox; | 629 std::string sys_info_checkbox; |
633 (*i++)->GetAsString(&sys_info_checkbox); | 630 (*i++)->GetAsString(&sys_info_checkbox); |
634 bool send_sys_info = (sys_info_checkbox == "true"); | 631 bool send_sys_info = (sys_info_checkbox == "true"); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 ChromeURLDataManager::AddDataSource(profile, html_source); | 722 ChromeURLDataManager::AddDataSource(profile, html_source); |
726 } | 723 } |
727 | 724 |
728 #if defined(OS_CHROMEOS) | 725 #if defined(OS_CHROMEOS) |
729 // static | 726 // static |
730 void FeedbackUI::GetMostRecentScreenshots( | 727 void FeedbackUI::GetMostRecentScreenshots( |
731 const FilePath& filepath, | 728 const FilePath& filepath, |
732 std::vector<std::string>* saved_screenshots, | 729 std::vector<std::string>* saved_screenshots, |
733 size_t max_saved) { | 730 size_t max_saved) { |
734 std::string pattern = | 731 std::string pattern = |
735 std::string(kScreenshotPrefix) + "*" + kScreenshotSuffix; | 732 std::string(ScreenshotSource::kScreenshotPrefix) + "*" + |
| 733 ScreenshotSource::kScreenshotSuffix; |
736 file_util::FileEnumerator screenshots(filepath, false, | 734 file_util::FileEnumerator screenshots(filepath, false, |
737 file_util::FileEnumerator::FILES, | 735 file_util::FileEnumerator::FILES, |
738 pattern); | 736 pattern); |
739 FilePath screenshot = screenshots.Next(); | 737 FilePath screenshot = screenshots.Next(); |
740 | 738 |
741 std::vector<std::string> screenshot_filepaths; | 739 std::vector<std::string> screenshot_filepaths; |
742 while (!screenshot.empty()) { | 740 while (!screenshot.empty()) { |
743 screenshot_filepaths.push_back(screenshot.BaseName().value()); | 741 screenshot_filepaths.push_back(screenshot.BaseName().value()); |
744 screenshot = screenshots.Next(); | 742 screenshot = screenshots.Next(); |
745 } | 743 } |
746 | 744 |
747 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); | 745 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); |
748 std::partial_sort(screenshot_filepaths.begin(), | 746 std::partial_sort(screenshot_filepaths.begin(), |
749 screenshot_filepaths.begin() + sort_size, | 747 screenshot_filepaths.begin() + sort_size, |
750 screenshot_filepaths.end(), | 748 screenshot_filepaths.end(), |
751 ScreenshotTimestampComp); | 749 ScreenshotTimestampComp); |
752 for (size_t i = 0; i < sort_size; ++i) | 750 for (size_t i = 0; i < sort_size; ++i) |
753 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + | 751 saved_screenshots->push_back( |
754 screenshot_filepaths[i]); | 752 std::string(ScreenshotSource::kScreenshotUrlRoot) + |
| 753 std::string(ScreenshotSource::kScreenshotSaved) + |
| 754 screenshot_filepaths[i]); |
755 } | 755 } |
756 #endif | 756 #endif |
OLD | NEW |