| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/browser_command_controller.h" | 5 #include "chrome/browser/ui/browser_command_controller.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/defaults.h" | 10 #include "chrome/browser/defaults.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 base::Unretained(this))); | 194 base::Unretained(this))); |
| 195 profile_pref_registrar_.Add( | 195 profile_pref_registrar_.Add( |
| 196 prefs::kIncognitoModeAvailability, | 196 prefs::kIncognitoModeAvailability, |
| 197 base::Bind( | 197 base::Bind( |
| 198 &BrowserCommandController::UpdateCommandsForIncognitoAvailability, | 198 &BrowserCommandController::UpdateCommandsForIncognitoAvailability, |
| 199 base::Unretained(this))); | 199 base::Unretained(this))); |
| 200 profile_pref_registrar_.Add( | 200 profile_pref_registrar_.Add( |
| 201 prefs::kPrintingEnabled, | 201 prefs::kPrintingEnabled, |
| 202 base::Bind(&BrowserCommandController::UpdatePrintingState, | 202 base::Bind(&BrowserCommandController::UpdatePrintingState, |
| 203 base::Unretained(this))); | 203 base::Unretained(this))); |
| 204 pref_signin_allowed_.Init( |
| 205 prefs::kSigninAllowed, |
| 206 profile()->GetOriginalProfile()->GetPrefs(), |
| 207 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange, |
| 208 base::Unretained(this))); |
| 204 | 209 |
| 205 InitCommandState(); | 210 InitCommandState(); |
| 206 | 211 |
| 207 TabRestoreService* tab_restore_service = | 212 TabRestoreService* tab_restore_service = |
| 208 TabRestoreServiceFactory::GetForProfile(profile()); | 213 TabRestoreServiceFactory::GetForProfile(profile()); |
| 209 if (tab_restore_service) { | 214 if (tab_restore_service) { |
| 210 tab_restore_service->AddObserver(this); | 215 tab_restore_service->AddObserver(this); |
| 211 TabRestoreServiceChanged(tab_restore_service); | 216 TabRestoreServiceChanged(tab_restore_service); |
| 212 } | 217 } |
| 213 } | 218 } |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 void BrowserCommandController::OnProfileNameChanged( | 738 void BrowserCommandController::OnProfileNameChanged( |
| 734 const base::FilePath& profile_path, | 739 const base::FilePath& profile_path, |
| 735 const string16& old_profile_name) { | 740 const string16& old_profile_name) { |
| 736 } | 741 } |
| 737 | 742 |
| 738 void BrowserCommandController::OnProfileAvatarChanged( | 743 void BrowserCommandController::OnProfileAvatarChanged( |
| 739 const base::FilePath& profile_path) { | 744 const base::FilePath& profile_path) { |
| 740 } | 745 } |
| 741 | 746 |
| 742 //////////////////////////////////////////////////////////////////////////////// | 747 //////////////////////////////////////////////////////////////////////////////// |
| 748 // BrowserCommandController, SigninPrefObserver implementation: |
| 749 |
| 750 void BrowserCommandController::OnSigninAllowedPrefChange() { |
| 751 // For unit tests, we don't have a window. |
| 752 if (!window()) |
| 753 return; |
| 754 UpdateShowSyncState(IsShowingMainUI(window()->IsFullscreen())); |
| 755 } |
| 756 |
| 743 // BrowserCommandController, TabStripModelObserver implementation: | 757 // BrowserCommandController, TabStripModelObserver implementation: |
| 744 | 758 |
| 745 void BrowserCommandController::TabInsertedAt(WebContents* contents, | 759 void BrowserCommandController::TabInsertedAt(WebContents* contents, |
| 746 int index, | 760 int index, |
| 747 bool foreground) { | 761 bool foreground) { |
| 748 AddInterstitialObservers(contents); | 762 AddInterstitialObservers(contents); |
| 749 } | 763 } |
| 750 | 764 |
| 751 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { | 765 void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) { |
| 752 RemoveInterstitialObservers(contents); | 766 RemoveInterstitialObservers(contents); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 !profile()->IsGuestSession()); | 887 !profile()->IsGuestSession()); |
| 874 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 888 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 875 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); | 889 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
| 876 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 890 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
| 877 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, | 891 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, |
| 878 !profile()->IsGuestSession()); | 892 !profile()->IsGuestSession()); |
| 879 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, | 893 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, |
| 880 !profile()->IsGuestSession() && | 894 !profile()->IsGuestSession() && |
| 881 !profile()->IsOffTheRecord()); | 895 !profile()->IsOffTheRecord()); |
| 882 | 896 |
| 883 command_updater_.UpdateCommandEnabled(IDC_SHOW_SIGNIN, true); | 897 UpdateShowSyncState(true); |
| 884 | 898 |
| 885 // Initialize other commands based on the window type. | 899 // Initialize other commands based on the window type. |
| 886 bool normal_window = browser_->is_type_tabbed(); | 900 bool normal_window = browser_->is_type_tabbed(); |
| 887 | 901 |
| 888 // Navigation commands | 902 // Navigation commands |
| 889 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 903 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
| 890 | 904 |
| 891 // Window management commands | 905 // Window management commands |
| 892 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 906 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 893 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 907 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 command_updater_.UpdateCommandEnabled( | 1122 command_updater_.UpdateCommandEnabled( |
| 1109 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); | 1123 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
| 1110 command_updater_.UpdateCommandEnabled( | 1124 command_updater_.UpdateCommandEnabled( |
| 1111 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); | 1125 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 1112 command_updater_.UpdateCommandEnabled( | 1126 command_updater_.UpdateCommandEnabled( |
| 1113 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); | 1127 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 1114 | 1128 |
| 1115 // Show various bits of UI | 1129 // Show various bits of UI |
| 1116 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 1130 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 1117 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 1131 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
| 1132 UpdateShowSyncState(show_main_ui); |
| 1118 | 1133 |
| 1119 // Settings page/subpages are forced to open in normal mode. We disable these | 1134 // Settings page/subpages are forced to open in normal mode. We disable these |
| 1120 // commands when incognito is forced. | 1135 // commands when incognito is forced. |
| 1121 const bool options_enabled = show_main_ui && | 1136 const bool options_enabled = show_main_ui && |
| 1122 IncognitoModePrefs::GetAvailability( | 1137 IncognitoModePrefs::GetAvailability( |
| 1123 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 1138 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 1124 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); | 1139 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
| 1125 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); | 1140 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); |
| 1126 | 1141 |
| 1127 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1142 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 if (metro_enable_printing) | 1195 if (metro_enable_printing) |
| 1181 metro_enable_printing(print_enabled); | 1196 metro_enable_printing(print_enabled); |
| 1182 } | 1197 } |
| 1183 #endif | 1198 #endif |
| 1184 } | 1199 } |
| 1185 | 1200 |
| 1186 void BrowserCommandController::UpdateSaveAsState() { | 1201 void BrowserCommandController::UpdateSaveAsState() { |
| 1187 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); | 1202 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
| 1188 } | 1203 } |
| 1189 | 1204 |
| 1205 void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) { |
| 1206 command_updater_.UpdateCommandEnabled( |
| 1207 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue()); |
| 1208 } |
| 1209 |
| 1190 // static | 1210 // static |
| 1191 void BrowserCommandController::UpdateOpenFileState( | 1211 void BrowserCommandController::UpdateOpenFileState( |
| 1192 CommandUpdater* command_updater) { | 1212 CommandUpdater* command_updater) { |
| 1193 bool enabled = true; | 1213 bool enabled = true; |
| 1194 PrefService* local_state = g_browser_process->local_state(); | 1214 PrefService* local_state = g_browser_process->local_state(); |
| 1195 if (local_state) | 1215 if (local_state) |
| 1196 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); | 1216 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 1197 | 1217 |
| 1198 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); | 1218 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 1199 } | 1219 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 | 1251 |
| 1232 BrowserWindow* BrowserCommandController::window() { | 1252 BrowserWindow* BrowserCommandController::window() { |
| 1233 return browser_->window(); | 1253 return browser_->window(); |
| 1234 } | 1254 } |
| 1235 | 1255 |
| 1236 Profile* BrowserCommandController::profile() { | 1256 Profile* BrowserCommandController::profile() { |
| 1237 return browser_->profile(); | 1257 return browser_->profile(); |
| 1238 } | 1258 } |
| 1239 | 1259 |
| 1240 } // namespace chrome | 1260 } // namespace chrome |
| OLD | NEW |