Bug 1136855 - Print settings are not saved from print job to print job
Oh boy.

Oh boy oh boy oh boy. I caused this one with bug 1082575 . :(

dw-dev noticed back on February 10th:

"1. In printUtils.js, between lines 172 & 173, need to reinstate the following code:

if (gPrintSettingsAreGlobal && gSavePrintSettings) { /* missing in Firefox 36.0a1 */ /*???*/
printEdit.psService.savePrintSettingsToPrefs(printSettings, true,
printSettings.kInitSaveAll);
printEdit.psService.savePrintSettingsToPrefs(printSettings, false,
printSettings.kInitSavePrinterName);"

The save occurs after the print is requested.

I think what I'll need to do is have the child send a message back up to the parent when printing is done, and then we'll save the settings.

This is so crazy.

The problem there is that savePrintSettingsToPrefs takes the nsIPrintSettings, and that'll be a CPOW if it came from the child.

Ohhhh - but in the single process case (which is what Aurora, Beta and Release have to worry about), it'll work just fine.

So, potential attack plan:

  1. Solve the single-process case, since that's probably highest priority. Have the child send up the nsIPrintSettings after the print job is completed, and the parent can save it without difficulty.
  2. Figure out a new solution for the multi-process case. With the settings initted from the child, this makes things more complicated...
  3. See if there's a way to write a test for this to avoid regressing it again.

Ok, let's roll.

So that seems to work OK. I've put the patch up, and tested it on Linux, and it works well. Waiting for a Windows build to finish so that I can test there.

In the mean time, how to write a test?

Suppose I mock out the PrintingPromptService, and factory for nsIDeviceContextSpec...

I think that'd probably be enough...

interface nsIPrintingPromptService : nsISupports
{
/**
* This service enables embedders to implement their own Print and Progress Dialogs.
* Each platform has a "base" or "basckstop" implementation of the service. The
* service is automatically registered at start up.
*
* Historically, platform toolkits with native dialogs have implemented them in the GFX layer
* Usually they were displayed when a new DeviceContextSpec specific to that platform
* was created.
*
* Windows: The GFX layer no longers supports default toolkit behavior for displaying the
* native Print Dialog.
* If an embedder implemented service returns any error code (other than NS_ERROR_ABORT)
* printing will terminate.
*
* Returning NS_OK assumes that the PrintSettings object was correctly filled in and
* if it does not have valid fields for printer name, etc. it may also terminate.
*
* Defaults for platform service:
* showPrintDialog - displays a native dialog
* showPageSetup - displays a XUL dialog
* showProgress - displays a XUL dialog
* showPrinterProperties - n/a
*
* Summary for Windows Embedders:
* Stated once again: There is no "fallback" native platform support in GFX for the
* displaying of the native print dialog. The current default implementation for Windows
* display a native print dialog but a XUL-based progress dialog.
* If you wish to have a native progress dialog on Windows you will have to create and
* register your own service.
*
* Note: The Windows version Mozilla implements this service which is
* automatically built and registered for you. You can use it as an example.
* It is located at "mozilla/embedding/components/printingui/win". That service
* is capable of displaying a native print dialog and a XUL progress dialog.
*
* To fly your own dialog you may:
*
* 1) Implement this service to display at least the Print Dialog and a Print Progress Dialog
* or you may implement just one of the dialogs and pass back NS_ERROR_NOT_IMPLEMENTED
* for any of the others.
*
* 2) For the Print Dialog:
* You may stub out this service by having all the methods return NS_ERROR_NOT_IMPLEMENTED.
* You can then fly you own dialog and then properly fill in the PrintSettings object
* before calling nsIWebBrowserPrint's Print method. If you stub out this service
* you MUST set "printSilent" to true, if you do not, Printing will terminate and an
* error dialog will be displayed.
*
* Mac: The GFX layer still supports default toolkit behavior for displaying the Print Dialog.
* If an embedder implemented service returns NS_ERROR_NOT_IMPLEMENTED for "showPrintDialog"
* The toolkit will display the native print dialog.
*
* Defaults for platform service:
* Mac OS9: showPrintDialog - displays a native dialog
* showPageSetup - displays a native dialog
* showProgress - displays a XUL dialog
* showPrinterProperties - n/a
*
* Mac OSX: showPrintDialog - displays a native dialog
* showPageSetup - displays a native dialog
* showProgress - not implemented (provided by OS)
* showPrinterProperties - n/a
*
* GTK: There are no native dialog for GTK.
*
* Defaults for platform service:
* showPrintDialog - displays a XUL dialog
* showPageSetup - displays a XUL dialog
* showProgress - displays a XUL dialog
* showPrinterProperties - displays a XUL dialog
*
*/



/**
* Show the Print Dialog
*
* @param parent - a DOM windows the dialog will be parented to (required)
* @param webBrowserPrint - represents the document to be printed (required)
* @param printSettings - PrintSettings for print "job" (required)
*
*/
void showPrintDialog(in nsIDOMWindow parent,
in nsIWebBrowserPrint webBrowserPrint,
in nsIPrintSettings printSettings);

/**
* Shows the print progress dialog
*
* @param parent - a DOM windows the dialog will be parented to
* @param webBrowserPrint - represents the document to be printed
* @param printSettings - PrintSettings for print "job"
* @param openDialogObserver - an observer that will be notifed when the dialog is opened
* @param isForPrinting - true - for printing, false for print preview
* @param webProgressListener - additional listener can be registered for progress notifications
* @param printProgressParams - parameter object for passing progress state
* @param notifyOnOpen - this indicates that the observer will be notified when the progress
* dialog has been opened. If false is returned it means the observer
* (usually the caller) shouldn't wait
* For Print Preview Progress there is intermediate progress
*/
void showProgress(in nsIDOMWindow parent,
in nsIWebBrowserPrint webBrowserPrint,
in nsIPrintSettings printSettings,
in nsIObserver openDialogObserver,
in boolean isForPrinting,
out nsIWebProgressListener webProgressListener,
out nsIPrintProgressParams printProgressParams,
out boolean notifyOnOpen);

/**
* Shows the print progress dialog
*
* @param parent - a DOM windows the dialog will be parented to (required)
* @param printSettings - PrintSettings for page setup (required)
* @param aObs - An observer to know if the contents of the Print Settings
* object has changed while the dialog is being shown.
* For example, some platforms may implement an "Apply" button (not required)
*/
void showPageSetup(in nsIDOMWindow parent,
in nsIPrintSettings printSettings,
in nsIObserver aObs);

/**
* Sometimes platforms need to bring up a special properties dialog for showing
* print specific properties. Although the PrintSettings has a place to set the
* printer name, here is is an argument to be clear as to what printer is being
* asked to have the properties set for it. The Printer name in the PS is ignored.
*
* @param parent - a DOM windows the dialog will be parented to (required)
* @param printerName - name of printer (required)
* @param printSettings - PrintSettings for page setup (required)
*/
void showPrinterProperties(in nsIDOMWindow parent,
in wstring printerName,
in nsIPrintSettings printSettings);

};

and

class nsIDeviceContextSpec : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDEVICE_CONTEXT_SPEC_IID)

/**
* Initialize the device context spec.
* @param aWidget A widget a dialog can be hosted in
* @param aPrintSettings Print settings for the print operation
* @param aIsPrintPreview True if creating Spec for PrintPreview
* @return NS_OK or a suitable error code.
*/
NS_IMETHOD Init(nsIWidget *aWidget,
nsIPrintSettings* aPrintSettings,
bool aIsPrintPreview) = 0;

NS_IMETHOD GetSurfaceForPrinter(gfxASurface **nativeSurface) = 0;

NS_IMETHOD BeginDocument(const nsAString& aTitle,
char16_t* aPrintToFileName,
int32_t aStartPage,
int32_t aEndPage) = 0;

NS_IMETHOD EndDocument() = 0;
NS_IMETHOD BeginPage() = 0;
NS_IMETHOD EndPage() = 0;
};

That's actually not bad - I think I can work with that.

Except I can't. BAH. I can't mock out an gfxASurface**. :(((((

So much for a test case. *sigh*