| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/preferences_window_controller.h" | 5 #import "chrome/browser/cocoa/preferences_window_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 - (void)customHomePagesChanged; | 79 - (void)customHomePagesChanged; |
| 80 | 80 |
| 81 // KVC setter methods. | 81 // KVC setter methods. |
| 82 - (void)setNewTabPageIsHomePageIndex:(NSInteger)val; | 82 - (void)setNewTabPageIsHomePageIndex:(NSInteger)val; |
| 83 - (void)setHomepageURL:(NSString*)urlString; | 83 - (void)setHomepageURL:(NSString*)urlString; |
| 84 - (void)setRestoreOnStartupIndex:(NSInteger)type; | 84 - (void)setRestoreOnStartupIndex:(NSInteger)type; |
| 85 - (void)setShowHomeButton:(BOOL)value; | 85 - (void)setShowHomeButton:(BOOL)value; |
| 86 - (void)setShowPageOptionsButtons:(BOOL)value; | 86 - (void)setShowPageOptionsButtons:(BOOL)value; |
| 87 - (void)setPasswordManagerEnabledIndex:(NSInteger)value; | 87 - (void)setPasswordManagerEnabledIndex:(NSInteger)value; |
| 88 - (void)setFormAutofillEnabledIndex:(NSInteger)value; | 88 - (void)setFormAutofillEnabledIndex:(NSInteger)value; |
| 89 - (void)setIsUsingDefaultTheme:(BOOL)value; |
| 89 - (void)setShowAlternateErrorPages:(BOOL)value; | 90 - (void)setShowAlternateErrorPages:(BOOL)value; |
| 90 - (void)setUseSuggest:(BOOL)value; | 91 - (void)setUseSuggest:(BOOL)value; |
| 91 - (void)setDnsPrefetch:(BOOL)value; | 92 - (void)setDnsPrefetch:(BOOL)value; |
| 92 - (void)setSafeBrowsing:(BOOL)value; | 93 - (void)setSafeBrowsing:(BOOL)value; |
| 93 - (void)setMetricsRecording:(BOOL)value; | 94 - (void)setMetricsRecording:(BOOL)value; |
| 94 - (void)setCookieBehavior:(NSInteger)value; | 95 - (void)setCookieBehavior:(NSInteger)value; |
| 95 - (void)setAskForSaveLocation:(BOOL)value; | 96 - (void)setAskForSaveLocation:(BOOL)value; |
| 96 - (void)displayPreferenceViewForToolbarItem:(NSToolbarItem*)toolbarItem | 97 - (void)displayPreferenceViewForToolbarItem:(NSToolbarItem*)toolbarItem |
| 97 animate:(BOOL)animate; | 98 animate:(BOOL)animate; |
| 98 @end | 99 @end |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 prefs_->AddPrefObserver(prefs::kURLsToRestoreOnStartup, observer_.get()); | 243 prefs_->AddPrefObserver(prefs::kURLsToRestoreOnStartup, observer_.get()); |
| 243 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); | 244 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); |
| 244 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, | 245 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, |
| 245 prefs_, observer_.get()); | 246 prefs_, observer_.get()); |
| 246 homepage_.Init(prefs::kHomePage, prefs_, observer_.get()); | 247 homepage_.Init(prefs::kHomePage, prefs_, observer_.get()); |
| 247 showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get()); | 248 showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get()); |
| 248 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs_, | 249 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs_, |
| 249 observer_.get()); | 250 observer_.get()); |
| 250 // TODO(pinkerton): Register Default search. | 251 // TODO(pinkerton): Register Default search. |
| 251 | 252 |
| 252 // UserData panel | 253 // Personal Stuff panel |
| 253 askSavePasswords_.Init(prefs::kPasswordManagerEnabled, | 254 askSavePasswords_.Init(prefs::kPasswordManagerEnabled, |
| 254 prefs_, observer_.get()); | 255 prefs_, observer_.get()); |
| 255 formAutofill_.Init(prefs::kFormAutofillEnabled, prefs_, observer_.get()); | 256 formAutofill_.Init(prefs::kFormAutofillEnabled, prefs_, observer_.get()); |
| 257 currentTheme_.Init(prefs::kCurrentThemeID, prefs_, observer_.get()); |
| 256 | 258 |
| 257 // Under the hood panel | 259 // Under the hood panel |
| 258 alternateErrorPages_.Init(prefs::kAlternateErrorPagesEnabled, | 260 alternateErrorPages_.Init(prefs::kAlternateErrorPagesEnabled, |
| 259 prefs_, observer_.get()); | 261 prefs_, observer_.get()); |
| 260 useSuggest_.Init(prefs::kSearchSuggestEnabled, prefs_, observer_.get()); | 262 useSuggest_.Init(prefs::kSearchSuggestEnabled, prefs_, observer_.get()); |
| 261 dnsPrefetch_.Init(prefs::kDnsPrefetchingEnabled, prefs_, observer_.get()); | 263 dnsPrefetch_.Init(prefs::kDnsPrefetchingEnabled, prefs_, observer_.get()); |
| 262 safeBrowsing_.Init(prefs::kSafeBrowsingEnabled, prefs_, observer_.get()); | 264 safeBrowsing_.Init(prefs::kSafeBrowsingEnabled, prefs_, observer_.get()); |
| 265 |
| 263 // During unit tests, there is no local state object, so we fall back to | 266 // During unit tests, there is no local state object, so we fall back to |
| 264 // the prefs object (where we've explicitly registered this pref so we | 267 // the prefs object (where we've explicitly registered this pref so we |
| 265 // know it's there). | 268 // know it's there). |
| 266 PrefService* local = g_browser_process->local_state(); | 269 PrefService* local = g_browser_process->local_state(); |
| 267 if (!local) | 270 if (!local) |
| 268 local = prefs_; | 271 local = prefs_; |
| 269 metricsRecording_.Init(prefs::kMetricsReportingEnabled, | 272 metricsRecording_.Init(prefs::kMetricsReportingEnabled, |
| 270 local, observer_.get()); | 273 local, observer_.get()); |
| 271 cookieBehavior_.Init(prefs::kCookieBehavior, prefs_, observer_.get()); | 274 cookieBehavior_.Init(prefs::kCookieBehavior, prefs_, observer_.get()); |
| 272 defaultDownloadLocation_.Init(prefs::kDownloadDefaultDirectory, prefs_, | 275 defaultDownloadLocation_.Init(prefs::kDownloadDefaultDirectory, prefs_, |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 // User Data panel | 667 // User Data panel |
| 665 | 668 |
| 666 // Since passwords and forms are radio groups, 'enabled' is index 0 and | 669 // Since passwords and forms are radio groups, 'enabled' is index 0 and |
| 667 // 'disabled' is index 1. Yay. | 670 // 'disabled' is index 1. Yay. |
| 668 const int kEnabledIndex = 0; | 671 const int kEnabledIndex = 0; |
| 669 const int kDisabledIndex = 1; | 672 const int kDisabledIndex = 1; |
| 670 | 673 |
| 671 // Callback when preferences are changed. |prefName| is the name of the pref | 674 // Callback when preferences are changed. |prefName| is the name of the pref |
| 672 // that has changed. Unlike on Windows, we don't need to use this method for | 675 // that has changed. Unlike on Windows, we don't need to use this method for |
| 673 // initializing, that's handled by Cocoa Bindings. | 676 // initializing, that's handled by Cocoa Bindings. |
| 674 // Handles prefs for the "Minor Tweaks" panel. | 677 // Handles prefs for the "Personal Stuff" panel. |
| 675 - (void)userDataPrefChanged:(std::wstring*)prefName { | 678 - (void)userDataPrefChanged:(std::wstring*)prefName { |
| 676 if (*prefName == prefs::kPasswordManagerEnabled) { | 679 if (*prefName == prefs::kPasswordManagerEnabled) { |
| 677 [self setPasswordManagerEnabledIndex:askSavePasswords_.GetValue() ? | 680 [self setPasswordManagerEnabledIndex:askSavePasswords_.GetValue() ? |
| 678 kEnabledIndex : kDisabledIndex]; | 681 kEnabledIndex : kDisabledIndex]; |
| 679 } | 682 } |
| 680 if (*prefName == prefs::kFormAutofillEnabled) { | 683 if (*prefName == prefs::kFormAutofillEnabled) { |
| 681 [self setFormAutofillEnabledIndex:formAutofill_.GetValue() ? | 684 [self setFormAutofillEnabledIndex:formAutofill_.GetValue() ? |
| 682 kEnabledIndex : kDisabledIndex]; | 685 kEnabledIndex : kDisabledIndex]; |
| 683 } | 686 } |
| 687 if (*prefName == prefs::kCurrentThemeID) { |
| 688 [self setIsUsingDefaultTheme:currentTheme_.GetValue().length() == 0]; |
| 689 } |
| 684 } | 690 } |
| 685 | 691 |
| 686 // Called to launch the Keychain Access app to show the user's stored | 692 // Called to launch the Keychain Access app to show the user's stored |
| 687 // passwords. | 693 // passwords. |
| 688 - (IBAction)showSavedPasswords:(id)sender { | 694 - (IBAction)showSavedPasswords:(id)sender { |
| 689 NSString* const kKeychainBundleId = @"com.apple.keychainaccess"; | 695 NSString* const kKeychainBundleId = @"com.apple.keychainaccess"; |
| 690 [self recordUserAction:L"Options_ShowPasswordsExceptions"]; | 696 [self recordUserAction:L"Options_ShowPasswordsExceptions"]; |
| 691 [[NSWorkspace sharedWorkspace] | 697 [[NSWorkspace sharedWorkspace] |
| 692 launchAppWithBundleIdentifier:kKeychainBundleId | 698 launchAppWithBundleIdentifier:kKeychainBundleId |
| 693 options:0L | 699 options:0L |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 [self recordUserAction:L"Options_FormAutofill_Enable"]; | 754 [self recordUserAction:L"Options_FormAutofill_Enable"]; |
| 749 else | 755 else |
| 750 [self recordUserAction:L"Options_FormAutofill_Disable"]; | 756 [self recordUserAction:L"Options_FormAutofill_Disable"]; |
| 751 formAutofill_.SetValue(value == kEnabledIndex ? true : false); | 757 formAutofill_.SetValue(value == kEnabledIndex ? true : false); |
| 752 } | 758 } |
| 753 | 759 |
| 754 - (NSInteger)formAutofillEnabledIndex { | 760 - (NSInteger)formAutofillEnabledIndex { |
| 755 return formAutofill_.GetValue() ? kEnabledIndex : kDisabledIndex; | 761 return formAutofill_.GetValue() ? kEnabledIndex : kDisabledIndex; |
| 756 } | 762 } |
| 757 | 763 |
| 764 - (void)setIsUsingDefaultTheme:(BOOL)value { |
| 765 if (value) |
| 766 [self recordUserAction:L"Options_IsUsingDefaultTheme_Enable"]; |
| 767 else |
| 768 [self recordUserAction:L"Options_IsUsingDefaultTheme_Disable"]; |
| 769 } |
| 770 |
| 771 - (BOOL)isUsingDefaultTheme { |
| 772 return currentTheme_.GetValue().length() == 0; |
| 773 } |
| 774 |
| 758 //------------------------------------------------------------------------- | 775 //------------------------------------------------------------------------- |
| 759 // Under the hood panel | 776 // Under the hood panel |
| 760 | 777 |
| 761 // Callback when preferences are changed. |prefName| is the name of the pref | 778 // Callback when preferences are changed. |prefName| is the name of the pref |
| 762 // that has changed. Unlike on Windows, we don't need to use this method for | 779 // that has changed. Unlike on Windows, we don't need to use this method for |
| 763 // initializing, that's handled by Cocoa Bindings. | 780 // initializing, that's handled by Cocoa Bindings. |
| 764 // Handles prefs for the "Under the hood" panel. | 781 // Handles prefs for the "Under the hood" panel. |
| 765 - (void)underHoodPrefChanged:(std::wstring*)prefName { | 782 - (void)underHoodPrefChanged:(std::wstring*)prefName { |
| 766 if (*prefName == prefs::kAlternateErrorPagesEnabled) { | 783 if (*prefName == prefs::kAlternateErrorPagesEnabled) { |
| 767 [self setShowAlternateErrorPages: | 784 [self setShowAlternateErrorPages: |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 [[NSNotificationCenter defaultCenter] | 1142 [[NSNotificationCenter defaultCenter] |
| 1126 postNotificationName:kUserDoneEditingPrefsNotification | 1143 postNotificationName:kUserDoneEditingPrefsNotification |
| 1127 object:self]; | 1144 object:self]; |
| 1128 } | 1145 } |
| 1129 | 1146 |
| 1130 - (void)controlTextDidEndEditing:(NSNotification*)notification { | 1147 - (void)controlTextDidEndEditing:(NSNotification*)notification { |
| 1131 [customPagesSource_ validateURLs]; | 1148 [customPagesSource_ validateURLs]; |
| 1132 } | 1149 } |
| 1133 | 1150 |
| 1134 @end | 1151 @end |
| OLD | NEW |