| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/cocoa/options/preferences_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/options/preferences_window_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 @synthesize passwordManagerButtonEnabled = passwordManagerButtonEnabled_; | 479 @synthesize passwordManagerButtonEnabled = passwordManagerButtonEnabled_; |
| 480 @synthesize autoFillSettingsButtonEnabled = autoFillSettingsButtonEnabled_; | 480 @synthesize autoFillSettingsButtonEnabled = autoFillSettingsButtonEnabled_; |
| 481 @synthesize showAlternateErrorPagesEnabled = showAlternateErrorPagesEnabled_; | 481 @synthesize showAlternateErrorPagesEnabled = showAlternateErrorPagesEnabled_; |
| 482 @synthesize useSuggestEnabled = useSuggestEnabled_; | 482 @synthesize useSuggestEnabled = useSuggestEnabled_; |
| 483 @synthesize dnsPrefetchEnabled = dnsPrefetchEnabled_; | 483 @synthesize dnsPrefetchEnabled = dnsPrefetchEnabled_; |
| 484 @synthesize safeBrowsingEnabled = safeBrowsingEnabled_; | 484 @synthesize safeBrowsingEnabled = safeBrowsingEnabled_; |
| 485 @synthesize metricsReportingEnabled = metricsReportingEnabled_; | 485 @synthesize metricsReportingEnabled = metricsReportingEnabled_; |
| 486 @synthesize proxiesConfigureButtonEnabled = proxiesConfigureButtonEnabled_; | 486 @synthesize proxiesConfigureButtonEnabled = proxiesConfigureButtonEnabled_; |
| 487 | 487 |
| 488 - (id)initWithProfile:(Profile*)profile initialPage:(OptionsPage)initialPage { | 488 - (id)initWithProfile:(Profile*)profile initialPage:(OptionsPage)initialPage { |
| 489 return [self initWithProfile:profile |
| 490 localState:NULL |
| 491 initialPage:initialPage]; |
| 492 } |
| 493 |
| 494 - (id)initWithProfile:(Profile*)profile localState:(PrefService*)local_state |
| 495 initialPage:(OptionsPage)initialPage { |
| 489 DCHECK(profile); | 496 DCHECK(profile); |
| 490 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we | 497 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we |
| 491 // can override it in a unit test. | 498 // can override it in a unit test. |
| 492 NSString* nibPath = [base::mac::MainAppBundle() | 499 NSString* nibPath = [base::mac::MainAppBundle() |
| 493 pathForResource:@"Preferences" | 500 pathForResource:@"Preferences" |
| 494 ofType:@"nib"]; | 501 ofType:@"nib"]; |
| 495 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { | 502 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
| 496 profile_ = profile->GetOriginalProfile(); | 503 profile_ = profile->GetOriginalProfile(); |
| 497 initialPage_ = initialPage; | 504 initialPage_ = initialPage; |
| 498 prefs_ = profile->GetPrefs(); | 505 prefs_ = profile->GetPrefs(); |
| 499 DCHECK(prefs_); | 506 DCHECK(prefs_); |
| 507 local_state_ = local_state; |
| 500 observer_.reset( | 508 observer_.reset( |
| 501 new PreferencesWindowControllerInternal::PrefObserverBridge(self)); | 509 new PreferencesWindowControllerInternal::PrefObserverBridge(self)); |
| 502 | 510 |
| 503 // Set up the model for the custom home page table. The KVO observation | 511 // Set up the model for the custom home page table. The KVO observation |
| 504 // tells us when the number of items in the array changes. The normal | 512 // tells us when the number of items in the array changes. The normal |
| 505 // observation tells us when one of the URLs of an item changes. | 513 // observation tells us when one of the URLs of an item changes. |
| 506 customPagesSource_.reset([[CustomHomePagesModel alloc] | 514 customPagesSource_.reset([[CustomHomePagesModel alloc] |
| 507 initWithProfile:profile_]); | 515 initWithProfile:profile_]); |
| 508 const SessionStartupPref startupPref = | 516 const SessionStartupPref startupPref = |
| 509 SessionStartupPref::GetStartupPref(prefs_); | 517 SessionStartupPref::GetStartupPref(prefs_); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 // Register our interest in the preferences we're displaying so if anything | 838 // Register our interest in the preferences we're displaying so if anything |
| 831 // else in the UI changes them we will be updated. | 839 // else in the UI changes them we will be updated. |
| 832 - (void)registerPrefObservers { | 840 - (void)registerPrefObservers { |
| 833 if (!prefs_) return; | 841 if (!prefs_) return; |
| 834 | 842 |
| 835 // During unit tests, there is no local state object, so we fall back to | 843 // During unit tests, there is no local state object, so we fall back to |
| 836 // the prefs object (where we've explicitly registered this pref so we | 844 // the prefs object (where we've explicitly registered this pref so we |
| 837 // know it's there). | 845 // know it's there). |
| 838 PrefService* local = g_browser_process->local_state(); | 846 PrefService* local = g_browser_process->local_state(); |
| 839 if (!local) | 847 if (!local) |
| 840 local = prefs_; | 848 local = local_state_ ? local_state_ : prefs_; |
| 841 | 849 |
| 842 // Basics panel | 850 // Basics panel |
| 843 registrar_.Init(prefs_); | 851 registrar_.Init(prefs_); |
| 844 registrar_.Add(prefs::kURLsToRestoreOnStartup, observer_.get()); | 852 registrar_.Add(prefs::kURLsToRestoreOnStartup, observer_.get()); |
| 845 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); | 853 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); |
| 846 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, | 854 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, |
| 847 prefs_, observer_.get()); | 855 prefs_, observer_.get()); |
| 848 homepage_.Init(prefs::kHomePage, prefs_, observer_.get()); | 856 homepage_.Init(prefs::kHomePage, prefs_, observer_.get()); |
| 849 showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get()); | 857 showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get()); |
| 850 instantEnabled_.Init(prefs::kInstantEnabled, prefs_, observer_.get()); | 858 instantEnabled_.Init(prefs::kInstantEnabled, prefs_, observer_.get()); |
| (...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 // Reinitializes the banner state tracker object to watch for managed bits of | 2069 // Reinitializes the banner state tracker object to watch for managed bits of |
| 2062 // preferences relevant to the given options |page|. | 2070 // preferences relevant to the given options |page|. |
| 2063 - (void)initBannerStateForPage:(OptionsPage)page { | 2071 - (void)initBannerStateForPage:(OptionsPage)page { |
| 2064 page = [self normalizePage:page]; | 2072 page = [self normalizePage:page]; |
| 2065 | 2073 |
| 2066 // During unit tests, there is no local state object, so we fall back to | 2074 // During unit tests, there is no local state object, so we fall back to |
| 2067 // the prefs object (where we've explicitly registered this pref so we | 2075 // the prefs object (where we've explicitly registered this pref so we |
| 2068 // know it's there). | 2076 // know it's there). |
| 2069 PrefService* local = g_browser_process->local_state(); | 2077 PrefService* local = g_browser_process->local_state(); |
| 2070 if (!local) | 2078 if (!local) |
| 2071 local = prefs_; | 2079 local = local_state_ ? local_state_ : prefs_; |
| 2072 bannerState_.reset( | 2080 bannerState_.reset( |
| 2073 new PreferencesWindowControllerInternal::ManagedPrefsBannerState( | 2081 new PreferencesWindowControllerInternal::ManagedPrefsBannerState( |
| 2074 self, page, local, prefs_)); | 2082 self, page, local, prefs_)); |
| 2075 } | 2083 } |
| 2076 | 2084 |
| 2077 - (void)switchToPage:(OptionsPage)page animate:(BOOL)animate { | 2085 - (void)switchToPage:(OptionsPage)page animate:(BOOL)animate { |
| 2078 [self displayPreferenceViewForPage:page animate:animate]; | 2086 [self displayPreferenceViewForPage:page animate:animate]; |
| 2079 NSToolbarItem* toolbarItem = [self getToolbarItemForPage:page]; | 2087 NSToolbarItem* toolbarItem = [self getToolbarItemForPage:page]; |
| 2080 [toolbar_ setSelectedItemIdentifier:[toolbarItem itemIdentifier]]; | 2088 [toolbar_ setSelectedItemIdentifier:[toolbarItem itemIdentifier]]; |
| 2081 } | 2089 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2175 case OPTIONS_PAGE_ADVANCED: | 2183 case OPTIONS_PAGE_ADVANCED: |
| 2176 return underTheHoodView_; | 2184 return underTheHoodView_; |
| 2177 case OPTIONS_PAGE_DEFAULT: | 2185 case OPTIONS_PAGE_DEFAULT: |
| 2178 case OPTIONS_PAGE_COUNT: | 2186 case OPTIONS_PAGE_COUNT: |
| 2179 LOG(DFATAL) << "Invalid page value " << page; | 2187 LOG(DFATAL) << "Invalid page value " << page; |
| 2180 } | 2188 } |
| 2181 return basicsView_; | 2189 return basicsView_; |
| 2182 } | 2190 } |
| 2183 | 2191 |
| 2184 @end | 2192 @end |
| OLD | NEW |