Bug 1660527 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Bug 1658300 and bug 1658299 have now landed. 

The new UI is currently relying on code that calls nsIPrintSettingsService.initPrintSettingsFromPrinter to get its print settings object. There are a couple of issues with this API:

 1. On macOS and Linux this function does basically nothing much and so the nsIPrintSettings object does not get lots of its properties set with sensible, printer specific defaults (hence the preview being displayed with zero margins for printers that don't support that, etc.).

2. The call is a blocking call, and would be better done as a background task.

The new [nsIPrinterList.getNamedOrDefaultPrinter](https://searchfox.org/mozilla-central/source/widget/nsIPrinterList.idl) (not showing in searchfox yet) and [nsIPrinter.createDefaultSettings](https://searchfox.org/mozilla-central/rev/73e4e809df771baeb61635b25f53dfb44e930904/widget/nsIPrinter.idl#23) APIs allow the frontend code to now be written along the lines of the following (plus caching, etc.):

```
  let lastUsedPrinterName = printSettingsService.lastUsedPrinterName;

  let printer = await printerList.getNamedOrDefaultPrinter(lastUsedPrinterName);
  if (!printer) {
    printer = getPseudoMozillaSaveToPDFPrinter();
  }

  // In the future we should just use the saved settings, if present, and avoid
  // waiting for the defaults to be fetched asynchronously.  Unfortunately for
  // now we need to always get the defaults and overwrite them with any
  // saved settings.
  let settings = await printer.getDefaultSettings();
  printSettingsService.initPrintSettingsFromPrefs(settings, /* aUsePrinterNamePrefix */ true, settings.kInitSaveAll);

  // Now that we have our initial settings, send them to the content process
  // ASAP to start the print preview creation since this can take a long time.
  // All other work should happen after this point so that the parent and
  // content process can be doing their work in parallel.
  browser.print(settings);

  this.populateUIFormFieldsWithCurrentSettings(settings);
  this.updateUIWithAvailablePrinterSettings(printer);

  // Get other available printers:
  let availablePrinters = await printerList.printers;
  for (let printer of availablePrinters) {
    // Add name to printer dropdown
  }
```
Bug 1658300 and bug 1658299 have now landed. 

The new UI is currently relying on code that calls nsIPrintSettingsService.initPrintSettingsFromPrinter to get its print settings object. There are a couple of issues with this API:

 1. On macOS and Linux this function does basically nothing much and so the nsIPrintSettings object does not get lots of its properties set with sensible, printer specific defaults (hence the preview being displayed with zero margins for printers that don't support that, etc.).

2. The call is a blocking call, and would be better done as a background task.

The new [nsIPrinterList.getNamedOrDefaultPrinter](https://searchfox.org/mozilla-central/source/widget/nsIPrinterList.idl) (not showing in searchfox yet) and [nsIPrinter.createDefaultSettings](https://searchfox.org/mozilla-central/rev/73e4e809df771baeb61635b25f53dfb44e930904/widget/nsIPrinter.idl#23) APIs allow the frontend code to now be written along the lines of the following (plus caching, etc.):

```
  let lastUsedPrinterName = printSettingsService.lastUsedPrinterName;

  let printer = await printerList.getNamedOrDefaultPrinter(lastUsedPrinterName);
  if (!printer) {
    printer = getPseudoMozillaSaveToPDFPrinter();
  }

  // In the future we should just use the saved settings, if present, and avoid
  // waiting for the defaults to be fetched asynchronously.  Unfortunately for
  // now we need to always get the defaults and overwrite them with any
  // saved settings.
  let settings = await printer.createDefaultSettings();
  printSettingsService.initPrintSettingsFromPrefs(settings, /* aUsePrinterNamePrefix */ true, settings.kInitSaveAll);

  // Now that we have our initial settings, send them to the content process
  // ASAP to start the print preview creation since this can take a long time.
  // All other work should happen after this point so that the parent and
  // content process can be doing their work in parallel.
  browser.print(settings);

  this.populateUIFormFieldsWithCurrentSettings(settings);
  this.updateUIWithAvailablePrinterSettings(printer);

  // Get other available printers:
  let availablePrinters = await printerList.printers;
  for (let printer of availablePrinters) {
    // Add name to printer dropdown
  }
```
Bug 1658300 and bug 1658299 have now landed. 

The new UI is currently relying on code that calls nsIPrintSettingsService.initPrintSettingsFromPrinter to get its print settings object. There are a couple of issues with this API:

 1. On macOS and Linux this function does basically nothing much and so the nsIPrintSettings object does not get lots of its properties set with sensible, printer specific defaults (hence the preview being displayed with zero margins for printers that don't support that, etc.).

2. The call is a blocking call, and would be better done as a background task.

The new [nsIPrinterList.getNamedOrDefaultPrinter](https://searchfox.org/mozilla-central/rev/19c23d725f27d0989e4a60f36d64004cebb39736/widget/nsIPrinterList.idl#43) and [nsIPrinter.createDefaultSettings](https://searchfox.org/mozilla-central/rev/73e4e809df771baeb61635b25f53dfb44e930904/widget/nsIPrinter.idl#23) APIs allow the frontend code to now be written along the lines of the following (plus caching, etc.):

```
  let lastUsedPrinterName = printSettingsService.lastUsedPrinterName;

  let printer = await printerList.getNamedOrDefaultPrinter(lastUsedPrinterName);
  if (!printer) {
    printer = getPseudoMozillaSaveToPDFPrinter();
  }

  // In the future we should just use the saved settings, if present, and avoid
  // waiting for the defaults to be fetched asynchronously.  Unfortunately for
  // now we need to always get the defaults and overwrite them with any
  // saved settings.
  let settings = await printer.createDefaultSettings();
  printSettingsService.initPrintSettingsFromPrefs(settings, /* aUsePrinterNamePrefix */ true, settings.kInitSaveAll);

  // Now that we have our initial settings, send them to the content process
  // ASAP to start the print preview creation since this can take a long time.
  // All other work should happen after this point so that the parent and
  // content process can be doing their work in parallel.
  browser.print(settings);

  this.populateUIFormFieldsWithCurrentSettings(settings);
  this.updateUIWithAvailablePrinterSettings(printer);

  // Get other available printers:
  let availablePrinters = await printerList.printers;
  for (let printer of availablePrinters) {
    // Add name to printer dropdown
  }
```

Back to Bug 1660527 Comment 0