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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar { | 827 - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar { |
828 DCHECK(toolbar == toolbar_); | 828 DCHECK(toolbar == toolbar_); |
829 return [[toolbar_ items] valueForKey:@"itemIdentifier"]; | 829 return [[toolbar_ items] valueForKey:@"itemIdentifier"]; |
830 } | 830 } |
831 | 831 |
832 // Register our interest in the preferences we're displaying so if anything | 832 // Register our interest in the preferences we're displaying so if anything |
833 // else in the UI changes them we will be updated. | 833 // else in the UI changes them we will be updated. |
834 - (void)registerPrefObservers { | 834 - (void)registerPrefObservers { |
835 if (!prefs_) return; | 835 if (!prefs_) return; |
836 | 836 |
837 // During unit tests, there is no local state object, so we fall back to | |
838 // the prefs object (where we've explicitly registered this pref so we | |
839 // know it's there). | |
840 PrefService* local = g_browser_process->local_state(); | 837 PrefService* local = g_browser_process->local_state(); |
841 if (!local) | |
842 local = prefs_; | |
843 | 838 |
844 // Basics panel | 839 // Basics panel |
845 registrar_.Init(prefs_); | 840 registrar_.Init(prefs_); |
846 registrar_.Add(prefs::kURLsToRestoreOnStartup, observer_.get()); | 841 registrar_.Add(prefs::kURLsToRestoreOnStartup, observer_.get()); |
847 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); | 842 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); |
848 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, | 843 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, |
849 prefs_, observer_.get()); | 844 prefs_, observer_.get()); |
850 homepage_.Init(prefs::kHomePage, prefs_, observer_.get()); | 845 homepage_.Init(prefs::kHomePage, prefs_, observer_.get()); |
851 showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get()); | 846 showHomeButton_.Init(prefs::kShowHomeButton, prefs_, observer_.get()); |
852 instantEnabled_.Init(prefs::kInstantEnabled, prefs_, observer_.get()); | 847 instantEnabled_.Init(prefs::kInstantEnabled, prefs_, observer_.get()); |
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 DCHECK_EQ(animation_.get(), animation); | 2054 DCHECK_EQ(animation_.get(), animation); |
2060 // Animation finished, reset subviews to current prefs view and the banner. | 2055 // Animation finished, reset subviews to current prefs view and the banner. |
2061 [self resetSubViews]; | 2056 [self resetSubViews]; |
2062 } | 2057 } |
2063 | 2058 |
2064 // Reinitializes the banner state tracker object to watch for managed bits of | 2059 // Reinitializes the banner state tracker object to watch for managed bits of |
2065 // preferences relevant to the given options |page|. | 2060 // preferences relevant to the given options |page|. |
2066 - (void)initBannerStateForPage:(OptionsPage)page { | 2061 - (void)initBannerStateForPage:(OptionsPage)page { |
2067 page = [self normalizePage:page]; | 2062 page = [self normalizePage:page]; |
2068 | 2063 |
2069 // During unit tests, there is no local state object, so we fall back to | |
2070 // the prefs object (where we've explicitly registered this pref so we | |
2071 // know it's there). | |
2072 PrefService* local = g_browser_process->local_state(); | |
2073 if (!local) | |
2074 local = prefs_; | |
2075 bannerState_.reset( | 2064 bannerState_.reset( |
2076 new PreferencesWindowControllerInternal::ManagedPrefsBannerState( | 2065 new PreferencesWindowControllerInternal::ManagedPrefsBannerState( |
2077 self, page, local, prefs_)); | 2066 self, page, g_browser_process->local_state(), prefs_)); |
2078 } | 2067 } |
2079 | 2068 |
2080 - (void)switchToPage:(OptionsPage)page animate:(BOOL)animate { | 2069 - (void)switchToPage:(OptionsPage)page animate:(BOOL)animate { |
2081 [self displayPreferenceViewForPage:page animate:animate]; | 2070 [self displayPreferenceViewForPage:page animate:animate]; |
2082 NSToolbarItem* toolbarItem = [self getToolbarItemForPage:page]; | 2071 NSToolbarItem* toolbarItem = [self getToolbarItemForPage:page]; |
2083 [toolbar_ setSelectedItemIdentifier:[toolbarItem itemIdentifier]]; | 2072 [toolbar_ setSelectedItemIdentifier:[toolbarItem itemIdentifier]]; |
2084 } | 2073 } |
2085 | 2074 |
2086 // Called when the window is being closed. Send out a notification that the user | 2075 // Called when the window is being closed. Send out a notification that the user |
2087 // is done editing preferences. Make sure there are no pending field editors | 2076 // is done editing preferences. Make sure there are no pending field editors |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2178 case OPTIONS_PAGE_ADVANCED: | 2167 case OPTIONS_PAGE_ADVANCED: |
2179 return underTheHoodView_; | 2168 return underTheHoodView_; |
2180 case OPTIONS_PAGE_DEFAULT: | 2169 case OPTIONS_PAGE_DEFAULT: |
2181 case OPTIONS_PAGE_COUNT: | 2170 case OPTIONS_PAGE_COUNT: |
2182 LOG(DFATAL) << "Invalid page value " << page; | 2171 LOG(DFATAL) << "Invalid page value " << page; |
2183 } | 2172 } |
2184 return basicsView_; | 2173 return basicsView_; |
2185 } | 2174 } |
2186 | 2175 |
2187 @end | 2176 @end |
OLD | NEW |