From fd8eb3de1bffdec11a3ccf542e028f953ac280b4 Mon Sep 17 00:00:00 2001 From: Black-Hole <158blackhole@gmail.com> Date: Thu, 2 Sep 2021 06:36:21 +0800 Subject: [PATCH] fix: remove extension warning that do not have any impact (#29695) --- .../extensions/electron_extension_loader.cc | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/shell/browser/extensions/electron_extension_loader.cc b/shell/browser/extensions/electron_extension_loader.cc index 0c85a4440ba..87ca552bf62 100644 --- a/shell/browser/extensions/electron_extension_loader.cc +++ b/shell/browser/extensions/electron_extension_loader.cc @@ -21,7 +21,9 @@ #include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_registry.h" #include "extensions/browser/pref_names.h" +#include "extensions/common/error_utils.h" #include "extensions/common/file_util.h" +#include "extensions/common/manifest_constants.h" namespace extensions { @@ -41,6 +43,15 @@ std::pair, std::string> LoadUnpacked( return std::make_pair(nullptr, err); } + // remove _metadata folder. Otherwise, the following warning will be thrown + // Cannot load extension with file or directory name _metadata. + // Filenames starting with "_" are reserved for use by the system. + // see: https://bugs.chromium.org/p/chromium/issues/detail?id=377278 + base::FilePath metadata_dir = extension_dir.Append(kMetadataFolder); + if (base::DirectoryExists(metadata_dir)) { + base::DeletePathRecursively(metadata_dir); + } + std::string load_error; scoped_refptr extension = file_util::LoadExtension( extension_dir, extensions::mojom::ManifestLocation::kCommandLine, @@ -55,10 +66,25 @@ std::pair, std::string> LoadUnpacked( std::string warnings; // Log warnings. if (!extension->install_warnings().empty()) { - warnings += "Warnings loading extension at " + - base::UTF16ToUTF8(extension_dir.LossyDisplayName()) + ":\n"; + std::string warning_prefix = + "Warnings loading extension at " + + base::UTF16ToUTF8(extension_dir.LossyDisplayName()); + for (const auto& warning : extension->install_warnings()) { - warnings += " " + warning.message + "\n"; + std::string unrecognized_manifest_error = ErrorUtils::FormatErrorMessage( + manifest_errors::kUnrecognizedManifestKey, warning.key); + + if (warning.message == unrecognized_manifest_error) { + // filter kUnrecognizedManifestKey error. This error does not have any + // impact e.g: Unrecognized manifest key 'minimum_chrome_version' etc. + LOG(WARNING) << warning_prefix << ": " << warning.message; + } else { + warnings += " " + warning.message + "\n"; + } + } + + if (warnings != "") { + warnings = warning_prefix + ":\n" + warnings; } }