fix: remove extension warning that do not have any impact (#29695)

This commit is contained in:
Black-Hole 2021-09-02 06:36:21 +08:00 committed by GitHub
parent 4d89174b41
commit fd8eb3de1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<scoped_refptr<const Extension>, 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> extension = file_util::LoadExtension(
extension_dir, extensions::mojom::ManifestLocation::kCommandLine,
@ -55,13 +66,28 @@ std::pair<scoped_refptr<const Extension>, 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()) {
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;
}
}
return std::make_pair(extension, warnings);
}