| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 UMA_HISTOGRAM_ENUMERATION("PushMessaging.UnregistrationGCMResult", result, | 93 UMA_HISTOGRAM_ENUMERATION("PushMessaging.UnregistrationGCMResult", result, |
| 94 gcm::GCMClient::LAST_RESULT + 1); | 94 gcm::GCMClient::LAST_RESULT + 1); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void RecordUnsubscribeIIDResult(InstanceID::Result result) { | 97 void RecordUnsubscribeIIDResult(InstanceID::Result result) { |
| 98 UMA_HISTOGRAM_ENUMERATION("PushMessaging.UnregistrationIIDResult", result, | 98 UMA_HISTOGRAM_ENUMERATION("PushMessaging.UnregistrationIIDResult", result, |
| 99 InstanceID::LAST_RESULT + 1); | 99 InstanceID::LAST_RESULT + 1); |
| 100 } | 100 } |
| 101 | 101 |
| 102 blink::WebPushPermissionStatus ToPushPermission( | 102 blink::WebPushPermissionStatus ToPushPermission( |
| 103 blink::mojom::PermissionStatus permission_status) { | 103 ContentSetting content_setting) { |
| 104 switch (permission_status) { | 104 switch (content_setting) { |
| 105 case blink::mojom::PermissionStatus::GRANTED: | 105 case CONTENT_SETTING_ALLOW: |
| 106 return blink::WebPushPermissionStatusGranted; | 106 return blink::WebPushPermissionStatusGranted; |
| 107 case blink::mojom::PermissionStatus::DENIED: | 107 case CONTENT_SETTING_BLOCK: |
| 108 return blink::WebPushPermissionStatusDenied; | 108 return blink::WebPushPermissionStatusDenied; |
| 109 case blink::mojom::PermissionStatus::ASK: | 109 case CONTENT_SETTING_ASK: |
| 110 return blink::WebPushPermissionStatusPrompt; | 110 return blink::WebPushPermissionStatusPrompt; |
| 111 default: |
| 112 break; |
| 111 } | 113 } |
| 112 NOTREACHED(); | 114 NOTREACHED(); |
| 113 return blink::WebPushPermissionStatusDenied; | 115 return blink::WebPushPermissionStatusDenied; |
| 114 } | 116 } |
| 115 | 117 |
| 116 void UnregisterCallbackToClosure(const base::Closure& closure, | 118 void UnregisterCallbackToClosure(const base::Closure& closure, |
| 117 content::PushUnregistrationStatus status) { | 119 content::PushUnregistrationStatus status) { |
| 118 DCHECK(!closure.is_null()); | 120 DCHECK(!closure.is_null()); |
| 119 closure.Run(); | 121 closure.Run(); |
| 120 } | 122 } |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 blink::WebPushPermissionStatus permission_status = | 502 blink::WebPushPermissionStatus permission_status = |
| 501 GetPermissionStatus(requesting_origin, options.user_visible_only); | 503 GetPermissionStatus(requesting_origin, options.user_visible_only); |
| 502 | 504 |
| 503 if (permission_status != blink::WebPushPermissionStatusGranted) { | 505 if (permission_status != blink::WebPushPermissionStatusGranted) { |
| 504 SubscribeEndWithError(register_callback, | 506 SubscribeEndWithError(register_callback, |
| 505 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 507 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
| 506 return; | 508 return; |
| 507 } | 509 } |
| 508 | 510 |
| 509 DoSubscribe(app_identifier, options, register_callback, | 511 DoSubscribe(app_identifier, options, register_callback, |
| 510 blink::mojom::PermissionStatus::GRANTED); | 512 CONTENT_SETTING_ALLOW); |
| 511 } | 513 } |
| 512 | 514 |
| 513 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( | 515 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( |
| 514 const GURL& origin, | 516 const GURL& origin, |
| 515 bool user_visible) { | 517 bool user_visible) { |
| 516 if (!user_visible) | 518 if (!user_visible) |
| 517 return blink::WebPushPermissionStatusDenied; | 519 return blink::WebPushPermissionStatusDenied; |
| 518 | 520 |
| 519 // Because the Push API is tied to Service Workers, many usages of the API | 521 // Because the Push API is tied to Service Workers, many usages of the API |
| 520 // won't have an embedding origin at all. Only consider the requesting | 522 // won't have an embedding origin at all. Only consider the requesting |
| 521 // |origin| when checking whether permission to use the API has been granted. | 523 // |origin| when checking whether permission to use the API has been granted. |
| 522 return ToPushPermission(PermissionManager::Get(profile_)->GetPermissionStatus( | 524 return ToPushPermission(PermissionManager::Get(profile_)->GetPermissionStatus( |
| 523 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, origin, origin)); | 525 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, origin, origin)); |
| 524 } | 526 } |
| 525 | 527 |
| 526 bool PushMessagingServiceImpl::SupportNonVisibleMessages() { | 528 bool PushMessagingServiceImpl::SupportNonVisibleMessages() { |
| 527 return false; | 529 return false; |
| 528 } | 530 } |
| 529 | 531 |
| 530 void PushMessagingServiceImpl::DoSubscribe( | 532 void PushMessagingServiceImpl::DoSubscribe( |
| 531 const PushMessagingAppIdentifier& app_identifier, | 533 const PushMessagingAppIdentifier& app_identifier, |
| 532 const content::PushSubscriptionOptions& options, | 534 const content::PushSubscriptionOptions& options, |
| 533 const RegisterCallback& register_callback, | 535 const RegisterCallback& register_callback, |
| 534 blink::mojom::PermissionStatus permission_status) { | 536 ContentSetting content_setting) { |
| 535 if (permission_status != blink::mojom::PermissionStatus::GRANTED) { | 537 if (content_setting != CONTENT_SETTING_ALLOW) { |
| 536 SubscribeEndWithError(register_callback, | 538 SubscribeEndWithError(register_callback, |
| 537 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 539 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
| 538 return; | 540 return; |
| 539 } | 541 } |
| 540 | 542 |
| 541 IncreasePushSubscriptionCount(1, true /* is_pending */); | 543 IncreasePushSubscriptionCount(1, true /* is_pending */); |
| 542 | 544 |
| 543 GetInstanceIDDriver() | 545 GetInstanceIDDriver() |
| 544 ->GetInstanceID(app_identifier.app_id()) | 546 ->GetInstanceID(app_identifier.app_id()) |
| 545 ->GetToken(NormalizeSenderInfo(options.sender_info), kGCMScope, | 547 ->GetToken(NormalizeSenderInfo(options.sender_info), kGCMScope, |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 } | 985 } |
| 984 | 986 |
| 985 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() | 987 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() |
| 986 const { | 988 const { |
| 987 instance_id::InstanceIDProfileService* instance_id_profile_service = | 989 instance_id::InstanceIDProfileService* instance_id_profile_service = |
| 988 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); | 990 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); |
| 989 CHECK(instance_id_profile_service); | 991 CHECK(instance_id_profile_service); |
| 990 CHECK(instance_id_profile_service->driver()); | 992 CHECK(instance_id_profile_service->driver()); |
| 991 return instance_id_profile_service->driver(); | 993 return instance_id_profile_service->driver(); |
| 992 } | 994 } |
| OLD | NEW |