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

Side by Side Diff: third_party/WebKit/Source/modules/notifications/Notification.h

Issue 1904163002: Move Web Notifications to use Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@skbitmap-blink
Patch Set: it works \o/ Created 4 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
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 33
34 #include "bindings/core/v8/ActiveScriptWrappable.h" 34 #include "bindings/core/v8/ActiveScriptWrappable.h"
35 #include "bindings/core/v8/ScriptPromise.h" 35 #include "bindings/core/v8/ScriptPromise.h"
36 #include "bindings/core/v8/ScriptValue.h" 36 #include "bindings/core/v8/ScriptValue.h"
37 #include "bindings/core/v8/SerializedScriptValue.h" 37 #include "bindings/core/v8/SerializedScriptValue.h"
38 #include "core/dom/ActiveDOMObject.h" 38 #include "core/dom/ActiveDOMObject.h"
39 #include "core/dom/DOMTimeStamp.h" 39 #include "core/dom/DOMTimeStamp.h"
40 #include "modules/EventTargetModules.h" 40 #include "modules/EventTargetModules.h"
41 #include "modules/ModulesExport.h" 41 #include "modules/ModulesExport.h"
42 #include "modules/vibration/NavigatorVibration.h" 42 #include "modules/vibration/NavigatorVibration.h"
43 #include "mojo/public/cpp/bindings/binding.h"
43 #include "platform/AsyncMethodRunner.h" 44 #include "platform/AsyncMethodRunner.h"
44 #include "platform/heap/Handle.h" 45 #include "platform/heap/Handle.h"
45 #include "platform/weborigin/KURL.h" 46 #include "platform/weborigin/KURL.h"
46 #include "public/platform/WebVector.h" 47 #include "public/platform/WebVector.h"
47 #include "public/platform/modules/notifications/WebNotificationData.h" 48 #include "public/platform/modules/notifications/notification.mojom-blink.h"
48 #include "public/platform/modules/notifications/WebNotificationDelegate.h" 49 #include "public/platform/modules/notifications/notification_service.mojom-blink .h"
49 #include "public/platform/modules/permissions/permission_status.mojom.h" 50 #include "public/platform/modules/permissions/permission_status.mojom.h"
50 51
51 namespace blink { 52 namespace blink {
52 53
53 class ExecutionContext; 54 class ExecutionContext;
54 class NotificationAction; 55 class NotificationAction;
56 class NotificationManager;
55 class NotificationOptions; 57 class NotificationOptions;
56 class NotificationPermissionCallback; 58 class NotificationPermissionCallback;
57 class NotificationResourcesLoader; 59 class NotificationResourcesLoader;
58 class ScriptState; 60 class ScriptState;
59 61
60 class MODULES_EXPORT Notification final : public EventTargetWithInlineData, publ ic ActiveScriptWrappable, public ActiveDOMObject, public WebNotificationDelegate { 62 class MODULES_EXPORT Notification final : public EventTargetWithInlineData, publ ic ActiveScriptWrappable, public ActiveDOMObject, public mojom::blink::Notificat ionClient {
61 USING_GARBAGE_COLLECTED_MIXIN(Notification); 63 USING_GARBAGE_COLLECTED_MIXIN(Notification);
62 DEFINE_WRAPPERTYPEINFO(); 64 DEFINE_WRAPPERTYPEINFO();
63 public: 65 public:
64 // Used for JavaScript instantiations of the Notification object. Will autom atically schedule for 66 // Used for JavaScript instantiations of the Notification object. Will autom atically schedule for
65 // the notification to be displayed to the user when the developer-provided data is valid. 67 // the notification to be displayed to the user when the developer-provided data is valid.
66 static Notification* create(ExecutionContext*, const String& title, const No tificationOptions&, ExceptionState&); 68 static Notification* create(ExecutionContext*, const String& title, const No tificationOptions&, ExceptionState&);
67 69
68 // Used for embedder-created Notification objects. If |showing| is true, wil l initialize the 70 // Used for embedder-created Notification objects. If |showing| is true, wil l initialize the
69 // Notification's state as showing, or as closed otherwise. 71 // Notification's state as showing, or as closed otherwise.
70 static Notification* create(ExecutionContext*, int64_t persistentId, const W ebNotificationData&, bool showing); 72 static Notification* create(ExecutionContext*, mojom::blink::NotificationPtr , bool showing);
71 73
72 ~Notification() override; 74 ~Notification() override;
73 75
74 void close(); 76 void close();
75 77
76 DEFINE_ATTRIBUTE_EVENT_LISTENER(click); 78 DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
77 DEFINE_ATTRIBUTE_EVENT_LISTENER(show); 79 DEFINE_ATTRIBUTE_EVENT_LISTENER(show);
78 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 80 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
79 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); 81 DEFINE_ATTRIBUTE_EVENT_LISTENER(close);
80 82
81 // WebNotificationDelegate implementation. 83 // mojom::blink::NotificationClient implementation.
82 void dispatchShowEvent() override; 84 void OnClick() override;
83 void dispatchClickEvent() override; 85 void OnClose(mojom::blink::NotificationCloseResult result) override;
84 void dispatchErrorEvent() override;
85 void dispatchCloseEvent() override;
86 86
87 String title() const; 87 String title() const;
88 String dir() const; 88 String dir() const;
89 String lang() const; 89 String lang() const;
90 String body() const; 90 String body() const;
91 String tag() const; 91 String tag() const;
92 String icon() const; 92 String icon() const;
93 String badge() const; 93 String badge() const;
94 NavigatorVibration::VibrationPattern vibrate(bool& isNull) const; 94 NavigatorVibration::VibrationPattern vibrate(bool& isNull) const;
95 DOMTimeStamp timestamp() const; 95 DOMTimeStamp timestamp() const;
96 bool renotify() const; 96 bool renotify() const;
97 bool silent() const; 97 bool silent() const;
98 bool requireInteraction() const; 98 bool requireInteraction() const;
99 ScriptValue data(ScriptState*); 99 ScriptValue data(ScriptState*);
100 HeapVector<NotificationAction> actions() const; 100 HeapVector<NotificationAction> actions() const;
101 101
102 static String permissionString(mojom::PermissionStatus); 102 static String permissionString(mojom::PermissionStatus);
103 static String permission(ExecutionContext*); 103 static String permission(ExecutionContext*);
104 static mojom::PermissionStatus checkPermission(ExecutionContext*);
105 static ScriptPromise requestPermission(ScriptState*, NotificationPermissionC allback*); 104 static ScriptPromise requestPermission(ScriptState*, NotificationPermissionC allback*);
106 105
107 static size_t maxActions(); 106 static size_t maxActions();
108 107
109 // EventTarget interface. 108 // EventTarget interface.
110 ExecutionContext* getExecutionContext() const final { return ActiveDOMObject ::getExecutionContext(); } 109 ExecutionContext* getExecutionContext() const final { return ActiveDOMObject ::getExecutionContext(); }
111 const AtomicString& interfaceName() const override; 110 const AtomicString& interfaceName() const override;
112 111
113 // ActiveDOMObject interface. 112 // ActiveDOMObject interface.
114 void stop() override; 113 void stop() override;
115 114
116 // ActiveScriptWrappable interface. 115 // ActiveScriptWrappable interface.
117 bool hasPendingActivity() const final; 116 bool hasPendingActivity() const final;
118 117
119 DECLARE_VIRTUAL_TRACE(); 118 DECLARE_VIRTUAL_TRACE();
120 119
121 protected: 120 protected:
122 // EventTarget interface. 121 // EventTarget interface.
123 DispatchEventResult dispatchEventInternal(Event*) final; 122 DispatchEventResult dispatchEventInternal(Event*) final;
124 123
125 private: 124 private:
126 Notification(ExecutionContext*, const WebNotificationData&); 125 Notification(ExecutionContext*, mojom::blink::NotificationPtr);
126
127 // Returns the notification manager responsible for this notification.
128 NotificationManager* manager() const;
127 129
128 // Schedules an asynchronous call to |prepareShow|, allowing the constructor 130 // Schedules an asynchronous call to |prepareShow|, allowing the constructor
129 // to return so that events can be fired on the notification object. 131 // to return so that events can be fired on the notification object.
130 void schedulePrepareShow(); 132 void schedulePrepareShow();
131 133
132 // Checks permission and loads any necessary resources (this may be async) 134 // Checks permission and loads any necessary resources (this may be async)
133 // before showing the notification. 135 // before showing the notification.
134 void prepareShow(); 136 void prepareShow();
135 137
136 // Shows the notification, using the resources loaded by the 138 // Shows the |notification|, using the resources loaded by the given loader.
137 // NotificationResourcesLoader. 139 void didLoadResources(NotificationResourcesLoader*, mojom::blink::Notificati onPtr notification);
138 void didLoadResources(NotificationResourcesLoader*);
139 140
140 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId; } 141 // Fires the "show" event on the notification's object, stores the id given
142 // by the embedder in the local notification data.
143 void didShowNotification(mojom::blink::NotificationDisplayResult result, con st String& id);
141 144
142 WebNotificationData m_data; 145 mojom::blink::NotificationPtr m_data;
143 146
144 // ScriptValue representations of the developer-associated data. Initialized lazily on first access. 147 // ScriptValue representations of the developer-associated data. Initialized lazily on first access.
145 ScriptValue m_developerData; 148 ScriptValue m_developerData;
146 149
147 // Notifications can either be bound to the page, which means they're identi fied by
148 // their delegate, or persistent, which means they're identified by a persis tent Id
149 // given to us by the embedder. This influences how we close the notificatio n.
150 int64_t m_persistentId;
151
152 enum NotificationState { 150 enum NotificationState {
153 NotificationStateIdle, 151 NotificationStateIdle,
152 NotificationStateLoading,
154 NotificationStateShowing, 153 NotificationStateShowing,
155 NotificationStateClosing, 154 NotificationStateClosing,
156 NotificationStateClosed 155 NotificationStateClosed
157 }; 156 };
158 157
159 // Only to be used by the Notification::create() method when notifications w ere created 158 // Only to be used by the Notification::create() method when notifications w ere created
160 // by the embedder rather than by Blink. 159 // by the embedder rather than by Blink.
161 void setState(NotificationState state) { m_state = state; } 160 void setState(NotificationState state) { m_state = state; }
162 161
163 NotificationState m_state; 162 NotificationState m_state;
164 163
165 Member<AsyncMethodRunner<Notification>> m_prepareShowMethodRunner; 164 Member<AsyncMethodRunner<Notification>> m_prepareShowMethodRunner;
166 165
167 Member<NotificationResourcesLoader> m_loader; 166 Member<NotificationResourcesLoader> m_loader;
167
168 mojo::Binding<mojom::blink::NotificationClient> m_binding;
168 }; 169 };
169 170
170 } // namespace blink 171 } // namespace blink
171 172
172 #endif // Notification_h 173 #endif // Notification_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/modules.gypi ('k') | third_party/WebKit/Source/modules/notifications/Notification.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698