| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 52 |
| 53 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta
te* scriptState, ServiceWorkerRegistration& registration, const String& title, c
onst NotificationOptions& options, ExceptionState& exceptionState) | 53 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta
te* scriptState, ServiceWorkerRegistration& registration, const String& title, c
onst NotificationOptions& options, ExceptionState& exceptionState) |
| 54 { | 54 { |
| 55 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 55 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 56 | 56 |
| 57 // If context object's active worker is null, reject promise with a TypeErro
r exception. | 57 // If context object's active worker is null, reject promise with a TypeErro
r exception. |
| 58 if (!registration.active()) | 58 if (!registration.active()) |
| 59 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "No active registration available on the ServiceWork
erRegistration.")); | 59 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "No active registration available on the ServiceWork
erRegistration.")); |
| 60 | 60 |
| 61 // If permission for notification's origin is not "granted", reject promise
with a TypeError exception, and terminate these substeps. | 61 // If permission for notification's origin is not "granted", reject promise
with a TypeError exception, and terminate these substeps. |
| 62 if (Notification::checkPermission(executionContext) != mojom::PermissionStat
us::GRANTED) | 62 if (Notification::checkPermission(executionContext) != permissions::mojom::P
ermissionStatus::GRANTED) |
| 63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "No notification permission has been granted for thi
s origin.")); | 63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr
ror(scriptState->isolate(), "No notification permission has been granted for thi
s origin.")); |
| 64 | 64 |
| 65 // Validate the developer-provided values to get a WebNotificationData objec
t. | 65 // Validate the developer-provided values to get a WebNotificationData objec
t. |
| 66 WebNotificationData data = createWebNotificationData(executionContext, title
, options, exceptionState); | 66 WebNotificationData data = createWebNotificationData(executionContext, title
, options, exceptionState); |
| 67 if (exceptionState.hadException()) | 67 if (exceptionState.hadException()) |
| 68 return exceptionState.reject(scriptState); | 68 return exceptionState.reject(scriptState); |
| 69 | 69 |
| 70 // Log number of actions developer provided in linear histogram: 0 -> underf
low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket. | 70 // Log number of actions developer provided in linear histogram: 0 -> underf
low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket. |
| 71 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, notificationCountHisto
gram, new EnumerationHistogram("Notifications.PersistentNotificationActionCount"
, 17)); | 71 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, notificationCountHisto
gram, new EnumerationHistogram("Notifications.PersistentNotificationActionCount"
, 17)); |
| 72 notificationCountHistogram.count(options.actions().size()); | 72 notificationCountHistogram.count(options.actions().size()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 DCHECK(m_loaders.contains(loader)); | 136 DCHECK(m_loaders.contains(loader)); |
| 137 | 137 |
| 138 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); | 138 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); |
| 139 DCHECK(notificationManager); | 139 DCHECK(notificationManager); |
| 140 | 140 |
| 141 notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, l
oader->getResources(), m_registration->webRegistration(), callbacks.leakPtr()); | 141 notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, l
oader->getResources(), m_registration->webRegistration(), callbacks.leakPtr()); |
| 142 m_loaders.remove(loader); | 142 m_loaders.remove(loader); |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace blink | 145 } // namespace blink |
| OLD | NEW |