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 27 matching lines...) Expand all Loading... |
38 #include "components/content_settings/core/browser/host_content_settings_map.h" | 38 #include "components/content_settings/core/browser/host_content_settings_map.h" |
39 #include "components/gcm_driver/gcm_driver.h" | 39 #include "components/gcm_driver/gcm_driver.h" |
40 #include "components/gcm_driver/gcm_profile_service.h" | 40 #include "components/gcm_driver/gcm_profile_service.h" |
41 #include "components/gcm_driver/instance_id/instance_id.h" | 41 #include "components/gcm_driver/instance_id/instance_id.h" |
42 #include "components/gcm_driver/instance_id/instance_id_driver.h" | 42 #include "components/gcm_driver/instance_id/instance_id_driver.h" |
43 #include "components/pref_registry/pref_registry_syncable.h" | 43 #include "components/pref_registry/pref_registry_syncable.h" |
44 #include "components/prefs/pref_service.h" | 44 #include "components/prefs/pref_service.h" |
45 #include "components/rappor/public/rappor_utils.h" | 45 #include "components/rappor/public/rappor_utils.h" |
46 #include "components/rappor/rappor_service_impl.h" | 46 #include "components/rappor/rappor_service_impl.h" |
47 #include "content/public/browser/browser_context.h" | 47 #include "content/public/browser/browser_context.h" |
48 #include "content/public/browser/permission_type.h" | |
49 #include "content/public/browser/render_frame_host.h" | 48 #include "content/public/browser/render_frame_host.h" |
50 #include "content/public/browser/service_worker_context.h" | 49 #include "content/public/browser/service_worker_context.h" |
51 #include "content/public/browser/storage_partition.h" | 50 #include "content/public/browser/storage_partition.h" |
52 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
53 #include "content/public/common/child_process_host.h" | 52 #include "content/public/common/child_process_host.h" |
54 #include "content/public/common/content_switches.h" | 53 #include "content/public/common/content_switches.h" |
55 #include "content/public/common/push_messaging_status.h" | 54 #include "content/public/common/push_messaging_status.h" |
56 #include "content/public/common/push_subscription_options.h" | 55 #include "content/public/common/push_subscription_options.h" |
57 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" |
58 | 57 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (!options.user_visible_only) { | 466 if (!options.user_visible_only) { |
468 web_contents->GetMainFrame()->AddMessageToConsole( | 467 web_contents->GetMainFrame()->AddMessageToConsole( |
469 content::CONSOLE_MESSAGE_LEVEL_ERROR, kSilentPushUnsupportedMessage); | 468 content::CONSOLE_MESSAGE_LEVEL_ERROR, kSilentPushUnsupportedMessage); |
470 | 469 |
471 SubscribeEndWithError(callback, | 470 SubscribeEndWithError(callback, |
472 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 471 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
473 return; | 472 return; |
474 } | 473 } |
475 | 474 |
476 // Push does not allow permission requests from iframes. | 475 // Push does not allow permission requests from iframes. |
477 profile_->GetPermissionManager()->RequestPermission( | 476 PermissionManager::Get(profile_)->RequestPermission( |
478 content::PermissionType::PUSH_MESSAGING, web_contents->GetMainFrame(), | 477 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, web_contents->GetMainFrame(), |
479 requesting_origin, true /* user_gesture */, | 478 requesting_origin, true /* user_gesture */, |
480 base::Bind(&PushMessagingServiceImpl::DoSubscribe, | 479 base::Bind(&PushMessagingServiceImpl::DoSubscribe, |
481 weak_factory_.GetWeakPtr(), app_identifier, options, | 480 weak_factory_.GetWeakPtr(), app_identifier, options, |
482 callback)); | 481 callback)); |
483 } | 482 } |
484 | 483 |
485 void PushMessagingServiceImpl::SubscribeFromWorker( | 484 void PushMessagingServiceImpl::SubscribeFromWorker( |
486 const GURL& requesting_origin, | 485 const GURL& requesting_origin, |
487 int64_t service_worker_registration_id, | 486 int64_t service_worker_registration_id, |
488 const content::PushSubscriptionOptions& options, | 487 const content::PushSubscriptionOptions& options, |
(...skipping 24 matching lines...) Expand all Loading... |
513 | 512 |
514 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( | 513 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( |
515 const GURL& origin, | 514 const GURL& origin, |
516 bool user_visible) { | 515 bool user_visible) { |
517 if (!user_visible) | 516 if (!user_visible) |
518 return blink::WebPushPermissionStatusDenied; | 517 return blink::WebPushPermissionStatusDenied; |
519 | 518 |
520 // Because the Push API is tied to Service Workers, many usages of the API | 519 // Because the Push API is tied to Service Workers, many usages of the API |
521 // won't have an embedding origin at all. Only consider the requesting | 520 // won't have an embedding origin at all. Only consider the requesting |
522 // |origin| when checking whether permission to use the API has been granted. | 521 // |origin| when checking whether permission to use the API has been granted. |
523 return ToPushPermission(profile_->GetPermissionManager()->GetPermissionStatus( | 522 return ToPushPermission(PermissionManager::Get(profile_)->GetPermissionStatus( |
524 content::PermissionType::PUSH_MESSAGING, origin, origin)); | 523 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, origin, origin)); |
525 } | 524 } |
526 | 525 |
527 bool PushMessagingServiceImpl::SupportNonVisibleMessages() { | 526 bool PushMessagingServiceImpl::SupportNonVisibleMessages() { |
528 return false; | 527 return false; |
529 } | 528 } |
530 | 529 |
531 void PushMessagingServiceImpl::DoSubscribe( | 530 void PushMessagingServiceImpl::DoSubscribe( |
532 const PushMessagingAppIdentifier& app_identifier, | 531 const PushMessagingAppIdentifier& app_identifier, |
533 const content::PushSubscriptionOptions& options, | 532 const content::PushSubscriptionOptions& options, |
534 const RegisterCallback& register_callback, | 533 const RegisterCallback& register_callback, |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 } | 983 } |
985 | 984 |
986 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() | 985 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() |
987 const { | 986 const { |
988 instance_id::InstanceIDProfileService* instance_id_profile_service = | 987 instance_id::InstanceIDProfileService* instance_id_profile_service = |
989 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); | 988 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); |
990 CHECK(instance_id_profile_service); | 989 CHECK(instance_id_profile_service); |
991 CHECK(instance_id_profile_service->driver()); | 990 CHECK(instance_id_profile_service->driver()); |
992 return instance_id_profile_service->driver(); | 991 return instance_id_profile_service->driver(); |
993 } | 992 } |
OLD | NEW |