123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- # Add extension-mime-request-handling chrome://flag to tweak the behavior of
- # extension MIME types
- --- a/chrome/browser/download/download_crx_util.cc
- +++ b/chrome/browser/download/download_crx_util.cc
- @@ -8,6 +8,7 @@
-
- #include <memory>
-
- +#include "base/command_line.h"
- #include "chrome/browser/chrome_notification_types.h"
- #include "chrome/browser/extensions/crx_installer.h"
- #include "chrome/browser/extensions/extension_install_prompt.h"
- @@ -128,6 +129,14 @@ scoped_refptr<extensions::CrxInstaller>
- return installer;
- }
-
- +bool ShouldDownloadAsRegularFile() {
- + const base::CommandLine& command_line =
- + *base::CommandLine::ForCurrentProcess();
- + return command_line.HasSwitch("extension-mime-request-handling") &&
- + command_line.GetSwitchValueASCII("extension-mime-request-handling") ==
- + "download-as-regular-file";
- +}
- +
- bool IsExtensionDownload(const DownloadItem& download_item) {
- if (download_item.GetTargetDisposition() ==
- DownloadItem::TARGET_DISPOSITION_PROMPT)
- @@ -136,7 +145,7 @@ bool IsExtensionDownload(const DownloadI
- if (download_item.GetMimeType() == extensions::Extension::kMimeType ||
- extensions::UserScript::IsURLUserScript(download_item.GetURL(),
- download_item.GetMimeType())) {
- - return true;
- + return !ShouldDownloadAsRegularFile();
- } else {
- return false;
- }
- --- a/chrome/browser/download/download_crx_util.h
- +++ b/chrome/browser/download/download_crx_util.h
- @@ -43,6 +43,10 @@ scoped_refptr<extensions::CrxInstaller>
- Profile* profile,
- const download::DownloadItem& download_item);
-
- +// Returns true if the user wants all extensions to be downloaded as regular
- +// files.
- +bool ShouldDownloadAsRegularFile();
- +
- // Returns true if this is an extension download. This also considers user
- // scripts to be extension downloads, since we convert those automatically.
- bool IsExtensionDownload(const download::DownloadItem& download_item);
- --- a/chrome/browser/download/download_target_determiner.cc
- +++ b/chrome/browser/download/download_target_determiner.cc
- @@ -1055,10 +1055,12 @@ DownloadConfirmationReason DownloadTarge
- return DownloadConfirmationReason::SAVE_AS;
-
- #if BUILDFLAG(ENABLE_EXTENSIONS)
- - // Don't prompt for extension downloads if the installation site is white
- - // listed.
- - if (download_crx_util::IsTrustedExtensionDownload(GetProfile(), *download_))
- - return DownloadConfirmationReason::NONE;
- + if (!download_crx_util::ShouldDownloadAsRegularFile()) {
- + // Don't prompt for extension downloads.
- + if (download_crx_util::IsTrustedExtensionDownload(GetProfile(), *download_) ||
- + filename.MatchesExtension(extensions::kExtensionFileExtension))
- + return DownloadConfirmationReason::NONE;
- + }
- #endif
-
- // Don't prompt for file types that are marked for opening automatically.
- --- a/chrome/browser/extensions/extension_management.cc
- +++ b/chrome/browser/extensions/extension_management.cc
- @@ -10,6 +10,7 @@
-
- #include "base/bind.h"
- #include "base/callback_helpers.h"
- +#include "base/command_line.h"
- #include "base/containers/contains.h"
- #include "base/logging.h"
- #include "base/metrics/histogram_functions.h"
- @@ -237,6 +238,13 @@ bool ExtensionManagement::IsInstallation
- bool ExtensionManagement::IsOffstoreInstallAllowed(
- const GURL& url,
- const GURL& referrer_url) const {
- + const base::CommandLine& command_line =
- + *base::CommandLine::ForCurrentProcess();
- + if (command_line.HasSwitch("extension-mime-request-handling") &&
- + command_line.GetSwitchValueASCII("extension-mime-request-handling") ==
- + "always-prompt-for-install") {
- + return true;
- + }
- // No allowed install sites specified, disallow by default.
- if (!global_settings_->has_restricted_install_sources)
- return false;
- --- a/chrome/browser/ungoogled_flag_choices.h
- +++ b/chrome/browser/ungoogled_flag_choices.h
- @@ -4,4 +4,13 @@
-
- #ifndef CHROME_BROWSER_UNGOOGLED_FLAG_CHOICES_H_
- #define CHROME_BROWSER_UNGOOGLED_FLAG_CHOICES_H_
- +const FeatureEntry::Choice kExtensionHandlingChoices[] = {
- + {flags_ui::kGenericExperimentChoiceDefault, "", ""},
- + {"Download as regular file",
- + "extension-mime-request-handling",
- + "download-as-regular-file"},
- + {"Always prompt for install",
- + "extension-mime-request-handling",
- + "always-prompt-for-install"},
- +};
- #endif // CHROME_BROWSER_UNGOOGLED_FLAG_CHOICES_H_
- --- a/chrome/browser/ungoogled_flag_entries.h
- +++ b/chrome/browser/ungoogled_flag_entries.h
- @@ -12,4 +12,8 @@
- "Enable stacking in the tab strip",
- "Forces tabs to be stacked in the tab strip. Otherwise, they follow default behavior. ungoogled-chromium flag.",
- kOsAll, SINGLE_VALUE_TYPE("enable-stacked-tab-strip")},
- + {"extension-mime-request-handling",
- + "Handling of extension MIME type requests",
- + "Used when deciding how to handle a request for a CRX or User Script MIME type. ungoogled-chromium flag.",
- + kOsAll, MULTI_VALUE_TYPE(kExtensionHandlingChoices)},
- #endif // CHROME_BROWSER_UNGOOGLED_FLAG_ENTRIES_H_
|