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