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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 | 53 |
54 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. | 54 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. |
55 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed) | 55 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed) |
56 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); | 56 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); |
57 | 57 |
58 // Validate the developer-provided values to get a WebNotificationData objec t. | 58 // Validate the developer-provided values to get a WebNotificationData objec t. |
59 WebNotificationData data = createWebNotificationData(executionContext, title , options, exceptionState); | 59 WebNotificationData data = createWebNotificationData(executionContext, title , options, exceptionState); |
60 if (exceptionState.hadException()) | 60 if (exceptionState.hadException()) |
61 return exceptionState.reject(scriptState); | 61 return exceptionState.reject(scriptState); |
62 | 62 |
63 // Log number of actions developer provided, even if it's more than we curre ntly support. | |
Alexei Svitkine (slow)
2015/11/23 16:19:19
Nit: Expand comment to mention you're intentionall
johnme
2015/11/24 11:24:12
Done.
| |
64 Platform::current()->histogramEnumeration("Notifications.PersistentNotificat ionActionCount", options.actions().size(), 17); | |
65 | |
63 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 66 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
64 ScriptPromise promise = resolver->promise(); | 67 ScriptPromise promise = resolver->promise(); |
65 | 68 |
66 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); | 69 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); |
67 | 70 |
68 SecurityOrigin* origin = executionContext->securityOrigin(); | 71 SecurityOrigin* origin = executionContext->securityOrigin(); |
69 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); | 72 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); |
70 ASSERT(notificationManager); | 73 ASSERT(notificationManager); |
71 | 74 |
72 notificationManager->showPersistent(WebSecurityOrigin(origin), data, service WorkerRegistration.webRegistration(), callbacks); | 75 notificationManager->showPersistent(WebSecurityOrigin(origin), data, service WorkerRegistration.webRegistration(), callbacks); |
73 return promise; | 76 return promise; |
74 } | 77 } |
75 | 78 |
76 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) | 79 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) |
77 { | 80 { |
78 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 81 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
79 ScriptPromise promise = resolver->promise(); | 82 ScriptPromise promise = resolver->promise(); |
80 | 83 |
81 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); | 84 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); |
82 | 85 |
83 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); | 86 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); |
84 ASSERT(notificationManager); | 87 ASSERT(notificationManager); |
85 | 88 |
86 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); | 89 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); |
87 return promise; | 90 return promise; |
88 } | 91 } |
89 | 92 |
90 } // namespace blink | 93 } // namespace blink |
OLD | NEW |