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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 ExecutionContext* executionContext = scriptState->executionContext(); | 59 ExecutionContext* executionContext = scriptState->executionContext(); |
60 | 60 |
61 // If context object's active worker is null, reject promise with a TypeErro r exception. | 61 // If context object's active worker is null, reject promise with a TypeErro r exception. |
62 if (!serviceWorkerRegistration.active()) | 62 if (!serviceWorkerRegistration.active()) |
63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); | 63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); |
64 | 64 |
65 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. | 65 // 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) | 66 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.")); | 67 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); |
68 | 68 |
69 if (options.hasVibrate() && options.silent()) | |
70 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Slient notification must not specify vibration patt erns")); | |
Peter Beverloo
2015/04/09 13:03:17
nit: Sentences end with a period.
Sanghyun Park
2015/04/09 13:48:05
Done.
| |
71 | |
69 // FIXME: Unify the code path here with the Notification.create() function. | 72 // FIXME: Unify the code path here with the Notification.create() function. |
70 Vector<char> dataAsWireBytes; | 73 Vector<char> dataAsWireBytes; |
71 if (options.hasData()) { | 74 if (options.hasData()) { |
72 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta nce().create(options.data(), nullptr, exceptionState, options.data().isolate()); | 75 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta nce().create(options.data(), nullptr, exceptionState, options.data().isolate()); |
73 if (exceptionState.hadException()) | 76 if (exceptionState.hadException()) |
74 return exceptionState.reject(scriptState); | 77 return exceptionState.reject(scriptState); |
75 | 78 |
76 data->toWireBytes(dataAsWireBytes); | 79 data->toWireBytes(dataAsWireBytes); |
77 } | 80 } |
78 | 81 |
79 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 82 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
80 ScriptPromise promise = resolver->promise(); | 83 ScriptPromise promise = resolver->promise(); |
81 | 84 |
82 // FIXME: Do the appropriate CORS checks on the icon URL. | 85 // FIXME: Do the appropriate CORS checks on the icon URL. |
83 | 86 |
84 KURL iconUrl; | 87 KURL iconUrl; |
85 if (options.hasIcon() && !options.icon().isEmpty()) { | 88 if (options.hasIcon() && !options.icon().isEmpty()) { |
86 iconUrl = executionContext->completeURL(options.icon()); | 89 iconUrl = executionContext->completeURL(options.icon()); |
87 if (!iconUrl.isValid()) | 90 if (!iconUrl.isValid()) |
88 iconUrl = KURL(); | 91 iconUrl = KURL(); |
89 } | 92 } |
90 | 93 |
91 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; | 94 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; |
92 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, options.silent(), dataAsWireBytes); | 95 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, Notification::sanitizeVibrationPattern(options.vibrate( )), options.silent(), dataAsWireBytes); |
93 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); | 96 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); |
94 | 97 |
95 SecurityOrigin* origin = executionContext->securityOrigin(); | 98 SecurityOrigin* origin = executionContext->securityOrigin(); |
96 ASSERT(origin); | 99 ASSERT(origin); |
97 | 100 |
98 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); | 101 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); |
99 ASSERT(notificationManager); | 102 ASSERT(notificationManager); |
100 | 103 |
101 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); | 104 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); |
102 return promise; | 105 return promise; |
103 } | 106 } |
104 | 107 |
105 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) | 108 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) |
106 { | 109 { |
107 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | 110 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); |
108 ScriptPromise promise = resolver->promise(); | 111 ScriptPromise promise = resolver->promise(); |
109 | 112 |
110 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); | 113 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); |
111 | 114 |
112 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); | 115 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); |
113 ASSERT(notificationManager); | 116 ASSERT(notificationManager); |
114 | 117 |
115 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); | 118 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); |
116 return promise; | 119 return promise; |
117 } | 120 } |
118 | 121 |
119 } // namespace blink | 122 } // namespace blink |
OLD | NEW |