| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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_TEMPLATE_BUILDER_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEMPLATE_BUILDER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 |
| 13 class GURL; |
| 14 class XmlWriter; |
| 15 |
| 16 namespace message_center { |
| 17 class Notification; |
| 18 } |
| 19 |
| 20 // Builds XML-based notification templates for displaying a given notification |
| 21 // in the Windows Action Center. |
| 22 // |
| 23 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/schema-root |
| 24 // https://msdn.microsoft.com/library/1a437614-4259-426b-8e3f-ca57368b2e7a |
| 25 // |
| 26 // The current builder is a best-effort implementation that supports the title |
| 27 // body text and attribution of a notification. |
| 28 class NotificationTemplateBuilder { |
| 29 public: |
| 30 // Builds the notification template for the given |notification|. The given |
| 31 // |notification_id| will be available when the user interacts with the toast. |
| 32 static std::unique_ptr<NotificationTemplateBuilder> Build( |
| 33 const std::string& notification_id, |
| 34 const message_center::Notification& notification); |
| 35 |
| 36 ~NotificationTemplateBuilder(); |
| 37 |
| 38 // Gets the XML template that was created by this builder. |
| 39 std::string GetNotificationTemplate(); |
| 40 |
| 41 private: |
| 42 NotificationTemplateBuilder(); |
| 43 |
| 44 // Formats the |origin| for display in the notification template. |
| 45 std::string FormatOrigin(const GURL& origin) const; |
| 46 |
| 47 // Writes the <toast> element with the |notification_id| as the launch string. |
| 48 // Also closes the |xml_writer_| for writing as the toast is now complete. |
| 49 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-toas
t |
| 50 void StartToastElement(const std::string& notification_id); |
| 51 void EndToastElement(); |
| 52 |
| 53 // Writes the <visual> element. |
| 54 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-visu
al |
| 55 void StartVisualElement(); |
| 56 void EndVisualElement(); |
| 57 |
| 58 // Writes the <binding> element with the given |template_name|. |
| 59 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-bind
ing |
| 60 void StartBindingElement(const std::string& template_name); |
| 61 void EndBindingElement(); |
| 62 |
| 63 // Writes the <text> element with the given |id| and |content|. |
| 64 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-text |
| 65 void WriteTextElement(const std::string& id, const std::string& content); |
| 66 |
| 67 // The XML writer to which the template will be written. |
| 68 std::unique_ptr<XmlWriter> xml_writer_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(NotificationTemplateBuilder); |
| 71 }; |
| 72 |
| 73 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEMPLATE_BUILDER_H_ |
| OLD | NEW |