Commit cc1c8db4 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Add a Manifest V3 base::Feature

Add a base::Feature to control Manifest V3 support. If disabled, all
Manifest V3-based extensions will fail to load. This should only be
used as a last resort, and is very much a kill-switch (rather than a
gradual ramp-up tool).

By default, this feature is enabled (allowing manifest v3 extensions).

Bug: 1147344
Change-Id: I3e30ad76fce12bae584a625c81e3759b31d9478e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2520333Reviewed-by: default avatarKelvin Jiang <kelvinjiang@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826985}
parent b95d501a
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/error_utils.h" #include "extensions/common/error_utils.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/feature_switch.h" #include "extensions/common/feature_switch.h"
#include "extensions/common/manifest.h" #include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
...@@ -85,6 +87,15 @@ bool IsManifestSupported(int manifest_version, ...@@ -85,6 +87,15 @@ bool IsManifestSupported(int manifest_version,
static constexpr int kMaximumSupportedManifestVersion = 2; static constexpr int kMaximumSupportedManifestVersion = 2;
static_assert(kMaximumSupportedManifestVersion >= kModernManifestVersion, static_assert(kMaximumSupportedManifestVersion >= kModernManifestVersion,
"The modern manifest version must be supported."); "The modern manifest version must be supported.");
// The ultimate short-circuit: If the feature for MV3 is disabled, it's not
// supported.
if (manifest_version == 3 &&
!base::FeatureList::IsEnabled(
extensions_features::kMv3ExtensionsSupported)) {
return false;
}
// Modern is always safe. // Modern is always safe.
if (manifest_version >= kModernManifestVersion && if (manifest_version >= kModernManifestVersion &&
manifest_version <= kMaximumSupportedManifestVersion) { manifest_version <= kMaximumSupportedManifestVersion) {
......
...@@ -48,6 +48,10 @@ const base::Feature kAllowWithholdingExtensionPermissionsOnInstall{ ...@@ -48,6 +48,10 @@ const base::Feature kAllowWithholdingExtensionPermissionsOnInstall{
const base::Feature kContentScriptsMatchOriginAsFallback{ const base::Feature kContentScriptsMatchOriginAsFallback{
"ContentScriptsMatchOriginAsFallback", base::FEATURE_DISABLED_BY_DEFAULT}; "ContentScriptsMatchOriginAsFallback", base::FEATURE_DISABLED_BY_DEFAULT};
// Whether Manifest Version 3-based extensions are supported.
const base::Feature kMv3ExtensionsSupported{"Mv3ExtensionsSupported",
base::FEATURE_ENABLED_BY_DEFAULT};
// Reports Extensions.WebRequest.KeepaliveRequestFinished when enabled. // Reports Extensions.WebRequest.KeepaliveRequestFinished when enabled.
const base::Feature kReportKeepaliveUkm{"ReportKeepaliveUkm", const base::Feature kReportKeepaliveUkm{"ReportKeepaliveUkm",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
......
...@@ -27,6 +27,8 @@ extern const base::Feature kAllowWithholdingExtensionPermissionsOnInstall; ...@@ -27,6 +27,8 @@ extern const base::Feature kAllowWithholdingExtensionPermissionsOnInstall;
extern const base::Feature kContentScriptsMatchOriginAsFallback; extern const base::Feature kContentScriptsMatchOriginAsFallback;
extern const base::Feature kMv3ExtensionsSupported;
extern const base::Feature kReportKeepaliveUkm; extern const base::Feature kReportKeepaliveUkm;
extern const base::Feature kReturnScopesInGetAuthToken; extern const base::Feature kReturnScopesInGetAuthToken;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/test/scoped_command_line.h" #include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "extensions/common/switches.h" #include "extensions/common/switches.h"
#include "extensions/common/value_builder.h" #include "extensions/common/value_builder.h"
...@@ -126,6 +128,15 @@ TEST(ExtensionTest, ExtensionManifestVersions) { ...@@ -126,6 +128,15 @@ TEST(ExtensionTest, ExtensionManifestVersions) {
EXPECT_TRUE( EXPECT_TRUE(
RunManifestVersionSuccess(get_manifest(base::nullopt), kType, 1)); RunManifestVersionSuccess(get_manifest(base::nullopt), kType, 1));
} }
{
// If the requisite feature is disabled, Manifest V3 extensions should
// fail to load.
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(
extensions_features::kMv3ExtensionsSupported);
EXPECT_TRUE(RunManifestVersionFailure(get_manifest(3)));
}
} }
TEST(ExtensionTest, PlatformAppManifestVersions) { TEST(ExtensionTest, PlatformAppManifestVersions) {
......
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