| 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 #include "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 PrefService* local_state = g_browser_process->local_state(); | 285 PrefService* local_state = g_browser_process->local_state(); |
| 286 if (local_state) { | 286 if (local_state) { |
| 287 local_pref_registrar_.Init(local_state); | 287 local_pref_registrar_.Init(local_state); |
| 288 local_pref_registrar_.Add(prefs::kPrintingEnabled, this); | 288 local_pref_registrar_.Add(prefs::kPrintingEnabled, this); |
| 289 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); | 289 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); |
| 290 } | 290 } |
| 291 | 291 |
| 292 profile_pref_registrar_.Init(profile_->GetPrefs()); | 292 profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 293 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); | 293 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
| 294 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); | 294 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); |
| 295 profile_pref_registrar_.Add(prefs::kEnableBookmarkBar, this); |
| 295 profile_pref_registrar_.Add(prefs::kInstantEnabled, this); | 296 profile_pref_registrar_.Add(prefs::kInstantEnabled, this); |
| 296 profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this); | 297 profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this); |
| 297 | 298 |
| 298 InitCommandState(); | 299 InitCommandState(); |
| 299 BrowserList::AddBrowser(this); | 300 BrowserList::AddBrowser(this); |
| 300 | 301 |
| 301 // NOTE: These prefs all need to be explicitly destroyed in the destructor | 302 // NOTE: These prefs all need to be explicitly destroyed in the destructor |
| 302 // or you'll get a nasty surprise when you run the incognito tests. | 303 // or you'll get a nasty surprise when you run the incognito tests. |
| 303 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, | 304 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 304 profile_->GetPrefs(), NULL); | 305 profile_->GetPrefs(), NULL); |
| (...skipping 3416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3721 available != IncognitoModePrefs::FORCED); | 3722 available != IncognitoModePrefs::FORCED); |
| 3722 command_updater_.UpdateCommandEnabled( | 3723 command_updater_.UpdateCommandEnabled( |
| 3723 IDC_NEW_INCOGNITO_WINDOW, | 3724 IDC_NEW_INCOGNITO_WINDOW, |
| 3724 available != IncognitoModePrefs::DISABLED); | 3725 available != IncognitoModePrefs::DISABLED); |
| 3725 } else if (pref_name == prefs::kDevToolsDisabled) { | 3726 } else if (pref_name == prefs::kDevToolsDisabled) { |
| 3726 UpdateCommandsForDevTools(); | 3727 UpdateCommandsForDevTools(); |
| 3727 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 3728 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
| 3728 g_browser_process->devtools_manager()->CloseAllClientHosts(); | 3729 g_browser_process->devtools_manager()->CloseAllClientHosts(); |
| 3729 } else if (pref_name == prefs::kEditBookmarksEnabled) { | 3730 } else if (pref_name == prefs::kEditBookmarksEnabled) { |
| 3730 UpdateCommandsForBookmarkEditing(); | 3731 UpdateCommandsForBookmarkEditing(); |
| 3732 } else if (pref_name == prefs::kEnableBookmarkBar) { |
| 3733 UpdateCommandsForBookmarkBar(); |
| 3731 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { | 3734 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { |
| 3732 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); | 3735 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); |
| 3733 UpdateOpenFileState(); | 3736 UpdateOpenFileState(); |
| 3734 } else { | 3737 } else { |
| 3735 NOTREACHED(); | 3738 NOTREACHED(); |
| 3736 } | 3739 } |
| 3737 break; | 3740 break; |
| 3738 } | 3741 } |
| 3739 | 3742 |
| 3740 case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: { | 3743 case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4036 command_updater_.UpdateCommandEnabled( | 4039 command_updater_.UpdateCommandEnabled( |
| 4037 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); | 4040 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 4038 command_updater_.UpdateCommandEnabled( | 4041 command_updater_.UpdateCommandEnabled( |
| 4039 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); | 4042 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 4040 command_updater_.UpdateCommandEnabled( | 4043 command_updater_.UpdateCommandEnabled( |
| 4041 IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen); | 4044 IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen); |
| 4042 | 4045 |
| 4043 // Show various bits of UI | 4046 // Show various bits of UI |
| 4044 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 4047 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 4045 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 4048 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
| 4046 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, | |
| 4047 browser_defaults::bookmarks_enabled && show_main_ui); | |
| 4048 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, show_main_ui); | 4049 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, show_main_ui); |
| 4049 command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, | 4050 command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, |
| 4050 show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible()); | 4051 show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible()); |
| 4051 | 4052 |
| 4052 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, show_main_ui); | 4053 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, show_main_ui); |
| 4053 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 4054 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 4054 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 4055 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 4055 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 4056 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 4056 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 4057 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| 4057 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); | 4058 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); |
| 4058 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); | 4059 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); |
| 4059 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) | 4060 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 4060 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 4061 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 4061 #endif | 4062 #endif |
| 4063 |
| 4064 UpdateCommandsForBookmarkBar(); |
| 4062 } | 4065 } |
| 4063 | 4066 |
| 4064 void Browser::UpdateCommandsForTabState() { | 4067 void Browser::UpdateCommandsForTabState() { |
| 4065 TabContents* current_tab = GetSelectedTabContents(); | 4068 TabContents* current_tab = GetSelectedTabContents(); |
| 4066 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); | 4069 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); |
| 4067 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. | 4070 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. |
| 4068 return; | 4071 return; |
| 4069 | 4072 |
| 4070 // Navigation commands | 4073 // Navigation commands |
| 4071 NavigationController& nc = current_tab->controller(); | 4074 NavigationController& nc = current_tab->controller(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4152 bool enabled = | 4155 bool enabled = |
| 4153 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled) && | 4156 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled) && |
| 4154 browser_defaults::bookmarks_enabled; | 4157 browser_defaults::bookmarks_enabled; |
| 4155 | 4158 |
| 4156 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, | 4159 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, |
| 4157 enabled && is_type_tabbed()); | 4160 enabled && is_type_tabbed()); |
| 4158 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, | 4161 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, |
| 4159 enabled && CanBookmarkAllTabs()); | 4162 enabled && CanBookmarkAllTabs()); |
| 4160 } | 4163 } |
| 4161 | 4164 |
| 4165 void Browser::UpdateCommandsForBookmarkBar() { |
| 4166 #if !defined(OS_MACOSX) |
| 4167 const bool show_main_ui = is_type_tabbed() && |
| 4168 (!window_ || !window_->IsFullscreen()); |
| 4169 #else |
| 4170 const bool show_main_ui = is_type_tabbed(); |
| 4171 #endif |
| 4172 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, |
| 4173 browser_defaults::bookmarks_enabled && |
| 4174 !profile_->GetPrefs()->IsManagedPreference(prefs::kEnableBookmarkBar) && |
| 4175 show_main_ui); |
| 4176 } |
| 4177 |
| 4162 void Browser::UpdateSaveAsState(int content_restrictions) { | 4178 void Browser::UpdateSaveAsState(int content_restrictions) { |
| 4163 bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE); | 4179 bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE); |
| 4164 PrefService* state = g_browser_process->local_state(); | 4180 PrefService* state = g_browser_process->local_state(); |
| 4165 if (state) | 4181 if (state) |
| 4166 enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); | 4182 enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 4167 | 4183 |
| 4168 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); | 4184 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); |
| 4169 } | 4185 } |
| 4170 | 4186 |
| 4171 void Browser::UpdateOpenFileState() { | 4187 void Browser::UpdateOpenFileState() { |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4836 } | 4852 } |
| 4837 | 4853 |
| 4838 void Browser::ShowSyncSetup() { | 4854 void Browser::ShowSyncSetup() { |
| 4839 ProfileSyncService* service = | 4855 ProfileSyncService* service = |
| 4840 profile()->GetOriginalProfile()->GetProfileSyncService(); | 4856 profile()->GetOriginalProfile()->GetProfileSyncService(); |
| 4841 if (service->HasSyncSetupCompleted()) | 4857 if (service->HasSyncSetupCompleted()) |
| 4842 ShowOptionsTab(chrome::kSyncSetupSubPage); | 4858 ShowOptionsTab(chrome::kSyncSetupSubPage); |
| 4843 else | 4859 else |
| 4844 service->ShowLoginDialog(); | 4860 service->ShowLoginDialog(); |
| 4845 } | 4861 } |
| OLD | NEW |