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

Side by Side Diff: third_party/WebKit/Source/modules/push_messaging/PushManager.cpp

Issue 1816123002: Add testing for subscription from service workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix asan errors Created 4 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 "modules/push_messaging/PushManager.h" 5 #include "modules/push_messaging/PushManager.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
(...skipping 20 matching lines...) Expand all
31 { 31 {
32 WebPushProvider* webPushProvider = Platform::current()->pushProvider(); 32 WebPushProvider* webPushProvider = Platform::current()->pushProvider();
33 ASSERT(webPushProvider); 33 ASSERT(webPushProvider);
34 return webPushProvider; 34 return webPushProvider;
35 } 35 }
36 36
37 String bufferSourceToString(const ArrayBufferOrArrayBufferView& applicationServe rKey, ExceptionState& exceptionState) 37 String bufferSourceToString(const ArrayBufferOrArrayBufferView& applicationServe rKey, ExceptionState& exceptionState)
38 { 38 {
39 // Check the validity of the sender info. It must be a 65 byte unencrypted k ey, 39 // Check the validity of the sender info. It must be a 65 byte unencrypted k ey,
40 // which has the byte 0x04 as the first byte as a marker. 40 // which has the byte 0x04 as the first byte as a marker.
41 char* input; 41 unsigned char* input;
42 int length; 42 int length;
43 if (applicationServerKey.isArrayBuffer()) { 43 if (applicationServerKey.isArrayBuffer()) {
44 input = static_cast<char*>( 44 input = static_cast<unsigned char*>(
45 applicationServerKey.getAsArrayBuffer()->data()); 45 applicationServerKey.getAsArrayBuffer()->data());
46 length = applicationServerKey.getAsArrayBuffer()->byteLength(); 46 length = applicationServerKey.getAsArrayBuffer()->byteLength();
47 } else if (applicationServerKey.isArrayBufferView()) { 47 } else if (applicationServerKey.isArrayBufferView()) {
48 input = static_cast<char*>( 48 input = static_cast<unsigned char*>(
49 applicationServerKey.getAsArrayBufferView()->buffer()->data()); 49 applicationServerKey.getAsArrayBufferView()->buffer()->data());
50 length = applicationServerKey.getAsArrayBufferView()->buffer()->byteLeng th(); 50 length = applicationServerKey.getAsArrayBufferView()->buffer()->byteLeng th();
51 } else { 51 } else {
52 ASSERT_NOT_REACHED(); 52 ASSERT_NOT_REACHED();
53 return String(); 53 return String();
54 } 54 }
55 55
56 // If the key is valid, just treat it as a string of bytes and pass it to
57 // the push service.
56 if (length == 65 && input[0] == 0x04) 58 if (length == 65 && input[0] == 0x04)
57 return WebString::fromUTF8(input, length); 59 return WebString::fromLatin1(input, length);
60
58 exceptionState.throwDOMException(InvalidAccessError, "The provided applicati onServerKey is not valid."); 61 exceptionState.throwDOMException(InvalidAccessError, "The provided applicati onServerKey is not valid.");
59 return String(); 62 return String();
60 } 63 }
61 64
62 } // namespace 65 } // namespace
63 66
64 PushManager::PushManager(ServiceWorkerRegistration* registration) 67 PushManager::PushManager(ServiceWorkerRegistration* registration)
65 : m_registration(registration) 68 : m_registration(registration)
66 { 69 {
67 ASSERT(registration); 70 ASSERT(registration);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 pushProvider()->getPermissionStatus(m_registration->webRegistration(), toWeb PushSubscriptionOptions(options, exceptionState), new PushPermissionStatusCallba cks(resolver)); 131 pushProvider()->getPermissionStatus(m_registration->webRegistration(), toWeb PushSubscriptionOptions(options, exceptionState), new PushPermissionStatusCallba cks(resolver));
129 return promise; 132 return promise;
130 } 133 }
131 134
132 DEFINE_TRACE(PushManager) 135 DEFINE_TRACE(PushManager)
133 { 136 {
134 visitor->trace(m_registration); 137 visitor->trace(m_registration);
135 } 138 }
136 139
137 } // namespace blink 140 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698