Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: third_party/WebKit/Source/modules/notifications/ServiceWorkerRegistrationNotifications.cpp

Issue 1948223004: Introduce the Blink NotificationService, move permission checks there (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "modules/notifications/GetNotificationOptions.h" 11 #include "modules/notifications/GetNotificationOptions.h"
12 #include "modules/notifications/Notification.h" 12 #include "modules/notifications/Notification.h"
13 #include "modules/notifications/NotificationData.h" 13 #include "modules/notifications/NotificationData.h"
14 #include "modules/notifications/NotificationManager.h"
14 #include "modules/notifications/NotificationOptions.h" 15 #include "modules/notifications/NotificationOptions.h"
15 #include "modules/notifications/NotificationResourcesLoader.h" 16 #include "modules/notifications/NotificationResourcesLoader.h"
16 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 17 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
17 #include "platform/Histogram.h" 18 #include "platform/Histogram.h"
18 #include "platform/heap/Handle.h" 19 #include "platform/heap/Handle.h"
19 #include "public/platform/Platform.h" 20 #include "public/platform/Platform.h"
20 #include "public/platform/WebSecurityOrigin.h" 21 #include "public/platform/WebSecurityOrigin.h"
21 #include "public/platform/modules/notifications/WebNotificationData.h" 22 #include "public/platform/modules/notifications/WebNotificationData.h"
22 #include "wtf/RefPtr.h" 23 #include "wtf/RefPtr.h"
23 24
(...skipping 28 matching lines...) Expand all
52 53
53 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& registration, const String& title, c onst NotificationOptions& options, ExceptionState& exceptionState) 54 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& registration, const String& title, c onst NotificationOptions& options, ExceptionState& exceptionState)
54 { 55 {
55 ExecutionContext* executionContext = scriptState->getExecutionContext(); 56 ExecutionContext* executionContext = scriptState->getExecutionContext();
56 57
57 // If context object's active worker is null, reject promise with a TypeErro r exception. 58 // If context object's active worker is null, reject promise with a TypeErro r exception.
58 if (!registration.active()) 59 if (!registration.active())
59 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); 60 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration."));
60 61
61 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. 62 // 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::blink::Permiss ionStatus::GRANTED) 63 if (NotificationManager::from(executionContext)->permissionStatus() != mojom ::blink::PermissionStatus::GRANTED)
63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); 64 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin."));
64 65
65 // Validate the developer-provided values to get a WebNotificationData objec t. 66 // Validate the developer-provided values to get a WebNotificationData objec t.
66 WebNotificationData data = createWebNotificationData(executionContext, title , options, exceptionState); 67 WebNotificationData data = createWebNotificationData(executionContext, title , options, exceptionState);
67 if (exceptionState.hadException()) 68 if (exceptionState.hadException())
68 return exceptionState.reject(scriptState); 69 return exceptionState.reject(scriptState);
69 70
70 // Log number of actions developer provided in linear histogram: 0 -> underf low bucket, 1-16 -> distinct buckets, 17+ -> overflow bucket. 71 // 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)); 72 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, notificationCountHisto gram, new EnumerationHistogram("Notifications.PersistentNotificationActionCount" , 17));
72 notificationCountHistogram.count(options.actions().size()); 73 notificationCountHistogram.count(options.actions().size());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 DCHECK(m_loaders.contains(loader)); 137 DCHECK(m_loaders.contains(loader));
137 138
138 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 139 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
139 DCHECK(notificationManager); 140 DCHECK(notificationManager);
140 141
141 notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, l oader->getResources(), m_registration->webRegistration(), callbacks.leakPtr()); 142 notificationManager->showPersistent(WebSecurityOrigin(origin.get()), data, l oader->getResources(), m_registration->webRegistration(), callbacks.leakPtr());
142 m_loaders.remove(loader); 143 m_loaders.remove(loader);
143 } 144 }
144 145
145 } // namespace blink 146 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698