| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 PrefService* local_state = g_browser_process->local_state(); | 284 PrefService* local_state = g_browser_process->local_state(); |
| 285 if (local_state) { | 285 if (local_state) { |
| 286 local_pref_registrar_.Init(local_state); | 286 local_pref_registrar_.Init(local_state); |
| 287 local_pref_registrar_.Add(prefs::kPrintingEnabled, this); | 287 local_pref_registrar_.Add(prefs::kPrintingEnabled, this); |
| 288 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); | 288 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); |
| 289 } | 289 } |
| 290 | 290 |
| 291 profile_pref_registrar_.Init(profile_->GetPrefs()); | 291 profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 292 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); | 292 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
| 293 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); | 293 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); |
| 294 profile_pref_registrar_.Add(prefs::kEnableBookmarkBar, this); |
| 294 profile_pref_registrar_.Add(prefs::kInstantEnabled, this); | 295 profile_pref_registrar_.Add(prefs::kInstantEnabled, this); |
| 295 profile_pref_registrar_.Add(prefs::kIncognitoEnabled, this); | 296 profile_pref_registrar_.Add(prefs::kIncognitoEnabled, this); |
| 296 | 297 |
| 297 InitCommandState(); | 298 InitCommandState(); |
| 298 BrowserList::AddBrowser(this); | 299 BrowserList::AddBrowser(this); |
| 299 | 300 |
| 300 // NOTE: These prefs all need to be explicitly destroyed in the destructor | 301 // NOTE: These prefs all need to be explicitly destroyed in the destructor |
| 301 // or you'll get a nasty surprise when you run the incognito tests. | 302 // or you'll get a nasty surprise when you run the incognito tests. |
| 302 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, | 303 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 303 profile_->GetPrefs(), NULL); | 304 profile_->GetPrefs(), NULL); |
| (...skipping 3404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3708 } else if (pref_name == prefs::kIncognitoEnabled) { | 3709 } else if (pref_name == prefs::kIncognitoEnabled) { |
| 3709 command_updater_.UpdateCommandEnabled( | 3710 command_updater_.UpdateCommandEnabled( |
| 3710 IDC_NEW_INCOGNITO_WINDOW, | 3711 IDC_NEW_INCOGNITO_WINDOW, |
| 3711 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); | 3712 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); |
| 3712 } else if (pref_name == prefs::kDevToolsDisabled) { | 3713 } else if (pref_name == prefs::kDevToolsDisabled) { |
| 3713 UpdateCommandsForDevTools(); | 3714 UpdateCommandsForDevTools(); |
| 3714 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 3715 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
| 3715 g_browser_process->devtools_manager()->CloseAllClientHosts(); | 3716 g_browser_process->devtools_manager()->CloseAllClientHosts(); |
| 3716 } else if (pref_name == prefs::kEditBookmarksEnabled) { | 3717 } else if (pref_name == prefs::kEditBookmarksEnabled) { |
| 3717 UpdateCommandsForBookmarkEditing(); | 3718 UpdateCommandsForBookmarkEditing(); |
| 3719 } else if (pref_name == prefs::kEnableBookmarkBar) { |
| 3720 UpdateCommandsForBookmarkBar(); |
| 3718 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { | 3721 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { |
| 3719 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); | 3722 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); |
| 3720 UpdateOpenFileState(); | 3723 UpdateOpenFileState(); |
| 3721 } else { | 3724 } else { |
| 3722 NOTREACHED(); | 3725 NOTREACHED(); |
| 3723 } | 3726 } |
| 3724 break; | 3727 break; |
| 3725 } | 3728 } |
| 3726 | 3729 |
| 3727 case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: { | 3730 case chrome::NOTIFICATION_TAB_CONTENT_SETTINGS_CHANGED: { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4014 command_updater_.UpdateCommandEnabled( | 4017 command_updater_.UpdateCommandEnabled( |
| 4015 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); | 4018 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen); |
| 4016 command_updater_.UpdateCommandEnabled( | 4019 command_updater_.UpdateCommandEnabled( |
| 4017 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); | 4020 IDC_FOCUS_BOOKMARKS, main_not_fullscreen); |
| 4018 command_updater_.UpdateCommandEnabled( | 4021 command_updater_.UpdateCommandEnabled( |
| 4019 IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen); | 4022 IDC_FOCUS_CHROMEOS_STATUS, main_not_fullscreen); |
| 4020 | 4023 |
| 4021 // Show various bits of UI | 4024 // Show various bits of UI |
| 4022 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); | 4025 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui); |
| 4023 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); | 4026 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui); |
| 4024 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, | |
| 4025 browser_defaults::bookmarks_enabled && show_main_ui); | |
| 4026 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, show_main_ui); | 4027 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, show_main_ui); |
| 4027 command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, | 4028 command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, |
| 4028 show_main_ui && profile_->IsSyncAccessible()); | 4029 show_main_ui && profile_->IsSyncAccessible()); |
| 4029 | 4030 |
| 4030 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, show_main_ui); | 4031 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, show_main_ui); |
| 4031 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); | 4032 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui); |
| 4032 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); | 4033 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui); |
| 4033 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); | 4034 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui); |
| 4034 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); | 4035 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui); |
| 4035 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); | 4036 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, show_main_ui); |
| 4036 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); | 4037 command_updater_.UpdateCommandEnabled(IDC_COMPACT_NAVBAR, show_main_ui); |
| 4037 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) | 4038 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC) |
| 4038 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); | 4039 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui); |
| 4039 #endif | 4040 #endif |
| 4041 |
| 4042 UpdateCommandsForBookmarkBar(); |
| 4040 } | 4043 } |
| 4041 | 4044 |
| 4042 void Browser::UpdateCommandsForTabState() { | 4045 void Browser::UpdateCommandsForTabState() { |
| 4043 TabContents* current_tab = GetSelectedTabContents(); | 4046 TabContents* current_tab = GetSelectedTabContents(); |
| 4044 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); | 4047 TabContentsWrapper* current_tab_wrapper = GetSelectedTabContentsWrapper(); |
| 4045 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. | 4048 if (!current_tab || !current_tab_wrapper) // May be NULL during tab restore. |
| 4046 return; | 4049 return; |
| 4047 | 4050 |
| 4048 // Navigation commands | 4051 // Navigation commands |
| 4049 NavigationController& nc = current_tab->controller(); | 4052 NavigationController& nc = current_tab->controller(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4130 bool enabled = | 4133 bool enabled = |
| 4131 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled) && | 4134 profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled) && |
| 4132 browser_defaults::bookmarks_enabled; | 4135 browser_defaults::bookmarks_enabled; |
| 4133 | 4136 |
| 4134 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, | 4137 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE, |
| 4135 enabled && is_type_tabbed()); | 4138 enabled && is_type_tabbed()); |
| 4136 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, | 4139 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS, |
| 4137 enabled && CanBookmarkAllTabs()); | 4140 enabled && CanBookmarkAllTabs()); |
| 4138 } | 4141 } |
| 4139 | 4142 |
| 4143 void Browser::UpdateCommandsForBookmarkBar() { |
| 4144 #if !defined(OS_MACOSX) |
| 4145 const bool show_main_ui = is_type_tabbed() && |
| 4146 (!window_ || !window_->IsFullscreen()); |
| 4147 #else |
| 4148 const bool show_main_ui = is_type_tabbed(); |
| 4149 #endif |
| 4150 command_updater_.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR, |
| 4151 browser_defaults::bookmarks_enabled && |
| 4152 !profile_->GetPrefs()->IsManagedPreference(prefs::kEnableBookmarkBar) && |
| 4153 show_main_ui); |
| 4154 } |
| 4155 |
| 4140 void Browser::UpdateSaveAsState(int content_restrictions) { | 4156 void Browser::UpdateSaveAsState(int content_restrictions) { |
| 4141 bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE); | 4157 bool enabled = !(content_restrictions & CONTENT_RESTRICTION_SAVE); |
| 4142 PrefService* state = g_browser_process->local_state(); | 4158 PrefService* state = g_browser_process->local_state(); |
| 4143 if (state) | 4159 if (state) |
| 4144 enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); | 4160 enabled = enabled && state->GetBoolean(prefs::kAllowFileSelectionDialogs); |
| 4145 | 4161 |
| 4146 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); | 4162 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, enabled); |
| 4147 } | 4163 } |
| 4148 | 4164 |
| 4149 void Browser::UpdateOpenFileState() { | 4165 void Browser::UpdateOpenFileState() { |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4814 } | 4830 } |
| 4815 | 4831 |
| 4816 void Browser::ShowSyncSetup() { | 4832 void Browser::ShowSyncSetup() { |
| 4817 ProfileSyncService* service = | 4833 ProfileSyncService* service = |
| 4818 profile()->GetOriginalProfile()->GetProfileSyncService(); | 4834 profile()->GetOriginalProfile()->GetProfileSyncService(); |
| 4819 if (service->HasSyncSetupCompleted()) | 4835 if (service->HasSyncSetupCompleted()) |
| 4820 ShowOptionsTab(chrome::kSyncSetupSubPage); | 4836 ShowOptionsTab(chrome::kSyncSetupSubPage); |
| 4821 else | 4837 else |
| 4822 service->ShowLoginDialog(); | 4838 service->ShowLoginDialog(); |
| 4823 } | 4839 } |
| OLD | NEW |