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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 if (!options.user_visible_only) { | 500 if (!options.user_visible_only) { |
502 web_contents->GetMainFrame()->AddMessageToConsole( | 501 web_contents->GetMainFrame()->AddMessageToConsole( |
503 content::CONSOLE_MESSAGE_LEVEL_ERROR, kSilentPushUnsupportedMessage); | 502 content::CONSOLE_MESSAGE_LEVEL_ERROR, kSilentPushUnsupportedMessage); |
504 | 503 |
505 SubscribeEndWithError(callback, | 504 SubscribeEndWithError(callback, |
506 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 505 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
507 return; | 506 return; |
508 } | 507 } |
509 | 508 |
510 // Push does not allow permission requests from iframes. | 509 // Push does not allow permission requests from iframes. |
511 profile_->GetPermissionManager()->RequestPermission( | 510 PermissionManager::Get(profile_)->RequestPermission( |
512 content::PermissionType::PUSH_MESSAGING, web_contents->GetMainFrame(), | 511 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, web_contents->GetMainFrame(), |
513 requesting_origin, true /* user_gesture */, | 512 requesting_origin, true /* user_gesture */, |
514 base::Bind(&PushMessagingServiceImpl::DoSubscribe, | 513 base::Bind(&PushMessagingServiceImpl::DoSubscribe, |
515 weak_factory_.GetWeakPtr(), app_identifier, options, | 514 weak_factory_.GetWeakPtr(), app_identifier, options, |
516 callback)); | 515 callback)); |
517 } | 516 } |
518 | 517 |
519 void PushMessagingServiceImpl::SubscribeFromWorker( | 518 void PushMessagingServiceImpl::SubscribeFromWorker( |
520 const GURL& requesting_origin, | 519 const GURL& requesting_origin, |
521 int64_t service_worker_registration_id, | 520 int64_t service_worker_registration_id, |
522 const content::PushSubscriptionOptions& options, | 521 const content::PushSubscriptionOptions& options, |
(...skipping 24 matching lines...) Expand all Loading... |
547 | 546 |
548 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( | 547 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus( |
549 const GURL& origin, | 548 const GURL& origin, |
550 bool user_visible) { | 549 bool user_visible) { |
551 if (!user_visible) | 550 if (!user_visible) |
552 return blink::WebPushPermissionStatusDenied; | 551 return blink::WebPushPermissionStatusDenied; |
553 | 552 |
554 // Because the Push API is tied to Service Workers, many usages of the API | 553 // Because the Push API is tied to Service Workers, many usages of the API |
555 // won't have an embedding origin at all. Only consider the requesting | 554 // won't have an embedding origin at all. Only consider the requesting |
556 // |origin| when checking whether permission to use the API has been granted. | 555 // |origin| when checking whether permission to use the API has been granted. |
557 return ToPushPermission(profile_->GetPermissionManager()->GetPermissionStatus( | 556 return ToPushPermission(PermissionManager::Get(profile_)->GetPermissionStatus( |
558 content::PermissionType::PUSH_MESSAGING, origin, origin)); | 557 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, origin, origin)); |
559 } | 558 } |
560 | 559 |
561 bool PushMessagingServiceImpl::SupportNonVisibleMessages() { | 560 bool PushMessagingServiceImpl::SupportNonVisibleMessages() { |
562 return false; | 561 return false; |
563 } | 562 } |
564 | 563 |
565 void PushMessagingServiceImpl::DoSubscribe( | 564 void PushMessagingServiceImpl::DoSubscribe( |
566 const PushMessagingAppIdentifier& app_identifier, | 565 const PushMessagingAppIdentifier& app_identifier, |
567 const content::PushSubscriptionOptions& options, | 566 const content::PushSubscriptionOptions& options, |
568 const RegisterCallback& register_callback, | 567 const RegisterCallback& register_callback, |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 } | 1004 } |
1006 | 1005 |
1007 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() | 1006 instance_id::InstanceIDDriver* PushMessagingServiceImpl::GetInstanceIDDriver() |
1008 const { | 1007 const { |
1009 instance_id::InstanceIDProfileService* instance_id_profile_service = | 1008 instance_id::InstanceIDProfileService* instance_id_profile_service = |
1010 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); | 1009 instance_id::InstanceIDProfileServiceFactory::GetForProfile(profile_); |
1011 CHECK(instance_id_profile_service); | 1010 CHECK(instance_id_profile_service); |
1012 CHECK(instance_id_profile_service->driver()); | 1011 CHECK(instance_id_profile_service->driver()); |
1013 return instance_id_profile_service->driver(); | 1012 return instance_id_profile_service->driver(); |
1014 } | 1013 } |
OLD | NEW |