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

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

Issue 787893002: Actually hook up ServiceWorkerRegistration.showNotification() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: add missing file Created 6 years 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 | Annotate | Revision Log
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 "config.h" 5 #include "config.h"
6 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h" 6 #include "modules/notifications/ServiceWorkerRegistrationNotifications.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/V8ThrowException.h"
8 #include "core/dom/DOMException.h" 11 #include "core/dom/DOMException.h"
9 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
10 #include "core/dom/ExecutionContext.h" 13 #include "core/dom/ExecutionContext.h"
14 #include "modules/notifications/Notification.h"
11 #include "modules/notifications/NotificationOptions.h" 15 #include "modules/notifications/NotificationOptions.h"
12 #include "platform/weborigin/KURL.h" 16 #include "platform/weborigin/KURL.h"
17 #include "public/platform/Platform.h"
13 #include "public/platform/WebNotificationData.h" 18 #include "public/platform/WebNotificationData.h"
19 #include "public/platform/WebNotificationManager.h"
20 #include "public/platform/WebSerializedOrigin.h"
14 21
15 namespace blink { 22 namespace blink {
16 23
17 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str ing& title, const NotificationOptions& options) 24 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str ing& title, const NotificationOptions& options)
Michael van Ouwerkerk 2014/12/09 19:38:04 Why can't ServiceWorkerRegistration& be const?
Peter Beverloo 2014/12/10 13:24:36 Neither .active() nor .webRegistration() are defin
18 { 25 {
26 ExecutionContext* executionContext = scriptState->executionContext();
27
28 // If context object's active worker is null, reject promise with a TypeErro r exception.
29 if (!serviceWorkerRegistration.active())
30 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration."));
31
32 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps.
33 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed)
34 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin."));
35
36 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
Michael van Ouwerkerk 2014/12/09 19:38:04 Might want to keep an eye on this patch and resolv
Peter Beverloo 2014/12/10 13:24:36 Will do, thanks for the pointer!
37 ScriptPromise promise = resolver->promise();
38
39 // FIXME: Do the appropriate CORS checks on the icon URL.
40 // FIXME: Determine the text direction based on the options dictionary.
41
19 KURL iconUrl; 42 KURL iconUrl;
20 if (options.hasIcon() && !options.icon().isEmpty()) { 43 if (options.hasIcon() && !options.icon().isEmpty()) {
21 iconUrl = scriptState->executionContext()->completeURL(options.icon()); 44 iconUrl = executionContext->completeURL(options.icon());
22 if (!iconUrl.isValid()) 45 if (!iconUrl.isValid())
23 iconUrl = KURL(); 46 iconUrl = KURL();
24 } 47 }
25 48
26 WebNotificationData notification(title, WebNotificationData::DirectionLeftTo Right, options.lang(), options.body(), options.tag(), iconUrl); 49 WebNotificationData notification(title, WebNotificationData::DirectionLeftTo Right, options.lang(), options.body(), options.tag(), iconUrl);
50 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver);
27 51
28 // FIXME: Hook this up with the Blink API once it's been implemented. 52 SecurityOrigin* origin = executionContext->securityOrigin();
Michael van Ouwerkerk 2014/12/09 19:38:04 It would seem you don't need to pass the origin al
Peter Beverloo 2014/12/10 13:24:36 Acknowledged. I'll opt for more three-sided clean-
29 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError, "showNotification is not implemented yet.")); 53 ASSERT(origin);
54
55 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
56 ASSERT(notificationManager);
57
58 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks);
59 return promise;
30 } 60 }
31 61
32 } // namespace blink 62 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698