Chromium Code Reviews| Index: third_party/WebKit/Source/modules/push_messaging/PushManager.cpp |
| diff --git a/third_party/WebKit/Source/modules/push_messaging/PushManager.cpp b/third_party/WebKit/Source/modules/push_messaging/PushManager.cpp |
| index 0f5a2ffd66ddd641444c5580ef3b4c3273ccc98d..f534cbc44f42cf9cd0b3244f19df2f92684762be 100644 |
| --- a/third_party/WebKit/Source/modules/push_messaging/PushManager.cpp |
| +++ b/third_party/WebKit/Source/modules/push_messaging/PushManager.cpp |
| @@ -34,13 +34,6 @@ WebPushProvider* pushProvider() |
| return webPushProvider; |
| } |
| -WebPushSubscriptionOptions toWebPushSubscriptionOptions(const PushSubscriptionOptions& options) |
| -{ |
| - WebPushSubscriptionOptions webOptions; |
| - webOptions.userVisibleOnly = options.userVisibleOnly(); |
| - return webOptions; |
| -} |
| - |
| } // namespace |
| PushManager::PushManager(ServiceWorkerRegistration* registration) |
| @@ -49,6 +42,39 @@ PushManager::PushManager(ServiceWorkerRegistration* registration) |
| ASSERT(registration); |
| } |
| +String PushManager::toString(const ArrayBufferOrArrayBufferView& applicationServerKey) |
| +{ |
| + // Check the validity of the sender info. It should either be a numeric sender |
| + // ID or a 65 byte unencrypted key. |
|
Peter Beverloo
2016/02/23 14:28:29
Developers will have two ways in Chrome to provide
harkness
2016/02/26 11:44:26
Done.
|
| + char* input; |
| + int length; |
| + if (applicationServerKey.isArrayBuffer()) { |
| + input = static_cast<char*>( |
| + applicationServerKey.getAsArrayBuffer()->data()); |
| + length = applicationServerKey.getAsArrayBuffer()->byteLength(); |
| + } else if (applicationServerKey.isArrayBufferView()) { |
| + input = static_cast<char*>( |
| + applicationServerKey.getAsArrayBufferView()->buffer()->data()); |
| + length = applicationServerKey.getAsArrayBufferView()->buffer()->byteLength(); |
| + } else { |
| + return String(); |
|
Peter Beverloo
2016/02/23 14:28:29
ASSERT_NOT_REACHED();
(The ArrayBufferOrArrayBuff
harkness
2016/02/26 11:44:26
Done.
|
| + } |
| + |
| + if ((atoi(input) != 0) || (length == 65 && input[0] == 0x04)) |
| + return WebString::fromUTF8(input, length); |
| + return String(); |
|
Peter Beverloo
2016/02/23 14:28:29
Per the specification:
harkness
2016/02/26 11:44:26
Done.
|
| +} |
| + |
| +WebPushSubscriptionOptions PushManager::toWebPushSubscriptionOptions(const PushSubscriptionOptions& options) |
| +{ |
| + WebPushSubscriptionOptions webOptions; |
| + webOptions.userVisibleOnly = options.userVisibleOnly(); |
| + if (options.hasApplicationServerKey()) { |
|
Peter Beverloo
2016/02/23 14:28:29
nit: no need for brackets on one-line statements.
harkness
2016/02/26 11:44:26
Done.
|
| + webOptions.applicationServerKey = PushManager::toString(options.applicationServerKey()); |
| + } |
| + return webOptions; |
| +} |
| + |
| ScriptPromise PushManager::subscribe(ScriptState* scriptState, const PushSubscriptionOptions& options) |
| { |
| if (!m_registration->active()) |