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/permission_context_uma_util.h" | 7 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
8 #include "chrome/browser/notifications/desktop_notification_service.h" | 8 #include "chrome/browser/notifications/notification_permission_context.h" |
9 #include "chrome/browser/notifications/desktop_notification_service_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" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "components/content_settings/core/browser/host_content_settings_map.h" | 12 #include "components/content_settings/core/browser/host_content_settings_map.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_delegate.h" | 15 #include "content/public/browser/web_contents_delegate.h" |
16 | 16 |
17 const ContentSettingsType kPushSettingType = | 17 const ContentSettingsType kPushSettingType = |
18 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING; | 18 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING; |
19 | 19 |
(...skipping 10 matching lines...) Expand all Loading... | |
30 const GURL& requesting_origin, | 30 const GURL& requesting_origin, |
31 const GURL& embedding_origin) const { | 31 const GURL& embedding_origin) const { |
32 #if defined(ENABLE_NOTIFICATIONS) | 32 #if defined(ENABLE_NOTIFICATIONS) |
33 if (requesting_origin != embedding_origin) | 33 if (requesting_origin != embedding_origin) |
34 return CONTENT_SETTING_BLOCK; | 34 return CONTENT_SETTING_BLOCK; |
35 | 35 |
36 ContentSetting push_content_setting = | 36 ContentSetting push_content_setting = |
37 profile_->GetHostContentSettingsMap()->GetContentSetting( | 37 profile_->GetHostContentSettingsMap()->GetContentSetting( |
38 requesting_origin, embedding_origin, kPushSettingType, std::string()); | 38 requesting_origin, embedding_origin, kPushSettingType, std::string()); |
39 | 39 |
40 DesktopNotificationService* notification_service = | 40 NotificationPermissionContext* notification_context = |
41 DesktopNotificationServiceFactory::GetForProfile(profile_); | 41 NotificationPermissionContextFactory::GetForProfile(profile_); |
42 DCHECK(notification_service); | 42 DCHECK(notification_context); |
43 | 43 |
44 ContentSetting notifications_permission = | 44 ContentSetting notifications_permission = |
45 notification_service->GetPermissionStatus(requesting_origin, | 45 notification_context->GetPermissionStatus(requesting_origin, |
46 embedding_origin); | 46 embedding_origin); |
47 | 47 |
48 if (notifications_permission == CONTENT_SETTING_BLOCK || | 48 if (notifications_permission == CONTENT_SETTING_BLOCK || |
49 push_content_setting == CONTENT_SETTING_BLOCK) { | 49 push_content_setting == CONTENT_SETTING_BLOCK) { |
50 return CONTENT_SETTING_BLOCK; | 50 return CONTENT_SETTING_BLOCK; |
51 } | 51 } |
52 if (notifications_permission == CONTENT_SETTING_ASK || | 52 if (notifications_permission == CONTENT_SETTING_ASK || |
53 push_content_setting == CONTENT_SETTING_ASK) { | 53 push_content_setting == CONTENT_SETTING_ASK) { |
54 return CONTENT_SETTING_ASK; | 54 return CONTENT_SETTING_ASK; |
55 } | 55 } |
56 DCHECK_EQ(CONTENT_SETTING_ALLOW, notifications_permission); | 56 DCHECK_EQ(CONTENT_SETTING_ALLOW, notifications_permission); |
57 DCHECK_EQ(CONTENT_SETTING_ALLOW, push_content_setting); | 57 DCHECK_EQ(CONTENT_SETTING_ALLOW, push_content_setting); |
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 void PushMessagingPermissionContext::CancelPermissionRequest( | 64 void PushMessagingPermissionContext::CancelPermissionRequest( |
65 content::WebContents* web_contents, const PermissionRequestID& id) { | 65 content::WebContents* web_contents, const PermissionRequestID& id) { |
66 // TODO(peter): consider implementing this method. | 66 // TODO(peter): consider implementing this method. |
67 NOTIMPLEMENTED() << "CancelPermission not implemented for push messaging"; | 67 NOTIMPLEMENTED() << "CancelPermission not implemented for push messaging"; |
mlamouri (slow - plz ping)
2015/06/29 10:57:42
Why isn't that using the default implementation? T
Peter Beverloo
2015/06/29 12:54:21
I'm not sure, Tim added this in a permission servi
| |
68 } | 68 } |
69 | 69 |
70 // Unlike other permissions, push is decided by the following algorithm | 70 // Unlike other permissions, push is decided by the following algorithm |
71 // - You need to request it from a top level domain | 71 // - You need to request it from a top level domain |
72 // - You need to have notification permission granted. | 72 // - You need to have notification permission granted. |
73 // - You need to not have push permission explicitly blocked. | 73 // - You need to not have push permission explicitly blocked. |
74 // - If those two things are true it is granted without prompting. | 74 // - If those two things are true it is granted without prompting. |
75 // This is done to avoid double prompting for notifications and push. | 75 // This is done to avoid double prompting for notifications and push. |
76 void PushMessagingPermissionContext::DecidePermission( | 76 void PushMessagingPermissionContext::DecidePermission( |
77 content::WebContents* web_contents, | 77 content::WebContents* web_contents, |
78 const PermissionRequestID& id, | 78 const PermissionRequestID& id, |
79 const GURL& requesting_origin, | 79 const GURL& requesting_origin, |
80 const GURL& embedding_origin, | 80 const GURL& embedding_origin, |
81 bool user_gesture, | 81 bool user_gesture, |
82 const BrowserPermissionCallback& callback) { | 82 const BrowserPermissionCallback& callback) { |
83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
84 #if defined(ENABLE_NOTIFICATIONS) | 84 #if defined(ENABLE_NOTIFICATIONS) |
85 if (requesting_origin != embedding_origin) { | 85 if (requesting_origin != embedding_origin) { |
86 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 86 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
87 false /* persist */, CONTENT_SETTING_BLOCK); | 87 false /* persist */, CONTENT_SETTING_BLOCK); |
88 return; | 88 return; |
89 } | 89 } |
90 DesktopNotificationService* notification_service = | |
91 DesktopNotificationServiceFactory::GetForProfile(profile_); | |
92 DCHECK(notification_service); | |
93 | 90 |
94 notification_service->RequestPermission( | 91 NotificationPermissionContext* notification_context = |
92 NotificationPermissionContextFactory::GetForProfile(profile_); | |
93 DCHECK(notification_context); | |
mlamouri (slow - plz ping)
2015/06/29 10:57:42
I'm wondering: should PushPermissionContext::Reset
Peter Beverloo
2015/06/29 12:54:21
Not as long as we keep a separate content setting,
| |
94 | |
95 notification_context->RequestPermission( | |
95 web_contents, id, requesting_origin, user_gesture, | 96 web_contents, id, requesting_origin, user_gesture, |
96 base::Bind(&PushMessagingPermissionContext::DecidePushPermission, | 97 base::Bind(&PushMessagingPermissionContext::DecidePushPermission, |
97 weak_factory_ui_thread_.GetWeakPtr(), id, requesting_origin, | 98 weak_factory_ui_thread_.GetWeakPtr(), id, requesting_origin, |
98 embedding_origin, callback)); | 99 embedding_origin, callback)); |
99 #else | 100 #else |
100 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 101 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
101 false /* persist */, CONTENT_SETTING_BLOCK); | 102 false /* persist */, CONTENT_SETTING_BLOCK); |
102 #endif | 103 #endif |
103 } | 104 } |
104 | 105 |
(...skipping 28 matching lines...) Expand all Loading... | |
133 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 134 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
134 false /* persist */, notification_content_setting); | 135 false /* persist */, notification_content_setting); |
135 return; | 136 return; |
136 } | 137 } |
137 | 138 |
138 PermissionContextUmaUtil::PermissionGranted(kPushSettingType, | 139 PermissionContextUmaUtil::PermissionGranted(kPushSettingType, |
139 requesting_origin); | 140 requesting_origin); |
140 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 141 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
141 true /* persist */, CONTENT_SETTING_ALLOW); | 142 true /* persist */, CONTENT_SETTING_ALLOW); |
142 } | 143 } |
OLD | NEW |