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 "config.h" | 5 #include "config.h" |
6 #include "modules/notifications/NotificationData.h" | 6 #include "modules/notifications/NotificationData.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/SerializedScriptValue.h" | 9 #include "bindings/core/v8/SerializedScriptValue.h" |
10 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 10 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptVa
lueFactory::instance().create(options.data().isolate(), options.data(), nullptr,
exceptionState); | 64 RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptVa
lueFactory::instance().create(options.data().isolate(), options.data(), nullptr,
exceptionState); |
65 if (exceptionState.hadException()) | 65 if (exceptionState.hadException()) |
66 return WebNotificationData(); | 66 return WebNotificationData(); |
67 | 67 |
68 Vector<char> serializedData; | 68 Vector<char> serializedData; |
69 serializedScriptValue->toWireBytes(serializedData); | 69 serializedScriptValue->toWireBytes(serializedData); |
70 | 70 |
71 webData.data = serializedData; | 71 webData.data = serializedData; |
72 } | 72 } |
73 | 73 |
74 // Ignore experimental NotificationOptions members if the flag is not set. | 74 Vector<WebNotificationAction> actions; |
75 if (RuntimeEnabledFeatures::notificationExperimentalEnabled()) { | |
76 Vector<WebNotificationAction> actions; | |
77 | 75 |
78 const size_t maxActions = Notification::maxActions(); | 76 const size_t maxActions = Notification::maxActions(); |
79 for (const NotificationAction& action : options.actions()) { | 77 for (const NotificationAction& action : options.actions()) { |
80 if (action.action().isEmpty()) { | 78 if (action.action().isEmpty()) { |
81 exceptionState.throwTypeError("NotificationAction `action` must
not be empty."); | 79 exceptionState.throwTypeError("NotificationAction `action` must not
be empty."); |
82 return WebNotificationData(); | 80 return WebNotificationData(); |
83 } | |
84 | |
85 if (action.title().isEmpty()) { | |
86 exceptionState.throwTypeError("NotificationAction `title` must n
ot be empty."); | |
87 return WebNotificationData(); | |
88 } | |
89 | |
90 if (actions.size() >= maxActions) | |
91 continue; | |
92 | |
93 WebNotificationAction webAction; | |
94 webAction.action = action.action(); | |
95 webAction.title = action.title(); | |
96 | |
97 actions.append(webAction); | |
98 } | 81 } |
99 | 82 |
100 webData.actions = actions; | 83 if (action.title().isEmpty()) { |
| 84 exceptionState.throwTypeError("NotificationAction `title` must not b
e empty."); |
| 85 return WebNotificationData(); |
| 86 } |
| 87 |
| 88 if (actions.size() >= maxActions) |
| 89 continue; |
| 90 |
| 91 WebNotificationAction webAction; |
| 92 webAction.action = action.action(); |
| 93 webAction.title = action.title(); |
| 94 |
| 95 actions.append(webAction); |
101 } | 96 } |
102 | 97 |
| 98 webData.actions = actions; |
| 99 |
103 return webData; | 100 return webData; |
104 } | 101 } |
105 | 102 |
106 } // namespace blink | 103 } // namespace blink |
OLD | NEW |