OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/download/notification/download_item_notification.h" | 5 #include "chrome/browser/download/notification/download_item_notification.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/download/download_crx_util.h" | 10 #include "chrome/browser/download/download_crx_util.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 content::RecordAction( | 147 content::RecordAction( |
148 UserMetricsAction("DownloadNotification.Button_Pause")); | 148 UserMetricsAction("DownloadNotification.Button_Pause")); |
149 break; | 149 break; |
150 case DownloadCommands::RESUME: | 150 case DownloadCommands::RESUME: |
151 content::RecordAction( | 151 content::RecordAction( |
152 UserMetricsAction("DownloadNotification.Button_Resume")); | 152 UserMetricsAction("DownloadNotification.Button_Resume")); |
153 break; | 153 break; |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
| 157 struct DownloadItemNotificationCommandEntry { |
| 158 DownloadCommands::Command command; |
| 159 int id; |
| 160 }; |
| 161 |
| 162 DownloadItemNotificationCommandEntry kDownloadNotificationCommand[] = { |
| 163 {DownloadCommands::OPEN_WHEN_COMPLETE, |
| 164 IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE}, |
| 165 {DownloadCommands::PAUSE, IDS_DOWNLOAD_LINK_PAUSE}, |
| 166 {DownloadCommands::RESUME, IDS_DOWNLOAD_LINK_RESUME}, |
| 167 {DownloadCommands::SHOW_IN_FOLDER, IDS_DOWNLOAD_LINK_SHOW}, |
| 168 {DownloadCommands::DISCARD, IDS_DISCARD_DOWNLOAD}, |
| 169 {DownloadCommands::KEEP, IDS_CONFIRM_DOWNLOAD}, |
| 170 {DownloadCommands::CANCEL, IDS_DOWNLOAD_LINK_CANCEL}, |
| 171 {DownloadCommands::LEARN_MORE_SCANNING, |
| 172 IDS_DOWNLOAD_LINK_LEARN_MORE_SCANNING}, |
| 173 }; |
| 174 |
157 } // anonymous namespace | 175 } // anonymous namespace |
158 | 176 |
159 DownloadItemNotification::DownloadItemNotification( | 177 DownloadItemNotification::DownloadItemNotification( |
160 content::DownloadItem* item, | 178 content::DownloadItem* item, |
161 DownloadNotificationManagerForProfile* manager) | 179 DownloadNotificationManagerForProfile* manager) |
162 : item_(item), | 180 : item_(item), |
163 weak_factory_(this) { | 181 weak_factory_(this) { |
164 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 182 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
165 | 183 |
166 message_center::RichNotificationData data; | 184 message_center::RichNotificationData data; |
(...skipping 25 matching lines...) Expand all Loading... |
192 // Dangerous notifications don't have a click handler. | 210 // Dangerous notifications don't have a click handler. |
193 return false; | 211 return false; |
194 } | 212 } |
195 return true; | 213 return true; |
196 } | 214 } |
197 | 215 |
198 void DownloadItemNotification::OnNotificationClose() { | 216 void DownloadItemNotification::OnNotificationClose() { |
199 visible_ = false; | 217 visible_ = false; |
200 | 218 |
201 if (item_ && item_->IsDangerous() && !item_->IsDone()) { | 219 if (item_ && item_->IsDangerous() && !item_->IsDone()) { |
202 // TODO(yoshiki): Add metrics. | 220 content::RecordAction( |
| 221 UserMetricsAction("DownloadNotification.Close_Dangerous")); |
203 item_->Cancel(true /* by_user */); | 222 item_->Cancel(true /* by_user */); |
204 return; | 223 return; |
205 } | 224 } |
206 | 225 |
207 if (image_decode_status_ == IN_PROGRESS) { | 226 if (image_decode_status_ == IN_PROGRESS) { |
208 image_decode_status_ = NOT_STARTED; | 227 image_decode_status_ = NOT_STARTED; |
209 ImageDecoder::Cancel(this); | 228 ImageDecoder::Cancel(this); |
210 } | 229 } |
211 } | 230 } |
212 | 231 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE, file_name); | 655 IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE, file_name); |
637 break; | 656 break; |
638 case content::DownloadItem::MAX_DOWNLOAD_STATE: | 657 case content::DownloadItem::MAX_DOWNLOAD_STATE: |
639 NOTREACHED(); | 658 NOTREACHED(); |
640 } | 659 } |
641 return title_text; | 660 return title_text; |
642 } | 661 } |
643 | 662 |
644 base::string16 DownloadItemNotification::GetCommandLabel( | 663 base::string16 DownloadItemNotification::GetCommandLabel( |
645 DownloadCommands::Command command) const { | 664 DownloadCommands::Command command) const { |
646 int id = -1; | 665 for (const DownloadItemNotificationCommandEntry& entry : |
647 switch (command) { | 666 kDownloadNotificationCommand) { |
648 case DownloadCommands::OPEN_WHEN_COMPLETE: | 667 if (entry.command == command) { |
649 if (item_ && !item_->IsDone()) | 668 return l10n_util::GetStringUTF16(entry.id); |
650 id = IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE; | 669 } |
651 else | |
652 id = IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE; | |
653 break; | |
654 case DownloadCommands::PAUSE: | |
655 // Only for non menu. | |
656 id = IDS_DOWNLOAD_LINK_PAUSE; | |
657 break; | |
658 case DownloadCommands::RESUME: | |
659 // Only for non menu. | |
660 id = IDS_DOWNLOAD_LINK_RESUME; | |
661 break; | |
662 case DownloadCommands::SHOW_IN_FOLDER: | |
663 id = IDS_DOWNLOAD_LINK_SHOW; | |
664 break; | |
665 case DownloadCommands::DISCARD: | |
666 id = IDS_DISCARD_DOWNLOAD; | |
667 break; | |
668 case DownloadCommands::KEEP: | |
669 id = IDS_CONFIRM_DOWNLOAD; | |
670 break; | |
671 case DownloadCommands::CANCEL: | |
672 id = IDS_DOWNLOAD_LINK_CANCEL; | |
673 break; | |
674 case DownloadCommands::LEARN_MORE_SCANNING: | |
675 id = IDS_DOWNLOAD_LINK_LEARN_MORE_SCANNING; | |
676 break; | |
677 case DownloadCommands::ALWAYS_OPEN_TYPE: | |
678 case DownloadCommands::PLATFORM_OPEN: | |
679 case DownloadCommands::LEARN_MORE_INTERRUPTED: | |
680 // Only for menu. | |
681 NOTREACHED(); | |
682 return base::string16(); | |
683 } | 670 } |
684 CHECK(id != -1); | 671 NOTREACHED(); |
685 return l10n_util::GetStringUTF16(id); | 672 return base::string16(); |
686 } | 673 } |
687 | 674 |
688 base::string16 DownloadItemNotification::GetWarningStatusString() const { | 675 base::string16 DownloadItemNotification::GetWarningStatusString() const { |
689 // Should only be called if IsDangerous(). | 676 // Should only be called if IsDangerous(). |
690 DCHECK(item_->IsDangerous()); | 677 DCHECK(item_->IsDangerous()); |
691 base::string16 elided_filename = | 678 base::string16 elided_filename = |
692 item_->GetFileNameToReportUser().LossyDisplayName(); | 679 item_->GetFileNameToReportUser().LossyDisplayName(); |
693 switch (item_->GetDangerType()) { | 680 switch (item_->GetDangerType()) { |
694 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: { | 681 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: { |
695 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); | 682 return l10n_util::GetStringUTF16(IDS_PROMPT_MALICIOUS_DOWNLOAD_URL); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 profile_id); | 840 profile_id); |
854 | 841 |
855 message_center::NotificationList::Notifications visible_notifications = | 842 message_center::NotificationList::Notifications visible_notifications = |
856 g_browser_process->message_center()->GetVisibleNotifications(); | 843 g_browser_process->message_center()->GetVisibleNotifications(); |
857 for (const auto& notification : visible_notifications) { | 844 for (const auto& notification : visible_notifications) { |
858 if (notification->id() == notification_id_in_message_center) | 845 if (notification->id() == notification_id_in_message_center) |
859 return true; | 846 return true; |
860 } | 847 } |
861 return false; | 848 return false; |
862 } | 849 } |
OLD | NEW |