Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / nsPrintSettingsServiceX.mm
blobd2cb4486af25d65a9a516712b1be2cef17c4cbc0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsPrintSettingsServiceX.h"
8 #include "mozilla/embedding/PPrintingTypes.h"
9 #include "nsCOMPtr.h"
10 #include "nsQueryObject.h"
11 #include "nsPrintSettingsX.h"
12 #include "nsCocoaUtils.h"
14 using namespace mozilla::embedding;
16 NS_IMETHODIMP
17 nsPrintSettingsServiceX::SerializeToPrintData(nsIPrintSettings* aSettings,
18                                               PrintData* data) {
19   nsresult rv = nsPrintSettingsService::SerializeToPrintData(aSettings, data);
20   if (NS_WARN_IF(NS_FAILED(rv))) {
21     return rv;
22   }
24   RefPtr<nsPrintSettingsX> settingsX(do_QueryObject(aSettings));
25   if (NS_WARN_IF(!settingsX)) {
26     return NS_ERROR_FAILURE;
27   }
29   settingsX->GetDisposition(data->disposition());
30   settingsX->GetDestination(&data->destination());
32   return NS_OK;
35 NS_IMETHODIMP
36 nsPrintSettingsServiceX::DeserializeToPrintSettings(
37     const PrintData& data, nsIPrintSettings* settings) {
38   nsresult rv =
39       nsPrintSettingsService::DeserializeToPrintSettings(data, settings);
40   if (NS_WARN_IF(NS_FAILED(rv))) {
41     return rv;
42   }
44   RefPtr<nsPrintSettingsX> settingsX(do_QueryObject(settings));
45   if (NS_WARN_IF(!settingsX)) {
46     return NS_ERROR_FAILURE;
47   }
49   settingsX->SetDisposition(data.disposition());
50   settingsX->SetDestination(data.destination());
52   return NS_OK;
55 nsresult nsPrintSettingsServiceX::_CreatePrintSettings(
56     nsIPrintSettings** _retval) {
57   nsresult rv;
58   *_retval = nullptr;
60   nsPrintSettingsX* printSettings =
61       new nsPrintSettingsX;  // does not initially ref count
62   NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
63   NS_ADDREF(*_retval = printSettings);
65   rv = printSettings->Init();
66   if (NS_FAILED(rv)) {
67     NS_RELEASE(*_retval);
68     return rv;
69   }
71   auto globalPrintSettings = nsIPrintSettings::kGlobalSettings;
73   // XXX Why is Mac special? Why are we copying global print settings here?
74   // nsPrintSettingsService::InitPrintSettingsFromPrefs already gets the few
75   // global defaults that we want, doesn't it?
76   InitPrintSettingsFromPrefs(*_retval, false, globalPrintSettings);
77   return rv;