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 "modules/notifications/ServiceWorkerRegistrationNotifications.h" | 5 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h" |
6 | 6 |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 m_registration(registration) {} | 60 m_registration(registration) {} |
61 | 61 |
62 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification( | 62 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification( |
63 ScriptState* scriptState, | 63 ScriptState* scriptState, |
64 ServiceWorkerRegistration& registration, | 64 ServiceWorkerRegistration& registration, |
65 const String& title, | 65 const String& title, |
66 const NotificationOptions& options, | 66 const NotificationOptions& options, |
67 ExceptionState& exceptionState) { | 67 ExceptionState& exceptionState) { |
68 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 68 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
69 | 69 |
70 // If context object's active worker is null, reject promise with a TypeError
exception. | 70 // If context object's active worker is null, reject the promise with a |
| 71 // TypeError exception. |
71 if (!registration.active()) | 72 if (!registration.active()) |
72 return ScriptPromise::reject( | 73 return ScriptPromise::reject( |
73 scriptState, | 74 scriptState, |
74 V8ThrowException::createTypeError(scriptState->isolate(), | 75 V8ThrowException::createTypeError(scriptState->isolate(), |
75 "No active registration available on " | 76 "No active registration available on " |
76 "the ServiceWorkerRegistration.")); | 77 "the ServiceWorkerRegistration.")); |
77 | 78 |
78 // If permission for notification's origin is not "granted", reject promise wi
th a TypeError exception, and terminate these substeps. | 79 // If permission for notification's origin is not "granted", reject the |
| 80 // promise with a TypeError exception, and terminate these substeps. |
79 if (NotificationManager::from(executionContext)->permissionStatus() != | 81 if (NotificationManager::from(executionContext)->permissionStatus() != |
80 mojom::blink::PermissionStatus::GRANTED) | 82 mojom::blink::PermissionStatus::GRANTED) |
81 return ScriptPromise::reject( | 83 return ScriptPromise::reject( |
82 scriptState, | 84 scriptState, |
83 V8ThrowException::createTypeError( | 85 V8ThrowException::createTypeError( |
84 scriptState->isolate(), | 86 scriptState->isolate(), |
85 "No notification permission has been granted for this origin.")); | 87 "No notification permission has been granted for this origin.")); |
86 | 88 |
87 // Validate the developer-provided values to get a WebNotificationData object. | 89 // Validate the developer-provided options to get the WebNotificationData. |
88 WebNotificationData data = createWebNotificationData(executionContext, title, | 90 WebNotificationData data = createWebNotificationData(executionContext, title, |
89 options, exceptionState); | 91 options, exceptionState); |
90 if (exceptionState.hadException()) | 92 if (exceptionState.hadException()) |
91 return exceptionState.reject(scriptState); | 93 return exceptionState.reject(scriptState); |
92 | 94 |
93 // Log number of actions developer provided in linear histogram: 0 -> underflo
w bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket. | 95 // Log number of actions developer provided in linear histogram: |
| 96 // 0 -> underflow bucket, |
| 97 // 1-16 -> distinct buckets, |
| 98 // 17+ -> overflow bucket. |
94 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 99 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
95 EnumerationHistogram, notificationCountHistogram, | 100 EnumerationHistogram, notificationCountHistogram, |
96 new EnumerationHistogram( | 101 new EnumerationHistogram( |
97 "Notifications.PersistentNotificationActionCount", 17)); | 102 "Notifications.PersistentNotificationActionCount", 17)); |
98 notificationCountHistogram.count(options.actions().size()); | 103 notificationCountHistogram.count(options.actions().size()); |
99 | 104 |
100 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 105 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
101 ScriptPromise promise = resolver->promise(); | 106 ScriptPromise promise = resolver->promise(); |
102 | 107 |
103 std::unique_ptr<WebNotificationShowCallbacks> callbacks = | 108 std::unique_ptr<WebNotificationShowCallbacks> callbacks = |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 Platform::current()->notificationManager(); | 187 Platform::current()->notificationManager(); |
183 DCHECK(notificationManager); | 188 DCHECK(notificationManager); |
184 | 189 |
185 notificationManager->showPersistent( | 190 notificationManager->showPersistent( |
186 WebSecurityOrigin(origin.get()), data, loader->getResources(), | 191 WebSecurityOrigin(origin.get()), data, loader->getResources(), |
187 m_registration->webRegistration(), callbacks.release()); | 192 m_registration->webRegistration(), callbacks.release()); |
188 m_loaders.remove(loader); | 193 m_loaders.remove(loader); |
189 } | 194 } |
190 | 195 |
191 } // namespace blink | 196 } // namespace blink |
OLD | NEW |