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/browser/push_messaging/push_messaging_message_filter.h" | 5 #include "content/browser/push_messaging/push_messaging_message_filter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 PUSH_UNREGISTRATION_STATUS_LAST + 1); | 57 PUSH_UNREGISTRATION_STATUS_LAST + 1); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void RecordGetRegistrationStatus(PushGetRegistrationStatus status) { | 60 void RecordGetRegistrationStatus(PushGetRegistrationStatus status) { |
| 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 62 UMA_HISTOGRAM_ENUMERATION("PushMessaging.GetRegistrationStatus", | 62 UMA_HISTOGRAM_ENUMERATION("PushMessaging.GetRegistrationStatus", |
| 63 status, | 63 status, |
| 64 PUSH_GETREGISTRATION_STATUS_LAST + 1); | 64 PUSH_GETREGISTRATION_STATUS_LAST + 1); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Curries the |success| and |curve25519dh| parameters over to |callback| and | |
| 68 // posts a task to invoke |callback| on the IO thread. | |
| 69 void ForwardPublicEncryptionKeysToIOThreadProxy( | |
|
johnme
2015/07/09 16:02:53
It's a bit unusual that Core::GetPublicEncryptionK
Peter Beverloo
2015/07/09 18:54:17
All the Record*Status have DCHECKS to be on the IO
| |
| 70 const PushMessagingService::PublicKeyCallback& callback, | |
| 71 bool success, | |
| 72 const std::vector<uint8_t>& curve25519dh) { | |
| 73 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 74 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 75 base::Bind(callback, success, curve25519dh)); | |
| 76 } | |
| 77 | |
| 67 // Concatenates the subscription id with the endpoint base to create a new | 78 // Concatenates the subscription id with the endpoint base to create a new |
| 68 // GURL object containing the endpoint unique to the subscription. | 79 // GURL object containing the endpoint unique to the subscription. |
| 69 GURL CreatePushEndpoint(const GURL& push_endpoint_base, | 80 GURL CreatePushEndpoint(const GURL& push_endpoint_base, |
| 70 const std::string& push_subscription_id) { | 81 const std::string& push_subscription_id) { |
| 71 return GURL(push_endpoint_base.spec() + "/" + push_subscription_id); | 82 return GURL(push_endpoint_base.spec() + "/" + push_subscription_id); |
| 72 } | 83 } |
| 73 | 84 |
| 74 } // namespace | 85 } // namespace |
| 75 | 86 |
| 76 struct PushMessagingMessageFilter::RegisterData { | 87 struct PushMessagingMessageFilter::RegisterData { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 90 class PushMessagingMessageFilter::Core { | 101 class PushMessagingMessageFilter::Core { |
| 91 public: | 102 public: |
| 92 Core(const base::WeakPtr<PushMessagingMessageFilter>& io_parent, | 103 Core(const base::WeakPtr<PushMessagingMessageFilter>& io_parent, |
| 93 int render_process_id); | 104 int render_process_id); |
| 94 | 105 |
| 95 // Public Register methods on UI thread -------------------------------------- | 106 // Public Register methods on UI thread -------------------------------------- |
| 96 | 107 |
| 97 // Called via PostTask from IO thread. | 108 // Called via PostTask from IO thread. |
| 98 void RegisterOnUI(const RegisterData& data, const std::string& sender_id); | 109 void RegisterOnUI(const RegisterData& data, const std::string& sender_id); |
| 99 | 110 |
| 111 // Called via PostTask from IO thread. | |
| 112 void GetPublicEncryptionKeyOnUI( | |
|
johnme
2015/07/09 16:02:53
Please move this to the "Public helper methods on
Peter Beverloo
2015/07/09 18:54:17
Done.
| |
| 113 const GURL& origin, | |
| 114 int64_t service_worker_registration_id, | |
| 115 const PushMessagingService::PublicKeyCallback& callback); | |
| 116 | |
| 100 // Public Unregister methods on UI thread ------------------------------------ | 117 // Public Unregister methods on UI thread ------------------------------------ |
| 101 | 118 |
| 102 // Called via PostTask from IO thread. | 119 // Called via PostTask from IO thread. |
| 103 void UnregisterFromService(int request_id, | 120 void UnregisterFromService(int request_id, |
| 104 int64_t service_worker_registration_id, | 121 int64_t service_worker_registration_id, |
| 105 const GURL& requesting_origin, | 122 const GURL& requesting_origin, |
| 106 const std::string& sender_id); | 123 const std::string& sender_id); |
| 107 | 124 |
| 108 // Public GetPermission methods on UI thread --------------------------------- | 125 // Public GetPermission methods on UI thread --------------------------------- |
| 109 | 126 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 123 private: | 140 private: |
| 124 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 141 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 125 friend class base::DeleteHelper<Core>; | 142 friend class base::DeleteHelper<Core>; |
| 126 | 143 |
| 127 ~Core(); | 144 ~Core(); |
| 128 | 145 |
| 129 // Private Register methods on UI thread ------------------------------------- | 146 // Private Register methods on UI thread ------------------------------------- |
| 130 | 147 |
| 131 void DidRegister(const RegisterData& data, | 148 void DidRegister(const RegisterData& data, |
| 132 const std::string& push_registration_id, | 149 const std::string& push_registration_id, |
| 150 const std::vector<uint8_t>& curve25519dh, | |
| 133 PushRegistrationStatus status); | 151 PushRegistrationStatus status); |
| 134 | 152 |
| 135 // Private Unregister methods on UI thread ----------------------------------- | 153 // Private Unregister methods on UI thread ----------------------------------- |
| 136 | 154 |
| 137 void DidUnregisterFromService(int request_id, | 155 void DidUnregisterFromService(int request_id, |
| 138 int64_t service_worker_registration_id, | 156 int64_t service_worker_registration_id, |
| 139 PushUnregistrationStatus unregistration_status); | 157 PushUnregistrationStatus unregistration_status); |
| 140 | 158 |
| 141 // Private helper methods on UI thread --------------------------------------- | 159 // Private helper methods on UI thread --------------------------------------- |
| 142 | 160 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 weak_factory_io_to_io_.GetWeakPtr(), data, sender_id)); | 323 weak_factory_io_to_io_.GetWeakPtr(), data, sender_id)); |
| 306 } | 324 } |
| 307 | 325 |
| 308 void PushMessagingMessageFilter::DidCheckForExistingRegistration( | 326 void PushMessagingMessageFilter::DidCheckForExistingRegistration( |
| 309 const RegisterData& data, | 327 const RegisterData& data, |
| 310 const std::string& sender_id, | 328 const std::string& sender_id, |
| 311 const std::string& push_registration_id, | 329 const std::string& push_registration_id, |
| 312 ServiceWorkerStatusCode service_worker_status) { | 330 ServiceWorkerStatusCode service_worker_status) { |
| 313 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 331 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 314 if (service_worker_status == SERVICE_WORKER_OK) { | 332 if (service_worker_status == SERVICE_WORKER_OK) { |
| 315 SendRegisterSuccess(data, PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE, | 333 auto callback = |
| 316 push_registration_id); | 334 base::Bind(&PushMessagingMessageFilter::DidGetEncryptionKeys, |
| 335 weak_factory_io_to_io_.GetWeakPtr(), data, | |
| 336 push_registration_id); | |
| 337 | |
| 338 BrowserThread::PostTask( | |
| 339 BrowserThread::UI, FROM_HERE, | |
| 340 base::Bind(&Core::GetPublicEncryptionKeyOnUI, | |
| 341 base::Unretained(ui_core_.get()), data.requesting_origin, | |
| 342 data.service_worker_registration_id, callback)); | |
| 317 return; | 343 return; |
| 318 } | 344 } |
| 319 // TODO(johnme): The spec allows the register algorithm to reject with an | 345 // TODO(johnme): The spec allows the register algorithm to reject with an |
| 320 // AbortError when accessing storage fails. Perhaps we should do that if | 346 // AbortError when accessing storage fails. Perhaps we should do that if |
| 321 // service_worker_status != SERVICE_WORKER_ERROR_NOT_FOUND instead of | 347 // service_worker_status != SERVICE_WORKER_ERROR_NOT_FOUND instead of |
| 322 // attempting to do a fresh registration? | 348 // attempting to do a fresh registration? |
| 323 // https://w3c.github.io/push-api/#widl-PushRegistrationManager-register-Promi se-PushRegistration | 349 // https://w3c.github.io/push-api/#widl-PushRegistrationManager-register-Promi se-PushRegistration |
| 324 if (data.FromDocument()) { | 350 if (data.FromDocument()) { |
| 325 BrowserThread::PostTask( | 351 BrowserThread::PostTask( |
| 326 BrowserThread::UI, FROM_HERE, | 352 BrowserThread::UI, FROM_HERE, |
| 327 base::Bind(&Core::RegisterOnUI, base::Unretained(ui_core_.get()), | 353 base::Bind(&Core::RegisterOnUI, base::Unretained(ui_core_.get()), |
| 328 data, sender_id)); | 354 data, sender_id)); |
| 329 } else { | 355 } else { |
| 330 service_worker_context_->GetRegistrationUserData( | 356 service_worker_context_->GetRegistrationUserData( |
| 331 data.service_worker_registration_id, | 357 data.service_worker_registration_id, |
| 332 kPushSenderIdServiceWorkerKey, | 358 kPushSenderIdServiceWorkerKey, |
| 333 base::Bind(&PushMessagingMessageFilter::DidGetSenderIdFromStorage, | 359 base::Bind(&PushMessagingMessageFilter::DidGetSenderIdFromStorage, |
| 334 weak_factory_io_to_io_.GetWeakPtr(), data)); | 360 weak_factory_io_to_io_.GetWeakPtr(), data)); |
| 335 } | 361 } |
| 336 } | 362 } |
| 337 | 363 |
| 364 void PushMessagingMessageFilter::Core::GetPublicEncryptionKeyOnUI( | |
|
johnme
2015/07/09 16:02:53
Similarly, please move this to the "Helper methods
Peter Beverloo
2015/07/09 18:54:17
Done.
| |
| 365 const GURL& origin, | |
| 366 int64_t service_worker_registration_id, | |
| 367 const PushMessagingService::PublicKeyCallback& callback) { | |
| 368 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 369 PushMessagingService* push_service = service(); | |
| 370 if (push_service) { | |
| 371 push_service->GetPublicEncryptionKey( | |
| 372 origin, service_worker_registration_id, | |
| 373 base::Bind(&ForwardPublicEncryptionKeysToIOThreadProxy, callback)); | |
| 374 return; | |
| 375 } | |
| 376 | |
| 377 BrowserThread::PostTask( | |
| 378 BrowserThread::IO, FROM_HERE, | |
| 379 base::Bind(callback, false /* success */, std::vector<uint8_t>())); | |
| 380 } | |
| 381 | |
| 382 void PushMessagingMessageFilter::DidGetEncryptionKeys( | |
| 383 const RegisterData& data, | |
| 384 const std::string& push_registration_id, | |
| 385 bool success, | |
| 386 const std::vector<uint8_t>& curve25519dh) { | |
| 387 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 388 if (!success) { | |
| 389 SendRegisterError(data, PUSH_REGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE); | |
| 390 return; | |
| 391 } | |
| 392 | |
| 393 SendRegisterSuccess(data, PUSH_REGISTRATION_STATUS_SUCCESS_FROM_CACHE, | |
| 394 push_registration_id, curve25519dh); | |
| 395 } | |
| 396 | |
| 338 void PushMessagingMessageFilter::DidGetSenderIdFromStorage( | 397 void PushMessagingMessageFilter::DidGetSenderIdFromStorage( |
| 339 const RegisterData& data, | 398 const RegisterData& data, |
| 340 const std::string& sender_id, | 399 const std::string& sender_id, |
| 341 ServiceWorkerStatusCode service_worker_status) { | 400 ServiceWorkerStatusCode service_worker_status) { |
| 342 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 401 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 343 if (service_worker_status != SERVICE_WORKER_OK) { | 402 if (service_worker_status != SERVICE_WORKER_OK) { |
| 344 SendRegisterError(data, PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 403 SendRegisterError(data, PUSH_REGISTRATION_STATUS_NO_SENDER_ID); |
| 345 return; | 404 return; |
| 346 } | 405 } |
| 347 BrowserThread::PostTask( | 406 BrowserThread::PostTask( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 data.requesting_origin, data.service_worker_registration_id, sender_id, | 461 data.requesting_origin, data.service_worker_registration_id, sender_id, |
| 403 data.user_visible, | 462 data.user_visible, |
| 404 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), | 463 base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(), |
| 405 data)); | 464 data)); |
| 406 } | 465 } |
| 407 } | 466 } |
| 408 | 467 |
| 409 void PushMessagingMessageFilter::Core::DidRegister( | 468 void PushMessagingMessageFilter::Core::DidRegister( |
| 410 const RegisterData& data, | 469 const RegisterData& data, |
| 411 const std::string& push_registration_id, | 470 const std::string& push_registration_id, |
| 471 const std::vector<uint8_t>& curve25519dh, | |
| 412 PushRegistrationStatus status) { | 472 PushRegistrationStatus status) { |
| 413 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 473 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 414 if (status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE) { | 474 if (status == PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE) { |
| 415 BrowserThread::PostTask( | 475 BrowserThread::PostTask( |
| 416 BrowserThread::IO, FROM_HERE, | 476 BrowserThread::IO, FROM_HERE, |
| 417 base::Bind(&PushMessagingMessageFilter::PersistRegistrationOnIO, | 477 base::Bind(&PushMessagingMessageFilter::PersistRegistrationOnIO, |
| 418 io_parent_, data, push_registration_id)); | 478 io_parent_, data, push_registration_id, curve25519dh)); |
| 419 } else { | 479 } else { |
| 420 BrowserThread::PostTask( | 480 BrowserThread::PostTask( |
| 421 BrowserThread::IO, FROM_HERE, | 481 BrowserThread::IO, FROM_HERE, |
| 422 base::Bind(&PushMessagingMessageFilter::SendRegisterError, io_parent_, | 482 base::Bind(&PushMessagingMessageFilter::SendRegisterError, io_parent_, |
| 423 data, status)); | 483 data, status)); |
| 424 } | 484 } |
| 425 } | 485 } |
| 426 | 486 |
| 427 void PushMessagingMessageFilter::PersistRegistrationOnIO( | 487 void PushMessagingMessageFilter::PersistRegistrationOnIO( |
| 428 const RegisterData& data, | 488 const RegisterData& data, |
| 429 const std::string& push_registration_id) { | 489 const std::string& push_registration_id, |
| 490 const std::vector<uint8_t>& curve25519dh) { | |
| 430 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 491 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 431 service_worker_context_->StoreRegistrationUserData( | 492 service_worker_context_->StoreRegistrationUserData( |
| 432 data.service_worker_registration_id, | 493 data.service_worker_registration_id, |
| 433 data.requesting_origin, | 494 data.requesting_origin, |
| 434 kPushRegistrationIdServiceWorkerKey, | 495 kPushRegistrationIdServiceWorkerKey, |
| 435 push_registration_id, | 496 push_registration_id, |
| 436 base::Bind(&PushMessagingMessageFilter::DidPersistRegistrationOnIO, | 497 base::Bind(&PushMessagingMessageFilter::DidPersistRegistrationOnIO, |
| 437 weak_factory_io_to_io_.GetWeakPtr(), | 498 weak_factory_io_to_io_.GetWeakPtr(), |
| 438 data, push_registration_id)); | 499 data, push_registration_id, curve25519dh)); |
| 439 } | 500 } |
| 440 | 501 |
| 441 void PushMessagingMessageFilter::DidPersistRegistrationOnIO( | 502 void PushMessagingMessageFilter::DidPersistRegistrationOnIO( |
| 442 const RegisterData& data, | 503 const RegisterData& data, |
| 443 const std::string& push_registration_id, | 504 const std::string& push_registration_id, |
| 505 const std::vector<uint8_t>& curve25519dh, | |
| 444 ServiceWorkerStatusCode service_worker_status) { | 506 ServiceWorkerStatusCode service_worker_status) { |
| 445 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 507 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 446 if (service_worker_status == SERVICE_WORKER_OK) { | 508 if (service_worker_status == SERVICE_WORKER_OK) { |
| 447 SendRegisterSuccess(data, | 509 SendRegisterSuccess(data, |
| 448 PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE, | 510 PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE, |
| 449 push_registration_id); | 511 push_registration_id, curve25519dh); |
| 450 } else { | 512 } else { |
| 451 // TODO(johnme): Unregister, so PushMessagingServiceImpl can decrease count. | 513 // TODO(johnme): Unregister, so PushMessagingServiceImpl can decrease count. |
| 452 SendRegisterError(data, PUSH_REGISTRATION_STATUS_STORAGE_ERROR); | 514 SendRegisterError(data, PUSH_REGISTRATION_STATUS_STORAGE_ERROR); |
| 453 } | 515 } |
| 454 } | 516 } |
| 455 | 517 |
| 456 void PushMessagingMessageFilter::SendRegisterError( | 518 void PushMessagingMessageFilter::SendRegisterError( |
| 457 const RegisterData& data, PushRegistrationStatus status) { | 519 const RegisterData& data, PushRegistrationStatus status) { |
| 458 // Only called from IO thread, but would be safe to call from UI thread. | 520 // Only called from IO thread, but would be safe to call from UI thread. |
| 459 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 521 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 460 if (data.FromDocument()) { | 522 if (data.FromDocument()) { |
| 461 Send(new PushMessagingMsg_SubscribeFromDocumentError( | 523 Send(new PushMessagingMsg_SubscribeFromDocumentError( |
| 462 data.render_frame_id, data.request_id, status)); | 524 data.render_frame_id, data.request_id, status)); |
| 463 } else { | 525 } else { |
| 464 Send(new PushMessagingMsg_SubscribeFromWorkerError( | 526 Send(new PushMessagingMsg_SubscribeFromWorkerError( |
| 465 data.request_id, status)); | 527 data.request_id, status)); |
| 466 } | 528 } |
| 467 RecordRegistrationStatus(status); | 529 RecordRegistrationStatus(status); |
| 468 } | 530 } |
| 469 | 531 |
| 470 void PushMessagingMessageFilter::SendRegisterSuccess( | 532 void PushMessagingMessageFilter::SendRegisterSuccess( |
| 471 const RegisterData& data, | 533 const RegisterData& data, |
| 472 PushRegistrationStatus status, | 534 PushRegistrationStatus status, |
| 473 const std::string& push_registration_id) { | 535 const std::string& push_registration_id, |
| 536 const std::vector<uint8_t>& curve25519dh) { | |
| 474 // Only called from IO thread, but would be safe to call from UI thread. | 537 // Only called from IO thread, but would be safe to call from UI thread. |
| 475 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 538 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 476 if (push_endpoint_base_.is_empty()) { | 539 if (push_endpoint_base_.is_empty()) { |
| 477 // This shouldn't be possible in incognito mode, since we've already checked | 540 // This shouldn't be possible in incognito mode, since we've already checked |
| 478 // that we have an existing registration. Hence it's ok to throw an error. | 541 // that we have an existing registration. Hence it's ok to throw an error. |
| 479 DCHECK(!ui_core_->is_incognito()); | 542 DCHECK(!ui_core_->is_incognito()); |
| 480 SendRegisterError(data, PUSH_REGISTRATION_STATUS_SERVICE_NOT_AVAILABLE); | 543 SendRegisterError(data, PUSH_REGISTRATION_STATUS_SERVICE_NOT_AVAILABLE); |
| 481 return; | 544 return; |
| 482 } | 545 } |
| 483 if (data.FromDocument()) { | 546 if (data.FromDocument()) { |
| 484 Send(new PushMessagingMsg_SubscribeFromDocumentSuccess( | 547 Send(new PushMessagingMsg_SubscribeFromDocumentSuccess( |
| 485 data.render_frame_id, | 548 data.render_frame_id, |
| 486 data.request_id, | 549 data.request_id, |
| 487 CreatePushEndpoint(push_endpoint_base_, push_registration_id))); | 550 CreatePushEndpoint(push_endpoint_base_, push_registration_id), |
| 551 curve25519dh)); | |
| 488 } else { | 552 } else { |
| 489 Send(new PushMessagingMsg_SubscribeFromWorkerSuccess( | 553 Send(new PushMessagingMsg_SubscribeFromWorkerSuccess( |
| 490 data.request_id, | 554 data.request_id, |
| 491 CreatePushEndpoint(push_endpoint_base_, push_registration_id))); | 555 CreatePushEndpoint(push_endpoint_base_, push_registration_id), |
| 556 curve25519dh)); | |
| 492 } | 557 } |
| 493 RecordRegistrationStatus(status); | 558 RecordRegistrationStatus(status); |
| 494 } | 559 } |
| 495 | 560 |
| 496 // Unsubscribe methods on both IO and UI threads, merged in order of use from | 561 // Unsubscribe methods on both IO and UI threads, merged in order of use from |
| 497 // PushMessagingMessageFilter and Core. | 562 // PushMessagingMessageFilter and Core. |
| 498 // ----------------------------------------------------------------------------- | 563 // ----------------------------------------------------------------------------- |
| 499 | 564 |
| 500 void PushMessagingMessageFilter::OnUnsubscribe( | 565 void PushMessagingMessageFilter::OnUnsubscribe( |
| 501 int request_id, int64_t service_worker_registration_id) { | 566 int request_id, int64_t service_worker_registration_id) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 705 } | 770 } |
| 706 RecordUnregistrationStatus(unregistration_status); | 771 RecordUnregistrationStatus(unregistration_status); |
| 707 } | 772 } |
| 708 | 773 |
| 709 // GetRegistration methods on both IO and UI threads, merged in order of use | 774 // GetRegistration methods on both IO and UI threads, merged in order of use |
| 710 // from PushMessagingMessageFilter and Core. | 775 // from PushMessagingMessageFilter and Core. |
| 711 // ----------------------------------------------------------------------------- | 776 // ----------------------------------------------------------------------------- |
| 712 | 777 |
| 713 void PushMessagingMessageFilter::OnGetRegistration( | 778 void PushMessagingMessageFilter::OnGetRegistration( |
| 714 int request_id, | 779 int request_id, |
| 780 const GURL& origin, | |
| 715 int64_t service_worker_registration_id) { | 781 int64_t service_worker_registration_id) { |
| 716 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 782 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 717 // TODO(johnme): Validate arguments? | 783 // TODO(johnme): Validate arguments? |
| 718 service_worker_context_->GetRegistrationUserData( | 784 service_worker_context_->GetRegistrationUserData( |
| 719 service_worker_registration_id, | 785 service_worker_registration_id, |
| 720 kPushRegistrationIdServiceWorkerKey, | 786 kPushRegistrationIdServiceWorkerKey, |
| 721 base::Bind(&PushMessagingMessageFilter::DidGetRegistration, | 787 base::Bind(&PushMessagingMessageFilter::DidGetRegistration, |
| 722 weak_factory_io_to_io_.GetWeakPtr(), request_id)); | 788 weak_factory_io_to_io_.GetWeakPtr(), request_id, origin, |
| 789 service_worker_registration_id)); | |
| 723 } | 790 } |
| 724 | 791 |
| 725 void PushMessagingMessageFilter::DidGetRegistration( | 792 void PushMessagingMessageFilter::DidGetRegistration( |
| 726 int request_id, | 793 int request_id, |
| 794 const GURL& origin, | |
| 795 int64_t service_worker_registration_id, | |
| 727 const std::string& push_registration_id, | 796 const std::string& push_registration_id, |
| 728 ServiceWorkerStatusCode service_worker_status) { | 797 ServiceWorkerStatusCode service_worker_status) { |
| 729 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 798 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 730 PushGetRegistrationStatus get_status = | 799 PushGetRegistrationStatus get_status = |
| 731 PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; | 800 PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; |
| 732 switch (service_worker_status) { | 801 switch (service_worker_status) { |
| 733 case SERVICE_WORKER_OK: | 802 case SERVICE_WORKER_OK: { |
| 734 if (push_endpoint_base_.is_empty()) { | 803 if (push_endpoint_base_.is_empty()) { |
| 735 // Return not found in incognito mode, so websites can't detect it. | 804 // Return not found in incognito mode, so websites can't detect it. |
| 736 get_status = | 805 get_status = |
| 737 ui_core_->is_incognito() | 806 ui_core_->is_incognito() |
| 738 ? PUSH_GETREGISTRATION_STATUS_INCOGNITO_REGISTRATION_NOT_FOUND | 807 ? PUSH_GETREGISTRATION_STATUS_INCOGNITO_REGISTRATION_NOT_FOUND |
| 739 : PUSH_GETREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE; | 808 : PUSH_GETREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE; |
| 740 break; | 809 break; |
| 741 } | 810 } |
| 742 | 811 |
| 743 Send(new PushMessagingMsg_GetRegistrationSuccess( | 812 const GURL endpoint = |
| 744 request_id, | 813 CreatePushEndpoint(push_endpoint_base_, push_registration_id); |
| 745 CreatePushEndpoint(push_endpoint_base_, push_registration_id))); | 814 |
| 746 RecordGetRegistrationStatus(PUSH_GETREGISTRATION_STATUS_SUCCESS); | 815 auto callback = |
| 816 base::Bind(&PushMessagingMessageFilter::DidGetRegistrationKeys, | |
| 817 weak_factory_io_to_io_.GetWeakPtr(), request_id, endpoint); | |
| 818 | |
| 819 BrowserThread::PostTask( | |
| 820 BrowserThread::UI, FROM_HERE, | |
| 821 base::Bind(&Core::GetPublicEncryptionKeyOnUI, | |
| 822 base::Unretained(ui_core_.get()), origin, | |
| 823 service_worker_registration_id, callback)); | |
| 824 | |
| 747 return; | 825 return; |
| 748 case SERVICE_WORKER_ERROR_NOT_FOUND: | 826 } |
| 827 case SERVICE_WORKER_ERROR_NOT_FOUND: { | |
| 749 get_status = PUSH_GETREGISTRATION_STATUS_REGISTRATION_NOT_FOUND; | 828 get_status = PUSH_GETREGISTRATION_STATUS_REGISTRATION_NOT_FOUND; |
| 750 break; | 829 break; |
| 751 case SERVICE_WORKER_ERROR_FAILED: | 830 } |
| 831 case SERVICE_WORKER_ERROR_FAILED: { | |
| 752 get_status = PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; | 832 get_status = PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; |
| 753 break; | 833 break; |
| 834 } | |
| 754 case SERVICE_WORKER_ERROR_ABORT: | 835 case SERVICE_WORKER_ERROR_ABORT: |
| 755 case SERVICE_WORKER_ERROR_START_WORKER_FAILED: | 836 case SERVICE_WORKER_ERROR_START_WORKER_FAILED: |
| 756 case SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND: | 837 case SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND: |
| 757 case SERVICE_WORKER_ERROR_EXISTS: | 838 case SERVICE_WORKER_ERROR_EXISTS: |
| 758 case SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED: | 839 case SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED: |
| 759 case SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED: | 840 case SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED: |
| 760 case SERVICE_WORKER_ERROR_IPC_FAILED: | 841 case SERVICE_WORKER_ERROR_IPC_FAILED: |
| 761 case SERVICE_WORKER_ERROR_NETWORK: | 842 case SERVICE_WORKER_ERROR_NETWORK: |
| 762 case SERVICE_WORKER_ERROR_SECURITY: | 843 case SERVICE_WORKER_ERROR_SECURITY: |
| 763 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED: | 844 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED: |
| 764 case SERVICE_WORKER_ERROR_STATE: | 845 case SERVICE_WORKER_ERROR_STATE: |
| 765 case SERVICE_WORKER_ERROR_TIMEOUT: | 846 case SERVICE_WORKER_ERROR_TIMEOUT: |
| 766 case SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED: | 847 case SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED: |
| 767 case SERVICE_WORKER_ERROR_DISK_CACHE: | 848 case SERVICE_WORKER_ERROR_DISK_CACHE: |
| 768 case SERVICE_WORKER_ERROR_REDUNDANT: | 849 case SERVICE_WORKER_ERROR_REDUNDANT: |
| 769 case SERVICE_WORKER_ERROR_MAX_VALUE: | 850 case SERVICE_WORKER_ERROR_MAX_VALUE: { |
| 770 NOTREACHED() << "Got unexpected error code: " << service_worker_status | 851 NOTREACHED() << "Got unexpected error code: " << service_worker_status |
| 771 << " " << ServiceWorkerStatusToString(service_worker_status); | 852 << " " << ServiceWorkerStatusToString(service_worker_status); |
| 772 get_status = PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; | 853 get_status = PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; |
| 773 break; | 854 break; |
| 855 } | |
| 774 } | 856 } |
| 775 Send(new PushMessagingMsg_GetRegistrationError(request_id, get_status)); | 857 Send(new PushMessagingMsg_GetRegistrationError(request_id, get_status)); |
| 776 RecordGetRegistrationStatus(get_status); | 858 RecordGetRegistrationStatus(get_status); |
| 777 } | 859 } |
| 778 | 860 |
| 861 void PushMessagingMessageFilter::DidGetRegistrationKeys( | |
|
johnme
2015/07/09 16:02:53
Please add a DCHECK_CURRENTLY_ON.
Peter Beverloo
2015/07/09 18:54:17
Done.
| |
| 862 int request_id, | |
| 863 const GURL& endpoint, | |
| 864 bool success, | |
| 865 const std::vector<uint8_t>& curve25519dh) { | |
| 866 if (!success) { | |
| 867 PushGetRegistrationStatus status = | |
| 868 PUSH_GETREGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE; | |
| 869 | |
| 870 Send(new PushMessagingMsg_GetRegistrationError(request_id, status)); | |
| 871 | |
| 872 RecordGetRegistrationStatus(status); | |
| 873 return; | |
| 874 } | |
| 875 | |
| 876 Send(new PushMessagingMsg_GetRegistrationSuccess(request_id, endpoint, | |
| 877 curve25519dh)); | |
| 878 | |
| 879 RecordGetRegistrationStatus(PUSH_GETREGISTRATION_STATUS_SUCCESS); | |
| 880 } | |
| 881 | |
| 779 // GetPermission methods on both IO and UI threads, merged in order of use from | 882 // GetPermission methods on both IO and UI threads, merged in order of use from |
| 780 // PushMessagingMessageFilter and Core. | 883 // PushMessagingMessageFilter and Core. |
| 781 // ----------------------------------------------------------------------------- | 884 // ----------------------------------------------------------------------------- |
| 782 | 885 |
| 783 void PushMessagingMessageFilter::OnGetPermissionStatus( | 886 void PushMessagingMessageFilter::OnGetPermissionStatus( |
| 784 int request_id, | 887 int request_id, |
| 785 int64_t service_worker_registration_id, | 888 int64_t service_worker_registration_id, |
| 786 bool user_visible) { | 889 bool user_visible) { |
| 787 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 890 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 788 ServiceWorkerRegistration* service_worker_registration = | 891 ServiceWorkerRegistration* service_worker_registration = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 847 PushMessagingService* PushMessagingMessageFilter::Core::service() { | 950 PushMessagingService* PushMessagingMessageFilter::Core::service() { |
| 848 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 951 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 849 RenderProcessHost* process_host = | 952 RenderProcessHost* process_host = |
| 850 RenderProcessHost::FromID(render_process_id_); | 953 RenderProcessHost::FromID(render_process_id_); |
| 851 return process_host | 954 return process_host |
| 852 ? process_host->GetBrowserContext()->GetPushMessagingService() | 955 ? process_host->GetBrowserContext()->GetPushMessagingService() |
| 853 : nullptr; | 956 : nullptr; |
| 854 } | 957 } |
| 855 | 958 |
| 856 } // namespace content | 959 } // namespace content |
| OLD | NEW |