| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "platform/UserGestureIndicator.h" | 48 #include "platform/UserGestureIndicator.h" |
| 49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
| 50 #include "public/platform/WebSerializedOrigin.h" | 50 #include "public/platform/WebSerializedOrigin.h" |
| 51 #include "public/platform/WebString.h" | 51 #include "public/platform/WebString.h" |
| 52 #include "public/platform/modules/notifications/WebNotificationData.h" | 52 #include "public/platform/modules/notifications/WebNotificationData.h" |
| 53 #include "public/platform/modules/notifications/WebNotificationManager.h" | 53 #include "public/platform/modules/notifications/WebNotificationManager.h" |
| 54 | 54 |
| 55 namespace blink { | 55 namespace blink { |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 const int64_t kInvalidPersistentId = -1; |
| 59 |
| 58 WebNotificationManager* notificationManager() | 60 WebNotificationManager* notificationManager() |
| 59 { | 61 { |
| 60 return Platform::current()->notificationManager(); | 62 return Platform::current()->notificationManager(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 } // namespace | 65 } // namespace |
| 64 | 66 |
| 65 Notification* Notification::create(ExecutionContext* context, const String& titl
e, const NotificationOptions& options, ExceptionState& exceptionState) | 67 Notification* Notification::create(ExecutionContext* context, const String& titl
e, const NotificationOptions& options, ExceptionState& exceptionState) |
| 66 { | 68 { |
| 67 // The Web Notification constructor may be disabled through a runtime featur
e. The | 69 // The Web Notification constructor may be disabled through a runtime featur
e. The |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 String insecureOriginMessage; | 103 String insecureOriginMessage; |
| 102 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq
uiringSecureOrigin(insecureOriginMessage) | 104 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq
uiringSecureOrigin(insecureOriginMessage) |
| 103 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur
eOrigin; | 105 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur
eOrigin; |
| 104 UseCounter::count(context, feature); | 106 UseCounter::count(context, feature); |
| 105 | 107 |
| 106 notification->scheduleShow(); | 108 notification->scheduleShow(); |
| 107 notification->suspendIfNeeded(); | 109 notification->suspendIfNeeded(); |
| 108 return notification; | 110 return notification; |
| 109 } | 111 } |
| 110 | 112 |
| 111 Notification* Notification::create(ExecutionContext* context, const String& pers
istentId, const WebNotificationData& data) | 113 Notification* Notification::create(ExecutionContext* context, int64_t persistent
Id, const WebNotificationData& data) |
| 112 { | 114 { |
| 113 Notification* notification = new Notification(data.title, context); | 115 Notification* notification = new Notification(data.title, context); |
| 114 | 116 |
| 115 notification->setPersistentId(persistentId); | 117 notification->setPersistentId(persistentId); |
| 116 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); | 118 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); |
| 117 notification->setLang(data.lang); | 119 notification->setLang(data.lang); |
| 118 notification->setBody(data.body); | 120 notification->setBody(data.body); |
| 119 notification->setTag(data.tag); | 121 notification->setTag(data.tag); |
| 120 notification->setSilent(data.silent); | 122 notification->setSilent(data.silent); |
| 121 | 123 |
| 122 if (!data.icon.isEmpty()) | 124 if (!data.icon.isEmpty()) |
| 123 notification->setIconUrl(data.icon); | 125 notification->setIconUrl(data.icon); |
| 124 | 126 |
| 125 const WebVector<char>& dataBytes = data.data; | 127 const WebVector<char>& dataBytes = data.data; |
| 126 if (!dataBytes.isEmpty()) { | 128 if (!dataBytes.isEmpty()) { |
| 127 notification->setSerializedData(SerializedScriptValueFactory::instance()
.createFromWireBytes(dataBytes.data(), dataBytes.size())); | 129 notification->setSerializedData(SerializedScriptValueFactory::instance()
.createFromWireBytes(dataBytes.data(), dataBytes.size())); |
| 128 notification->serializedData()->registerMemoryAllocatedWithCurrentScript
Context(); | 130 notification->serializedData()->registerMemoryAllocatedWithCurrentScript
Context(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 notification->setState(NotificationStateShowing); | 133 notification->setState(NotificationStateShowing); |
| 132 notification->suspendIfNeeded(); | 134 notification->suspendIfNeeded(); |
| 133 return notification; | 135 return notification; |
| 134 } | 136 } |
| 135 | 137 |
| 138 Notification* Notification::create(ExecutionContext* context, const String& pers
istentId, const WebNotificationData& data) |
| 139 { |
| 140 Notification* notification = new Notification(data.title, context); |
| 141 |
| 142 notification->setPersistentIdString(persistentId); |
| 143 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); |
| 144 notification->setLang(data.lang); |
| 145 notification->setBody(data.body); |
| 146 notification->setTag(data.tag); |
| 147 notification->setSilent(data.silent); |
| 148 |
| 149 if (!data.icon.isEmpty()) |
| 150 notification->setIconUrl(data.icon); |
| 151 |
| 152 const WebVector<char>& dataBytes = data.data; |
| 153 if (!dataBytes.isEmpty()) { |
| 154 notification->setSerializedData(SerializedScriptValueFactory::instance()
.createFromWireBytes(dataBytes.data(), dataBytes.size())); |
| 155 notification->serializedData()->registerMemoryAllocatedWithCurrentScript
Context(); |
| 156 } |
| 157 |
| 158 notification->setState(NotificationStateShowing); |
| 159 notification->suspendIfNeeded(); |
| 160 return notification; |
| 161 } |
| 162 |
| 136 Notification::Notification(const String& title, ExecutionContext* context) | 163 Notification::Notification(const String& title, ExecutionContext* context) |
| 137 : ActiveDOMObject(context) | 164 : ActiveDOMObject(context) |
| 138 , m_title(title) | 165 , m_title(title) |
| 139 , m_dir("auto") | 166 , m_dir("auto") |
| 140 , m_silent(false) | 167 , m_silent(false) |
| 168 , m_persistentId(kInvalidPersistentId) |
| 141 , m_state(NotificationStateIdle) | 169 , m_state(NotificationStateIdle) |
| 142 , m_asyncRunner(this, &Notification::show) | 170 , m_asyncRunner(this, &Notification::show) |
| 143 { | 171 { |
| 144 ASSERT(notificationManager()); | 172 ASSERT(notificationManager()); |
| 145 } | 173 } |
| 146 | 174 |
| 147 Notification::~Notification() | 175 Notification::~Notification() |
| 148 { | 176 { |
| 149 } | 177 } |
| 150 | 178 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 178 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); | 206 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); |
| 179 | 207 |
| 180 m_state = NotificationStateShowing; | 208 m_state = NotificationStateShowing; |
| 181 } | 209 } |
| 182 | 210 |
| 183 void Notification::close() | 211 void Notification::close() |
| 184 { | 212 { |
| 185 if (m_state != NotificationStateShowing) | 213 if (m_state != NotificationStateShowing) |
| 186 return; | 214 return; |
| 187 | 215 |
| 188 if (m_persistentId.isEmpty()) { | 216 if (m_persistentIdString.isEmpty() && m_persistentId == kInvalidPersistentId
) { |
| 189 // Fire the close event asynchronously. | 217 // Fire the close event asynchronously. |
| 190 executionContext()->postTask(FROM_HERE, createSameThreadTask(&Notificati
on::dispatchCloseEvent, this)); | 218 executionContext()->postTask(FROM_HERE, createSameThreadTask(&Notificati
on::dispatchCloseEvent, this)); |
| 191 | 219 |
| 192 m_state = NotificationStateClosing; | 220 m_state = NotificationStateClosing; |
| 193 notificationManager()->close(this); | 221 notificationManager()->close(this); |
| 194 } else { | 222 } else { |
| 195 m_state = NotificationStateClosed; | 223 m_state = NotificationStateClosed; |
| 196 | 224 |
| 197 SecurityOrigin* origin = executionContext()->securityOrigin(); | 225 SecurityOrigin* origin = executionContext()->securityOrigin(); |
| 198 ASSERT(origin); | 226 ASSERT(origin); |
| 199 | 227 |
| 200 notificationManager()->closePersistent(WebSerializedOrigin(*origin), m_p
ersistentId); | 228 if (!m_persistentIdString.isEmpty()) |
| 229 notificationManager()->closePersistent(WebSerializedOrigin(*origin),
m_persistentIdString); |
| 230 else |
| 231 notificationManager()->closePersistent(WebSerializedOrigin(*origin),
m_persistentId); |
| 201 } | 232 } |
| 202 } | 233 } |
| 203 | 234 |
| 204 void Notification::dispatchShowEvent() | 235 void Notification::dispatchShowEvent() |
| 205 { | 236 { |
| 206 dispatchEvent(Event::create(EventTypeNames::show)); | 237 dispatchEvent(Event::create(EventTypeNames::show)); |
| 207 } | 238 } |
| 208 | 239 |
| 209 void Notification::dispatchClickEvent() | 240 void Notification::dispatchClickEvent() |
| 210 { | 241 { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); | 335 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); |
| 305 } | 336 } |
| 306 | 337 |
| 307 DEFINE_TRACE(Notification) | 338 DEFINE_TRACE(Notification) |
| 308 { | 339 { |
| 309 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); | 340 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); |
| 310 ActiveDOMObject::trace(visitor); | 341 ActiveDOMObject::trace(visitor); |
| 311 } | 342 } |
| 312 | 343 |
| 313 } // namespace blink | 344 } // namespace blink |
| OLD | NEW |