[Extensions] Remove old permission withholding pref migration
This was a limited time pref key migration, which is well past time for removal at this point. Bug: 40636075 Change-Id: I72478bb6cf8f9a8f47f60158924edf941c8136a5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6397376 Reviewed-by: David Bertoni <dbertoni@chromium.org> Commit-Queue: Tim <tjudkins@chromium.org> Cr-Commit-Position: refs/heads/main@{#1438348}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
21739f82e5
commit
a25caa571f
chrome/browser/extensions
extensions/browser
@ -1287,80 +1287,6 @@ TEST_P(ExtensionPrefsApplyPendingUpdates, ExtensionPrefsApplyPendingUpdates) {
|
||||
|
||||
using ExtensionPrefsSimpleTest = testing::Test;
|
||||
|
||||
// Tests the migration from the old withholding pref key to the new one.
|
||||
TEST_F(ExtensionPrefsSimpleTest, OldWithholdingPrefMigration) {
|
||||
constexpr char kOldPrefKey[] = "extension_can_script_all_urls";
|
||||
constexpr char kNewPrefKey[] = "withholding_permissions";
|
||||
|
||||
content::BrowserTaskEnvironment task_environment_;
|
||||
TestExtensionPrefs prefs(base::SingleThreadTaskRunner::GetCurrentDefault());
|
||||
|
||||
std::string previous_false_id = prefs.AddExtensionAndReturnId("Old false");
|
||||
std::string previous_true_id = prefs.AddExtensionAndReturnId("Old true");
|
||||
std::string previous_empty_id = prefs.AddExtensionAndReturnId("Old empty");
|
||||
std::string force_installed_id =
|
||||
prefs
|
||||
.AddExtensionWithLocation("Force installed",
|
||||
ManifestLocation::kExternalPolicy)
|
||||
->id();
|
||||
|
||||
// We need to explicitly remove the default value for the new pref as it is
|
||||
// added on install by default.
|
||||
prefs.prefs()->UpdateExtensionPref(previous_false_id, kNewPrefKey,
|
||||
std::nullopt);
|
||||
prefs.prefs()->UpdateExtensionPref(previous_true_id, kNewPrefKey,
|
||||
std::nullopt);
|
||||
prefs.prefs()->UpdateExtensionPref(previous_empty_id, kNewPrefKey,
|
||||
std::nullopt);
|
||||
|
||||
prefs.prefs()->UpdateExtensionPref(previous_false_id, kOldPrefKey,
|
||||
base::Value(false));
|
||||
prefs.prefs()->UpdateExtensionPref(previous_true_id, kOldPrefKey,
|
||||
base::Value(true));
|
||||
|
||||
// First make sure that all prefs start out as we expect them to be.
|
||||
bool bool_value = false;
|
||||
EXPECT_TRUE(prefs.prefs()->ReadPrefAsBoolean(previous_false_id, kOldPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_FALSE(bool_value);
|
||||
|
||||
EXPECT_TRUE(prefs.prefs()->ReadPrefAsBoolean(previous_true_id, kOldPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_TRUE(bool_value);
|
||||
|
||||
EXPECT_FALSE(prefs.prefs()->ReadPrefAsBoolean(previous_empty_id, kOldPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_FALSE(prefs.prefs()->ReadPrefAsBoolean(force_installed_id, kOldPrefKey,
|
||||
&bool_value));
|
||||
|
||||
EXPECT_FALSE(prefs.prefs()->ReadPrefAsBoolean(previous_false_id, kNewPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_FALSE(prefs.prefs()->ReadPrefAsBoolean(previous_true_id, kNewPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_FALSE(prefs.prefs()->ReadPrefAsBoolean(previous_empty_id, kNewPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_FALSE(prefs.prefs()->ReadPrefAsBoolean(force_installed_id, kNewPrefKey,
|
||||
&bool_value));
|
||||
|
||||
// Now we reload the prefs and verify the migration happens.
|
||||
prefs.RecreateExtensionPrefs();
|
||||
|
||||
EXPECT_TRUE(prefs.prefs()->ReadPrefAsBoolean(previous_false_id, kNewPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_TRUE(bool_value);
|
||||
|
||||
EXPECT_TRUE(prefs.prefs()->ReadPrefAsBoolean(previous_true_id, kNewPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_FALSE(bool_value);
|
||||
|
||||
EXPECT_TRUE(prefs.prefs()->ReadPrefAsBoolean(previous_empty_id, kNewPrefKey,
|
||||
&bool_value));
|
||||
EXPECT_FALSE(bool_value);
|
||||
|
||||
EXPECT_FALSE(prefs.prefs()->ReadPrefAsBoolean(force_installed_id, kNewPrefKey,
|
||||
&bool_value));
|
||||
}
|
||||
|
||||
// Tests that raw manipulation of extension disable reasons works and unknown
|
||||
// values can be written / read back. This also also tests that the non-raw
|
||||
// getter collapses unknown values to DISABLE_UNKNOWN.
|
||||
|
@ -175,13 +175,6 @@ constexpr const char kPrefDesiredActivePermissions[] = "active_permissions";
|
||||
// permissions increase.
|
||||
constexpr const char kPrefGrantedPermissions[] = "granted_permissions";
|
||||
|
||||
// Pref that was previously used to indicate if host permissions should be
|
||||
// withheld. Due to the confusing name and the need to logically invert it when
|
||||
// being used, we transitioned to use kPrefWithholdingPermissions
|
||||
// instead.
|
||||
const char kGrantExtensionAllHostPermissions[] =
|
||||
"extension_can_script_all_urls";
|
||||
|
||||
// A preference indicating if requested host permissions are being withheld from
|
||||
// the extension, requiring them to be granted through the permissions API or
|
||||
// runtime host permissions.
|
||||
@ -2222,8 +2215,6 @@ ExtensionPrefs::ExtensionPrefs(
|
||||
|
||||
BackfillAndMigrateInstallTimePrefs();
|
||||
|
||||
MigrateToNewWithholdingPref();
|
||||
|
||||
MigrateDeprecatedDisableReasons();
|
||||
|
||||
MaybeMigrateDisableReasonsBitflagToList();
|
||||
@ -2723,50 +2714,6 @@ void ExtensionPrefs::MigrateObsoleteExtensionPrefs() {
|
||||
}
|
||||
}
|
||||
|
||||
void ExtensionPrefs::MigrateToNewWithholdingPref() {
|
||||
const ExtensionsInfo extensions_info = GetInstalledExtensionsInfo();
|
||||
|
||||
for (const auto& info : extensions_info) {
|
||||
const ExtensionId& extension_id = info.extension_id;
|
||||
// The manifest may be null in some cases, such as unpacked extensions
|
||||
// retrieved from the Preference file.
|
||||
if (!info.extension_manifest) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the new key is present in the prefs already, we don't need to check
|
||||
// further.
|
||||
bool value = false;
|
||||
if (ReadPrefAsBoolean(extension_id, kPrefWithholdingPermissions, &value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We only want to migrate extensions we can actually withhold permissions
|
||||
// from.
|
||||
Manifest::Type type =
|
||||
Manifest::GetTypeFromManifestValue(*info.extension_manifest);
|
||||
ManifestLocation location = info.extension_location;
|
||||
if (!util::CanWithholdPermissionsFromExtension(extension_id, type,
|
||||
location))
|
||||
continue;
|
||||
|
||||
bool old_pref_value = false;
|
||||
// If there was an old preference set, use the same (conceptual) value.
|
||||
// Otherwise, use the default setting.
|
||||
bool new_pref_value = kDefaultWithholdingBehavior;
|
||||
if (ReadPrefAsBoolean(extension_id, kGrantExtensionAllHostPermissions,
|
||||
&old_pref_value)) {
|
||||
// We invert the value as the previous pref stored if the extension was
|
||||
// granted all the requested permissions, whereas the new pref stores if
|
||||
// requested permissions are currently being withheld.
|
||||
new_pref_value = !old_pref_value;
|
||||
}
|
||||
|
||||
UpdateExtensionPref(extension_id, kPrefWithholdingPermissions,
|
||||
base::Value(new_pref_value));
|
||||
}
|
||||
}
|
||||
|
||||
bool ExtensionPrefs::ShouldInstallObsoleteComponentExtension(
|
||||
const ExtensionId& extension_id) {
|
||||
ScopedListPrefUpdate update(prefs_, pref_names::kDeletedComponentExtensions);
|
||||
|
@ -759,11 +759,6 @@ class ExtensionPrefs : public KeyedService {
|
||||
// extension's dictionary, which is keyed on the extension ID.
|
||||
void MigrateObsoleteExtensionPrefs();
|
||||
|
||||
// Updates an extension to use the new withholding pref key if it doesn't have
|
||||
// it yet, removing the old key in the process.
|
||||
// TODO(tjudkins): Remove this and the obsolete key in M83.
|
||||
void MigrateToNewWithholdingPref();
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
// Updates pref that were scheduled to be applied after Chrome restarts. This
|
||||
// function should only be called from the constructor of the ExtensionPrefs
|
||||
|
Reference in New Issue
Block a user