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/permissions/permission_manager.h" | 8 #include "chrome/browser/permissions/permission_manager.h" |
9 #include "chrome/browser/permissions/permission_request_id.h" | 9 #include "chrome/browser/permissions/permission_request_id.h" |
10 #include "chrome/browser/permissions/permission_uma_util.h" | 10 #include "chrome/browser/permissions/permission_uma_util.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // - You need to request it from a top level domain | 68 // - You need to request it from a top level domain |
69 // - You need to have notification permission granted. | 69 // - You need to have notification permission granted. |
70 // - You need to not have push permission explicitly blocked. | 70 // - You need to not have push permission explicitly blocked. |
71 // - If those 3 things are true it is granted without prompting. | 71 // - If those 3 things are true it is granted without prompting. |
72 // This is done to avoid double prompting for notifications and push. | 72 // This is done to avoid double prompting for notifications and push. |
73 void PushMessagingPermissionContext::DecidePermission( | 73 void PushMessagingPermissionContext::DecidePermission( |
74 content::WebContents* web_contents, | 74 content::WebContents* web_contents, |
75 const PermissionRequestID& id, | 75 const PermissionRequestID& id, |
76 const GURL& requesting_origin, | 76 const GURL& requesting_origin, |
77 const GURL& embedding_origin, | 77 const GURL& embedding_origin, |
| 78 bool user_gesture, |
78 const BrowserPermissionCallback& callback) { | 79 const BrowserPermissionCallback& callback) { |
79 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
80 #if defined(ENABLE_NOTIFICATIONS) | 81 #if defined(ENABLE_NOTIFICATIONS) |
81 if (requesting_origin != embedding_origin) { | 82 if (requesting_origin != embedding_origin) { |
82 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 83 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
83 false /* persist */, CONTENT_SETTING_BLOCK); | 84 false /* persist */, CONTENT_SETTING_BLOCK); |
84 return; | 85 return; |
85 } | 86 } |
86 | 87 |
87 PermissionManager::Get(profile_)->RequestPermission( | 88 PermissionManager::Get(profile_)->RequestPermission( |
88 content::PermissionType::NOTIFICATIONS, web_contents->GetMainFrame(), | 89 content::PermissionType::NOTIFICATIONS, web_contents->GetMainFrame(), |
89 requesting_origin, | 90 requesting_origin, user_gesture, |
90 base::Bind(&PushMessagingPermissionContext::DecidePushPermission, | 91 base::Bind(&PushMessagingPermissionContext::DecidePushPermission, |
91 weak_factory_ui_thread_.GetWeakPtr(), id, requesting_origin, | 92 weak_factory_ui_thread_.GetWeakPtr(), id, requesting_origin, |
92 embedding_origin, callback)); | 93 embedding_origin, callback)); |
93 #else | 94 #else |
94 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 95 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
95 false /* persist */, CONTENT_SETTING_BLOCK); | 96 false /* persist */, CONTENT_SETTING_BLOCK); |
96 #endif | 97 #endif |
97 } | 98 } |
98 | 99 |
99 bool PushMessagingPermissionContext::IsRestrictedToSecureOrigins() const { | 100 bool PushMessagingPermissionContext::IsRestrictedToSecureOrigins() const { |
(...skipping 27 matching lines...) Expand all Loading... |
127 DVLOG(1) << "Notification permission has not been granted."; | 128 DVLOG(1) << "Notification permission has not been granted."; |
128 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 129 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
129 false /* persist */, CONTENT_SETTING_BLOCK); | 130 false /* persist */, CONTENT_SETTING_BLOCK); |
130 return; | 131 return; |
131 } | 132 } |
132 | 133 |
133 PermissionUmaUtil::PermissionGranted(permission_type(), requesting_origin); | 134 PermissionUmaUtil::PermissionGranted(permission_type(), requesting_origin); |
134 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 135 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
135 true /* persist */, CONTENT_SETTING_ALLOW); | 136 true /* persist */, CONTENT_SETTING_ALLOW); |
136 } | 137 } |
OLD | NEW |