add-flag-to-configure-extension-downloading.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Add extension-mime-request-handling chrome://flag to tweak the behavior of
  2. # extension MIME types
  3. --- a/chrome/browser/download/download_crx_util.cc
  4. +++ b/chrome/browser/download/download_crx_util.cc
  5. @@ -8,6 +8,7 @@
  6. #include <memory>
  7. +#include "base/command_line.h"
  8. #include "chrome/browser/extensions/crx_installer.h"
  9. #include "chrome/browser/extensions/extension_install_prompt.h"
  10. #include "chrome/browser/extensions/extension_management.h"
  11. @@ -101,6 +102,14 @@ scoped_refptr<extensions::CrxInstaller>
  12. return installer;
  13. }
  14. +bool ShouldDownloadAsRegularFile() {
  15. + const base::CommandLine& command_line =
  16. + *base::CommandLine::ForCurrentProcess();
  17. + return command_line.HasSwitch("extension-mime-request-handling") &&
  18. + command_line.GetSwitchValueASCII("extension-mime-request-handling") ==
  19. + "download-as-regular-file";
  20. +}
  21. +
  22. bool IsExtensionDownload(const DownloadItem& download_item) {
  23. if (download_item.GetTargetDisposition() ==
  24. DownloadItem::TARGET_DISPOSITION_PROMPT)
  25. @@ -109,7 +118,7 @@ bool IsExtensionDownload(const DownloadI
  26. if (download_item.GetMimeType() == extensions::Extension::kMimeType ||
  27. extensions::UserScript::IsURLUserScript(download_item.GetURL(),
  28. download_item.GetMimeType())) {
  29. - return true;
  30. + return !ShouldDownloadAsRegularFile();
  31. } else {
  32. return false;
  33. }
  34. --- a/chrome/browser/download/download_crx_util.h
  35. +++ b/chrome/browser/download/download_crx_util.h
  36. @@ -35,6 +35,10 @@ scoped_refptr<extensions::CrxInstaller>
  37. Profile* profile,
  38. const download::DownloadItem& download_item);
  39. +// Returns true if the user wants all extensions to be downloaded as regular
  40. +// files.
  41. +bool ShouldDownloadAsRegularFile();
  42. +
  43. // Returns true if this is an extension download. This also considers user
  44. // scripts to be extension downloads, since we convert those automatically.
  45. bool IsExtensionDownload(const download::DownloadItem& download_item);
  46. --- a/chrome/browser/download/download_target_determiner.cc
  47. +++ b/chrome/browser/download/download_target_determiner.cc
  48. @@ -1187,10 +1187,12 @@ DownloadConfirmationReason DownloadTarge
  49. return DownloadConfirmationReason::SAVE_AS;
  50. #if BUILDFLAG(ENABLE_EXTENSIONS)
  51. - // Don't prompt for extension downloads if the installation site is white
  52. - // listed.
  53. - if (download_crx_util::IsTrustedExtensionDownload(GetProfile(), *download_))
  54. - return DownloadConfirmationReason::NONE;
  55. + if (!download_crx_util::ShouldDownloadAsRegularFile()) {
  56. + // Don't prompt for extension downloads.
  57. + if (download_crx_util::IsTrustedExtensionDownload(GetProfile(), *download_) ||
  58. + filename.MatchesExtension(extensions::kExtensionFileExtension))
  59. + return DownloadConfirmationReason::NONE;
  60. + }
  61. #endif
  62. // Don't prompt for file types that are marked for opening automatically.
  63. --- a/chrome/browser/extensions/extension_management.cc
  64. +++ b/chrome/browser/extensions/extension_management.cc
  65. @@ -8,6 +8,7 @@
  66. #include <string>
  67. #include <utility>
  68. +#include "base/command_line.h"
  69. #include "base/containers/contains.h"
  70. #include "base/feature_list.h"
  71. #include "base/functional/bind.h"
  72. @@ -253,6 +254,13 @@ bool ExtensionManagement::IsInstallation
  73. bool ExtensionManagement::IsOffstoreInstallAllowed(
  74. const GURL& url,
  75. const GURL& referrer_url) const {
  76. + const base::CommandLine& command_line =
  77. + *base::CommandLine::ForCurrentProcess();
  78. + if (command_line.HasSwitch("extension-mime-request-handling") &&
  79. + command_line.GetSwitchValueASCII("extension-mime-request-handling") ==
  80. + "always-prompt-for-install") {
  81. + return true;
  82. + }
  83. // No allowed install sites specified, disallow by default.
  84. if (!global_settings_->install_sources.has_value())
  85. return false;
  86. --- a/chrome/browser/ungoogled_flag_choices.h
  87. +++ b/chrome/browser/ungoogled_flag_choices.h
  88. @@ -4,4 +4,13 @@
  89. #ifndef CHROME_BROWSER_UNGOOGLED_FLAG_CHOICES_H_
  90. #define CHROME_BROWSER_UNGOOGLED_FLAG_CHOICES_H_
  91. +const FeatureEntry::Choice kExtensionHandlingChoices[] = {
  92. + {flags_ui::kGenericExperimentChoiceDefault, "", ""},
  93. + {"Download as regular file",
  94. + "extension-mime-request-handling",
  95. + "download-as-regular-file"},
  96. + {"Always prompt for install",
  97. + "extension-mime-request-handling",
  98. + "always-prompt-for-install"},
  99. +};
  100. #endif // CHROME_BROWSER_UNGOOGLED_FLAG_CHOICES_H_
  101. --- a/chrome/browser/ungoogled_flag_entries.h
  102. +++ b/chrome/browser/ungoogled_flag_entries.h
  103. @@ -8,4 +8,8 @@
  104. "SetIpv6ProbeFalse",
  105. "Forces the result of the browser's IPv6 probing (i.e. IPv6 connectivity test) to be unsuccessful. This causes IPv4 addresses to be prioritized over IPv6 addresses. Without this flag, the probing result is set to be successful, which causes IPv6 to be used over IPv4 when possible. ungoogled-chromium flag.",
  106. kOsAll, FEATURE_VALUE_TYPE(net::features::kSetIpv6ProbeFalse)},
  107. + {"extension-mime-request-handling",
  108. + "Handling of extension MIME type requests",
  109. + "Used when deciding how to handle a request for a CRX or User Script MIME type. ungoogled-chromium flag.",
  110. + kOsAll, MULTI_VALUE_TYPE(kExtensionHandlingChoices)},
  111. #endif // CHROME_BROWSER_UNGOOGLED_FLAG_ENTRIES_H_