| 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/services/gcm/push_messaging_service_impl.h" | 5 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" |
| 6 | 6 |
| 7 #include <bitset> | 7 #include <bitset> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/notifications/notification_ui_manager.h" | 18 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 19 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 19 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/push_messaging/push_messaging_application_id.h" |
| 22 #include "chrome/browser/push_messaging/push_messaging_permission_context.h" |
| 23 #include "chrome/browser/push_messaging/push_messaging_permission_context_factor
y.h" |
| 21 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 24 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 22 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 25 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 23 #include "chrome/browser/services/gcm/push_messaging_application_id.h" | |
| 24 #include "chrome/browser/services/gcm/push_messaging_constants.h" | 26 #include "chrome/browser/services/gcm/push_messaging_constants.h" |
| 25 #include "chrome/browser/services/gcm/push_messaging_permission_context.h" | |
| 26 #include "chrome/browser/services/gcm/push_messaging_permission_context_factory.
h" | |
| 27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/grit/generated_resources.h" | 29 #include "chrome/grit/generated_resources.h" |
| 30 #include "components/content_settings/core/browser/host_content_settings_map.h" | 30 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 31 #include "components/content_settings/core/common/permission_request_id.h" | 31 #include "components/content_settings/core/common/permission_request_id.h" |
| 32 #include "components/gcm_driver/gcm_driver.h" | 32 #include "components/gcm_driver/gcm_driver.h" |
| 33 #include "components/pref_registry/pref_registry_syncable.h" | 33 #include "components/pref_registry/pref_registry_syncable.h" |
| 34 #include "content/public/browser/browser_context.h" | 34 #include "content/public/browser/browser_context.h" |
| 35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/render_frame_host.h" | 36 #include "content/public/browser/render_frame_host.h" |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 if (!web_contents) | 487 if (!web_contents) |
| 488 return; | 488 return; |
| 489 | 489 |
| 490 // TODO(miguelg) need to send this over IPC when bubble support is | 490 // TODO(miguelg) need to send this over IPC when bubble support is |
| 491 // implemented. | 491 // implemented. |
| 492 int bridge_id = -1; | 492 int bridge_id = -1; |
| 493 | 493 |
| 494 const PermissionRequestID id( | 494 const PermissionRequestID id( |
| 495 renderer_id, web_contents->GetRoutingID(), bridge_id, GURL()); | 495 renderer_id, web_contents->GetRoutingID(), bridge_id, GURL()); |
| 496 | 496 |
| 497 gcm::PushMessagingPermissionContext* permission_context = | 497 PushMessagingPermissionContext* permission_context = |
| 498 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); | 498 PushMessagingPermissionContextFactory::GetForProfile(profile_); |
| 499 | 499 |
| 500 if (permission_context == NULL || !user_visible_only) { | 500 if (permission_context == NULL || !user_visible_only) { |
| 501 RegisterEnd(callback, | 501 RegisterEnd(callback, |
| 502 std::string(), | 502 std::string(), |
| 503 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); | 503 content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED); |
| 504 return; | 504 return; |
| 505 } | 505 } |
| 506 | 506 |
| 507 // TODO(miguelg): Consider the value of |user_visible_only| when making | 507 // TODO(miguelg): Consider the value of |user_visible_only| when making |
| 508 // the permission request. | 508 // the permission request. |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 UnregisterCallback()); | 768 UnregisterCallback()); |
| 769 | 769 |
| 770 // Clear the associated service worker push registration id. | 770 // Clear the associated service worker push registration id. |
| 771 PushMessagingService::ClearPushRegistrationID( | 771 PushMessagingService::ClearPushRegistrationID( |
| 772 profile_, id.origin(), id.service_worker_registration_id()); | 772 profile_, id.origin(), id.service_worker_registration_id()); |
| 773 } | 773 } |
| 774 | 774 |
| 775 // Helper methods -------------------------------------------------------------- | 775 // Helper methods -------------------------------------------------------------- |
| 776 | 776 |
| 777 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { | 777 bool PushMessagingServiceImpl::HasPermission(const GURL& origin) { |
| 778 gcm::PushMessagingPermissionContext* permission_context = | 778 PushMessagingPermissionContext* permission_context = |
| 779 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); | 779 PushMessagingPermissionContextFactory::GetForProfile(profile_); |
| 780 DCHECK(permission_context); | 780 DCHECK(permission_context); |
| 781 | 781 |
| 782 return permission_context->GetPermissionStatus(origin, origin) == | 782 return permission_context->GetPermissionStatus(origin, origin) == |
| 783 CONTENT_SETTING_ALLOW; | 783 CONTENT_SETTING_ALLOW; |
| 784 } | 784 } |
| 785 | 785 |
| 786 void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) { | 786 void PushMessagingServiceImpl::SetProfileForTesting(Profile* profile) { |
| 787 profile_ = profile; | 787 profile_ = profile; |
| 788 profile_->GetHostContentSettingsMap()->AddObserver(this); | 788 profile_->GetHostContentSettingsMap()->AddObserver(this); |
| 789 } | 789 } |
| 790 | 790 |
| 791 } // namespace gcm | 791 } // namespace gcm |
| OLD | NEW |