зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1576347 - Correct referrerInfo when saving media and add a test of "Go To Download Page" button r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D43749 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
9e00f531f2
Коммит
c175f3d626
|
@ -623,11 +623,19 @@ class ContextMenuChild extends JSWindowActorChild {
|
|||
let referrerInfo = Cc["@mozilla.org/referrer-info;1"].createInstance(
|
||||
Ci.nsIReferrerInfo
|
||||
);
|
||||
referrerInfo.initWithNode(
|
||||
context.onLink ? context.link : aEvent.composedTarget
|
||||
);
|
||||
referrerInfo.initWithNode(aEvent.composedTarget);
|
||||
referrerInfo = E10SUtils.serializeReferrerInfo(referrerInfo);
|
||||
|
||||
// In the case "onLink" we may have to send link referrerInfo to use in
|
||||
// _openLinkInParameters
|
||||
let linkReferrerInfo = null;
|
||||
if (context.onLink) {
|
||||
linkReferrerInfo = Cc["@mozilla.org/referrer-info;1"].createInstance(
|
||||
Ci.nsIReferrerInfo
|
||||
);
|
||||
linkReferrerInfo.initWithNode(context.link);
|
||||
}
|
||||
|
||||
let target = context.target;
|
||||
if (target) {
|
||||
this._cleanContext();
|
||||
|
@ -681,17 +689,8 @@ class ContextMenuChild extends JSWindowActorChild {
|
|||
);
|
||||
}
|
||||
|
||||
// In the case "onLink" we may have to send target referrerInfo. This object
|
||||
// may be used to in saveMedia function.
|
||||
if (context.onLink) {
|
||||
let targetReferrerInfo = Cc[
|
||||
"@mozilla.org/referrer-info;1"
|
||||
].createInstance(Ci.nsIReferrerInfo);
|
||||
|
||||
targetReferrerInfo.initWithNode(aEvent.composedTarget);
|
||||
data.targetReferrerInfo = E10SUtils.serializeReferrerInfo(
|
||||
targetReferrerInfo
|
||||
);
|
||||
if (linkReferrerInfo) {
|
||||
data.linkReferrerInfo = E10SUtils.serializeReferrerInfo(linkReferrerInfo);
|
||||
}
|
||||
|
||||
if (Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT) {
|
||||
|
|
|
@ -43,7 +43,7 @@ function openContextMenu(aMessage, aBrowser, aActor) {
|
|||
let actor = aActor;
|
||||
let spellInfo = data.spellInfo;
|
||||
let frameReferrerInfo = data.frameReferrerInfo;
|
||||
let targetReferrerInfo = data.targetReferrerInfo;
|
||||
let linkReferrerInfo = data.linkReferrerInfo;
|
||||
let principal = data.principal;
|
||||
let storagePrincipal = data.storagePrincipal;
|
||||
|
||||
|
@ -61,8 +61,8 @@ function openContextMenu(aMessage, aBrowser, aActor) {
|
|||
frameReferrerInfo = E10SUtils.deserializeReferrerInfo(frameReferrerInfo);
|
||||
}
|
||||
|
||||
if (targetReferrerInfo) {
|
||||
targetReferrerInfo = E10SUtils.deserializeReferrerInfo(targetReferrerInfo);
|
||||
if (linkReferrerInfo) {
|
||||
linkReferrerInfo = E10SUtils.deserializeReferrerInfo(linkReferrerInfo);
|
||||
}
|
||||
|
||||
// For now, JS Window Actors don't deserialize Principals automatically, so we
|
||||
|
@ -100,7 +100,7 @@ function openContextMenu(aMessage, aBrowser, aActor) {
|
|||
charSet: data.charSet,
|
||||
referrerInfo: E10SUtils.deserializeReferrerInfo(data.referrerInfo),
|
||||
frameReferrerInfo,
|
||||
targetReferrerInfo,
|
||||
linkReferrerInfo,
|
||||
contentType: data.contentType,
|
||||
contentDisposition: data.contentDisposition,
|
||||
frameOuterWindowID: data.frameOuterWindowID,
|
||||
|
@ -1095,7 +1095,9 @@ nsContextMenu.prototype = {
|
|||
params[p] = extra[p];
|
||||
}
|
||||
|
||||
let referrerInfo = gContextMenuContentData.referrerInfo;
|
||||
let referrerInfo = this.onLink
|
||||
? gContextMenuContentData.linkReferrerInfo
|
||||
: gContextMenuContentData.referrerInfo;
|
||||
// If we want to change userContextId, we must be sure that we don't
|
||||
// propagate the referrer.
|
||||
if (
|
||||
|
@ -1342,7 +1344,7 @@ nsContextMenu.prototype = {
|
|||
}
|
||||
|
||||
// Cache this because we fetch the data async
|
||||
let { targetReferrerInfo } = gContextMenuContentData;
|
||||
let referrerInfo = gContextMenuContentData.referrerInfo;
|
||||
|
||||
this.actor.saveVideoFrameAsImage(this.targetIdentifier).then(dataURL => {
|
||||
// FIXME can we switch this to a blob URL?
|
||||
|
@ -1352,7 +1354,7 @@ nsContextMenu.prototype = {
|
|||
"SaveImageTitle",
|
||||
true, // bypass cache
|
||||
false, // don't skip prompt for where to save
|
||||
targetReferrerInfo, // referrer info
|
||||
referrerInfo, // referrer info
|
||||
null, // document
|
||||
null, // content type
|
||||
null, // content disposition
|
||||
|
@ -1620,6 +1622,10 @@ nsContextMenu.prototype = {
|
|||
|
||||
// Save URL of clicked-on link.
|
||||
saveLink() {
|
||||
let referrerInfo = this.onLink
|
||||
? gContextMenuContentData.linkReferrerInfo
|
||||
: gContextMenuContentData.referrerInfo;
|
||||
|
||||
let isContentWindowPrivate = this.ownerDoc.isPrivate;
|
||||
this.saveHelper(
|
||||
this.linkURL,
|
||||
|
@ -1627,7 +1633,7 @@ nsContextMenu.prototype = {
|
|||
null,
|
||||
true,
|
||||
this.ownerDoc,
|
||||
gContextMenuContentData.referrerInfo,
|
||||
referrerInfo,
|
||||
this.frameOuterWindowID,
|
||||
this.linkDownload,
|
||||
isContentWindowPrivate
|
||||
|
@ -1645,7 +1651,7 @@ nsContextMenu.prototype = {
|
|||
saveMedia() {
|
||||
let doc = this.ownerDoc;
|
||||
let isContentWindowPrivate = this.ownerDoc.isPrivate;
|
||||
let referrerInfo = gContextMenuContentData.targetReferrerInfo;
|
||||
let referrerInfo = gContextMenuContentData.referrerInfo;
|
||||
let isPrivate = PrivateBrowsingUtils.isBrowserPrivate(this.browser);
|
||||
if (this.onCanvas) {
|
||||
// Bypass cache, since it's a data: URL.
|
||||
|
|
|
@ -327,8 +327,14 @@ this.DownloadsViewUI.DownloadElementShell.prototype = {
|
|||
* Downloads View.
|
||||
*/
|
||||
showStatusWithDetails(stateLabel, hoverStatus) {
|
||||
let referrer =
|
||||
this.download.source.referrerInfo &&
|
||||
this.download.source.referrerInfo.originalReferrer
|
||||
? this.download.source.referrerInfo.originalReferrer.spec
|
||||
: null;
|
||||
|
||||
let [displayHost] = DownloadUtils.getURIHost(
|
||||
this.download.source.referrer || this.download.source.url
|
||||
referrer || this.download.source.url
|
||||
);
|
||||
let [displayDate] = DownloadUtils.getReadableDates(
|
||||
new Date(this.download.endTime)
|
||||
|
|
|
@ -16,3 +16,4 @@ skip-if = (os == 'win' && os_version == '10.0' && ccov) # Bug 1306510
|
|||
skip-if = true # Bug 1352792
|
||||
[browser_downloads_panel_height.js]
|
||||
[browser_downloads_autohide.js]
|
||||
[browser_go_to_download_page.js]
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const ReferrerInfo = Components.Constructor(
|
||||
"@mozilla.org/referrer-info;1",
|
||||
"nsIReferrerInfo",
|
||||
"init"
|
||||
);
|
||||
|
||||
const TEST_REFERRER = "https://example.com/";
|
||||
|
||||
registerCleanupFunction(async function() {
|
||||
await task_resetState();
|
||||
await PlacesUtils.history.clear();
|
||||
});
|
||||
|
||||
async function addDownload(referrerInfo) {
|
||||
let startTimeMs = Date.now();
|
||||
|
||||
let publicList = await Downloads.getList(Downloads.PUBLIC);
|
||||
let downloadData = {
|
||||
source: {
|
||||
url: "http://www.example.com/test-download.txt",
|
||||
referrerInfo,
|
||||
},
|
||||
target: {
|
||||
path: gTestTargetFile.path,
|
||||
},
|
||||
startTime: new Date(startTimeMs++),
|
||||
};
|
||||
let download = await Downloads.createDownload(downloadData);
|
||||
await publicList.add(download);
|
||||
await download.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure "Go To Download Page" is enabled and works as expected.
|
||||
*/
|
||||
add_task(async function test_go_to_download_page() {
|
||||
let referrerInfo = new ReferrerInfo(
|
||||
Ci.nsIReferrerInfo.NO_REFERRER,
|
||||
true,
|
||||
NetUtil.newURI(TEST_REFERRER)
|
||||
);
|
||||
|
||||
let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, TEST_REFERRER);
|
||||
|
||||
// Wait for focus first
|
||||
await promiseFocus();
|
||||
|
||||
// Ensure that state is reset in case previous tests didn't finish.
|
||||
await task_resetState();
|
||||
|
||||
// Populate the downloads database with the data required by this test.
|
||||
await addDownload(referrerInfo);
|
||||
|
||||
// Open the user interface and wait for data to be fully loaded.
|
||||
await task_openPanel();
|
||||
|
||||
let win = await openLibrary("Downloads");
|
||||
registerCleanupFunction(function() {
|
||||
win.close();
|
||||
});
|
||||
|
||||
let listbox = win.document.getElementById("downloadsRichListBox");
|
||||
ok(listbox, "download list box present");
|
||||
|
||||
// Select one of the downloads.
|
||||
listbox.itemChildren[0].click();
|
||||
|
||||
let contextMenu = win.document.getElementById("downloadsContextMenu");
|
||||
|
||||
let popupShownPromise = BrowserTestUtils.waitForEvent(
|
||||
contextMenu,
|
||||
"popupshown"
|
||||
);
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
listbox.itemChildren[0],
|
||||
{ type: "contextmenu", button: 2 },
|
||||
win
|
||||
);
|
||||
await popupShownPromise;
|
||||
|
||||
// Find and click "Go To Download Page"
|
||||
let goToDownloadButton = [...contextMenu.children].find(
|
||||
child => child.command == "downloadsCmd_openReferrer"
|
||||
);
|
||||
goToDownloadButton.click();
|
||||
|
||||
let newTab = await tabPromise;
|
||||
ok(newTab, "Go To Download Page opened a new tab");
|
||||
gBrowser.removeTab(newTab);
|
||||
});
|
|
@ -1396,7 +1396,7 @@ function getCharsetforSave(aDocument) {
|
|||
* WARNING: Please note that openURL() does not perform any content security checks!!!
|
||||
*/
|
||||
function openURL(aURL) {
|
||||
var uri = makeURI(aURL);
|
||||
var uri = aURL instanceof Ci.nsIURI ? aURL : makeURI(aURL);
|
||||
|
||||
var protocolSvc = Cc[
|
||||
"@mozilla.org/uriloader/external-protocol-service;1"
|
||||
|
|
Загрузка…
Ссылка в новой задаче