Chromium Code Reviews| 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/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "bindings/core/v8/ScriptValue.h" | |
| 12 #include "bindings/core/v8/SerializedScriptValue.h" | |
| 13 #include "bindings/core/v8/SerializedScriptValueFactory.h" | |
| 10 #include "bindings/core/v8/V8ThrowException.h" | 14 #include "bindings/core/v8/V8ThrowException.h" |
| 11 #include "core/dom/DOMException.h" | 15 #include "core/dom/DOMException.h" |
| 12 #include "core/dom/ExceptionCode.h" | 16 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/dom/ExecutionContext.h" | 17 #include "core/dom/ExecutionContext.h" |
| 14 #include "modules/notifications/Notification.h" | 18 #include "modules/notifications/Notification.h" |
| 15 #include "modules/notifications/NotificationOptions.h" | 19 #include "modules/notifications/NotificationOptions.h" |
| 16 #include "platform/weborigin/KURL.h" | 20 #include "platform/weborigin/KURL.h" |
| 17 #include "public/platform/Platform.h" | 21 #include "public/platform/Platform.h" |
| 18 #include "public/platform/WebSerializedOrigin.h" | 22 #include "public/platform/WebSerializedOrigin.h" |
| 19 #include "public/platform/modules/notifications/WebNotificationData.h" | 23 #include "public/platform/modules/notifications/WebNotificationData.h" |
| 20 #include "public/platform/modules/notifications/WebNotificationManager.h" | 24 #include "public/platform/modules/notifications/WebNotificationManager.h" |
| 21 | 25 |
| 22 namespace blink { | 26 namespace blink { |
| 23 | 27 |
| 24 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str ing& title, const NotificationOptions& options) | 28 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str ing& title, const NotificationOptions& options, ExceptionState& exceptionState) |
| 25 { | 29 { |
| 26 ExecutionContext* executionContext = scriptState->executionContext(); | 30 ExecutionContext* executionContext = scriptState->executionContext(); |
| 27 | 31 |
| 28 // If context object's active worker is null, reject promise with a TypeErro r exception. | 32 // If context object's active worker is null, reject promise with a TypeErro r exception. |
| 29 if (!serviceWorkerRegistration.active()) | 33 if (!serviceWorkerRegistration.active()) |
| 30 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); | 34 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); |
| 31 | 35 |
| 32 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. | 36 // 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) | 37 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.")); | 38 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); |
| 35 | 39 |
| 36 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 40 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
| 37 ScriptPromise promise = resolver->promise(); | 41 ScriptPromise promise = resolver->promise(); |
| 38 | 42 |
| 43 // FIXME: Unifying these code paths at some point in the future | |
|
Peter Beverloo
2015/03/12 01:16:26
micro nit: Unifying -> Unify. It would also be goo
Sanghyun Park
2015/03/12 02:58:47
I'll fix this.
| |
| 44 RefPtr<SerializedScriptValue> data; | |
| 45 if (options.hasData()) { | |
| 46 data = SerializedScriptValueFactory::instance().create(options.data(), 0 , exceptionState, options.data().isolate()); | |
| 47 if (exceptionState.hadException()) | |
| 48 return ScriptPromise::reject(scriptState, V8ThrowException::createTy peError(scriptState->isolate(), "No data property can be serialized")); | |
|
Peter Beverloo
2015/03/12 01:16:26
Per the specification:
"4. Set notification's
Peter Beverloo
2015/03/12 02:28:50
Scrap the above :-).
Right now you're throwing a
Sanghyun Park
2015/03/12 02:58:47
I see.
Thank you so much for finding solution.
I'l
| |
| 49 } | |
| 50 | |
| 39 // FIXME: Do the appropriate CORS checks on the icon URL. | 51 // FIXME: Do the appropriate CORS checks on the icon URL. |
| 40 | 52 |
| 41 KURL iconUrl; | 53 KURL iconUrl; |
| 42 if (options.hasIcon() && !options.icon().isEmpty()) { | 54 if (options.hasIcon() && !options.icon().isEmpty()) { |
| 43 iconUrl = executionContext->completeURL(options.icon()); | 55 iconUrl = executionContext->completeURL(options.icon()); |
| 44 if (!iconUrl.isValid()) | 56 if (!iconUrl.isValid()) |
| 45 iconUrl = KURL(); | 57 iconUrl = KURL(); |
| 46 } | 58 } |
| 47 | 59 |
| 48 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 60 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
| 49 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, options.silent()); | 61 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, options.silent(), data.release()); |
| 50 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); | 62 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); |
| 51 | 63 |
| 52 SecurityOrigin* origin = executionContext->securityOrigin(); | 64 SecurityOrigin* origin = executionContext->securityOrigin(); |
| 53 ASSERT(origin); | 65 ASSERT(origin); |
| 54 | 66 |
| 55 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); | 67 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); |
| 56 ASSERT(notificationManager); | 68 ASSERT(notificationManager); |
| 57 | 69 |
| 58 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); | 70 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); |
| 59 return promise; | 71 return promise; |
| 60 } | 72 } |
| 61 | 73 |
| 62 } // namespace blink | 74 } // namespace blink |
| OLD | NEW |