| 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()); |
| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 !profile()->IsGuestSession()); | 885 !profile()->IsGuestSession()); |
| 872 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); | 886 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true); |
| 873 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); | 887 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true); |
| 874 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); | 888 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true); |
| 875 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, | 889 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, |
| 876 !profile()->IsGuestSession()); | 890 !profile()->IsGuestSession()); |
| 877 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, | 891 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU, |
| 878 !profile()->IsGuestSession() && | 892 !profile()->IsGuestSession() && |
| 879 !profile()->IsOffTheRecord()); | 893 !profile()->IsOffTheRecord()); |
| 880 | 894 |
| 881 command_updater_.UpdateCommandEnabled(IDC_SHOW_SIGNIN, true); | 895 UpdateShowSyncState(true); |
| 882 | 896 |
| 883 // Initialize other commands based on the window type. | 897 // Initialize other commands based on the window type. |
| 884 bool normal_window = browser_->is_type_tabbed(); | 898 bool normal_window = browser_->is_type_tabbed(); |
| 885 | 899 |
| 886 // Navigation commands | 900 // Navigation commands |
| 887 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); | 901 command_updater_.UpdateCommandEnabled(IDC_HOME, normal_window); |
| 888 | 902 |
| 889 // Window management commands | 903 // Window management commands |
| 890 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); | 904 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window); |
| 891 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, | 905 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 command_updater_.UpdateCommandEnabled( | 1115 command_updater_.UpdateCommandEnabled( |
| 1102 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); | 1116 IDC_FOCUS_NEXT_PANE, main_not_fullscreen); |
| 1103 command_updater_.UpdateCommandEnabled( | 1117 command_updater_.UpdateCommandEnabled( |
| 1104 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); | 1118 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 1105 command_updater_.UpdateCommandEnabled( | 1119 command_updater_.UpdateCommandEnabled( |
| 1106 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); | 1120 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 1107 | 1121 |
| 1108 // Show various bits of UI | 1122 // Show various bits of UI |
| 1109 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 1123 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 1110 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 1124 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
| 1125 UpdateShowSyncState(show_main_ui); |
| 1111 | 1126 |
| 1112 // Settings page/subpages are forced to open in normal mode. We disable these | 1127 // Settings page/subpages are forced to open in normal mode. We disable these |
| 1113 // commands when incognito is forced. | 1128 // commands when incognito is forced. |
| 1114 const bool options_enabled = show_main_ui && | 1129 const bool options_enabled = show_main_ui && |
| 1115 IncognitoModePrefs::GetAvailability( | 1130 IncognitoModePrefs::GetAvailability( |
| 1116 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; | 1131 profile()->GetPrefs()) != IncognitoModePrefs::FORCED; |
| 1117 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); | 1132 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled); |
| 1118 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); | 1133 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, options_enabled); |
| 1119 | 1134 |
| 1120 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 1135 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 if (metro_enable_printing) | 1187 if (metro_enable_printing) |
| 1173 metro_enable_printing(print_enabled); | 1188 metro_enable_printing(print_enabled); |
| 1174 } | 1189 } |
| 1175 #endif | 1190 #endif |
| 1176 } | 1191 } |
| 1177 | 1192 |
| 1178 void BrowserCommandController::UpdateSaveAsState() { | 1193 void BrowserCommandController::UpdateSaveAsState() { |
| 1179 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); | 1194 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_)); |
| 1180 } | 1195 } |
| 1181 | 1196 |
| 1197 void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) { |
| 1198 command_updater_.UpdateCommandEnabled( |
| 1199 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue()); |
| 1200 } |
| 1201 |
| 1182 // static | 1202 // static |
| 1183 void BrowserCommandController::UpdateOpenFileState( | 1203 void BrowserCommandController::UpdateOpenFileState( |
| 1184 CommandUpdater* command_updater) { | 1204 CommandUpdater* command_updater) { |
| 1185 bool enabled = true; | 1205 bool enabled = true; |
| 1186 PrefService* local_state = g_browser_process->local_state(); | 1206 PrefService* local_state = g_browser_process->local_state(); |
| 1187 if (local_state) | 1207 if (local_state) |
| 1188 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); | 1208 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 1189 | 1209 |
| 1190 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); | 1210 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled); |
| 1191 } | 1211 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 | 1243 |
| 1224 BrowserWindow* BrowserCommandController::window() { | 1244 BrowserWindow* BrowserCommandController::window() { |
| 1225 return browser_->window(); | 1245 return browser_->window(); |
| 1226 } | 1246 } |
| 1227 | 1247 |
| 1228 Profile* BrowserCommandController::profile() { | 1248 Profile* BrowserCommandController::profile() { |
| 1229 return browser_->profile(); | 1249 return browser_->profile(); |
| 1230 } | 1250 } |
| 1231 | 1251 |
| 1232 } // namespace chrome | 1252 } // namespace chrome |
| OLD | NEW |