Bug 1721146 - Fix Missing ReferrerInfo on Blocked Downloads r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D121608
This commit is contained in:
Sebastian Streich
2021-08-04 12:41:16 +00:00
parent fd94ff77cb
commit dcf8a75022
7 changed files with 41 additions and 11 deletions

View File

@@ -16,7 +16,7 @@
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/Services.h"
#include "nsString.h"
#include "js/PropertyAndElement.h" // JS_Enumerate, JS_GetElement, JS_GetProperty, JS_GetPropertyById, JS_HasOwnProperty, JS_SetUCProperty
#include "js/PropertyAndElement.h" // JS_Enumerate, JS_GetElement, JS_GetProperty, JS_GetPropertyById, JS_HasOwnProperty, JS_SetUCProperty
#import "mozAccessible.h"

View File

@@ -121,6 +121,10 @@ async function shouldNotifyDownloadUI() {
if ((await IOUtils.stat(aDownload.target.path)).size != 0) {
throw new Error(`Download partFile was not cleaned up properly`);
}
// Assert that the Referrer is presnt
if (!aDownload.source.referrerInfo) {
throw new Error("The Blocked download is missing the ReferrerInfo");
}
res(aDownload);
list.removeView(view);

View File

@@ -270,7 +270,8 @@ DownloadLegacyTransfer.prototype = {
aTempFile,
aCancelable,
aIsPrivate,
aDownloadClassification
aDownloadClassification,
aReferrerInfo
) {
return this._nsITransferInitInternal(
aSource,
@@ -281,7 +282,8 @@ DownloadLegacyTransfer.prototype = {
aTempFile,
aCancelable,
aIsPrivate,
aDownloadClassification
aDownloadClassification,
aReferrerInfo
);
},
@@ -296,6 +298,7 @@ DownloadLegacyTransfer.prototype = {
aCancelable,
aIsPrivate,
aDownloadClassification,
aReferrerInfo,
aBrowsingContext,
aHandleInternally
) {
@@ -317,6 +320,7 @@ DownloadLegacyTransfer.prototype = {
aCancelable,
aIsPrivate,
aDownloadClassification,
aReferrerInfo,
userContextId,
browsingContextId,
aHandleInternally
@@ -333,6 +337,7 @@ DownloadLegacyTransfer.prototype = {
aCancelable,
isPrivate,
aDownloadClassification,
referrerInfo,
userContextId = 0,
browsingContextId = 0,
handleInternally = false
@@ -364,6 +369,7 @@ DownloadLegacyTransfer.prototype = {
isPrivate,
userContextId,
browsingContextId,
referrerInfo,
},
target: {
path: aTarget.QueryInterface(Ci.nsIFileURL).file.path,

View File

@@ -371,7 +371,8 @@ function promiseStartLegacyDownload(aSourceUrl, aOptions) {
null,
persist,
isPrivate,
Ci.nsITransfer.DOWNLOAD_ACCEPTABLE
Ci.nsITransfer.DOWNLOAD_ACCEPTABLE,
null
);
persist.progressListener = transfer;

View File

@@ -454,7 +454,8 @@ function internalPersist(persistArgs) {
null,
persist,
persistArgs.isPrivate,
Ci.nsITransfer.DOWNLOAD_ACCEPTABLE
Ci.nsITransfer.DOWNLOAD_ACCEPTABLE,
persistArgs.sourceReferrerInfo
);
persist.progressListener = new DownloadListener(window, tr);

View File

@@ -10,6 +10,7 @@ interface nsIURI;
interface nsICancelable;
interface nsIMIMEInfo;
interface nsIFile;
interface nsIReferrerInfo;
webidl BrowsingContext;
[scriptable, uuid(37ec75d3-97ad-4da8-afaa-eabe5b4afd73)]
@@ -55,8 +56,9 @@ interface nsITransfer : nsIWebProgressListener2 {
* If true, indicates that the transfer was initiated from
* a source that desires privacy.
*
* @param aDownloadClassification Indicates wheter the dowload is unwanted,
* @param aDownloadClassification Indicates wheter the download is unwanted,
* should be considered dangerous or insecure.
* @param aReferrerInfo The Referrer this download is started with
*/
void init(in nsIURI aSource,
in nsIURI aTarget,
@@ -66,7 +68,8 @@ interface nsITransfer : nsIWebProgressListener2 {
in nsIFile aTempFile,
in nsICancelable aCancelable,
in boolean aIsPrivate,
in long aDownloadClassification);
in long aDownloadClassification,
in nsIReferrerInfo aReferrerInfo);
/**
* Same as init, but allows for passing the browsingContext
@@ -87,6 +90,7 @@ interface nsITransfer : nsIWebProgressListener2 {
in nsICancelable aCancelable,
in boolean aIsPrivate,
in long aDownloadClassification,
in nsIReferrerInfo aReferrerInfo,
in BrowsingContext aBrowsingContext,
in boolean aHandleInternally);

View File

@@ -2339,16 +2339,23 @@ nsresult nsExternalAppHandler::CreateTransfer() {
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mRequest);
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mRequest);
nsCOMPtr<nsIReferrerInfo> referrerInfo = nullptr;
if (httpChannel) {
referrerInfo = httpChannel->GetReferrerInfo();
}
if (mBrowsingContext) {
rv = transfer->InitWithBrowsingContext(
mSourceUrl, target, u""_ns, mMimeInfo, mTimeDownloadStarted, mTempFile,
this, channel && NS_UsePrivateBrowsing(channel),
mDownloadClassification, mBrowsingContext, mHandleInternally);
mDownloadClassification, referrerInfo, mBrowsingContext,
mHandleInternally);
} else {
rv = transfer->Init(mSourceUrl, target, u""_ns, mMimeInfo,
mTimeDownloadStarted, mTempFile, this,
channel && NS_UsePrivateBrowsing(channel),
mDownloadClassification);
mDownloadClassification, referrerInfo);
}
NS_ENSURE_SUCCESS(rv, rv);
@@ -2424,16 +2431,23 @@ nsresult nsExternalAppHandler::CreateFailedTransfer() {
}
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mRequest);
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mRequest);
nsCOMPtr<nsIReferrerInfo> referrerInfo = nullptr;
if (httpChannel) {
referrerInfo = httpChannel->GetReferrerInfo();
}
if (mBrowsingContext) {
rv = transfer->InitWithBrowsingContext(
mSourceUrl, pseudoTarget, u""_ns, mMimeInfo, mTimeDownloadStarted,
mTempFile, this, channel && NS_UsePrivateBrowsing(channel),
mDownloadClassification, mBrowsingContext, mHandleInternally);
mDownloadClassification, referrerInfo, mBrowsingContext,
mHandleInternally);
} else {
rv = transfer->Init(mSourceUrl, pseudoTarget, u""_ns, mMimeInfo,
mTimeDownloadStarted, mTempFile, this,
channel && NS_UsePrivateBrowsing(channel),
mDownloadClassification);
mDownloadClassification, referrerInfo);
}
NS_ENSURE_SUCCESS(rv, rv);