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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/notification_platform_bridge_win.h
diff --git a/chrome/browser/notifications/notification_platform_bridge_win.h b/chrome/browser/notifications/notification_platform_bridge_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..d2417f52607eb0cfad34f71f89f8497cfae50bb7
--- /dev/null
+++ b/chrome/browser/notifications/notification_platform_bridge_win.h
@@ -0,0 +1,121 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_
+#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_
+
+#include <windows.ui.notifications.h>
+
+#include <map>
+#include <string>
+
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "chrome/browser/notifications/notification_platform_bridge.h"
+
+namespace winui = ABI::Windows::UI;
+
+class Notification;
+struct NotificationToastSession;
+
+// This class is an implementation of NotificationPlatformBridge that will
+// send platform notifications to the Windows Notification Area.
+class NotificationPlatformBridgeWin : public NotificationPlatformBridge {
+ public:
+ // Handler for Notification events from Windows. Special care is needed since
+ // callback may occur at any time, including at shut down! To handle this:
+ // - A static singleton NotificationPlatformBridgeWin::|toast_event_handler_|
+ // is used throughout. As a result, constructor must be trivial.
+ // - Operations related to NotificationPlatformBridgeWin need to be posted on
+ // UI thread.
+ class ToastEventHandler {
+ public:
+ enum EventType {
+ EVENT_TYPE_ACTIVATED,
+ EVENT_TYPE_DISMISSED,
+ EVENT_TYPE_FAILED,
+ };
+
+ HRESULT OnActivated(winui::Notifications::IToastNotification* notification,
+ IInspectable* inspectable);
+
+ HRESULT OnDismissed(winui::Notifications::IToastNotification* notification,
+ winui::Notifications::IToastDismissedEventArgs* args);
+
+ HRESULT OnFailed(winui::Notifications::IToastNotification* notification,
+ winui::Notifications::IToastFailedEventArgs* args);
+
+ private:
+ friend NotificationPlatformBridgeWin;
+
+ // Constructor must be trivial.
+ ToastEventHandler() = default;
+
+ static void PostHandlerOnUIThread(EventType type,
+ winui::Notifications::IToastNotification* notification);
+
+ // Runs on the UI thread.
+ static void HandleOnUIThread(EventType type,
+ const std::string& notification_id,
+ const std::string& profile_id);
+ };
+
+ NotificationPlatformBridgeWin() = default;
+ ~NotificationPlatformBridgeWin() override;
+
+ // NotificationPlatformBridge implementation.
+ void Display(NotificationCommon::Type notification_type,
+ const std::string& notification_id,
+ const std::string& profile_id,
+ bool incognito,
+ const Notification& notification) override;
+ void Close(const std::string& profile_id,
+ const std::string& notification_id) override;
+ void GetDisplayed(const std::string& profile_id,
+ bool incognito,
+ const GetDisplayedNotificationsCallback& callback)
+ const override;
+ void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
+
+ private:
+ friend ToastEventHandler;
+
+ // Runs on a worker thread.
+ void DisplayStepFormatIconOnWorkerThread(
+ scoped_refptr<NotificationToastSession> session);
+
+ // Runs on FILE thread.
+ void DisplayStepPrepareIconOnFileThread(
+ scoped_refptr<NotificationToastSession> session);
+
+ // Runs on UI thread. Returns true on success.
+ bool DisplayStepMainWorker(scoped_refptr<NotificationToastSession> session);
+
+ // Runs on UI thread.
+ void DisplayStepMain(scoped_refptr<NotificationToastSession> session);
+
+ // Called when toast notification gets clicked. This might not work on some
+ // regions of the notification toast.
+ void OnClickEvent(const std::string& notification_id,
+ const std::string& profile_id);
+
+ // Called when toast notification gets closed.
+ void OnCloseEvent(const std::string& notification_id,
+ const std::string& profile_id);
+
+ // Removes |notification_id| from |session_map_|, cleans up resources used.
+ void CleanupSession(std::string notification_id);
+
+ // Static instance to handle Toast event callback from Windows.
+ static ToastEventHandler toast_event_handler_;
+
+ // Main storage of notification sessions.
+ // TODO(huangs): Also key by |is_incognito| and |profile_id|??
+ std::map<std::string, scoped_refptr<NotificationToastSession>> session_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeWin);
+};
+
+#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698