From 7003e8611729dfc770aa09af52964eaa8280bb38 Mon Sep 17 00:00:00 2001 From: criss Date: Mon, 17 Jan 2022 15:53:10 +0200 Subject: [PATCH] Backed out 2 changesets (bug 1745650) for causing build bustages on browser_download_slow. CLOSED TREE Backed out changeset 32bac3160aa5 (bug 1745650) Backed out changeset 336d3cfecad2 (bug 1745650) --- dom/security/nsContentSecurityManager.cpp | 4 - dom/security/nsHTTPSOnlyUtils.cpp | 7 +- dom/security/test/https-first/browser.ini | 4 - .../test/https-first/browser_slow_download.js | 162 ------------------ .../test/https-first/file_slow_download.html | 14 -- .../test/https-first/file_slow_download.sjs | 26 --- netwerk/base/nsILoadInfo.idl | 18 +- .../exthandler/nsExternalHelperAppService.cpp | 13 -- 8 files changed, 7 insertions(+), 241 deletions(-) delete mode 100644 dom/security/test/https-first/browser_slow_download.js delete mode 100644 dom/security/test/https-first/file_slow_download.html delete mode 100644 dom/security/test/https-first/file_slow_download.sjs diff --git a/dom/security/nsContentSecurityManager.cpp b/dom/security/nsContentSecurityManager.cpp index 25468f2d2a0d..75ad2b0a1ef2 100644 --- a/dom/security/nsContentSecurityManager.cpp +++ b/dom/security/nsContentSecurityManager.cpp @@ -680,10 +680,6 @@ static void LogHTTPSOnlyInfo(nsILoadInfo* aLoadInfo) { MOZ_LOG(sCSMLog, LogLevel::Verbose, (" - HTTPS_ONLY_TOP_LEVEL_LOAD_IN_PROGRESS")); } - if (httpsOnlyStatus & nsILoadInfo::HTTPS_ONLY_DOWNLOAD_IN_PROGRESS) { - MOZ_LOG(sCSMLog, LogLevel::Verbose, - (" - HTTPS_ONLY_DOWNLOAD_IN_PROGRESS")); - } if (httpsOnlyStatus & nsILoadInfo::HTTPS_ONLY_DO_NOT_LOG_TO_CONSOLE) { MOZ_LOG(sCSMLog, LogLevel::Verbose, (" - HTTPS_ONLY_DO_NOT_LOG_TO_CONSOLE")); diff --git a/dom/security/nsHTTPSOnlyUtils.cpp b/dom/security/nsHTTPSOnlyUtils.cpp index 45fad0b1fe03..21ee9c356806 100644 --- a/dom/security/nsHTTPSOnlyUtils.cpp +++ b/dom/security/nsHTTPSOnlyUtils.cpp @@ -986,11 +986,8 @@ TestHTTPAnswerRunnable::Notify(nsITimer* aTimer) { nsCOMPtr origChannel = mDocumentLoadListener->GetChannel(); nsCOMPtr origLoadInfo = origChannel->LoadInfo(); uint32_t origHttpsOnlyStatus = origLoadInfo->GetHttpsOnlyStatus(); - uint32_t topLevelLoadInProgress = - origHttpsOnlyStatus & nsILoadInfo::HTTPS_ONLY_TOP_LEVEL_LOAD_IN_PROGRESS; - uint32_t downloadInProgress = - origHttpsOnlyStatus & nsILoadInfo::HTTPS_ONLY_DOWNLOAD_IN_PROGRESS; - if (topLevelLoadInProgress || downloadInProgress) { + if ((origHttpsOnlyStatus & + nsILoadInfo::HTTPS_ONLY_TOP_LEVEL_LOAD_IN_PROGRESS)) { return NS_OK; } diff --git a/dom/security/test/https-first/browser.ini b/dom/security/test/https-first/browser.ini index eff99e54a882..0bef183d48ff 100644 --- a/dom/security/test/https-first/browser.ini +++ b/dom/security/test/https-first/browser.ini @@ -21,7 +21,3 @@ skip-if = win10_2004 && debug # Bug 1723573 support-files = download_page.html download_server.sjs -[browser_slow_download.js] -support-files = - browser_download_slow.html - browser_download_slow.sjs diff --git a/dom/security/test/https-first/browser_slow_download.js b/dom/security/test/https-first/browser_slow_download.js deleted file mode 100644 index 8766e12f3460..000000000000 --- a/dom/security/test/https-first/browser_slow_download.js +++ /dev/null @@ -1,162 +0,0 @@ -"use strict"; - -XPCOMUtils.defineLazyModuleGetters(this, { - BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm", -}); -// Create a uri for an https site -const testPath = getRootDirectory(gTestPath).replace( - "chrome://mochitests/content", - "https://example.com" -); -const TEST_URI = testPath + "file_slow_download.html"; -const EXPECTED_DOWNLOAD_URL = - "example.com/browser/dom/security/test/https-first/file_slow_download.sjs"; - -// Since the server send the complete download file after 3 seconds we need an longer timeout -requestLongerTimeout(4); - -function promisePanelOpened() { - if (DownloadsPanel.panel && DownloadsPanel.panel.state == "open") { - return Promise.resolve(); - } - return BrowserTestUtils.waitForEvent(DownloadsPanel.panel, "popupshown"); -} - -/** - * Waits for a download to finish, in case it has not finished already. - * - * @param aDownload - * The Download object to wait upon. - * - * @return {Promise} - * @resolves When the download has finished successfully. - * @rejects JavaScript exception if the download failed. - */ -function promiseDownloadStopped(aDownload) { - if (!aDownload.stopped) { - // The download is in progress, wait for the current attempt to finish and - // report any errors that may occur. - return aDownload.start(); - } - - if (aDownload.succeeded) { - return Promise.resolve(); - } - - // The download failed or was canceled. - return Promise.reject(aDownload.error || new Error("Download canceled.")); -} - -// Verifys that no background request was send -let requestCounter = 0; -function examiner() { - SpecialPowers.addObserver(this, "specialpowers-http-notify-request"); -} - -examiner.prototype = { - observe(subject, topic, data) { - if (topic !== "specialpowers-http-notify-request") { - return; - } - // On Android we have other requests appear here as well. Let's make - // sure we only evaluate requests triggered by the test. - if ( - !data.startsWith("http://example.com") && - !data.startsWith("https://example.com") - ) { - return; - } - ++requestCounter; - if (requestCounter == 1) { - is(data, TEST_URI, "Download start page is https"); - return; - } - if (requestCounter == 2) { - // The specialpowers-http-notify-request fires before the internal redirect( /upgrade) to - // https happens. - is( - data, - "http://" + EXPECTED_DOWNLOAD_URL, - "First download request is http (internal)" - ); - return; - } - if (requestCounter == 3) { - is( - data, - "https://" + EXPECTED_DOWNLOAD_URL, - "Download got upgraded to https" - ); - return; - } - ok(false, "we should never get here, but just in case"); - }, - remove() { - SpecialPowers.removeObserver(this, "specialpowers-http-notify-request"); - }, -}; - -// Test description: -// 1. Open https://example.com -// 2. Start download - location of download is http -// 3. https-first upgrades to https -// 4. Server send first part of download and after 3 seconds the rest -// 5. Complete download of text file -add_task(async function test_slow_download() { - await SpecialPowers.pushPrefEnv({ - set: [ - ["dom.security.https_first", true], - // ensure that download panel gets opened - ["browser.download.improvements_to_download_panel", true], - ], - }); - - // remove all previous downloads - let downloadsList = await Downloads.getList(Downloads.PUBLIC); - await downloadsList.removeFinished(); - - // add observer to ensure that the background request gets canceled for the upgraded Download - this.examiner = new examiner(); - - let downloadsPanelPromise = promisePanelOpened(); - let downloadsPromise = Downloads.getList(Downloads.PUBLIC); - BrowserTestUtils.loadURI(gBrowser, TEST_URI); - // wait for downloadsPanel to open before continuing with test - await downloadsPanelPromise; - let downloadList = await downloadsPromise; - is(DownloadsPanel.isPanelShowing, true, "DownloadsPanel should be open."); - is(downloadList._downloads.length, 1, "File should be downloaded."); - let [download] = downloadList._downloads; - // wait for download to finish (with success or error) - await promiseDownloadStopped(download); - is(download.contentType, "text/plain", "File contentType should be correct."); - // ensure https-first did upgrade the scheme. - is( - download.source.url, - "https://" + EXPECTED_DOWNLOAD_URL, - "Scheme should be https." - ); - // ensure that no background request was send - is( - requestCounter, - 3, - "three requests total (download page, download http, download https/ upgraded)" - ); - // ensure that downloaded is complete - is(download.target.size, 25, "Download size is correct"); - //clean up - this.examiner.remove(); - info("cleaning up downloads"); - try { - if (Services.appinfo.OS === "WINNT") { - // We need to make the file writable to delete it on Windows. - await IOUtils.setPermissions(download.target.path, 0o600); - } - await IOUtils.remove(download.target.path); - } catch (error) { - info("The file " + download.target.path + " is not removed, " + error); - } - - await downloadList.remove(download); - await download.finalize(); -}); diff --git a/dom/security/test/https-first/file_slow_download.html b/dom/security/test/https-first/file_slow_download.html deleted file mode 100644 index 084977607d72..000000000000 --- a/dom/security/test/https-first/file_slow_download.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - Test slow download from an http site that gets upgraded to https - - - download by attribute - - - diff --git a/dom/security/test/https-first/file_slow_download.sjs b/dom/security/test/https-first/file_slow_download.sjs deleted file mode 100644 index 6e4f109068f5..000000000000 --- a/dom/security/test/https-first/file_slow_download.sjs +++ /dev/null @@ -1,26 +0,0 @@ -"use strict"; -let timer; - -// Send a part of the file then wait for 3 second before sending the rest. -// If download isn't exempt from background timer of https-only/-first then the download -// gets cancelled before it completed. -const DELAY_MS = 3500; -function handleRequest(request, response) { - response.processAsync(); - timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - response.setHeader("Cache-Control", "no-cache", false); - response.setHeader( - "Content-Disposition", - "attachment; filename=large-dummy-file.txt" - ); - response.setHeader("Content-Type", "text/plain"); - response.write("Begin the file"); - timer.init( - () => { - response.write("End of file"); - response.finish(); - }, - DELAY_MS, - Ci.nsITimer.TYPE_ONE_SHOT - ); -} diff --git a/netwerk/base/nsILoadInfo.idl b/netwerk/base/nsILoadInfo.idl index 0a7d0c66fb3e..b5fdbade9427 100644 --- a/netwerk/base/nsILoadInfo.idl +++ b/netwerk/base/nsILoadInfo.idl @@ -464,25 +464,17 @@ interface nsILoadInfo : nsISupports */ const unsigned long HTTPS_ONLY_TOP_LEVEL_LOAD_IN_PROGRESS = (1 << 4); - /** - * This flag can only ever be set on downloads. It indicates - * that the download https connection succeeded. This flag is mostly - * used to counter time-outs which allows to cancel the channel - * if the https load has not started. + /** + * This flag indicates that the request should not be logged to the + * console. */ - const unsigned long HTTPS_ONLY_DOWNLOAD_IN_PROGRESS = (1 << 5); + const unsigned long HTTPS_ONLY_DO_NOT_LOG_TO_CONSOLE = (1 << 5); /** * This flag indicates that the request should not be logged to the * console. */ - const unsigned long HTTPS_ONLY_DO_NOT_LOG_TO_CONSOLE = (1 << 6); - - /** - * This flag indicates that the request should not be logged to the - * console. - */ - const unsigned long HTTPS_ONLY_UPGRADED_HTTPS_FIRST = (1 << 7); + const unsigned long HTTPS_ONLY_UPGRADED_HTTPS_FIRST = (1 << 6); /** * Upgrade state of HTTPS-Only Mode. The flag HTTPS_ONLY_EXEMPT can get diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index a20f202f2318..d52e357dcc06 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -96,8 +96,6 @@ #include "nsPIDOMWindow.h" #include "ExternalHelperAppChild.h" -#include "mozilla/dom/nsHTTPSOnlyUtils.h" - #ifdef XP_WIN # include "nsWindowsHelpers.h" #endif @@ -1743,17 +1741,6 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) { // Now get the URI if (aChannel) { aChannel->GetURI(getter_AddRefs(mSourceUrl)); - // HTTPS-Only/HTTPS-FirstMode tries to upgrade connections to https. Once - // the download is in progress we set that flag so that timeout counter - // measures do not kick in. - nsCOMPtr loadInfo = aChannel->LoadInfo(); - bool isPrivateWin = loadInfo->GetOriginAttributes().mPrivateBrowsingId > 0; - if (nsHTTPSOnlyUtils::IsHttpsOnlyModeEnabled(isPrivateWin) || - nsHTTPSOnlyUtils::IsHttpsFirstModeEnabled(isPrivateWin)) { - uint32_t httpsOnlyStatus = loadInfo->GetHttpsOnlyStatus(); - httpsOnlyStatus |= nsILoadInfo::HTTPS_ONLY_DOWNLOAD_IN_PROGRESS; - loadInfo->SetHttpsOnlyStatus(httpsOnlyStatus); - } } if (!mForceSave && StaticPrefs::browser_download_enable_spam_prevention() &&