Bug 1719203 - Let "Copy Image Link" use the original URL before redirects. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D125849
This commit is contained in:
Dão Gottwald 2021-09-22 16:54:53 +00:00
Родитель a1c4e115cf
Коммит a1585362ad
7 изменённых файлов: 66 добавлений и 15 удалений

Просмотреть файл

@ -975,6 +975,16 @@ class ContextMenuChild extends JSWindowActorChild {
context.onCompletedImage = true;
}
// The URL of the image before redirects is the currentURI. This is
// intended to be used for "Copy Image Link".
context.originalMediaURL = (() => {
let currentURI = context.target.currentURI?.spec;
if (currentURI && this._isMediaURLReusable(currentURI)) {
return currentURI;
}
return "";
})();
// The actual URL the image was loaded from (after redirects) is the
// currentRequestFinalURI. We should use that as the URL for purposes of
// deciding on the filename, if it is present. It might not be present

Просмотреть файл

@ -188,6 +188,7 @@ class nsContextMenu {
this.imageDescURL = context.imageDescURL;
this.imageInfo = context.imageInfo;
this.mediaURL = context.mediaURL || context.bgImageURL;
this.originalMediaURL = context.originalMediaURL || this.mediaURL;
this.webExtBrowserType = context.webExtBrowserType;
this.canSpellCheck = context.canSpellCheck;
@ -2098,7 +2099,7 @@ class nsContextMenu {
var clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(
Ci.nsIClipboardHelper
);
clipboard.copyString(this.mediaURL);
clipboard.copyString(this.originalMediaURL);
}
drmLearnMore(aEvent) {
@ -2114,13 +2115,6 @@ class nsContextMenu {
openTrustedLinkIn(drmInfoURL, dest);
}
get imageURL() {
if (this.onImage) {
return this.mediaURL;
}
return "";
}
// Formats the 'Search <engine> for "<selection or link text>"' context menu.
showAndFormatSearchContextItem() {
let menuItem = document.getElementById("context-searchselect");

Просмотреть файл

@ -37,22 +37,27 @@ run-if = os == "win"
[browser_contextmenu_spellcheck.js]
https_first_disabled = true
skip-if = toolkit == "gtk" || (os == "win" && processor == "aarch64") # disabled on Linux due to bug 513558, aarch64 due to 1533161
[browser_view_image.js]
support-files =
test_view_image_revoked_cached_blob.html
[browser_contextmenu_touch.js]
skip-if = true # Bug 1424433, disable due to very high frequency failure rate also on Windows 10
[browser_contextmenu_linkopen.js]
[browser_contextmenu_iframe.js]
support-files =
test_contextmenu_iframe.html
[browser_utilityOverlay.js]
https_first_disabled = true
[browser_utilityOverlayPrincipal.js]
https_first_disabled = true
[browser_contextmenu_childprocess.js]
[browser_contextmenu.js]
tags = fullscreen
skip-if = toolkit == "gtk" || verify || (os == "win" && processor == "aarch64") # disabled on Linux due to bug 513558, aarch64 due to 1531590
[browser_contextmenu_input.js]
skip-if = toolkit == "gtk" || (os == "win" && processor == "aarch64") # disabled on Linux due to bug 513558, aarch64 due to 1533161
[browser_copy_image_link.js]
support-files =
doggy.png
firebird.png
firebird.png^headers^
[browser_utilityOverlay.js]
https_first_disabled = true
[browser_utilityOverlayPrincipal.js]
https_first_disabled = true
[browser_view_image.js]
support-files =
test_view_image_revoked_cached_blob.html

Просмотреть файл

@ -0,0 +1,40 @@
/**
* Testcase for bug 1719203
* <https://bugzilla.mozilla.org/show_bug.cgi?id=1719203>
*
* Load firebird.png, redirect it to doggy.png, and verify that "Copy Image
* Link" copies firebird.png.
*/
add_task(async function() {
// This URL will redirect to doggy.png.
const URL_FIREBIRD =
"http://mochi.test:8888/browser/browser/base/content/test/contextMenu/firebird.png";
await BrowserTestUtils.withNewTab(URL_FIREBIRD, async function(browser) {
// Click image to show context menu.
let popupShownPromise = BrowserTestUtils.waitForEvent(
document,
"popupshown"
);
await BrowserTestUtils.synthesizeMouseAtCenter(
"img",
{ type: "contextmenu", button: 2 },
browser
);
await popupShownPromise;
await SimpleTest.promiseClipboardChange(URL_FIREBIRD, () => {
document.getElementById("context-copyimage").doCommand();
});
// Close context menu.
let contextMenu = document.getElementById("contentAreaContextMenu");
let popupHiddenPromise = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
contextMenu.hidePopup();
await popupHiddenPromise;
});
});

Двоичные данные
browser/base/content/test/contextMenu/doggy.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 46 KiB

Двоичные данные
browser/base/content/test/contextMenu/firebird.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 16 KiB

Просмотреть файл

@ -0,0 +1,2 @@
HTTP 302 Found
Location: doggy.png