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

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: 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_availability_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 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() {
1473 if (browser_defaults::kAlwaysOpenIncognitoWindow && 1474 if (browser_defaults::kAlwaysOpenIncognitoWindow &&
1474 (CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) || 1475 profile_->GetPrefs()->GetInteger(prefs::kIncognitoModeAvailability) ==
1475 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoForced)) && 1476 IncognitoModeAvailabilityPrefs::FORCED) {
1476 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) {
1477 NewIncognitoWindow(); 1477 NewIncognitoWindow();
1478 return; 1478 return;
1479 } 1479 }
1480 UserMetrics::RecordAction(UserMetricsAction("NewWindow")); 1480 UserMetrics::RecordAction(UserMetricsAction("NewWindow"));
1481 SessionService* session_service = 1481 SessionService* session_service =
1482 SessionServiceFactory::GetForProfile(profile_->GetOriginalProfile()); 1482 SessionServiceFactory::GetForProfile(profile_->GetOriginalProfile());
1483 if (!session_service || 1483 if (!session_service ||
1484 !session_service->RestoreIfNecessary(std::vector<GURL>())) { 1484 !session_service->RestoreIfNecessary(std::vector<GURL>())) {
1485 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); 1485 Browser::OpenEmptyWindow(profile_->GetOriginalProfile());
1486 } 1486 }
1487 } 1487 }
1488 1488
1489 void Browser::NewIncognitoWindow() { 1489 void Browser::NewIncognitoWindow() {
1490 if (!profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { 1490 if (profile_->GetPrefs()->GetInteger(prefs::kIncognitoModeAvailability) ==
1491 IncognitoModeAvailabilityPrefs::DISABLED) {
1491 NewWindow(); 1492 NewWindow();
1492 return; 1493 return;
1493 } 1494 }
1494 1495
1495 UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow")); 1496 UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow"));
1496 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); 1497 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile());
1497 } 1498 }
1498 1499
1499 void Browser::CloseWindow() { 1500 void Browser::CloseWindow() {
1500 UserMetrics::RecordAction(UserMetricsAction("CloseWindow")); 1501 UserMetrics::RecordAction(UserMetricsAction("CloseWindow"));
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 PrefService::UNSYNCABLE_PREF); 2249 PrefService::UNSYNCABLE_PREF);
2249 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, 2250 prefs->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled,
2250 true, 2251 true,
2251 PrefService::UNSYNCABLE_PREF); 2252 PrefService::UNSYNCABLE_PREF);
2252 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, 2253 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled,
2253 false, 2254 false,
2254 PrefService::UNSYNCABLE_PREF); 2255 PrefService::UNSYNCABLE_PREF);
2255 prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, 2256 prefs->RegisterBooleanPref(prefs::kIncognitoEnabled,
2256 true, 2257 true,
2257 PrefService::UNSYNCABLE_PREF); 2258 PrefService::UNSYNCABLE_PREF);
2258 prefs->RegisterBooleanPref(prefs::kIncognitoForced, 2259 prefs->RegisterIntegerPref(prefs::kIncognitoModeAvailability,
Mattias Nissler (ping if slow) 2011/07/28 11:08:50 As mentioned, this should be moved to your helper
rustema 2011/07/29 06:49:23 Done.
2259 false, 2260 IncognitoModeAvailabilityPrefs::ENABLED,
2260 PrefService::UNSYNCABLE_PREF); 2261 PrefService::UNSYNCABLE_PREF);
2261 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, 2262 prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation,
2262 -1, 2263 -1,
2263 PrefService::UNSYNCABLE_PREF); 2264 PrefService::UNSYNCABLE_PREF);
2264 prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement, 2265 prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement,
2265 PrefService::UNSYNCABLE_PREF); 2266 PrefService::UNSYNCABLE_PREF);
2266 prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement, 2267 prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement,
2267 PrefService::UNSYNCABLE_PREF); 2268 PrefService::UNSYNCABLE_PREF);
2268 // We need to register the type of these preferences in order to query 2269 // We need to register the type of these preferences in order to query
2269 // them even though they're only typically controlled via policy. 2270 // them even though they're only typically controlled via policy.
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
3688 } else if (pref_name == prefs::kInstantEnabled) { 3689 } else if (pref_name == prefs::kInstantEnabled) {
3689 if (!InstantController::IsEnabled(profile())) { 3690 if (!InstantController::IsEnabled(profile())) {
3690 if (instant()) { 3691 if (instant()) {
3691 instant()->DestroyPreviewContents(); 3692 instant()->DestroyPreviewContents();
3692 instant_.reset(); 3693 instant_.reset();
3693 instant_unload_handler_.reset(); 3694 instant_unload_handler_.reset();
3694 } 3695 }
3695 } else { 3696 } else {
3696 CreateInstantIfNecessary(); 3697 CreateInstantIfNecessary();
3697 } 3698 }
3698 } else if (pref_name == prefs::kIncognitoEnabled) { 3699 } else if (pref_name == prefs::kIncognitoModeAvailability) {
3700 IncognitoModeAvailabilityPrefs::IncognitoModeAvailability available =
3701 static_cast<
3702 IncognitoModeAvailabilityPrefs::IncognitoModeAvailability>(
3703 profile_->GetPrefs()->GetInteger(
3704 prefs::kIncognitoModeAvailability));
3705 command_updater_.UpdateCommandEnabled(
3706 IDC_NEW_WINDOW,
3707 available != IncognitoModeAvailabilityPrefs::FORCED);
3699 command_updater_.UpdateCommandEnabled( 3708 command_updater_.UpdateCommandEnabled(
3700 IDC_NEW_INCOGNITO_WINDOW, 3709 IDC_NEW_INCOGNITO_WINDOW,
3701 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); 3710 available != IncognitoModeAvailabilityPrefs::DISABLED);
3702 } else if (pref_name == prefs::kDevToolsDisabled) { 3711 } else if (pref_name == prefs::kDevToolsDisabled) {
3703 UpdateCommandsForDevTools(); 3712 UpdateCommandsForDevTools();
3704 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 3713 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
3705 g_browser_process->devtools_manager()->CloseAllClientHosts(); 3714 g_browser_process->devtools_manager()->CloseAllClientHosts();
3706 } else if (pref_name == prefs::kEditBookmarksEnabled) { 3715 } else if (pref_name == prefs::kEditBookmarksEnabled) {
3707 UpdateCommandsForBookmarkEditing(); 3716 UpdateCommandsForBookmarkEditing();
3708 } else if (pref_name == prefs::kAllowFileSelectionDialogs) { 3717 } else if (pref_name == prefs::kAllowFileSelectionDialogs) {
3709 UpdateSaveAsState(GetContentRestrictionsForSelectedTab()); 3718 UpdateSaveAsState(GetContentRestrictionsForSelectedTab());
3710 UpdateOpenFileState(); 3719 UpdateOpenFileState();
3711 } else { 3720 } else {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3826 void Browser::InitCommandState() { 3835 void Browser::InitCommandState() {
3827 // All browser commands whose state isn't set automagically some other way 3836 // All browser commands whose state isn't set automagically some other way
3828 // (like Back & Forward with initial page load) must have their state 3837 // (like Back & Forward with initial page load) must have their state
3829 // initialized here, otherwise they will be forever disabled. 3838 // initialized here, otherwise they will be forever disabled.
3830 3839
3831 // Navigation commands 3840 // Navigation commands
3832 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); 3841 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
3833 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); 3842 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true);
3834 3843
3835 // Window management commands 3844 // Window management commands
3836 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); 3845 IncognitoModeAvailabilityPrefs::IncognitoModeAvailability incognito_avail =
3846 static_cast<IncognitoModeAvailabilityPrefs::IncognitoModeAvailability>(
3847 profile_->GetPrefs()->GetInteger(prefs::kIncognitoModeAvailability));
3848 command_updater_.UpdateCommandEnabled(
3849 IDC_NEW_WINDOW,
3850 incognito_avail != IncognitoModeAvailabilityPrefs::FORCED);
3837 command_updater_.UpdateCommandEnabled( 3851 command_updater_.UpdateCommandEnabled(
3838 IDC_NEW_INCOGNITO_WINDOW, 3852 IDC_NEW_INCOGNITO_WINDOW,
3839 profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); 3853 incognito_avail != IncognitoModeAvailabilityPrefs::DISABLED);
3854
3840 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); 3855 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
3841 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); 3856 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
3842 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); 3857 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
3843 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); 3858 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
3844 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); 3859 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false);
3845 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); 3860 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
3846 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true); 3861 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true);
3847 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true); 3862 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
3848 3863
3849 // Page-related commands 3864 // Page-related commands
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
4803 window_->BookmarkBarStateChanged(animate_type); 4818 window_->BookmarkBarStateChanged(animate_type);
4804 } 4819 }
4805 4820
4806 void Browser::ShowSyncSetup() { 4821 void Browser::ShowSyncSetup() {
4807 ProfileSyncService* service = profile()->GetProfileSyncService(); 4822 ProfileSyncService* service = profile()->GetProfileSyncService();
4808 if (service->HasSyncSetupCompleted()) 4823 if (service->HasSyncSetupCompleted())
4809 ShowOptionsTab(chrome::kSyncSetupSubPage); 4824 ShowOptionsTab(chrome::kSyncSetupSubPage);
4810 else 4825 else
4811 profile()->GetProfileSyncService()->ShowLoginDialog(); 4826 profile()->GetProfileSyncService()->ShowLoginDialog();
4812 } 4827 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698