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 #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ |
7 | 7 |
8 #include "chrome/browser/download/notification/download_notification_item.h" | 8 #include "chrome/browser/download/notification/download_notification_item.h" |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "chrome/browser/download/download_commands.h" | 11 #include "chrome/browser/download/download_commands.h" |
| 12 #include "chrome/browser/image_decoder.h" |
12 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
13 #include "chrome/browser/notifications/notification_delegate.h" | 14 #include "chrome/browser/notifications/notification_delegate.h" |
14 #include "chrome/browser/notifications/notification_test_util.h" | 15 #include "chrome/browser/notifications/notification_test_util.h" |
15 #include "content/public/browser/download_item.h" | 16 #include "content/public/browser/download_item.h" |
16 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" |
17 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
18 #include "ui/message_center/message_center_observer.h" | 20 #include "ui/message_center/message_center_observer.h" |
19 | 21 |
20 namespace test { | 22 namespace test { |
21 class DownloadNotificationItemTest; | 23 class DownloadNotificationItemTest; |
22 } | 24 } |
23 | 25 |
24 class DownloadNotificationItem : public content::DownloadItem::Observer { | 26 class DownloadNotificationItem : public content::DownloadItem::Observer, |
| 27 public ImageDecoder::ImageRequest { |
25 public: | 28 public: |
26 class Delegate { | 29 class Delegate { |
27 public: | 30 public: |
28 virtual void OnCreated(DownloadNotificationItem* item) = 0; | 31 virtual void OnCreated(DownloadNotificationItem* item) = 0; |
29 virtual void OnDownloadStarted(DownloadNotificationItem* item) = 0; | 32 virtual void OnDownloadStarted(DownloadNotificationItem* item) = 0; |
30 virtual void OnDownloadStopped(DownloadNotificationItem* item) = 0; | 33 virtual void OnDownloadStopped(DownloadNotificationItem* item) = 0; |
31 virtual void OnDownloadRemoved(DownloadNotificationItem* item) = 0; | 34 virtual void OnDownloadRemoved(DownloadNotificationItem* item) = 0; |
32 }; | 35 }; |
33 | 36 |
34 static const char kDownloadNotificationOrigin[]; | 37 static const char kDownloadNotificationOrigin[]; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 82 |
80 // DownloadItem::Observer overrides: | 83 // DownloadItem::Observer overrides: |
81 void OnDownloadUpdated(content::DownloadItem* item) override; | 84 void OnDownloadUpdated(content::DownloadItem* item) override; |
82 void OnDownloadOpened(content::DownloadItem* item) override; | 85 void OnDownloadOpened(content::DownloadItem* item) override; |
83 void OnDownloadRemoved(content::DownloadItem* item) override; | 86 void OnDownloadRemoved(content::DownloadItem* item) override; |
84 void OnDownloadDestroyed(content::DownloadItem* item) override; | 87 void OnDownloadDestroyed(content::DownloadItem* item) override; |
85 | 88 |
86 void CloseNotificationByUser(); | 89 void CloseNotificationByUser(); |
87 void CloseNotificationByNonUser(); | 90 void CloseNotificationByNonUser(); |
88 void UpdateNotificationData(NotificationUpdateType type); | 91 void UpdateNotificationData(NotificationUpdateType type); |
89 void SetNotificationImage(int resource_id); | 92 |
| 93 // Set icon of the notification. |
| 94 void SetNotificationIcon(int resource_id); |
| 95 |
| 96 // Set preview image of the notification. Must be called on IO thread. |
| 97 void OnImageLoaded(std::string image_data); |
| 98 |
| 99 // ImageDecoder::ImageRequest overrides: |
| 100 void OnImageDecoded(const SkBitmap& decoded_image) override; |
| 101 void OnDecodeImageFailed() override; |
90 | 102 |
91 NotificationUIManager* notification_ui_manager() const; | 103 NotificationUIManager* notification_ui_manager() const; |
92 | 104 |
93 // Returns a short one-line status string for the download. | 105 // Returns a short one-line status string for the download. |
94 base::string16 GetTitle() const; | 106 base::string16 GetTitle() const; |
95 | 107 |
96 // Returns a short one-line status string for a download command. | 108 // Returns a short one-line status string for a download command. |
97 base::string16 GetCommandLabel(DownloadCommands::Command command) const; | 109 base::string16 GetCommandLabel(DownloadCommands::Command command) const; |
98 | 110 |
99 // Get the warning test to notify a dangerous download. Should only be called | 111 // Get the warning test to notify a dangerous download. Should only be called |
100 // if IsDangerous() is true. | 112 // if IsDangerous() is true. |
101 base::string16 GetWarningText() const; | 113 base::string16 GetWarningText() const; |
102 | 114 |
103 Browser* GetBrowser(); | 115 Browser* GetBrowser(); |
104 | 116 |
105 // Returns the list of possible extra (all except the default) actions. | 117 // Returns the list of possible extra (all except the default) actions. |
106 scoped_ptr<std::vector<DownloadCommands::Command>> GetExtraActions() const; | 118 scoped_ptr<std::vector<DownloadCommands::Command>> GetExtraActions() const; |
107 | 119 |
108 int image_resource_id_ = 0; | 120 int image_resource_id_ = 0; |
109 content::DownloadItem::DownloadState previous_download_state_ = | 121 content::DownloadItem::DownloadState previous_download_state_ = |
110 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state | 122 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state |
111 Profile* profile_; | 123 Profile* profile_; |
112 scoped_refptr<NotificationWatcher> watcher_; | 124 scoped_refptr<NotificationWatcher> watcher_; |
113 scoped_ptr<Notification> notification_; | 125 scoped_ptr<Notification> notification_; |
114 content::DownloadItem* item_; | 126 content::DownloadItem* item_; |
115 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; | 127 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; |
116 Delegate* const delegate_; | 128 Delegate* const delegate_; |
117 | 129 |
| 130 // Whether the preview image been has set or not. |
| 131 bool set_image_ = false; |
| 132 |
| 133 base::WeakPtrFactory<DownloadNotificationItem> weak_factory_; |
| 134 |
118 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); | 135 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); |
119 }; | 136 }; |
120 | 137 |
121 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ | 138 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ |
OLD | NEW |