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/browser/push_messaging/push_messaging_message_filter.h" | 5 #include "content/browser/push_messaging/push_messaging_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "content/browser/renderer_host/render_process_host_impl.h" | 18 #include "content/browser/renderer_host/render_process_host_impl.h" |
19 #include "content/browser/service_worker/service_worker_context_core.h" | 19 #include "content/browser/service_worker/service_worker_context_core.h" |
20 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 20 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
21 #include "content/browser/service_worker/service_worker_storage.h" | 21 #include "content/browser/service_worker/service_worker_storage.h" |
22 #include "content/common/push_messaging_messages.h" | |
23 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
Peter Beverloo
2017/02/16 16:08:32
nit: this is now included in the header, so can be
ke.he
2017/02/17 08:22:28
Done.
| |
25 #include "content/public/browser/permission_manager.h" | 24 #include "content/public/browser/permission_manager.h" |
26 #include "content/public/browser/permission_type.h" | 25 #include "content/public/browser/permission_type.h" |
27 #include "content/public/browser/push_messaging_service.h" | 26 #include "content/public/browser/push_messaging_service.h" |
28 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
29 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
30 #include "content/public/common/child_process_host.h" | 29 #include "content/public/common/child_process_host.h" |
31 #include "content/public/common/console_message_level.h" | 30 #include "content/public/common/console_message_level.h" |
32 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
33 #include "content/public/common/push_messaging_status.h" | 32 #include "content/public/common/push_messaging_status.h" |
34 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi ssionStatus.h" | 33 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi ssionStatus.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 const std::string& stored_sender_id) { | 102 const std::string& stored_sender_id) { |
104 if (!sender_info.empty()) | 103 if (!sender_info.empty()) |
105 return sender_info; | 104 return sender_info; |
106 if (base::ContainsOnlyChars(stored_sender_id, "0123456789")) | 105 if (base::ContainsOnlyChars(stored_sender_id, "0123456789")) |
107 return stored_sender_id; | 106 return stored_sender_id; |
108 return std::string(); | 107 return std::string(); |
109 } | 108 } |
110 | 109 |
111 } // namespace | 110 } // namespace |
112 | 111 |
113 struct PushMessagingMessageFilter::RegisterData { | 112 struct PushMessagingManager::RegisterData { |
114 RegisterData(); | 113 RegisterData(); |
115 RegisterData(const RegisterData& other) = default; | 114 RegisterData(const RegisterData& other) = default; |
116 bool FromDocument() const; | 115 bool FromDocument() const; |
117 int request_id; | |
118 GURL requesting_origin; | 116 GURL requesting_origin; |
119 int64_t service_worker_registration_id; | 117 int64_t service_worker_registration_id; |
120 PushSubscriptionOptions options; | 118 PushSubscriptionOptions options; |
121 // The following member should only be read if FromDocument() is true. | 119 // The following member should only be read if FromDocument() is true. |
122 int render_frame_id; | 120 int render_frame_id; |
123 }; | 121 }; |
124 | 122 |
125 // Inner core of this message filter which lives on the UI thread. | 123 // Inner core of the PushMessagingManager which lives on the UI thread. |
126 class PushMessagingMessageFilter::Core { | 124 class PushMessagingManager::Core { |
127 public: | 125 public: |
128 Core(const base::WeakPtr<PushMessagingMessageFilter>& io_parent, | 126 Core(const base::WeakPtr<PushMessagingManager>& io_parent, |
129 int render_process_id); | 127 int render_process_id); |
130 | 128 |
131 // Public Register methods on UI thread -------------------------------------- | 129 // Public Register methods on UI thread -------------------------------------- |
132 | 130 |
133 // Called via PostTask from IO thread. | 131 // Called via PostTask from IO thread. |
134 void RegisterOnUI(const RegisterData& data); | 132 void RegisterOnUI(const SubscribeCallback& callback, |
133 const RegisterData& data); | |
135 | 134 |
136 // Public Unregister methods on UI thread ------------------------------------ | 135 // Public Unregister methods on UI thread ------------------------------------ |
137 | 136 |
138 // Called via PostTask from IO thread. | 137 // Called via PostTask from IO thread. |
139 void UnregisterFromService(int request_id, | 138 void UnregisterFromService(const UnsubscribeCallback& callback, |
140 int64_t service_worker_registration_id, | 139 int64_t service_worker_registration_id, |
141 const GURL& requesting_origin, | 140 const GURL& requesting_origin, |
142 const std::string& sender_id); | 141 const std::string& sender_id); |
143 | 142 |
144 // Public GetPermission methods on UI thread --------------------------------- | 143 // Public GetPermission methods on UI thread --------------------------------- |
145 | 144 |
146 // Called via PostTask from IO thread. | 145 // Called via PostTask from IO thread. |
147 void GetPermissionStatusOnUI(const GURL& requesting_origin, | 146 void GetPermissionStatusOnUI(const GetPermissionStatusCallback& callback, |
148 bool user_visible, | 147 const GURL& requesting_origin, |
149 int request_id); | 148 bool user_visible); |
150 | 149 |
151 // Public helper methods on UI thread ---------------------------------------- | 150 // Public helper methods on UI thread ---------------------------------------- |
152 | 151 |
153 // Called via PostTask from IO thread. The |io_thread_callback| callback | 152 // Called via PostTask from IO thread. The |io_thread_callback| callback |
154 // will be invoked on the IO thread. | 153 // will be invoked on the IO thread. |
155 void GetEncryptionInfoOnUI( | 154 void GetEncryptionInfoOnUI( |
156 const GURL& origin, | 155 const GURL& origin, |
157 int64_t service_worker_registration_id, | 156 int64_t service_worker_registration_id, |
158 const std::string& sender_id, | 157 const std::string& sender_id, |
159 const PushMessagingService::EncryptionInfoCallback& io_thread_callback); | 158 const PushMessagingService::EncryptionInfoCallback& io_thread_callback); |
160 | 159 |
161 // Called (directly) from both the UI and IO threads. | 160 // Called (directly) from both the UI and IO threads. |
162 bool is_incognito() const { return is_incognito_; } | 161 bool is_incognito() const { return is_incognito_; } |
163 | 162 |
164 // Returns a push messaging service. May return null. | 163 // Returns a push messaging service. May return null. |
165 PushMessagingService* service(); | 164 PushMessagingService* service(); |
166 | 165 |
167 private: | 166 private: |
168 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 167 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
169 friend class base::DeleteHelper<Core>; | 168 friend class base::DeleteHelper<Core>; |
170 | 169 |
171 ~Core(); | 170 ~Core(); |
172 | 171 |
173 // Private Register methods on UI thread ------------------------------------- | 172 // Private Register methods on UI thread ------------------------------------- |
174 | 173 |
175 void DidRequestPermissionInIncognito(const RegisterData& data, | 174 void DidRequestPermissionInIncognito(const SubscribeCallback& callback, |
175 const RegisterData& data, | |
176 blink::mojom::PermissionStatus status); | 176 blink::mojom::PermissionStatus status); |
177 | 177 |
178 void DidRegister(const RegisterData& data, | 178 void DidRegister(const SubscribeCallback& callback, |
179 const RegisterData& data, | |
179 const std::string& push_registration_id, | 180 const std::string& push_registration_id, |
180 const std::vector<uint8_t>& p256dh, | 181 const std::vector<uint8_t>& p256dh, |
181 const std::vector<uint8_t>& auth, | 182 const std::vector<uint8_t>& auth, |
182 PushRegistrationStatus status); | 183 PushRegistrationStatus status); |
183 | 184 |
184 // Private Unregister methods on UI thread ----------------------------------- | 185 // Private Unregister methods on UI thread ----------------------------------- |
185 | 186 |
186 void DidUnregisterFromService(int request_id, | 187 void DidUnregisterFromService(const UnsubscribeCallback& callback, |
187 int64_t service_worker_registration_id, | 188 int64_t service_worker_registration_id, |
188 PushUnregistrationStatus unregistration_status); | 189 PushUnregistrationStatus unregistration_status); |
189 | 190 |
190 // Private helper methods on UI thread --------------------------------------- | 191 // Outer part of the PushMessagingManager which lives on the IO thread. |
191 | 192 base::WeakPtr<PushMessagingManager> io_parent_; |
192 void Send(IPC::Message* message); | |
193 | |
194 // Outer part of this message filter which lives on the IO thread. | |
195 base::WeakPtr<PushMessagingMessageFilter> io_parent_; | |
196 | 193 |
197 int render_process_id_; | 194 int render_process_id_; |
198 | 195 |
199 bool is_incognito_; | 196 bool is_incognito_; |
200 | 197 |
201 base::WeakPtrFactory<Core> weak_factory_ui_to_ui_; | 198 base::WeakPtrFactory<Core> weak_factory_ui_to_ui_; |
202 | 199 |
203 DISALLOW_COPY_AND_ASSIGN(Core); | 200 DISALLOW_COPY_AND_ASSIGN(Core); |
204 }; | 201 }; |
205 | 202 |
206 PushMessagingMessageFilter::RegisterData::RegisterData() | 203 PushMessagingManager::RegisterData::RegisterData() |
207 : request_id(0), | 204 : service_worker_registration_id(0), |
208 service_worker_registration_id(0), | |
209 render_frame_id(ChildProcessHost::kInvalidUniqueID) {} | 205 render_frame_id(ChildProcessHost::kInvalidUniqueID) {} |
210 | 206 |
211 bool PushMessagingMessageFilter::RegisterData::FromDocument() const { | 207 bool PushMessagingManager::RegisterData::FromDocument() const { |
212 return render_frame_id != ChildProcessHost::kInvalidUniqueID; | 208 return render_frame_id != ChildProcessHost::kInvalidUniqueID; |
213 } | 209 } |
214 | 210 |
215 PushMessagingMessageFilter::Core::Core( | 211 PushMessagingManager::Core::Core( |
216 const base::WeakPtr<PushMessagingMessageFilter>& io_parent, | 212 const base::WeakPtr<PushMessagingManager>& io_parent, |
217 int render_process_id) | 213 int render_process_id) |
218 : io_parent_(io_parent), | 214 : io_parent_(io_parent), |
219 render_process_id_(render_process_id), | 215 render_process_id_(render_process_id), |
220 weak_factory_ui_to_ui_(this) { | 216 weak_factory_ui_to_ui_(this) { |
221 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 217 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
222 RenderProcessHost* process_host = | 218 RenderProcessHost* process_host = |
223 RenderProcessHost::FromID(render_process_id_); // Can't be null yet. | 219 RenderProcessHost::FromID(render_process_id_); // Can't be null yet. |
224 is_incognito_ = process_host->GetBrowserContext()->IsOffTheRecord(); | 220 is_incognito_ = process_host->GetBrowserContext()->IsOffTheRecord(); |
225 } | 221 } |
226 | 222 |
227 PushMessagingMessageFilter::Core::~Core() {} | 223 PushMessagingManager::Core::~Core() {} |
228 | 224 |
229 PushMessagingMessageFilter::PushMessagingMessageFilter( | 225 PushMessagingManager::PushMessagingManager( |
230 int render_process_id, | 226 int render_process_id, |
231 ServiceWorkerContextWrapper* service_worker_context) | 227 ServiceWorkerContextWrapper* service_worker_context) |
232 : BrowserMessageFilter(PushMessagingMsgStart), | 228 : service_worker_context_(service_worker_context), |
233 service_worker_context_(service_worker_context), | |
234 weak_factory_io_to_io_(this) { | 229 weak_factory_io_to_io_(this) { |
235 // Although this class is used only on the IO thread, it is constructed on UI. | 230 // Although this class is used only on the IO thread, it is constructed on UI. |
236 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 231 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
237 // Normally, it would be unsafe to obtain a weak pointer from the UI thread, | 232 // Normally, it would be unsafe to obtain a weak pointer from the UI thread, |
238 // but it's ok in the constructor since we can't be destroyed before our | 233 // but it's ok in the constructor since we can't be destroyed before our |
239 // constructor finishes. | 234 // constructor finishes. |
240 ui_core_.reset( | 235 ui_core_.reset( |
241 new Core(weak_factory_io_to_io_.GetWeakPtr(), render_process_id)); | 236 new Core(weak_factory_io_to_io_.GetWeakPtr(), render_process_id)); |
242 | 237 |
243 PushMessagingService* service = ui_core_->service(); | 238 PushMessagingService* service = ui_core_->service(); |
244 service_available_ = !!service; | 239 service_available_ = !!service; |
245 | 240 |
246 if (service_available_) { | 241 if (service_available_) { |
247 default_endpoint_ = service->GetEndpoint(false /* standard_protocol */); | 242 default_endpoint_ = service->GetEndpoint(false /* standard_protocol */); |
248 web_push_protocol_endpoint_ = | 243 web_push_protocol_endpoint_ = |
249 service->GetEndpoint(true /* standard_protocol */); | 244 service->GetEndpoint(true /* standard_protocol */); |
250 } | 245 } |
251 } | 246 } |
252 | 247 |
253 PushMessagingMessageFilter::~PushMessagingMessageFilter() {} | 248 PushMessagingManager::~PushMessagingManager() {} |
254 | 249 |
255 void PushMessagingMessageFilter::OnDestruct() const { | 250 void PushMessagingManager::BindRequest(mojom::PushMessagingRequest request) { |
256 BrowserThread::DeleteOnIOThread::Destruct(this); | 251 bindings_.AddBinding(this, std::move(request)); |
257 } | |
258 | |
259 bool PushMessagingMessageFilter::OnMessageReceived( | |
260 const IPC::Message& message) { | |
261 bool handled = true; | |
262 IPC_BEGIN_MESSAGE_MAP(PushMessagingMessageFilter, message) | |
263 IPC_MESSAGE_HANDLER(PushMessagingHostMsg_Subscribe, OnSubscribe) | |
264 IPC_MESSAGE_HANDLER(PushMessagingHostMsg_Unsubscribe, OnUnsubscribe) | |
265 IPC_MESSAGE_HANDLER(PushMessagingHostMsg_GetSubscription, OnGetSubscription) | |
266 IPC_MESSAGE_HANDLER(PushMessagingHostMsg_GetPermissionStatus, | |
267 OnGetPermissionStatus) | |
268 IPC_MESSAGE_UNHANDLED(handled = false) | |
269 IPC_END_MESSAGE_MAP() | |
270 return handled; | |
271 } | 252 } |
272 | 253 |
273 // Subscribe methods on both IO and UI threads, merged in order of use from | 254 // Subscribe methods on both IO and UI threads, merged in order of use from |
274 // PushMessagingMessageFilter and Core. | 255 // PushMessagingManager and Core. |
275 // ----------------------------------------------------------------------------- | 256 // ----------------------------------------------------------------------------- |
276 | 257 |
277 void PushMessagingMessageFilter::OnSubscribe( | 258 void PushMessagingManager::Subscribe(int32_t render_frame_id, |
278 int render_frame_id, | 259 int64_t service_worker_registration_id, |
279 int request_id, | 260 const PushSubscriptionOptions& options, |
280 int64_t service_worker_registration_id, | 261 const SubscribeCallback& callback) { |
281 const PushSubscriptionOptions& options) { | |
282 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 262 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
283 // TODO(mvanouwerkerk): Validate arguments? | 263 // TODO(mvanouwerkerk): Validate arguments? |
284 RegisterData data; | 264 RegisterData data; |
285 | 265 |
286 // Will be ChildProcessHost::kInvalidUniqueID in requests from Service Worker. | 266 // Will be ChildProcessHost::kInvalidUniqueID in requests from Service Worker. |
287 data.render_frame_id = render_frame_id; | 267 data.render_frame_id = render_frame_id; |
288 | 268 |
289 data.request_id = request_id; | |
290 data.service_worker_registration_id = service_worker_registration_id; | 269 data.service_worker_registration_id = service_worker_registration_id; |
291 data.options = options; | 270 data.options = options; |
292 | 271 |
293 ServiceWorkerRegistration* service_worker_registration = | 272 ServiceWorkerRegistration* service_worker_registration = |
294 service_worker_context_->GetLiveRegistration( | 273 service_worker_context_->GetLiveRegistration( |
295 data.service_worker_registration_id); | 274 data.service_worker_registration_id); |
296 if (!service_worker_registration || | 275 if (!service_worker_registration || |
297 !service_worker_registration->active_version()) { | 276 !service_worker_registration->active_version()) { |
298 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_NO_SERVICE_WORKER); | 277 SendSubscriptionError(callback, data, |
Peter Beverloo
2017/02/16 16:08:32
Did you consider storing |callback| in |data| (Reg
ke.he
2017/02/17 08:22:28
tracked by issue 693366.
| |
278 PUSH_REGISTRATION_STATUS_NO_SERVICE_WORKER); | |
299 return; | 279 return; |
300 } | 280 } |
301 data.requesting_origin = service_worker_registration->pattern().GetOrigin(); | 281 data.requesting_origin = service_worker_registration->pattern().GetOrigin(); |
302 | 282 |
303 DCHECK(!(data.options.sender_info.empty() && data.FromDocument())); | 283 DCHECK(!(data.options.sender_info.empty() && data.FromDocument())); |
304 | 284 |
305 service_worker_context_->GetRegistrationUserData( | 285 service_worker_context_->GetRegistrationUserData( |
306 data.service_worker_registration_id, | 286 data.service_worker_registration_id, |
307 {kPushRegistrationIdServiceWorkerKey, kPushSenderIdServiceWorkerKey}, | 287 {kPushRegistrationIdServiceWorkerKey, kPushSenderIdServiceWorkerKey}, |
308 base::Bind(&PushMessagingMessageFilter::DidCheckForExistingRegistration, | 288 base::Bind(&PushMessagingManager::DidCheckForExistingRegistration, |
309 weak_factory_io_to_io_.GetWeakPtr(), data)); | 289 weak_factory_io_to_io_.GetWeakPtr(), callback, data)); |
310 } | 290 } |
311 | 291 |
312 void PushMessagingMessageFilter::DidCheckForExistingRegistration( | 292 void PushMessagingManager::DidCheckForExistingRegistration( |
293 const SubscribeCallback& callback, | |
313 const RegisterData& data, | 294 const RegisterData& data, |
314 const std::vector<std::string>& push_registration_id_and_sender_id, | 295 const std::vector<std::string>& push_registration_id_and_sender_id, |
315 ServiceWorkerStatusCode service_worker_status) { | 296 ServiceWorkerStatusCode service_worker_status) { |
316 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 297 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
317 if (service_worker_status == SERVICE_WORKER_OK) { | 298 if (service_worker_status == SERVICE_WORKER_OK) { |
318 DCHECK_EQ(2u, push_registration_id_and_sender_id.size()); | 299 DCHECK_EQ(2u, push_registration_id_and_sender_id.size()); |
319 const auto& push_registration_id = push_registration_id_and_sender_id[0]; | 300 const auto& push_registration_id = push_registration_id_and_sender_id[0]; |
320 const auto& stored_sender_id = push_registration_id_and_sender_id[1]; | 301 const auto& stored_sender_id = push_registration_id_and_sender_id[1]; |
321 std::string fixed_sender_id = | 302 std::string fixed_sender_id = |
322 FixSenderInfo(data.options.sender_info, stored_sender_id); | 303 FixSenderInfo(data.options.sender_info, stored_sender_id); |
323 if (fixed_sender_id.empty()) { | 304 if (fixed_sender_id.empty()) { |
324 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 305 SendSubscriptionError(callback, data, |
306 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | |
325 return; | 307 return; |
326 } | 308 } |
327 if (fixed_sender_id != stored_sender_id) { | 309 if (fixed_sender_id != stored_sender_id) { |
328 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_SENDER_ID_MISMATCH); | 310 SendSubscriptionError(callback, data, |
311 PUSH_REGISTRATION_STATUS_SENDER_ID_MISMATCH); | |
329 return; | 312 return; |
330 } | 313 } |
331 auto callback = base::Bind( | 314 auto callback_ui = base::Bind(&PushMessagingManager::DidGetEncryptionKeys, |
332 &PushMessagingMessageFilter::DidGetEncryptionKeys, | 315 weak_factory_io_to_io_.GetWeakPtr(), callback, |
333 weak_factory_io_to_io_.GetWeakPtr(), data, push_registration_id); | 316 data, push_registration_id); |
334 BrowserThread::PostTask( | 317 BrowserThread::PostTask( |
335 BrowserThread::UI, FROM_HERE, | 318 BrowserThread::UI, FROM_HERE, |
336 base::Bind(&Core::GetEncryptionInfoOnUI, | 319 base::Bind(&Core::GetEncryptionInfoOnUI, |
337 base::Unretained(ui_core_.get()), data.requesting_origin, | 320 base::Unretained(ui_core_.get()), data.requesting_origin, |
338 data.service_worker_registration_id, fixed_sender_id, | 321 data.service_worker_registration_id, fixed_sender_id, |
339 callback)); | 322 callback_ui)); |
340 return; | 323 return; |
341 } | 324 } |
342 // TODO(johnme): The spec allows the register algorithm to reject with an | 325 // TODO(johnme): The spec allows the register algorithm to reject with an |
343 // AbortError when accessing storage fails. Perhaps we should do that if | 326 // AbortError when accessing storage fails. Perhaps we should do that if |
344 // service_worker_status != SERVICE_WORKER_ERROR_NOT_FOUND instead of | 327 // service_worker_status != SERVICE_WORKER_ERROR_NOT_FOUND instead of |
345 // attempting to do a fresh registration? | 328 // attempting to do a fresh registration? |
346 // https://w3c.github.io/push-api/#widl-PushRegistrationManager-register-Promi se-PushRegistration | 329 // https://w3c.github.io/push-api/#widl-PushRegistrationManager-register-Promi se-PushRegistration |
347 if (!data.options.sender_info.empty()) { | 330 if (!data.options.sender_info.empty()) { |
348 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 331 BrowserThread::PostTask( |
349 base::Bind(&Core::RegisterOnUI, | 332 BrowserThread::UI, FROM_HERE, |
350 base::Unretained(ui_core_.get()), data)); | 333 base::Bind(&Core::RegisterOnUI, base::Unretained(ui_core_.get()), |
334 callback, data)); | |
351 } else { | 335 } else { |
352 // There is no existing registration and the sender_info passed in was | 336 // There is no existing registration and the sender_info passed in was |
353 // empty, but perhaps there is a stored sender id we can use. | 337 // empty, but perhaps there is a stored sender id we can use. |
354 service_worker_context_->GetRegistrationUserData( | 338 service_worker_context_->GetRegistrationUserData( |
355 data.service_worker_registration_id, {kPushSenderIdServiceWorkerKey}, | 339 data.service_worker_registration_id, {kPushSenderIdServiceWorkerKey}, |
356 base::Bind(&PushMessagingMessageFilter::DidGetSenderIdFromStorage, | 340 base::Bind(&PushMessagingManager::DidGetSenderIdFromStorage, |
357 weak_factory_io_to_io_.GetWeakPtr(), data)); | 341 weak_factory_io_to_io_.GetWeakPtr(), callback, data)); |
358 } | 342 } |
359 } | 343 } |
360 | 344 |
361 void PushMessagingMessageFilter::DidGetEncryptionKeys( | 345 void PushMessagingManager::DidGetEncryptionKeys( |
346 const SubscribeCallback& callback, | |
362 const RegisterData& data, | 347 const RegisterData& data, |
363 const std::string& push_registration_id, | 348 const std::string& push_registration_id, |
364 bool success, | 349 bool success, |
365 const std::vector<uint8_t>& p256dh, | 350 const std::vector<uint8_t>& p256dh, |
366 const std::vector<uint8_t>& auth) { | 351 const std::vector<uint8_t>& auth) { |
367 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 352 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
368 if (!success) { | 353 if (!success) { |
369 SendSubscriptionError( | 354 SendSubscriptionError(callback, data, |
370 data, PUSH_REGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE); | 355 PUSH_REGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE); |
371 return; | 356 return; |
372 } | 357 } |
373 | 358 |
374 SendSubscriptionSuccess(data, PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE, | 359 SendSubscriptionSuccess(callback, data, |
360 PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE, | |
375 push_registration_id, p256dh, auth); | 361 push_registration_id, p256dh, auth); |
376 } | 362 } |
377 | 363 |
378 void PushMessagingMessageFilter::DidGetSenderIdFromStorage( | 364 void PushMessagingManager::DidGetSenderIdFromStorage( |
365 const SubscribeCallback& callback, | |
379 const RegisterData& data, | 366 const RegisterData& data, |
380 const std::vector<std::string>& stored_sender_id, | 367 const std::vector<std::string>& stored_sender_id, |
381 ServiceWorkerStatusCode service_worker_status) { | 368 ServiceWorkerStatusCode service_worker_status) { |
382 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 369 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
383 if (service_worker_status != SERVICE_WORKER_OK) { | 370 if (service_worker_status != SERVICE_WORKER_OK) { |
384 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 371 SendSubscriptionError(callback, data, |
372 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | |
385 return; | 373 return; |
386 } | 374 } |
387 DCHECK_EQ(1u, stored_sender_id.size()); | 375 DCHECK_EQ(1u, stored_sender_id.size()); |
388 // We should only be here because no sender info was supplied to subscribe(). | 376 // We should only be here because no sender info was supplied to subscribe(). |
389 DCHECK(data.options.sender_info.empty()); | 377 DCHECK(data.options.sender_info.empty()); |
390 std::string fixed_sender_id = | 378 std::string fixed_sender_id = |
391 FixSenderInfo(data.options.sender_info, stored_sender_id[0]); | 379 FixSenderInfo(data.options.sender_info, stored_sender_id[0]); |
392 if (fixed_sender_id.empty()) { | 380 if (fixed_sender_id.empty()) { |
393 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 381 SendSubscriptionError(callback, data, |
382 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | |
394 return; | 383 return; |
395 } | 384 } |
396 RegisterData mutated_data = data; | 385 RegisterData mutated_data = data; |
397 mutated_data.options.sender_info = fixed_sender_id; | 386 mutated_data.options.sender_info = fixed_sender_id; |
398 BrowserThread::PostTask( | 387 BrowserThread::PostTask( |
399 BrowserThread::UI, FROM_HERE, | 388 BrowserThread::UI, FROM_HERE, |
400 base::Bind(&Core::RegisterOnUI, base::Unretained(ui_core_.get()), | 389 base::Bind(&Core::RegisterOnUI, base::Unretained(ui_core_.get()), |
401 mutated_data)); | 390 callback, mutated_data)); |
402 } | 391 } |
403 | 392 |
404 void PushMessagingMessageFilter::Core::RegisterOnUI( | 393 void PushMessagingManager::Core::RegisterOnUI( |
405 const PushMessagingMessageFilter::RegisterData& data) { | 394 const SubscribeCallback& callback, |
395 const PushMessagingManager::RegisterData& data) { | |
406 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 396 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
407 PushMessagingService* push_service = service(); | 397 PushMessagingService* push_service = service(); |
408 if (!push_service) { | 398 if (!push_service) { |
409 if (!is_incognito()) { | 399 if (!is_incognito()) { |
410 // This might happen if InstanceIDProfileService::IsInstanceIDEnabled | 400 // This might happen if InstanceIDProfileService::IsInstanceIDEnabled |
411 // returns false because the Instance ID kill switch was enabled. | 401 // returns false because the Instance ID kill switch was enabled. |
412 // TODO(johnme): Might be better not to expose the API in this case. | 402 // TODO(johnme): Might be better not to expose the API in this case. |
413 BrowserThread::PostTask( | 403 BrowserThread::PostTask( |
414 BrowserThread::IO, FROM_HERE, | 404 BrowserThread::IO, FROM_HERE, |
415 base::Bind(&PushMessagingMessageFilter::SendSubscriptionError, | 405 base::Bind(&PushMessagingManager::SendSubscriptionError, io_parent_, |
416 io_parent_, | 406 callback, data, |
417 data, PUSH_REGISTRATION_STATUS_SERVICE_NOT_AVAILABLE)); | 407 PUSH_REGISTRATION_STATUS_SERVICE_NOT_AVAILABLE)); |
418 } else { | 408 } else { |
419 // Prevent websites from detecting incognito mode, by emulating what would | 409 // Prevent websites from detecting incognito mode, by emulating what would |
420 // have happened if we had a PushMessagingService available. | 410 // have happened if we had a PushMessagingService available. |
421 if (!data.FromDocument() || !data.options.user_visible_only) { | 411 if (!data.FromDocument() || !data.options.user_visible_only) { |
422 // Throw a permission denied error under the same circumstances. | 412 // Throw a permission denied error under the same circumstances. |
423 BrowserThread::PostTask( | 413 BrowserThread::PostTask( |
424 BrowserThread::IO, FROM_HERE, | 414 BrowserThread::IO, FROM_HERE, |
425 base::Bind(&PushMessagingMessageFilter::SendSubscriptionError, | 415 base::Bind(&PushMessagingManager::SendSubscriptionError, io_parent_, |
426 io_parent_, data, | 416 callback, data, |
427 PUSH_REGISTRATION_STATUS_INCOGNITO_PERMISSION_DENIED)); | 417 PUSH_REGISTRATION_STATUS_INCOGNITO_PERMISSION_DENIED)); |
428 } else { | 418 } else { |
429 RenderFrameHost* render_frame_host = | 419 RenderFrameHost* render_frame_host = |
430 RenderFrameHost::FromID(render_process_id_, data.render_frame_id); | 420 RenderFrameHost::FromID(render_process_id_, data.render_frame_id); |
431 WebContents* web_contents = | 421 WebContents* web_contents = |
432 WebContents::FromRenderFrameHost(render_frame_host); | 422 WebContents::FromRenderFrameHost(render_frame_host); |
433 if (web_contents) { | 423 if (web_contents) { |
434 web_contents->GetMainFrame()->AddMessageToConsole( | 424 web_contents->GetMainFrame()->AddMessageToConsole( |
435 CONSOLE_MESSAGE_LEVEL_ERROR, kIncognitoPushUnsupportedMessage); | 425 CONSOLE_MESSAGE_LEVEL_ERROR, kIncognitoPushUnsupportedMessage); |
436 // Request push messaging permission (which will fail, since | 426 // Request push messaging permission (which will fail, since |
437 // notifications aren't supported in incognito), so the website can't | 427 // notifications aren't supported in incognito), so the website can't |
438 // detect whether incognito is active. | 428 // detect whether incognito is active. |
439 web_contents->GetBrowserContext() | 429 web_contents->GetBrowserContext() |
440 ->GetPermissionManager() | 430 ->GetPermissionManager() |
441 ->RequestPermission( | 431 ->RequestPermission( |
442 PermissionType::PUSH_MESSAGING, render_frame_host, | 432 PermissionType::PUSH_MESSAGING, render_frame_host, |
443 data.requesting_origin, false /* user_gesture */, | 433 data.requesting_origin, false /* user_gesture */, |
444 base::Bind(&PushMessagingMessageFilter::Core:: | 434 base::Bind(&PushMessagingManager::Core:: |
445 DidRequestPermissionInIncognito, | 435 DidRequestPermissionInIncognito, |
446 weak_factory_ui_to_ui_.GetWeakPtr(), data)); | 436 weak_factory_ui_to_ui_.GetWeakPtr(), callback, |
437 data)); | |
447 } | 438 } |
448 } | 439 } |
449 } | 440 } |
450 return; | 441 return; |
451 } | 442 } |
452 | 443 |
453 if (data.FromDocument()) { | 444 if (data.FromDocument()) { |
454 push_service->SubscribeFromDocument( | 445 push_service->SubscribeFromDocument( |
455 data.requesting_origin, data.service_worker_registration_id, | 446 data.requesting_origin, data.service_worker_registration_id, |
456 render_process_id_, data.render_frame_id, data.options, | 447 render_process_id_, data.render_frame_id, data.options, |
457 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), | 448 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), |
458 data)); | 449 callback, data)); |
459 } else { | 450 } else { |
460 push_service->SubscribeFromWorker( | 451 push_service->SubscribeFromWorker( |
461 data.requesting_origin, data.service_worker_registration_id, | 452 data.requesting_origin, data.service_worker_registration_id, |
462 data.options, base::Bind(&Core::DidRegister, | 453 data.options, |
463 weak_factory_ui_to_ui_.GetWeakPtr(), data)); | 454 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), |
455 callback, data)); | |
464 } | 456 } |
465 } | 457 } |
466 | 458 |
467 void PushMessagingMessageFilter::Core::DidRequestPermissionInIncognito( | 459 void PushMessagingManager::Core::DidRequestPermissionInIncognito( |
460 const SubscribeCallback& callback, | |
468 const RegisterData& data, | 461 const RegisterData& data, |
469 blink::mojom::PermissionStatus status) { | 462 blink::mojom::PermissionStatus status) { |
470 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 463 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
471 // Notification permission should always be denied in incognito. | 464 // Notification permission should always be denied in incognito. |
472 DCHECK_EQ(blink::mojom::PermissionStatus::DENIED, status); | 465 DCHECK_EQ(blink::mojom::PermissionStatus::DENIED, status); |
473 BrowserThread::PostTask( | 466 BrowserThread::PostTask( |
474 BrowserThread::IO, FROM_HERE, | 467 BrowserThread::IO, FROM_HERE, |
475 base::Bind(&PushMessagingMessageFilter::SendSubscriptionError, io_parent_, | 468 base::Bind(&PushMessagingManager::SendSubscriptionError, io_parent_, |
476 data, PUSH_REGISTRATION_STATUS_INCOGNITO_PERMISSION_DENIED)); | 469 callback, data, |
470 PUSH_REGISTRATION_STATUS_INCOGNITO_PERMISSION_DENIED)); | |
477 } | 471 } |
478 | 472 |
479 void PushMessagingMessageFilter::Core::DidRegister( | 473 void PushMessagingManager::Core::DidRegister( |
474 const SubscribeCallback& callback, | |
480 const RegisterData& data, | 475 const RegisterData& data, |
481 const std::string& push_registration_id, | 476 const std::string& push_registration_id, |
482 const std::vector<uint8_t>& p256dh, | 477 const std::vector<uint8_t>& p256dh, |
483 const std::vector<uint8_t>& auth, | 478 const std::vector<uint8_t>& auth, |
484 PushRegistrationStatus status) { | 479 PushRegistrationStatus status) { |
485 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 480 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
486 if (status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE) { | 481 if (status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE) { |
487 BrowserThread::PostTask( | 482 BrowserThread::PostTask( |
488 BrowserThread::IO, FROM_HERE, | 483 BrowserThread::IO, FROM_HERE, |
489 base::Bind(&PushMessagingMessageFilter::PersistRegistrationOnIO, | 484 base::Bind(&PushMessagingManager::PersistRegistrationOnIO, io_parent_, |
490 io_parent_, data, push_registration_id, p256dh, auth)); | 485 callback, data, push_registration_id, p256dh, auth)); |
491 } else { | 486 } else { |
492 BrowserThread::PostTask( | 487 BrowserThread::PostTask( |
493 BrowserThread::IO, FROM_HERE, | 488 BrowserThread::IO, FROM_HERE, |
494 base::Bind(&PushMessagingMessageFilter::SendSubscriptionError, | 489 base::Bind(&PushMessagingManager::SendSubscriptionError, io_parent_, |
495 io_parent_, data, status)); | 490 callback, data, status)); |
496 } | 491 } |
497 } | 492 } |
498 | 493 |
499 void PushMessagingMessageFilter::PersistRegistrationOnIO( | 494 void PushMessagingManager::PersistRegistrationOnIO( |
495 const SubscribeCallback& callback, | |
500 const RegisterData& data, | 496 const RegisterData& data, |
501 const std::string& push_registration_id, | 497 const std::string& push_registration_id, |
502 const std::vector<uint8_t>& p256dh, | 498 const std::vector<uint8_t>& p256dh, |
503 const std::vector<uint8_t>& auth) { | 499 const std::vector<uint8_t>& auth) { |
504 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 500 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
505 service_worker_context_->StoreRegistrationUserData( | 501 service_worker_context_->StoreRegistrationUserData( |
506 data.service_worker_registration_id, data.requesting_origin, | 502 data.service_worker_registration_id, data.requesting_origin, |
507 {{kPushRegistrationIdServiceWorkerKey, push_registration_id}, | 503 {{kPushRegistrationIdServiceWorkerKey, push_registration_id}, |
508 {kPushSenderIdServiceWorkerKey, data.options.sender_info}}, | 504 {kPushSenderIdServiceWorkerKey, data.options.sender_info}}, |
509 base::Bind(&PushMessagingMessageFilter::DidPersistRegistrationOnIO, | 505 base::Bind(&PushMessagingManager::DidPersistRegistrationOnIO, |
510 weak_factory_io_to_io_.GetWeakPtr(), data, | 506 weak_factory_io_to_io_.GetWeakPtr(), callback, data, |
511 push_registration_id, p256dh, auth)); | 507 push_registration_id, p256dh, auth)); |
512 } | 508 } |
513 | 509 |
514 void PushMessagingMessageFilter::DidPersistRegistrationOnIO( | 510 void PushMessagingManager::DidPersistRegistrationOnIO( |
511 const SubscribeCallback& callback, | |
515 const RegisterData& data, | 512 const RegisterData& data, |
516 const std::string& push_registration_id, | 513 const std::string& push_registration_id, |
517 const std::vector<uint8_t>& p256dh, | 514 const std::vector<uint8_t>& p256dh, |
518 const std::vector<uint8_t>& auth, | 515 const std::vector<uint8_t>& auth, |
519 ServiceWorkerStatusCode service_worker_status) { | 516 ServiceWorkerStatusCode service_worker_status) { |
520 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 517 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
521 if (service_worker_status == SERVICE_WORKER_OK) { | 518 if (service_worker_status == SERVICE_WORKER_OK) { |
522 SendSubscriptionSuccess(data, | 519 SendSubscriptionSuccess(callback, data, |
523 PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE, | 520 PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE, |
524 push_registration_id, p256dh, auth); | 521 push_registration_id, p256dh, auth); |
525 } else { | 522 } else { |
526 // TODO(johnme): Unregister, so PushMessagingServiceImpl can decrease count. | 523 // TODO(johnme): Unregister, so PushMessagingServiceImpl can decrease count. |
527 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_STORAGE_ERROR); | 524 SendSubscriptionError(callback, data, |
525 PUSH_REGISTRATION_STATUS_STORAGE_ERROR); | |
528 } | 526 } |
529 } | 527 } |
530 | 528 |
531 void PushMessagingMessageFilter::SendSubscriptionError( | 529 void PushMessagingManager::SendSubscriptionError( |
532 const RegisterData& data, PushRegistrationStatus status) { | 530 const SubscribeCallback& callback, |
531 const RegisterData& data, | |
532 PushRegistrationStatus status) { | |
533 // Only called from IO thread, but would be safe to call from UI thread. | 533 // Only called from IO thread, but would be safe to call from UI thread. |
534 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 534 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
535 if (data.FromDocument()) { | 535 callback.Run(status, base::nullopt /* endpoint */, |
536 Send(new PushMessagingMsg_SubscribeFromDocumentError( | 536 base::nullopt /* options */, base::nullopt /* p256dh */, |
537 data.render_frame_id, data.request_id, status)); | 537 base::nullopt /* auth */); |
538 } else { | |
539 Send( | |
540 new PushMessagingMsg_SubscribeFromWorkerError(data.request_id, status)); | |
541 } | |
542 RecordRegistrationStatus(status); | 538 RecordRegistrationStatus(status); |
543 } | 539 } |
544 | 540 |
545 void PushMessagingMessageFilter::SendSubscriptionSuccess( | 541 void PushMessagingManager::SendSubscriptionSuccess( |
542 const SubscribeCallback& callback, | |
546 const RegisterData& data, | 543 const RegisterData& data, |
547 PushRegistrationStatus status, | 544 PushRegistrationStatus status, |
548 const std::string& push_subscription_id, | 545 const std::string& push_subscription_id, |
549 const std::vector<uint8_t>& p256dh, | 546 const std::vector<uint8_t>& p256dh, |
550 const std::vector<uint8_t>& auth) { | 547 const std::vector<uint8_t>& auth) { |
551 // Only called from IO thread, but would be safe to call from UI thread. | 548 // Only called from IO thread, but would be safe to call from UI thread. |
552 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 549 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
553 if (!service_available_) { | 550 if (!service_available_) { |
554 // This shouldn't be possible in incognito mode, since we've already checked | 551 // This shouldn't be possible in incognito mode, since we've already checked |
555 // that we have an existing registration. Hence it's ok to throw an error. | 552 // that we have an existing registration. Hence it's ok to throw an error. |
556 DCHECK(!ui_core_->is_incognito()); | 553 DCHECK(!ui_core_->is_incognito()); |
557 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_SERVICE_NOT_AVAILABLE); | 554 SendSubscriptionError(callback, data, |
555 PUSH_REGISTRATION_STATUS_SERVICE_NOT_AVAILABLE); | |
558 return; | 556 return; |
559 } | 557 } |
560 | 558 |
561 const GURL endpoint = CreateEndpoint( | 559 const GURL endpoint = CreateEndpoint( |
562 IsApplicationServerKey(data.options.sender_info), push_subscription_id); | 560 IsApplicationServerKey(data.options.sender_info), push_subscription_id); |
563 | 561 |
564 if (data.FromDocument()) { | 562 callback.Run(status, endpoint, data.options, p256dh, auth); |
565 Send(new PushMessagingMsg_SubscribeFromDocumentSuccess( | 563 |
566 data.render_frame_id, data.request_id, endpoint, data.options, p256dh, | |
567 auth)); | |
568 } else { | |
569 Send(new PushMessagingMsg_SubscribeFromWorkerSuccess( | |
570 data.request_id, endpoint, data.options, p256dh, auth)); | |
571 } | |
572 RecordRegistrationStatus(status); | 564 RecordRegistrationStatus(status); |
573 } | 565 } |
574 | 566 |
575 // Unsubscribe methods on both IO and UI threads, merged in order of use from | 567 // Unsubscribe methods on both IO and UI threads, merged in order of use from |
576 // PushMessagingMessageFilter and Core. | 568 // PushMessagingManager and Core. |
577 // ----------------------------------------------------------------------------- | 569 // ----------------------------------------------------------------------------- |
578 | 570 |
579 void PushMessagingMessageFilter::OnUnsubscribe( | 571 void PushMessagingManager::Unsubscribe(int64_t service_worker_registration_id, |
580 int request_id, int64_t service_worker_registration_id) { | 572 const UnsubscribeCallback& callback) { |
581 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 573 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
582 ServiceWorkerRegistration* service_worker_registration = | 574 ServiceWorkerRegistration* service_worker_registration = |
583 service_worker_context_->GetLiveRegistration( | 575 service_worker_context_->GetLiveRegistration( |
584 service_worker_registration_id); | 576 service_worker_registration_id); |
585 if (!service_worker_registration) { | 577 if (!service_worker_registration) { |
586 DidUnregister(request_id, PUSH_UNREGISTRATION_STATUS_NO_SERVICE_WORKER); | 578 DidUnregister(callback, PUSH_UNREGISTRATION_STATUS_NO_SERVICE_WORKER); |
587 return; | 579 return; |
588 } | 580 } |
589 | 581 |
590 service_worker_context_->GetRegistrationUserData( | 582 service_worker_context_->GetRegistrationUserData( |
591 service_worker_registration_id, {kPushSenderIdServiceWorkerKey}, | 583 service_worker_registration_id, {kPushSenderIdServiceWorkerKey}, |
592 base::Bind(&PushMessagingMessageFilter::UnsubscribeHavingGottenSenderId, | 584 base::Bind(&PushMessagingManager::UnsubscribeHavingGottenSenderId, |
593 weak_factory_io_to_io_.GetWeakPtr(), request_id, | 585 weak_factory_io_to_io_.GetWeakPtr(), callback, |
594 service_worker_registration_id, | 586 service_worker_registration_id, |
595 service_worker_registration->pattern().GetOrigin())); | 587 service_worker_registration->pattern().GetOrigin())); |
596 } | 588 } |
597 | 589 |
598 void PushMessagingMessageFilter::UnsubscribeHavingGottenSenderId( | 590 void PushMessagingManager::UnsubscribeHavingGottenSenderId( |
599 int request_id, | 591 const UnsubscribeCallback& callback, |
600 int64_t service_worker_registration_id, | 592 int64_t service_worker_registration_id, |
601 const GURL& requesting_origin, | 593 const GURL& requesting_origin, |
602 const std::vector<std::string>& sender_ids, | 594 const std::vector<std::string>& sender_ids, |
603 ServiceWorkerStatusCode service_worker_status) { | 595 ServiceWorkerStatusCode service_worker_status) { |
604 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 596 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
605 | 597 |
606 std::string sender_id; | 598 std::string sender_id; |
607 if (service_worker_status == SERVICE_WORKER_OK) { | 599 if (service_worker_status == SERVICE_WORKER_OK) { |
608 DCHECK_EQ(1u, sender_ids.size()); | 600 DCHECK_EQ(1u, sender_ids.size()); |
609 sender_id = sender_ids[0]; | 601 sender_id = sender_ids[0]; |
610 } | 602 } |
611 BrowserThread::PostTask( | 603 BrowserThread::PostTask( |
612 BrowserThread::UI, FROM_HERE, | 604 BrowserThread::UI, FROM_HERE, |
613 base::Bind(&Core::UnregisterFromService, base::Unretained(ui_core_.get()), | 605 base::Bind(&Core::UnregisterFromService, base::Unretained(ui_core_.get()), |
614 request_id, service_worker_registration_id, requesting_origin, | 606 callback, service_worker_registration_id, requesting_origin, |
615 sender_id)); | 607 sender_id)); |
616 } | 608 } |
617 | 609 |
618 void PushMessagingMessageFilter::Core::UnregisterFromService( | 610 void PushMessagingManager::Core::UnregisterFromService( |
619 int request_id, | 611 const UnsubscribeCallback& callback, |
620 int64_t service_worker_registration_id, | 612 int64_t service_worker_registration_id, |
621 const GURL& requesting_origin, | 613 const GURL& requesting_origin, |
622 const std::string& sender_id) { | 614 const std::string& sender_id) { |
623 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 615 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
624 PushMessagingService* push_service = service(); | 616 PushMessagingService* push_service = service(); |
625 if (!push_service) { | 617 if (!push_service) { |
626 // This shouldn't be possible in incognito mode, since we've already checked | 618 // This shouldn't be possible in incognito mode, since we've already checked |
627 // that we have an existing registration. Hence it's ok to throw an error. | 619 // that we have an existing registration. Hence it's ok to throw an error. |
628 DCHECK(!is_incognito()); | 620 DCHECK(!is_incognito()); |
629 BrowserThread::PostTask( | 621 BrowserThread::PostTask( |
630 BrowserThread::IO, FROM_HERE, | 622 BrowserThread::IO, FROM_HERE, |
631 base::Bind(&PushMessagingMessageFilter::DidUnregister, io_parent_, | 623 base::Bind(&PushMessagingManager::DidUnregister, io_parent_, callback, |
632 request_id, | |
633 PUSH_UNREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE)); | 624 PUSH_UNREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE)); |
634 return; | 625 return; |
635 } | 626 } |
636 | 627 |
637 push_service->Unsubscribe( | 628 push_service->Unsubscribe( |
638 requesting_origin, service_worker_registration_id, sender_id, | 629 requesting_origin, service_worker_registration_id, sender_id, |
639 base::Bind(&Core::DidUnregisterFromService, | 630 base::Bind(&Core::DidUnregisterFromService, |
640 weak_factory_ui_to_ui_.GetWeakPtr(), request_id, | 631 weak_factory_ui_to_ui_.GetWeakPtr(), callback, |
641 service_worker_registration_id)); | 632 service_worker_registration_id)); |
642 } | 633 } |
643 | 634 |
644 void PushMessagingMessageFilter::Core::DidUnregisterFromService( | 635 void PushMessagingManager::Core::DidUnregisterFromService( |
645 int request_id, | 636 const UnsubscribeCallback& callback, |
646 int64_t service_worker_registration_id, | 637 int64_t service_worker_registration_id, |
647 PushUnregistrationStatus unregistration_status) { | 638 PushUnregistrationStatus unregistration_status) { |
648 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 639 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
649 | 640 |
650 BrowserThread::PostTask( | 641 BrowserThread::PostTask( |
651 BrowserThread::IO, FROM_HERE, | 642 BrowserThread::IO, FROM_HERE, |
652 base::Bind(&PushMessagingMessageFilter::DidUnregister, io_parent_, | 643 base::Bind(&PushMessagingManager::DidUnregister, io_parent_, callback, |
653 request_id, unregistration_status)); | 644 unregistration_status)); |
654 } | 645 } |
655 | 646 |
656 void PushMessagingMessageFilter::DidUnregister( | 647 void PushMessagingManager::DidUnregister( |
657 int request_id, | 648 const UnsubscribeCallback& callback, |
658 PushUnregistrationStatus unregistration_status) { | 649 PushUnregistrationStatus unregistration_status) { |
659 // Only called from IO thread, but would be safe to call from UI thread. | 650 // Only called from IO thread, but would be safe to call from UI thread. |
660 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 651 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
661 switch (unregistration_status) { | 652 switch (unregistration_status) { |
662 case PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED: | 653 case PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTERED: |
663 case PUSH_UNREGISTRATION_STATUS_PENDING_NETWORK_ERROR: | 654 case PUSH_UNREGISTRATION_STATUS_PENDING_NETWORK_ERROR: |
664 case PUSH_UNREGISTRATION_STATUS_PENDING_SERVICE_ERROR: | 655 case PUSH_UNREGISTRATION_STATUS_PENDING_SERVICE_ERROR: |
665 Send(new PushMessagingMsg_UnsubscribeSuccess(request_id, true)); | 656 callback.Run(true /* success */, true /* did_unsubscribe */, |
657 blink::WebPushError::ErrorTypeUnknown, | |
658 base::nullopt /* error_message */); | |
666 break; | 659 break; |
667 case PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED: | 660 case PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED: |
668 Send(new PushMessagingMsg_UnsubscribeSuccess(request_id, false)); | 661 callback.Run(true /* success */, false /* did_unsubscribe */, |
662 blink::WebPushError::ErrorTypeUnknown, | |
663 base::nullopt /* error_message */); | |
669 break; | 664 break; |
670 case PUSH_UNREGISTRATION_STATUS_NO_SERVICE_WORKER: | 665 case PUSH_UNREGISTRATION_STATUS_NO_SERVICE_WORKER: |
671 case PUSH_UNREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE: | 666 case PUSH_UNREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE: |
672 case PUSH_UNREGISTRATION_STATUS_STORAGE_ERROR: | 667 case PUSH_UNREGISTRATION_STATUS_STORAGE_ERROR: |
673 Send(new PushMessagingMsg_UnsubscribeError( | 668 callback.Run( |
674 request_id, blink::WebPushError::ErrorTypeAbort, | 669 false /* error */, false, blink::WebPushError::ErrorTypeAbort, |
675 PushUnregistrationStatusToString(unregistration_status))); | 670 std::string(PushUnregistrationStatusToString(unregistration_status))); |
676 break; | 671 break; |
677 case PUSH_UNREGISTRATION_STATUS_NETWORK_ERROR: | 672 case PUSH_UNREGISTRATION_STATUS_NETWORK_ERROR: |
678 NOTREACHED(); | 673 NOTREACHED(); |
679 break; | 674 break; |
680 } | 675 } |
681 RecordUnregistrationStatus(unregistration_status); | 676 RecordUnregistrationStatus(unregistration_status); |
682 } | 677 } |
683 | 678 |
684 // GetSubscription methods on both IO and UI threads, merged in order of use | 679 // GetSubscription methods on both IO and UI threads, merged in order of use |
685 // from PushMessagingMessageFilter and Core. | 680 // from PushMessagingManager and Core. |
686 // ----------------------------------------------------------------------------- | 681 // ----------------------------------------------------------------------------- |
687 | 682 |
688 void PushMessagingMessageFilter::OnGetSubscription( | 683 void PushMessagingManager::GetSubscription( |
689 int request_id, | 684 int64_t service_worker_registration_id, |
690 int64_t service_worker_registration_id) { | 685 const GetSubscriptionCallback& callback) { |
691 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 686 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
692 // TODO(johnme): Validate arguments? | 687 // TODO(johnme): Validate arguments? |
693 service_worker_context_->GetRegistrationUserData( | 688 service_worker_context_->GetRegistrationUserData( |
694 service_worker_registration_id, | 689 service_worker_registration_id, |
695 {kPushRegistrationIdServiceWorkerKey, kPushSenderIdServiceWorkerKey}, | 690 {kPushRegistrationIdServiceWorkerKey, kPushSenderIdServiceWorkerKey}, |
696 base::Bind(&PushMessagingMessageFilter::DidGetSubscription, | 691 base::Bind(&PushMessagingManager::DidGetSubscription, |
697 weak_factory_io_to_io_.GetWeakPtr(), request_id, | 692 weak_factory_io_to_io_.GetWeakPtr(), callback, |
698 service_worker_registration_id)); | 693 service_worker_registration_id)); |
699 } | 694 } |
700 | 695 |
701 void PushMessagingMessageFilter::DidGetSubscription( | 696 void PushMessagingManager::DidGetSubscription( |
702 int request_id, | 697 const GetSubscriptionCallback& callback, |
703 int64_t service_worker_registration_id, | 698 int64_t service_worker_registration_id, |
704 const std::vector<std::string>& push_subscription_id_and_sender_info, | 699 const std::vector<std::string>& push_subscription_id_and_sender_info, |
705 ServiceWorkerStatusCode service_worker_status) { | 700 ServiceWorkerStatusCode service_worker_status) { |
706 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 701 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
707 PushGetRegistrationStatus get_status = | 702 PushGetRegistrationStatus get_status = |
708 PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; | 703 PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; |
709 switch (service_worker_status) { | 704 switch (service_worker_status) { |
710 case SERVICE_WORKER_OK: { | 705 case SERVICE_WORKER_OK: { |
711 DCHECK_EQ(2u, push_subscription_id_and_sender_info.size()); | 706 DCHECK_EQ(2u, push_subscription_id_and_sender_info.size()); |
712 | 707 |
713 if (!service_available_) { | 708 if (!service_available_) { |
714 // Return not found in incognito mode, so websites can't detect it. | 709 // Return not found in incognito mode, so websites can't detect it. |
715 get_status = | 710 get_status = |
716 ui_core_->is_incognito() | 711 ui_core_->is_incognito() |
717 ? PUSH_GETREGISTRATION_STATUS_INCOGNITO_REGISTRATION_NOT_FOUND | 712 ? PUSH_GETREGISTRATION_STATUS_INCOGNITO_REGISTRATION_NOT_FOUND |
718 : PUSH_GETREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE; | 713 : PUSH_GETREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE; |
719 break; | 714 break; |
720 } | 715 } |
721 | 716 |
722 ServiceWorkerRegistration* registration = | 717 ServiceWorkerRegistration* registration = |
723 service_worker_context_->GetLiveRegistration( | 718 service_worker_context_->GetLiveRegistration( |
724 service_worker_registration_id); | 719 service_worker_registration_id); |
725 const GURL origin = registration->pattern().GetOrigin(); | 720 const GURL origin = registration->pattern().GetOrigin(); |
726 | 721 |
727 const bool uses_standard_protocol = | 722 const bool uses_standard_protocol = |
728 IsApplicationServerKey(push_subscription_id_and_sender_info[1]); | 723 IsApplicationServerKey(push_subscription_id_and_sender_info[1]); |
729 const GURL endpoint = CreateEndpoint( | 724 const GURL endpoint = CreateEndpoint( |
730 uses_standard_protocol, push_subscription_id_and_sender_info[0]); | 725 uses_standard_protocol, push_subscription_id_and_sender_info[0]); |
731 | 726 |
732 auto callback = | 727 auto callback_ui = |
733 base::Bind(&PushMessagingMessageFilter::DidGetSubscriptionKeys, | 728 base::Bind(&PushMessagingManager::DidGetSubscriptionKeys, |
734 weak_factory_io_to_io_.GetWeakPtr(), request_id, endpoint, | 729 weak_factory_io_to_io_.GetWeakPtr(), callback, endpoint, |
735 push_subscription_id_and_sender_info[1]); | 730 push_subscription_id_and_sender_info[1]); |
736 | 731 |
737 BrowserThread::PostTask( | 732 BrowserThread::PostTask( |
738 BrowserThread::UI, FROM_HERE, | 733 BrowserThread::UI, FROM_HERE, |
739 base::Bind(&Core::GetEncryptionInfoOnUI, | 734 base::Bind(&Core::GetEncryptionInfoOnUI, |
740 base::Unretained(ui_core_.get()), origin, | 735 base::Unretained(ui_core_.get()), origin, |
741 service_worker_registration_id, | 736 service_worker_registration_id, |
742 push_subscription_id_and_sender_info[1], callback)); | 737 push_subscription_id_and_sender_info[1], callback_ui)); |
743 | 738 |
744 return; | 739 return; |
745 } | 740 } |
746 case SERVICE_WORKER_ERROR_NOT_FOUND: { | 741 case SERVICE_WORKER_ERROR_NOT_FOUND: { |
747 get_status = PUSH_GETREGISTRATION_STATUS_REGISTRATION_NOT_FOUND; | 742 get_status = PUSH_GETREGISTRATION_STATUS_REGISTRATION_NOT_FOUND; |
748 break; | 743 break; |
749 } | 744 } |
750 case SERVICE_WORKER_ERROR_FAILED: { | 745 case SERVICE_WORKER_ERROR_FAILED: { |
751 get_status = PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; | 746 get_status = PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; |
752 break; | 747 break; |
(...skipping 14 matching lines...) Expand all Loading... | |
767 case SERVICE_WORKER_ERROR_DISK_CACHE: | 762 case SERVICE_WORKER_ERROR_DISK_CACHE: |
768 case SERVICE_WORKER_ERROR_REDUNDANT: | 763 case SERVICE_WORKER_ERROR_REDUNDANT: |
769 case SERVICE_WORKER_ERROR_DISALLOWED: | 764 case SERVICE_WORKER_ERROR_DISALLOWED: |
770 case SERVICE_WORKER_ERROR_MAX_VALUE: { | 765 case SERVICE_WORKER_ERROR_MAX_VALUE: { |
771 NOTREACHED() << "Got unexpected error code: " << service_worker_status | 766 NOTREACHED() << "Got unexpected error code: " << service_worker_status |
772 << " " << ServiceWorkerStatusToString(service_worker_status); | 767 << " " << ServiceWorkerStatusToString(service_worker_status); |
773 get_status = PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; | 768 get_status = PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; |
774 break; | 769 break; |
775 } | 770 } |
776 } | 771 } |
777 Send(new PushMessagingMsg_GetSubscriptionError(request_id, get_status)); | 772 callback.Run(get_status, base::nullopt /* endpoint */, |
773 base::nullopt /* options */, base::nullopt /* p256dh */, | |
774 base::nullopt /* auth */); | |
778 RecordGetRegistrationStatus(get_status); | 775 RecordGetRegistrationStatus(get_status); |
779 } | 776 } |
780 | 777 |
781 void PushMessagingMessageFilter::DidGetSubscriptionKeys( | 778 void PushMessagingManager::DidGetSubscriptionKeys( |
782 int request_id, | 779 const GetSubscriptionCallback& callback, |
783 const GURL& endpoint, | 780 const GURL& endpoint, |
784 const std::string& sender_info, | 781 const std::string& sender_info, |
785 bool success, | 782 bool success, |
786 const std::vector<uint8_t>& p256dh, | 783 const std::vector<uint8_t>& p256dh, |
787 const std::vector<uint8_t>& auth) { | 784 const std::vector<uint8_t>& auth) { |
788 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 785 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
789 if (!success) { | 786 if (!success) { |
790 PushGetRegistrationStatus status = | 787 PushGetRegistrationStatus status = |
791 PUSH_GETREGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE; | 788 PUSH_GETREGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE; |
792 | 789 |
793 Send(new PushMessagingMsg_GetSubscriptionError(request_id, status)); | 790 callback.Run(status, base::nullopt /* endpoint */, |
791 base::nullopt /* options */, base::nullopt /* p256dh */, | |
792 base::nullopt /* auth */); | |
794 | 793 |
795 RecordGetRegistrationStatus(status); | 794 RecordGetRegistrationStatus(status); |
796 return; | 795 return; |
797 } | 796 } |
798 | 797 |
799 PushSubscriptionOptions options; | 798 PushSubscriptionOptions options; |
800 // Chrome rejects subscription requests with userVisibleOnly false, so it must | 799 // Chrome rejects subscription requests with userVisibleOnly false, so it must |
801 // have been true. TODO(harkness): If Chrome starts accepting silent push | 800 // have been true. TODO(harkness): If Chrome starts accepting silent push |
802 // subscriptions with userVisibleOnly false, the bool will need to be stored. | 801 // subscriptions with userVisibleOnly false, the bool will need to be stored. |
803 options.user_visible_only = true; | 802 options.user_visible_only = true; |
804 options.sender_info = sender_info; | 803 options.sender_info = sender_info; |
805 | 804 |
806 Send(new PushMessagingMsg_GetSubscriptionSuccess(request_id, endpoint, | 805 callback.Run(PUSH_GETREGISTRATION_STATUS_SUCCESS, endpoint, options, p256dh, |
807 options, p256dh, auth)); | 806 auth); |
808 | 807 |
809 RecordGetRegistrationStatus(PUSH_GETREGISTRATION_STATUS_SUCCESS); | 808 RecordGetRegistrationStatus(PUSH_GETREGISTRATION_STATUS_SUCCESS); |
810 } | 809 } |
811 | 810 |
812 // GetPermission methods on both IO and UI threads, merged in order of use from | 811 // GetPermission methods on both IO and UI threads, merged in order of use from |
813 // PushMessagingMessageFilter and Core. | 812 // PushMessagingManager and Core. |
814 // ----------------------------------------------------------------------------- | 813 // ----------------------------------------------------------------------------- |
815 | 814 |
816 void PushMessagingMessageFilter::OnGetPermissionStatus( | 815 void PushMessagingManager::GetPermissionStatus( |
817 int request_id, | |
818 int64_t service_worker_registration_id, | 816 int64_t service_worker_registration_id, |
819 bool user_visible) { | 817 bool user_visible, |
818 const GetPermissionStatusCallback& callback) { | |
820 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 819 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
821 ServiceWorkerRegistration* service_worker_registration = | 820 ServiceWorkerRegistration* service_worker_registration = |
822 service_worker_context_->GetLiveRegistration( | 821 service_worker_context_->GetLiveRegistration( |
823 service_worker_registration_id); | 822 service_worker_registration_id); |
824 if (!service_worker_registration) { | 823 if (!service_worker_registration) { |
825 Send(new PushMessagingMsg_GetPermissionStatusError( | 824 callback.Run(false /* error */, blink::WebPushPermissionStatusDenied, |
826 request_id, blink::WebPushError::ErrorTypeAbort)); | 825 blink::WebPushError::ErrorTypeAbort); |
827 return; | 826 return; |
828 } | 827 } |
829 | 828 |
830 BrowserThread::PostTask( | 829 BrowserThread::PostTask( |
831 BrowserThread::UI, FROM_HERE, | 830 BrowserThread::UI, FROM_HERE, |
832 base::Bind(&Core::GetPermissionStatusOnUI, | 831 base::Bind(&Core::GetPermissionStatusOnUI, |
833 base::Unretained(ui_core_.get()), | 832 base::Unretained(ui_core_.get()), callback, |
834 service_worker_registration->pattern().GetOrigin(), | 833 service_worker_registration->pattern().GetOrigin(), |
835 user_visible, request_id)); | 834 user_visible)); |
836 } | 835 } |
837 | 836 |
838 void PushMessagingMessageFilter::Core::GetPermissionStatusOnUI( | 837 void PushMessagingManager::Core::GetPermissionStatusOnUI( |
839 const GURL& requesting_origin, bool user_visible, int request_id) { | 838 const GetPermissionStatusCallback& callback, |
839 const GURL& requesting_origin, | |
840 bool user_visible) { | |
840 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 841 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
841 blink::WebPushPermissionStatus permission_status; | 842 blink::WebPushPermissionStatus permission_status; |
842 PushMessagingService* push_service = service(); | 843 PushMessagingService* push_service = service(); |
843 if (push_service) { | 844 if (push_service) { |
844 if (!user_visible && !push_service->SupportNonVisibleMessages()) { | 845 if (!user_visible && !push_service->SupportNonVisibleMessages()) { |
845 Send(new PushMessagingMsg_GetPermissionStatusError( | 846 BrowserThread::PostTask( |
846 request_id, blink::WebPushError::ErrorTypeNotSupported)); | 847 BrowserThread::IO, FROM_HERE, |
848 base::Bind(callback, false /* error */, | |
849 blink::WebPushPermissionStatusDenied, | |
850 blink::WebPushError::ErrorTypeNotSupported)); | |
847 return; | 851 return; |
848 } | 852 } |
849 permission_status = | 853 permission_status = |
850 push_service->GetPermissionStatus(requesting_origin, user_visible); | 854 push_service->GetPermissionStatus(requesting_origin, user_visible); |
851 } else if (is_incognito()) { | 855 } else if (is_incognito()) { |
852 // Return prompt, so the website can't detect incognito mode. | 856 // Return prompt, so the website can't detect incognito mode. |
853 permission_status = blink::WebPushPermissionStatusPrompt; | 857 permission_status = blink::WebPushPermissionStatusPrompt; |
854 } else { | 858 } else { |
855 Send(new PushMessagingMsg_GetPermissionStatusError( | 859 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
856 request_id, blink::WebPushError::ErrorTypeAbort)); | 860 base::Bind(callback, false /* error */, |
861 blink::WebPushPermissionStatusDenied, | |
862 blink::WebPushError::ErrorTypeAbort)); | |
857 return; | 863 return; |
858 } | 864 } |
859 Send(new PushMessagingMsg_GetPermissionStatusSuccess(request_id, | 865 BrowserThread::PostTask( |
860 permission_status)); | 866 BrowserThread::IO, FROM_HERE, |
867 base::Bind(callback, true /* success */, permission_status, | |
868 blink::WebPushError::ErrorTypeUnknown)); | |
Peter Beverloo
2017/02/16 16:08:32
Something to consider for follow-ups: a blink::Web
ke.he
2017/02/17 08:22:28
tracked by 693366
| |
861 } | 869 } |
862 | 870 |
863 // Helper methods on both IO and UI threads, merged from | 871 // Helper methods on both IO and UI threads, merged from |
864 // PushMessagingMessageFilter and Core. | 872 // PushMessagingManager and Core. |
865 // ----------------------------------------------------------------------------- | 873 // ----------------------------------------------------------------------------- |
866 | 874 |
867 void PushMessagingMessageFilter::Core::GetEncryptionInfoOnUI( | 875 void PushMessagingManager::Core::GetEncryptionInfoOnUI( |
868 const GURL& origin, | 876 const GURL& origin, |
869 int64_t service_worker_registration_id, | 877 int64_t service_worker_registration_id, |
870 const std::string& sender_id, | 878 const std::string& sender_id, |
871 const PushMessagingService::EncryptionInfoCallback& io_thread_callback) { | 879 const PushMessagingService::EncryptionInfoCallback& io_thread_callback) { |
872 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 880 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
873 PushMessagingService* push_service = service(); | 881 PushMessagingService* push_service = service(); |
874 if (push_service) { | 882 if (push_service) { |
875 push_service->GetEncryptionInfo( | 883 push_service->GetEncryptionInfo( |
876 origin, service_worker_registration_id, sender_id, | 884 origin, service_worker_registration_id, sender_id, |
877 base::Bind(&ForwardEncryptionInfoToIOThreadProxy, io_thread_callback)); | 885 base::Bind(&ForwardEncryptionInfoToIOThreadProxy, io_thread_callback)); |
878 return; | 886 return; |
879 } | 887 } |
880 | 888 |
881 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 889 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
882 base::Bind(io_thread_callback, false /* success */, | 890 base::Bind(io_thread_callback, false /* success */, |
883 std::vector<uint8_t>() /* p256dh */, | 891 std::vector<uint8_t>() /* p256dh */, |
884 std::vector<uint8_t>() /* auth */)); | 892 std::vector<uint8_t>() /* auth */)); |
885 } | 893 } |
886 | 894 |
887 void PushMessagingMessageFilter::Core::Send(IPC::Message* message) { | 895 GURL PushMessagingManager::CreateEndpoint( |
888 BrowserThread::PostTask( | |
889 BrowserThread::IO, FROM_HERE, | |
890 base::Bind(&PushMessagingMessageFilter::SendIPC, io_parent_, | |
891 base::Passed(base::WrapUnique(message)))); | |
892 } | |
893 | |
894 void PushMessagingMessageFilter::SendIPC( | |
895 std::unique_ptr<IPC::Message> message) { | |
896 Send(message.release()); | |
897 } | |
898 | |
899 GURL PushMessagingMessageFilter::CreateEndpoint( | |
900 bool standard_protocol, | 896 bool standard_protocol, |
901 const std::string& subscription_id) const { | 897 const std::string& subscription_id) const { |
902 const GURL& base = | 898 const GURL& base = |
903 standard_protocol ? web_push_protocol_endpoint_ : default_endpoint_; | 899 standard_protocol ? web_push_protocol_endpoint_ : default_endpoint_; |
904 | 900 |
905 return GURL(base.spec() + subscription_id); | 901 return GURL(base.spec() + subscription_id); |
906 } | 902 } |
907 | 903 |
908 PushMessagingService* PushMessagingMessageFilter::Core::service() { | 904 PushMessagingService* PushMessagingManager::Core::service() { |
909 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 905 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
910 RenderProcessHost* process_host = | 906 RenderProcessHost* process_host = |
911 RenderProcessHost::FromID(render_process_id_); | 907 RenderProcessHost::FromID(render_process_id_); |
912 return process_host | 908 return process_host |
913 ? process_host->GetBrowserContext()->GetPushMessagingService() | 909 ? process_host->GetBrowserContext()->GetPushMessagingService() |
914 : nullptr; | 910 : nullptr; |
915 } | 911 } |
916 | 912 |
917 } // namespace content | 913 } // namespace content |
OLD | NEW |