| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h" | 6 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // FIXME: Do the appropriate CORS checks on the icon URL. | 86 // FIXME: Do the appropriate CORS checks on the icon URL. |
| 87 | 87 |
| 88 KURL iconUrl; | 88 KURL iconUrl; |
| 89 if (options.hasIcon() && !options.icon().isEmpty()) { | 89 if (options.hasIcon() && !options.icon().isEmpty()) { |
| 90 iconUrl = executionContext->completeURL(options.icon()); | 90 iconUrl = executionContext->completeURL(options.icon()); |
| 91 if (!iconUrl.isValid()) | 91 if (!iconUrl.isValid()) |
| 92 iconUrl = KURL(); | 92 iconUrl = KURL(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio
nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 95 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio
nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
| 96 WebNotificationData::Priority priority = Notification::priorityEnum(options.
priority()); |
| 96 NavigatorVibration::VibrationPattern vibrate = NavigatorVibration::sanitizeV
ibrationPattern(options.vibrate()); | 97 NavigatorVibration::VibrationPattern vibrate = NavigatorVibration::sanitizeV
ibrationPattern(options.vibrate()); |
| 97 WebVector<WebNotificationAction> webActions; | 98 WebVector<WebNotificationAction> webActions; |
| 98 Notification::actionsToWebActions(options.actions(), &webActions); | 99 Notification::actionsToWebActions(options.actions(), &webActions); |
| 99 WebNotificationData notification(title, dir, options.lang(), options.body(),
options.tag(), iconUrl, vibrate, options.silent(), dataAsWireBytes, webActions)
; | 100 WebNotificationData notification(title, dir, options.lang(), options.body(),
options.tag(), priority, iconUrl, vibrate, options.silent(), dataAsWireBytes, w
ebActions); |
| 100 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v
oid>(resolver); | 101 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v
oid>(resolver); |
| 101 | 102 |
| 102 SecurityOrigin* origin = executionContext->securityOrigin(); | 103 SecurityOrigin* origin = executionContext->securityOrigin(); |
| 103 ASSERT(origin); | 104 ASSERT(origin); |
| 104 | 105 |
| 105 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); | 106 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); |
| 106 ASSERT(notificationManager); | 107 ASSERT(notificationManager); |
| 107 | 108 |
| 108 notificationManager->showPersistent(WebSecurityOrigin(origin), notification,
serviceWorkerRegistration.webRegistration(), callbacks); | 109 notificationManager->showPersistent(WebSecurityOrigin(origin), notification,
serviceWorkerRegistration.webRegistration(), callbacks); |
| 109 return promise; | 110 return promise; |
| 110 } | 111 } |
| 111 | 112 |
| 112 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta
te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get
NotificationOptions& options) | 113 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta
te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get
NotificationOptions& options) |
| 113 { | 114 { |
| 114 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 115 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 115 ScriptPromise promise = resolver->promise(); | 116 ScriptPromise promise = resolver->promise(); |
| 116 | 117 |
| 117 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica
tionArray, void>(resolver); | 118 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica
tionArray, void>(resolver); |
| 118 | 119 |
| 119 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); | 120 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); |
| 120 ASSERT(notificationManager); | 121 ASSERT(notificationManager); |
| 121 | 122 |
| 122 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati
on.webRegistration(), callbacks); | 123 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati
on.webRegistration(), callbacks); |
| 123 return promise; | 124 return promise; |
| 124 } | 125 } |
| 125 | 126 |
| 126 } // namespace blink | 127 } // namespace blink |
| OLD | NEW |