Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1461)

Side by Side Diff: chrome/browser/notifications/notification_permission_context.cc

Issue 1441143006: Disable Notifications in Incognito (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@innoinherit
Patch Set: Address nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
39
40 if (profile()->IsOffTheRecord()) {
41 // Notifications are disabled in incognito, so show a custom infobar which
42 // explains this to the user, and denies permission once the infobar is
43 // dismissed (the permission has to start off as ASK to prevent websites
44 // from detecting incognito mode).
45 IncognitoDeniedInfobarDelegate::Create(
46 InfoBarService::FromWebContents(web_contents), requesting_origin,
47 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
48 base::Bind(&HostContentSettingsMap::SetContentSetting,
49 HostContentSettingsMapFactory::GetForProfile(profile()),
50 ContentSettingsPattern::FromURLNoWildcard(
51 requesting_origin.GetOrigin()),
52 ContentSettingsPattern::Wildcard(),
53 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
54 std::string(),
55 CONTENT_SETTING_BLOCK));
56 return;
57 }
58
59 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin,
60 embedding_origin, user_gesture,
61 callback);
62 }
63
23 // Unlike other permission types, granting a notification for a given origin 64 // 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 65 // will not take into account the |embedder_origin|, it will only be based
25 // on the requesting iframe origin. 66 // on the requesting iframe origin.
26 // TODO(mukai) Consider why notifications behave differently than 67 // TODO(mukai) Consider why notifications behave differently than
27 // other permissions. https://crbug.com/416894 68 // other permissions. https://crbug.com/416894
28 void NotificationPermissionContext::UpdateContentSetting( 69 void NotificationPermissionContext::UpdateContentSetting(
29 const GURL& requesting_origin, 70 const GURL& requesting_origin,
30 const GURL& embedder_origin, 71 const GURL& embedder_origin,
31 ContentSetting content_setting) { 72 ContentSetting content_setting) {
32 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 73 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
33 content_setting == CONTENT_SETTING_BLOCK); 74 content_setting == CONTENT_SETTING_BLOCK);
34 75
35 if (content_setting == CONTENT_SETTING_ALLOW) { 76 if (content_setting == CONTENT_SETTING_ALLOW) {
36 DesktopNotificationProfileUtil::GrantPermission(profile(), 77 DesktopNotificationProfileUtil::GrantPermission(profile(),
37 requesting_origin); 78 requesting_origin);
38 } else { 79 } else {
39 DesktopNotificationProfileUtil::DenyPermission(profile(), 80 DesktopNotificationProfileUtil::DenyPermission(profile(),
40 requesting_origin); 81 requesting_origin);
41 } 82 }
42 } 83 }
43 84
44 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { 85 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const {
45 return false; 86 return false;
46 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698