Commit 99457e02 authored by Hiroyuki Ikezoe's avatar Hiroyuki Ikezoe
Browse files

Bug 1641733 - Trigger print via FrameLoader.print in the parant process...

Bug 1641733 - Trigger print via FrameLoader.print in the parant process instead of in the content process. r=jwatt, a=test-only

Differential Revision: https://phabricator.services.mozilla.com/D78214
parent 37236ba0
...@@ -231,9 +231,8 @@ function setupPrintMode() { ...@@ -231,9 +231,8 @@ function setupPrintMode() {
docShell.contentViewer.setPageModeForTesting(/* aPageMode */ true, ps); docShell.contentViewer.setPageModeForTesting(/* aPageMode */ true, ps);
} }
// Prints current page to a PDF file and calls callback when sucessfully // Message the parent process to ask it to print the current page to a PDF file.
// printed and written. function printToPdf() {
function printToPdf(callback) {
let currentDoc = content.document; let currentDoc = content.document;
let isPrintSelection = false; let isPrintSelection = false;
let printRange = ''; let printRange = '';
...@@ -252,45 +251,7 @@ function printToPdf(callback) { ...@@ -252,45 +251,7 @@ function printToPdf(callback) {
} }
} }
let fileName =`reftest-print-${Date.now()}-`; SendStartPrint(isPrintSelection, printRange);
content.crypto.getRandomValues(new Uint8Array(4)).forEach(x => fileName += x.toString(16));
fileName += ".pdf"
let file = Services.dirsvc.get("TmpD", Ci.nsIFile);
file.append(fileName);
let PSSVC = Cc[PRINTSETTINGS_CONTRACTID].getService(Ci.nsIPrintSettingsService);
let ps = PSSVC.newPrintSettings;
ps.printSilent = true;
ps.showPrintProgress = false;
ps.printBGImages = true;
ps.printBGColors = true;
ps.printToFile = true;
ps.toFileName = file.path;
ps.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF;
if (isPrintSelection) {
ps.printRange = Ci.nsIPrintSettings.kRangeSelection;
} else if (printRange) {
ps.printRange = Ci.nsIPrintSettings.kRangeSpecifiedPageRange;
let range = printRange.split('-');
ps.startPageRange = +range[0] || 1;
ps.endPageRange = +range[1] || 1;
}
let webBrowserPrint = content.getInterface(Ci.nsIWebBrowserPrint);
webBrowserPrint.print(ps, {
onStateChange: function(webProgress, request, stateFlags, status) {
if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
callback(status, file.path);
}
},
onProgressChange: function () {},
onLocationChange: function () {},
onStatusChange: function () {},
onSecurityChange: function () {},
onContentBlockingEvent: function () {},
});
} }
function attrOrDefault(element, attr, def) { function attrOrDefault(element, attr, def) {
...@@ -1250,10 +1211,7 @@ function RecordResult(forURL) ...@@ -1250,10 +1211,7 @@ function RecordResult(forURL)
gCurrentURLTargetType = undefined; gCurrentURLTargetType = undefined;
if (gCurrentTestType == TYPE_PRINT) { if (gCurrentTestType == TYPE_PRINT) {
printToPdf(function (status, fileName) { printToPdf();
SendPrintResult(currentTestRunTime, status, fileName);
FinishTestItem();
});
return; return;
} }
if (gCurrentTestType == TYPE_SCRIPT) { if (gCurrentTestType == TYPE_SCRIPT) {
...@@ -1453,6 +1411,10 @@ function RegisterMessageListeners() ...@@ -1453,6 +1411,10 @@ function RegisterMessageListeners()
"reftest:ResetRenderingState", "reftest:ResetRenderingState",
function (m) { RecvResetRenderingState(); } function (m) { RecvResetRenderingState(); }
); );
addMessageListener(
"reftest:PrintDone",
function (m) { RecvPrintDone(m.json.status, m.json.fileName); }
);
} }
function RecvClear() function RecvClear()
...@@ -1482,6 +1444,13 @@ function RecvResetRenderingState() ...@@ -1482,6 +1444,13 @@ function RecvResetRenderingState()
resetDisplayportAndViewport(); resetDisplayportAndViewport();
} }
function RecvPrintDone(status, fileName)
{
const currentTestRunTime = Date.now() - gCurrentTestStartTime;
SendPrintResult(currentTestRunTime, status, fileName);
FinishTestItem();
}
function SendAssertionCount(numAssertions) function SendAssertionCount(numAssertions)
{ {
sendAsyncMessage("reftest:AssertionCount", { count: numAssertions }); sendAsyncMessage("reftest:AssertionCount", { count: numAssertions });
...@@ -1591,6 +1560,11 @@ function SendScriptResults(runtimeMs, error, results) ...@@ -1591,6 +1560,11 @@ function SendScriptResults(runtimeMs, error, results)
{ runtimeMs: runtimeMs, error: error, results: results }); { runtimeMs: runtimeMs, error: error, results: results });
} }
function SendStartPrint(isPrintSelection, printRange)
{
sendAsyncMessage("reftest:StartPrint", { isPrintSelection, printRange });
}
function SendPrintResult(runtimeMs, status, fileName) function SendPrintResult(runtimeMs, status, fileName)
{ {
sendAsyncMessage("reftest:PrintResult", sendAsyncMessage("reftest:PrintResult",
......
...@@ -1535,6 +1535,10 @@ function RegisterMessageListenersAndLoadContentScript(aReload) ...@@ -1535,6 +1535,10 @@ function RegisterMessageListenersAndLoadContentScript(aReload)
"reftest:ScriptResults", "reftest:ScriptResults",
function (m) { RecvScriptResults(m.json.runtimeMs, m.json.error, m.json.results); } function (m) { RecvScriptResults(m.json.runtimeMs, m.json.error, m.json.results); }
); );
g.browserMessageManager.addMessageListener(
"reftest:StartPrint",
function (m) { RecvStartPrint(m.json.isPrintSelection, m.json.printRange); }
);
g.browserMessageManager.addMessageListener( g.browserMessageManager.addMessageListener(
"reftest:PrintResult", "reftest:PrintResult",
function (m) { RecvPrintResult(m.json.runtimeMs, m.json.status, m.json.fileName); } function (m) { RecvPrintResult(m.json.runtimeMs, m.json.status, m.json.fileName); }
...@@ -1657,6 +1661,47 @@ function RecvScriptResults(runtimeMs, error, results) ...@@ -1657,6 +1661,47 @@ function RecvScriptResults(runtimeMs, error, results)
RecordResult(runtimeMs, error, results); RecordResult(runtimeMs, error, results);
} }
function RecvStartPrint(isPrintSelection, printRange)
{
let fileName =`reftest-print-${Date.now()}-`;
crypto.getRandomValues(new Uint8Array(4)).forEach(x => fileName += x.toString(16));
fileName += ".pdf"
let file = Services.dirsvc.get("TmpD", Ci.nsIFile);
file.append(fileName);
let PSSVC = Cc["@mozilla.org/gfx/printsettings-service;1"].getService(Ci.nsIPrintSettingsService);
let ps = PSSVC.newPrintSettings;
ps.printSilent = true;
ps.showPrintProgress = false;
ps.printBGImages = true;
ps.printBGColors = true;
ps.printToFile = true;
ps.toFileName = file.path;
ps.outputFormat = Ci.nsIPrintSettings.kOutputFormatPDF;
if (isPrintSelection) {
ps.printRange = Ci.nsIPrintSettings.kRangeSelection;
} else if (printRange) {
ps.printRange = Ci.nsIPrintSettings.kRangeSpecifiedPageRange;
let range = printRange.split('-');
ps.startPageRange = +range[0] || 1;
ps.endPageRange = +range[1] || 1;
}
g.browser.frameLoader.print(g.browser.outerWindowID, ps, {
onStateChange: function(webProgress, request, stateFlags, status) {
if (stateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
SendPrintDone(status, file.path);
}
},
onProgressChange: function () {},
onLocationChange: function () {},
onStatusChange: function () {},
onSecurityChange: function () {},
onContentBlockingEvent: function () {},
});
}
function RecvPrintResult(runtimeMs, status, fileName) function RecvPrintResult(runtimeMs, status, fileName)
{ {
if (!Components.isSuccessCode(status)) { if (!Components.isSuccessCode(status)) {
...@@ -1750,6 +1795,11 @@ function SendResetRenderingState() ...@@ -1750,6 +1795,11 @@ function SendResetRenderingState()
g.browserMessageManager.sendAsyncMessage("reftest:ResetRenderingState"); g.browserMessageManager.sendAsyncMessage("reftest:ResetRenderingState");
} }
function SendPrintDone(status, fileName)
{
g.browserMessageManager.sendAsyncMessage("reftest:PrintDone", { status, fileName });
}
var pdfjsHasLoaded; var pdfjsHasLoaded;
function pdfjsHasLoadedPromise() { function pdfjsHasLoadedPromise() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment