Index: chrome/browser/notifications/desktop_notification_service.cc |
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc |
index 683af4eb4d17d1a37b17dfd5fac57147d33b27e5..103c0f16a3d85634f8bcec6c4bc1f8e1e8ba976c 100644 |
--- a/chrome/browser/notifications/desktop_notification_service.cc |
+++ b/chrome/browser/notifications/desktop_notification_service.cc |
@@ -37,6 +37,8 @@ |
using WebKit::WebNotificationPresenter; |
+const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; |
dhollowa
2010/07/03 02:12:01
Please wrap in anonymous namespace.
Nico
2010/07/03 02:18:29
Not necessary, consts implicitly have internal lin
|
+ |
// static |
string16 DesktopNotificationService::CreateDataUrl( |
const GURL& icon_url, const string16& title, const string16& body) { |
@@ -203,6 +205,11 @@ DesktopNotificationService::~DesktopNotificationService() { |
} |
void DesktopNotificationService::RegisterUserPrefs(PrefService* user_prefs) { |
+ if (!user_prefs->FindPreference( |
+ prefs::kDesktopNotificationDefaultContentSetting)) { |
+ user_prefs->RegisterIntegerPref( |
+ prefs::kDesktopNotificationDefaultContentSetting, kDefaultSetting); |
+ } |
if (!user_prefs->FindPreference(prefs::kDesktopNotificationAllowedOrigins)) |
user_prefs->RegisterListPref(prefs::kDesktopNotificationAllowedOrigins); |
if (!user_prefs->FindPreference(prefs::kDesktopNotificationDeniedOrigins)) |
@@ -215,8 +222,12 @@ void DesktopNotificationService::InitPrefs() { |
PrefService* prefs = profile_->GetPrefs(); |
std::vector<GURL> allowed_origins; |
std::vector<GURL> denied_origins; |
+ ContentSetting default_content_setting = CONTENT_SETTING_DEFAULT; |
if (!profile_->IsOffTheRecord()) { |
+ default_content_setting = IntToContentSetting( |
+ prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); |
+ |
const ListValue* allowed_sites = |
prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); |
if (allowed_sites) |
@@ -231,6 +242,7 @@ void DesktopNotificationService::InitPrefs() { |
} |
prefs_cache_ = new NotificationsPrefsCache(); |
+ prefs_cache_->SetCacheDefaultContentSetting(default_content_setting); |
prefs_cache_->SetCacheAllowedOrigins(allowed_origins); |
prefs_cache_->SetCacheDeniedOrigins(denied_origins); |
prefs_cache_->set_is_initialized(true); |
@@ -239,6 +251,8 @@ void DesktopNotificationService::InitPrefs() { |
void DesktopNotificationService::StartObserving() { |
if (!profile_->IsOffTheRecord()) { |
PrefService* prefs = profile_->GetPrefs(); |
+ prefs->AddPrefObserver(prefs::kDesktopNotificationDefaultContentSetting, |
+ this); |
prefs->AddPrefObserver(prefs::kDesktopNotificationAllowedOrigins, this); |
prefs->AddPrefObserver(prefs::kDesktopNotificationDeniedOrigins, this); |
} |
@@ -247,6 +261,8 @@ void DesktopNotificationService::StartObserving() { |
void DesktopNotificationService::StopObserving() { |
if (!profile_->IsOffTheRecord()) { |
PrefService* prefs = profile_->GetPrefs(); |
+ prefs->RemovePrefObserver(prefs::kDesktopNotificationDefaultContentSetting, |
+ this); |
prefs->RemovePrefObserver(prefs::kDesktopNotificationAllowedOrigins, this); |
prefs->RemovePrefObserver(prefs::kDesktopNotificationDeniedOrigins, this); |
} |
@@ -313,6 +329,18 @@ void DesktopNotificationService::Observe(NotificationType type, |
prefs_cache_.get(), |
&NotificationsPrefsCache::SetCacheDeniedOrigins, |
denied_origins)); |
+ } else if (0 == name->compare( |
+ prefs::kDesktopNotificationDefaultContentSetting)) { |
+ const ContentSetting default_content_setting = IntToContentSetting( |
+ prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); |
+ |
+ // Schedule a cache update on the IO thread. |
+ ChromeThread::PostTask( |
+ ChromeThread::IO, FROM_HERE, |
+ NewRunnableMethod( |
+ prefs_cache_.get(), |
+ &NotificationsPrefsCache::SetCacheDefaultContentSetting, |
+ default_content_setting)); |
} |
} |
@@ -377,6 +405,24 @@ void DesktopNotificationService::PersistPermissionChange( |
StartObserving(); |
} |
+ContentSetting DesktopNotificationService::GetDefaultContentSetting() { |
+ PrefService* prefs = profile_->GetPrefs(); |
+ ContentSetting setting = IntToContentSetting( |
+ prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); |
+ if (setting == CONTENT_SETTING_DEFAULT) |
+ setting = kDefaultSetting; |
+ return setting; |
+} |
+ |
+void DesktopNotificationService::SetDefaultContentSetting( |
+ ContentSetting setting) { |
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
+ profile_->GetPrefs()->SetInteger( |
+ prefs::kDesktopNotificationDefaultContentSetting, |
+ setting == CONTENT_SETTING_DEFAULT ? kDefaultSetting : setting); |
dhollowa
2010/07/03 02:12:01
There's an asymmetry here with respect to |GetDefa
Nico
2010/07/03 02:18:29
Yes, CONTENT_SETTING_DEFAULT should never be store
Nico
2010/07/03 02:33:18
(This mirrors SetDefaultContentSetting() and ReadD
|
+ // The cache is updated through the notification observer. |
+} |
+ |
void DesktopNotificationService::RequestPermission( |
const GURL& origin, int process_id, int route_id, int callback_context, |
TabContents* tab) { |