Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / download / notification / download_item_notification.h
blob390b1fd6ea33f27c89a156d47ee714415c4d7071
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_ITEM_NOTIFICATION_H_
6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_ITEM_NOTIFICATION_H_
8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/download/download_commands.h"
10 #include "chrome/browser/download/notification/download_notification.h"
11 #include "chrome/browser/image_decoder.h"
12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_delegate.h"
14 #include "chrome/browser/notifications/notification_test_util.h"
15 #include "content/public/browser/download_item.h"
16 #include "grit/theme_resources.h"
17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "ui/message_center/message_center.h"
19 #include "ui/message_center/message_center_observer.h"
21 namespace test {
22 class DownloadItemNotificationTest;
25 class DownloadItemNotification : public DownloadNotification,
26 public ImageDecoder::ImageRequest {
27 public:
28 DownloadItemNotification(content::DownloadItem* item,
29 DownloadNotificationManagerForProfile* manager);
31 ~DownloadItemNotification() override;
33 // Methods called from NotificationWatcher.
34 void OnDownloadUpdated(content::DownloadItem* item) override;
35 void OnDownloadRemoved(content::DownloadItem* item) override;
36 bool HasNotificationClickedListener() override;
37 void OnNotificationClose() override;
38 void OnNotificationClick() override;
39 void OnNotificationButtonClick(int button_index) override;
40 std::string GetNotificationId() const override;
42 private:
43 friend class test::DownloadItemNotificationTest;
45 enum ImageDecodeStatus { NOT_STARTED, IN_PROGRESS, DONE, FAILED, NOT_IMAGE };
47 enum NotificationUpdateType {
48 ADD,
49 UPDATE,
50 UPDATE_AND_POPUP
53 void CloseNotificationByUser();
54 void CloseNotificationByNonUser();
55 void Update();
56 void UpdateNotificationData(NotificationUpdateType type);
58 // Set icon of the notification.
59 void SetNotificationIcon(int resource_id);
61 // Set preview image of the notification. Must be called on IO thread.
62 void OnImageLoaded(const std::string& image_data);
63 void OnImageCropped(const SkBitmap& image);
65 // ImageDecoder::ImageRequest overrides:
66 void OnImageDecoded(const SkBitmap& decoded_image) override;
67 void OnDecodeImageFailed() override;
69 // Returns a short one-line status string for the download.
70 base::string16 GetTitle() const;
72 // Returns a short one-line status string for a download command.
73 base::string16 GetCommandLabel(DownloadCommands::Command command) const;
75 // Get the warning text to notify a dangerous download. Should only be called
76 // if IsDangerous() is true.
77 base::string16 GetWarningStatusString() const;
79 // Get the sub status text of the current in-progress download status. Should
80 // be called only for downloads in progress.
81 base::string16 GetInProgressSubStatusString() const;
83 // Get the status text.
84 base::string16 GetStatusString() const;
86 bool IsNotificationVisible() const;
88 Browser* GetBrowser() const;
89 Profile* profile() const;
91 // Returns the list of possible extra (all except the default) actions.
92 scoped_ptr<std::vector<DownloadCommands::Command>> GetExtraActions() const;
94 // Flag to show the notification on next update. If true, the notification
95 // goes visible. The initial value is true so it gets shown on initial update.
96 bool show_next_ = true;
97 // Current vilibility status of the notification.
98 bool visible_ = false;
100 int image_resource_id_ = 0;
101 content::DownloadItem::DownloadState previous_download_state_ =
102 content::DownloadItem::MAX_DOWNLOAD_STATE; // As uninitialized state
103 bool previous_dangerous_state_ = false;
104 scoped_ptr<Notification> notification_;
105 content::DownloadItem* item_;
106 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_;
108 // Status of the preview image decode.
109 ImageDecodeStatus image_decode_status_ = NOT_STARTED;
111 base::WeakPtrFactory<DownloadItemNotification> weak_factory_;
113 DISALLOW_COPY_AND_ASSIGN(DownloadItemNotification);
116 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_ITEM_NOTIFICATION_H_