diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 00:24:20 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 00:24:20 +0000 |
commit | 8a2bc9dd3c3a8185a7fc1ecc9c70d621cfc10553 (patch) | |
tree | 2c1db8f4a6bd0f0315a32472bcd46197a78f2163 /chrome | |
parent | cbd238142237cfacd962936debbdc228a66e19d0 (diff) | |
download | chromium_src-8a2bc9dd3c3a8185a7fc1ecc9c70d621cfc10553.zip chromium_src-8a2bc9dd3c3a8185a7fc1ecc9c70d621cfc10553.tar.gz chromium_src-8a2bc9dd3c3a8185a7fc1ecc9c70d621cfc10553.tar.bz2 |
DOM UI Settings - Desktop Notification exceptions
- hook up desktop notification exceptions map to the view.
- fix the notification system for desktop notifications and geolocation so that the views update in real time
- disable double-click editing of desktop/location exceptions
BUG=57457
TEST=manual
Review URL: http://codereview.chromium.org/3709006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62361 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
5 files changed, 118 insertions, 19 deletions
diff --git a/chrome/browser/dom_ui/options/content_settings_handler.cc b/chrome/browser/dom_ui/options/content_settings_handler.cc index d989dc3..67d9acc 100644 --- a/chrome/browser/dom_ui/options/content_settings_handler.cc +++ b/chrome/browser/dom_ui/options/content_settings_handler.cc @@ -48,7 +48,7 @@ ContentSettingsType ContentSettingsTypeFromGroupName(const std::string& name) { if (name == "notifications") return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; - NOTREACHED(); + NOTREACHED() << name << " is not a recognized content settings type."; return CONTENT_SETTINGS_TYPE_DEFAULT; } @@ -64,10 +64,11 @@ std::string ContentSettingToString(ContentSetting setting) { return "session"; case CONTENT_SETTING_DEFAULT: return "default"; - default: + case CONTENT_SETTING_NUM_SETTINGS: NOTREACHED(); - return ""; } + + return ""; } ContentSetting ContentSettingFromString(const std::string& name) { @@ -80,7 +81,7 @@ ContentSetting ContentSettingFromString(const std::string& name) { if (name == "session") return CONTENT_SETTING_SESSION_ONLY; - NOTREACHED(); + NOTREACHED() << name << " is not a recognized content setting."; return CONTENT_SETTING_DEFAULT; } @@ -144,6 +145,25 @@ DictionaryValue* GetGeolocationExceptionForPage(const GURL& origin, return exception; } +// Create a DictionaryValue* that will act as a data source for a single row +// in the desktop notifications exceptions table. Ownership of the pointer is +// passed to the caller. +DictionaryValue* GetNotificationExceptionForPage( + const GURL& url, + ContentSetting setting) { + DictionaryValue* exception = new DictionaryValue(); + exception->Set( + kDisplayPattern, + new StringValue(content_settings_helper::OriginToString(url))); + exception->Set( + kSetting, + new StringValue(ContentSettingToString(setting))); + exception->Set( + kOrigin, + new StringValue(url.spec())); + return exception; +} + } // namespace ContentSettingsHandler::ContentSettingsHandler() { @@ -281,22 +301,54 @@ void ContentSettingsHandler::Initialize() { notification_registrar_.Add( this, NotificationType::CONTENT_SETTINGS_CHANGED, Source<const HostContentSettingsMap>(settings_map)); + notification_registrar_.Add( + this, NotificationType::GEOLOCATION_DEFAULT_CHANGED, + NotificationService::AllSources()); + notification_registrar_.Add( + this, NotificationType::GEOLOCATION_SETTINGS_CHANGED, + NotificationService::AllSources()); + notification_registrar_.Add( + this, NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, + NotificationService::AllSources()); + notification_registrar_.Add( + this, NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, + NotificationService::AllSources()); } void ContentSettingsHandler::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - if (type != NotificationType::CONTENT_SETTINGS_CHANGED) - return OptionsPageUIHandler::Observe(type, source, details); - - const ContentSettingsDetails* settings_details = - static_cast<Details<const ContentSettingsDetails> >(details).ptr(); - - // TODO(estade): we pretend update_all() is always true. - if (settings_details->update_all_types()) - UpdateAllExceptionsViewsFromModel(); - else - UpdateExceptionsViewFromModel(settings_details->type()); + switch (type.value) { + case NotificationType::CONTENT_SETTINGS_CHANGED: { + const ContentSettingsDetails* settings_details = + static_cast<Details<const ContentSettingsDetails> >(details).ptr(); + + // TODO(estade): we pretend update_all() is always true. + if (settings_details->update_all_types()) + UpdateAllExceptionsViewsFromModel(); + else + UpdateExceptionsViewFromModel(settings_details->type()); + break; + } + case NotificationType::GEOLOCATION_DEFAULT_CHANGED: { + UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); + break; + } + case NotificationType::GEOLOCATION_SETTINGS_CHANGED: { + UpdateGeolocationExceptionsView(); + break; + } + case NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED: { + UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); + break; + } + case NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED: { + UpdateNotificationExceptionsView(); + break; + } + default: + OptionsPageUIHandler::Observe(type, source, details); + } } void ContentSettingsHandler::UpdateSettingDefaultFromModel( @@ -381,13 +433,36 @@ void ContentSettingsHandler::UpdateGeolocationExceptionsView() { dom_ui_->CallJavascriptFunction( L"ContentSettings.setExceptions", type_string, exceptions); - // The default may also have changed (we won't get a separate notification). - // If it hasn't changed, this call will be harmless. + // This is mainly here to keep this function ideologically parallel to + // UpdateExceptionsViewFromHostContentSettingsMap(). UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_GEOLOCATION); } void ContentSettingsHandler::UpdateNotificationExceptionsView() { - NOTIMPLEMENTED(); + DesktopNotificationService* service = + dom_ui_->GetProfile()->GetDesktopNotificationService(); + + std::vector<GURL> allowed(service->GetAllowedOrigins()); + std::vector<GURL> blocked(service->GetBlockedOrigins()); + + ListValue exceptions; + for (size_t i = 0; i < allowed.size(); ++i) { + exceptions.Append( + GetNotificationExceptionForPage(allowed[i], CONTENT_SETTING_ALLOW)); + } + for (size_t i = 0; i < blocked.size(); ++i) { + exceptions.Append( + GetNotificationExceptionForPage(blocked[i], CONTENT_SETTING_BLOCK)); + } + + StringValue type_string( + ContentSettingsTypeToGroupName(CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); + dom_ui_->CallJavascriptFunction( + L"ContentSettings.setExceptions", type_string, exceptions); + + // This is mainly here to keep this function ideologically parallel to + // UpdateExceptionsViewFromHostContentSettingsMap(). + UpdateSettingDefaultFromModel(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); } void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( diff --git a/chrome/browser/geolocation/geolocation_content_settings_map.cc b/chrome/browser/geolocation/geolocation_content_settings_map.cc index c302d4e..0bf798c 100644 --- a/chrome/browser/geolocation/geolocation_content_settings_map.cc +++ b/chrome/browser/geolocation/geolocation_content_settings_map.cc @@ -117,6 +117,11 @@ void GeolocationContentSettingsMap::SetDefaultContentSetting( profile_->GetPrefs()->SetInteger(prefs::kGeolocationDefaultContentSetting, setting == CONTENT_SETTING_DEFAULT ? kDefaultSetting : setting); + + NotificationService::current()->Notify( + NotificationType::GEOLOCATION_DEFAULT_CHANGED, + Source<GeolocationContentSettingsMap>(this), + NotificationService::NoDetails()); } void GeolocationContentSettingsMap::SetContentSetting( diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index f6e3ccd..4df30e9 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -328,6 +328,11 @@ void DesktopNotificationService::Observe(NotificationType type, &NotificationsPrefsCache::SetCacheDeniedOrigins, denied_origins)); } else if (name == prefs::kDesktopNotificationDefaultContentSetting) { + NotificationService::current()->Notify( + NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED, + Source<DesktopNotificationService>(this), + NotificationService::NoDetails()); + const ContentSetting default_content_setting = IntToContentSetting( prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); diff --git a/chrome/browser/resources/options/content_settings_exceptions_area.js b/chrome/browser/resources/options/content_settings_exceptions_area.js index f6ee979..4d3f4ad 100644 --- a/chrome/browser/resources/options/content_settings_exceptions_area.js +++ b/chrome/browser/resources/options/content_settings_exceptions_area.js @@ -106,6 +106,11 @@ cr.define('options.contentSettings', function() { var listItem = this; this.ondblclick = function(event) { + // Editing notifications and geolocation is disabled for now. + if (listItem.contentType == 'notifications' || + listItem.contentType == 'location') + return; + listItem.editing = true; }; @@ -401,7 +406,8 @@ cr.define('options.contentSettings', function() { args.push(selectedItems[i]['origin']); args.push(selectedItems[i]['embeddingOrigin']); } else if (this.contentType == 'notifications') { - // TODO(estade): fill this in. + args.push(selectedItems[i]['origin']); + args.push(selectedItems[i]['setting']); } else { args.push(this.mode); args.push(selectedItems[i]['displayPattern']); diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 3440538..0ee2429 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -1018,11 +1018,19 @@ class NotificationType { // TabSpecificContentSettings object, there are no details. COLLECTED_COOKIES_SHOWN, + // Sent when the default geolocation setting has changed. The source is the + // GeolocationContentSettingsMap, the details are None. + GEOLOCATION_DEFAULT_CHANGED, + // Sent when a non-default setting in the the geolocation content settings // map has changed. The source is the GeolocationContentSettingsMap, the // details are None. GEOLOCATION_SETTINGS_CHANGED, + // Sent when the default setting for desktop notifications has changed. + // The source is the DesktopNotificationService, the details are None. + DESKTOP_NOTIFICATION_DEFAULT_CHANGED, + // Sent when a non-default setting in the the notification content settings // map has changed. The source is the DesktopNotificationService, the // details are None. |