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 "chrome/browser/push_messaging/push_messaging_service_impl.h" | 5 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
10 #include "base/base64url.h" | 10 #include "base/base64url.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 PushMessagingAppIdentifier app_identifier = | 270 PushMessagingAppIdentifier app_identifier = |
271 PushMessagingAppIdentifier::FindByAppId(profile_, app_id); | 271 PushMessagingAppIdentifier::FindByAppId(profile_, app_id); |
272 // Drop message and unregister if app_id was unknown (maybe recently deleted). | 272 // Drop message and unregister if app_id was unknown (maybe recently deleted). |
273 if (app_identifier.is_null()) { | 273 if (app_identifier.is_null()) { |
274 DeliverMessageCallback(app_id, GURL::EmptyGURL(), | 274 DeliverMessageCallback(app_id, GURL::EmptyGURL(), |
275 -1 /* kInvalidServiceWorkerRegistrationId */, | 275 -1 /* kInvalidServiceWorkerRegistrationId */, |
276 message, message_handled_closure, | 276 message, message_handled_closure, |
277 content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID); | 277 content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID); |
278 return; | 278 return; |
279 } | 279 } |
280 // Drop message and unregister if |origin| has lost push permission. | 280 |
281 if (!IsPermissionSet(app_identifier.origin())) { | 281 // Drop message and unregister if |origin| has lost push permission. However, |
| 282 // we should only drop the subscription if the permission was in fact denied |
| 283 // rather than suspended, for example through the kill switch. |
| 284 PermissionResult permission_result = |
| 285 PermissionManager::Get(profile_)->GetPermissionStatus( |
| 286 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, app_identifier.origin(), |
| 287 app_identifier.origin()); |
| 288 |
| 289 if (permission_result.content_setting != CONTENT_SETTING_ALLOW) { |
| 290 content::PushDeliveryStatus status = |
| 291 content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED; |
| 292 |
| 293 switch (permission_result.source) { |
| 294 case PermissionStatusSource::KILL_SWITCH: |
| 295 status = content::PUSH_DELIVERY_STATUS_PERMISSION_SUSPENDED; |
| 296 break; |
| 297 case PermissionStatusSource::UNSPECIFIED: |
| 298 case PermissionStatusSource::SAFE_BROWSING_BLACKLIST: |
| 299 case PermissionStatusSource::MULTIPLE_DISMISSALS: |
| 300 case PermissionStatusSource::MULTIPLE_IGNORES: |
| 301 status = content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED; |
| 302 break; |
| 303 } |
| 304 |
282 DeliverMessageCallback(app_id, app_identifier.origin(), | 305 DeliverMessageCallback(app_id, app_identifier.origin(), |
283 app_identifier.service_worker_registration_id(), | 306 app_identifier.service_worker_registration_id(), |
284 message, message_handled_closure, | 307 message, message_handled_closure, status); |
285 content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED); | |
286 return; | 308 return; |
287 } | 309 } |
288 | 310 |
289 rappor::SampleDomainAndRegistryFromGURL( | 311 rappor::SampleDomainAndRegistryFromGURL( |
290 g_browser_process->rappor_service(), | 312 g_browser_process->rappor_service(), |
291 "PushMessaging.MessageReceived.Origin", app_identifier.origin()); | 313 "PushMessaging.MessageReceived.Origin", app_identifier.origin()); |
292 | 314 |
293 // The payload of a push message can be valid with content, valid with empty | 315 // The payload of a push message can be valid with content, valid with empty |
294 // content, or null. Only set the payload data if it is non-null. | 316 // content, or null. Only set the payload data if it is non-null. |
295 content::PushEventPayload payload; | 317 content::PushEventPayload payload; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // Do nothing, and hope the error is transient. | 384 // Do nothing, and hope the error is transient. |
363 break; | 385 break; |
364 case content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID: | 386 case content::PUSH_DELIVERY_STATUS_UNKNOWN_APP_ID: |
365 unsubscribe_reason = | 387 unsubscribe_reason = |
366 content::PUSH_UNREGISTRATION_REASON_DELIVERY_UNKNOWN_APP_ID; | 388 content::PUSH_UNREGISTRATION_REASON_DELIVERY_UNKNOWN_APP_ID; |
367 break; | 389 break; |
368 case content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED: | 390 case content::PUSH_DELIVERY_STATUS_PERMISSION_DENIED: |
369 unsubscribe_reason = | 391 unsubscribe_reason = |
370 content::PUSH_UNREGISTRATION_REASON_DELIVERY_PERMISSION_DENIED; | 392 content::PUSH_UNREGISTRATION_REASON_DELIVERY_PERMISSION_DENIED; |
371 break; | 393 break; |
| 394 case content::PUSH_DELIVERY_STATUS_PERMISSION_SUSPENDED: |
| 395 // Do nothing, the kill switch might be withdrawn at some point. |
| 396 break; |
372 case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER: | 397 case content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER: |
373 unsubscribe_reason = | 398 unsubscribe_reason = |
374 content::PUSH_UNREGISTRATION_REASON_DELIVERY_NO_SERVICE_WORKER; | 399 content::PUSH_UNREGISTRATION_REASON_DELIVERY_NO_SERVICE_WORKER; |
375 break; | 400 break; |
376 } | 401 } |
377 | 402 |
378 if (unsubscribe_reason != content::PUSH_UNREGISTRATION_REASON_UNKNOWN) { | 403 if (unsubscribe_reason != content::PUSH_UNREGISTRATION_REASON_UNKNOWN) { |
379 PushMessagingAppIdentifier app_identifier = | 404 PushMessagingAppIdentifier app_identifier = |
380 PushMessagingAppIdentifier::FindByAppId(profile_, app_id); | 405 PushMessagingAppIdentifier::FindByAppId(profile_, app_id); |
381 UnsubscribeInternal( | 406 UnsubscribeInternal( |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 // permission change because it can happen for example when the entire | 921 // permission change because it can happen for example when the entire |
897 // Push or Notifications permissions are cleared. | 922 // Push or Notifications permissions are cleared. |
898 // Otherwise, the permission should be checked if the pattern matches the | 923 // Otherwise, the permission should be checked if the pattern matches the |
899 // origin. | 924 // origin. |
900 if (primary_pattern.IsValid() && | 925 if (primary_pattern.IsValid() && |
901 !primary_pattern.Matches(app_identifier.origin())) { | 926 !primary_pattern.Matches(app_identifier.origin())) { |
902 barrier_closure.Run(); | 927 barrier_closure.Run(); |
903 continue; | 928 continue; |
904 } | 929 } |
905 | 930 |
906 if (IsPermissionSet(app_identifier.origin())) { | 931 if (GetPermissionStatus(app_identifier.origin(), true /* user_visible */) == |
| 932 blink::kWebPushPermissionStatusGranted) { |
907 barrier_closure.Run(); | 933 barrier_closure.Run(); |
908 continue; | 934 continue; |
909 } | 935 } |
910 | 936 |
911 bool need_sender_id = false; | 937 bool need_sender_id = false; |
912 #if defined(OS_ANDROID) | 938 #if defined(OS_ANDROID) |
913 need_sender_id = | 939 need_sender_id = |
914 !PushMessagingAppIdentifier::UseInstanceID(app_identifier.app_id()); | 940 !PushMessagingAppIdentifier::UseInstanceID(app_identifier.app_id()); |
915 #endif | 941 #endif |
916 if (need_sender_id) { | 942 if (need_sender_id) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 if (sender_info.size() != 65 || sender_info[0] != 0x04) | 1028 if (sender_info.size() != 65 || sender_info[0] != 0x04) |
1003 return sender_info; | 1029 return sender_info; |
1004 | 1030 |
1005 std::string encoded_sender_info; | 1031 std::string encoded_sender_info; |
1006 base::Base64UrlEncode(sender_info, base::Base64UrlEncodePolicy::OMIT_PADDING, | 1032 base::Base64UrlEncode(sender_info, base::Base64UrlEncodePolicy::OMIT_PADDING, |
1007 &encoded_sender_info); | 1033 &encoded_sender_info); |
1008 | 1034 |
1009 return encoded_sender_info; | 1035 return encoded_sender_info; |
1010 } | 1036 } |
1011 | 1037 |
1012 // Assumes user_visible always since this is just meant to check | |
1013 // if the permission was previously granted and not revoked. | |
1014 bool PushMessagingServiceImpl::IsPermissionSet(const GURL& origin) { | |
1015 return GetPermissionStatus(origin, true /* user_visible */) == | |
1016 blink::kWebPushPermissionStatusGranted; | |
1017 } | |
1018 | |
1019 void PushMessagingServiceImpl::GetEncryptionInfoForAppId( | 1038 void PushMessagingServiceImpl::GetEncryptionInfoForAppId( |
1020 const std::string& app_id, | 1039 const std::string& app_id, |
1021 const std::string& sender_id, | 1040 const std::string& sender_id, |
1022 gcm::GCMEncryptionProvider::EncryptionInfoCallback callback) { | 1041 gcm::GCMEncryptionProvider::EncryptionInfoCallback callback) { |
1023 if (PushMessagingAppIdentifier::UseInstanceID(app_id)) { | 1042 if (PushMessagingAppIdentifier::UseInstanceID(app_id)) { |
1024 GetInstanceIDDriver()->GetInstanceID(app_id)->GetEncryptionInfo( | 1043 GetInstanceIDDriver()->GetInstanceID(app_id)->GetEncryptionInfo( |
1025 NormalizeSenderInfo(sender_id), callback); | 1044 NormalizeSenderInfo(sender_id), callback); |
1026 } else { | 1045 } else { |
1027 GetGCMDriver()->GetEncryptionInfo(app_id, callback); | 1046 GetGCMDriver()->GetEncryptionInfo(app_id, callback); |
1028 } | 1047 } |
1029 } | 1048 } |
1030 | 1049 |
1031 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { | 1050 gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const { |
1032 gcm::GCMProfileService* gcm_profile_service = | 1051 gcm::GCMProfileService* gcm_profile_service = |
1033 gcm::GCMProfileServiceFactory::GetForProfile(profile_); | 1052 gcm::GCMProfileServiceFactory::GetForProfile(profile_); |
1034 CHECK(gcm_profile_service); | 1053 CHECK(gcm_profile_service); |
1035 CHECK(gcm_profile_service->driver()); | 1054 CHECK(gcm_profile_service->driver()); |
1036 return gcm_profile_service->driver(); | 1055 return gcm_profile_service->driver(); |
1037 } | 1056 } |
1038 | 1057 |
1039 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() | 1058 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() |
1040 const { | 1059 const { |
1041 instance_id::InstanceIDProfileService* instance_id_profile_service = | 1060 instance_id::InstanceIDProfileService* instance_id_profile_service = |
1042 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); | 1061 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); |
1043 CHECK(instance_id_profile_service); | 1062 CHECK(instance_id_profile_service); |
1044 CHECK(instance_id_profile_service->driver()); | 1063 CHECK(instance_id_profile_service->driver()); |
1045 return instance_id_profile_service->driver(); | 1064 return instance_id_profile_service->driver(); |
1046 } | 1065 } |
OLD | NEW |