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

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

Issue 1995663003: Revert of 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"
15 #include "modules/notifications/NotificationOptions.h" 14 #include "modules/notifications/NotificationOptions.h"
16 #include "modules/notifications/NotificationResourcesLoader.h" 15 #include "modules/notifications/NotificationResourcesLoader.h"
17 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 16 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
18 #include "platform/Histogram.h" 17 #include "platform/Histogram.h"
19 #include "platform/heap/Handle.h" 18 #include "platform/heap/Handle.h"
20 #include "public/platform/Platform.h" 19 #include "public/platform/Platform.h"
21 #include "public/platform/WebSecurityOrigin.h" 20 #include "public/platform/WebSecurityOrigin.h"
22 #include "public/platform/modules/notifications/WebNotificationData.h" 21 #include "public/platform/modules/notifications/WebNotificationData.h"
23 #include "wtf/RefPtr.h" 22 #include "wtf/RefPtr.h"
24 23
(...skipping 28 matching lines...) Expand all
53 52
54 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)
55 { 54 {
56 ExecutionContext* executionContext = scriptState->getExecutionContext(); 55 ExecutionContext* executionContext = scriptState->getExecutionContext();
57 56
58 // 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.
59 if (!registration.active()) 58 if (!registration.active())
60 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."));
61 60
62 // 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.
63 if (NotificationManager::from(executionContext)->permissionStatus() != mojom ::blink::PermissionStatus::GRANTED) 62 if (Notification::checkPermission(executionContext) != mojom::blink::Permiss ionStatus::GRANTED)
64 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."));
65 64
66 // Validate the developer-provided values to get a WebNotificationData objec t. 65 // Validate the developer-provided values to get a WebNotificationData objec t.
67 WebNotificationData data = createWebNotificationData(executionContext, title , options, exceptionState); 66 WebNotificationData data = createWebNotificationData(executionContext, title , options, exceptionState);
68 if (exceptionState.hadException()) 67 if (exceptionState.hadException())
69 return exceptionState.reject(scriptState); 68 return exceptionState.reject(scriptState);
70 69
71 // 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.
72 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));
73 notificationCountHistogram.count(options.actions().size()); 72 notificationCountHistogram.count(options.actions().size());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 DCHECK(m_loaders.contains(loader)); 136 DCHECK(m_loaders.contains(loader));
138 137
139 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 138 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
140 DCHECK(notificationManager); 139 DCHECK(notificationManager);
141 140
142 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());
143 m_loaders.remove(loader); 142 m_loaders.remove(loader);
144 } 143 }
145 144
146 } // namespace blink 145 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/notifications/NotificationManager.cpp ('k') | third_party/WebKit/public/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698