OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/notifications/notification_permission_context.h" | 5 #include "chrome/browser/notifications/notification_permission_context.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | |
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
9 #include "chrome/browser/infobars/infobar_service.h" | |
7 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
11 #include "chrome/browser/notifications/incognito_denied_infobar_delegate.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/common/pref_names.h" | |
14 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
8 #include "components/content_settings/core/common/content_settings_pattern.h" | 15 #include "components/content_settings/core/common/content_settings_pattern.h" |
16 #include "content/public/browser/browser_thread.h" | |
9 #include "url/gurl.h" | 17 #include "url/gurl.h" |
10 | 18 |
11 NotificationPermissionContext::NotificationPermissionContext(Profile* profile) | 19 NotificationPermissionContext::NotificationPermissionContext(Profile* profile) |
12 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {} | 20 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {} |
13 | 21 |
14 NotificationPermissionContext::~NotificationPermissionContext() {} | 22 NotificationPermissionContext::~NotificationPermissionContext() {} |
15 | 23 |
16 void NotificationPermissionContext::ResetPermission( | 24 void NotificationPermissionContext::ResetPermission( |
17 const GURL& requesting_origin, | 25 const GURL& requesting_origin, |
18 const GURL& embedder_origin) { | 26 const GURL& embedder_origin) { |
19 DesktopNotificationProfileUtil::ClearSetting( | 27 DesktopNotificationProfileUtil::ClearSetting( |
20 profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin)); | 28 profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin)); |
21 } | 29 } |
22 | 30 |
31 void NotificationPermissionContext::DecidePermission( | |
32 content::WebContents* web_contents, | |
33 const PermissionRequestID& id, | |
34 const GURL& requesting_origin, | |
35 const GURL& embedding_origin, | |
36 bool user_gesture, | |
37 const BrowserPermissionCallback& callback) { | |
38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
mlamouri (slow - plz ping)
2015/12/02 15:59:29
nit: I would leave an empty line after the DCHECK
johnme
2015/12/08 17:37:22
Done.
johnme
2015/12/08 17:37:22
Done.
| |
39 if (profile()->IsOffTheRecord()) { | |
40 // Notifications are disabled in incognito, so show a custom infobar which | |
41 // explains this to the user, and denies permission once the infobar is | |
42 // dismissed (the permission has to start off as ASK to prevent websites | |
43 // from detecting incognito mode). | |
mlamouri (slow - plz ping)
2015/12/02 15:59:29
nit: I think this comment would be better the `if`
johnme
2015/12/08 17:37:22
I kept it inside the if to clarify that you don't
| |
44 IncognitoDeniedInfobarDelegate::Create( | |
45 InfoBarService::FromWebContents(web_contents), requesting_origin, | |
46 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), | |
47 base::Bind(&HostContentSettingsMap::SetContentSetting, | |
48 HostContentSettingsMapFactory::GetForProfile(profile()), | |
49 ContentSettingsPattern::FromURLNoWildcard( | |
50 requesting_origin.GetOrigin()), | |
51 ContentSettingsPattern::Wildcard(), | |
52 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
53 std::string(), | |
54 CONTENT_SETTING_BLOCK)); | |
55 return; | |
56 } | |
57 | |
58 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, | |
59 embedding_origin, user_gesture, | |
60 callback); | |
61 } | |
62 | |
23 // Unlike other permission types, granting a notification for a given origin | 63 // Unlike other permission types, granting a notification for a given origin |
24 // will not take into account the |embedder_origin|, it will only be based | 64 // will not take into account the |embedder_origin|, it will only be based |
25 // on the requesting iframe origin. | 65 // on the requesting iframe origin. |
26 // TODO(mukai) Consider why notifications behave differently than | 66 // TODO(mukai) Consider why notifications behave differently than |
27 // other permissions. https://crbug.com/416894 | 67 // other permissions. https://crbug.com/416894 |
28 void NotificationPermissionContext::UpdateContentSetting( | 68 void NotificationPermissionContext::UpdateContentSetting( |
29 const GURL& requesting_origin, | 69 const GURL& requesting_origin, |
30 const GURL& embedder_origin, | 70 const GURL& embedder_origin, |
31 ContentSetting content_setting) { | 71 ContentSetting content_setting) { |
32 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 72 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
33 content_setting == CONTENT_SETTING_BLOCK); | 73 content_setting == CONTENT_SETTING_BLOCK); |
34 | 74 |
35 if (content_setting == CONTENT_SETTING_ALLOW) { | 75 if (content_setting == CONTENT_SETTING_ALLOW) { |
36 DesktopNotificationProfileUtil::GrantPermission(profile(), | 76 DesktopNotificationProfileUtil::GrantPermission(profile(), |
37 requesting_origin); | 77 requesting_origin); |
38 } else { | 78 } else { |
39 DesktopNotificationProfileUtil::DenyPermission(profile(), | 79 DesktopNotificationProfileUtil::DenyPermission(profile(), |
40 requesting_origin); | 80 requesting_origin); |
41 } | 81 } |
42 } | 82 } |
43 | 83 |
44 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { | 84 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { |
45 return false; | 85 return false; |
46 } | 86 } |
OLD | NEW |