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

Side by Side Diff: content/browser/push_messaging/push_messaging_message_filter.cc

Issue 2133673002: Push API: Implement and ship PushSubscription.options (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 DCHECK(!ui_core_->is_incognito()); 512 DCHECK(!ui_core_->is_incognito());
513 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_SERVICE_NOT_AVAILABLE); 513 SendSubscriptionError(data, PUSH_REGISTRATION_STATUS_SERVICE_NOT_AVAILABLE);
514 return; 514 return;
515 } 515 }
516 516
517 const GURL endpoint = CreateEndpoint( 517 const GURL endpoint = CreateEndpoint(
518 IsApplicationServerKey(data.options.sender_info), push_subscription_id); 518 IsApplicationServerKey(data.options.sender_info), push_subscription_id);
519 519
520 if (data.FromDocument()) { 520 if (data.FromDocument()) {
521 Send(new PushMessagingMsg_SubscribeFromDocumentSuccess( 521 Send(new PushMessagingMsg_SubscribeFromDocumentSuccess(
522 data.render_frame_id, data.request_id, endpoint, p256dh, auth)); 522 data.render_frame_id, data.request_id, endpoint, data.options, p256dh,
523 auth));
523 } else { 524 } else {
524 Send(new PushMessagingMsg_SubscribeFromWorkerSuccess( 525 Send(new PushMessagingMsg_SubscribeFromWorkerSuccess(
525 data.request_id, endpoint, p256dh, auth)); 526 data.request_id, endpoint, data.options, p256dh, auth));
526 } 527 }
527 RecordRegistrationStatus(status); 528 RecordRegistrationStatus(status);
528 } 529 }
529 530
530 // Unsubscribe methods on both IO and UI threads, merged in order of use from 531 // Unsubscribe methods on both IO and UI threads, merged in order of use from
531 // PushMessagingMessageFilter and Core. 532 // PushMessagingMessageFilter and Core.
532 // ----------------------------------------------------------------------------- 533 // -----------------------------------------------------------------------------
533 534
534 void PushMessagingMessageFilter::OnUnsubscribe( 535 void PushMessagingMessageFilter::OnUnsubscribe(
535 int request_id, int64_t service_worker_registration_id) { 536 int request_id, int64_t service_worker_registration_id) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 // GetSubscription methods on both IO and UI threads, merged in order of use 718 // GetSubscription methods on both IO and UI threads, merged in order of use
718 // from PushMessagingMessageFilter and Core. 719 // from PushMessagingMessageFilter and Core.
719 // ----------------------------------------------------------------------------- 720 // -----------------------------------------------------------------------------
720 721
721 void PushMessagingMessageFilter::OnGetSubscription( 722 void PushMessagingMessageFilter::OnGetSubscription(
722 int request_id, 723 int request_id,
723 int64_t service_worker_registration_id) { 724 int64_t service_worker_registration_id) {
724 DCHECK_CURRENTLY_ON(BrowserThread::IO); 725 DCHECK_CURRENTLY_ON(BrowserThread::IO);
725 // TODO(johnme): Validate arguments? 726 // TODO(johnme): Validate arguments?
726 service_worker_context_->GetRegistrationUserData( 727 service_worker_context_->GetRegistrationUserData(
727 service_worker_registration_id, {kPushSenderIdServiceWorkerKey}, 728 service_worker_registration_id,
728 base::Bind(&PushMessagingMessageFilter::DidGetSenderInfo, 729 {kPushRegistrationIdServiceWorkerKey, kPushSenderIdServiceWorkerKey},
730 base::Bind(&PushMessagingMessageFilter::DidGetSubscription,
729 weak_factory_io_to_io_.GetWeakPtr(), request_id, 731 weak_factory_io_to_io_.GetWeakPtr(), request_id,
730 service_worker_registration_id)); 732 service_worker_registration_id));
731 } 733 }
732 734
733 void PushMessagingMessageFilter::DidGetSenderInfo(
734 int request_id,
735 int64_t service_worker_registration_id,
736 const std::vector<std::string>& sender_info,
737 ServiceWorkerStatusCode status) {
738 DCHECK_CURRENTLY_ON(BrowserThread::IO);
739 if (status != SERVICE_WORKER_OK || sender_info.size() != 1) {
740 DidGetSubscription(request_id, service_worker_registration_id,
741 false /* uses_standard_protocol */,
742 std::vector<std::string>() /* push_subscription_id */,
743 status);
744 return;
745 }
746
747 const bool uses_standard_protocol = IsApplicationServerKey(sender_info[0]);
748 service_worker_context_->GetRegistrationUserData(
749 service_worker_registration_id, {kPushRegistrationIdServiceWorkerKey},
750 base::Bind(&PushMessagingMessageFilter::DidGetSubscription,
751 weak_factory_io_to_io_.GetWeakPtr(), request_id,
752 service_worker_registration_id, uses_standard_protocol));
753 }
754
755 void PushMessagingMessageFilter::DidGetSubscription( 735 void PushMessagingMessageFilter::DidGetSubscription(
756 int request_id, 736 int request_id,
757 int64_t service_worker_registration_id, 737 int64_t service_worker_registration_id,
758 bool uses_standard_protocol, 738 const std::vector<std::string>& push_subscription_id_and_sender_info,
759 const std::vector<std::string>& push_subscription_id,
760 ServiceWorkerStatusCode service_worker_status) { 739 ServiceWorkerStatusCode service_worker_status) {
761 DCHECK_CURRENTLY_ON(BrowserThread::IO); 740 DCHECK_CURRENTLY_ON(BrowserThread::IO);
762 PushGetRegistrationStatus get_status = 741 PushGetRegistrationStatus get_status =
763 PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR; 742 PUSH_GETREGISTRATION_STATUS_STORAGE_ERROR;
764 switch (service_worker_status) { 743 switch (service_worker_status) {
765 case SERVICE_WORKER_OK: { 744 case SERVICE_WORKER_OK: {
745 DCHECK_EQ(2u, push_subscription_id_and_sender_info.size());
746
766 if (!service_available_) { 747 if (!service_available_) {
767 // Return not found in incognito mode, so websites can't detect it. 748 // Return not found in incognito mode, so websites can't detect it.
768 get_status = 749 get_status =
769 ui_core_->is_incognito() 750 ui_core_->is_incognito()
770 ? PUSH_GETREGISTRATION_STATUS_INCOGNITO_REGISTRATION_NOT_FOUND 751 ? PUSH_GETREGISTRATION_STATUS_INCOGNITO_REGISTRATION_NOT_FOUND
771 : PUSH_GETREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE; 752 : PUSH_GETREGISTRATION_STATUS_SERVICE_NOT_AVAILABLE;
772 break; 753 break;
773 } 754 }
774 755
775 ServiceWorkerRegistration* registration = 756 ServiceWorkerRegistration* registration =
776 service_worker_context_->GetLiveRegistration( 757 service_worker_context_->GetLiveRegistration(
777 service_worker_registration_id); 758 service_worker_registration_id);
759 const GURL origin = registration->pattern().GetOrigin();
Peter Beverloo 2016/07/08 18:30:11 nit: move to :770?
johnme 2016/07/13 17:51:57 Done.
778 760
779 const GURL origin = registration->pattern().GetOrigin(); 761 const bool uses_standard_protocol =
780 DCHECK_EQ(1u, push_subscription_id.size()); 762 IsApplicationServerKey(push_subscription_id_and_sender_info[1]);
781 const GURL endpoint = 763 const GURL endpoint = CreateEndpoint(
782 CreateEndpoint(uses_standard_protocol, push_subscription_id[0]); 764 uses_standard_protocol, push_subscription_id_and_sender_info[0]);
783 765
784 auto callback = 766 auto callback =
785 base::Bind(&PushMessagingMessageFilter::DidGetSubscriptionKeys, 767 base::Bind(&PushMessagingMessageFilter::DidGetSubscriptionKeys,
786 weak_factory_io_to_io_.GetWeakPtr(), request_id, endpoint); 768 weak_factory_io_to_io_.GetWeakPtr(), request_id, endpoint,
769 push_subscription_id_and_sender_info[1]);
787 770
788 BrowserThread::PostTask( 771 BrowserThread::PostTask(
789 BrowserThread::UI, FROM_HERE, 772 BrowserThread::UI, FROM_HERE,
790 base::Bind(&Core::GetEncryptionInfoOnUI, 773 base::Bind(&Core::GetEncryptionInfoOnUI,
791 base::Unretained(ui_core_.get()), origin, 774 base::Unretained(ui_core_.get()), origin,
792 service_worker_registration_id, callback)); 775 service_worker_registration_id, callback));
793 776
794 return; 777 return;
795 } 778 }
796 case SERVICE_WORKER_ERROR_NOT_FOUND: { 779 case SERVICE_WORKER_ERROR_NOT_FOUND: {
(...skipping 27 matching lines...) Expand all
824 break; 807 break;
825 } 808 }
826 } 809 }
827 Send(new PushMessagingMsg_GetSubscriptionError(request_id, get_status)); 810 Send(new PushMessagingMsg_GetSubscriptionError(request_id, get_status));
828 RecordGetRegistrationStatus(get_status); 811 RecordGetRegistrationStatus(get_status);
829 } 812 }
830 813
831 void PushMessagingMessageFilter::DidGetSubscriptionKeys( 814 void PushMessagingMessageFilter::DidGetSubscriptionKeys(
832 int request_id, 815 int request_id,
833 const GURL& endpoint, 816 const GURL& endpoint,
817 const std::string& sender_info,
834 bool success, 818 bool success,
835 const std::vector<uint8_t>& p256dh, 819 const std::vector<uint8_t>& p256dh,
836 const std::vector<uint8_t>& auth) { 820 const std::vector<uint8_t>& auth) {
837 DCHECK_CURRENTLY_ON(BrowserThread::IO); 821 DCHECK_CURRENTLY_ON(BrowserThread::IO);
838 if (!success) { 822 if (!success) {
839 PushGetRegistrationStatus status = 823 PushGetRegistrationStatus status =
840 PUSH_GETREGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE; 824 PUSH_GETREGISTRATION_STATUS_PUBLIC_KEY_UNAVAILABLE;
841 825
842 Send(new PushMessagingMsg_GetSubscriptionError(request_id, status)); 826 Send(new PushMessagingMsg_GetSubscriptionError(request_id, status));
843 827
844 RecordGetRegistrationStatus(status); 828 RecordGetRegistrationStatus(status);
845 return; 829 return;
846 } 830 }
847 831
832 PushSubscriptionOptions options;
833 // We reject subscription requests with userVisibleOnly false, so it must have
Peter Beverloo 2016/07/08 18:30:11 nit: don't use "we" in comments. Probably want to
johnme 2016/07/13 17:51:57 Ended up putting Chrome, since I'm relying on an i
834 // been true. TODO(harkness): If Chrome starts accepting silent push
835 // subscriptions with userVisibleOnly false, the bool will need to be stored.
836 options.user_visible_only = true;
837 options.sender_info = sender_info;
838
848 Send(new PushMessagingMsg_GetSubscriptionSuccess(request_id, endpoint, 839 Send(new PushMessagingMsg_GetSubscriptionSuccess(request_id, endpoint,
849 p256dh, auth)); 840 options, p256dh, auth));
850 841
851 RecordGetRegistrationStatus(PUSH_GETREGISTRATION_STATUS_SUCCESS); 842 RecordGetRegistrationStatus(PUSH_GETREGISTRATION_STATUS_SUCCESS);
852 } 843 }
853 844
854 // GetPermission methods on both IO and UI threads, merged in order of use from 845 // GetPermission methods on both IO and UI threads, merged in order of use from
855 // PushMessagingMessageFilter and Core. 846 // PushMessagingMessageFilter and Core.
856 // ----------------------------------------------------------------------------- 847 // -----------------------------------------------------------------------------
857 848
858 void PushMessagingMessageFilter::OnGetPermissionStatus( 849 void PushMessagingMessageFilter::OnGetPermissionStatus(
859 int request_id, 850 int request_id,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 PushMessagingService* PushMessagingMessageFilter::Core::service() { 940 PushMessagingService* PushMessagingMessageFilter::Core::service() {
950 DCHECK_CURRENTLY_ON(BrowserThread::UI); 941 DCHECK_CURRENTLY_ON(BrowserThread::UI);
951 RenderProcessHost* process_host = 942 RenderProcessHost* process_host =
952 RenderProcessHost::FromID(render_process_id_); 943 RenderProcessHost::FromID(render_process_id_);
953 return process_host 944 return process_host
954 ? process_host->GetBrowserContext()->GetPushMessagingService() 945 ? process_host->GetBrowserContext()->GetPushMessagingService()
955 : nullptr; 946 : nullptr;
956 } 947 }
957 948
958 } // namespace content 949 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698