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 | |
Peter Beverloo
2015/04/01 14:26:29
nit: no blank line
Sanghyun Park
2015/04/01 17:46:08
Done.
| |
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 9 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
9 #include "bindings/core/v8/ExceptionState.h" | 10 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 11 #include "bindings/core/v8/ScriptPromiseResolver.h" |
11 #include "bindings/core/v8/SerializedScriptValue.h" | 12 #include "bindings/core/v8/SerializedScriptValue.h" |
12 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 13 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
13 #include "bindings/core/v8/V8ThrowException.h" | 14 #include "bindings/core/v8/V8ThrowException.h" |
14 #include "core/dom/DOMException.h" | 15 #include "core/dom/DOMException.h" |
15 #include "core/dom/ExceptionCode.h" | 16 #include "core/dom/ExceptionCode.h" |
16 #include "core/dom/ExecutionContext.h" | 17 #include "core/dom/ExecutionContext.h" |
17 #include "modules/notifications/GetNotificationOptions.h" | 18 #include "modules/notifications/GetNotificationOptions.h" |
18 #include "modules/notifications/Notification.h" | 19 #include "modules/notifications/Notification.h" |
19 #include "modules/notifications/NotificationOptions.h" | 20 #include "modules/notifications/NotificationOptions.h" |
21 #include "modules/vibration/NavigatorVibration.h" | |
20 #include "platform/weborigin/KURL.h" | 22 #include "platform/weborigin/KURL.h" |
21 #include "public/platform/Platform.h" | 23 #include "public/platform/Platform.h" |
22 #include "public/platform/WebSerializedOrigin.h" | 24 #include "public/platform/WebSerializedOrigin.h" |
23 #include "public/platform/modules/notifications/WebNotificationData.h" | 25 #include "public/platform/modules/notifications/WebNotificationData.h" |
24 #include "public/platform/modules/notifications/WebNotificationManager.h" | 26 #include "public/platform/modules/notifications/WebNotificationManager.h" |
25 | 27 |
26 namespace blink { | 28 namespace blink { |
27 namespace { | 29 namespace { |
28 | 30 |
29 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the | 31 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the |
(...skipping 30 matching lines...) Expand all Loading... | |
60 | 62 |
61 // If context object's active worker is null, reject promise with a TypeErro r exception. | 63 // If context object's active worker is null, reject promise with a TypeErro r exception. |
62 if (!serviceWorkerRegistration.active()) | 64 if (!serviceWorkerRegistration.active()) |
63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); | 65 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); |
64 | 66 |
65 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. | 67 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. |
66 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed) | 68 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed) |
67 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); | 69 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); |
68 | 70 |
69 // FIXME: Unify the code path here with the Notification.create() function. | 71 // FIXME: Unify the code path here with the Notification.create() function. |
72 NavigatorVibration::VibrationPattern vibrate; | |
Peter Beverloo
2015/04/01 14:26:29
Perhaps it makes sense to look into unifying the m
Sanghyun Park
2015/04/01 17:46:08
I'll also your opinion.
But, if we'll support vibr
| |
73 if (options.hasVibrate()) { | |
74 if (options.silent()) | |
75 return ScriptPromise::reject(scriptState, V8ThrowException::createTy peError(scriptState->isolate(), "If options's silent is true, options's vibrate should not be presented.")); | |
76 | |
77 NavigatorVibration::VibrationPattern pattern; | |
78 if (options.vibrate().isUnsignedLong()) | |
79 pattern.append(options.vibrate().getAsUnsignedLong()); | |
80 else | |
81 pattern = options.vibrate().getAsUnsignedLongSequence(); | |
82 vibrate = NavigatorVibration::verifyVibrationPattern(pattern); | |
83 } | |
84 | |
70 String dataAsWireString; | 85 String dataAsWireString; |
71 if (options.hasData()) { | 86 if (options.hasData()) { |
72 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta nce().create(options.data(), nullptr, exceptionState, options.data().isolate()); | 87 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta nce().create(options.data(), nullptr, exceptionState, options.data().isolate()); |
73 if (exceptionState.hadException()) | 88 if (exceptionState.hadException()) |
74 return exceptionState.reject(scriptState); | 89 return exceptionState.reject(scriptState); |
75 dataAsWireString = data->toWireString(); | 90 dataAsWireString = data->toWireString(); |
76 } | 91 } |
77 | 92 |
78 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 93 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
79 ScriptPromise promise = resolver->promise(); | 94 ScriptPromise promise = resolver->promise(); |
80 | 95 |
81 // FIXME: Do the appropriate CORS checks on the icon URL. | 96 // FIXME: Do the appropriate CORS checks on the icon URL. |
82 | 97 |
83 KURL iconUrl; | 98 KURL iconUrl; |
84 if (options.hasIcon() && !options.icon().isEmpty()) { | 99 if (options.hasIcon() && !options.icon().isEmpty()) { |
85 iconUrl = executionContext->completeURL(options.icon()); | 100 iconUrl = executionContext->completeURL(options.icon()); |
86 if (!iconUrl.isValid()) | 101 if (!iconUrl.isValid()) |
87 iconUrl = KURL(); | 102 iconUrl = KURL(); |
88 } | 103 } |
89 | 104 |
90 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 105 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
91 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, options.silent(), dataAsWireString); | 106 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, vibrate, options.silent(), dataAsWireString); |
92 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); | 107 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); |
93 | 108 |
94 SecurityOrigin* origin = executionContext->securityOrigin(); | 109 SecurityOrigin* origin = executionContext->securityOrigin(); |
95 ASSERT(origin); | 110 ASSERT(origin); |
96 | 111 |
97 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); | 112 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); |
98 ASSERT(notificationManager); | 113 ASSERT(notificationManager); |
99 | 114 |
100 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); | 115 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); |
101 return promise; | 116 return promise; |
102 } | 117 } |
103 | 118 |
104 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) | 119 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) |
105 { | 120 { |
106 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 121 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
107 ScriptPromise promise = resolver->promise(); | 122 ScriptPromise promise = resolver->promise(); |
108 | 123 |
109 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); | 124 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); |
110 | 125 |
111 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); | 126 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); |
112 ASSERT(notificationManager); | 127 ASSERT(notificationManager); |
113 | 128 |
114 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); | 129 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); |
115 return promise; | 130 return promise; |
116 } | 131 } |
117 | 132 |
118 } // namespace blink | 133 } // namespace blink |
OLD | NEW |