Commit 49c09c5c authored by elijahtaylor's avatar elijahtaylor Committed by Commit bot

Make sure Shared Modules cannot be disabled

BUG=601310,620091
TEST=ExtensionServiceTest.CannotDisableSharedModules
TEST=manually disable shared module in preferences, start chrome and observe
     shared module is enabled on restart

Review-Url: https://codereview.chromium.org/2131173003
Cr-Commit-Position: refs/heads/master@{#404554}
parent 1552cf3a
......@@ -869,6 +869,12 @@ void ExtensionService::DisableExtension(const std::string& extension_id,
}
const Extension* extension = GetInstalledExtension(extension_id);
// Shared modules cannot be disabled, they are just resources used by other
// extensions, and are not user controlled.
if (extension && SharedModuleInfo::IsSharedModule(extension))
return;
// |extension| can be nullptr if sync disables an extension that is not
// installed yet.
// EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
......@@ -1420,6 +1426,18 @@ void ExtensionService::OnLoadedInstalledExtensions() {
if (updater_)
updater_->Start();
// Enable any Shared Modules that incorrectly got disabled previously.
// This is temporary code to fix incorrect behavior from previous versions of
// Chrome and can be removed after several releases (perhaps M60).
extensions::ExtensionList to_enable;
for (const auto& extension : registry_->disabled_extensions()) {
if (SharedModuleInfo::IsSharedModule(extension.get()))
to_enable.push_back(extension);
}
for (const auto& extension : to_enable) {
EnableExtension(extension->id());
}
OnBlacklistUpdated();
}
......
......@@ -6776,6 +6776,36 @@ TEST_F(ExtensionServiceTest, CannotEnableBlacklistedExtension) {
EXPECT_TRUE(ExtensionPrefs::Get(profile())->IsExtensionBlacklisted(id));
}
// Test that calls to disable Shared Modules do not work.
TEST_F(ExtensionServiceTest, CannotDisableSharedModules) {
InitializeEmptyExtensionService();
std::unique_ptr<base::DictionaryValue> manifest =
extensions::DictionaryBuilder()
.Set("name", "Shared Module")
.Set("version", "1.0")
.Set("manifest_version", 2)
.Set("export",
extensions::DictionaryBuilder()
.Set("resources",
extensions::ListBuilder().Append("foo.js").Build())
.Build())
.Build();
scoped_refptr<Extension> extension = extensions::ExtensionBuilder()
.SetManifest(std::move(manifest))
.AddFlags(Extension::FROM_WEBSTORE)
.Build();
service()->OnExtensionInstalled(extension.get(), syncer::StringOrdinal(),
extensions::kInstallFlagInstallImmediately);
ASSERT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
// Try to disable the extension.
service()->DisableExtension(extension->id(), Extension::DISABLE_USER_ACTION);
// Shared Module should still be enabled.
EXPECT_TRUE(registry()->enabled_extensions().Contains(extension->id()));
}
// Make sure we can uninstall a blacklisted extension
TEST_F(ExtensionServiceTest, UninstallBlacklistedExtension) {
InitializeGoodInstalledExtensionService();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment