| 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/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "bindings/core/v8/V8ThrowException.h" | 10 #include "bindings/core/v8/V8ThrowException.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 ExecutionContext* executionContext = scriptState->executionContext(); | 26 ExecutionContext* executionContext = scriptState->executionContext(); |
| 27 | 27 |
| 28 // If context object's active worker is null, reject promise with a TypeErro
r exception. | 28 // If context object's active worker is null, reject promise with a TypeErro
r exception. |
| 29 if (!serviceWorkerRegistration.active()) | 29 if (!serviceWorkerRegistration.active()) |
| 30 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "No active registration available on the ServiceWork
erRegistration.")); | 30 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "No active registration available on the ServiceWork
erRegistration.")); |
| 31 | 31 |
| 32 // If permission for notification's origin is not "granted", reject promise
with a TypeError exception, and terminate these substeps. | 32 // If permission for notification's origin is not "granted", reject promise
with a TypeError exception, and terminate these substeps. |
| 33 if (Notification::checkPermission(executionContext) != WebNotificationPermis
sionAllowed) | 33 if (Notification::checkPermission(executionContext) != WebNotificationPermis
sionAllowed) |
| 34 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "No notification permission has been granted for thi
s origin.")); | 34 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "No notification permission has been granted for thi
s origin.")); |
| 35 | 35 |
| 36 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); | 36 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); |
| 37 ScriptPromise promise = resolver->promise(); | 37 ScriptPromise promise = resolver->promise(); |
| 38 | 38 |
| 39 // FIXME: Do the appropriate CORS checks on the icon URL. | 39 // FIXME: Do the appropriate CORS checks on the icon URL. |
| 40 // FIXME: Determine the text direction based on the options dictionary. | 40 // FIXME: Determine the text direction based on the options dictionary. |
| 41 | 41 |
| 42 KURL iconUrl; | 42 KURL iconUrl; |
| 43 if (options.hasIcon() && !options.icon().isEmpty()) { | 43 if (options.hasIcon() && !options.icon().isEmpty()) { |
| 44 iconUrl = executionContext->completeURL(options.icon()); | 44 iconUrl = executionContext->completeURL(options.icon()); |
| 45 if (!iconUrl.isValid()) | 45 if (!iconUrl.isValid()) |
| 46 iconUrl = KURL(); | 46 iconUrl = KURL(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 WebNotificationData notification(title, WebNotificationData::DirectionLeftTo
Right, options.lang(), options.body(), options.tag(), iconUrl); | 49 WebNotificationData notification(title, WebNotificationData::DirectionLeftTo
Right, options.lang(), options.body(), options.tag(), iconUrl); |
| 50 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v
oid>(resolver); | 50 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v
oid>(resolver); |
| 51 | 51 |
| 52 SecurityOrigin* origin = executionContext->securityOrigin(); | 52 SecurityOrigin* origin = executionContext->securityOrigin(); |
| 53 ASSERT(origin); | 53 ASSERT(origin); |
| 54 | 54 |
| 55 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); | 55 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); |
| 56 ASSERT(notificationManager); | 56 ASSERT(notificationManager); |
| 57 | 57 |
| 58 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati
on, serviceWorkerRegistration.webRegistration(), callbacks); | 58 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati
on, serviceWorkerRegistration.webRegistration(), callbacks); |
| 59 return promise; | 59 return promise; |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |