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

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

Issue 1234553003: Supports the sound attribute to the Notification object Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: [WIP] Created 5 years, 5 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/ExceptionState.h"
10 #include "bindings/core/v8/ScriptPromiseResolver.h" 10 #include "bindings/core/v8/ScriptPromiseResolver.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ExecutionContext* executionContext = scriptState->executionContext(); 53 ExecutionContext* executionContext = scriptState->executionContext();
54 54
55 // If context object's active worker is null, reject promise with a TypeErro r exception. 55 // If context object's active worker is null, reject promise with a TypeErro r exception.
56 if (!serviceWorkerRegistration.active()) 56 if (!serviceWorkerRegistration.active())
57 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); 57 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration."));
58 58
59 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. 59 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps.
60 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed) 60 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed)
61 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); 61 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin."));
62 62
63 if (options.hasVibrate() && options.silent()) 63 if ((options.hasSound() || options.hasVibrate()) && options.silent())
64 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Silent notifications must not specify vibration pat terns.")); 64 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Silent notifications must not specify sound or vibr ation patterns."));
65 65
66 // FIXME: Unify the code path here with the Notification.create() function. 66 // FIXME: Unify the code path here with the Notification.create() function.
67 Vector<char> dataAsWireBytes; 67 Vector<char> dataAsWireBytes;
68 if (options.hasData()) { 68 if (options.hasData()) {
69 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta nce().create(options.data().isolate(), options.data(), nullptr, exceptionState); 69 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta nce().create(options.data().isolate(), options.data(), nullptr, exceptionState);
70 if (exceptionState.hadException()) 70 if (exceptionState.hadException())
71 return exceptionState.reject(scriptState); 71 return exceptionState.reject(scriptState);
72 72
73 data->toWireBytes(dataAsWireBytes); 73 data->toWireBytes(dataAsWireBytes);
74 } 74 }
75 75
76 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 76 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
77 ScriptPromise promise = resolver->promise(); 77 ScriptPromise promise = resolver->promise();
78 78
79 // FIXME: Do the appropriate CORS checks on the icon URL. 79 // FIXME: Do the appropriate CORS checks on the icon URL.
80 80
81 KURL iconUrl; 81 KURL iconUrl;
82 if (options.hasIcon() && !options.icon().isEmpty()) { 82 if (options.hasIcon() && !options.icon().isEmpty()) {
83 iconUrl = executionContext->completeURL(options.icon()); 83 iconUrl = executionContext->completeURL(options.icon());
84 if (!iconUrl.isValid()) 84 if (!iconUrl.isValid())
85 iconUrl = KURL(); 85 iconUrl = KURL();
86 } 86 }
87 87
88 KURL soundUrl;
89 if (options.hasSound() && !options.sound().isEmpty()) {
90 soundUrl = executionContext->completeURL(options.sound());
91 if (!soundUrl.isValid())
92 soundUrl = KURL();
93 }
94
88 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; 95 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight;
89 NavigatorVibration::VibrationPattern vibrate = NavigatorVibration::sanitizeV ibrationPattern(options.vibrate()); 96 NavigatorVibration::VibrationPattern vibrate = NavigatorVibration::sanitizeV ibrationPattern(options.vibrate());
90 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, vibrate, options.silent(), dataAsWireBytes); 97 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, soundUrl, vibrate, options.silent(), dataAsWireBytes);
91 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); 98 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver);
92 99
93 SecurityOrigin* origin = executionContext->securityOrigin(); 100 SecurityOrigin* origin = executionContext->securityOrigin();
94 ASSERT(origin); 101 ASSERT(origin);
95 102
96 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 103 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
97 ASSERT(notificationManager); 104 ASSERT(notificationManager);
98 105
99 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); 106 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks);
100 return promise; 107 return promise;
101 } 108 }
102 109
103 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) 110 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options)
104 { 111 {
105 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 112 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
106 ScriptPromise promise = resolver->promise(); 113 ScriptPromise promise = resolver->promise();
107 114
108 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); 115 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver);
109 116
110 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 117 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
111 ASSERT(notificationManager); 118 ASSERT(notificationManager);
112 119
113 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); 120 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks);
114 return promise; 121 return promise;
115 } 122 }
116 123
117 } // namespace blink 124 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/notifications/NotificationOptions.idl ('k') | public/platform/modules/notifications/WebNotificationData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698