diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 22:43:26 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-13 22:43:26 +0000 |
commit | 06e29a9c6a9f6279fcaca61fe10d7d31021b8b6e (patch) | |
tree | 7bbef5f0965da6cd321a11dd812e121fbd243161 | |
parent | 94f9c526e7d1241b8889ad66c5a72c2287d0f1fe (diff) | |
download | chromium_src-06e29a9c6a9f6279fcaca61fe10d7d31021b8b6e.zip chromium_src-06e29a9c6a9f6279fcaca61fe10d7d31021b8b6e.tar.gz chromium_src-06e29a9c6a9f6279fcaca61fe10d7d31021b8b6e.tar.bz2 |
DOM UI Settings - content settings exceptions tables
show/hide the OTR exceptions tables when an OTR profile comes into being or its flame is extinguished
BUG=57459
TEST=manual
Review URL: http://codereview.chromium.org/3757002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62471 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/dom_ui/options/content_settings_handler.cc | 66 | ||||
-rw-r--r-- | chrome/browser/dom_ui/options/content_settings_handler.h | 12 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 2 | ||||
-rw-r--r-- | chrome/browser/profile_impl.cc | 5 | ||||
-rw-r--r-- | chrome/browser/resources/options/content_settings.js | 24 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 4 |
6 files changed, 98 insertions, 15 deletions
diff --git a/chrome/browser/dom_ui/options/content_settings_handler.cc b/chrome/browser/dom_ui/options/content_settings_handler.cc index 67d9acc..8ba0982 100644 --- a/chrome/browser/dom_ui/options/content_settings_handler.cc +++ b/chrome/browser/dom_ui/options/content_settings_handler.cc @@ -297,6 +297,13 @@ void ContentSettingsHandler::Initialize() { dom_ui_->CallJavascriptFunction( L"ContentSettings.setBlockThirdPartyCookies", *block_3rd_party.get()); + notification_registrar_.Add( + this, NotificationType::OTR_PROFILE_CREATED, + NotificationService::AllSources()); + notification_registrar_.Add( + this, NotificationType::PROFILE_DESTROYED, + NotificationService::AllSources()); + UpdateAllExceptionsViewsFromModel(); notification_registrar_.Add( this, NotificationType::CONTENT_SETTINGS_CHANGED, @@ -319,6 +326,18 @@ void ContentSettingsHandler::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { switch (type.value) { + case NotificationType::PROFILE_DESTROYED: { + Profile* profile = static_cast<Source<Profile> >(source).ptr(); + if (profile->IsOffTheRecord()) + dom_ui_->CallJavascriptFunction(L"ContentSettings.OTRProfileDestroyed"); + break; + } + + case NotificationType::OTR_PROFILE_CREATED: { + UpdateAllOTRExceptionsViewsFromModel(); + break; + } + case NotificationType::CONTENT_SETTINGS_CHANGED: { const ContentSettingsDetails* settings_details = static_cast<Details<const ContentSettingsDetails> >(details).ptr(); @@ -330,22 +349,27 @@ void ContentSettingsHandler::Observe(NotificationType type, 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); } @@ -384,6 +408,19 @@ void ContentSettingsHandler::UpdateAllExceptionsViewsFromModel() { } } +void ContentSettingsHandler::UpdateAllOTRExceptionsViewsFromModel() { + for (int type = CONTENT_SETTINGS_TYPE_DEFAULT + 1; + type < CONTENT_SETTINGS_NUM_TYPES; ++type) { + if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION || + type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { + continue; + } + + UpdateExceptionsViewFromOTRHostContentSettingsMap( + static_cast<ContentSettingsType>(type)); + } +} + void ContentSettingsHandler::UpdateExceptionsViewFromModel( ContentSettingsType type) { if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) @@ -479,24 +516,31 @@ void ContentSettingsHandler::UpdateExceptionsViewFromHostContentSettingsMap( dom_ui_->CallJavascriptFunction( L"ContentSettings.setExceptions", type_string, exceptions); + UpdateExceptionsViewFromOTRHostContentSettingsMap(type); + // The default may also have changed (we won't get a separate notification). // If it hasn't changed, this call will be harmless. UpdateSettingDefaultFromModel(type); +} +void ContentSettingsHandler::UpdateExceptionsViewFromOTRHostContentSettingsMap( + ContentSettingsType type) { const HostContentSettingsMap* otr_settings_map = GetOTRContentSettingsMap(); - if (otr_settings_map) { - HostContentSettingsMap::SettingsForOneType otr_entries; - otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); - - ListValue otr_exceptions; - for (size_t i = 0; i < otr_entries.size(); ++i) { - otr_exceptions.Append(GetExceptionForPage(entries[i].first, - entries[i].second)); - } + if (!otr_settings_map) + return; - dom_ui_->CallJavascriptFunction( - L"ContentSettings.setOTRExceptions", type_string, otr_exceptions); + HostContentSettingsMap::SettingsForOneType otr_entries; + otr_settings_map->GetSettingsForOneType(type, "", &otr_entries); + + ListValue otr_exceptions; + for (size_t i = 0; i < otr_entries.size(); ++i) { + otr_exceptions.Append(GetExceptionForPage(otr_entries[i].first, + otr_entries[i].second)); } + + StringValue type_string(ContentSettingsTypeToGroupName(type)); + dom_ui_->CallJavascriptFunction( + L"ContentSettings.setOTRExceptions", type_string, otr_exceptions); } void ContentSettingsHandler::RegisterMessages() { diff --git a/chrome/browser/dom_ui/options/content_settings_handler.h b/chrome/browser/dom_ui/options/content_settings_handler.h index b894135..7874dae 100644 --- a/chrome/browser/dom_ui/options/content_settings_handler.h +++ b/chrome/browser/dom_ui/options/content_settings_handler.h @@ -41,15 +41,21 @@ class ContentSettingsHandler : public OptionsPageUIHandler { // Clobbers and rebuilds the specific content setting type exceptions table. void UpdateExceptionsViewFromModel(ContentSettingsType type); - // Clobbers and rebuilds all the exceptions tables in the page. + // Clobbers and rebuilds all the exceptions tables in the page (both normal + // and OTR tables). void UpdateAllExceptionsViewsFromModel(); + // As above, but only OTR tables. + void UpdateAllOTRExceptionsViewsFromModel(); // Clobbers and rebuilds just the geolocation exception table. void UpdateGeolocationExceptionsView(); // Clobbers and rebuilds just the desktop notification exception table. void UpdateNotificationExceptionsView(); - // Clobbers and rebuilds an exception table that's managed by the - // host content settings map. + // Clobbers and rebuilds an exception table that's managed by the host content + // settings map. void UpdateExceptionsViewFromHostContentSettingsMap(ContentSettingsType type); + // As above, but acts on the OTR table for the content setting type. + void UpdateExceptionsViewFromOTRHostContentSettingsMap( + ContentSettingsType type); // Callbacks used by the page ------------------------------------------------ diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 56e5e6e..79c091b 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -628,6 +628,6 @@ class OffTheRecordProfileImpl : public Profile, DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); }; -Profile *Profile::CreateOffTheRecordProfile() { +Profile* Profile::CreateOffTheRecordProfile() { return new OffTheRecordProfileImpl(this); } diff --git a/chrome/browser/profile_impl.cc b/chrome/browser/profile_impl.cc index c3e90d3..e2ea94a 100644 --- a/chrome/browser/profile_impl.cc +++ b/chrome/browser/profile_impl.cc @@ -564,6 +564,11 @@ Profile* ProfileImpl::GetOffTheRecordProfile() { if (!off_the_record_profile_.get()) { scoped_ptr<Profile> p(CreateOffTheRecordProfile()); off_the_record_profile_.swap(p); + + NotificationService::current()->Notify( + NotificationType::OTR_PROFILE_CREATED, + Source<Profile>(off_the_record_profile_.get()), + NotificationService::NoDetails()); } return off_the_record_profile_.get(); } diff --git a/chrome/browser/resources/options/content_settings.js b/chrome/browser/resources/options/content_settings.js index 686d5e9..37dec2b 100644 --- a/chrome/browser/resources/options/content_settings.js +++ b/chrome/browser/resources/options/content_settings.js @@ -121,6 +121,30 @@ cr.define('options', function() { for (var i = 0; i < list.length; i++) { exceptionsList.addException(list[i]); } + + // If an OTR table is added while the normal exceptions area is already + // showing (because the exceptions area is already expanded), then show + // the new OTR table. + var parentExceptionsArea = + document.querySelector('div[contentType=' + type + '][mode=normal]'); + if (!parentExceptionsArea.classList.contains('hidden')) { + exceptionsArea.classList.remove('hidden'); + exceptionsArea.querySelector('list').redraw(); + } + }; + + /** + * Clears and hides the incognito exceptions lists. + */ + ContentSettings.OTRProfileDestroyed = function() { + var exceptionsAreas = + document.querySelectorAll('div[contentType][mode=otr]'); + + for (var i = 0; i < exceptionsAreas.length; i++) { + exceptionsAreas[i].otrProfileExists = false; + exceptionsAreas[i].classList.add('hidden'); + exceptionsAreas[i].querySelector('list').clear(); + } }; /** diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 0ee2429..1ba2c39 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -641,6 +641,10 @@ class NotificationType { // browser window should notify the user of this error. PROFILE_ERROR, + // Sent after an incognito profile has been created. The details are none + // and the source is the new profile. + OTR_PROFILE_CREATED, + // Sent before a Profile is destroyed. The details are // none and the source is a Profile*. PROFILE_DESTROYED, |