Commit 4c52ad41 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Remove the DCHECK in plugin_utils.cc when replacing allowlisted mime handlers

4 of the 5 allowed extensions are "quickoffice" and they all want to
handle the same mime types, when multiple are installed. And this is not
the right place to attempt to protect against multiple copies of the
extension being installed.

Fixed: 970227
Change-Id: I83922b6973c252dc497a04b623582878bfcde23c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2282545
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788832}
parent a14f34f4
......@@ -184,15 +184,15 @@ PluginUtils::GetMimeTypeToExtensionIdMap(
base::flat_map<std::string, std::string> mime_type_to_extension_id_map;
#if BUILDFLAG(ENABLE_EXTENSIONS)
Profile* profile = Profile::FromBrowserContext(browser_context);
std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist();
// Go through the white-listed extensions and try to use them to intercept
std::vector<std::string> allowlist = MimeTypesHandler::GetMIMETypeAllowlist();
// Go through the allowed extensions and try to use them to intercept
// the URL request.
for (const std::string& extension_id : whitelist) {
for (const std::string& extension_id : allowlist) {
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(browser_context)
->enabled_extensions()
.GetByID(extension_id);
// The white-listed extension may not be installed, so we have to nullptr
// The allowed extension may not be installed, so we have to nullptr
// check |extension|.
if (!extension ||
(profile->IsOffTheRecord() && !extensions::util::IsIncognitoEnabled(
......@@ -208,8 +208,10 @@ PluginUtils::GetMimeTypeToExtensionIdMap(
if (MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension)) {
for (const auto& supported_mime_type : handler->mime_type_set()) {
DCHECK(!base::Contains(mime_type_to_extension_id_map,
supported_mime_type));
// If multiple are installed, Quickoffice extensions may clobber ones
// earlier in the allowlist. Silently allow this (logging causes ~100
// lines of output since this function is invoked 3 times during startup
// for ~30 mime types).
mime_type_to_extension_id_map[supported_mime_type] = extension_id;
}
}
......
......@@ -23,7 +23,9 @@ namespace errors = extensions::manifest_errors;
namespace {
// This has to by in sync with MimeHandlerType enum.
const char* const kMIMETypeHandlersWhitelist[] = {
// Note that if multiple versions of quickoffice are installed, the
// higher-indexed entry will clobber earlier entries.
const char* const kMIMETypeHandlersAllowlist[] = {
extension_misc::kPdfExtensionId,
extension_misc::kQuickOfficeComponentExtensionId,
extension_misc::kQuickOfficeInternalExtensionId,
......@@ -31,7 +33,7 @@ const char* const kMIMETypeHandlersWhitelist[] = {
extension_misc::kMimeHandlerPrivateTestExtensionId};
// Used for UMA stats. Entries should not be renumbered and numeric values
// should never be reused. This corresponds to kMimeTypeHandlersWhitelist.
// should never be reused. This corresponds to kMimeTypeHandlersAllowlist.
// Don't forget to update enums.xml when updating these.
enum class MimeHandlerType {
kPdfExtension = 0,
......@@ -44,9 +46,9 @@ enum class MimeHandlerType {
};
static_assert(
base::size(kMIMETypeHandlersWhitelist) ==
base::size(kMIMETypeHandlersAllowlist) ==
static_cast<size_t>(MimeHandlerType::kMaxValue) + 1,
"MimeHandlerType enum is not in sync with kMIMETypeHandlersWhitelist.");
"MimeHandlerType enum is not in sync with kMIMETypeHandlersAllowlist.");
constexpr SkColor kPdfExtensionBackgroundColor = SkColorSetRGB(82, 86, 89);
constexpr SkColor kQuickOfficeExtensionBackgroundColor =
......@@ -66,21 +68,19 @@ MimeTypesHandlerInfo::~MimeTypesHandlerInfo() = default;
} // namespace
// static
std::vector<std::string> MimeTypesHandler::GetMIMETypeWhitelist() {
std::vector<std::string> whitelist;
for (size_t i = 0; i < base::size(kMIMETypeHandlersWhitelist); ++i)
whitelist.push_back(kMIMETypeHandlersWhitelist[i]);
return whitelist;
std::vector<std::string> MimeTypesHandler::GetMIMETypeAllowlist() {
return {std::begin(kMIMETypeHandlersAllowlist),
std::end(kMIMETypeHandlersAllowlist)};
}
// static
void MimeTypesHandler::ReportUsedHandler(const std::string& extension_id) {
auto* const* it =
std::find(std::begin(kMIMETypeHandlersWhitelist),
std::end(kMIMETypeHandlersWhitelist), extension_id);
if (it != std::end(kMIMETypeHandlersWhitelist)) {
std::find(std::begin(kMIMETypeHandlersAllowlist),
std::end(kMIMETypeHandlersAllowlist), extension_id);
if (it != std::end(kMIMETypeHandlersAllowlist)) {
MimeHandlerType type = static_cast<MimeHandlerType>(
it - std::begin(kMIMETypeHandlersWhitelist));
it - std::begin(kMIMETypeHandlersAllowlist));
base::UmaHistogramEnumeration("Extensions.UsedMimeTypeHandler", type);
}
}
......
......@@ -16,7 +16,7 @@
class MimeTypesHandler {
public:
// Returns list of extensions' ids that are allowed to use MIME type filters.
static std::vector<std::string> GetMIMETypeWhitelist();
static std::vector<std::string> GetMIMETypeAllowlist();
static MimeTypesHandler* GetHandler(const extensions::Extension* extension);
......
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