summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-27 13:26:55 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-27 13:26:55 +0000
commit6e6f6cb268866ca931e7e9ddb839e978c1bfdc1a (patch)
tree68e433ba64393e640414009634b2a28e7e634a95 /chrome
parentebd0b02ef588eb4ceb22408c168c505963e97b3f (diff)
downloadchromium_src-6e6f6cb268866ca931e7e9ddb839e978c1bfdc1a.zip
chromium_src-6e6f6cb268866ca931e7e9ddb839e978c1bfdc1a.tar.gz
chromium_src-6e6f6cb268866ca931e7e9ddb839e978c1bfdc1a.tar.bz2
Implement pref policy for disabling incognito mode.
2nd attempt with shutdown crash fix (only difference is in browser.cc). BUG=66413 TEST=None Review URL: http://codereview.chromium.org/6279012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72791 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/policy/policy_templates.json13
-rw-r--r--chrome/browser/policy/config_dir_policy_provider_unittest.cc7
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.cc3
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store_unittest.cc2
-rw-r--r--chrome/browser/policy/configuration_policy_provider_win_unittest.cc7
-rw-r--r--chrome/browser/policy/configuration_policy_store_interface.h3
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc3
-rw-r--r--chrome/browser/ui/browser.cc19
-rw-r--r--chrome/browser/ui/browser.h3
-rw-r--r--chrome/browser/ui/browser_init.cc7
-rw-r--r--chrome/common/policy_constants.cc3
-rw-r--r--chrome/common/policy_constants.h3
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
14 files changed, 64 insertions, 13 deletions
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json
index 291fb8d..16b0a4a 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 b9e1e8c..aec9bb2 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -221,11 +221,15 @@ Browser::Browser(Type type, Profile* profile)
registrar_.Add(this, NotificationType::EXTENSION_READY_FOR_INSTALL,
NotificationService::AllSources());
+ // NOTE: These prefs all need to be explicitly destroyed in the destructor
+ // or you'll get a nasty surprise when you run the incognito tests.
PrefService* local_state = g_browser_process->local_state();
if (local_state)
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);
@@ -289,6 +293,7 @@ Browser::~Browser() {
encoding_auto_detect_.Destroy();
printing_enabled_.Destroy();
dev_tools_disabled_.Destroy();
+ incognito_mode_allowed_.Destroy();
instant_enabled_.Destroy();
use_vertical_tabs_.Destroy();
@@ -1316,7 +1321,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;
}
@@ -1330,6 +1336,11 @@ void Browser::NewWindow() {
}
void Browser::NewIncognitoWindow() {
+ if (!incognito_mode_allowed_.GetValue()) {
+ NewWindow();
+ return;
+ }
+
UserMetrics::RecordAction(UserMetricsAction("NewIncognitoWindow"), profile_);
Browser::OpenEmptyWindow(profile_->GetOffTheRecordProfile());
}
@@ -1953,7 +1964,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.
}
}
@@ -2049,6 +2060,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
@@ -3452,7 +3464,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 a0fb4b6..2cf9d62 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -365,7 +365,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.
@@ -479,8 +480,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 e7651c7..d2b938a 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -158,6 +158,9 @@ const char kSafeBrowsingEnabled[] = "safebrowsing.enabled";
const char kSafeBrowsingReportingEnabled[] =
"safebrowsing.reporting_enabled";
+// Boolean that is true when Incognito support is enabled.
+const char kIncognitoEnabled[] = "incognito.enabled";
+
// Boolean that is true when Suggest support is enabled.
const char kSearchSuggestEnabled[] = "search.suggest_enabled";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index af91d40..11aaad1 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -62,6 +62,7 @@ extern const char kPasswordManagerAllowShowPasswords[];
extern const char kFormAutofillEnabled[]; // OBSOLETE
extern const char kSafeBrowsingEnabled[];
extern const char kSafeBrowsingReportingEnabled[];
+extern const char kIncognitoEnabled[];
extern const char kSearchSuggestEnabled[];
extern const char kCookieBehavior[]; // OBSOLETE
extern const char kDefaultSearchProviderEnabled[];