Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/NotificationData.h" | 5 #include "modules/notifications/NotificationData.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/SerializedScriptValue.h" | 8 #include "bindings/core/v8/SerializedScriptValue.h" |
| 9 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 9 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 WebNotificationData createWebNotificationData(ExecutionContext* executionContext , const String& title, const NotificationOptions& options, ExceptionState& excep tionState) | 33 WebNotificationData createWebNotificationData(ExecutionContext* executionContext , const String& title, const NotificationOptions& options, ExceptionState& excep tionState) |
| 34 { | 34 { |
| 35 // If silent is true, the notification must not have a vibration pattern. | 35 // If silent is true, the notification must not have a vibration pattern. |
| 36 if (options.hasVibrate() && options.silent()) { | 36 if (options.hasVibrate() && options.silent()) { |
| 37 exceptionState.throwTypeError("Silent notifications must not specify vib ration patterns."); | 37 exceptionState.throwTypeError("Silent notifications must not specify vib ration patterns."); |
| 38 return WebNotificationData(); | 38 return WebNotificationData(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // If renotify is true, the notification must have a tag. | |
| 42 if (options.renotify() && options.tag().isEmpty()) { | |
| 43 exceptionState.throwTypeError("Notifications which set the renotify flag must specify a valid tag."); | |
|
Peter Beverloo
2016/02/02 23:43:10
a valid tag -> a non-empty tag
The only validity
harkness
2016/02/03 11:24:28
Done.
| |
| 44 return WebNotificationData(); | |
| 45 } | |
| 46 | |
| 41 WebNotificationData webData; | 47 WebNotificationData webData; |
| 42 | 48 |
| 43 webData.title = title; | 49 webData.title = title; |
| 44 webData.direction = toDirectionEnumValue(options.dir()); | 50 webData.direction = toDirectionEnumValue(options.dir()); |
| 45 webData.lang = options.lang(); | 51 webData.lang = options.lang(); |
| 46 webData.body = options.body(); | 52 webData.body = options.body(); |
| 47 webData.tag = options.tag(); | 53 webData.tag = options.tag(); |
| 48 | 54 |
| 49 KURL iconUrl; | 55 KURL iconUrl; |
| 50 | 56 |
| 51 // TODO(peter): Apply the appropriate CORS checks on the |iconUrl|. | 57 // TODO(peter): Apply the appropriate CORS checks on the |iconUrl|. |
| 52 if (options.hasIcon() && !options.icon().isEmpty()) { | 58 if (options.hasIcon() && !options.icon().isEmpty()) { |
| 53 iconUrl = executionContext->completeURL(options.icon()); | 59 iconUrl = executionContext->completeURL(options.icon()); |
| 54 if (!iconUrl.isValid()) | 60 if (!iconUrl.isValid()) |
| 55 iconUrl = KURL(); | 61 iconUrl = KURL(); |
| 56 } | 62 } |
| 57 | 63 |
| 58 webData.icon = iconUrl; | 64 webData.icon = iconUrl; |
| 59 webData.vibrate = NavigatorVibration::sanitizeVibrationPattern(options.vibra te()); | 65 webData.vibrate = NavigatorVibration::sanitizeVibrationPattern(options.vibra te()); |
| 60 webData.timestamp = options.hasTimestamp() ? static_cast<double>(options.tim estamp()) : WTF::currentTimeMS(); | 66 webData.timestamp = options.hasTimestamp() ? static_cast<double>(options.tim estamp()) : WTF::currentTimeMS(); |
| 61 webData.silent = options.silent(); | 67 webData.silent = options.silent(); |
| 68 webData.renotify = options.renotify(); | |
| 62 webData.requireInteraction = options.requireInteraction(); | 69 webData.requireInteraction = options.requireInteraction(); |
| 63 | 70 |
| 64 if (options.hasData()) { | 71 if (options.hasData()) { |
| 65 RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptVa lueFactory::instance().create(options.data().isolate(), options.data(), nullptr, exceptionState); | 72 RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptVa lueFactory::instance().create(options.data().isolate(), options.data(), nullptr, exceptionState); |
| 66 if (exceptionState.hadException()) | 73 if (exceptionState.hadException()) |
| 67 return WebNotificationData(); | 74 return WebNotificationData(); |
| 68 | 75 |
| 69 Vector<char> serializedData; | 76 Vector<char> serializedData; |
| 70 serializedScriptValue->toWireBytes(serializedData); | 77 serializedScriptValue->toWireBytes(serializedData); |
| 71 | 78 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 85 | 92 |
| 86 actions.append(webAction); | 93 actions.append(webAction); |
| 87 } | 94 } |
| 88 | 95 |
| 89 webData.actions = actions; | 96 webData.actions = actions; |
| 90 | 97 |
| 91 return webData; | 98 return webData; |
| 92 } | 99 } |
| 93 | 100 |
| 94 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |