| OLD | NEW |
| 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 "content/renderer/push_messaging/push_messaging_dispatcher.h" | 5 #include "content/renderer/push_messaging/push_messaging_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 9 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 10 #include "content/common/push_messaging_messages.h" | 10 #include "content/common/push_messaging_messages.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 108 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); |
| 109 return; | 109 return; |
| 110 } | 110 } |
| 111 Send(new PushMessagingHostMsg_Subscribe( | 111 Send(new PushMessagingHostMsg_Subscribe( |
| 112 routing_id(), request_id, service_worker_registration_id, options)); | 112 routing_id(), request_id, service_worker_registration_id, options)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( | 115 void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( |
| 116 int32_t request_id, | 116 int32_t request_id, |
| 117 const GURL& endpoint, | 117 const GURL& endpoint, |
| 118 const PushSubscriptionOptions& options, |
| 118 const std::vector<uint8_t>& p256dh, | 119 const std::vector<uint8_t>& p256dh, |
| 119 const std::vector<uint8_t>& auth) { | 120 const std::vector<uint8_t>& auth) { |
| 120 blink::WebPushSubscriptionCallbacks* callbacks = | 121 blink::WebPushSubscriptionCallbacks* callbacks = |
| 121 subscription_callbacks_.Lookup(request_id); | 122 subscription_callbacks_.Lookup(request_id); |
| 122 DCHECK(callbacks); | 123 DCHECK(callbacks); |
| 123 | 124 |
| 124 callbacks->onSuccess( | 125 callbacks->onSuccess(base::WrapUnique(new blink::WebPushSubscription( |
| 125 base::WrapUnique(new blink::WebPushSubscription(endpoint, p256dh, auth))); | 126 endpoint, options.user_visible_only, |
| 127 blink::WebString::fromLatin1(options.sender_info), p256dh, auth))); |
| 126 | 128 |
| 127 subscription_callbacks_.Remove(request_id); | 129 subscription_callbacks_.Remove(request_id); |
| 128 } | 130 } |
| 129 | 131 |
| 130 void PushMessagingDispatcher::OnSubscribeFromDocumentError( | 132 void PushMessagingDispatcher::OnSubscribeFromDocumentError( |
| 131 int32_t request_id, | 133 int32_t request_id, |
| 132 PushRegistrationStatus status) { | 134 PushRegistrationStatus status) { |
| 133 blink::WebPushSubscriptionCallbacks* callbacks = | 135 blink::WebPushSubscriptionCallbacks* callbacks = |
| 134 subscription_callbacks_.Lookup(request_id); | 136 subscription_callbacks_.Lookup(request_id); |
| 135 DCHECK(callbacks); | 137 DCHECK(callbacks); |
| 136 | 138 |
| 137 blink::WebPushError::ErrorType error_type = | 139 blink::WebPushError::ErrorType error_type = |
| 138 status == PUSH_REGISTRATION_STATUS_PERMISSION_DENIED | 140 status == PUSH_REGISTRATION_STATUS_PERMISSION_DENIED |
| 139 ? blink::WebPushError::ErrorTypePermissionDenied | 141 ? blink::WebPushError::ErrorTypePermissionDenied |
| 140 : blink::WebPushError::ErrorTypeAbort; | 142 : blink::WebPushError::ErrorTypeAbort; |
| 141 | 143 |
| 142 callbacks->onError(blink::WebPushError( | 144 callbacks->onError(blink::WebPushError( |
| 143 error_type, | 145 error_type, |
| 144 blink::WebString::fromUTF8(PushRegistrationStatusToString(status)))); | 146 blink::WebString::fromUTF8(PushRegistrationStatusToString(status)))); |
| 145 | 147 |
| 146 subscription_callbacks_.Remove(request_id); | 148 subscription_callbacks_.Remove(request_id); |
| 147 } | 149 } |
| 148 | 150 |
| 149 } // namespace content | 151 } // namespace content |
| OLD | NEW |