Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5302)

Unified Diff: chrome/browser/cocoa/content_settings_dialog_controller.mm

Issue 661354: Mac: Select right tab in content settings dialog. (Closed)
Patch Set: comments Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/content_settings_dialog_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/content_settings_dialog_controller.mm
diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.mm b/chrome/browser/cocoa/content_settings_dialog_controller.mm
index 0b59c50c9f9ac2cd2bd59d04c30b6be12378036d..2532a4442a750a242fec3653bd5b1ce39deb269a 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];
« no previous file with comments | « chrome/browser/cocoa/content_settings_dialog_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698