| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/cocoa/content_settings_dialog_controller.h" | 5 #import "chrome/browser/cocoa/content_settings_dialog_controller.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
| 11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/browser_window.h" | 12 #include "chrome/browser/browser_window.h" |
| 13 #import "chrome/browser/cocoa/content_exceptions_window_controller.h" | 13 #import "chrome/browser/cocoa/content_exceptions_window_controller.h" |
| 14 #import "chrome/browser/cocoa/cookies_window_controller.h" | 14 #import "chrome/browser/cocoa/cookies_window_controller.h" |
| 15 #import "chrome/browser/cocoa/geolocation_exceptions_window_controller.h" | 15 #import "chrome/browser/cocoa/geolocation_exceptions_window_controller.h" |
| 16 #import "chrome/browser/cocoa/l10n_util.h" | 16 #import "chrome/browser/cocoa/l10n_util.h" |
| 17 #import "chrome/browser/geolocation/geolocation_content_settings_map.h" | 17 #import "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 18 #import "chrome/browser/host_content_settings_map.h" | 18 #import "chrome/browser/host_content_settings_map.h" |
| 19 #include "chrome/browser/pref_service.h" | 19 #include "chrome/browser/pref_service.h" |
| 20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 21 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "grit/locale_settings.h" | 24 #include "grit/locale_settings.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Index of the "enabled" and "disabled" radio group settings in all tabs except | |
| 29 // for the cookies tab. | |
| 30 const NSInteger kEnabledIndex = 0; | |
| 31 const NSInteger kDisabledIndex = 1; | |
| 32 | |
| 33 // Indices of the various cookie settings in the cookie radio group. | |
| 34 const NSInteger kCookieEnabledIndex = 0; | |
| 35 const NSInteger kCookieAskIndex = 1; | |
| 36 const NSInteger kCookieDisabledIndex = 2; | |
| 37 | |
| 38 // Stores the currently visible content settings dialog, if any. | 28 // Stores the currently visible content settings dialog, if any. |
| 39 ContentSettingsDialogController* g_instance = nil; | 29 ContentSettingsDialogController* g_instance = nil; |
| 40 | 30 |
| 41 // Indices of the various geolocation settings in the geolocation radio group. | |
| 42 const NSInteger kGeolocationEnabledIndex = 0; | |
| 43 const NSInteger kGeolocationAskIndex = 1; | |
| 44 const NSInteger kGeolocationDisabledIndex = 2; | |
| 45 | |
| 46 // Walks views in top-down order, wraps each to their current width, and moves | 31 // Walks views in top-down order, wraps each to their current width, and moves |
| 47 // the latter ones down to prevent overlaps. | 32 // the latter ones down to prevent overlaps. |
| 48 CGFloat VerticallyReflowGroup(NSArray* views) { | 33 CGFloat VerticallyReflowGroup(NSArray* views) { |
| 49 views = [views sortedArrayUsingFunction:cocoa_l10n_util::CompareFrameY | 34 views = [views sortedArrayUsingFunction:cocoa_l10n_util::CompareFrameY |
| 50 context:NULL]; | 35 context:NULL]; |
| 51 CGFloat localVerticalShift = 0; | 36 CGFloat localVerticalShift = 0; |
| 52 for (NSInteger index = [views count] - 1; index >= 0; --index) { | 37 for (NSInteger index = [views count] - 1; index >= 0; --index) { |
| 53 NSView* view = [views objectAtIndex:index]; | 38 NSView* view = [views objectAtIndex:index]; |
| 54 | 39 |
| 55 // Since the tab pane is in a horizontal resizer in IB, it's convenient | 40 // Since the tab pane is in a horizontal resizer in IB, it's convenient |
| (...skipping 14 matching lines...) Expand all Loading... |
| 70 } | 55 } |
| 71 | 56 |
| 72 } // namespace | 57 } // namespace |
| 73 | 58 |
| 74 | 59 |
| 75 @interface ContentSettingsDialogController(Private) | 60 @interface ContentSettingsDialogController(Private) |
| 76 - (id)initWithProfile:(Profile*)profile; | 61 - (id)initWithProfile:(Profile*)profile; |
| 77 - (void)selectTab:(ContentSettingsType)settingsType; | 62 - (void)selectTab:(ContentSettingsType)settingsType; |
| 78 - (void)showExceptionsForType:(ContentSettingsType)settingsType; | 63 - (void)showExceptionsForType:(ContentSettingsType)settingsType; |
| 79 | 64 |
| 80 // Properties that the radio groups and checkboxes are bound to. | 65 // Callback when preferences are changed. |prefName| is the name of the |
| 81 @property(assign, nonatomic) NSInteger cookieSettingIndex; | 66 // pref that has changed. |
| 82 @property(assign, nonatomic) BOOL blockThirdPartyCookies; | 67 - (void)prefChanged:(std::wstring*)prefName; |
| 83 @property(assign, nonatomic) BOOL clearSiteDataOnExit; | |
| 84 @property(assign, nonatomic) NSInteger imagesEnabledIndex; | |
| 85 @property(assign, nonatomic) NSInteger javaScriptEnabledIndex; | |
| 86 @property(assign, nonatomic) NSInteger popupsEnabledIndex; | |
| 87 @property(assign, nonatomic) NSInteger pluginsEnabledIndex; | |
| 88 @property(assign, nonatomic) NSInteger geolocationSettingIndex; | |
| 89 | 68 |
| 90 @end | 69 @end |
| 91 | 70 |
| 92 namespace ContentSettingsDialogControllerInternal { | 71 namespace ContentSettingsDialogControllerInternal { |
| 93 | 72 |
| 94 // A C++ class registered for changes in preferences. | 73 // A C++ class registered for changes in preferences. |
| 95 class PrefObserverBridge : public NotificationObserver { | 74 class PrefObserverBridge : public NotificationObserver { |
| 96 public: | 75 public: |
| 97 PrefObserverBridge(ContentSettingsDialogController* controller) | 76 PrefObserverBridge(ContentSettingsDialogController* controller) |
| 98 : controller_(controller) {} | 77 : controller_(controller) {} |
| 99 | 78 |
| 100 virtual ~PrefObserverBridge() {} | 79 virtual ~PrefObserverBridge() {} |
| 101 | 80 |
| 102 virtual void Observe(NotificationType type, | 81 virtual void Observe(NotificationType type, |
| 103 const NotificationSource& source, | 82 const NotificationSource& source, |
| 104 const NotificationDetails& details) { | 83 const NotificationDetails& details) { |
| 105 if (type == NotificationType::PREF_CHANGED) { | 84 if (!disabled_ && type == NotificationType::PREF_CHANGED) { |
| 106 std::wstring* pref_name = Details<std::wstring>(details).ptr(); | 85 [controller_ prefChanged:Details<std::wstring>(details).ptr()]; |
| 107 if (*pref_name == prefs::kClearSiteDataOnExit) { | |
| 108 // Update UI. | |
| 109 [controller_ setClearSiteDataOnExit:[controller_ clearSiteDataOnExit]]; | |
| 110 } | |
| 111 } | 86 } |
| 112 } | 87 } |
| 113 | 88 |
| 89 void SetDisabled(bool disabled) { |
| 90 disabled_ = disabled; |
| 91 } |
| 92 |
| 114 private: | 93 private: |
| 115 ContentSettingsDialogController* controller_; // weak, owns us | 94 ContentSettingsDialogController* controller_; // weak, owns us |
| 95 bool disabled_; // true if notifications should be ignored. |
| 96 }; |
| 97 |
| 98 // A C++ utility class to disable notifications for PrefsObserverBridge. |
| 99 // The intended usage is to create on the stack. |
| 100 class PrefObserverDisabler { |
| 101 public: |
| 102 PrefObserverDisabler(PrefObserverBridge *bridge) : bridge_(bridge) { |
| 103 bridge_->SetDisabled(true); |
| 104 } |
| 105 |
| 106 ~PrefObserverDisabler() { |
| 107 bridge_->SetDisabled(false); |
| 108 } |
| 109 |
| 110 private: |
| 111 PrefObserverBridge *bridge_; |
| 116 }; | 112 }; |
| 117 | 113 |
| 118 } // ContentSettingsDialogControllerInternal | 114 } // ContentSettingsDialogControllerInternal |
| 119 | 115 |
| 120 @implementation ContentSettingsDialogController | 116 @implementation ContentSettingsDialogController |
| 121 | 117 |
| 122 +(id)showContentSettingsForType:(ContentSettingsType)settingsType | 118 + (id)showContentSettingsForType:(ContentSettingsType)settingsType |
| 123 profile:(Profile*)profile { | 119 profile:(Profile*)profile { |
| 124 profile = profile->GetOriginalProfile(); | 120 profile = profile->GetOriginalProfile(); |
| 125 if (!g_instance) | 121 if (!g_instance) |
| 126 g_instance = [[self alloc] initWithProfile:profile]; | 122 g_instance = [[self alloc] initWithProfile:profile]; |
| 127 | 123 |
| 128 // The code doesn't expect multiple profiles. Check that support for that | 124 // The code doesn't expect multiple profiles. Check that support for that |
| 129 // hasn't been added. | 125 // hasn't been added. |
| 130 DCHECK(g_instance->profile_ == profile); | 126 DCHECK(g_instance->profile_ == profile); |
| 131 | 127 |
| 132 // Select desired tab. | 128 // Select desired tab. |
| 133 if (settingsType == CONTENT_SETTINGS_TYPE_DEFAULT) { | 129 if (settingsType == CONTENT_SETTINGS_TYPE_DEFAULT) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 150 DCHECK(profile); | 146 DCHECK(profile); |
| 151 NSString* nibpath = | 147 NSString* nibpath = |
| 152 [mac_util::MainAppBundle() pathForResource:@"ContentSettings" | 148 [mac_util::MainAppBundle() pathForResource:@"ContentSettings" |
| 153 ofType:@"nib"]; | 149 ofType:@"nib"]; |
| 154 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 150 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 155 profile_ = profile; | 151 profile_ = profile; |
| 156 | 152 |
| 157 observer_.reset( | 153 observer_.reset( |
| 158 new ContentSettingsDialogControllerInternal::PrefObserverBridge(self)); | 154 new ContentSettingsDialogControllerInternal::PrefObserverBridge(self)); |
| 159 clearSiteDataOnExit_.Init(prefs::kClearSiteDataOnExit, | 155 clearSiteDataOnExit_.Init(prefs::kClearSiteDataOnExit, |
| 160 profile->GetPrefs(), observer_.get()); | 156 profile_->GetPrefs(), observer_.get()); |
| 157 |
| 158 // Manually observe notifications for preferences that are grouped in |
| 159 // the HostContentSettingsMap or GeolocationContentSettingsMap. |
| 160 PrefService* prefs = profile_->GetPrefs(); |
| 161 prefs->AddPrefObserver(prefs::kBlockThirdPartyCookies, observer_.get()); |
| 162 prefs->AddPrefObserver(prefs::kDefaultContentSettings, observer_.get()); |
| 163 prefs->AddPrefObserver(prefs::kGeolocationDefaultContentSetting, |
| 164 observer_.get()); |
| 161 | 165 |
| 162 // We don't need to observe changes in this value. | 166 // We don't need to observe changes in this value. |
| 163 lastSelectedTab_.Init(prefs::kContentSettingsWindowLastTabIndex, | 167 lastSelectedTab_.Init(prefs::kContentSettingsWindowLastTabIndex, |
| 164 profile->GetPrefs(), NULL); | 168 profile_->GetPrefs(), NULL); |
| 165 } | 169 } |
| 166 return self; | 170 return self; |
| 167 } | 171 } |
| 168 | 172 |
| 173 - (void)dealloc { |
| 174 if (profile_) { |
| 175 PrefService* prefs = profile_->GetPrefs(); |
| 176 prefs->RemovePrefObserver(prefs::kBlockThirdPartyCookies, observer_.get()); |
| 177 prefs->RemovePrefObserver(prefs::kDefaultContentSettings, observer_.get()); |
| 178 prefs->RemovePrefObserver(prefs::kGeolocationDefaultContentSetting, |
| 179 observer_.get()); |
| 180 } |
| 181 |
| 182 [super dealloc]; |
| 183 } |
| 184 |
| 169 - (void)closeExceptionsSheet { | 185 - (void)closeExceptionsSheet { |
| 170 NSWindow* attachedSheet = [[self window] attachedSheet]; | 186 NSWindow* attachedSheet = [[self window] attachedSheet]; |
| 171 if (attachedSheet) { | 187 if (attachedSheet) { |
| 172 [NSApp endSheet:attachedSheet]; | 188 [NSApp endSheet:attachedSheet]; |
| 173 } | 189 } |
| 174 } | 190 } |
| 175 | 191 |
| 176 - (void)awakeFromNib { | 192 - (void)awakeFromNib { |
| 177 DCHECK([self window]); | 193 DCHECK([self window]); |
| 178 DCHECK_EQ(self, [[self window] delegate]); | 194 DCHECK_EQ(self, [[self window] delegate]); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 237 |
| 222 - (void)setCookieSettingIndex:(NSInteger)value { | 238 - (void)setCookieSettingIndex:(NSInteger)value { |
| 223 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 239 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 224 switch (value) { | 240 switch (value) { |
| 225 case kCookieEnabledIndex: setting = CONTENT_SETTING_ALLOW; break; | 241 case kCookieEnabledIndex: setting = CONTENT_SETTING_ALLOW; break; |
| 226 case kCookieAskIndex: setting = CONTENT_SETTING_ASK; break; | 242 case kCookieAskIndex: setting = CONTENT_SETTING_ASK; break; |
| 227 case kCookieDisabledIndex: setting = CONTENT_SETTING_BLOCK; break; | 243 case kCookieDisabledIndex: setting = CONTENT_SETTING_BLOCK; break; |
| 228 default: | 244 default: |
| 229 NOTREACHED(); | 245 NOTREACHED(); |
| 230 } | 246 } |
| 247 ContentSettingsDialogControllerInternal::PrefObserverDisabler |
| 248 disabler(observer_.get()); |
| 231 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | 249 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( |
| 232 CONTENT_SETTINGS_TYPE_COOKIES, | 250 CONTENT_SETTINGS_TYPE_COOKIES, |
| 233 setting); | 251 setting); |
| 234 } | 252 } |
| 235 | 253 |
| 236 - (NSInteger)cookieSettingIndex { | 254 - (NSInteger)cookieSettingIndex { |
| 237 switch (profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | 255 switch (profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( |
| 238 CONTENT_SETTINGS_TYPE_COOKIES)) { | 256 CONTENT_SETTINGS_TYPE_COOKIES)) { |
| 239 case CONTENT_SETTING_ALLOW: return kCookieEnabledIndex; | 257 case CONTENT_SETTING_ALLOW: return kCookieEnabledIndex; |
| 240 case CONTENT_SETTING_ASK: return kCookieAskIndex; | 258 case CONTENT_SETTING_ASK: return kCookieAskIndex; |
| 241 case CONTENT_SETTING_BLOCK: return kCookieDisabledIndex; | 259 case CONTENT_SETTING_BLOCK: return kCookieDisabledIndex; |
| 242 default: | 260 default: |
| 243 NOTREACHED(); | 261 NOTREACHED(); |
| 244 return kCookieEnabledIndex; | 262 return kCookieEnabledIndex; |
| 245 } | 263 } |
| 246 } | 264 } |
| 247 | 265 |
| 248 - (BOOL)blockThirdPartyCookies { | 266 - (BOOL)blockThirdPartyCookies { |
| 249 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); | 267 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); |
| 250 return settingsMap->BlockThirdPartyCookies(); | 268 return settingsMap->BlockThirdPartyCookies(); |
| 251 } | 269 } |
| 252 | 270 |
| 253 - (void)setBlockThirdPartyCookies:(BOOL)value { | 271 - (void)setBlockThirdPartyCookies:(BOOL)value { |
| 254 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); | 272 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); |
| 273 ContentSettingsDialogControllerInternal::PrefObserverDisabler |
| 274 disabler(observer_.get()); |
| 255 settingsMap->SetBlockThirdPartyCookies(value); | 275 settingsMap->SetBlockThirdPartyCookies(value); |
| 256 } | 276 } |
| 257 | 277 |
| 258 - (BOOL)clearSiteDataOnExit { | 278 - (BOOL)clearSiteDataOnExit { |
| 259 return clearSiteDataOnExit_.GetValue(); | 279 return clearSiteDataOnExit_.GetValue(); |
| 260 } | 280 } |
| 261 | 281 |
| 262 - (void)setClearSiteDataOnExit:(BOOL)value { | 282 - (void)setClearSiteDataOnExit:(BOOL)value { |
| 263 return clearSiteDataOnExit_.SetValue(value); | 283 ContentSettingsDialogControllerInternal::PrefObserverDisabler |
| 284 disabler(observer_.get()); |
| 285 clearSiteDataOnExit_.SetValue(value); |
| 264 } | 286 } |
| 265 | 287 |
| 266 // Shows the cookies controller. | 288 // Shows the cookies controller. |
| 267 - (IBAction)showCookies:(id)sender { | 289 - (IBAction)showCookies:(id)sender { |
| 268 // The cookie controller will autorelease itself when it's closed. | 290 // The cookie controller will autorelease itself when it's closed. |
| 269 BrowsingDataDatabaseHelper* databaseHelper = | 291 BrowsingDataDatabaseHelper* databaseHelper = |
| 270 new BrowsingDataDatabaseHelper(profile_); | 292 new BrowsingDataDatabaseHelper(profile_); |
| 271 BrowsingDataLocalStorageHelper* storageHelper = | 293 BrowsingDataLocalStorageHelper* storageHelper = |
| 272 new BrowsingDataLocalStorageHelper(profile_); | 294 new BrowsingDataLocalStorageHelper(profile_); |
| 273 BrowsingDataAppCacheHelper* appcacheHelper = | 295 BrowsingDataAppCacheHelper* appcacheHelper = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 346 } |
| 325 | 347 |
| 326 - (void)showExceptionsForType:(ContentSettingsType)settingsType { | 348 - (void)showExceptionsForType:(ContentSettingsType)settingsType { |
| 327 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); | 349 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); |
| 328 [[ContentExceptionsWindowController controllerForType:settingsType | 350 [[ContentExceptionsWindowController controllerForType:settingsType |
| 329 settingsMap:settingsMap] | 351 settingsMap:settingsMap] |
| 330 attachSheetTo:[self window]]; | 352 attachSheetTo:[self window]]; |
| 331 } | 353 } |
| 332 | 354 |
| 333 - (void)setImagesEnabledIndex:(NSInteger)value { | 355 - (void)setImagesEnabledIndex:(NSInteger)value { |
| 334 ContentSetting setting = value == kEnabledIndex ? | 356 ContentSetting setting = value == kContentSettingsEnabledIndex ? |
| 335 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 357 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 358 ContentSettingsDialogControllerInternal::PrefObserverDisabler |
| 359 disabler(observer_.get()); |
| 336 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | 360 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( |
| 337 CONTENT_SETTINGS_TYPE_IMAGES, setting); | 361 CONTENT_SETTINGS_TYPE_IMAGES, setting); |
| 338 } | 362 } |
| 339 | 363 |
| 340 - (NSInteger)imagesEnabledIndex { | 364 - (NSInteger)imagesEnabledIndex { |
| 341 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); | 365 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); |
| 342 bool enabled = | 366 bool enabled = |
| 343 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES) == | 367 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_IMAGES) == |
| 344 CONTENT_SETTING_ALLOW; | 368 CONTENT_SETTING_ALLOW; |
| 345 return enabled ? kEnabledIndex : kDisabledIndex; | 369 return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; |
| 346 } | 370 } |
| 347 | 371 |
| 348 - (void)setJavaScriptEnabledIndex:(NSInteger)value { | 372 - (void)setJavaScriptEnabledIndex:(NSInteger)value { |
| 349 ContentSetting setting = value == kEnabledIndex ? | 373 ContentSetting setting = value == kContentSettingsEnabledIndex ? |
| 350 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 374 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 375 ContentSettingsDialogControllerInternal::PrefObserverDisabler |
| 376 disabler(observer_.get()); |
| 351 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | 377 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( |
| 352 CONTENT_SETTINGS_TYPE_JAVASCRIPT, setting); | 378 CONTENT_SETTINGS_TYPE_JAVASCRIPT, setting); |
| 353 } | 379 } |
| 354 | 380 |
| 355 - (NSInteger)javaScriptEnabledIndex { | 381 - (NSInteger)javaScriptEnabledIndex { |
| 356 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); | 382 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); |
| 357 bool enabled = | 383 bool enabled = |
| 358 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT) == | 384 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT) == |
| 359 CONTENT_SETTING_ALLOW; | 385 CONTENT_SETTING_ALLOW; |
| 360 return enabled ? kEnabledIndex : kDisabledIndex; | 386 return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; |
| 361 } | 387 } |
| 362 | 388 |
| 363 - (void)setPluginsEnabledIndex:(NSInteger)value { | 389 - (void)setPluginsEnabledIndex:(NSInteger)value { |
| 364 ContentSetting setting = value == kEnabledIndex ? | 390 ContentSetting setting = value == kContentSettingsEnabledIndex ? |
| 365 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 391 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 392 ContentSettingsDialogControllerInternal::PrefObserverDisabler |
| 393 disabler(observer_.get()); |
| 366 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | 394 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( |
| 367 CONTENT_SETTINGS_TYPE_PLUGINS, setting); | 395 CONTENT_SETTINGS_TYPE_PLUGINS, setting); |
| 368 } | 396 } |
| 369 | 397 |
| 370 - (NSInteger)pluginsEnabledIndex { | 398 - (NSInteger)pluginsEnabledIndex { |
| 371 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); | 399 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); |
| 372 bool enabled = | 400 bool enabled = |
| 373 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS) == | 401 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS) == |
| 374 CONTENT_SETTING_ALLOW; | 402 CONTENT_SETTING_ALLOW; |
| 375 return enabled ? kEnabledIndex : kDisabledIndex; | 403 return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; |
| 376 } | 404 } |
| 377 | 405 |
| 378 - (void)setPopupsEnabledIndex:(NSInteger)value { | 406 - (void)setPopupsEnabledIndex:(NSInteger)value { |
| 379 ContentSetting setting = value == kEnabledIndex ? | 407 ContentSetting setting = value == kContentSettingsEnabledIndex ? |
| 380 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 408 CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 409 ContentSettingsDialogControllerInternal::PrefObserverDisabler |
| 410 disabler(observer_.get()); |
| 381 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | 411 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( |
| 382 CONTENT_SETTINGS_TYPE_POPUPS, setting); | 412 CONTENT_SETTINGS_TYPE_POPUPS, setting); |
| 383 } | 413 } |
| 384 | 414 |
| 385 - (NSInteger)popupsEnabledIndex { | 415 - (NSInteger)popupsEnabledIndex { |
| 386 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); | 416 HostContentSettingsMap* settingsMap = profile_->GetHostContentSettingsMap(); |
| 387 bool enabled = | 417 bool enabled = |
| 388 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS) == | 418 settingsMap->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS) == |
| 389 CONTENT_SETTING_ALLOW; | 419 CONTENT_SETTING_ALLOW; |
| 390 return enabled ? kEnabledIndex : kDisabledIndex; | 420 return enabled ? kContentSettingsEnabledIndex : kContentSettingsDisabledIndex; |
| 391 } | 421 } |
| 392 | 422 |
| 393 - (void)setGeolocationSettingIndex:(NSInteger)value { | 423 - (void)setGeolocationSettingIndex:(NSInteger)value { |
| 394 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 424 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 395 switch (value) { | 425 switch (value) { |
| 396 case kGeolocationEnabledIndex: setting = CONTENT_SETTING_ALLOW; break; | 426 case kGeolocationEnabledIndex: setting = CONTENT_SETTING_ALLOW; break; |
| 397 case kGeolocationAskIndex: setting = CONTENT_SETTING_ASK; break; | 427 case kGeolocationAskIndex: setting = CONTENT_SETTING_ASK; break; |
| 398 case kGeolocationDisabledIndex: setting = CONTENT_SETTING_BLOCK; break; | 428 case kGeolocationDisabledIndex: setting = CONTENT_SETTING_BLOCK; break; |
| 399 default: | 429 default: |
| 400 NOTREACHED(); | 430 NOTREACHED(); |
| 401 } | 431 } |
| 432 ContentSettingsDialogControllerInternal::PrefObserverDisabler |
| 433 disabler(observer_.get()); |
| 402 profile_->GetGeolocationContentSettingsMap()->SetDefaultContentSetting( | 434 profile_->GetGeolocationContentSettingsMap()->SetDefaultContentSetting( |
| 403 setting); | 435 setting); |
| 404 } | 436 } |
| 405 | 437 |
| 406 - (NSInteger)geolocationSettingIndex { | 438 - (NSInteger)geolocationSettingIndex { |
| 407 ContentSetting setting = | 439 ContentSetting setting = |
| 408 profile_->GetGeolocationContentSettingsMap()->GetDefaultContentSetting(); | 440 profile_->GetGeolocationContentSettingsMap()->GetDefaultContentSetting(); |
| 409 switch (setting) { | 441 switch (setting) { |
| 410 case CONTENT_SETTING_ALLOW: return kGeolocationEnabledIndex; | 442 case CONTENT_SETTING_ALLOW: return kGeolocationEnabledIndex; |
| 411 case CONTENT_SETTING_ASK: return kGeolocationAskIndex; | 443 case CONTENT_SETTING_ASK: return kGeolocationAskIndex; |
| 412 case CONTENT_SETTING_BLOCK: return kGeolocationDisabledIndex; | 444 case CONTENT_SETTING_BLOCK: return kGeolocationDisabledIndex; |
| 413 default: | 445 default: |
| 414 NOTREACHED(); | 446 NOTREACHED(); |
| 415 return kGeolocationAskIndex; | 447 return kGeolocationAskIndex; |
| 416 } | 448 } |
| 417 } | 449 } |
| 418 | 450 |
| 451 // Callback when preferences are changed. |prefName| is the name of the |
| 452 // pref that has changed and should not be NULL. |
| 453 - (void)prefChanged:(std::wstring*)prefName { |
| 454 DCHECK(prefName); |
| 455 if (!prefName) return; |
| 456 if (*prefName == prefs::kClearSiteDataOnExit) { |
| 457 [self willChangeValueForKey:@"clearSiteDataOnExit"]; |
| 458 [self didChangeValueForKey:@"clearSiteDataOnExit"]; |
| 459 } |
| 460 if (*prefName == prefs::kBlockThirdPartyCookies) { |
| 461 [self willChangeValueForKey:@"blockThirdPartyCookies"]; |
| 462 [self didChangeValueForKey:@"blockThirdPartyCookies"]; |
| 463 } |
| 464 if (*prefName == prefs::kDefaultContentSettings) { |
| 465 // We don't know exactly which setting has changed, so we'll tickle all |
| 466 // of the properties that apply to kDefaultContentSettings. This will |
| 467 // keep the UI up-to-date. |
| 468 [self willChangeValueForKey:@"cookieSettingIndex"]; |
| 469 [self didChangeValueForKey:@"cookieSettingIndex"]; |
| 470 [self willChangeValueForKey:@"imagesEnabledIndex"]; |
| 471 [self didChangeValueForKey:@"imagesEnabledIndex"]; |
| 472 [self willChangeValueForKey:@"javaScriptEnabledIndex"]; |
| 473 [self didChangeValueForKey:@"javaScriptEnabledIndex"]; |
| 474 [self willChangeValueForKey:@"pluginsEnabledIndex"]; |
| 475 [self didChangeValueForKey:@"pluginsEnabledIndex"]; |
| 476 [self willChangeValueForKey:@"popupsEnabledIndex"]; |
| 477 [self didChangeValueForKey:@"popupsEnabledIndex"]; |
| 478 } |
| 479 if (*prefName == prefs::kGeolocationDefaultContentSetting) { |
| 480 [self willChangeValueForKey:@"geolocationSettingIndex"]; |
| 481 [self didChangeValueForKey:@"geolocationSettingIndex"]; |
| 482 } |
| 483 } |
| 484 |
| 419 @end | 485 @end |
| OLD | NEW |