commit b5d0a61cd5df Author: Amy Chung Date: Sun Sep 24 00:38:32 2017 +0800 Bug 1360603 - Mark the save channel as throttleable. r=baku, a=sledru --HG-- extra : source : d409c2ac7d88b7193e8369aa3359a9368e1135b3 --- dom/webbrowserpersist/nsWebBrowserPersist.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git dom/webbrowserpersist/nsWebBrowserPersist.cpp dom/webbrowserpersist/nsWebBrowserPersist.cpp index a9b37ed281ca..a5971216d8b4 100644 --- dom/webbrowserpersist/nsWebBrowserPersist.cpp +++ dom/webbrowserpersist/nsWebBrowserPersist.cpp @@ -13,6 +13,7 @@ #include "nsAutoPtr.h" #include "nsNetCID.h" #include "nsNetUtil.h" +#include "nsIClassOfService.h" #include "nsIInterfaceRequestorUtils.h" #include "nsILoadContext.h" #include "nsIPrivateBrowsingChannel.h" @@ -1497,6 +1498,12 @@ nsresult nsWebBrowserPersist::SaveChannelInternal( return StartUpload(bufferedInputStream, aFile, contentType); } + // Mark save channel as throttleable. + nsCOMPtr cos(do_QueryInterface(aChannel)); + if (cos) { + cos->AddClassFlags(nsIClassOfService::Throttleable); + } + // Read from the input channel nsresult rv = NS_MaybeOpenChannelUsingAsyncOpen2(aChannel, this); if (rv == NS_ERROR_NO_CONTENT) commit 1e11071bc4f9 Author: Amy Chung Date: Sun Sep 24 00:56:04 2017 +0800 Bug 1360603 - Confirm the Throttleable flag on browser_saveImageURL.js. r=baku, a=sledru --HG-- extra : source : 6d7610f4d26d76878b83b1f2489a96116c2bdf15 --- toolkit/content/contentAreaUtils.js | 4 ++++ toolkit/content/tests/browser/browser_saveImageURL.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git toolkit/content/contentAreaUtils.js toolkit/content/contentAreaUtils.js index fba70c91c8a3..1492b4c1654c 100644 --- toolkit/content/contentAreaUtils.js +++ toolkit/content/contentAreaUtils.js @@ -1264,6 +1264,10 @@ function openURL(aURL) { loadUsingSystemPrincipal: true }); + if (channel) { + channel.channelIsForDownload = true; + } + var uriLoader = Components.classes["@mozilla.org/uriloader;1"] .getService(Components.interfaces.nsIURILoader); uriLoader.openURI(channel, diff --git toolkit/content/tests/browser/browser_saveImageURL.js toolkit/content/tests/browser/browser_saveImageURL.js index fe10482f35dc..0d9c872921c2 100644 --- toolkit/content/tests/browser/browser_saveImageURL.js +++ toolkit/content/tests/browser/browser_saveImageURL.js @@ -37,6 +37,15 @@ add_task(async function preferred_API() { }); saveImageURL(url, "image.jpg", null, true, false, null, null, null, null, false); + let channel = content.document.docShell.currentDocumentChannel; + if (channel) { + ok(true, channel.QueryInterface(Ci.nsIHttpChannelInternal) + .channelIsForDownload); + + // Throttleable is the only class flag assigned to downloads. + ok(channel.QueryInterface(Ci.nsIClassOfService).classFlags, + Ci.nsIClassOfService.Throttleable); + } await waitForFilePicker(); }); }); @@ -64,6 +73,15 @@ add_task(async function deprecated_API() { // pass the XUL document instead to test this interface. let doc = document; + let channel = content.document.docShell.currentDocumentChannel; + if (channel) { + ok(true, channel.QueryInterface(Ci.nsIHttpChannelInternal) + .channelIsForDownload); + + // Throttleable is the only class flag assigned to downloads. + ok(channel.QueryInterface(Ci.nsIClassOfService).classFlags, + Ci.nsIClassOfService.Throttleable); + } saveImageURL(url, "image.jpg", null, true, false, null, doc, null, null); await waitForFilePicker(); });