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

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: Clean up DecidePermission override, and prevent Page Info Bubble enabling permission. 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
19 namespace {
20
21 void RunClosureIgnoringBools(const base::Closure& closure,
22 bool ignored_a, bool ignored_b) {
23 closure.Run();
24 }
25
26 } // namespace
27
11 NotificationPermissionContext::NotificationPermissionContext(Profile* profile) 28 NotificationPermissionContext::NotificationPermissionContext(Profile* profile)
12 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {} 29 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {}
13 30
14 NotificationPermissionContext::~NotificationPermissionContext() {} 31 NotificationPermissionContext::~NotificationPermissionContext() {}
15 32
16 void NotificationPermissionContext::ResetPermission( 33 void NotificationPermissionContext::ResetPermission(
17 const GURL& requesting_origin, 34 const GURL& requesting_origin,
18 const GURL& embedder_origin) { 35 const GURL& embedder_origin) {
19 DesktopNotificationProfileUtil::ClearSetting( 36 DesktopNotificationProfileUtil::ClearSetting(
20 profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin)); 37 profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin));
21 } 38 }
22 39
40 void NotificationPermissionContext::DecidePermission(
41 content::WebContents* web_contents,
42 const PermissionRequestID& id,
43 const GURL& requesting_origin,
44 const GURL& embedding_origin,
45 bool user_gesture,
46 const BrowserPermissionCallback& callback) {
47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
48 if (!profile()->IsOffTheRecord()) {
mlamouri (slow - plz ping) 2015/11/28 17:00:54 nit: I think it's nice to have the special case fi
johnme 2015/11/30 15:37:20 Usually I prefer to keep the short early-out first
49 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin,
50 embedding_origin, user_gesture,
51 callback);
52 return;
53 }
54 // Notifications are disabled in incognito, so show a custom infobar which
55 // explains this to the user, and denies permission once the infobar is
56 // dismissed (the permission has to start off as ASK to prevent websites
57 // from detecting incognito mode).
58 base::Closure deny_closure =
59 base::Bind(&HostContentSettingsMap::SetContentSetting,
60 HostContentSettingsMapFactory::GetForProfile(profile()),
61 ContentSettingsPattern::FromURLNoWildcard(
62 requesting_origin.GetOrigin()),
63 ContentSettingsPattern::Wildcard(),
64 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
65 std::string(),
66 CONTENT_SETTING_BLOCK);
67 IncognitoDeniedInfobarDelegate::Create(
mlamouri (slow - plz ping) 2015/11/28 17:00:54 I thought we were moving infobar out on Desktop. U
johnme 2015/11/30 15:37:20 I'll double-check with them before landing.
68 InfoBarService::FromWebContents(web_contents), requesting_origin,
69 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
70 base::Bind(&RunClosureIgnoringBools, deny_closure));
mlamouri (slow - plz ping) 2015/11/28 17:00:54 Instead of having this closure to re-route while i
johnme 2015/11/30 15:37:20 Done (heh, yeah, realised this myself when mulling
71 }
72
23 // Unlike other permission types, granting a notification for a given origin 73 // 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 74 // will not take into account the |embedder_origin|, it will only be based
25 // on the requesting iframe origin. 75 // on the requesting iframe origin.
26 // TODO(mukai) Consider why notifications behave differently than 76 // TODO(mukai) Consider why notifications behave differently than
27 // other permissions. https://crbug.com/416894 77 // other permissions. https://crbug.com/416894
28 void NotificationPermissionContext::UpdateContentSetting( 78 void NotificationPermissionContext::UpdateContentSetting(
29 const GURL& requesting_origin, 79 const GURL& requesting_origin,
30 const GURL& embedder_origin, 80 const GURL& embedder_origin,
31 ContentSetting content_setting) { 81 ContentSetting content_setting) {
32 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 82 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
33 content_setting == CONTENT_SETTING_BLOCK); 83 content_setting == CONTENT_SETTING_BLOCK);
34 84
35 if (content_setting == CONTENT_SETTING_ALLOW) { 85 if (content_setting == CONTENT_SETTING_ALLOW) {
36 DesktopNotificationProfileUtil::GrantPermission(profile(), 86 DesktopNotificationProfileUtil::GrantPermission(profile(),
37 requesting_origin); 87 requesting_origin);
38 } else { 88 } else {
39 DesktopNotificationProfileUtil::DenyPermission(profile(), 89 DesktopNotificationProfileUtil::DenyPermission(profile(),
40 requesting_origin); 90 requesting_origin);
41 } 91 }
42 } 92 }
43 93
44 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { 94 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const {
45 return false; 95 return false;
46 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698