| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta
te* scriptState, ServiceWorkerRegistration& registration, const String& title, c
onst NotificationOptions& options, ExceptionState& exceptionState) | 57 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta
te* scriptState, ServiceWorkerRegistration& registration, const String& title, c
onst NotificationOptions& options, ExceptionState& exceptionState) |
| 58 { | 58 { |
| 59 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 59 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 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 (!registration.active()) | 62 if (!registration.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) != mojom::PermissionStat
us::GRANTED) | 66 if (Notification::checkPermission(executionContext) != permission::mojom::Pe
rmissionStatus::GRANTED) |
| 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 // Validate the developer-provided values to get a WebNotificationData objec
t. | 69 // Validate the developer-provided values to get a WebNotificationData objec
t. |
| 70 WebNotificationData data = createWebNotificationData(executionContext, title
, options, exceptionState); | 70 WebNotificationData data = createWebNotificationData(executionContext, title
, options, exceptionState); |
| 71 if (exceptionState.hadException()) | 71 if (exceptionState.hadException()) |
| 72 return exceptionState.reject(scriptState); | 72 return exceptionState.reject(scriptState); |
| 73 | 73 |
| 74 // Log number of actions developer provided in linear histogram: 0 -> underf
low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket. | 74 // Log number of actions developer provided in linear histogram: 0 -> underf
low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket. |
| 75 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, notificationCountHisto
gram, new EnumerationHistogram("Notifications.PersistentNotificationActionCount"
, 17)); | 75 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, notificationCountHisto
gram, new EnumerationHistogram("Notifications.PersistentNotificationActionCount"
, 17)); |
| 76 notificationCountHistogram.count(options.actions().size()); | 76 notificationCountHistogram.count(options.actions().size()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 DCHECK(m_loaders.contains(loader)); | 140 DCHECK(m_loaders.contains(loader)); |
| 141 | 141 |
| 142 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); | 142 WebNotificationManager* notificationManager = Platform::current()->notificat
ionManager(); |
| 143 DCHECK(notificationManager); | 143 DCHECK(notificationManager); |
| 144 | 144 |
| 145 notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, l
oader->getResources(), m_registration->webRegistration(), callbacks.leakPtr()); | 145 notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, l
oader->getResources(), m_registration->webRegistration(), callbacks.leakPtr()); |
| 146 m_loaders.remove(loader); | 146 m_loaders.remove(loader); |
| 147 } | 147 } |
| 148 | 148 |
| 149 } // namespace blink | 149 } // namespace blink |
| OLD | NEW |