  }
  
 +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";
++    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)
+@@ -134,7 +143,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>

 // 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_item_model.cc
+++ b/chrome/browser/download/download_item_model.cc
@@ -540,16 +540,16 @@ bool DownloadItemModel::IsCommandEnabled
       return download_->CanShowInFolder();
     case DownloadCommands::OPEN_WHEN_COMPLETE:
       return download_->CanOpenDownload() &&
-             !download_crx_util::IsExtensionDownload(*download_);
+             !IsExtensionDownload();
     case DownloadCommands::PLATFORM_OPEN:
       return download_->CanOpenDownload() &&
-             !download_crx_util::IsExtensionDownload(*download_);
+             !IsExtensionDownload();
     case DownloadCommands::ALWAYS_OPEN_TYPE:
       // For temporary downloads, the target filename might be a temporary
       // filename. Don't base an "Always open" decision based on it. Also
       // exclude extensions.
       return download_->CanOpenDownload() &&
-             !download_crx_util::IsExtensionDownload(*download_);
+             !IsExtensionDownload();
     case DownloadCommands::PAUSE:
       return !download_->IsSavePackageDownload() &&
              DownloadUIModel::IsCommandEnabled(download_commands, command);
@@ -576,7 +576,7 @@ bool DownloadItemModel::IsCommandChecked
   switch (command) {
     case DownloadCommands::OPEN_WHEN_COMPLETE:
       return download_->GetOpenWhenComplete() ||
-             download_crx_util::IsExtensionDownload(*download_);
+             IsExtensionDownload();
     case DownloadCommands::ALWAYS_OPEN_TYPE:
 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
       if (download_commands->CanOpenPdfInSystemViewer()) {
@@ -746,7 +746,13 @@ std::string DownloadItemModel::GetMimeTy
 }
 
 bool DownloadItemModel::IsExtensionDownload() const {
-  return download_crx_util::IsExtensionDownload(*download_);
+  // Derivation of boolean statement:
+  // In original code, "IsExtensionDownload" always meant the extension
+  // was installed.
+  // In ungoogled code, "IsExtensionDownload && !ShouldDownloadAsRegularFile"
+  // is true iff this extension is to be installed.
+  return download_crx_util::IsExtensionDownload(*download_) &&
+      !download_crx_util::ShouldDownloadAsRegularFile();
 }
 
 #if BUILDFLAG(FULL_SAFE_BROWSING)
--- a/chrome/browser/download/download_target_determiner.cc
+++ b/chrome/browser/download/download_target_determiner.cc
@@ -1018,10 +1018,12 @@ DownloadConfirmationReason DownloadTarge

   // No allowed install sites specified, disallow by default.
   if (!global_settings_->has_restricted_install_sources)
     return false;
