| 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_permission_context.h" | 5 #include "chrome/browser/push_messaging/push_messaging_permission_context.h" |
| 6 | 6 |
| 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 8 #include "chrome/browser/notifications/notification_permission_context.h" | 8 #include "chrome/browser/notifications/notification_permission_context.h" |
| 9 #include "chrome/browser/notifications/notification_permission_context_factory.h
" | 9 #include "chrome/browser/notifications/notification_permission_context_factory.h
" |
| 10 #include "chrome/browser/permissions/permission_request_id.h" | 10 #include "chrome/browser/permissions/permission_request_id.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return CONTENT_SETTING_ALLOW; | 58 return CONTENT_SETTING_ALLOW; |
| 59 #else | 59 #else |
| 60 return CONTENT_SETTING_BLOCK; | 60 return CONTENT_SETTING_BLOCK; |
| 61 #endif | 61 #endif |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Unlike other permissions, push is decided by the following algorithm | 64 // Unlike other permissions, push is decided by the following algorithm |
| 65 // - You need to request it from a top level domain | 65 // - You need to request it from a top level domain |
| 66 // - You need to have notification permission granted. | 66 // - You need to have notification permission granted. |
| 67 // - You need to not have push permission explicitly blocked. | 67 // - You need to not have push permission explicitly blocked. |
| 68 // - If those two things are true it is granted without prompting. | 68 // - If those 3 things are true it is granted without prompting. |
| 69 // This is done to avoid double prompting for notifications and push. | 69 // This is done to avoid double prompting for notifications and push. |
| 70 void PushMessagingPermissionContext::DecidePermission( | 70 void PushMessagingPermissionContext::DecidePermission( |
| 71 content::WebContents* web_contents, | 71 content::WebContents* web_contents, |
| 72 const PermissionRequestID& id, | 72 const PermissionRequestID& id, |
| 73 const GURL& requesting_origin, | 73 const GURL& requesting_origin, |
| 74 const GURL& embedding_origin, | 74 const GURL& embedding_origin, |
| 75 bool user_gesture, | 75 bool user_gesture, |
| 76 const BrowserPermissionCallback& callback) { | 76 const BrowserPermissionCallback& callback) { |
| 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 78 #if defined(ENABLE_NOTIFICATIONS) | 78 #if defined(ENABLE_NOTIFICATIONS) |
| 79 if (requesting_origin != embedding_origin) { | 79 if (requesting_origin != embedding_origin) { |
| 80 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 80 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 81 false /* persist */, CONTENT_SETTING_BLOCK); | 81 false /* persist */, CONTENT_SETTING_BLOCK); |
| 82 return; | 82 return; |
| 83 } | 83 } |
| 84 | 84 |
| 85 if (IsRestrictedToSecureOrigins() && | |
| 86 !content::IsOriginSecure(requesting_origin)) { | |
| 87 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
| 88 false /* persist */, CONTENT_SETTING_BLOCK); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 NotificationPermissionContext* notification_context = | 85 NotificationPermissionContext* notification_context = |
| 93 NotificationPermissionContextFactory::GetForProfile(profile_); | 86 NotificationPermissionContextFactory::GetForProfile(profile_); |
| 94 DCHECK(notification_context); | 87 DCHECK(notification_context); |
| 95 | 88 |
| 96 notification_context->RequestPermission( | 89 notification_context->RequestPermission( |
| 97 web_contents, id, requesting_origin, user_gesture, | 90 web_contents, id, requesting_origin, user_gesture, |
| 98 base::Bind(&PushMessagingPermissionContext::DecidePushPermission, | 91 base::Bind(&PushMessagingPermissionContext::DecidePushPermission, |
| 99 weak_factory_ui_thread_.GetWeakPtr(), id, requesting_origin, | 92 weak_factory_ui_thread_.GetWeakPtr(), id, requesting_origin, |
| 100 embedding_origin, callback)); | 93 embedding_origin, callback)); |
| 101 #else | 94 #else |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 DVLOG(1) << "Notification permission has not been granted."; | 126 DVLOG(1) << "Notification permission has not been granted."; |
| 134 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 127 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 135 false /* persist */, notification_content_setting); | 128 false /* persist */, notification_content_setting); |
| 136 return; | 129 return; |
| 137 } | 130 } |
| 138 | 131 |
| 139 PermissionUmaUtil::PermissionGranted(kPushSettingType, requesting_origin); | 132 PermissionUmaUtil::PermissionGranted(kPushSettingType, requesting_origin); |
| 140 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 133 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 141 true /* persist */, CONTENT_SETTING_ALLOW); | 134 true /* persist */, CONTENT_SETTING_ALLOW); |
| 142 } | 135 } |
| OLD | NEW |