Chromium Code Reviews| 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 { | |
|
asanka
2015/09/17 14:29:40
This is no longer necessary since you are only usi
Deepak
2015/09/18 04:38:01
Done.
| |
| 158 DownloadCommands::Command command; | |
| 159 int id; | |
| 160 }; | |
| 161 | |
| 162 DownloadItemNotificationCommandEntry kDownloadNotificationCommand[] = { | |
|
asanka
2015/09/17 14:29:40
Pick a name that implies that this is a mapping fr
Deepak
2015/09/18 04:38:01
Done.
| |
| 163 {DownloadCommands::SHOW_IN_FOLDER, IDS_DOWNLOAD_LINK_SHOW}, | |
| 164 {DownloadCommands::OPEN_WHEN_COMPLETE, | |
| 165 IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE}, | |
| 166 {DownloadCommands::ALWAYS_OPEN_TYPE, -1}, | |
| 167 {DownloadCommands::PLATFORM_OPEN, -1}, | |
| 168 {DownloadCommands::CANCEL, IDS_DOWNLOAD_LINK_CANCEL}, | |
| 169 {DownloadCommands::PAUSE, IDS_DOWNLOAD_LINK_PAUSE}, | |
| 170 {DownloadCommands::RESUME, IDS_DOWNLOAD_LINK_RESUME}, | |
| 171 {DownloadCommands::DISCARD, IDS_DISCARD_DOWNLOAD}, | |
| 172 {DownloadCommands::KEEP, IDS_CONFIRM_DOWNLOAD}, | |
| 173 {DownloadCommands::LEARN_MORE_SCANNING, | |
| 174 IDS_DOWNLOAD_LINK_LEARN_MORE_SCANNING}, | |
| 175 {DownloadCommands::LEARN_MORE_INTERRUPTED, -1}, | |
| 176 }; | |
| 177 | |
| 157 } // anonymous namespace | 178 } // anonymous namespace |
| 158 | 179 |
| 159 DownloadItemNotification::DownloadItemNotification( | 180 DownloadItemNotification::DownloadItemNotification( |
| 160 content::DownloadItem* item, | 181 content::DownloadItem* item, |
| 161 DownloadNotificationManagerForProfile* manager) | 182 DownloadNotificationManagerForProfile* manager) |
| 162 : item_(item), | 183 : item_(item), |
| 163 weak_factory_(this) { | 184 weak_factory_(this) { |
| 164 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 185 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 165 | 186 |
| 166 message_center::RichNotificationData data; | 187 message_center::RichNotificationData data; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 192 // Dangerous notifications don't have a click handler. | 213 // Dangerous notifications don't have a click handler. |
| 193 return false; | 214 return false; |
| 194 } | 215 } |
| 195 return true; | 216 return true; |
| 196 } | 217 } |
| 197 | 218 |
| 198 void DownloadItemNotification::OnNotificationClose() { | 219 void DownloadItemNotification::OnNotificationClose() { |
| 199 visible_ = false; | 220 visible_ = false; |
| 200 | 221 |
| 201 if (item_ && item_->IsDangerous() && !item_->IsDone()) { | 222 if (item_ && item_->IsDangerous() && !item_->IsDone()) { |
| 202 // TODO(yoshiki): Add metrics. | 223 content::RecordAction( |
| 224 UserMetricsAction("DownloadNotification.Close_Dangerous")); | |
| 203 item_->Cancel(true /* by_user */); | 225 item_->Cancel(true /* by_user */); |
| 204 return; | 226 return; |
| 205 } | 227 } |
| 206 | 228 |
| 207 if (image_decode_status_ == IN_PROGRESS) { | 229 if (image_decode_status_ == IN_PROGRESS) { |
| 208 image_decode_status_ = NOT_STARTED; | 230 image_decode_status_ = NOT_STARTED; |
| 209 ImageDecoder::Cancel(this); | 231 ImageDecoder::Cancel(this); |
| 210 } | 232 } |
| 211 } | 233 } |
| 212 | 234 |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE, file_name); | 658 IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE, file_name); |
| 637 break; | 659 break; |
| 638 case content::DownloadItem::MAX_DOWNLOAD_STATE: | 660 case content::DownloadItem::MAX_DOWNLOAD_STATE: |
| 639 NOTREACHED(); | 661 NOTREACHED(); |
| 640 } | 662 } |
| 641 return title_text; | 663 return title_text; |
| 642 } | 664 } |
| 643 | 665 |
| 644 base::string16 DownloadItemNotification::GetCommandLabel( | 666 base::string16 DownloadItemNotification::GetCommandLabel( |
| 645 DownloadCommands::Command command) const { | 667 DownloadCommands::Command command) const { |
| 646 int id = -1; | 668 int id = kDownloadNotificationCommand[command].id; |
|
asanka
2015/09/17 14:29:40
This lookup is off by one and will access past the
Deepak
2015/09/18 04:38:01
Done.
| |
| 647 switch (command) { | 669 if (id != -1) |
|
asanka
2015/09/17 14:29:40
The advantage of using a switch is that:
1. Compi
Deepak
2015/09/18 04:38:01
Acknowledged.
| |
| 648 case DownloadCommands::OPEN_WHEN_COMPLETE: | 670 return l10n_util::GetStringUTF16(id); |
| 649 if (item_ && !item_->IsDone()) | 671 NOTREACHED(); |
| 650 id = IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE; | 672 return base::string16(); |
| 651 else | |
| 652 id = IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE; | |
|
asanka
2015/09/17 14:29:40
How did this slip by? I think it's supposed to say
Deepak
2015/09/18 04:38:01
I think here the message is "In both the cases whe
| |
| 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 } | |
| 684 CHECK(id != -1); | |
| 685 return l10n_util::GetStringUTF16(id); | |
| 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 |