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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/metrics/user_metrics.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "base/task_scheduler/post_task.h" | 13 #include "base/task_scheduler/post_task.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "chrome/app/vector_icons/vector_icons.h" | 15 #include "chrome/app/vector_icons/vector_icons.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/download/download_crx_util.h" | 17 #include "chrome/browser/download/download_crx_util.h" |
17 #include "chrome/browser/download/download_item_model.h" | 18 #include "chrome/browser/download/download_item_model.h" |
18 #include "chrome/browser/download/notification/download_notification_manager.h" | 19 #include "chrome/browser/download/notification/download_notification_manager.h" |
19 #include "chrome/browser/notifications/notification.h" | 20 #include "chrome/browser/notifications/notification.h" |
20 #include "chrome/browser/notifications/notification_ui_manager.h" | 21 #include "chrome/browser/notifications/notification_ui_manager.h" |
21 #include "chrome/browser/notifications/profile_notification.h" | 22 #include "chrome/browser/notifications/profile_notification.h" |
22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 23 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
24 #include "chrome/grit/chromium_strings.h" | 25 #include "chrome/grit/chromium_strings.h" |
25 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
26 #include "chrome/grit/theme_resources.h" | 27 #include "chrome/grit/theme_resources.h" |
27 #include "components/mime_util/mime_util.h" | 28 #include "components/mime_util/mime_util.h" |
28 #include "components/url_formatter/elide_url.h" | 29 #include "components/url_formatter/elide_url.h" |
29 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/download_interrupt_reasons.h" | 32 #include "content/public/browser/download_interrupt_reasons.h" |
32 #include "content/public/browser/download_item.h" | 33 #include "content/public/browser/download_item.h" |
33 #include "content/public/browser/page_navigator.h" | 34 #include "content/public/browser/page_navigator.h" |
34 #include "content/public/browser/user_metrics.h" | |
35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
36 #include "net/base/mime_util.h" | 36 #include "net/base/mime_util.h" |
37 #include "third_party/skia/include/core/SkCanvas.h" | 37 #include "third_party/skia/include/core/SkCanvas.h" |
38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
39 #include "ui/base/l10n/time_format.h" | 39 #include "ui/base/l10n/time_format.h" |
40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
41 #include "ui/base/text/bytes_formatting.h" | 41 #include "ui/base/text/bytes_formatting.h" |
42 #include "ui/gfx/codec/jpeg_codec.h" | 42 #include "ui/gfx/codec/jpeg_codec.h" |
43 #include "ui/gfx/color_palette.h" | 43 #include "ui/gfx/color_palette.h" |
44 #include "ui/gfx/image/image.h" | 44 #include "ui/gfx/image/image.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 container_image.drawColor(kImageBackgroundColor); | 114 container_image.drawColor(kImageBackgroundColor); |
115 container_image.drawBitmapRect( | 115 container_image.drawBitmapRect( |
116 original_bitmap, source_rect, SkRect::MakeSize(container_size), &paint); | 116 original_bitmap, source_rect, SkRect::MakeSize(container_size), &paint); |
117 | 117 |
118 return container_bitmap; | 118 return container_bitmap; |
119 } | 119 } |
120 | 120 |
121 void RecordButtonClickAction(DownloadCommands::Command command) { | 121 void RecordButtonClickAction(DownloadCommands::Command command) { |
122 switch (command) { | 122 switch (command) { |
123 case DownloadCommands::SHOW_IN_FOLDER: | 123 case DownloadCommands::SHOW_IN_FOLDER: |
124 content::RecordAction( | 124 base::RecordAction( |
125 UserMetricsAction("DownloadNotification.Button_ShowInFolder")); | 125 UserMetricsAction("DownloadNotification.Button_ShowInFolder")); |
126 break; | 126 break; |
127 case DownloadCommands::OPEN_WHEN_COMPLETE: | 127 case DownloadCommands::OPEN_WHEN_COMPLETE: |
128 content::RecordAction( | 128 base::RecordAction( |
129 UserMetricsAction("DownloadNotification.Button_OpenWhenComplete")); | 129 UserMetricsAction("DownloadNotification.Button_OpenWhenComplete")); |
130 break; | 130 break; |
131 case DownloadCommands::ALWAYS_OPEN_TYPE: | 131 case DownloadCommands::ALWAYS_OPEN_TYPE: |
132 content::RecordAction( | 132 base::RecordAction( |
133 UserMetricsAction("DownloadNotification.Button_AlwaysOpenType")); | 133 UserMetricsAction("DownloadNotification.Button_AlwaysOpenType")); |
134 break; | 134 break; |
135 case DownloadCommands::PLATFORM_OPEN: | 135 case DownloadCommands::PLATFORM_OPEN: |
136 content::RecordAction( | 136 base::RecordAction( |
137 UserMetricsAction("DownloadNotification.Button_PlatformOpen")); | 137 UserMetricsAction("DownloadNotification.Button_PlatformOpen")); |
138 break; | 138 break; |
139 case DownloadCommands::CANCEL: | 139 case DownloadCommands::CANCEL: |
140 content::RecordAction( | 140 base::RecordAction( |
141 UserMetricsAction("DownloadNotification.Button_Cancel")); | 141 UserMetricsAction("DownloadNotification.Button_Cancel")); |
142 break; | 142 break; |
143 case DownloadCommands::DISCARD: | 143 case DownloadCommands::DISCARD: |
144 content::RecordAction( | 144 base::RecordAction( |
145 UserMetricsAction("DownloadNotification.Button_Discard")); | 145 UserMetricsAction("DownloadNotification.Button_Discard")); |
146 break; | 146 break; |
147 case DownloadCommands::KEEP: | 147 case DownloadCommands::KEEP: |
148 content::RecordAction( | 148 base::RecordAction(UserMetricsAction("DownloadNotification.Button_Keep")); |
149 UserMetricsAction("DownloadNotification.Button_Keep")); | |
150 break; | 149 break; |
151 case DownloadCommands::LEARN_MORE_SCANNING: | 150 case DownloadCommands::LEARN_MORE_SCANNING: |
152 content::RecordAction( | 151 base::RecordAction( |
153 UserMetricsAction("DownloadNotification.Button_LearnScanning")); | 152 UserMetricsAction("DownloadNotification.Button_LearnScanning")); |
154 break; | 153 break; |
155 case DownloadCommands::LEARN_MORE_INTERRUPTED: | 154 case DownloadCommands::LEARN_MORE_INTERRUPTED: |
156 content::RecordAction( | 155 base::RecordAction( |
157 UserMetricsAction("DownloadNotification.Button_LearnInterrupted")); | 156 UserMetricsAction("DownloadNotification.Button_LearnInterrupted")); |
158 break; | 157 break; |
159 case DownloadCommands::PAUSE: | 158 case DownloadCommands::PAUSE: |
160 content::RecordAction( | 159 base::RecordAction( |
161 UserMetricsAction("DownloadNotification.Button_Pause")); | 160 UserMetricsAction("DownloadNotification.Button_Pause")); |
162 break; | 161 break; |
163 case DownloadCommands::RESUME: | 162 case DownloadCommands::RESUME: |
164 content::RecordAction( | 163 base::RecordAction( |
165 UserMetricsAction("DownloadNotification.Button_Resume")); | 164 UserMetricsAction("DownloadNotification.Button_Resume")); |
166 break; | 165 break; |
167 case DownloadCommands::COPY_TO_CLIPBOARD: | 166 case DownloadCommands::COPY_TO_CLIPBOARD: |
168 content::RecordAction( | 167 base::RecordAction( |
169 UserMetricsAction("DownloadNotification.Button_CopyToClipboard")); | 168 UserMetricsAction("DownloadNotification.Button_CopyToClipboard")); |
170 break; | 169 break; |
171 case DownloadCommands::ANNOTATE: | 170 case DownloadCommands::ANNOTATE: |
172 content::RecordAction( | 171 base::RecordAction( |
173 UserMetricsAction("DownloadNotification.Button_Annotate")); | 172 UserMetricsAction("DownloadNotification.Button_Annotate")); |
174 break; | 173 break; |
175 } | 174 } |
176 } | 175 } |
177 | 176 |
178 } // anonymous namespace | 177 } // anonymous namespace |
179 | 178 |
180 DownloadItemNotification::DownloadItemNotification( | 179 DownloadItemNotification::DownloadItemNotification( |
181 content::DownloadItem* item, | 180 content::DownloadItem* item, |
182 DownloadNotificationManagerForProfile* manager) | 181 DownloadNotificationManagerForProfile* manager) |
(...skipping 30 matching lines...) Expand all Loading... |
213 bool DownloadItemNotification::HasNotificationClickedListener() { | 212 bool DownloadItemNotification::HasNotificationClickedListener() { |
214 if (item_->IsDangerous()) { | 213 if (item_->IsDangerous()) { |
215 // Dangerous notifications don't have a click handler. | 214 // Dangerous notifications don't have a click handler. |
216 return false; | 215 return false; |
217 } | 216 } |
218 return true; | 217 return true; |
219 } | 218 } |
220 | 219 |
221 void DownloadItemNotification::OnNotificationClose() { | 220 void DownloadItemNotification::OnNotificationClose() { |
222 if (item_ && item_->IsDangerous() && !item_->IsDone()) { | 221 if (item_ && item_->IsDangerous() && !item_->IsDone()) { |
223 content::RecordAction( | 222 base::RecordAction( |
224 UserMetricsAction("DownloadNotification.Close_Dangerous")); | 223 UserMetricsAction("DownloadNotification.Close_Dangerous")); |
225 closed_ = true; // Should be set before cancelling the download. | 224 closed_ = true; // Should be set before cancelling the download. |
226 item_->Cancel(true /* by_user */); | 225 item_->Cancel(true /* by_user */); |
227 return; | 226 return; |
228 } | 227 } |
229 | 228 |
230 if (image_decode_status_ == IN_PROGRESS) { | 229 if (image_decode_status_ == IN_PROGRESS) { |
231 image_decode_status_ = NOT_STARTED; | 230 image_decode_status_ = NOT_STARTED; |
232 ImageDecoder::Cancel(this); | 231 ImageDecoder::Cancel(this); |
233 } | 232 } |
234 } | 233 } |
235 | 234 |
236 void DownloadItemNotification::OnNotificationClick() { | 235 void DownloadItemNotification::OnNotificationClick() { |
237 if (item_->IsDangerous()) { | 236 if (item_->IsDangerous()) { |
238 content::RecordAction( | 237 base::RecordAction( |
239 UserMetricsAction("DownloadNotification.Click_Dangerous")); | 238 UserMetricsAction("DownloadNotification.Click_Dangerous")); |
240 // Do nothing. | 239 // Do nothing. |
241 return; | 240 return; |
242 } | 241 } |
243 | 242 |
244 switch (item_->GetState()) { | 243 switch (item_->GetState()) { |
245 case content::DownloadItem::IN_PROGRESS: | 244 case content::DownloadItem::IN_PROGRESS: |
246 content::RecordAction( | 245 base::RecordAction( |
247 UserMetricsAction("DownloadNotification.Click_InProgress")); | 246 UserMetricsAction("DownloadNotification.Click_InProgress")); |
248 item_->SetOpenWhenComplete(!item_->GetOpenWhenComplete()); // Toggle | 247 item_->SetOpenWhenComplete(!item_->GetOpenWhenComplete()); // Toggle |
249 break; | 248 break; |
250 case content::DownloadItem::CANCELLED: | 249 case content::DownloadItem::CANCELLED: |
251 case content::DownloadItem::INTERRUPTED: | 250 case content::DownloadItem::INTERRUPTED: |
252 content::RecordAction( | 251 base::RecordAction( |
253 UserMetricsAction("DownloadNotification.Click_Stopped")); | 252 UserMetricsAction("DownloadNotification.Click_Stopped")); |
254 GetBrowser()->OpenURL(content::OpenURLParams( | 253 GetBrowser()->OpenURL(content::OpenURLParams( |
255 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), | 254 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), |
256 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 255 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
257 false /* is_renderer_initiated */)); | 256 false /* is_renderer_initiated */)); |
258 CloseNotificationByUser(); | 257 CloseNotificationByUser(); |
259 break; | 258 break; |
260 case content::DownloadItem::COMPLETE: | 259 case content::DownloadItem::COMPLETE: |
261 content::RecordAction( | 260 base::RecordAction( |
262 UserMetricsAction("DownloadNotification.Click_Completed")); | 261 UserMetricsAction("DownloadNotification.Click_Completed")); |
263 item_->OpenDownload(); | 262 item_->OpenDownload(); |
264 CloseNotificationByUser(); | 263 CloseNotificationByUser(); |
265 break; | 264 break; |
266 case content::DownloadItem::MAX_DOWNLOAD_STATE: | 265 case content::DownloadItem::MAX_DOWNLOAD_STATE: |
267 NOTREACHED(); | 266 NOTREACHED(); |
268 } | 267 } |
269 } | 268 } |
270 | 269 |
271 void DownloadItemNotification::OnNotificationButtonClick(int button_index) { | 270 void DownloadItemNotification::OnNotificationButtonClick(int button_index) { |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 const std::string notification_id_in_message_center = notification->id(); | 930 const std::string notification_id_in_message_center = notification->id(); |
932 | 931 |
933 message_center::NotificationList::Notifications visible_notifications = | 932 message_center::NotificationList::Notifications visible_notifications = |
934 message_center_->GetVisibleNotifications(); | 933 message_center_->GetVisibleNotifications(); |
935 for (auto* notification : visible_notifications) { | 934 for (auto* notification : visible_notifications) { |
936 if (notification->id() == notification_id_in_message_center) | 935 if (notification->id() == notification_id_in_message_center) |
937 return true; | 936 return true; |
938 } | 937 } |
939 return false; | 938 return false; |
940 } | 939 } |
OLD | NEW |