| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "chrome/browser/favicon/favicon_tab_helper.h" | 48 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 49 #include "chrome/browser/first_run/first_run.h" | 49 #include "chrome/browser/first_run/first_run.h" |
| 50 #include "chrome/browser/google/google_url_tracker.h" | 50 #include "chrome/browser/google/google_url_tracker.h" |
| 51 #include "chrome/browser/google/google_util.h" | 51 #include "chrome/browser/google/google_util.h" |
| 52 #include "chrome/browser/instant/instant_controller.h" | 52 #include "chrome/browser/instant/instant_controller.h" |
| 53 #include "chrome/browser/instant/instant_unload_handler.h" | 53 #include "chrome/browser/instant/instant_unload_handler.h" |
| 54 #include "chrome/browser/net/browser_url_util.h" | 54 #include "chrome/browser/net/browser_url_util.h" |
| 55 #include "chrome/browser/net/url_fixer_upper.h" | 55 #include "chrome/browser/net/url_fixer_upper.h" |
| 56 #include "chrome/browser/notifications/notification_ui_manager.h" | 56 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 57 #include "chrome/browser/platform_util.h" | 57 #include "chrome/browser/platform_util.h" |
| 58 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 58 #include "chrome/browser/prefs/pref_service.h" | 59 #include "chrome/browser/prefs/pref_service.h" |
| 59 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" | 60 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
| 60 #include "chrome/browser/profiles/profile.h" | 61 #include "chrome/browser/profiles/profile.h" |
| 61 #include "chrome/browser/sessions/restore_tab_helper.h" | 62 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 62 #include "chrome/browser/sessions/session_service.h" | 63 #include "chrome/browser/sessions/session_service.h" |
| 63 #include "chrome/browser/sessions/session_service_factory.h" | 64 #include "chrome/browser/sessions/session_service_factory.h" |
| 64 #include "chrome/browser/sessions/session_types.h" | 65 #include "chrome/browser/sessions/session_types.h" |
| 65 #include "chrome/browser/sessions/tab_restore_service.h" | 66 #include "chrome/browser/sessions/tab_restore_service.h" |
| 66 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 67 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 67 #include "chrome/browser/sync/profile_sync_service.h" | 68 #include "chrome/browser/sync/profile_sync_service.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if (local_state) { | 286 if (local_state) { |
| 286 local_pref_registrar_.Init(local_state); | 287 local_pref_registrar_.Init(local_state); |
| 287 local_pref_registrar_.Add(prefs::kPrintingEnabled, this); | 288 local_pref_registrar_.Add(prefs::kPrintingEnabled, this); |
| 288 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); | 289 local_pref_registrar_.Add(prefs::kAllowFileSelectionDialogs, this); |
| 289 } | 290 } |
| 290 | 291 |
| 291 profile_pref_registrar_.Init(profile_->GetPrefs()); | 292 profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 292 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); | 293 profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
| 293 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); | 294 profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, 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::kIncognitoModeAvailability, 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); |
| 304 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); | 305 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); |
| 305 use_compact_navigation_bar_.Init(prefs::kUseCompactNavigationBar, | 306 use_compact_navigation_bar_.Init(prefs::kUseCompactNavigationBar, |
| (...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 1464 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
| 1464 } | 1465 } |
| 1465 } | 1466 } |
| 1466 | 1467 |
| 1467 void Browser::Stop() { | 1468 void Browser::Stop() { |
| 1468 UserMetrics::RecordAction(UserMetricsAction("Stop")); | 1469 UserMetrics::RecordAction(UserMetricsAction("Stop")); |
| 1469 GetSelectedTabContentsWrapper()->tab_contents()->Stop(); | 1470 GetSelectedTabContentsWrapper()->tab_contents()->Stop(); |
| 1470 } | 1471 } |
| 1471 | 1472 |
| 1472 void Browser::NewWindow() { | 1473 void Browser::NewWindow() { |
| 1474 IncognitoModePrefs::Availability incognito_avail = |
| 1475 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| 1473 if (browser_defaults::kAlwaysOpenIncognitoWindow && | 1476 if (browser_defaults::kAlwaysOpenIncognitoWindow && |
| 1477 incognito_avail != IncognitoModePrefs::DISABLED && |
| 1474 (CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) || | 1478 (CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) || |
| 1475 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoForced)) && | 1479 incognito_avail == IncognitoModePrefs::FORCED)) { |
| 1476 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { | |
| 1477 NewIncognitoWindow(); | 1480 NewIncognitoWindow(); |
| 1478 return; | 1481 return; |
| 1479 } | 1482 } |
| 1480 UserMetrics::RecordAction(UserMetricsAction("NewWindow")); | 1483 UserMetrics::RecordAction(UserMetricsAction("NewWindow")); |
| 1481 SessionService* session_service = | 1484 SessionService* session_service = |
| 1482 SessionServiceFactory::GetForProfile(profile_->GetOriginalProfile()); | 1485 SessionServiceFactory::GetForProfile(profile_->GetOriginalProfile()); |
| 1483 if (!session_service || | 1486 if (!session_service || |
| 1484 !session_service->RestoreIfNecessary(std::vector<GURL>())) { | 1487 !session_service->RestoreIfNecessary(std::vector<GURL>())) { |
| 1485 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); | 1488 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); |
| 1486 } | 1489 } |
| 1487 } | 1490 } |
| 1488 | 1491 |
| 1489 void Browser::NewIncognitoWindow() { | 1492 void Browser::NewIncognitoWindow() { |
| 1490 if (!profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { | 1493 if (IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) == |
| 1494 IncognitoModePrefs::DISABLED) { |
| 1491 NewWindow(); | 1495 NewWindow(); |
| 1492 return; | 1496 return; |
| 1493 } | 1497 } |
| 1494 | 1498 |
| 1495 UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow")); | 1499 UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow")); |
| 1496 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); | 1500 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); |
| 1497 } | 1501 } |
| 1498 | 1502 |
| 1499 void Browser::CloseWindow() { | 1503 void Browser::CloseWindow() { |
| 1500 UserMetrics::RecordAction(UserMetricsAction("CloseWindow")); | 1504 UserMetrics::RecordAction(UserMetricsAction("CloseWindow")); |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2245 PrefService::UNSYNCABLE_PREF); | 2249 PrefService::UNSYNCABLE_PREF); |
| 2246 prefs->RegisterStringPref(prefs::kCloudPrintEmail, | 2250 prefs->RegisterStringPref(prefs::kCloudPrintEmail, |
| 2247 std::string(), | 2251 std::string(), |
| 2248 PrefService::UNSYNCABLE_PREF); | 2252 PrefService::UNSYNCABLE_PREF); |
| 2249 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, | 2253 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, |
| 2250 true, | 2254 true, |
| 2251 PrefService::UNSYNCABLE_PREF); | 2255 PrefService::UNSYNCABLE_PREF); |
| 2252 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, | 2256 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, |
| 2253 false, | 2257 false, |
| 2254 PrefService::UNSYNCABLE_PREF); | 2258 PrefService::UNSYNCABLE_PREF); |
| 2255 prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, | |
| 2256 true, | |
| 2257 PrefService::UNSYNCABLE_PREF); | |
| 2258 prefs->RegisterBooleanPref(prefs::kIncognitoForced, | |
| 2259 false, | |
| 2260 PrefService::UNSYNCABLE_PREF); | |
| 2261 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, | 2259 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, |
| 2262 -1, | 2260 -1, |
| 2263 PrefService::UNSYNCABLE_PREF); | 2261 PrefService::UNSYNCABLE_PREF); |
| 2264 prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement, | 2262 prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement, |
| 2265 PrefService::UNSYNCABLE_PREF); | 2263 PrefService::UNSYNCABLE_PREF); |
| 2266 prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement, | 2264 prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement, |
| 2267 PrefService::UNSYNCABLE_PREF); | 2265 PrefService::UNSYNCABLE_PREF); |
| 2268 // We need to register the type of these preferences in order to query | 2266 // We need to register the type of these preferences in order to query |
| 2269 // them even though they're only typically controlled via policy. | 2267 // them even though they're only typically controlled via policy. |
| 2270 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, | 2268 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, |
| (...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3688 } else if (pref_name == prefs::kInstantEnabled) { | 3686 } else if (pref_name == prefs::kInstantEnabled) { |
| 3689 if (!InstantController::IsEnabled(profile())) { | 3687 if (!InstantController::IsEnabled(profile())) { |
| 3690 if (instant()) { | 3688 if (instant()) { |
| 3691 instant()->DestroyPreviewContents(); | 3689 instant()->DestroyPreviewContents(); |
| 3692 instant_.reset(); | 3690 instant_.reset(); |
| 3693 instant_unload_handler_.reset(); | 3691 instant_unload_handler_.reset(); |
| 3694 } | 3692 } |
| 3695 } else { | 3693 } else { |
| 3696 CreateInstantIfNecessary(); | 3694 CreateInstantIfNecessary(); |
| 3697 } | 3695 } |
| 3698 } else if (pref_name == prefs::kIncognitoEnabled) { | 3696 } else if (pref_name == prefs::kIncognitoModeAvailability) { |
| 3697 IncognitoModePrefs::Availability available = |
| 3698 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| 3699 command_updater_.UpdateCommandEnabled( |
| 3700 IDC_NEW_WINDOW, |
| 3701 available != IncognitoModePrefs::FORCED); |
| 3699 command_updater_.UpdateCommandEnabled( | 3702 command_updater_.UpdateCommandEnabled( |
| 3700 IDC_NEW_INCOGNITO_WINDOW, | 3703 IDC_NEW_INCOGNITO_WINDOW, |
| 3701 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); | 3704 available != IncognitoModePrefs::DISABLED); |
| 3702 } else if (pref_name == prefs::kDevToolsDisabled) { | 3705 } else if (pref_name == prefs::kDevToolsDisabled) { |
| 3703 UpdateCommandsForDevTools(); | 3706 UpdateCommandsForDevTools(); |
| 3704 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) | 3707 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
| 3705 g_browser_process->devtools_manager()->CloseAllClientHosts(); | 3708 g_browser_process->devtools_manager()->CloseAllClientHosts(); |
| 3706 } else if (pref_name == prefs::kEditBookmarksEnabled) { | 3709 } else if (pref_name == prefs::kEditBookmarksEnabled) { |
| 3707 UpdateCommandsForBookmarkEditing(); | 3710 UpdateCommandsForBookmarkEditing(); |
| 3708 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { | 3711 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { |
| 3709 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); | 3712 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); |
| 3710 UpdateOpenFileState(); | 3713 UpdateOpenFileState(); |
| 3711 } else { | 3714 } else { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3826 void Browser::InitCommandState() { | 3829 void Browser::InitCommandState() { |
| 3827 // All browser commands whose state isn't set automagically some other way | 3830 // All browser commands whose state isn't set automagically some other way |
| 3828 // (like Back & Forward with initial page load) must have their state | 3831 // (like Back & Forward with initial page load) must have their state |
| 3829 // initialized here, otherwise they will be forever disabled. | 3832 // initialized here, otherwise they will be forever disabled. |
| 3830 | 3833 |
| 3831 // Navigation commands | 3834 // Navigation commands |
| 3832 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); | 3835 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
| 3833 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); | 3836 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); |
| 3834 | 3837 |
| 3835 // Window management commands | 3838 // Window management commands |
| 3836 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); | 3839 IncognitoModePrefs::Availability incognito_avail = |
| 3840 IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); |
| 3841 command_updater_.UpdateCommandEnabled( |
| 3842 IDC_NEW_WINDOW, |
| 3843 incognito_avail != IncognitoModePrefs::FORCED); |
| 3837 command_updater_.UpdateCommandEnabled( | 3844 command_updater_.UpdateCommandEnabled( |
| 3838 IDC_NEW_INCOGNITO_WINDOW, | 3845 IDC_NEW_INCOGNITO_WINDOW, |
| 3839 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); | 3846 incognito_avail != IncognitoModePrefs::DISABLED); |
| 3847 |
| 3840 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); | 3848 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 3841 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); | 3849 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); |
| 3842 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); | 3850 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); |
| 3843 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); | 3851 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); |
| 3844 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); | 3852 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); |
| 3845 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); | 3853 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
| 3846 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true); | 3854 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true); |
| 3847 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); | 3855 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); |
| 3848 | 3856 |
| 3849 // Page-related commands | 3857 // Page-related commands |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4803 window_->BookmarkBarStateChanged(animate_type); | 4811 window_->BookmarkBarStateChanged(animate_type); |
| 4804 } | 4812 } |
| 4805 | 4813 |
| 4806 void Browser::ShowSyncSetup() { | 4814 void Browser::ShowSyncSetup() { |
| 4807 ProfileSyncService* service = profile()->GetProfileSyncService(); | 4815 ProfileSyncService* service = profile()->GetProfileSyncService(); |
| 4808 if (service->HasSyncSetupCompleted()) | 4816 if (service->HasSyncSetupCompleted()) |
| 4809 ShowOptionsTab(chrome::kSyncSetupSubPage); | 4817 ShowOptionsTab(chrome::kSyncSetupSubPage); |
| 4810 else | 4818 else |
| 4811 profile()->GetProfileSyncService()->ShowLoginDialog(); | 4819 profile()->GetProfileSyncService()->ShowLoginDialog(); |
| 4812 } | 4820 } |
| OLD | NEW |