| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg
istration.showNotification() instead."); | 72 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg
istration.showNotification() instead."); |
| 73 return nullptr; | 73 return nullptr; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // The Web Notification constructor may not be used in Service Worker contex
ts. | 76 // The Web Notification constructor may not be used in Service Worker contex
ts. |
| 77 if (context->isServiceWorkerGlobalScope()) { | 77 if (context->isServiceWorkerGlobalScope()) { |
| 78 exceptionState.throwTypeError("Illegal constructor."); | 78 exceptionState.throwTypeError("Illegal constructor."); |
| 79 return nullptr; | 79 return nullptr; |
| 80 } | 80 } |
| 81 | 81 |
| 82 // If options's silent is true, and options's vibrate is present, throw a Ty
peError exception. |
| 83 if (options.hasVibrate() && options.silent()) { |
| 84 exceptionState.throwTypeError("Silent notifications must not specify vib
ration patterns."); |
| 85 return nullptr; |
| 86 } |
| 87 |
| 82 RefPtr<SerializedScriptValue> data; | 88 RefPtr<SerializedScriptValue> data; |
| 83 if (options.hasData()) { | 89 if (options.hasData()) { |
| 84 data = SerializedScriptValueFactory::instance().create(options.data(), n
ullptr, exceptionState, options.data().isolate()); | 90 data = SerializedScriptValueFactory::instance().create(options.data(), n
ullptr, exceptionState, options.data().isolate()); |
| 85 if (exceptionState.hadException()) | 91 if (exceptionState.hadException()) |
| 86 return nullptr; | 92 return nullptr; |
| 87 } | 93 } |
| 88 | 94 |
| 89 Notification* notification = new Notification(title, context); | 95 Notification* notification = new Notification(title, context); |
| 90 | 96 |
| 91 notification->setBody(options.body()); | 97 notification->setBody(options.body()); |
| 92 notification->setTag(options.tag()); | 98 notification->setTag(options.tag()); |
| 93 notification->setLang(options.lang()); | 99 notification->setLang(options.lang()); |
| 94 notification->setDir(options.dir()); | 100 notification->setDir(options.dir()); |
| 101 notification->setVibrate(NavigatorVibration::sanitizeVibrationPattern(option
s.vibrate())); |
| 95 notification->setSilent(options.silent()); | 102 notification->setSilent(options.silent()); |
| 96 notification->setSerializedData(data.release()); | 103 notification->setSerializedData(data.release()); |
| 97 if (options.hasIcon()) { | 104 if (options.hasIcon()) { |
| 98 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(
options.icon()); | 105 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL(
options.icon()); |
| 99 if (!iconUrl.isEmpty() && iconUrl.isValid()) | 106 if (!iconUrl.isEmpty() && iconUrl.isValid()) |
| 100 notification->setIconUrl(iconUrl); | 107 notification->setIconUrl(iconUrl); |
| 101 } | 108 } |
| 102 | 109 |
| 103 String insecureOriginMessage; | 110 String insecureOriginMessage; |
| 104 UseCounter::Feature feature = context->isPrivilegedContext(insecureOriginMes
sage) | 111 UseCounter::Feature feature = context->isPrivilegedContext(insecureOriginMes
sage) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 notification->setPersistentId(persistentId); | 125 notification->setPersistentId(persistentId); |
| 119 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); | 126 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR
ight ? "ltr" : "rtl"); |
| 120 notification->setLang(data.lang); | 127 notification->setLang(data.lang); |
| 121 notification->setBody(data.body); | 128 notification->setBody(data.body); |
| 122 notification->setTag(data.tag); | 129 notification->setTag(data.tag); |
| 123 notification->setSilent(data.silent); | 130 notification->setSilent(data.silent); |
| 124 | 131 |
| 125 if (!data.icon.isEmpty()) | 132 if (!data.icon.isEmpty()) |
| 126 notification->setIconUrl(data.icon); | 133 notification->setIconUrl(data.icon); |
| 127 | 134 |
| 135 if (!data.vibrate.isEmpty()) { |
| 136 NavigatorVibration::VibrationPattern pattern; |
| 137 pattern.appendRange(data.vibrate.begin(), data.vibrate.end()); |
| 138 notification->setVibrate(pattern); |
| 139 } |
| 140 |
| 128 const WebVector<char>& dataBytes = data.data; | 141 const WebVector<char>& dataBytes = data.data; |
| 129 if (!dataBytes.isEmpty()) { | 142 if (!dataBytes.isEmpty()) { |
| 130 notification->setSerializedData(SerializedScriptValueFactory::instance()
.createFromWireBytes(dataBytes.data(), dataBytes.size())); | 143 notification->setSerializedData(SerializedScriptValueFactory::instance()
.createFromWireBytes(dataBytes.data(), dataBytes.size())); |
| 131 notification->serializedData()->registerMemoryAllocatedWithCurrentScript
Context(); | 144 notification->serializedData()->registerMemoryAllocatedWithCurrentScript
Context(); |
| 132 } | 145 } |
| 133 | 146 |
| 134 notification->setState(NotificationStateShowing); | 147 notification->setState(NotificationStateShowing); |
| 135 notification->suspendIfNeeded(); | 148 notification->suspendIfNeeded(); |
| 136 return notification; | 149 return notification; |
| 137 } | 150 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 SecurityOrigin* origin = executionContext()->securityOrigin(); | 209 SecurityOrigin* origin = executionContext()->securityOrigin(); |
| 197 ASSERT(origin); | 210 ASSERT(origin); |
| 198 | 211 |
| 199 // FIXME: Do CSP checks on the associated notification icon. | 212 // FIXME: Do CSP checks on the associated notification icon. |
| 200 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 213 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D
irectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
| 201 | 214 |
| 202 // The lifetime and availability of non-persistent notifications is tied to
the page | 215 // The lifetime and availability of non-persistent notifications is tied to
the page |
| 203 // they were created by, and thus the data doesn't have to be known to the e
mbedder. | 216 // they were created by, and thus the data doesn't have to be known to the e
mbedder. |
| 204 Vector<char> emptyDataWireBytes; | 217 Vector<char> emptyDataWireBytes; |
| 205 | 218 |
| 206 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_silent, emptyDataWireBytes); | 219 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_
iconUrl, m_vibrate, m_silent, emptyDataWireBytes); |
| 207 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); | 220 notificationManager()->show(WebSerializedOrigin(*origin), notificationData,
this); |
| 208 | 221 |
| 209 m_state = NotificationStateShowing; | 222 m_state = NotificationStateShowing; |
| 210 } | 223 } |
| 211 | 224 |
| 212 void Notification::close() | 225 void Notification::close() |
| 213 { | 226 { |
| 214 if (m_state != NotificationStateShowing) | 227 if (m_state != NotificationStateShowing) |
| 215 return; | 228 return; |
| 216 | 229 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 { | 267 { |
| 255 // The notification will be showing when the user initiated the close, or it
will be | 268 // The notification will be showing when the user initiated the close, or it
will be |
| 256 // closing if the developer initiated the close. | 269 // closing if the developer initiated the close. |
| 257 if (m_state != NotificationStateShowing && m_state != NotificationStateClosi
ng) | 270 if (m_state != NotificationStateShowing && m_state != NotificationStateClosi
ng) |
| 258 return; | 271 return; |
| 259 | 272 |
| 260 m_state = NotificationStateClosed; | 273 m_state = NotificationStateClosed; |
| 261 dispatchEvent(Event::create(EventTypeNames::close)); | 274 dispatchEvent(Event::create(EventTypeNames::close)); |
| 262 } | 275 } |
| 263 | 276 |
| 277 NavigatorVibration::VibrationPattern Notification::vibrate(bool& isNull) const |
| 278 { |
| 279 isNull = m_vibrate.isEmpty(); |
| 280 return m_vibrate; |
| 281 } |
| 282 |
| 264 TextDirection Notification::direction() const | 283 TextDirection Notification::direction() const |
| 265 { | 284 { |
| 266 // FIXME: Resolve dir()=="auto" against the document. | 285 // FIXME: Resolve dir()=="auto" against the document. |
| 267 return dir() == "rtl" ? RTL : LTR; | 286 return dir() == "rtl" ? RTL : LTR; |
| 268 } | 287 } |
| 269 | 288 |
| 270 String Notification::permissionString(WebNotificationPermission permission) | 289 String Notification::permissionString(WebNotificationPermission permission) |
| 271 { | 290 { |
| 272 switch (permission) { | 291 switch (permission) { |
| 273 case WebNotificationPermissionAllowed: | 292 case WebNotificationPermissionAllowed: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); | 355 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i
solate())); |
| 337 } | 356 } |
| 338 | 357 |
| 339 DEFINE_TRACE(Notification) | 358 DEFINE_TRACE(Notification) |
| 340 { | 359 { |
| 341 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); | 360 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis
itor); |
| 342 ActiveDOMObject::trace(visitor); | 361 ActiveDOMObject::trace(visitor); |
| 343 } | 362 } |
| 344 | 363 |
| 345 } // namespace blink | 364 } // namespace blink |
| OLD | NEW |