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

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

Issue 1042513002: Add the vibrate attribute to the Notification object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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"
11 #include "bindings/core/v8/SerializedScriptValue.h" 11 #include "bindings/core/v8/SerializedScriptValue.h"
12 #include "bindings/core/v8/SerializedScriptValueFactory.h" 12 #include "bindings/core/v8/SerializedScriptValueFactory.h"
13 #include "bindings/core/v8/V8ThrowException.h" 13 #include "bindings/core/v8/V8ThrowException.h"
14 #include "core/dom/DOMException.h" 14 #include "core/dom/DOMException.h"
15 #include "core/dom/ExceptionCode.h" 15 #include "core/dom/ExceptionCode.h"
16 #include "core/dom/ExecutionContext.h" 16 #include "core/dom/ExecutionContext.h"
17 #include "modules/notifications/GetNotificationOptions.h" 17 #include "modules/notifications/GetNotificationOptions.h"
18 #include "modules/notifications/Notification.h" 18 #include "modules/notifications/Notification.h"
19 #include "modules/notifications/NotificationOptions.h" 19 #include "modules/notifications/NotificationOptions.h"
20 #include "modules/vibration/NavigatorVibration.h"
20 #include "platform/weborigin/KURL.h" 21 #include "platform/weborigin/KURL.h"
21 #include "public/platform/Platform.h" 22 #include "public/platform/Platform.h"
22 #include "public/platform/WebSerializedOrigin.h" 23 #include "public/platform/WebSerializedOrigin.h"
23 #include "public/platform/modules/notifications/WebNotificationData.h" 24 #include "public/platform/modules/notifications/WebNotificationData.h"
24 #include "public/platform/modules/notifications/WebNotificationManager.h" 25 #include "public/platform/modules/notifications/WebNotificationManager.h"
25 26
26 namespace blink { 27 namespace blink {
27 namespace { 28 namespace {
28 29
29 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the 30 // Allows using a CallbackPromiseAdapter with a WebVector to resolve the
(...skipping 29 matching lines...) Expand all
59 ExecutionContext* executionContext = scriptState->executionContext(); 60 ExecutionContext* executionContext = scriptState->executionContext();
60 61
61 // If context object's active worker is null, reject promise with a TypeErro r exception. 62 // If context object's active worker is null, reject promise with a TypeErro r exception.
62 if (!serviceWorkerRegistration.active()) 63 if (!serviceWorkerRegistration.active())
63 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration.")); 64 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No active registration available on the ServiceWork erRegistration."));
64 65
65 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps. 66 // If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps.
66 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed) 67 if (Notification::checkPermission(executionContext) != WebNotificationPermis sionAllowed)
67 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin.")); 68 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "No notification permission has been granted for thi s origin."));
68 69
70 if (options.hasVibrate() && options.silent())
71 return ScriptPromise::reject(scriptState, V8ThrowException::createTypeEr ror(scriptState->isolate(), "Silent notification must not specify vibration patt erns."));
Peter Beverloo 2015/04/13 15:05:18 nit: notification -> notifications
Sanghyun Park 2015/04/13 17:27:23 Done.
72
69 // FIXME: Unify the code path here with the Notification.create() function. 73 // FIXME: Unify the code path here with the Notification.create() function.
70 Vector<char> dataAsWireBytes; 74 Vector<char> dataAsWireBytes;
71 if (options.hasData()) { 75 if (options.hasData()) {
72 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta nce().create(options.data(), nullptr, exceptionState, options.data().isolate()); 76 RefPtr<SerializedScriptValue> data = SerializedScriptValueFactory::insta nce().create(options.data(), nullptr, exceptionState, options.data().isolate());
73 if (exceptionState.hadException()) 77 if (exceptionState.hadException())
74 return exceptionState.reject(scriptState); 78 return exceptionState.reject(scriptState);
75 79
76 data->toWireBytes(dataAsWireBytes); 80 data->toWireBytes(dataAsWireBytes);
77 } 81 }
78 82
79 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 83 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
80 ScriptPromise promise = resolver->promise(); 84 ScriptPromise promise = resolver->promise();
81 85
82 // FIXME: Do the appropriate CORS checks on the icon URL. 86 // FIXME: Do the appropriate CORS checks on the icon URL.
83 87
84 KURL iconUrl; 88 KURL iconUrl;
85 if (options.hasIcon() && !options.icon().isEmpty()) { 89 if (options.hasIcon() && !options.icon().isEmpty()) {
86 iconUrl = executionContext->completeURL(options.icon()); 90 iconUrl = executionContext->completeURL(options.icon());
87 if (!iconUrl.isValid()) 91 if (!iconUrl.isValid())
88 iconUrl = KURL(); 92 iconUrl = KURL();
89 } 93 }
90 94
91 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight; 95 WebNotificationData::Direction dir = options.dir() == "rtl" ? WebNotificatio nData::DirectionRightToLeft : WebNotificationData::DirectionLeftToRight;
92 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, options.silent(), dataAsWireBytes); 96 WebNotificationData notification(title, dir, options.lang(), options.body(), options.tag(), iconUrl, NavigatorVibration::sanitizeVibrationPattern(options.vi brate()), options.silent(), dataAsWireBytes);
Peter Beverloo 2015/04/13 15:05:18 nit: Please extract this into a variable to improv
Sanghyun Park 2015/04/13 17:27:23 Okay I'll make variable about vibrate.
93 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver); 97 WebNotificationShowCallbacks* callbacks = new CallbackPromiseAdapter<void, v oid>(resolver);
94 98
95 SecurityOrigin* origin = executionContext->securityOrigin(); 99 SecurityOrigin* origin = executionContext->securityOrigin();
96 ASSERT(origin); 100 ASSERT(origin);
97 101
98 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 102 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
99 ASSERT(notificationManager); 103 ASSERT(notificationManager);
100 104
101 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks); 105 notificationManager->showPersistent(WebSerializedOrigin(*origin), notificati on, serviceWorkerRegistration.webRegistration(), callbacks);
102 return promise; 106 return promise;
103 } 107 }
104 108
105 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options) 109 ScriptPromise ServiceWorkerRegistrationNotifications::getNotifications(ScriptSta te* scriptState, ServiceWorkerRegistration& serviceWorkerRegistration, const Get NotificationOptions& options)
106 { 110 {
107 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 111 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
108 ScriptPromise promise = resolver->promise(); 112 ScriptPromise promise = resolver->promise();
109 113
110 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver); 114 WebNotificationGetCallbacks* callbacks = new CallbackPromiseAdapter<Notifica tionArray, void>(resolver);
111 115
112 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager(); 116 WebNotificationManager* notificationManager = Platform::current()->notificat ionManager();
113 ASSERT(notificationManager); 117 ASSERT(notificationManager);
114 118
115 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks); 119 notificationManager->getNotifications(options.tag(), serviceWorkerRegistrati on.webRegistration(), callbacks);
116 return promise; 120 return promise;
117 } 121 }
118 122
119 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698