Bug 1348062 - Mark channels used for downloads as throttable, r=nick+paolo

MozReview-Commit-ID: 9cg4PwrXtNa

--HG--
extra : rebase_source : 2ff2d771a6ccb2a3e11c2d65e0a64ebbaa443206
This commit is contained in:
Honza Bambas 2017-04-16 14:53:30 +01:00
parent 589e3693ed
commit 203c640be7
4 changed files with 21 additions and 1 deletions

View File

@ -6397,6 +6397,18 @@ nsHttpChannel::ForceIntercepted(uint64_t aInterceptionID)
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::SetChannelIsForDownload(bool aChannelIsForDownload)
{
if (aChannelIsForDownload) {
AddClassFlags(nsIClassOfService::Throttleable);
} else {
ClearClassFlags(nsIClassOfService::Throttleable);
}
return HttpBaseChannel::SetChannelIsForDownload(aChannelIsForDownload);
}
//-----------------------------------------------------------------------------
// nsHttpChannel::nsISupportsPriority
//-----------------------------------------------------------------------------

View File

@ -157,6 +157,7 @@ public:
// nsIHttpChannelInternal
NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey) override;
NS_IMETHOD ForceIntercepted(uint64_t aInterceptionID) override;
NS_IMETHOD SetChannelIsForDownload(bool aChannelIsForDownload) override;
// nsISupportsPriority
NS_IMETHOD SetPriority(int32_t value) override;
// nsIClassOfService

View File

@ -1976,6 +1976,12 @@ this.DownloadCopySaver.prototype = {
channel.referrer = NetUtil.newURI(download.source.referrer);
}
// This makes the channel be corretly throttled during page loads
// and also prevents its caching.
if (channel instanceof Ci.nsIHttpChannelInternal) {
channel.channelIsForDownload = true;
}
// If we have data that we can use to resume the download from where
// it stopped, try to use it.
let resumeAttempted = false;

View File

@ -1677,7 +1677,8 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
return NS_OK;
}
// Inform channel it is open on behalf of a download to prevent caching.
// Inform channel it is open on behalf of a download to throttle it during
// page loads and prevent its caching.
nsCOMPtr<nsIHttpChannelInternal> httpInternal = do_QueryInterface(aChannel);
if (httpInternal) {
rv = httpInternal->SetChannelIsForDownload(true);