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/ScriptValue.h" | |
11 #include "bindings/core/v8/SerializedScriptValue.h" | |
12 #include "bindings/core/v8/SerializedScriptValueFactory.h" | |
10 #include "bindings/core/v8/V8ThrowException.h" | 13 #include "bindings/core/v8/V8ThrowException.h" |
11 #include "core/dom/DOMException.h" | 14 #include "core/dom/DOMException.h" |
12 #include "core/dom/ExceptionCode.h" | 15 #include "core/dom/ExceptionCode.h" |
13 #include "core/dom/ExecutionContext.h" | 16 #include "core/dom/ExecutionContext.h" |
14 #include "modules/notifications/Notification.h" | 17 #include "modules/notifications/Notification.h" |
15 #include "modules/notifications/NotificationOptions.h" | 18 #include "modules/notifications/NotificationOptions.h" |
16 #include "platform/weborigin/KURL.h" | 19 #include "platform/weborigin/KURL.h" |
17 #include "public/platform/Platform.h" | 20 #include "public/platform/Platform.h" |
18 #include "public/platform/WebSerializedOrigin.h" | 21 #include "public/platform/WebSerializedOrigin.h" |
19 #include "public/platform/modules/notifications/WebNotificationData.h" | 22 #include "public/platform/modules/notifications/WebNotificationData.h" |
20 #include "public/platform/modules/notifications/WebNotificationManager.h" | 23 #include "public/platform/modules/notifications/WebNotificationManager.h" |
21 | 24 |
22 namespace blink { | 25 namespace blink { |
23 | 26 |
24 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str ing& title, const NotificationOptions& options) | 27 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str ing& title, const NotificationOptions& options, ExceptionState& exceptionState) |
25 { | 28 { |
26 ExecutionContext* executionContext = scriptState->executionContext(); | 29 ExecutionContext* executionContext = scriptState->executionContext(); |
27 | 30 |
28 // If context object's active worker is null, reject promise with a TypeErro r exception. | 31 // If context object's active worker is null, reject promise with a TypeErro r exception. |
29 if (!serviceWorkerRegistration.active()) | 32 if (!serviceWorkerRegistration.active()) |
30 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); | 33 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); |
31 | 34 |
32 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. | 35 // 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) | 36 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.")); | 37 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); |
35 | 38 |
36 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 39 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
37 ScriptPromise promise = resolver->promise(); | 40 ScriptPromise promise = resolver->promise(); |
38 | 41 |
39 // FIXME: Do the appropriate CORS checks on the icon URL. | 42 // FIXME: Do the appropriate CORS checks on the icon URL. |
40 | 43 |
41 KURL iconUrl; | 44 KURL iconUrl; |
42 if (options.hasIcon() && !options.icon().isEmpty()) { | 45 if (options.hasIcon() && !options.icon().isEmpty()) { |
43 iconUrl = executionContext->completeURL(options.icon()); | 46 iconUrl = executionContext->completeURL(options.icon()); |
44 if (!iconUrl.isValid()) | 47 if (!iconUrl.isValid()) |
45 iconUrl = KURL(); | 48 iconUrl = KURL(); |
46 } | 49 } |
47 | 50 |
48 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 51 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()); | 52 |
Peter Beverloo
2015/03/10 23:34:27
Mmm this duplication is not great. It happens in m
Sanghyun Park
2015/03/11 10:59:52
I cannot understand your comment properly.
Is you
| |
53 RefPtr<SerializedScriptValue> data; | |
54 if (options.hasData()) { | |
55 data = SerializedScriptValueFactory::instance().create(options.data(), 0 , exceptionState, options.data().isolate()); | |
Peter Beverloo
2015/03/10 23:34:27
nit: dito as in Notification.cpp, if exceptionStat
Sanghyun Park
2015/03/11 10:59:52
I'll fix this.
| |
56 data->registerMemoryAllocatedWithCurrentScriptContext(); | |
Peter Beverloo
2015/03/10 23:34:27
nit: dito as in Notification.cpp, we shouldn't hav
Sanghyun Park
2015/03/11 10:59:52
Ditto
| |
57 } | |
58 | |
59 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, options.silent(), data.release()); | |
Peter Beverloo
2015/03/10 23:34:27
note: data.release() is fine here, because we won'
| |
50 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); | 60 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); |
51 | 61 |
52 SecurityOrigin* origin = executionContext->securityOrigin(); | 62 SecurityOrigin* origin = executionContext->securityOrigin(); |
53 ASSERT(origin); | 63 ASSERT(origin); |
54 | 64 |
55 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); | 65 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); |
56 ASSERT(notificationManager); | 66 ASSERT(notificationManager); |
57 | 67 |
58 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); | 68 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); |
59 return promise; | 69 return promise; |
60 } | 70 } |
61 | 71 |
62 } // namespace blink | 72 } // namespace blink |
OLD | NEW |