| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // FIXME: Unify the code path here with the Notification.create() function. | 65 // FIXME: Unify the code path here with the Notification.create() function. |
| 66 Vector<char> dataAsWireBytes; | 66 Vector<char> dataAsWireBytes; |
| 67 if (options.hasData()) { | 67 if (options.hasData()) { |
| 68 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta
nce().create(options.data().isolate(), options.data(), nullptr, exceptionState); | 68 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta
nce().create(options.data().isolate(), options.data(), nullptr, exceptionState); |
| 69 if (exceptionState.hadException()) | 69 if (exceptionState.hadException()) |
| 70 return exceptionState.reject(scriptState); | 70 return exceptionState.reject(scriptState); |
| 71 | 71 |
| 72 data->toWireBytes(dataAsWireBytes); | 72 data->toWireBytes(dataAsWireBytes); |
| 73 } | 73 } |
| 74 | 74 |
| 75 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 75 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 76 ScriptPromise promise = resolver->promise(); | 76 ScriptPromise promise = resolver->promise(); |
| 77 | 77 |
| 78 // FIXME: Do the appropriate CORS checks on the icon URL. | 78 // FIXME: Do the appropriate CORS checks on the icon URL. |
| 79 | 79 |
| 80 KURL iconUrl; | 80 KURL iconUrl; |
| 81 if (options.hasIcon() && !options.icon().isEmpty()) { | 81 if (options.hasIcon() && !options.icon().isEmpty()) { |
| 82 iconUrl = executionContext->completeURL(options.icon()); | 82 iconUrl = executionContext->completeURL(options.icon()); |
| 83 if (!iconUrl.isValid()) | 83 if (!iconUrl.isValid()) |
| 84 iconUrl = KURL(); | 84 iconUrl = KURL(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio
nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 87 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio
nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
| 88 NavigatorVibration::VibrationPattern vibrate = NavigatorVibration::sanitizeV
ibrationPattern(options.vibrate()); | 88 NavigatorVibration::VibrationPattern vibrate = NavigatorVibration::sanitizeV
ibrationPattern(options.vibrate()); |
| 89 WebNotificationData notification(title, dir, options.lang(), options.body(),
options.tag(), iconUrl, vibrate, options.silent(), dataAsWireBytes); | 89 WebNotificationData notification(title, dir, options.lang(), options.body(),
options.tag(), iconUrl, vibrate, options.silent(), dataAsWireBytes); |
| 90 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v
oid>(resolver); | 90 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v
oid>(resolver); |
| 91 | 91 |
| 92 SecurityOrigin* origin = executionContext->securityOrigin(); | 92 SecurityOrigin* origin = executionContext->securityOrigin(); |
| 93 ASSERT(origin); | 93 ASSERT(origin); |
| 94 | 94 |
| 95 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); | 95 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); |
| 96 ASSERT(notificationManager); | 96 ASSERT(notificationManager); |
| 97 | 97 |
| 98 notificationManager->showPersistent(*origin, notification, serviceWorkerRegi
stration.webRegistration(), callbacks); | 98 notificationManager->showPersistent(*origin, notification, serviceWorkerRegi
stration.webRegistration(), callbacks); |
| 99 return promise; | 99 return promise; |
| 100 } | 100 } |
| 101 | 101 |
| 102 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta
te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get
NotificationOptions& options) | 102 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta
te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get
NotificationOptions& options) |
| 103 { | 103 { |
| 104 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 104 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 105 ScriptPromise promise = resolver->promise(); | 105 ScriptPromise promise = resolver->promise(); |
| 106 | 106 |
| 107 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica
tionArray, void>(resolver); | 107 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica
tionArray, void>(resolver); |
| 108 | 108 |
| 109 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); | 109 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); |
| 110 ASSERT(notificationManager); | 110 ASSERT(notificationManager); |
| 111 | 111 |
| 112 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati
on.webRegistration(), callbacks); | 112 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati
on.webRegistration(), callbacks); |
| 113 return promise; | 113 return promise; |
| 114 } | 114 } |
| 115 | 115 |
| 116 } // namespace blink | 116 } // namespace blink |
| OLD | NEW |