Chromium Code Reviews| 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/child/push_messaging/push_provider.h" | 5 #include "content/child/push_messaging/push_provider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/threading/thread_local.h" | 12 #include "base/threading/thread_local.h" |
| 13 #include "content/child/push_messaging/push_dispatcher.h" | 13 #include "content/child/push_messaging/push_dispatcher.h" |
| 14 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 14 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 15 #include "content/child/thread_safe_sender.h" | 15 #include "content/child/thread_safe_sender.h" |
| 16 #include "content/common/push_messaging_messages.h" | 16 #include "content/common/push_messaging_messages.h" |
| 17 #include "content/public/common/child_process_host.h" | 17 #include "content/public/common/child_process_host.h" |
| 18 #include "content/public/common/push_subscription_options.h" | |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc ription.h" | 20 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc ription.h" |
| 20 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc riptionOptions.h" | 21 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc riptionOptions.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 int CurrentWorkerId() { | 26 int CurrentWorkerId() { |
| 26 return WorkerThread::GetCurrentId(); | 27 return WorkerThread::GetCurrentId(); |
| 27 } | 28 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 OnGetPermissionStatusError); | 152 OnGetPermissionStatusError); |
| 152 IPC_MESSAGE_UNHANDLED(handled = false) | 153 IPC_MESSAGE_UNHANDLED(handled = false) |
| 153 IPC_END_MESSAGE_MAP() | 154 IPC_END_MESSAGE_MAP() |
| 154 | 155 |
| 155 return handled; | 156 return handled; |
| 156 } | 157 } |
| 157 | 158 |
| 158 void PushProvider::OnSubscribeFromWorkerSuccess( | 159 void PushProvider::OnSubscribeFromWorkerSuccess( |
| 159 int request_id, | 160 int request_id, |
| 160 const GURL& endpoint, | 161 const GURL& endpoint, |
| 162 const PushSubscriptionOptions& options, | |
| 161 const std::vector<uint8_t>& p256dh, | 163 const std::vector<uint8_t>& p256dh, |
| 162 const std::vector<uint8_t>& auth) { | 164 const std::vector<uint8_t>& auth) { |
| 163 blink::WebPushSubscriptionCallbacks* callbacks = | 165 blink::WebPushSubscriptionCallbacks* callbacks = |
| 164 subscription_callbacks_.Lookup(request_id); | 166 subscription_callbacks_.Lookup(request_id); |
| 165 if (!callbacks) | 167 if (!callbacks) |
| 166 return; | 168 return; |
| 167 | 169 |
| 168 callbacks->onSuccess( | 170 callbacks->onSuccess(base::WrapUnique(new blink::WebPushSubscription( |
| 169 base::WrapUnique(new blink::WebPushSubscription(endpoint, p256dh, auth))); | 171 endpoint, options.user_visible_only, |
| 172 blink::WebString::fromLatin1(options.sender_info), p256dh, auth))); | |
| 170 | 173 |
| 171 subscription_callbacks_.Remove(request_id); | 174 subscription_callbacks_.Remove(request_id); |
| 172 } | 175 } |
| 173 | 176 |
| 174 void PushProvider::OnSubscribeFromWorkerError(int request_id, | 177 void PushProvider::OnSubscribeFromWorkerError(int request_id, |
| 175 PushRegistrationStatus status) { | 178 PushRegistrationStatus status) { |
| 176 blink::WebPushSubscriptionCallbacks* callbacks = | 179 blink::WebPushSubscriptionCallbacks* callbacks = |
| 177 subscription_callbacks_.Lookup(request_id); | 180 subscription_callbacks_.Lookup(request_id); |
| 178 if (!callbacks) | 181 if (!callbacks) |
| 179 return; | 182 return; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 214 |
| 212 callbacks->onError(blink::WebPushError( | 215 callbacks->onError(blink::WebPushError( |
| 213 error_type, blink::WebString::fromUTF8(error_message))); | 216 error_type, blink::WebString::fromUTF8(error_message))); |
| 214 | 217 |
| 215 unsubscribe_callbacks_.Remove(request_id); | 218 unsubscribe_callbacks_.Remove(request_id); |
| 216 } | 219 } |
| 217 | 220 |
| 218 void PushProvider::OnGetSubscriptionSuccess( | 221 void PushProvider::OnGetSubscriptionSuccess( |
| 219 int request_id, | 222 int request_id, |
| 220 const GURL& endpoint, | 223 const GURL& endpoint, |
| 224 const PushSubscriptionOptions& options, | |
| 221 const std::vector<uint8_t>& p256dh, | 225 const std::vector<uint8_t>& p256dh, |
| 222 const std::vector<uint8_t>& auth) { | 226 const std::vector<uint8_t>& auth) { |
| 223 blink::WebPushSubscriptionCallbacks* callbacks = | 227 blink::WebPushSubscriptionCallbacks* callbacks = |
| 224 subscription_callbacks_.Lookup(request_id); | 228 subscription_callbacks_.Lookup(request_id); |
| 225 if (!callbacks) | 229 if (!callbacks) |
| 226 return; | 230 return; |
| 227 | 231 |
| 228 callbacks->onSuccess( | 232 callbacks->onSuccess(base::WrapUnique(new blink::WebPushSubscription( |
| 229 base::WrapUnique(new blink::WebPushSubscription(endpoint, p256dh, auth))); | 233 endpoint, options.user_visible_only, |
| 234 blink::WebString::fromLatin1(options.sender_info), p256dh, auth))); | |
|
Peter Beverloo
2016/07/08 18:30:12
When moving to Mojo, we'd probably want Blink to t
johnme
2016/07/13 17:51:57
Acknowledged. Added a TODO in WebPushSubscriptionO
| |
| 230 | 235 |
| 231 subscription_callbacks_.Remove(request_id); | 236 subscription_callbacks_.Remove(request_id); |
| 232 } | 237 } |
| 233 | 238 |
| 234 void PushProvider::OnGetSubscriptionError(int request_id, | 239 void PushProvider::OnGetSubscriptionError(int request_id, |
| 235 PushGetRegistrationStatus status) { | 240 PushGetRegistrationStatus status) { |
| 236 blink::WebPushSubscriptionCallbacks* callbacks = | 241 blink::WebPushSubscriptionCallbacks* callbacks = |
| 237 subscription_callbacks_.Lookup(request_id); | 242 subscription_callbacks_.Lookup(request_id); |
| 238 if (!callbacks) | 243 if (!callbacks) |
| 239 return; | 244 return; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 "supported."; | 277 "supported."; |
| 273 } | 278 } |
| 274 | 279 |
| 275 callbacks->onError( | 280 callbacks->onError( |
| 276 blink::WebPushError(error, blink::WebString::fromUTF8(error_message))); | 281 blink::WebPushError(error, blink::WebString::fromUTF8(error_message))); |
| 277 | 282 |
| 278 permission_status_callbacks_.Remove(request_id); | 283 permission_status_callbacks_.Remove(request_id); |
| 279 } | 284 } |
| 280 | 285 |
| 281 } // namespace content | 286 } // namespace content |
| OLD | NEW |