diff options
author | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-01 20:54:58 +0000 |
---|---|---|
committer | johnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-01 20:54:58 +0000 |
commit | 7d7696c51fcba9470ecddf095d8a6013f538fe3b (patch) | |
tree | d419d54f96947afd29f977e11856a52661991dad /chrome/browser/notifications | |
parent | a37ae1dd538a8cc96d749cf580646bf7b00bffd6 (diff) | |
download | chromium_src-7d7696c51fcba9470ecddf095d8a6013f538fe3b.zip chromium_src-7d7696c51fcba9470ecddf095d8a6013f538fe3b.tar.gz chromium_src-7d7696c51fcba9470ecddf095d8a6013f538fe3b.tar.bz2 |
Keep incognito notification preferences separate from regular ones, and don't persist them permanently.
BUG=none
TEST=use notifications in incognito
Review URL: http://codereview.chromium.org/455004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33476 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
-rw-r--r-- | chrome/browser/notifications/desktop_notification_service.cc | 63 | ||||
-rw-r--r-- | chrome/browser/notifications/desktop_notification_service.h | 3 |
2 files changed, 38 insertions, 28 deletions
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index 0c98404..8561440 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -205,16 +205,18 @@ DesktopNotificationService::~DesktopNotificationService() { // create the preferences if they don't exist yet. void DesktopNotificationService::InitPrefs() { PrefService* prefs = profile_->GetPrefs(); - const ListValue* allowed_sites; - const ListValue* denied_sites; + const ListValue* allowed_sites = NULL; + const ListValue* denied_sites = NULL; - if (!prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins)) - prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins); - allowed_sites = prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); + if (!profile_->IsOffTheRecord()) { + if (!prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins)) + prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins); + allowed_sites = prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); - if (!prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins)) - prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins); - denied_sites = prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); + if (!prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins)) + prefs->RegisterListPref(prefs::kDesktopNotificationDeniedOrigins); + denied_sites = prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); + } prefs_cache_ = new NotificationsPrefsCache(allowed_sites, denied_sites); @@ -246,16 +248,7 @@ void DesktopNotificationService::Observe(NotificationType type, void DesktopNotificationService::GrantPermission(const GURL& origin) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - PrefService* prefs = profile_->GetPrefs(); - ListValue* allowed_sites = - prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); - ListValue* denied_sites = - prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); - // Remove from the black-list and add to the white-list. - StringValue* value = new StringValue(origin.spec()); - denied_sites->Remove(*value); - allowed_sites->Append(value); - prefs->ScheduleSavePersistentPrefs(); + PersistPermissionChange(origin, true); // Schedule a cache update on the IO thread. ChromeThread::PostTask( @@ -267,16 +260,7 @@ void DesktopNotificationService::GrantPermission(const GURL& origin) { void DesktopNotificationService::DenyPermission(const GURL& origin) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - PrefService* prefs = profile_->GetPrefs(); - ListValue* allowed_sites = - prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); - ListValue* denied_sites = - prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); - StringValue* value = new StringValue(origin.spec()); - // Remove from the white-list and add to the black-list. - allowed_sites->Remove(*value); - denied_sites->Append(value); - prefs->ScheduleSavePersistentPrefs(); + PersistPermissionChange(origin, false); // Schedule a cache update on the IO thread. ChromeThread::PostTask( @@ -286,6 +270,29 @@ void DesktopNotificationService::DenyPermission(const GURL& origin) { origin)); } +void DesktopNotificationService::PersistPermissionChange( + const GURL& origin, bool is_allowed) { + // Don't persist changes when off the record. + if (profile_->IsOffTheRecord()) + return; + + PrefService* prefs = profile_->GetPrefs(); + ListValue* allowed_sites = + prefs->GetMutableList(prefs::kDesktopNotificationAllowedOrigins); + ListValue* denied_sites = + prefs->GetMutableList(prefs::kDesktopNotificationDeniedOrigins); + StringValue* value = new StringValue(origin.spec()); + // Remove from one list and add to the other. + if (is_allowed) { + allowed_sites->Append(value); + denied_sites->Remove(*value); + } else { + allowed_sites->Remove(*value); + denied_sites->Append(value); + } + prefs->ScheduleSavePersistentPrefs(); +} + void DesktopNotificationService::RequestPermission( const GURL& origin, int process_id, int route_id, int callback_context) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h index 05141ff..b384a79 100644 --- a/chrome/browser/notifications/desktop_notification_service.h +++ b/chrome/browser/notifications/desktop_notification_service.h @@ -78,6 +78,9 @@ class DesktopNotificationService : public NotificationObserver { private: void InitPrefs(); + // Save a permission change to the profile. + void PersistPermissionChange(const GURL& origin, bool is_allowed); + // Returns a display name for an origin, to be used in permission infobar // or on the frame of the notification toast. Different from the origin // itself when dealing with extensions. |