| 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 <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 // Need to know when to alert the user of theme install delay. | 217 // Need to know when to alert the user of theme install delay. |
| 218 registrar_.Add(this, NotificationType::EXTENSION_READY_FOR_INSTALL, | 218 registrar_.Add(this, NotificationType::EXTENSION_READY_FOR_INSTALL, |
| 219 NotificationService::AllSources()); | 219 NotificationService::AllSources()); |
| 220 | 220 |
| 221 PrefService* local_state = g_browser_process->local_state(); | 221 PrefService* local_state = g_browser_process->local_state(); |
| 222 if (local_state) | 222 if (local_state) |
| 223 printing_enabled_.Init(prefs::kPrintingEnabled, local_state, this); | 223 printing_enabled_.Init(prefs::kPrintingEnabled, local_state, this); |
| 224 dev_tools_disabled_.Init(prefs::kDevToolsDisabled, | 224 dev_tools_disabled_.Init(prefs::kDevToolsDisabled, |
| 225 profile_->GetPrefs(), this); | 225 profile_->GetPrefs(), this); |
| 226 incognito_mode_allowed_.Init(prefs::kIncognitoEnabled, | |
| 227 profile_->GetPrefs(), this); | |
| 228 | 226 |
| 229 InitCommandState(); | 227 InitCommandState(); |
| 230 BrowserList::AddBrowser(this); | 228 BrowserList::AddBrowser(this); |
| 231 | 229 |
| 232 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, | 230 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 233 profile_->GetPrefs(), NULL); | 231 profile_->GetPrefs(), NULL); |
| 234 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); | 232 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); |
| 235 instant_enabled_.Init(prefs::kInstantEnabled, profile_->GetPrefs(), this); | 233 instant_enabled_.Init(prefs::kInstantEnabled, profile_->GetPrefs(), this); |
| 236 if (!TabMenuModel::AreVerticalTabsEnabled()) { | 234 if (!TabMenuModel::AreVerticalTabsEnabled()) { |
| 237 // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we | 235 // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 browser::Navigate(¶ms); | 1298 browser::Navigate(¶ms); |
| 1301 } | 1299 } |
| 1302 | 1300 |
| 1303 void Browser::Stop() { | 1301 void Browser::Stop() { |
| 1304 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); | 1302 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); |
| 1305 GetSelectedTabContentsWrapper()->tab_contents()->Stop(); | 1303 GetSelectedTabContentsWrapper()->tab_contents()->Stop(); |
| 1306 } | 1304 } |
| 1307 | 1305 |
| 1308 void Browser::NewWindow() { | 1306 void Browser::NewWindow() { |
| 1309 if (browser_defaults::kAlwaysOpenIncognitoWindow && | 1307 if (browser_defaults::kAlwaysOpenIncognitoWindow && |
| 1310 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) && | 1308 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito)) { |
| 1311 incognito_mode_allowed_.GetValue()) { | |
| 1312 NewIncognitoWindow(); | 1309 NewIncognitoWindow(); |
| 1313 return; | 1310 return; |
| 1314 } | 1311 } |
| 1315 UserMetrics::RecordAction(UserMetricsAction("NewWindow"), profile_); | 1312 UserMetrics::RecordAction(UserMetricsAction("NewWindow"), profile_); |
| 1316 SessionService* session_service = | 1313 SessionService* session_service = |
| 1317 profile_->GetOriginalProfile()->GetSessionService(); | 1314 profile_->GetOriginalProfile()->GetSessionService(); |
| 1318 if (!session_service || | 1315 if (!session_service || |
| 1319 !session_service->RestoreIfNecessary(std::vector<GURL>())) { | 1316 !session_service->RestoreIfNecessary(std::vector<GURL>())) { |
| 1320 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); | 1317 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); |
| 1321 } | 1318 } |
| 1322 } | 1319 } |
| 1323 | 1320 |
| 1324 void Browser::NewIncognitoWindow() { | 1321 void Browser::NewIncognitoWindow() { |
| 1325 if (!incognito_mode_allowed_.GetValue()) { | |
| 1326 NewWindow(); | |
| 1327 return; | |
| 1328 } | |
| 1329 | |
| 1330 UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow"), profile_); | 1322 UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow"), profile_); |
| 1331 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); | 1323 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); |
| 1332 } | 1324 } |
| 1333 | 1325 |
| 1334 void Browser::CloseWindow() { | 1326 void Browser::CloseWindow() { |
| 1335 UserMetrics::RecordAction(UserMetricsAction("CloseWindow"), profile_); | 1327 UserMetrics::RecordAction(UserMetricsAction("CloseWindow"), profile_); |
| 1336 window_->Close(); | 1328 window_->Close(); |
| 1337 } | 1329 } |
| 1338 | 1330 |
| 1339 void Browser::NewTab() { | 1331 void Browser::NewTab() { |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 } | 1935 } |
| 1944 } | 1936 } |
| 1945 | 1937 |
| 1946 void Browser::OpenLanguageOptionsDialog() { | 1938 void Browser::OpenLanguageOptionsDialog() { |
| 1947 UserMetrics::RecordAction(UserMetricsAction("OpenLanguageOptionsDialog"), | 1939 UserMetrics::RecordAction(UserMetricsAction("OpenLanguageOptionsDialog"), |
| 1948 profile_); | 1940 profile_); |
| 1949 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 1941 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 1950 switches::kDisableTabbedOptions)) { | 1942 switches::kDisableTabbedOptions)) { |
| 1951 ShowOptionsTab(chrome::kLanguageOptionsSubPage); | 1943 ShowOptionsTab(chrome::kLanguageOptionsSubPage); |
| 1952 } else { | 1944 } else { |
| 1953 // Language options dialog has been replaced by DOMUI. | 1945 // Language options dialog has been replaced by DOMUI. |
| 1954 } | 1946 } |
| 1955 } | 1947 } |
| 1956 | 1948 |
| 1957 void Browser::OpenSystemTabAndActivate() { | 1949 void Browser::OpenSystemTabAndActivate() { |
| 1958 OpenURL(GURL(chrome::kChromeUISystemInfoURL), GURL(), | 1950 OpenURL(GURL(chrome::kChromeUISystemInfoURL), GURL(), |
| 1959 NEW_FOREGROUND_TAB, PageTransition::LINK); | 1951 NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 1960 window_->Activate(); | 1952 window_->Activate(); |
| 1961 } | 1953 } |
| 1962 | 1954 |
| 1963 void Browser::OpenMobilePlanTabAndActivate() { | 1955 void Browser::OpenMobilePlanTabAndActivate() { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2039 prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, true); | 2031 prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, true); |
| 2040 prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, true); | 2032 prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, true); |
| 2041 prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, true); | 2033 prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, true); |
| 2042 prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true); | 2034 prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true); |
| 2043 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true); | 2035 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true); |
| 2044 prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, false); | 2036 prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, false); |
| 2045 prefs->RegisterBooleanPref(prefs::kEnableTranslate, true); | 2037 prefs->RegisterBooleanPref(prefs::kEnableTranslate, true); |
| 2046 prefs->RegisterBooleanPref(prefs::kRemotingHasSetupCompleted, false); | 2038 prefs->RegisterBooleanPref(prefs::kRemotingHasSetupCompleted, false); |
| 2047 prefs->RegisterStringPref(prefs::kCloudPrintEmail, std::string()); | 2039 prefs->RegisterStringPref(prefs::kCloudPrintEmail, std::string()); |
| 2048 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); | 2040 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); |
| 2049 prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, true); | |
| 2050 prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); | 2041 prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); |
| 2051 prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); | 2042 prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); |
| 2052 // We need to register the type of this preference in order to query | 2043 // We need to register the type of this preference in order to query |
| 2053 // it even though it's only typically controlled via policy. | 2044 // it even though it's only typically controlled via policy. |
| 2054 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, false); | 2045 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, false); |
| 2055 } | 2046 } |
| 2056 | 2047 |
| 2057 // static | 2048 // static |
| 2058 bool Browser::RunUnloadEventsHelper(TabContents* contents) { | 2049 bool Browser::RunUnloadEventsHelper(TabContents* contents) { |
| 2059 // If the TabContents is not connected yet, then there's no unload | 2050 // If the TabContents is not connected yet, then there's no unload |
| (...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3443 // All browser commands whose state isn't set automagically some other way | 3434 // All browser commands whose state isn't set automagically some other way |
| 3444 // (like Back & Forward with initial page load) must have their state | 3435 // (like Back & Forward with initial page load) must have their state |
| 3445 // initialized here, otherwise they will be forever disabled. | 3436 // initialized here, otherwise they will be forever disabled. |
| 3446 | 3437 |
| 3447 // Navigation commands | 3438 // Navigation commands |
| 3448 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); | 3439 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
| 3449 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); | 3440 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); |
| 3450 | 3441 |
| 3451 // Window management commands | 3442 // Window management commands |
| 3452 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); | 3443 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); |
| 3453 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, | 3444 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); |
| 3454 incognito_mode_allowed_.GetValue()); | |
| 3455 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); | 3445 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 3456 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); | 3446 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); |
| 3457 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); | 3447 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); |
| 3458 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); | 3448 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); |
| 3459 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); | 3449 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); |
| 3460 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); | 3450 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
| 3461 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true); | 3451 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true); |
| 3462 | 3452 |
| 3463 // Page-related commands | 3453 // Page-related commands |
| 3464 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); | 3454 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4285 // The page transition below is only for the purpose of inserting the tab. | 4275 // The page transition below is only for the purpose of inserting the tab. |
| 4286 browser->AddTab(view_source_contents, PageTransition::LINK); | 4276 browser->AddTab(view_source_contents, PageTransition::LINK); |
| 4287 } | 4277 } |
| 4288 | 4278 |
| 4289 if (profile_->HasSessionService()) { | 4279 if (profile_->HasSessionService()) { |
| 4290 SessionService* session_service = profile_->GetSessionService(); | 4280 SessionService* session_service = profile_->GetSessionService(); |
| 4291 if (session_service) | 4281 if (session_service) |
| 4292 session_service->TabRestored(&view_source_contents->controller(), false); | 4282 session_service->TabRestored(&view_source_contents->controller(), false); |
| 4293 } | 4283 } |
| 4294 } | 4284 } |
| OLD | NEW |