diff options
-rw-r--r-- | base/cocoa_protocols_mac.h | 1 | ||||
-rw-r--r-- | chrome/app/nibs/ContentSettings.xib | 24 | ||||
-rw-r--r-- | chrome/browser/cocoa/content_settings_dialog_controller.h | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/content_settings_dialog_controller.mm | 50 |
4 files changed, 75 insertions, 6 deletions
diff --git a/base/cocoa_protocols_mac.h b/base/cocoa_protocols_mac.h index d3d06f4..a98d472 100644 --- a/base/cocoa_protocols_mac.h +++ b/base/cocoa_protocols_mac.h @@ -30,6 +30,7 @@ DEFINE_EMPTY_PROTOCOL(NSOpenSavePanelDelegate) DEFINE_EMPTY_PROTOCOL(NSOutlineViewDelegate) DEFINE_EMPTY_PROTOCOL(NSTableViewDataSource) DEFINE_EMPTY_PROTOCOL(NSTableViewDelegate) +DEFINE_EMPTY_PROTOCOL(NSTabViewDelegate) DEFINE_EMPTY_PROTOCOL(NSTextFieldDelegate) DEFINE_EMPTY_PROTOCOL(NSTextViewDelegate) DEFINE_EMPTY_PROTOCOL(NSWindowDelegate) diff --git a/chrome/app/nibs/ContentSettings.xib b/chrome/app/nibs/ContentSettings.xib index 2cf8c57..fbb58cd 100644 --- a/chrome/app/nibs/ContentSettings.xib +++ b/chrome/app/nibs/ContentSettings.xib @@ -8,7 +8,7 @@ <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="68"/> + <integer value="2"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -1818,6 +1818,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> <int key="connectionID">112</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">delegate</string> + <reference key="source" ref="604468971"/> + <reference key="destination" ref="1001"/> + </object> + <int key="connectionID">113</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">tabView_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="604468971"/> + </object> + <int key="connectionID">114</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -2555,7 +2571,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <nil key="sourceID"/> - <int key="maxID">112</int> + <int key="maxID">114</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -2594,6 +2610,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>id</string> </object> </object> + <object class="NSMutableDictionary" key="outlets"> + <string key="NS.key.0">tabView_</string> + <string key="NS.object.0">NSTabView</string> + </object> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">browser/cocoa/content_settings_dialog_controller.h</string> diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.h b/chrome/browser/cocoa/content_settings_dialog_controller.h index 7a4bc8c..40dceca 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.h +++ b/chrome/browser/cocoa/content_settings_dialog_controller.h @@ -5,19 +5,23 @@ #import <Cocoa/Cocoa.h> #import "base/cocoa_protocols_mac.h" +#include "base/scoped_ptr.h" #include "chrome/common/content_settings_types.h" #include "chrome/browser/pref_member.h" +class PrefObserverBridge; class Profile; // This controller manages a dialog that lets the user manage the content // settings for several content setting types. @interface ContentSettingsDialogController - : NSWindowController<NSWindowDelegate> { + : NSWindowController<NSWindowDelegate, NSTabViewDelegate> { @private + IBOutlet NSTabView* tabView_; Profile* profile_; // weak IntegerPrefMember lastSelectedTab_; BooleanPrefMember clearSiteDataOnExit_; + scoped_ptr<PrefObserverBridge> observer_; // Watches for pref changes. } // Show the content settings dialog associated with the given profile (or the diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.mm b/chrome/browser/cocoa/content_settings_dialog_controller.mm index 0b59c50..2532a44 100644 --- a/chrome/browser/cocoa/content_settings_dialog_controller.mm +++ b/chrome/browser/cocoa/content_settings_dialog_controller.mm @@ -13,7 +13,9 @@ #import "chrome/browser/cocoa/content_exceptions_window_controller.h" #import "chrome/browser/cocoa/cookies_window_controller.h" #import "chrome/browser/host_content_settings_map.h" +#include "chrome/browser/pref_service.h" #include "chrome/browser/profile.h" +#include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "grit/locale_settings.h" @@ -38,6 +40,7 @@ ContentSettingsDialogController* g_instance = nil; @interface ContentSettingsDialogController(Private) - (id)initWithProfile:(Profile*)profile; +- (void)selectTab:(ContentSettingsType)settingsType; - (void)showExceptionsForType:(ContentSettingsType)settingsType; // Properties that the radio groups and checkboxes are bound to. @@ -50,6 +53,29 @@ ContentSettingsDialogController* g_instance = nil; @property(assign, nonatomic) NSInteger pluginsEnabledIndex; @end +// A C++ class registered for changes in preferences. +class PrefObserverBridge : public NotificationObserver { + public: + PrefObserverBridge(ContentSettingsDialogController* controller) + : controller_(controller) {} + + virtual ~PrefObserverBridge() {} + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + std::wstring* pref_name = Details<std::wstring>(details).ptr(); + if (type == NotificationType::PREF_CHANGED && + *pref_name == prefs::kClearSiteDataOnExit) { + // Update UI. + [controller_ setClearSiteDataOnExit:[controller_ clearSiteDataOnExit]]; + } + } + + private: + ContentSettingsDialogController* controller_; // weak, owns us +}; + @implementation ContentSettingsDialogController @@ -72,10 +98,9 @@ ContentSettingsDialogController* g_instance = nil; if (settingsType == CONTENT_SETTINGS_TYPE_DEFAULT) settingsType = CONTENT_SETTINGS_TYPE_COOKIES; } - // TODO(thakis): Actually select desired tab. - // TODO(thakis): Safe current tab on tab switch as well. // TODO(thakis): Autosave window pos. + [g_instance selectTab:settingsType]; [g_instance showWindow:nil]; return g_instance; } @@ -88,7 +113,7 @@ ContentSettingsDialogController* g_instance = nil; if ((self = [super initWithWindowNibPath:nibpath owner:self])) { profile_ = profile; - // TODO(thakis): Listen for kClearSiteDataOnExit pref change notifications. + observer_.reset(new PrefObserverBridge(self)); clearSiteDataOnExit_.Init(prefs::kClearSiteDataOnExit, profile->GetPrefs(), NULL); @@ -104,11 +129,30 @@ ContentSettingsDialogController* g_instance = nil; DCHECK_EQ(self, [[self window] delegate]); } +// NSWindowDelegate method. - (void)windowWillClose:(NSNotification*)notification { [self autorelease]; g_instance = nil; } +- (void)selectTab:(ContentSettingsType)settingsType { + [self window]; // Make sure the nib file is loaded. + DCHECK(tabView_); + [tabView_ selectTabViewItemAtIndex:settingsType]; +} + +// NSTabViewDelegate method. +- (void) tabView:(NSTabView*)tabView + didSelectTabViewItem:(NSTabViewItem*)tabViewItem { + DCHECK_EQ(tabView_, tabView); + NSInteger index = [tabView indexOfTabViewItem:tabViewItem]; + DCHECK_GT(index, CONTENT_SETTINGS_TYPE_DEFAULT); + DCHECK_LT(index, CONTENT_SETTINGS_NUM_TYPES); + if (index > CONTENT_SETTINGS_TYPE_DEFAULT && + index < CONTENT_SETTINGS_NUM_TYPES) + lastSelectedTab_.SetValue(index); +} + // Let esc close the window. - (void)cancel:(id)sender { [self close]; |