Bug 1721146 - Fix Missing ReferrerInfo on Blocked Downloads r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D121608
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
#include "mozilla/dom/ToJSValue.h"
|
#include "mozilla/dom/ToJSValue.h"
|
||||||
#include "mozilla/Services.h"
|
#include "mozilla/Services.h"
|
||||||
#include "nsString.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"
|
#import "mozAccessible.h"
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,10 @@ async function shouldNotifyDownloadUI() {
|
|||||||
if ((await IOUtils.stat(aDownload.target.path)).size != 0) {
|
if ((await IOUtils.stat(aDownload.target.path)).size != 0) {
|
||||||
throw new Error(`Download partFile was not cleaned up properly`);
|
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);
|
res(aDownload);
|
||||||
list.removeView(view);
|
list.removeView(view);
|
||||||
|
|||||||
@@ -270,7 +270,8 @@ DownloadLegacyTransfer.prototype = {
|
|||||||
aTempFile,
|
aTempFile,
|
||||||
aCancelable,
|
aCancelable,
|
||||||
aIsPrivate,
|
aIsPrivate,
|
||||||
aDownloadClassification
|
aDownloadClassification,
|
||||||
|
aReferrerInfo
|
||||||
) {
|
) {
|
||||||
return this._nsITransferInitInternal(
|
return this._nsITransferInitInternal(
|
||||||
aSource,
|
aSource,
|
||||||
@@ -281,7 +282,8 @@ DownloadLegacyTransfer.prototype = {
|
|||||||
aTempFile,
|
aTempFile,
|
||||||
aCancelable,
|
aCancelable,
|
||||||
aIsPrivate,
|
aIsPrivate,
|
||||||
aDownloadClassification
|
aDownloadClassification,
|
||||||
|
aReferrerInfo
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -296,6 +298,7 @@ DownloadLegacyTransfer.prototype = {
|
|||||||
aCancelable,
|
aCancelable,
|
||||||
aIsPrivate,
|
aIsPrivate,
|
||||||
aDownloadClassification,
|
aDownloadClassification,
|
||||||
|
aReferrerInfo,
|
||||||
aBrowsingContext,
|
aBrowsingContext,
|
||||||
aHandleInternally
|
aHandleInternally
|
||||||
) {
|
) {
|
||||||
@@ -317,6 +320,7 @@ DownloadLegacyTransfer.prototype = {
|
|||||||
aCancelable,
|
aCancelable,
|
||||||
aIsPrivate,
|
aIsPrivate,
|
||||||
aDownloadClassification,
|
aDownloadClassification,
|
||||||
|
aReferrerInfo,
|
||||||
userContextId,
|
userContextId,
|
||||||
browsingContextId,
|
browsingContextId,
|
||||||
aHandleInternally
|
aHandleInternally
|
||||||
@@ -333,6 +337,7 @@ DownloadLegacyTransfer.prototype = {
|
|||||||
aCancelable,
|
aCancelable,
|
||||||
isPrivate,
|
isPrivate,
|
||||||
aDownloadClassification,
|
aDownloadClassification,
|
||||||
|
referrerInfo,
|
||||||
userContextId = 0,
|
userContextId = 0,
|
||||||
browsingContextId = 0,
|
browsingContextId = 0,
|
||||||
handleInternally = false
|
handleInternally = false
|
||||||
@@ -364,6 +369,7 @@ DownloadLegacyTransfer.prototype = {
|
|||||||
isPrivate,
|
isPrivate,
|
||||||
userContextId,
|
userContextId,
|
||||||
browsingContextId,
|
browsingContextId,
|
||||||
|
referrerInfo,
|
||||||
},
|
},
|
||||||
target: {
|
target: {
|
||||||
path: aTarget.QueryInterface(Ci.nsIFileURL).file.path,
|
path: aTarget.QueryInterface(Ci.nsIFileURL).file.path,
|
||||||
|
|||||||
@@ -371,7 +371,8 @@ function promiseStartLegacyDownload(aSourceUrl, aOptions) {
|
|||||||
null,
|
null,
|
||||||
persist,
|
persist,
|
||||||
isPrivate,
|
isPrivate,
|
||||||
Ci.nsITransfer.DOWNLOAD_ACCEPTABLE
|
Ci.nsITransfer.DOWNLOAD_ACCEPTABLE,
|
||||||
|
null
|
||||||
);
|
);
|
||||||
persist.progressListener = transfer;
|
persist.progressListener = transfer;
|
||||||
|
|
||||||
|
|||||||
@@ -454,7 +454,8 @@ function internalPersist(persistArgs) {
|
|||||||
null,
|
null,
|
||||||
persist,
|
persist,
|
||||||
persistArgs.isPrivate,
|
persistArgs.isPrivate,
|
||||||
Ci.nsITransfer.DOWNLOAD_ACCEPTABLE
|
Ci.nsITransfer.DOWNLOAD_ACCEPTABLE,
|
||||||
|
persistArgs.sourceReferrerInfo
|
||||||
);
|
);
|
||||||
persist.progressListener = new DownloadListener(window, tr);
|
persist.progressListener = new DownloadListener(window, tr);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ interface nsIURI;
|
|||||||
interface nsICancelable;
|
interface nsICancelable;
|
||||||
interface nsIMIMEInfo;
|
interface nsIMIMEInfo;
|
||||||
interface nsIFile;
|
interface nsIFile;
|
||||||
|
interface nsIReferrerInfo;
|
||||||
webidl BrowsingContext;
|
webidl BrowsingContext;
|
||||||
|
|
||||||
[scriptable, uuid(37ec75d3-97ad-4da8-afaa-eabe5b4afd73)]
|
[scriptable, uuid(37ec75d3-97ad-4da8-afaa-eabe5b4afd73)]
|
||||||
@@ -55,8 +56,9 @@ interface nsITransfer : nsIWebProgressListener2 {
|
|||||||
* If true, indicates that the transfer was initiated from
|
* If true, indicates that the transfer was initiated from
|
||||||
* a source that desires privacy.
|
* 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.
|
* should be considered dangerous or insecure.
|
||||||
|
* @param aReferrerInfo The Referrer this download is started with
|
||||||
*/
|
*/
|
||||||
void init(in nsIURI aSource,
|
void init(in nsIURI aSource,
|
||||||
in nsIURI aTarget,
|
in nsIURI aTarget,
|
||||||
@@ -66,7 +68,8 @@ interface nsITransfer : nsIWebProgressListener2 {
|
|||||||
in nsIFile aTempFile,
|
in nsIFile aTempFile,
|
||||||
in nsICancelable aCancelable,
|
in nsICancelable aCancelable,
|
||||||
in boolean aIsPrivate,
|
in boolean aIsPrivate,
|
||||||
in long aDownloadClassification);
|
in long aDownloadClassification,
|
||||||
|
in nsIReferrerInfo aReferrerInfo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as init, but allows for passing the browsingContext
|
* Same as init, but allows for passing the browsingContext
|
||||||
@@ -87,6 +90,7 @@ interface nsITransfer : nsIWebProgressListener2 {
|
|||||||
in nsICancelable aCancelable,
|
in nsICancelable aCancelable,
|
||||||
in boolean aIsPrivate,
|
in boolean aIsPrivate,
|
||||||
in long aDownloadClassification,
|
in long aDownloadClassification,
|
||||||
|
in nsIReferrerInfo aReferrerInfo,
|
||||||
in BrowsingContext aBrowsingContext,
|
in BrowsingContext aBrowsingContext,
|
||||||
in boolean aHandleInternally);
|
in boolean aHandleInternally);
|
||||||
|
|
||||||
|
|||||||
@@ -2339,16 +2339,23 @@ nsresult nsExternalAppHandler::CreateTransfer() {
|
|||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mRequest);
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mRequest);
|
||||||
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mRequest);
|
||||||
|
nsCOMPtr<nsIReferrerInfo> referrerInfo = nullptr;
|
||||||
|
if (httpChannel) {
|
||||||
|
referrerInfo = httpChannel->GetReferrerInfo();
|
||||||
|
}
|
||||||
|
|
||||||
if (mBrowsingContext) {
|
if (mBrowsingContext) {
|
||||||
rv = transfer->InitWithBrowsingContext(
|
rv = transfer->InitWithBrowsingContext(
|
||||||
mSourceUrl, target, u""_ns, mMimeInfo, mTimeDownloadStarted, mTempFile,
|
mSourceUrl, target, u""_ns, mMimeInfo, mTimeDownloadStarted, mTempFile,
|
||||||
this, channel && NS_UsePrivateBrowsing(channel),
|
this, channel && NS_UsePrivateBrowsing(channel),
|
||||||
mDownloadClassification, mBrowsingContext, mHandleInternally);
|
mDownloadClassification, referrerInfo, mBrowsingContext,
|
||||||
|
mHandleInternally);
|
||||||
} else {
|
} else {
|
||||||
rv = transfer->Init(mSourceUrl, target, u""_ns, mMimeInfo,
|
rv = transfer->Init(mSourceUrl, target, u""_ns, mMimeInfo,
|
||||||
mTimeDownloadStarted, mTempFile, this,
|
mTimeDownloadStarted, mTempFile, this,
|
||||||
channel && NS_UsePrivateBrowsing(channel),
|
channel && NS_UsePrivateBrowsing(channel),
|
||||||
mDownloadClassification);
|
mDownloadClassification, referrerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
@@ -2424,16 +2431,23 @@ nsresult nsExternalAppHandler::CreateFailedTransfer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mRequest);
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(mRequest);
|
||||||
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mRequest);
|
||||||
|
nsCOMPtr<nsIReferrerInfo> referrerInfo = nullptr;
|
||||||
|
if (httpChannel) {
|
||||||
|
referrerInfo = httpChannel->GetReferrerInfo();
|
||||||
|
}
|
||||||
|
|
||||||
if (mBrowsingContext) {
|
if (mBrowsingContext) {
|
||||||
rv = transfer->InitWithBrowsingContext(
|
rv = transfer->InitWithBrowsingContext(
|
||||||
mSourceUrl, pseudoTarget, u""_ns, mMimeInfo, mTimeDownloadStarted,
|
mSourceUrl, pseudoTarget, u""_ns, mMimeInfo, mTimeDownloadStarted,
|
||||||
mTempFile, this, channel && NS_UsePrivateBrowsing(channel),
|
mTempFile, this, channel && NS_UsePrivateBrowsing(channel),
|
||||||
mDownloadClassification, mBrowsingContext, mHandleInternally);
|
mDownloadClassification, referrerInfo, mBrowsingContext,
|
||||||
|
mHandleInternally);
|
||||||
} else {
|
} else {
|
||||||
rv = transfer->Init(mSourceUrl, pseudoTarget, u""_ns, mMimeInfo,
|
rv = transfer->Init(mSourceUrl, pseudoTarget, u""_ns, mMimeInfo,
|
||||||
mTimeDownloadStarted, mTempFile, this,
|
mTimeDownloadStarted, mTempFile, this,
|
||||||
channel && NS_UsePrivateBrowsing(channel),
|
channel && NS_UsePrivateBrowsing(channel),
|
||||||
mDownloadClassification);
|
mDownloadClassification, referrerInfo);
|
||||||
}
|
}
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user