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

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

Issue 2920303002: Add a NotificationTemplateBuilder for Action Center toasts (Closed)
Patch Set: Created 3 years, 6 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 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
Peter Beverloo 2017/06/05 17:06:25 Should this class be responsible for extracting th
Finnur 2017/06/06 11:00:09 Hmm... Not sure.
41 private:
42 friend class NotificationTemplateBuilderTest;
43
44 NotificationTemplateBuilder();
45
46 // Formats the |origin| for display in the notification template.
47 std::string FormatOrigin(const GURL& origin) const;
48
49 // Writes the <toast> element with the |notification_id| as the launch string.
50 // Also closes the |xml_writer_| for writing as the toast is now compelte.
Finnur 2017/06/06 11:00:09 s/compelte/complete/
Peter Beverloo 2017/06/16 15:40:21 Done.
51 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-toas t
52 void StartToastElement(const std::string& notification_id);
53 void EndToastElement();
54
55 // Writes the <visual> element.
56 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-visu al
57 void StartVisualElement();
58 void EndVisualElement();
59
60 // Writes the <binding> element with the given |template_name|.
61 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-bind ing
62 void StartBindingElement(const std::string& template_name);
63 void EndBindingElement();
64
65 // Writes the <text> element with the given |id| and |content|.
66 // https://docs.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-text
67 void WriteTextElement(const std::string& id, const std::string& content);
68
69 // The XML writer to which the template will be written.
70 std::unique_ptr<XmlWriter> xml_writer_;
71
72 DISALLOW_COPY_AND_ASSIGN(NotificationTemplateBuilder);
73 };
74
75 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEMPLATE_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698