Backed out 2 changesets (bug 1652344) for causing failures in test_printpreview.xhtml

CLOSED TREE

Backed out changeset d2b66d810ab5 (bug 1652344)
Backed out changeset 075903436ef2 (bug 1652344)
This commit is contained in:
Mihai Alexandru Michis 2020-07-13 01:21:28 +03:00
Родитель 3a2853e4cf
Коммит c6f6f8daa2
5 изменённых файлов: 63 добавлений и 51 удалений

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

@ -5191,10 +5191,41 @@ void nsGlobalWindowOuter::PrintOuter(ErrorResult& aError) {
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService("@mozilla.org/gfx/printsettings-service;1");
nsCOMPtr<nsIPrintSettings> printSettings;
if (printSettingsService) {
printSettingsService->GetGlobalPrintSettings(
getter_AddRefs(printSettings));
nsAutoString printerName;
printSettings->GetPrinterName(printerName);
bool shouldGetLastUsedPrinterName = printerName.IsEmpty();
# ifdef MOZ_X11
// In Linux, GTK backend does not support per printer settings.
// Calling GetLastUsedPrinterName causes a sandbox violation (see Bug
// 1329216). The printer name is not needed anywhere else on Linux
// before it gets to the parent. In the parent, we will then query the
// last-used printer name if no name is set. Unless we are in the parent,
// we will skip this part.
if (!XRE_IsParentProcess()) {
shouldGetLastUsedPrinterName = false;
}
# endif
if (shouldGetLastUsedPrinterName) {
printSettingsService->GetLastUsedPrinterName(printerName);
printSettings->SetPrinterName(printerName);
}
printSettingsService->InitPrintSettingsFromPrinter(printerName,
printSettings);
printSettingsService->InitPrintSettingsFromPrefs(
printSettings, true, nsIPrintSettings::kInitSaveAll);
EnterModalState();
webBrowserPrint->Print(nullptr, nullptr);
webBrowserPrint->Print(printSettings, nullptr);
LeaveModalState();
} else {
webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(printSettings));
webBrowserPrint->Print(printSettings, nullptr);
}
}
#endif // NS_PRINTING

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

@ -3330,6 +3330,12 @@ nsDocumentViewer::PrintPreviewScrollToPage(int16_t aType, int32_t aPageNum) {
return NS_OK;
}
NS_IMETHODIMP
nsDocumentViewer::GetGlobalPrintSettings(
nsIPrintSettings** aGlobalPrintSettings) {
return nsPrintJob::GetGlobalPrintSettings(aGlobalPrintSettings);
}
// XXX This always returns false for subdocuments
NS_IMETHODIMP
nsDocumentViewer::GetDoingPrint(bool* aDoingPrint) {

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

@ -401,51 +401,6 @@ static nsresult EnsureSettingsHasPrinterNameSet(
#endif
}
static nsresult GetGlobalPrintSettings(
nsIPrintSettings** aGlobalPrintSettings) {
*aGlobalPrintSettings = nullptr;
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService(sPrintSettingsServiceContractID, &rv);
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIPrintSettings> settings;
rv = printSettingsService->GetGlobalPrintSettings(getter_AddRefs(settings));
if (NS_FAILED(rv)) {
return rv;
}
nsAutoString printerName;
settings->GetPrinterName(printerName);
bool shouldGetLastUsedPrinterName = printerName.IsEmpty();
#ifdef MOZ_X11
// In Linux, GTK backend does not support per printer settings.
// Calling GetLastUsedPrinterName causes a sandbox violation (see Bug
// 1329216). The printer name is not needed anywhere else on Linux
// before it gets to the parent. In the parent, we will then query the
// last-used printer name if no name is set. Unless we are in the parent,
// we will skip this part.
if (!XRE_IsParentProcess()) {
shouldGetLastUsedPrinterName = false;
}
#endif
if (shouldGetLastUsedPrinterName) {
printSettingsService->GetLastUsedPrinterName(printerName);
settings->SetPrinterName(printerName);
}
printSettingsService->InitPrintSettingsFromPrinter(printerName, settings);
printSettingsService->InitPrintSettingsFromPrefs(
settings, true, nsIPrintSettings::kInitSaveAll);
*aGlobalPrintSettings = settings.forget().take();
return NS_OK;
}
//-------------------------------------------------------
NS_IMPL_ISUPPORTS(nsPrintJob, nsIWebProgressListener, nsISupportsWeakReference,
@ -952,11 +907,6 @@ nsresult nsPrintJob::Print(Document* aSourceDoc,
nsresult rv = CommonPrint(false, aPrintSettings, aWebProgressListener, doc);
if (!aPrintSettings) {
// This is temporary until after bug 1602410 lands.
return rv;
}
// Save the print settings if the user picked them.
// We should probably do this immediately after the user confirms their
// selection (that is, move this to nsPrintingPromptService::ShowPrintDialog,
@ -1040,6 +990,20 @@ int32_t nsPrintJob::GetPrintPreviewNumPages() {
return numPages;
}
//----------------------------------------------------------------------------------
nsresult nsPrintJob::GetGlobalPrintSettings(
nsIPrintSettings** aGlobalPrintSettings) {
NS_ENSURE_ARG_POINTER(aGlobalPrintSettings);
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService(sPrintSettingsServiceContractID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = printSettingsService->GetGlobalPrintSettings(aGlobalPrintSettings);
}
return rv;
}
//----------------------------------------------------------------------------------
already_AddRefed<nsIPrintSettings> nsPrintJob::GetCurrentPrintSettings() {
if (mPrt) {

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

@ -46,6 +46,7 @@ class nsPrintJob final : public nsIObserver,
public nsIWebProgressListener,
public nsSupportsWeakReference {
public:
static nsresult GetGlobalPrintSettings(nsIPrintSettings** aPrintSettings);
static void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
nsPrintJob() = default;

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

@ -26,6 +26,16 @@ interface nsIWebBrowserPrint : nsISupports
const short PRINTPREVIEW_HOME = 3;
const short PRINTPREVIEW_END = 4;
/**
* Returns a "global" PrintSettings object
* Creates a new the first time, if one doesn't exist.
*
* Then returns the same object each time after that.
*
* Initializes the globalPrintSettings from the default printer
*/
readonly attribute nsIPrintSettings globalPrintSettings;
/**
* Returns a pointer to the PrintSettings object that
* that was passed into either "print" or "print preview"