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

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

Issue 1005353002: Add data property in persistent web notification (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 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 "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" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
11 #include "bindings/core/v8/SerializedScriptValue.h"
12 #include "bindings/core/v8/SerializedScriptValueFactory.h"
10 #include "bindings/core/v8/V8ThrowException.h" 13 #include "bindings/core/v8/V8ThrowException.h"
11 #include "core/dom/DOMException.h" 14 #include "core/dom/DOMException.h"
12 #include "core/dom/ExceptionCode.h" 15 #include "core/dom/ExceptionCode.h"
13 #include "core/dom/ExecutionContext.h" 16 #include "core/dom/ExecutionContext.h"
14 #include "modules/notifications/Notification.h" 17 #include "modules/notifications/Notification.h"
15 #include "modules/notifications/NotificationOptions.h" 18 #include "modules/notifications/NotificationOptions.h"
16 #include "platform/weborigin/KURL.h" 19 #include "platform/weborigin/KURL.h"
17 #include "public/platform/Platform.h" 20 #include "public/platform/Platform.h"
18 #include "public/platform/WebSerializedOrigin.h" 21 #include "public/platform/WebSerializedOrigin.h"
19 #include "public/platform/modules/notifications/WebNotificationData.h" 22 #include "public/platform/modules/notifications/WebNotificationData.h"
20 #include "public/platform/modules/notifications/WebNotificationManager.h" 23 #include "public/platform/modules/notifications/WebNotificationManager.h"
21 24
22 namespace blink { 25 namespace blink {
23 26
24 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str ing& title, const NotificationOptions& options) 27 ScriptPromise ServiceWorkerRegistrationNotifications::showNotification(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Str ing& title, const NotificationOptions& options, ExceptionState& exceptionState)
25 { 28 {
26 ExecutionContext* executionContext = scriptState->executionContext(); 29 ExecutionContext* executionContext = scriptState->executionContext();
27 30
28 // If context object's active worker is null, reject promise with a TypeErro r exception. 31 // If context object's active worker is null, reject promise with a TypeErro r exception.
29 if (!serviceWorkerRegistration.active()) 32 if (!serviceWorkerRegistration.active())
30 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); 33 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration."));
31 34
32 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. 35 // 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) 36 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.")); 37 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin."));
35 38
39 // FIXME: Unify the code path here with the Notification.create() function.
40 RefPtr<SerializedScriptValue> data;
41 String dataAsWireString;
42 if (options.hasData()) {
43 data = SerializedScriptValueFactory::instance().create(options.data(), n ullptr, exceptionState, options.data().isolate());
44 if (exceptionState.hadException())
45 return exceptionState.reject(scriptState);
46 dataAsWireString = data->toWireString();
47 }
48
36 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 49 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
37 ScriptPromise promise = resolver->promise(); 50 ScriptPromise promise = resolver->promise();
38 51
39 // FIXME: Do the appropriate CORS checks on the icon URL. 52 // FIXME: Do the appropriate CORS checks on the icon URL.
40 53
41 KURL iconUrl; 54 KURL iconUrl;
42 if (options.hasIcon() && !options.icon().isEmpty()) { 55 if (options.hasIcon() && !options.icon().isEmpty()) {
43 iconUrl = executionContext->completeURL(options.icon()); 56 iconUrl = executionContext->completeURL(options.icon());
44 if (!iconUrl.isValid()) 57 if (!iconUrl.isValid())
45 iconUrl = KURL(); 58 iconUrl = KURL();
46 } 59 }
47 60
48 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; 61 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight;
49 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, options.silent()); 62 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, options.silent(), dataAsWireString);
50 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); 63 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver);
51 64
52 SecurityOrigin* origin = executionContext->securityOrigin(); 65 SecurityOrigin* origin = executionContext->securityOrigin();
53 ASSERT(origin); 66 ASSERT(origin);
54 67
55 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 68 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
56 ASSERT(notificationManager); 69 ASSERT(notificationManager);
57 70
58 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); 71 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks);
59 return promise; 72 return promise;
60 } 73 }
61 74
62 } // namespace blink 75 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698