Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 7520023: Converted IncognitoForced boolean policy into IncognitoModeAvailability enum policy. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Removed unnecessary comment. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 PrefService::UNSYNCABLE_PREF); 2243 PrefService::UNSYNCABLE_PREF);
2240 prefs->RegisterStringPref(prefs::kCloudPrintEmail, 2244 prefs->RegisterStringPref(prefs::kCloudPrintEmail,
2241 std::string(), 2245 std::string(),
2242 PrefService::UNSYNCABLE_PREF); 2246 PrefService::UNSYNCABLE_PREF);
2243 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, 2247 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled,
2244 true, 2248 true,
2245 PrefService::UNSYNCABLE_PREF); 2249 PrefService::UNSYNCABLE_PREF);
2246 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, 2250 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled,
2247 false, 2251 false,
2248 PrefService::UNSYNCABLE_PREF); 2252 PrefService::UNSYNCABLE_PREF);
2249 prefs->RegisterBooleanPref(prefs::kIncognitoEnabled,
2250 true,
2251 PrefService::UNSYNCABLE_PREF);
2252 prefs->RegisterBooleanPref(prefs::kIncognitoForced,
2253 false,
2254 PrefService::UNSYNCABLE_PREF);
2255 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, 2253 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation,
2256 -1, 2254 -1,
2257 PrefService::UNSYNCABLE_PREF); 2255 PrefService::UNSYNCABLE_PREF);
2258 prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement, 2256 prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement,
2259 PrefService::UNSYNCABLE_PREF); 2257 PrefService::UNSYNCABLE_PREF);
2260 prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement, 2258 prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement,
2261 PrefService::UNSYNCABLE_PREF); 2259 PrefService::UNSYNCABLE_PREF);
2262 // We need to register the type of these preferences in order to query 2260 // We need to register the type of these preferences in order to query
2263 // them even though they're only typically controlled via policy. 2261 // them even though they're only typically controlled via policy.
2264 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, 2262 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 } else if (pref_name == prefs::kInstantEnabled) { 3696 } else if (pref_name == prefs::kInstantEnabled) {
3699 if (!InstantController::IsEnabled(profile())) { 3697 if (!InstantController::IsEnabled(profile())) {
3700 if (instant()) { 3698 if (instant()) {
3701 instant()->DestroyPreviewContents(); 3699 instant()->DestroyPreviewContents();
3702 instant_.reset(); 3700 instant_.reset();
3703 instant_unload_handler_.reset(); 3701 instant_unload_handler_.reset();
3704 } 3702 }
3705 } else { 3703 } else {
3706 CreateInstantIfNecessary(); 3704 CreateInstantIfNecessary();
3707 } 3705 }
3708 } else if (pref_name == prefs::kIncognitoEnabled) { 3706 } else if (pref_name == prefs::kIncognitoModeAvailability) {
3707 IncognitoModePrefs::Availability available =
3708 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
3709 command_updater_.UpdateCommandEnabled(
3710 IDC_NEW_WINDOW,
3711 available != IncognitoModePrefs::FORCED);
3709 command_updater_.UpdateCommandEnabled( 3712 command_updater_.UpdateCommandEnabled(
3710 IDC_NEW_INCOGNITO_WINDOW, 3713 IDC_NEW_INCOGNITO_WINDOW,
3711 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); 3714 available != IncognitoModePrefs::DISABLED);
3712 } else if (pref_name == prefs::kDevToolsDisabled) { 3715 } else if (pref_name == prefs::kDevToolsDisabled) {
3713 UpdateCommandsForDevTools(); 3716 UpdateCommandsForDevTools();
3714 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 3717 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
3715 g_browser_process->devtools_manager()->CloseAllClientHosts(); 3718 g_browser_process->devtools_manager()->CloseAllClientHosts();
3716 } else if (pref_name == prefs::kEditBookmarksEnabled) { 3719 } else if (pref_name == prefs::kEditBookmarksEnabled) {
3717 UpdateCommandsForBookmarkEditing(); 3720 UpdateCommandsForBookmarkEditing();
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 {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 void Browser::InitCommandState() { 3839 void Browser::InitCommandState() {
3837 // All browser commands whose state isn't set automagically some other way 3840 // All browser commands whose state isn't set automagically some other way
3838 // (like Back & Forward with initial page load) must have their state 3841 // (like Back & Forward with initial page load) must have their state
3839 // initialized here, otherwise they will be forever disabled. 3842 // initialized here, otherwise they will be forever disabled.
3840 3843
3841 // Navigation commands 3844 // Navigation commands
3842 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); 3845 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
3843 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); 3846 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true);
3844 3847
3845 // Window management commands 3848 // Window management commands
3846 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); 3849 IncognitoModePrefs::Availability incognito_avail =
3850 IncognitoModePrefs::GetAvailability(profile_->GetPrefs());
3851 command_updater_.UpdateCommandEnabled(
3852 IDC_NEW_WINDOW,
3853 incognito_avail != IncognitoModePrefs::FORCED);
3847 command_updater_.UpdateCommandEnabled( 3854 command_updater_.UpdateCommandEnabled(
3848 IDC_NEW_INCOGNITO_WINDOW, 3855 IDC_NEW_INCOGNITO_WINDOW,
3849 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); 3856 incognito_avail != IncognitoModePrefs::DISABLED);
3857
3850 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); 3858 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
3851 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); 3859 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
3852 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); 3860 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
3853 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); 3861 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
3854 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); 3862 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false);
3855 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); 3863 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
3856 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true); 3864 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true);
3857 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); 3865 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
3858 3866
3859 // Page-related commands 3867 // Page-related commands
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
4814 } 4822 }
4815 4823
4816 void Browser::ShowSyncSetup() { 4824 void Browser::ShowSyncSetup() {
4817 ProfileSyncService* service = 4825 ProfileSyncService* service =
4818 profile()->GetOriginalProfile()->GetProfileSyncService(); 4826 profile()->GetOriginalProfile()->GetProfileSyncService();
4819 if (service->HasSyncSetupCompleted()) 4827 if (service->HasSyncSetupCompleted())
4820 ShowOptionsTab(chrome::kSyncSetupSubPage); 4828 ShowOptionsTab(chrome::kSyncSetupSubPage);
4821 else 4829 else
4822 service->ShowLoginDialog(); 4830 service->ShowLoginDialog();
4823 } 4831 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/render_view_context_menu.cc ('k') | chrome/browser/ui/browser_init.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698