diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 10:19:27 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 10:19:27 +0000 |
commit | e95a993bd76e6bcd3417c97fd9c8a02c1d5ba35e (patch) | |
tree | 5d7890959d1eaf5fb1cf6469a882499aff6489a8 | |
parent | a0e0a75aab7812c7683a571cd31e7fb7496dbdb3 (diff) | |
download | chromium_src-e95a993bd76e6bcd3417c97fd9c8a02c1d5ba35e.zip chromium_src-e95a993bd76e6bcd3417c97fd9c8a02c1d5ba35e.tar.gz chromium_src-e95a993bd76e6bcd3417c97fd9c8a02c1d5ba35e.tar.bz2 |
Implement pref policy for disabling incognito mode.
BUG=66413
TEST=None
Review URL: http://codereview.chromium.org/6313008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72624 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/policy/policy_templates.json | 13 | ||||
-rw-r--r-- | chrome/browser/policy/config_dir_policy_provider_unittest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_pref_store.cc | 3 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_pref_store_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_provider_win_unittest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_store_interface.h | 3 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 3 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 16 | ||||
-rw-r--r-- | chrome/browser/ui/browser.h | 3 | ||||
-rw-r--r-- | chrome/browser/ui/browser_init.cc | 7 | ||||
-rw-r--r-- | chrome/common/policy_constants.cc | 3 | ||||
-rw-r--r-- | chrome/common/policy_constants.h | 3 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 3 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 |
14 files changed, 61 insertions, 13 deletions
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json index bc4d628..1ff4634 100644 --- a/chrome/app/policy/policy_templates.json +++ b/chrome/app/policy/policy_templates.json @@ -206,6 +206,19 @@ If this setting is disabled, web pages cannot use JavaScript.''', }, { + 'name': 'IncognitoEnabled', + 'type': 'main', + 'supported_on': ['chrome.*:11-'], + 'features': {'dynamic_refresh': 1}, + 'example_value': False, + 'caption': '''Enable Incognito mode''', + 'desc': '''Enables Incognito mode in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>. + + If this setting is enabled or not configured, users can open web pages in incognito mode. + + If this setting is disabled, users cannot open web pages in incognito mode.''', + }, + { 'name': 'SavingBrowserHistoryDisabled', 'type': 'main', 'supported_on': ['chrome.*:8-'], diff --git a/chrome/browser/policy/config_dir_policy_provider_unittest.cc b/chrome/browser/policy/config_dir_policy_provider_unittest.cc index 67ac917..e41bb0c 100644 --- a/chrome/browser/policy/config_dir_policy_provider_unittest.cc +++ b/chrome/browser/policy/config_dir_policy_provider_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -323,6 +323,9 @@ INSTANTIATE_TEST_CASE_P( key::kPrintingEnabled), ValueTestParams::ForIntegerPolicy( kPolicyPolicyRefreshRate, - key::kPolicyRefreshRate))); + key::kPolicyRefreshRate), + ValueTestParams::ForBooleanPolicy( + kPolicyIncognitoEnabled, + key::kIncognitoEnabled))); } // namespace policy diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc index 2d4ab5f..b2411f2 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.cc +++ b/chrome/browser/policy/configuration_policy_pref_store.cc @@ -189,6 +189,8 @@ const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry prefs::kShowHomeButton }, { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled, prefs::kWebKitJavascriptEnabled }, + { Value::TYPE_BOOLEAN, kPolicyIncognitoEnabled, + prefs::kIncognitoEnabled }, { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, prefs::kSavingBrowserHistoryDisabled }, { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled, @@ -803,6 +805,7 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton }, { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, + { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled }, { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, key::kSavingBrowserHistoryDisabled }, { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN, diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc index 0ad9eb6d..036b338 100644 --- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc +++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc @@ -176,6 +176,8 @@ INSTANTIATE_TEST_CASE_P( prefs::kPrintingEnabled), TypeAndName(kPolicyJavascriptEnabled, prefs::kWebKitJavascriptEnabled), + TypeAndName(kPolicyIncognitoEnabled, + prefs::kIncognitoEnabled), TypeAndName(kPolicySavingBrowserHistoryDisabled, prefs::kSavingBrowserHistoryDisabled), TypeAndName(kPolicySavingBrowserHistoryDisabled, diff --git a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc index 1d2a9ee..aca642c 100644 --- a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc +++ b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -452,6 +452,9 @@ INSTANTIATE_TEST_CASE_P( key::kPrintingEnabled), PolicyTestParams::ForIntegerPolicy( kPolicyPolicyRefreshRate, - key::kPolicyRefreshRate))); + key::kPolicyRefreshRate), + PolicyTestParams::ForBooleanPolicy( + kPolicyIncognitoEnabled, + key::kIncognitoEnabled))); } // namespace policy diff --git a/chrome/browser/policy/configuration_policy_store_interface.h b/chrome/browser/policy/configuration_policy_store_interface.h index e697ed1..169757d 100644 --- a/chrome/browser/policy/configuration_policy_store_interface.h +++ b/chrome/browser/policy/configuration_policy_store_interface.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -50,6 +50,7 @@ enum ConfigurationPolicyType { kPolicyRenderInChromeFrameList, kPolicyRenderInHostList, kPolicyJavascriptEnabled, + kPolicyIncognitoEnabled, kPolicySavingBrowserHistoryDisabled, kPolicyDeveloperToolsDisabled, kPolicyBlockThirdPartyCookies, diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 3a343c5..508d8fe 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -943,7 +943,8 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { return !!(params_.edit_flags & WebContextMenuData::CanSelectAll); case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: - return !profile_->IsOffTheRecord() && params_.link_url.is_valid(); + return !profile_->IsOffTheRecord() && params_.link_url.is_valid() && + profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled); case IDC_SPELLCHECK_ADD_TO_DICTIONARY: return !params_.misspelled_word.empty(); diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index c95aa7d..03ee5e1 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -223,6 +223,8 @@ Browser::Browser(Type type, Profile* profile) printing_enabled_.Init(prefs::kPrintingEnabled, local_state, this); dev_tools_disabled_.Init(prefs::kDevToolsDisabled, profile_->GetPrefs(), this); + incognito_mode_allowed_.Init(prefs::kIncognitoEnabled, + profile_->GetPrefs(), this); InitCommandState(); BrowserList::AddBrowser(this); @@ -1305,7 +1307,8 @@ void Browser::Stop() { void Browser::NewWindow() { if (browser_defaults::kAlwaysOpenIncognitoWindow && - CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito)) { + CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) && + incognito_mode_allowed_.GetValue()) { NewIncognitoWindow(); return; } @@ -1319,6 +1322,11 @@ void Browser::NewWindow() { } void Browser::NewIncognitoWindow() { + if (!incognito_mode_allowed_.GetValue()) { + NewWindow(); + return; + } + UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow"), profile_); Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile()); } @@ -1942,7 +1950,7 @@ void Browser::OpenLanguageOptionsDialog() { switches::kDisableTabbedOptions)) { ShowOptionsTab(chrome::kLanguageOptionsSubPage); } else { - // Language options dialog has been replaced by DOMUI. + // Language options dialog has been replaced by DOMUI. } } @@ -2038,6 +2046,7 @@ void Browser::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kRemotingHasSetupCompleted, false); prefs->RegisterStringPref(prefs::kCloudPrintEmail, std::string()); prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); + prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, true); prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); // We need to register the type of this preference in order to query @@ -3441,7 +3450,8 @@ void Browser::InitCommandState() { // Window management commands command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); - command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); + command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, + incognito_mode_allowed_.GetValue()); command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true); command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true); diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index d59030e..0ab7df6 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -1112,6 +1112,9 @@ class Browser : public TabHandlerDelegate, // Keep track of when instant enabled changes. BooleanPrefMember instant_enabled_; + // Tracks the preference that controls whether incognito mode is allowed. + BooleanPrefMember incognito_mode_allowed_; + // Indicates if command execution is blocked. bool block_command_execution_; diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index 6d93a53..d99c3df 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -370,7 +370,8 @@ SessionStartupPref GetSessionStartupPref(const CommandLine& command_line, if (command_line.HasSwitch(switches::kRestoreLastSession)) pref.type = SessionStartupPref::LAST; if (command_line.HasSwitch(switches::kIncognito) && - pref.type == SessionStartupPref::LAST) { + pref.type == SessionStartupPref::LAST && + profile->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { // We don't store session information when incognito. If the user has // chosen to restore last session and launched incognito, fallback to // default launch behavior. @@ -484,8 +485,10 @@ bool BrowserInit::LaunchBrowser(const CommandLine& command_line, #endif // Continue with the off-the-record profile from here on if --incognito - if (command_line.HasSwitch(switches::kIncognito)) + if (command_line.HasSwitch(switches::kIncognito) && + profile->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { profile = profile->GetOffTheRecordProfile(); + } BrowserInit::LaunchWithProfile lwp(cur_dir, command_line, this); bool launched = lwp.Launch(profile, process_startup); diff --git a/chrome/common/policy_constants.cc b/chrome/common/policy_constants.cc index f02264c..3e2e7bf 100644 --- a/chrome/common/policy_constants.cc +++ b/chrome/common/policy_constants.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -58,6 +58,7 @@ const char kExtensionInstallForceList[] = "ExtensionInstallForcelist"; const char kShowHomeButton[] = "ShowHomeButton"; const char kPrintingEnabled[] = "PrintingEnabled"; const char kJavascriptEnabled[] = "JavascriptEnabled"; +const char kIncognitoEnabled[] = "IncognitoEnabled"; const char kSavingBrowserHistoryDisabled[] = "SavingBrowserHistoryDisabled"; const char kDeveloperToolsDisabled[] = "DeveloperToolsDisabled"; const char kBlockThirdPartyCookies[] = "BlockThirdPartyCookies"; diff --git a/chrome/common/policy_constants.h b/chrome/common/policy_constants.h index 22a41ba..ae9de9b 100644 --- a/chrome/common/policy_constants.h +++ b/chrome/common/policy_constants.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -53,6 +53,7 @@ extern const char kExtensionInstallForceList[]; extern const char kShowHomeButton[]; extern const char kPrintingEnabled[]; extern const char kJavascriptEnabled[]; +extern const char kIncognitoEnabled[]; extern const char kSavingBrowserHistoryDisabled[]; extern const char kDeveloperToolsDisabled[]; extern const char kBlockThirdPartyCookies[]; diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index d52d503..db8a59a 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -134,6 +134,9 @@ const char kFormAutofillEnabled[] = "profile.form_autofill_enabled"; // Boolean that is true when SafeBrowsing is enabled. const char kSafeBrowsingEnabled[] = "safebrowsing.enabled"; +// Boolean that is true when Incognito support is enabled. +const char kIncognitoEnabled[] = "incognito.enabled"; + // Boolean that is true when SafeBrowsing Malware Report is enabled. const char kSafeBrowsingReportingEnabled[] = "safebrowsing.reporting_enabled"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 327a49a..e01cd4f 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -62,6 +62,7 @@ extern const char kPasswordManagerEnabled[]; extern const char kPasswordManagerAllowShowPasswords[]; extern const char kFormAutofillEnabled[]; // OBSOLETE extern const char kSafeBrowsingEnabled[]; +extern const char kIncognitoEnabled[]; extern const char kSafeBrowsingReportingEnabled[]; extern const char kSearchSuggestEnabled[]; extern const char kCookieBehavior[]; // OBSOLETE |