Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_win.h

Issue 2033093003: [Notification] Make HTML5 Notification use ActionCenter on Windows 10, behind Flags. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and merge. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_
7
8 #include <windows.ui.notifications.h>
9
10 #include <map>
11 #include <string>
12
13 #include "base/files/file_path.h"
14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "chrome/browser/notifications/notification_platform_bridge.h"
17
18 namespace winui = ABI::Windows::UI;
19
20 class Notification;
21 struct NotificationToastSession;
22
23 // This class is an implementation of NotificationPlatformBridge that will
24 // send platform notifications to the Windows Notification Area.
25 class NotificationPlatformBridgeWin : public NotificationPlatformBridge {
26 public:
27 // Handler for Notification events from Windows. Special care is needed since
28 // callback may occur at any time, including at shut down! To handle this:
29 // - A static singleton NotificationPlatformBridgeWin::|toast_event_handler_|
30 // is used throughout. As a result, constructor must be trivial.
31 // - Operations related to NotificationPlatformBridgeWin need to be posted on
32 // UI thread.
33 class ToastEventHandler {
34 public:
35 enum EventType {
36 EVENT_TYPE_ACTIVATED,
37 EVENT_TYPE_DISMISSED,
38 EVENT_TYPE_FAILED,
39 };
40
41 HRESULT OnActivated(winui::Notifications::IToastNotification* notification,
42 IInspectable* inspectable);
43
44 HRESULT OnDismissed(winui::Notifications::IToastNotification* notification,
45 winui::Notifications::IToastDismissedEventArgs* args);
46
47 HRESULT OnFailed(winui::Notifications::IToastNotification* notification,
48 winui::Notifications::IToastFailedEventArgs* args);
49
50 private:
51 friend NotificationPlatformBridgeWin;
52
53 // Constructor must be trivial.
54 ToastEventHandler() = default;
55
56 static void PostHandlerOnUIThread(EventType type,
57 winui::Notifications::IToastNotification* notification);
58
59 // Runs on the UI thread.
60 static void HandleOnUIThread(EventType type,
61 const std::string& notification_id,
62 const std::string& profile_id);
63 };
64
65 NotificationPlatformBridgeWin() = default;
66 ~NotificationPlatformBridgeWin() override;
67
68 // NotificationPlatformBridge implementation.
69 void Display(NotificationCommon::Type notification_type,
70 const std::string& notification_id,
71 const std::string& profile_id,
72 bool incognito,
73 const Notification& notification) override;
74 void Close(const std::string& profile_id,
75 const std::string& notification_id) override;
76 void GetDisplayed(const std::string& profile_id,
77 bool incognito,
78 const GetDisplayedNotificationsCallback& callback)
79 const override;
80 void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
81
82 private:
83 friend ToastEventHandler;
84
85 // Runs on a worker thread.
86 void DisplayStepFormatIconOnWorkerThread(
87 scoped_refptr<NotificationToastSession> session);
88
89 // Runs on FILE thread.
90 void DisplayStepPrepareIconOnFileThread(
91 scoped_refptr<NotificationToastSession> session);
92
93 // Runs on UI thread. Returns true on success.
94 bool DisplayStepMainWorker(scoped_refptr<NotificationToastSession> session);
95
96 // Runs on UI thread.
97 void DisplayStepMain(scoped_refptr<NotificationToastSession> session);
98
99 // Called when toast notification gets clicked. This might not work on some
100 // regions of the notification toast.
101 void OnClickEvent(const std::string& notification_id,
102 const std::string& profile_id);
103
104 // Called when toast notification gets closed.
105 void OnCloseEvent(const std::string& notification_id,
106 const std::string& profile_id);
107
108 // Removes |notification_id| from |session_map_|, cleans up resources used.
109 void CleanupSession(std::string notification_id);
110
111 // Static instance to handle Toast event callback from Windows.
112 static ToastEventHandler toast_event_handler_;
113
114 // Main storage of notification sessions.
115 // TODO(huangs): Also key by |is_incognito| and |profile_id|??
116 std::map<std::string, scoped_refptr<NotificationToastSession>> session_map_;
117
118 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeWin);
119 };
120
121 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698