diff options
author | rustema@google.com <rustema@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-05 05:28:27 +0000 |
---|---|---|
committer | rustema@google.com <rustema@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-05 05:28:27 +0000 |
commit | 4e94ab3d72e4fd1cf76be4014721985dde1b724b (patch) | |
tree | c13ad27f4de1f44ee054929ead4960ca90039b90 | |
parent | 85acecb3f21d0905acae3fbbb27f904f15a6b878 (diff) | |
download | chromium_src-4e94ab3d72e4fd1cf76be4014721985dde1b724b.zip chromium_src-4e94ab3d72e4fd1cf76be4014721985dde1b724b.tar.gz chromium_src-4e94ab3d72e4fd1cf76be4014721985dde1b724b.tar.bz2 |
Converted IncognitoForced boolean policy into IncognitoModeAvailability enum policy.
Enum may take 3 values:
* ENABLED (default) - both normal and incognito modes are allowed.
* DISABLED - incognito mode cannot be used.
* FORCED - browsing is only possible in incognito mode.
Mapped IncognitoEnabled::false to IncognitoModeAvailability::DISABLED when IncognitoModeAvailability policy/pref is not set.
Removed IncognitoEnabled pref (no longer used).
BUG=69580
TEST=
Review URL: http://codereview.chromium.org/7520023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95580 0039d316-1c4b-4281-b951-d872f2087c98
26 files changed, 491 insertions, 68 deletions
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json index 59d9950..3399184 100644 --- a/chrome/app/policy/policy_templates.json +++ b/chrome/app/policy/policy_templates.json @@ -271,28 +271,49 @@ 'type': 'main', 'supported_on': ['chrome.*:11-', 'chrome_os:0.11-'], 'features': {'dynamic_refresh': 1}, + 'deprecated': True, 'example_value': False, 'id': 10, 'caption': '''Enable Incognito mode''', - 'desc': '''Enables Incognito mode in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>. + 'desc': '''This policy is deprecated. Please, use IncognitoModeAvailability instead. + 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': 'IncognitoForced', - 'type': 'main', + 'name': 'IncognitoModeAvailability', + 'type': 'int-enum', + 'items': [ + { + 'name': 'Enabled', + 'value': 0, + 'caption': '''Incognito mode available.''' + }, + { + 'name': 'Disabled', + 'value': 1, + 'caption': '''Incognito mode disabled.''' + }, + { + 'name': 'Forced', + 'value': 2, + 'caption': '''Incognito mode forced.''' + }, + ], 'supported_on': ['chrome.*:14-', 'chrome_os:0.14-'], 'features': {'dynamic_refresh': 1}, - 'example_value': False, + 'example_value': 1, 'id': 93, - 'caption': '''Force Incognito mode''', - 'desc': '''Forces every session into Incognito mode in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>. + 'caption': '''Incognito mode availability.''', + 'desc': '''Specifies whether the user may open pages in Incognito mode in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>. + + If 'Enabled' is selected, pages may be opened in Incognito mode. - If this setting is enabled, users can open pages only in incognito mode. + If 'Disabled' is selected, pages may not be opened in Incognito mode. - If this setting is disabled or not configured, users can use the browser in normal mode as well.''', + If 'Forced' is selected, pages may be opened ONLY in Incognito mode.''', }, { 'name': 'SavingBrowserHistoryDisabled', diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc index 644f513..62fa9ec 100644 --- a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc +++ b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc @@ -10,6 +10,7 @@ #include "chrome/browser/bookmarks/bookmark_folder_editor_controller.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_utils.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -243,18 +244,23 @@ bool BookmarkContextMenuController::IsCommandIdEnabled(int command_id) const { selection_[0]->parent() == model_->root_node()); bool can_edit = profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled); + IncognitoModePrefs::Availability incognito_avail = + IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); switch (command_id) { case IDC_BOOKMARK_BAR_OPEN_INCOGNITO: return !profile_->IsOffTheRecord() && - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled); + incognito_avail != IncognitoModePrefs::DISABLED; case IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO: - return HasURLs() && !profile_->IsOffTheRecord() && - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled); + return HasURLs() && + !profile_->IsOffTheRecord() && + incognito_avail != IncognitoModePrefs::DISABLED; case IDC_BOOKMARK_BAR_OPEN_ALL: - case IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW: return HasURLs(); + case IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW: + return HasURLs() && + incognito_avail != IncognitoModePrefs::FORCED; case IDC_BOOKMARK_BAR_RENAME_FOLDER: case IDC_BOOKMARK_BAR_EDIT: diff --git a/chrome/browser/extensions/extension_tabs_apitest.cc b/chrome/browser/extensions/extension_tabs_apitest.cc index 5e420af..5019c54 100644 --- a/chrome/browser/extensions/extension_tabs_apitest.cc +++ b/chrome/browser/extensions/extension_tabs_apitest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -200,7 +201,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FocusWindowDoesNotUnmaximize) { IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabledByPref) { ASSERT_TRUE(StartTestServer()); - browser()->profile()->GetPrefs()->SetBoolean(prefs::kIncognitoEnabled, false); + IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), + IncognitoModePrefs::DISABLED); // This makes sure that creating an incognito window fails due to pref // (policy) being set. diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index b0472e1..a949b4d 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -19,6 +19,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tabs_module_constants.h" #include "chrome/browser/net/url_fixer_upper.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/restore_tab_helper.h" #include "chrome/browser/tabs/tab_strip_model.h" @@ -527,7 +528,8 @@ bool CreateWindowFunction::RunImpl() { if (args->HasKey(keys::kIncognitoKey)) { EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kIncognitoKey, &incognito)); - if (!profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { + if (IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) == + IncognitoModePrefs::DISABLED) { error_ = keys::kIncognitoModeIsDisabled; return false; } diff --git a/chrome/browser/policy/config_dir_policy_provider_unittest.cc b/chrome/browser/policy/config_dir_policy_provider_unittest.cc index 12ff884..924d874 100644 --- a/chrome/browser/policy/config_dir_policy_provider_unittest.cc +++ b/chrome/browser/policy/config_dir_policy_provider_unittest.cc @@ -336,9 +336,9 @@ INSTANTIATE_TEST_CASE_P( ValueTestParams::ForBooleanPolicy( kPolicyInstantEnabled, key::kInstantEnabled), - ValueTestParams::ForBooleanPolicy( - kPolicyIncognitoEnabled, - key::kIncognitoEnabled), + ValueTestParams::ForIntegerPolicy( + kPolicyIncognitoModeAvailability, + key::kIncognitoModeAvailability), ValueTestParams::ForBooleanPolicy( kPolicyDisablePluginFinder, key::kDisablePluginFinder), diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc index 3f74a01..99a15ae 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.cc +++ b/chrome/browser/policy/configuration_policy_pref_store.cc @@ -21,6 +21,7 @@ #include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/policy/configuration_policy_provider.h" #include "chrome/browser/policy/policy_path_parser.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_value_map.h" #include "chrome/browser/prefs/proxy_config_dictionary.h" #include "chrome/browser/search_engines/search_terms_data.h" @@ -106,6 +107,11 @@ class ConfigurationPolicyPrefKeeper // ApplyDefaultSearchPolicy takes ownership of |value|. bool ApplyDefaultSearchPolicy(ConfigurationPolicyType policy, Value* value); + // Processes incognito mode availability related policies. Returns true if the + // specified policy is pertinent to incognito mode availability. In that case, + // the function takes ownership of |value|. + bool ApplyIncognitoModePolicy(ConfigurationPolicyType policy, Value* value); + // Make sure that the |path| if present in |prefs_|. If not, set it to // a blank string. void EnsureStringPrefExists(const std::string& path); @@ -121,6 +127,11 @@ class ConfigurationPolicyPrefKeeper // respective values in |prefs_|. void FinalizeProxyPolicySettings(); + // If the required entries for the Incognito mode availability settings + // are specified and valid, finalizes the policy-specified configuration + // by initializing the respective values in |prefs_|. + void FinalizeIncognitoModeSettings(); + // Returns true if the policy values stored in proxy_* represent a valid proxy // configuration, including the case in which there is no configuration at // all. @@ -136,6 +147,11 @@ class ConfigurationPolicyPrefKeeper // is called. std::map<ConfigurationPolicyType, Value*> proxy_policies_; + // Saved state of the deprecated kPolicyIncognitoEnabled. It is still used for + // backward compatibility to set the new kIncognitoAvailabilityMode pref in + // case the corresponding policy for the latter is not specified. + scoped_ptr<Value> deprecated_incognito_enabled_; + PrefValueMap prefs_; static const PolicyToPreferenceMapEntry kSimplePolicyMap[]; @@ -191,10 +207,6 @@ const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry prefs::kShowHomeButton }, { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled, prefs::kWebKitJavascriptEnabled }, - { Value::TYPE_BOOLEAN, kPolicyIncognitoEnabled, - prefs::kIncognitoEnabled }, - { Value::TYPE_BOOLEAN, kPolicyIncognitoForced, - prefs::kIncognitoForced }, { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, prefs::kSavingBrowserHistoryDisabled }, { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit, @@ -317,6 +329,7 @@ ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper( LOG(WARNING) << "Failed to get policy from provider."; FinalizeProxyPolicySettings(); FinalizeDefaultSearchPolicySettings(); + FinalizeIncognitoModeSettings(); } ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() { @@ -369,6 +382,9 @@ void ConfigurationPolicyPrefKeeper::Apply(ConfigurationPolicyType policy, if (ApplyDefaultSearchPolicy(policy, value)) return; + if (ApplyIncognitoModePolicy(policy, value)) + return; + if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap, arraysize(kSimplePolicyMap))) return; @@ -556,6 +572,37 @@ bool ConfigurationPolicyPrefKeeper::ApplyDefaultSearchPolicy( return false; } +bool ConfigurationPolicyPrefKeeper::ApplyIncognitoModePolicy( + ConfigurationPolicyType policy, + Value* value) { + if (policy == kPolicyIncognitoModeAvailability) { + int availability = IncognitoModePrefs::ENABLED; + bool result = value->GetAsInteger(&availability); + delete value; + if (result) { + IncognitoModePrefs::Availability availability_enum_value; + if (IncognitoModePrefs::IntToAvailability(availability, + &availability_enum_value)) { + prefs_.SetValue(prefs::kIncognitoModeAvailability, + Value::CreateIntegerValue(availability_enum_value)); + } else { + LOG(WARNING) << "IncognitoModeAvailability policy value is " + << "out of range " << availability; + } + } else { + LOG(WARNING) << "IncognitoModeAvailability policy value could not be " + << "parsed"; + } + return true; + } + if (policy == kPolicyIncognitoEnabled) { + deprecated_incognito_enabled_.reset(value); + return true; + } + // The policy is not relevant to incognito. + return false; +} + void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( const std::string& path) { std::string value; @@ -637,6 +684,25 @@ void ConfigurationPolicyPrefKeeper::FinalizeDefaultSearchPolicySettings() { arraysize(kDefaultSearchPolicyMap)); } +void ConfigurationPolicyPrefKeeper::FinalizeIncognitoModeSettings() { + int int_value; + if (!prefs_.GetInteger(prefs::kIncognitoModeAvailability, &int_value)) { + // If kPolicyIncognitoModeAvailability is not specified, check the obsolete + // kPolicyIncognitoEnabled. + if (deprecated_incognito_enabled_.get()) { + bool enabled = true; + if (deprecated_incognito_enabled_->GetAsBoolean(&enabled)) { + prefs_.SetInteger( + prefs::kIncognitoModeAvailability, + enabled ? IncognitoModePrefs::ENABLED : + IncognitoModePrefs::DISABLED); + } else { + LOG(WARNING) << "IncognitoEnabled policy value could not be parsed"; + } + } + } +} + void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { if (CheckProxySettings()) ApplyProxySettings(); @@ -999,7 +1065,8 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, { kPolicyIncognitoEnabled, Value::TYPE_BOOLEAN, key::kIncognitoEnabled }, - { kPolicyIncognitoForced, Value::TYPE_BOOLEAN, key::kIncognitoForced }, + { kPolicyIncognitoModeAvailability, Value::TYPE_INTEGER, + key::kIncognitoModeAvailability }, { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, key::kSavingBrowserHistoryDisabled }, { kPolicyClearSiteDataOnExit, 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 5f56df1..4474e69 100644 --- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc +++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc @@ -6,6 +6,7 @@ #include "base/memory/ref_counted.h" #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/policy/mock_configuration_policy_provider.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/proxy_config_dictionary.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_store_observer_mock.h" @@ -200,10 +201,6 @@ INSTANTIATE_TEST_CASE_P( prefs::kPrintingEnabled), TypeAndName(kPolicyJavascriptEnabled, prefs::kWebKitJavascriptEnabled), - TypeAndName(kPolicyIncognitoEnabled, - prefs::kIncognitoEnabled), - TypeAndName(kPolicyIncognitoForced, - prefs::kIncognitoForced), TypeAndName(kPolicyRemoteAccessClientFirewallTraversal, prefs::kRemoteAccessClientFirewallTraversal), TypeAndName(kPolicyRemoteAccessHostFirewallTraversal, @@ -697,6 +694,98 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) { store->GetValue(prefs::kDefaultSearchProviderEncodings, NULL)); } +// Tests Incognito mode availability preference setting. +class ConfigurationPolicyPrefStoreIncognitoModeTest : public testing::Test { + protected: + static const int kIncognitoModeAvailabilityNotSet = -1; + + enum ObsoleteIncognitoEnabledValue { + INCOGNITO_ENABLED_UNKNOWN, + INCOGNITO_ENABLED_TRUE, + INCOGNITO_ENABLED_FALSE + }; + + void SetPolicies(ObsoleteIncognitoEnabledValue incognito_enabled, + int availability) { + if (incognito_enabled != INCOGNITO_ENABLED_UNKNOWN) { + provider_.AddPolicy(kPolicyIncognitoEnabled, + Value::CreateBooleanValue( + incognito_enabled == INCOGNITO_ENABLED_TRUE)); + } + if (availability >= 0) { + provider_.AddPolicy(kPolicyIncognitoModeAvailability, + Value::CreateIntegerValue(availability)); + } + store_ = new ConfigurationPolicyPrefStore(&provider_); + } + + void VerifyValues(IncognitoModePrefs::Availability availability) { + const Value* value = NULL; + EXPECT_EQ(PrefStore::READ_OK, + store_->GetValue(prefs::kIncognitoModeAvailability, &value)); + EXPECT_TRUE(FundamentalValue(availability).Equals(value)); + } + + MockConfigurationPolicyProvider provider_; + scoped_refptr<ConfigurationPolicyPrefStore> store_; +}; + +// The following testcases verify that if the obsolete IncognitoEnabled +// policy is not set, the IncognitoModeAvailability values should be copied +// from IncognitoModeAvailability policy to pref "as is". +TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, + NoObsoletePolicyAndIncognitoEnabled) { + SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::ENABLED); + VerifyValues(IncognitoModePrefs::ENABLED); +} + +TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, + NoObsoletePolicyAndIncognitoDisabled) { + SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::DISABLED); + VerifyValues(IncognitoModePrefs::DISABLED); +} + +TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, + NoObsoletePolicyAndIncognitoForced) { + SetPolicies(INCOGNITO_ENABLED_UNKNOWN, IncognitoModePrefs::FORCED); + VerifyValues(IncognitoModePrefs::FORCED); +} + +TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, + NoObsoletePolicyAndNoIncognitoAvailability) { + SetPolicies(INCOGNITO_ENABLED_UNKNOWN, kIncognitoModeAvailabilityNotSet); + const Value* value = NULL; + EXPECT_EQ(PrefStore::READ_NO_VALUE, + store_->GetValue(prefs::kIncognitoModeAvailability, &value)); +} + +// Checks that if the obsolete IncognitoEnabled policy is set, if sets +// the IncognitoModeAvailability preference only in case +// the IncognitoModeAvailability policy is not specified. +TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, + ObsoletePolicyDoesNotAffectAvailabilityEnabled) { + SetPolicies(INCOGNITO_ENABLED_FALSE, IncognitoModePrefs::ENABLED); + VerifyValues(IncognitoModePrefs::ENABLED); +} + +TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, + ObsoletePolicyDoesNotAffectAvailabilityForced) { + SetPolicies(INCOGNITO_ENABLED_TRUE, IncognitoModePrefs::FORCED); + VerifyValues(IncognitoModePrefs::FORCED); +} + +TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, + ObsoletePolicySetsPreferenceToEnabled) { + SetPolicies(INCOGNITO_ENABLED_TRUE, kIncognitoModeAvailabilityNotSet); + VerifyValues(IncognitoModePrefs::ENABLED); +} + +TEST_F(ConfigurationPolicyPrefStoreIncognitoModeTest, + ObsoletePolicySetsPreferenceToDisabled) { + SetPolicies(INCOGNITO_ENABLED_FALSE, kIncognitoModeAvailabilityNotSet); + VerifyValues(IncognitoModePrefs::DISABLED); +} + // Test cases for the Sync policy setting. class ConfigurationPolicyPrefStoreSyncTest : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { diff --git a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc index af2fd2b..433891a 100644 --- a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc +++ b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc @@ -462,9 +462,9 @@ INSTANTIATE_TEST_CASE_P( PolicyTestParams::ForBooleanPolicy( kPolicyInstantEnabled, key::kInstantEnabled), - PolicyTestParams::ForBooleanPolicy( - kPolicyIncognitoEnabled, - key::kIncognitoEnabled), + PolicyTestParams::ForIntegerPolicy( + kPolicyIncognitoModeAvailability, + key::kIncognitoModeAvailability), PolicyTestParams::ForBooleanPolicy( kPolicyDisablePluginFinder, key::kDisablePluginFinder), diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 952317d..9b0db6e 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -38,6 +38,7 @@ #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/plugin_updater.h" #include "chrome/browser/policy/cloud_policy_subsystem.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/profiles/profile_impl.h" @@ -155,6 +156,7 @@ void RegisterUserPrefs(PrefService* user_prefs) { TemplateURLPrepopulateData::RegisterUserPrefs(user_prefs); ExtensionWebUI::RegisterUserPrefs(user_prefs); ExtensionsUI::RegisterUserPrefs(user_prefs); + IncognitoModePrefs::RegisterUserPrefs(user_prefs); NewTabUI::RegisterUserPrefs(user_prefs); PluginsUI::RegisterUserPrefs(user_prefs); PluginUpdater::RegisterPrefs(user_prefs); diff --git a/chrome/browser/prefs/command_line_pref_store.cc b/chrome/browser/prefs/command_line_pref_store.cc index a0e94dc..021be74 100644 --- a/chrome/browser/prefs/command_line_pref_store.cc +++ b/chrome/browser/prefs/command_line_pref_store.cc @@ -42,7 +42,6 @@ const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry prefs::kWebKitAllowDisplayingInsecureContent, false }, { switches::kAllowCrossOriginAuthPrompt, prefs::kAllowCrossOriginAuthPrompt, true }, - { switches::kIncognito, prefs::kIncognitoForced, true }, }; CommandLinePrefStore::CommandLinePrefStore(const CommandLine* command_line) diff --git a/chrome/browser/prefs/incognito_mode_prefs.cc b/chrome/browser/prefs/incognito_mode_prefs.cc new file mode 100644 index 0000000..067edc2 --- /dev/null +++ b/chrome/browser/prefs/incognito_mode_prefs.cc @@ -0,0 +1,45 @@ +// 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. + +#include "chrome/browser/prefs/incognito_mode_prefs.h" + +#include "base/logging.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/common/pref_names.h" + +// static +bool IncognitoModePrefs::IntToAvailability(int in_value, + Availability* out_value) { + if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) { + *out_value = ENABLED; + return false; + } + *out_value = static_cast<Availability>(in_value); + return true; +} + +// static +IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability( + const PrefService* pref_service) { + DCHECK(pref_service); + int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability); + Availability result = IncognitoModePrefs::ENABLED; + bool valid = IntToAvailability(pref_value, &result); + DCHECK(valid); + return result; +} + +// static +void IncognitoModePrefs::SetAvailability(PrefService* prefs, + const Availability availability) { + prefs->SetInteger(prefs::kIncognitoModeAvailability, availability); +} + +// static +void IncognitoModePrefs::RegisterUserPrefs(PrefService* pref_service) { + DCHECK(pref_service); + pref_service->RegisterIntegerPref(prefs::kIncognitoModeAvailability, + IncognitoModePrefs::ENABLED, + PrefService::UNSYNCABLE_PREF); +} diff --git a/chrome/browser/prefs/incognito_mode_prefs.h b/chrome/browser/prefs/incognito_mode_prefs.h new file mode 100644 index 0000000..907ac96 --- /dev/null +++ b/chrome/browser/prefs/incognito_mode_prefs.h @@ -0,0 +1,53 @@ +// 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. + +#ifndef CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_ +#define CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_ +#pragma once + +#include "base/basictypes.h" + +class PrefService; + +// Specifies Incognito mode availability preferences. +class IncognitoModePrefs { + public: + // Possible values for Incognito mode availability. Please, do not change + // the order of entries since numeric values are exposed to users. + enum Availability { + // Incognito mode enabled. Users may open pages in both Incognito mode and + // normal mode (the default behaviour). + ENABLED = 0, + // Incognito mode disabled. Users may not open pages in Incognito mode. + // Only normal mode is available for browsing. + DISABLED, + // Incognito mode forced. Users may open pages *ONLY* in Incognito mode. + // Normal mode is not available for browsing. + FORCED, + + AVAILABILITY_NUM_TYPES + }; + + // Register incognito related preferences. + static void RegisterUserPrefs(PrefService* prefs); + + // Returns kIncognitoModeAvailability preference value stored + // in the given pref service. + static Availability GetAvailability(const PrefService* prefs); + + // Sets kIncognitoModeAvailability preference to the specified availability + // value. + static void SetAvailability(PrefService* prefs, + const Availability availability); + + // Converts in_value into the corresponding Availability value. Returns true + // if conversion is successful (in_value is valid). Otherwise, returns false + // and *out_value is set to ENABLED. + static bool IntToAvailability(int in_value, Availability* out_value); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(IncognitoModePrefs); +}; + +#endif // CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_ diff --git a/chrome/browser/prefs/incognito_mode_prefs_unittest.cc b/chrome/browser/prefs/incognito_mode_prefs_unittest.cc new file mode 100644 index 0000000..053f0bf --- /dev/null +++ b/chrome/browser/prefs/incognito_mode_prefs_unittest.cc @@ -0,0 +1,66 @@ +// 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. + +#include "chrome/browser/prefs/incognito_mode_prefs.h" + +#include "chrome/common/pref_names.h" +#include "chrome/test/base/testing_pref_service.h" +#include "testing/gtest/include/gtest/gtest.h" + +class IncognitoModePrefsTest : public testing::Test { + protected: + virtual void SetUp() { + IncognitoModePrefs::RegisterUserPrefs(&prefs_); + } + + TestingPrefService prefs_; +}; + +TEST_F(IncognitoModePrefsTest, IntToAvailability) { + ASSERT_EQ(0, IncognitoModePrefs::ENABLED); + ASSERT_EQ(1, IncognitoModePrefs::DISABLED); + ASSERT_EQ(2, IncognitoModePrefs::FORCED); + + IncognitoModePrefs::Availability incognito; + EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(0, &incognito)); + EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito); + EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(1, &incognito)); + EXPECT_EQ(IncognitoModePrefs::DISABLED, incognito); + EXPECT_TRUE(IncognitoModePrefs::IntToAvailability(2, &incognito)); + EXPECT_EQ(IncognitoModePrefs::FORCED, incognito); + + EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(10, &incognito)); + EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito); + EXPECT_FALSE(IncognitoModePrefs::IntToAvailability(-1, &incognito)); + EXPECT_EQ(IncognitoModePrefs::ENABLED, incognito); +} + +TEST_F(IncognitoModePrefsTest, GetAvailability) { + prefs_.SetUserPref(prefs::kIncognitoModeAvailability, + Value::CreateIntegerValue(IncognitoModePrefs::ENABLED)); + EXPECT_EQ(IncognitoModePrefs::ENABLED, + IncognitoModePrefs::GetAvailability(&prefs_)); + + prefs_.SetUserPref(prefs::kIncognitoModeAvailability, + Value::CreateIntegerValue(IncognitoModePrefs::DISABLED)); + EXPECT_EQ(IncognitoModePrefs::DISABLED, + IncognitoModePrefs::GetAvailability(&prefs_)); + + prefs_.SetUserPref(prefs::kIncognitoModeAvailability, + Value::CreateIntegerValue(IncognitoModePrefs::FORCED)); + EXPECT_EQ(IncognitoModePrefs::FORCED, + IncognitoModePrefs::GetAvailability(&prefs_)); +} + +typedef IncognitoModePrefsTest IncognitoModePrefsDeathTest; + +TEST_F(IncognitoModePrefsDeathTest, GetAvailabilityBadValue) { + prefs_.SetUserPref(prefs::kIncognitoModeAvailability, + Value::CreateIntegerValue(-1)); + EXPECT_DEBUG_DEATH({ + IncognitoModePrefs::Availability availability = + IncognitoModePrefs::GetAvailability(&prefs_); + EXPECT_EQ(IncognitoModePrefs::ENABLED, availability); + }, ""); +} diff --git a/chrome/browser/prefs/pref_value_map.cc b/chrome/browser/prefs/pref_value_map.cc index b810519..3d69cf1 100644 --- a/chrome/browser/prefs/pref_value_map.cc +++ b/chrome/browser/prefs/pref_value_map.cc @@ -102,6 +102,15 @@ void PrefValueMap::SetString(const std::string& key, SetValue(key, Value::CreateStringValue(value)); } +bool PrefValueMap::GetInteger(const std::string& key, int* value) const { + const Value* stored_value = NULL; + return GetValue(key, &stored_value) && stored_value->GetAsInteger(value); +} + +void PrefValueMap::SetInteger(const std::string& key, const int value) { + SetValue(key, Value::CreateIntegerValue(value)); +} + void PrefValueMap::GetDifferingKeys( const PrefValueMap* other, std::vector<std::string>* differing_keys) const { diff --git a/chrome/browser/prefs/pref_value_map.h b/chrome/browser/prefs/pref_value_map.h index 100aa34..f8995ce 100644 --- a/chrome/browser/prefs/pref_value_map.h +++ b/chrome/browser/prefs/pref_value_map.h @@ -58,6 +58,13 @@ class PrefValueMap { // Sets the value for |key| to the string |value|. void SetString(const std::string& key, const std::string& value); + // Gets an int value for |key| and stores it in |value|. Returns true if + // the value was found and of the proper type. + bool GetInteger(const std::string& key, int* value) const; + + // Sets the value for |key| to the int |value|. + void SetInteger(const std::string& key, const int value); + // Compares this value map against |other| and stores all key names that have // different values in |differing_keys|. This includes keys that are present // only in one of the maps. diff --git a/chrome/browser/prefs/pref_value_map_unittest.cc b/chrome/browser/prefs/pref_value_map_unittest.cc index cc47a85..08aa578 100644 --- a/chrome/browser/prefs/pref_value_map_unittest.cc +++ b/chrome/browser/prefs/pref_value_map_unittest.cc @@ -23,6 +23,19 @@ TEST_F(PrefValueMapTest, SetValue) { EXPECT_TRUE(StringValue("hi mom!").Equals(result)); } +TEST_F(PrefValueMapTest, GetAndSetIntegerValue) { + PrefValueMap map; + ASSERT_TRUE(map.SetValue("key", Value::CreateIntegerValue(5))); + + int int_value = 0; + EXPECT_TRUE(map.GetInteger("key", &int_value)); + EXPECT_EQ(5, int_value); + + map.SetInteger("key", -14); + EXPECT_TRUE(map.GetInteger("key", &int_value)); + EXPECT_EQ(-14, int_value); +} + TEST_F(PrefValueMapTest, RemoveValue) { PrefValueMap map; EXPECT_FALSE(map.RemoveValue("key")); diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc index f83cbd7..8144b32 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -27,6 +27,7 @@ #include "chrome/browser/extensions/extension_special_storage_policy.h" #include "chrome/browser/extensions/extension_webrequest_api.h" #include "chrome/browser/net/pref_proxy_config_service.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/off_the_record_profile_io_data.h" #include "chrome/browser/profiles/profile_dependency_manager.h" @@ -242,7 +243,8 @@ class OffTheRecordProfileImpl : public Profile, ProfileDependencyManager::GetInstance()->CreateProfileServices(this, false); - DCHECK(real_profile->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); + DCHECK_NE(IncognitoModePrefs::DISABLED, + IncognitoModePrefs::GetAvailability(real_profile->GetPrefs())); // TODO(oshima): Remove the need to eagerly initialize the request context // getter. chromeos::OnlineAttempt is illegally trying to access this diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index ab01be8..d02f69d 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -28,6 +28,7 @@ #include "chrome/browser/net/browser_url_util.h" #include "chrome/browser/page_info_window.h" #include "chrome/browser/platform_util.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" @@ -977,6 +978,8 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { return true; } + IncognitoModePrefs::Availability incognito_avail = + IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); switch (id) { case IDC_BACK: return source_tab_contents_->controller().CanGoBack(); @@ -1028,8 +1031,10 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { } case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: - case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: return params_.link_url.is_valid(); + case IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW: + return params_.link_url.is_valid() && + incognito_avail != IncognitoModePrefs::FORCED; case IDC_CONTENT_CONTEXT_COPYLINKLOCATION: return params_.unfiltered_link_url.is_valid(); @@ -1153,7 +1158,7 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: return !profile_->IsOffTheRecord() && params_.link_url.is_valid() && - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled); + incognito_avail != IncognitoModePrefs::DISABLED; 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 ddfc395..34fbf01 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -55,6 +55,7 @@ #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/platform_util.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" #include "chrome/browser/profiles/profile.h" @@ -292,7 +293,7 @@ Browser::Browser(Type type, Profile* profile) profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); profile_pref_registrar_.Add(prefs::kEditBookmarksEnabled, this); profile_pref_registrar_.Add(prefs::kInstantEnabled, this); - profile_pref_registrar_.Add(prefs::kIncognitoEnabled, this); + profile_pref_registrar_.Add(prefs::kIncognitoModeAvailability, this); InitCommandState(); BrowserList::AddBrowser(this); @@ -1470,10 +1471,12 @@ void Browser::Stop() { } void Browser::NewWindow() { + IncognitoModePrefs::Availability incognito_avail = + IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); if (browser_defaults::kAlwaysOpenIncognitoWindow && + incognito_avail != IncognitoModePrefs::DISABLED && (CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) || - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoForced)) && - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { + incognito_avail == IncognitoModePrefs::FORCED)) { NewIncognitoWindow(); return; } @@ -1487,7 +1490,8 @@ void Browser::NewWindow() { } void Browser::NewIncognitoWindow() { - if (!profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { + if (IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) == + IncognitoModePrefs::DISABLED) { NewWindow(); return; } @@ -2253,12 +2257,6 @@ void Browser::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false, PrefService::UNSYNCABLE_PREF); - prefs->RegisterBooleanPref(prefs::kIncognitoEnabled, - true, - PrefService::UNSYNCABLE_PREF); - prefs->RegisterBooleanPref(prefs::kIncognitoForced, - false, - PrefService::UNSYNCABLE_PREF); prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, -1, PrefService::UNSYNCABLE_PREF); @@ -3715,10 +3713,15 @@ void Browser::Observe(int type, } else { CreateInstantIfNecessary(); } - } else if (pref_name == prefs::kIncognitoEnabled) { + } else if (pref_name == prefs::kIncognitoModeAvailability) { + IncognitoModePrefs::Availability available = + IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); + command_updater_.UpdateCommandEnabled( + IDC_NEW_WINDOW, + available != IncognitoModePrefs::FORCED); command_updater_.UpdateCommandEnabled( IDC_NEW_INCOGNITO_WINDOW, - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); + available != IncognitoModePrefs::DISABLED); } else if (pref_name == prefs::kDevToolsDisabled) { UpdateCommandsForDevTools(); if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) @@ -3854,10 +3857,15 @@ void Browser::InitCommandState() { command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); // Window management commands - command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); + IncognitoModePrefs::Availability incognito_avail = + IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); + command_updater_.UpdateCommandEnabled( + IDC_NEW_WINDOW, + incognito_avail != IncognitoModePrefs::FORCED); command_updater_.UpdateCommandEnabled( IDC_NEW_INCOGNITO_WINDOW, - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)); + incognito_avail != IncognitoModePrefs::DISABLED); + 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_init.cc b/chrome/browser/ui/browser_init.cc index 7fa78c3..0f672f3 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -31,6 +31,7 @@ #include "chrome/browser/net/predictor_api.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/notifications/desktop_notification_service.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" @@ -360,15 +361,22 @@ bool SessionCrashedInfoBarDelegate::Accept() { // Utility functions ---------------------------------------------------------- +bool IncognitoIsForced(const CommandLine& command_line, + const PrefService* prefs) { + IncognitoModePrefs::Availability incognito_avail = + IncognitoModePrefs::GetAvailability(prefs); + return incognito_avail != IncognitoModePrefs::DISABLED && + (command_line.HasSwitch(switches::kIncognito) || + incognito_avail == IncognitoModePrefs::FORCED); +} + SessionStartupPref GetSessionStartupPref(const CommandLine& command_line, Profile* profile) { SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); if (command_line.HasSwitch(switches::kRestoreLastSession)) pref.type = SessionStartupPref::LAST; - if ((command_line.HasSwitch(switches::kIncognito) || - profile->GetPrefs()->GetBoolean(prefs::kIncognitoForced)) && - pref.type == SessionStartupPref::LAST && - profile->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { + if (pref.type == SessionStartupPref::LAST && + IncognitoIsForced(command_line, profile->GetPrefs())) { // 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. @@ -537,10 +545,9 @@ bool BrowserInit::LaunchBrowser(const CommandLine& command_line, } #endif - // Continue with the incognito profile from here on if --incognito - if ((command_line.HasSwitch(switches::kIncognito) || - profile->GetPrefs()->GetBoolean(prefs::kIncognitoForced)) && - profile->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { + // Continue with the incognito profile from here on if Incognito mode + // is forced. + if (IncognitoIsForced(command_line, profile->GetPrefs())) { profile = profile->GetOffTheRecordProfile(); } diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm index e5917cf..6bb16a8 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm @@ -11,6 +11,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #import "chrome/browser/themes/theme_service.h" @@ -1085,12 +1086,23 @@ void RecordAppLaunch(Profile* profile, GURL url) { return NO; } + Profile* profile = browser_->profile(); // If this is an incognito window, don't allow "open in incognito". if ((action == @selector(openBookmarkInIncognitoWindow:)) || (action == @selector(openAllBookmarksIncognitoWindow:))) { - Profile* profile = browser_->profile(); if (profile->IsOffTheRecord() || - !profile->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled)) { + IncognitoModePrefs::GetAvailability(profile->GetPrefs()) == + IncognitoModePrefs::DISABLED) { + return NO; + } + } + + // If Incognito mode is forced, do not let open bookmarks in normal window. + if ((action == @selector(openBookmark:)) || + (action == @selector(openAllBookmarksNewWindow:)) || + (action == @selector(openAllBookmarks:))) { + if (IncognitoModePrefs::GetAvailability(profile->GetPrefs()) == + IncognitoModePrefs::FORCED) { return NO; } } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc index fe6ff6b..aaa4b92 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.cc @@ -10,6 +10,7 @@ #include "chrome/browser/bookmarks/bookmark_folder_editor_controller.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_utils.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -234,18 +235,23 @@ bool BookmarkContextMenuControllerViews::IsCommandEnabled(int id) const { selection_[0]->parent() == model_->root_node()); bool can_edit = profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled); + IncognitoModePrefs::Availability incognito_avail = + IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); switch (id) { case IDC_BOOKMARK_BAR_OPEN_INCOGNITO: return !profile_->IsOffTheRecord() && - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled); + incognito_avail != IncognitoModePrefs::DISABLED; case IDC_BOOKMARK_BAR_OPEN_ALL_INCOGNITO: - return HasURLs() && !profile_->IsOffTheRecord() && - profile_->GetPrefs()->GetBoolean(prefs::kIncognitoEnabled); + return HasURLs() && + !profile_->IsOffTheRecord() && + incognito_avail != IncognitoModePrefs::DISABLED; case IDC_BOOKMARK_BAR_OPEN_ALL: - case IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW: return HasURLs(); + case IDC_BOOKMARK_BAR_OPEN_ALL_NEW_WINDOW: + return HasURLs() && + incognito_avail != IncognitoModePrefs::FORCED; case IDC_BOOKMARK_BAR_RENAME_FOLDER: case IDC_BOOKMARK_BAR_EDIT: diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 85ed5b7..2f83f81 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1708,6 +1708,8 @@ 'browser/prefs/command_line_pref_store.h', 'browser/prefs/default_pref_store.cc', 'browser/prefs/default_pref_store.h', + 'browser/prefs/incognito_mode_prefs.cc', + 'browser/prefs/incognito_mode_prefs.h', 'browser/prefs/incognito_user_pref_store.cc', 'browser/prefs/incognito_user_pref_store.h', 'browser/prefs/pref_change_registrar.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index fe1e518..4e4a508 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1565,6 +1565,7 @@ 'browser/preferences_mock_mac.cc', 'browser/preferences_mock_mac.h', 'browser/prefs/command_line_pref_store_unittest.cc', + 'browser/prefs/incognito_mode_prefs_unittest.cc', 'browser/prefs/incognito_user_pref_store_unittest.cc', 'browser/prefs/pref_change_registrar_unittest.cc', 'browser/prefs/pref_member_unittest.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 019138f..9a9fc6d 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -164,11 +164,11 @@ 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 specifies if all user sessions should be forced into Incognito. -const char kIncognitoForced[] = "incognito.forced"; +// Enum that specifies whether Incognito mode is: +// 0 - Enabled. Default behaviour. Default mode is available on demand. +// 1 - Disabled. Used cannot browse pages in Incognito mode. +// 2 - Forced. All pages/sessions are forced into Incognito. +const char kIncognitoModeAvailability[] = "incognito.mode_availability"; // 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 2d11928..1ff960b 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -67,8 +67,7 @@ extern const char kPasswordManagerAllowShowPasswords[]; extern const char kAutologinEnabled[]; extern const char kSafeBrowsingEnabled[]; extern const char kSafeBrowsingReportingEnabled[]; -extern const char kIncognitoEnabled[]; -extern const char kIncognitoForced[]; +extern const char kIncognitoModeAvailability[]; extern const char kSearchSuggestEnabled[]; extern const char kConfirmToQuitEnabled[]; extern const char kCookieBehavior[]; // OBSOLETE |