| OLD | NEW |
| 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 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef Notification_h | 31 #ifndef Notification_h |
| 32 #define Notification_h | 32 #define Notification_h |
| 33 | 33 |
| 34 #include "bindings/core/v8/SerializedScriptValue.h" | 34 #include "bindings/core/v8/SerializedScriptValue.h" |
| 35 #include "core/dom/ActiveDOMObject.h" | 35 #include "core/dom/ActiveDOMObject.h" |
| 36 #include "modules/EventTargetModules.h" | 36 #include "modules/EventTargetModules.h" |
| 37 #include "modules/ModulesExport.h" | 37 #include "modules/ModulesExport.h" |
| 38 #include "modules/notifications/NotificationAction.h" |
| 38 #include "modules/vibration/NavigatorVibration.h" | 39 #include "modules/vibration/NavigatorVibration.h" |
| 39 #include "platform/AsyncMethodRunner.h" | 40 #include "platform/AsyncMethodRunner.h" |
| 40 #include "platform/heap/Handle.h" | 41 #include "platform/heap/Handle.h" |
| 41 #include "platform/text/TextDirection.h" | 42 #include "platform/text/TextDirection.h" |
| 42 #include "platform/weborigin/KURL.h" | 43 #include "platform/weborigin/KURL.h" |
| 44 #include "public/platform/WebVector.h" |
| 45 #include "public/platform/modules/notifications/WebNotificationAction.h" |
| 43 #include "public/platform/modules/notifications/WebNotificationDelegate.h" | 46 #include "public/platform/modules/notifications/WebNotificationDelegate.h" |
| 44 #include "public/platform/modules/notifications/WebNotificationPermission.h" | 47 #include "public/platform/modules/notifications/WebNotificationPermission.h" |
| 45 #include "wtf/PassOwnPtr.h" | 48 #include "wtf/PassOwnPtr.h" |
| 46 #include "wtf/PassRefPtr.h" | 49 #include "wtf/PassRefPtr.h" |
| 47 #include "wtf/RefCounted.h" | 50 #include "wtf/RefCounted.h" |
| 48 #include "wtf/RefPtr.h" | 51 #include "wtf/RefPtr.h" |
| 49 | 52 |
| 50 namespace blink { | 53 namespace blink { |
| 51 | 54 |
| 52 class ExecutionContext; | 55 class ExecutionContext; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 83 void dispatchClickEvent() override; | 86 void dispatchClickEvent() override; |
| 84 void dispatchErrorEvent() override; | 87 void dispatchErrorEvent() override; |
| 85 void dispatchCloseEvent() override; | 88 void dispatchCloseEvent() override; |
| 86 | 89 |
| 87 String title() const { return m_title; } | 90 String title() const { return m_title; } |
| 88 String dir() const { return m_dir; } | 91 String dir() const { return m_dir; } |
| 89 String lang() const { return m_lang; } | 92 String lang() const { return m_lang; } |
| 90 String body() const { return m_body; } | 93 String body() const { return m_body; } |
| 91 String tag() const { return m_tag; } | 94 String tag() const { return m_tag; } |
| 92 String icon() const { return m_iconUrl; } | 95 String icon() const { return m_iconUrl; } |
| 93 NavigatorVibration::VibrationPattern vibrate(bool& isNull) const; | 96 const NavigatorVibration::VibrationPattern& vibrate(bool& isNull) const; |
| 94 bool silent() const { return m_silent; } | 97 bool silent() const { return m_silent; } |
| 95 ScriptValue data(ScriptState*) const; | 98 ScriptValue data(ScriptState*) const; |
| 99 const HeapVector<NotificationAction>& actions() const { return m_actions; } |
| 96 | 100 |
| 97 TextDirection direction() const; | 101 TextDirection direction() const; |
| 98 KURL iconURL() const { return m_iconUrl; } | 102 KURL iconURL() const { return m_iconUrl; } |
| 99 SerializedScriptValue* serializedData() const { return m_serializedData.get(
); } | 103 SerializedScriptValue* serializedData() const { return m_serializedData.get(
); } |
| 100 | 104 |
| 101 static String permissionString(WebNotificationPermission); | 105 static String permissionString(WebNotificationPermission); |
| 102 static String permission(ExecutionContext*); | 106 static String permission(ExecutionContext*); |
| 103 static WebNotificationPermission checkPermission(ExecutionContext*); | 107 static WebNotificationPermission checkPermission(ExecutionContext*); |
| 104 static void requestPermission(ExecutionContext*, NotificationPermissionCallb
ack* = nullptr); | 108 static void requestPermission(ExecutionContext*, NotificationPermissionCallb
ack* = nullptr); |
| 105 | 109 |
| 106 static unsigned maxActions(); | 110 static unsigned maxActions(); |
| 107 | 111 |
| 112 static void actionsToWebActions(const HeapVector<NotificationAction>& action
s, WebVector<WebNotificationAction>* webActions); |
| 113 |
| 108 // EventTarget interface. | 114 // EventTarget interface. |
| 109 ExecutionContext* executionContext() const final { return ActiveDOMObject::e
xecutionContext(); } | 115 ExecutionContext* executionContext() const final { return ActiveDOMObject::e
xecutionContext(); } |
| 110 const AtomicString& interfaceName() const override; | 116 const AtomicString& interfaceName() const override; |
| 111 | 117 |
| 112 // ActiveDOMObject interface. | 118 // ActiveDOMObject interface. |
| 113 void stop() override; | 119 void stop() override; |
| 114 bool hasPendingActivity() const override; | 120 bool hasPendingActivity() const override; |
| 115 | 121 |
| 116 DECLARE_VIRTUAL_TRACE(); | 122 DECLARE_VIRTUAL_TRACE(); |
| 117 | 123 |
| 118 protected: | 124 protected: |
| 119 // EventTarget interface. | 125 // EventTarget interface. |
| 120 bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final; | 126 bool dispatchEventInternal(PassRefPtrWillBeRawPtr<Event>) final; |
| 121 | 127 |
| 122 private: | 128 private: |
| 129 static void webActionsToActions(const WebVector<WebNotificationAction>& webA
ctions, HeapVector<NotificationAction>* actions); |
| 130 |
| 123 Notification(const String& title, ExecutionContext*); | 131 Notification(const String& title, ExecutionContext*); |
| 124 | 132 |
| 125 void scheduleShow(); | 133 void scheduleShow(); |
| 126 | 134 |
| 127 // Calling show() may start asynchronous operation. If this object has | 135 // Calling show() may start asynchronous operation. If this object has |
| 128 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being | 136 // a V8 wrapper, hasPendingActivity() prevents the wrapper from being |
| 129 // collected while m_state is Showing, and so this instance stays alive | 137 // collected while m_state is Showing, and so this instance stays alive |
| 130 // until the operation completes. Otherwise, you need to hold a ref on this | 138 // until the operation completes. Otherwise, you need to hold a ref on this |
| 131 // instance until the operation completes. | 139 // instance until the operation completes. |
| 132 void show(); | 140 void show(); |
| 133 | 141 |
| 134 void setDir(const String& dir) { m_dir = dir; } | 142 void setDir(const String& dir) { m_dir = dir; } |
| 135 void setLang(const String& lang) { m_lang = lang; } | 143 void setLang(const String& lang) { m_lang = lang; } |
| 136 void setBody(const String& body) { m_body = body; } | 144 void setBody(const String& body) { m_body = body; } |
| 137 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; } | 145 void setIconUrl(KURL iconUrl) { m_iconUrl = iconUrl; } |
| 138 void setTag(const String& tag) { m_tag = tag; } | 146 void setTag(const String& tag) { m_tag = tag; } |
| 139 void setVibrate(const NavigatorVibration::VibrationPattern& vibrate) { m_vib
rate = vibrate; } | 147 void setVibrate(const NavigatorVibration::VibrationPattern& vibrate) { m_vib
rate = vibrate; } |
| 140 void setSilent(bool silent) { m_silent = silent; } | 148 void setSilent(bool silent) { m_silent = silent; } |
| 141 void setSerializedData(PassRefPtr<SerializedScriptValue> data) { m_serialize
dData = data; } | 149 void setSerializedData(PassRefPtr<SerializedScriptValue> data) { m_serialize
dData = data; } |
| 150 void setActions(const HeapVector<NotificationAction>& actions) { m_actions =
actions; } |
| 142 | 151 |
| 143 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId;
} | 152 void setPersistentId(int64_t persistentId) { m_persistentId = persistentId;
} |
| 144 | 153 |
| 145 private: | |
| 146 String m_title; | 154 String m_title; |
| 147 String m_dir; | 155 String m_dir; |
| 148 String m_lang; | 156 String m_lang; |
| 149 String m_body; | 157 String m_body; |
| 150 String m_tag; | 158 String m_tag; |
| 151 NavigatorVibration::VibrationPattern m_vibrate; | 159 NavigatorVibration::VibrationPattern m_vibrate; |
| 152 bool m_silent; | 160 bool m_silent; |
| 153 RefPtr<SerializedScriptValue> m_serializedData; | 161 RefPtr<SerializedScriptValue> m_serializedData; |
| 162 HeapVector<NotificationAction> m_actions; |
| 154 | 163 |
| 155 KURL m_iconUrl; | 164 KURL m_iconUrl; |
| 156 | 165 |
| 157 // Notifications can either be bound to the page, which means they're identi
fied by | 166 // Notifications can either be bound to the page, which means they're identi
fied by |
| 158 // their delegate, or persistent, which means they're identified by a persis
tent Id | 167 // their delegate, or persistent, which means they're identified by a persis
tent Id |
| 159 // given to us by the embedder. This influences how we close the notificatio
n. | 168 // given to us by the embedder. This influences how we close the notificatio
n. |
| 160 int64_t m_persistentId; | 169 int64_t m_persistentId; |
| 161 | 170 |
| 162 enum NotificationState { | 171 enum NotificationState { |
| 163 NotificationStateIdle, | 172 NotificationStateIdle, |
| 164 NotificationStateShowing, | 173 NotificationStateShowing, |
| 165 NotificationStateClosing, | 174 NotificationStateClosing, |
| 166 NotificationStateClosed | 175 NotificationStateClosed |
| 167 }; | 176 }; |
| 168 | 177 |
| 169 // Only to be used by the Notification::create() method when notifications w
ere created | 178 // Only to be used by the Notification::create() method when notifications w
ere created |
| 170 // by the embedder rather than by Blink. | 179 // by the embedder rather than by Blink. |
| 171 void setState(NotificationState state) { m_state = state; } | 180 void setState(NotificationState state) { m_state = state; } |
| 172 | 181 |
| 173 NotificationState m_state; | 182 NotificationState m_state; |
| 174 | 183 |
| 175 AsyncMethodRunner<Notification> m_asyncRunner; | 184 AsyncMethodRunner<Notification> m_asyncRunner; |
| 176 }; | 185 }; |
| 177 | 186 |
| 178 } // namespace blink | 187 } // namespace blink |
| 179 | 188 |
| 180 #endif // Notification_h | 189 #endif // Notification_h |
| OLD | NEW |