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

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

Issue 6279012: Implement pref policy for disabling incognito mode.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_init.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <shellapi.h> 8 #include <shellapi.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 NotificationService::AllSources()); 214 NotificationService::AllSources());
215 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, 215 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
216 NotificationService::AllSources()); 216 NotificationService::AllSources());
217 registrar_.Add(this, NotificationType::PROFILE_ERROR, 217 registrar_.Add(this, NotificationType::PROFILE_ERROR,
218 NotificationService::AllSources()); 218 NotificationService::AllSources());
219 219
220 // Need to know when to alert the user of theme install delay. 220 // Need to know when to alert the user of theme install delay.
221 registrar_.Add(this, NotificationType::EXTENSION_READY_FOR_INSTALL, 221 registrar_.Add(this, NotificationType::EXTENSION_READY_FOR_INSTALL,
222 NotificationService::AllSources()); 222 NotificationService::AllSources());
223 223
224 // NOTE: These prefs all need to be explicitly destroyed in the destructor
225 // or you'll get a nasty surprise when you run the incognito tests.
224 PrefService* local_state = g_browser_process->local_state(); 226 PrefService* local_state = g_browser_process->local_state();
225 if (local_state) 227 if (local_state)
226 printing_enabled_.Init(prefs::kPrintingEnabled, local_state, this); 228 printing_enabled_.Init(prefs::kPrintingEnabled, local_state, this);
227 dev_tools_disabled_.Init(prefs::kDevToolsDisabled, 229 dev_tools_disabled_.Init(prefs::kDevToolsDisabled,
228 profile_->GetPrefs(), this); 230 profile_->GetPrefs(), this);
231 incognito_mode_allowed_.Init(prefs::kIncognitoEnabled,
232 profile_->GetPrefs(), this);
229 233
230 InitCommandState(); 234 InitCommandState();
231 BrowserList::AddBrowser(this); 235 BrowserList::AddBrowser(this);
232 236
233 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, 237 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
234 profile_->GetPrefs(), NULL); 238 profile_->GetPrefs(), NULL);
235 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); 239 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this);
236 instant_enabled_.Init(prefs::kInstantEnabled, profile_->GetPrefs(), this); 240 instant_enabled_.Init(prefs::kInstantEnabled, profile_->GetPrefs(), this);
237 if (!TabMenuModel::AreVerticalTabsEnabled()) { 241 if (!TabMenuModel::AreVerticalTabsEnabled()) {
238 // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we 242 // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 if (session_service) 286 if (session_service)
283 session_service->WindowClosed(session_id_); 287 session_service->WindowClosed(session_id_);
284 288
285 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); 289 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService();
286 if (tab_restore_service) 290 if (tab_restore_service)
287 tab_restore_service->BrowserClosed(this); 291 tab_restore_service->BrowserClosed(this);
288 292
289 encoding_auto_detect_.Destroy(); 293 encoding_auto_detect_.Destroy();
290 printing_enabled_.Destroy(); 294 printing_enabled_.Destroy();
291 dev_tools_disabled_.Destroy(); 295 dev_tools_disabled_.Destroy();
296 incognito_mode_allowed_.Destroy();
292 instant_enabled_.Destroy(); 297 instant_enabled_.Destroy();
293 use_vertical_tabs_.Destroy(); 298 use_vertical_tabs_.Destroy();
294 299
295 if (profile_->IsOffTheRecord() && 300 if (profile_->IsOffTheRecord() &&
296 !BrowserList::IsOffTheRecordSessionActive()) { 301 !BrowserList::IsOffTheRecordSessionActive()) {
297 // An off-the-record profile is no longer needed, this indirectly 302 // An off-the-record profile is no longer needed, this indirectly
298 // frees its cache and cookies. 303 // frees its cache and cookies.
299 profile_->GetOriginalProfile()->DestroyOffTheRecordProfile(); 304 profile_->GetOriginalProfile()->DestroyOffTheRecordProfile();
300 } 305 }
301 306
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 browser::Navigate(&params); 1306 browser::Navigate(&params);
1302 } 1307 }
1303 1308
1304 void Browser::Stop() { 1309 void Browser::Stop() {
1305 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_); 1310 UserMetrics::RecordAction(UserMetricsAction("Stop"), profile_);
1306 GetSelectedTabContentsWrapper()->tab_contents()->Stop(); 1311 GetSelectedTabContentsWrapper()->tab_contents()->Stop();
1307 } 1312 }
1308 1313
1309 void Browser::NewWindow() { 1314 void Browser::NewWindow() {
1310 if (browser_defaults::kAlwaysOpenIncognitoWindow && 1315 if (browser_defaults::kAlwaysOpenIncognitoWindow &&
1311 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito)) { 1316 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) &&
1317 incognito_mode_allowed_.GetValue()) {
1312 NewIncognitoWindow(); 1318 NewIncognitoWindow();
1313 return; 1319 return;
1314 } 1320 }
1315 UserMetrics::RecordAction(UserMetricsAction("NewWindow"), profile_); 1321 UserMetrics::RecordAction(UserMetricsAction("NewWindow"), profile_);
1316 SessionService* session_service = 1322 SessionService* session_service =
1317 profile_->GetOriginalProfile()->GetSessionService(); 1323 profile_->GetOriginalProfile()->GetSessionService();
1318 if (!session_service || 1324 if (!session_service ||
1319 !session_service->RestoreIfNecessary(std::vector<GURL>())) { 1325 !session_service->RestoreIfNecessary(std::vector<GURL>())) {
1320 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); 1326 Browser::OpenEmptyWindow(profile_->GetOriginalProfile());
1321 } 1327 }
1322 } 1328 }
1323 1329
1324 void Browser::NewIncognitoWindow() { 1330 void Browser::NewIncognitoWindow() {
1331 if (!incognito_mode_allowed_.GetValue()) {
1332 NewWindow();
1333 return;
1334 }
1335
1325 UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow"), profile_); 1336 UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow"), profile_);
1326 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); 1337 Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile());
1327 } 1338 }
1328 1339
1329 void Browser::CloseWindow() { 1340 void Browser::CloseWindow() {
1330 UserMetrics::RecordAction(UserMetricsAction("CloseWindow"), profile_); 1341 UserMetrics::RecordAction(UserMetricsAction("CloseWindow"), profile_);
1331 window_->Close(); 1342 window_->Close();
1332 } 1343 }
1333 1344
1334 void Browser::NewTab() { 1345 void Browser::NewTab() {
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 } 1949 }
1939 } 1950 }
1940 1951
1941 void Browser::OpenLanguageOptionsDialog() { 1952 void Browser::OpenLanguageOptionsDialog() {
1942 UserMetrics::RecordAction(UserMetricsAction("OpenLanguageOptionsDialog"), 1953 UserMetrics::RecordAction(UserMetricsAction("OpenLanguageOptionsDialog"),
1943 profile_); 1954 profile_);
1944 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1955 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1945 switches::kDisableTabbedOptions)) { 1956 switches::kDisableTabbedOptions)) {
1946 ShowOptionsTab(chrome::kLanguageOptionsSubPage); 1957 ShowOptionsTab(chrome::kLanguageOptionsSubPage);
1947 } else { 1958 } else {
1948 // Language options dialog has been replaced by DOMUI. 1959 // Language options dialog has been replaced by DOMUI.
1949 } 1960 }
1950 } 1961 }
1951 1962
1952 void Browser::OpenSystemTabAndActivate() { 1963 void Browser::OpenSystemTabAndActivate() {
1953 OpenURL(GURL(chrome::kChromeUISystemInfoURL), GURL(), 1964 OpenURL(GURL(chrome::kChromeUISystemInfoURL), GURL(),
1954 NEW_FOREGROUND_TAB, PageTransition::LINK); 1965 NEW_FOREGROUND_TAB, PageTransition::LINK);
1955 window_->Activate(); 1966 window_->Activate();
1956 } 1967 }
1957 1968
1958 void Browser::OpenMobilePlanTabAndActivate() { 1969 void Browser::OpenMobilePlanTabAndActivate() {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, true); 2045 prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, true);
2035 prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, true); 2046 prefs->RegisterBooleanPref(prefs::kShowOmniboxSearchHint, true);
2036 prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, true); 2047 prefs->RegisterBooleanPref(prefs::kWebAppCreateOnDesktop, true);
2037 prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true); 2048 prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true);
2038 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true); 2049 prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true);
2039 prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, false); 2050 prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, false);
2040 prefs->RegisterBooleanPref(prefs::kEnableTranslate, true); 2051 prefs->RegisterBooleanPref(prefs::kEnableTranslate, true);
2041 prefs->RegisterBooleanPref(prefs::kRemotingHasSetupCompleted, false); 2052 prefs->RegisterBooleanPref(prefs::kRemotingHasSetupCompleted, false);
2042 prefs->RegisterStringPref(prefs::kCloudPrintEmail, std::string()); 2053 prefs->RegisterStringPref(prefs::kCloudPrintEmail, std::string());
2043 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); 2054 prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false);
2055 prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, true);
2044 prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); 2056 prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0);
2045 prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); 2057 prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0);
2046 // We need to register the type of this preference in order to query 2058 // We need to register the type of this preference in order to query
2047 // it even though it's only typically controlled via policy. 2059 // it even though it's only typically controlled via policy.
2048 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, false); 2060 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, false);
2049 } 2061 }
2050 2062
2051 // static 2063 // static
2052 bool Browser::RunUnloadEventsHelper(TabContents* contents) { 2064 bool Browser::RunUnloadEventsHelper(TabContents* contents) {
2053 // If the TabContents is not connected yet, then there's no unload 2065 // If the TabContents is not connected yet, then there's no unload
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
3437 // All browser commands whose state isn't set automagically some other way 3449 // All browser commands whose state isn't set automagically some other way
3438 // (like Back & Forward with initial page load) must have their state 3450 // (like Back & Forward with initial page load) must have their state
3439 // initialized here, otherwise they will be forever disabled. 3451 // initialized here, otherwise they will be forever disabled.
3440 3452
3441 // Navigation commands 3453 // Navigation commands
3442 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); 3454 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
3443 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); 3455 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true);
3444 3456
3445 // Window management commands 3457 // Window management commands
3446 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); 3458 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true);
3447 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); 3459 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW,
3460 incognito_mode_allowed_.GetValue());
3448 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); 3461 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
3449 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); 3462 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
3450 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); 3463 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
3451 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true); 3464 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
3452 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false); 3465 command_updater_.UpdateCommandEnabled(IDC_RESTORE_TAB, false);
3453 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); 3466 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
3454 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true); 3467 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_VERTICAL_TABS, true);
3455 3468
3456 // Page-related commands 3469 // Page-related commands
3457 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); 3470 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
4278 // The page transition below is only for the purpose of inserting the tab. 4291 // The page transition below is only for the purpose of inserting the tab.
4279 browser->AddTab(view_source_contents, PageTransition::LINK); 4292 browser->AddTab(view_source_contents, PageTransition::LINK);
4280 } 4293 }
4281 4294
4282 if (profile_->HasSessionService()) { 4295 if (profile_->HasSessionService()) {
4283 SessionService* session_service = profile_->GetSessionService(); 4296 SessionService* session_service = profile_->GetSessionService();
4284 if (session_service) 4297 if (session_service)
4285 session_service->TabRestored(&view_source_contents->controller(), false); 4298 session_service->TabRestored(&view_source_contents->controller(), false);
4286 } 4299 }
4287 } 4300 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | chrome/browser/ui/browser_init.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698