Bug 1651728 Remove reader mode toolbar from saved document. r=niklas,mtigley

Differential Revision: https://phabricator.services.mozilla.com/D138562
This commit is contained in:
chadb 2022-04-11 19:06:45 +00:00
Родитель abe0c11792
Коммит 0cd8a95d56
5 изменённых файлов: 145 добавлений и 2 удалений

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

@ -77,6 +77,16 @@ class AboutReaderChild extends JSWindowActorChild {
ReaderMode.leaveReaderMode(this.docShell, this.contentWindow);
break;
}
case "Reader:HideToolbar": {
this.toolbar = this.document.getElementById("toolbar");
this.toolbar.hidden = true;
break;
}
case "Reader:ShowToolbar": {
this.toolbar = this.document.getElementById("toolbar");
this.toolbar.hidden = false;
break;
}
}
// Forward the message to the reader if it has been created.

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

@ -16,6 +16,14 @@
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
});
ChromeUtils.defineModuleGetter(
this,
"Downloads",
@ -417,8 +425,27 @@ DownloadLegacyTransfer.prototype = {
aDownload.tryToKeepPartialData = true;
}
// Start the download before allowing it to be controlled. Ignore errors.
aDownload.start().catch(() => {});
// Hide toolbar before download if we're in reader mode
let aboutReaderCb = () => {};
if (aDownload.source.url.includes("about:reader")) {
let browserWin = BrowserWindowTracker.getTopWindow();
let actor = browserWin.gBrowser.selectedBrowser.browsingContext.currentWindowGlobal.getActor(
"AboutReader"
);
actor.sendQuery("Reader:HideToolbar");
aboutReaderCb = () => {
actor.sendQuery("Reader:ShowToolbar");
};
}
// Start the download before allwoing it to be controlled. Ignore errors.
aDownload
.start()
.then(() => {
aboutReaderCb();
})
.catch(() => {});
// Start processing all the other events received through nsITransfer.
this._download = aDownload;

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

@ -14,6 +14,10 @@ support-files =
[browser_readerMode_colorSchemePref.js]
support-files =
readerModeArticle.html
[browser_readerMode_download.js]
skip-if = os == "linux" && headless
support-files =
readerModeArticleShort.html
[browser_readerMode_hidden_nodes.js]
skip-if = debug && os == "linux" && os_version == "18.04" #bug 1638027
support-files =

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

@ -0,0 +1,91 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// This test verifies that the toolbar is hidden when saving in reader mode
const TEST_PATH = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://example.com"
);
var MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
function createTemporarySaveDirectory() {
var saveDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
saveDir.append("testsavedir");
if (!saveDir.exists()) {
saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
}
return saveDir;
}
function downloadHadFinished(publicList) {
return new Promise(resolve => {
publicList.addView({
onDownloadChanged(download) {
if (download.succeeded || download.error) {
publicList.removeView(this);
resolve(download);
}
},
});
});
}
/**
* Test that the reader modes toolbar is hidden on page download
*/
add_task(async function() {
// Open the page in reader mode
await BrowserTestUtils.withNewTab(
TEST_PATH + "readerModeArticleShort.html",
async function(browser) {
let pageShownPromise = BrowserTestUtils.waitForContentEvent(
browser,
"AboutReaderContentReady"
);
let readerButton = document.getElementById("reader-mode-button");
readerButton.click();
await pageShownPromise;
// Reader mode page open -- Begin downloading the Page
var fileName;
var destDir = createTemporarySaveDirectory();
var destFile = destDir.clone();
MockFilePicker.displayDirectory = destDir;
MockFilePicker.showCallback = function(fp) {
fileName = fp.defaultString;
destFile.append(fileName);
MockFilePicker.setFiles([destFile]);
MockFilePicker.filterIndex = 1; // kSaveAsType_URL
};
let fileSavePageAsElement = document.getElementById("menu_savePage");
fileSavePageAsElement.doCommand();
// Wait for the download to complete
let publicList = await Downloads.getList(Downloads.PUBLIC);
let downloadFinishedPromise = downloadHadFinished(publicList);
let download = await downloadFinishedPromise;
// Open the downloaded page
let fileDir = PathUtils.join(download.target.path);
let loadPromise = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser
);
BrowserTestUtils.loadURI(gBrowser.selectedBrowser, fileDir);
await loadPromise;
// Check that the toolbar is hidden
await SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
Assert.ok(
content.document.getElementById("toolbar").hidden,
"The toolbar is hidden"
);
});
}
);
});

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

@ -326,6 +326,17 @@ function internalSave(
promiseTargetFile(fpParams, aSkipPrompt, relatedURI)
.then(aDialogAccepted => {
if (!aDialogAccepted) {
let browserWin = BrowserWindowTracker.getTopWindow();
if (
browserWin.gBrowser.selectedBrowser.currentURI.spec.startsWith(
"about:reader?"
)
) {
let actor = browserWin.gBrowser.selectedBrowser.browsingContext.currentWindowGlobal.getActor(
"AboutReader"
);
actor.sendQuery("Reader:ShowToolbar");
}
return;
}