add-flag-to-configure-extension-downloading.patch 6.24 KB
Newer Older
1 2 3
# Add extension-mime-request-handling chrome://flag to tweak the behavior of
# extension MIME types

4
Index: chromium-127.0.6533.88/chrome/browser/download/download_crx_util.cc
5
===================================================================
6 7
--- chromium-127.0.6533.88.orig/chrome/browser/download/download_crx_util.cc
+++ chromium-127.0.6533.88/chrome/browser/download/download_crx_util.cc
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
@@ -8,6 +8,7 @@
 
 #include <memory>
 
+#include "base/command_line.h"
 #include "chrome/browser/extensions/crx_installer.h"
 #include "chrome/browser/extensions/extension_install_prompt.h"
 #include "chrome/browser/extensions/extension_management.h"
@@ -101,6 +102,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)
@@ -109,7 +118,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;
   }
40
Index: chromium-127.0.6533.88/chrome/browser/download/download_crx_util.h
41
===================================================================
42 43
--- chromium-127.0.6533.88.orig/chrome/browser/download/download_crx_util.h
+++ chromium-127.0.6533.88/chrome/browser/download/download_crx_util.h
44 45 46 47 48 49 50 51 52 53 54
@@ -35,6 +35,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);
55
Index: chromium-127.0.6533.88/chrome/browser/download/download_target_determiner.cc
56
===================================================================
57 58 59
--- chromium-127.0.6533.88.orig/chrome/browser/download/download_target_determiner.cc
+++ chromium-127.0.6533.88/chrome/browser/download/download_target_determiner.cc
@@ -1192,10 +1192,12 @@ DownloadConfirmationReason DownloadTarge
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
     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.
76
Index: chromium-127.0.6533.88/chrome/browser/extensions/extension_management.cc
77
===================================================================
78 79
--- chromium-127.0.6533.88.orig/chrome/browser/extensions/extension_management.cc
+++ chromium-127.0.6533.88/chrome/browser/extensions/extension_management.cc
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
@@ -8,6 +8,7 @@
 #include <string>
 #include <utility>
 
+#include "base/command_line.h"
 #include "base/containers/contains.h"
 #include "base/feature_list.h"
 #include "base/functional/bind.h"
@@ -253,6 +254,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_->install_sources.has_value())
     return false;
102
Index: chromium-127.0.6533.88/chrome/browser/ungoogled_flag_choices.h
103
===================================================================
104 105
--- chromium-127.0.6533.88.orig/chrome/browser/ungoogled_flag_choices.h
+++ chromium-127.0.6533.88/chrome/browser/ungoogled_flag_choices.h
106 107 108 109 110 111 112 113 114 115 116 117 118 119
@@ -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_
120
Index: chromium-127.0.6533.88/chrome/browser/ungoogled_flag_entries.h
121
===================================================================
122 123
--- chromium-127.0.6533.88.orig/chrome/browser/ungoogled_flag_entries.h
+++ chromium-127.0.6533.88/chrome/browser/ungoogled_flag_entries.h
124 125 126 127 128 129 130 131 132
@@ -8,4 +8,8 @@
      "SetIpv6ProbeFalse",
      "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.",
      kOsAll, FEATURE_VALUE_TYPE(net::features::kSetIpv6ProbeFalse)},
+    {"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_