add-flag-to-configure-extension-downloading.patch 5.0 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/chrome_notification_types.h"
  9. #include "chrome/browser/extensions/crx_installer.h"
  10. #include "chrome/browser/extensions/extension_install_prompt.h"
  11. @@ -128,6 +129,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. @@ -136,7 +145,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. @@ -43,6 +43,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. @@ -1055,10 +1055,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. @@ -10,6 +10,7 @@
  66. #include "base/bind.h"
  67. #include "base/callback_helpers.h"
  68. +#include "base/command_line.h"
  69. #include "base/containers/contains.h"
  70. #include "base/logging.h"
  71. #include "base/metrics/histogram_functions.h"
  72. @@ -237,6 +238,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_->has_restricted_install_sources)
  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. @@ -12,4 +12,8 @@
  104. "Enable stacking in the tab strip",
  105. "Forces tabs to be stacked in the tab strip. Otherwise, they follow default behavior. ungoogled-chromium flag.",
  106. kOsAll, SINGLE_VALUE_TYPE("enable-stacked-tab-strip")},
  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_