| Index: chrome/browser/notifications/notification_toast_helper_win.h
|
| diff --git a/chrome/browser/notifications/notification_toast_helper_win.h b/chrome/browser/notifications/notification_toast_helper_win.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..47e121c55a357dbcde712d66f60520517ac50b70
|
| --- /dev/null
|
| +++ b/chrome/browser/notifications/notification_toast_helper_win.h
|
| @@ -0,0 +1,151 @@
|
| +// 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_TOAST_HELPER_WIN_H_
|
| +#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TOAST_HELPER_WIN_H_
|
| +
|
| +#include <activation.h>
|
| +#include <d2d1_1.h>
|
| +#include <d3d11_1.h>
|
| +#include <roapi.h>
|
| +#include <shlwapi.h>
|
| +#include <wincodec.h>
|
| +#include <windows.h>
|
| +#include <windows.applicationModel.core.h>
|
| +#include <windows.applicationModel.datatransfer.h>
|
| +#include <windows.data.xml.dom.h>
|
| +#include <windows.graphics.printing.h>
|
| +#include <windows.storage.pickers.h>
|
| +#include <windows.ui.notifications.h>
|
| +#include <wrl/implements.h>
|
| +#include <wrl/module.h>
|
| +#include <wrl/event.h>
|
| +#include <wrl/wrappers/corewrappers.h>
|
| +
|
| +#include "base/macros.h"
|
| +#include "base/strings/string16.h"
|
| +
|
| +namespace mswr = Microsoft::WRL;
|
| +namespace mswrw = Microsoft::WRL::Wrappers;
|
| +
|
| +namespace winapp = ABI::Windows::ApplicationModel;
|
| +namespace windata = ABI::Windows::Data;
|
| +namespace winxml = ABI::Windows::Data::Xml;
|
| +namespace windevs = ABI::Windows::Devices;
|
| +namespace winfoundtn = ABI::Windows::Foundation;
|
| +namespace wingfx = ABI::Windows::Graphics;
|
| +namespace winui = ABI::Windows::UI;
|
| +namespace winsys = ABI::Windows::System;
|
| +namespace winstorage = ABI::Windows::Storage;
|
| +
|
| +namespace base {
|
| +class FilePath;
|
| +} // namespace base
|
| +
|
| +typedef winfoundtn::ITypedEventHandler<
|
| + winui::Notifications::ToastNotification*, IInspectable*>
|
| + ToastActivatedHandler;
|
| +
|
| +typedef winfoundtn::ITypedEventHandler<
|
| + winui::Notifications::ToastNotification*,
|
| + winui::Notifications::ToastDismissedEventArgs*> ToastDismissedHandler;
|
| +
|
| +typedef winfoundtn::ITypedEventHandler<
|
| + winui::Notifications::ToastNotification*,
|
| + winui::Notifications::ToastFailedEventArgs*> ToastFailedHandler;
|
| +
|
| +// This class provides an abstraction to COM calls to display and process
|
| +// Notification Toast in Windows. Features:
|
| +// - Stores HRESULT |hr_|, and coarse accessors HasFailed() or StillOkay().
|
| +// - Failure is permanent, and on failure all subsequent calls become no-op.
|
| +// - An implicit "current element" is stored, which is the target of various
|
| +// XML operations.
|
| +class NotificationToastHelperWin {
|
| + public:
|
| + NotificationToastHelperWin() = default;
|
| + ~NotificationToastHelperWin() = default;
|
| +
|
| + bool StillOkay() const { return SUCCEEDED(hr_); }
|
| + bool HasFailed() const { return !SUCCEEDED(hr_); }
|
| +
|
| + // Creates |toast_manager_|.
|
| + void CreateToastManager();
|
| +
|
| + // Loads |toast_xml_| from template, also loads |document_element_|.
|
| + void LoadXMLFromTemplate(winui::Notifications::ToastTemplateType type);
|
| +
|
| + // For debugging.
|
| + // TODO(huangs): Remove.
|
| + // Loads |toast_xml_| directly from |xml_str|.
|
| + void LoadXMLFromString(const base::string16& xml_str);
|
| +
|
| + // For debugging.
|
| + // TODO(huangs): Remove.
|
| + void AlertToastXml();
|
| +
|
| + // Selects |document_element_| as the "current element".
|
| + void SelectDocument();
|
| +
|
| + // Selects element with |tag_name| and at |index| as the "current element".
|
| + void SelectElementByTagNameAndIndex(const base::string16& tag_name,
|
| + unsigned int index);
|
| +
|
| + // Converts a file path, e.g., "C:\\User\\test\\AppData\\Local\\Temp\\a.tmp"
|
| + // to a file URL, e.g., "file:///C:/User/test/AppData/Local/Temp/a.tmp".
|
| + base::string16 FilePathToFileUrl(const base::FilePath& file_path);
|
| +
|
| + // Removes the current element, and selects the parent.
|
| + void RemoveElement();
|
| +
|
| + // Appends a text node to the "current element".
|
| + void AppendText(const base::string16& text);
|
| +
|
| + // Sets an attribute of the "current element".
|
| + void SetAttribute(const base::string16& name, const base::string16& value);
|
| +
|
| + // Reads an attribute of the "current element".
|
| + base::string16 GetAttribute(const base::string16& name);
|
| +
|
| + // Creates a toast notifier.
|
| + void CreateToastNotifier();
|
| +
|
| + // Creates a toast notification.
|
| + void CreateToastNotification();
|
| +
|
| + // Loads an existing |toast_notification|. Also loads |toast_xml_| and
|
| + // |document_element_|.
|
| + void LoadNotificationAndXml(
|
| + winui::Notifications::IToastNotification* toast_notification);
|
| +
|
| + // Displays a toast notification, using |toast_xml_|.
|
| + void Show(mswr::ComPtr<ToastActivatedHandler> activated_handler,
|
| + mswr::ComPtr<ToastDismissedHandler> dismissed_handler,
|
| + mswr::ComPtr<ToastFailedHandler> failed_handler,
|
| + EventRegistrationToken* activated_token,
|
| + EventRegistrationToken* dismissed_token,
|
| + EventRegistrationToken* failed_token);
|
| +
|
| + private:
|
| + // Returned HSTRING should be deallocated by ::WindowsDeleteString(). This can
|
| + // be done by attaching the return value to mswrw::HString.
|
| + HSTRING MakeHString(const base::string16& str);
|
| +
|
| + // Creates an intermediate text node.
|
| + void CreateTextNode(const base::string16& text,
|
| + mswr::ComPtr<winxml::Dom::IXmlNode>* node);
|
| +
|
| + HRESULT hr_ = S_OK;
|
| + mswr::ComPtr<winui::Notifications::IToastNotificationManagerStatics>
|
| + toast_manager_;
|
| + mswr::ComPtr<winxml::Dom::IXmlDocument> toast_xml_;
|
| + mswr::ComPtr<winxml::Dom::IXmlElement> document_element_;
|
| + mswr::ComPtr<winxml::Dom::IXmlElement> cur_element_;
|
| +
|
| + mswr::ComPtr<winui::Notifications::IToastNotifier> notifier_;
|
| + mswr::ComPtr<winui::Notifications::IToastNotification> toast_notification_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(NotificationToastHelperWin);
|
| +};
|
| +
|
| +#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TOAST_HELPER_WIN_H_
|
|
|