Bug 1407103 - Convert wstring attributes to AString in widget/nsIPrint*.idl. r=bobowen.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 09 Oct 2017 10:08:09 +1100
changeset 436597 396ff2a152d77a0c28f09fefc8b0a96659f2d4ba
parent 436596 7fde6d8f818288f648f077d83ee1f200b580e1ff
child 436598 c543c0a50db700883b57c052710c97b5ef731e1f
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1407103
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1407103 - Convert wstring attributes to AString in widget/nsIPrint*.idl. r=bobowen. This avoids a lot of mismatches between nsAString and char16_t*, thus removing many getter_Copies() and ToNewUnicode() and get() calls, and generally making things simpler. Note: the patch removes GetDefaultPrinterNameFromGlobalPrinters() by simply inlining it at its two callsites, which is easy with the changed types.
dom/base/nsGlobalWindow.cpp
layout/generic/nsPageFrame.cpp
layout/printing/nsPrintEngine.cpp
toolkit/components/printingui/ipc/PrintingParent.cpp
toolkit/components/printingui/win/nsPrintDialogUtil.cpp
widget/android/nsDeviceContextAndroid.cpp
widget/android/nsPrintOptionsAndroid.cpp
widget/cocoa/nsPrintDialogX.mm
widget/cocoa/nsPrintSettingsX.h
widget/cocoa/nsPrintSettingsX.mm
widget/gtk/nsDeviceContextSpecG.cpp
widget/gtk/nsPrintDialogGTK.cpp
widget/gtk/nsPrintSettingsGTK.cpp
widget/gtk/nsPrintSettingsGTK.h
widget/nsIPrintSettings.idl
widget/nsIPrintSettingsService.idl
widget/nsIPrintSettingsWin.idl
widget/nsIPrinterEnumerator.idl
widget/nsPrintOptionsImpl.cpp
widget/nsPrintSettingsImpl.cpp
widget/nsPrintSettingsImpl.h
widget/windows/nsDeviceContextSpecWin.cpp
widget/windows/nsDeviceContextSpecWin.h
widget/windows/nsPrintOptionsWin.cpp
widget/windows/nsPrintSettingsWin.cpp
widget/windows/nsPrintSettingsWin.h
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -8151,34 +8151,34 @@ nsGlobalWindow::PrintOuter(ErrorResult& 
     if (printSettingsService) {
       bool printSettingsAreGlobal =
         Preferences::GetBool("print.use_global_printsettings", false);
 
       if (printSettingsAreGlobal) {
         printSettingsService->GetGlobalPrintSettings(getter_AddRefs(printSettings));
 
         nsAutoString printerName;
-        printSettings->GetPrinterName(getter_Copies(printerName));
+        printSettings->GetPrinterName(printerName);
 
         bool shouldGetDefaultPrinterName = printerName.IsEmpty();
 #ifdef MOZ_X11
         // In Linux, GTK backend does not support per printer settings.
         // Calling GetDefaultPrinterName 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 default printer name if no name is set.
         // Unless we are in the parent, we will skip this part.
         if (!XRE_IsParentProcess()) {
           shouldGetDefaultPrinterName = false;
         }
 #endif
         if (shouldGetDefaultPrinterName) {
-          printSettingsService->GetDefaultPrinterName(getter_Copies(printerName));
-          printSettings->SetPrinterName(printerName.get());
+          printSettingsService->GetDefaultPrinterName(printerName);
+          printSettings->SetPrinterName(printerName);
         }
-        printSettingsService->InitPrintSettingsFromPrinter(printerName.get(),
+        printSettingsService->InitPrintSettingsFromPrinter(printerName,
                                                            printSettings);
         printSettingsService->InitPrintSettingsFromPrefs(printSettings,
                                                          true,
                                                          nsIPrintSettings::kInitSaveAll);
       } else {
         printSettingsService->GetNewPrintSettings(getter_AddRefs(printSettings));
       }
 
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -637,27 +637,27 @@ nsPageFrame::PaintHeaderFooter(gfxContex
   nscoord visibleHeight = 0;
   if (fontMet) {
     visibleHeight = fontMet->MaxHeight();
     ascent = fontMet->MaxAscent();
   }
 
   // print document headers and footers
   nsString headerLeft, headerCenter, headerRight;
-  mPD->mPrintSettings->GetHeaderStrLeft(getter_Copies(headerLeft));
-  mPD->mPrintSettings->GetHeaderStrCenter(getter_Copies(headerCenter));
-  mPD->mPrintSettings->GetHeaderStrRight(getter_Copies(headerRight));
+  mPD->mPrintSettings->GetHeaderStrLeft(headerLeft);
+  mPD->mPrintSettings->GetHeaderStrCenter(headerCenter);
+  mPD->mPrintSettings->GetHeaderStrRight(headerRight);
   DrawHeaderFooter(aRenderingContext, *fontMet, eHeader,
                    headerLeft, headerCenter, headerRight,
                    rect, ascent, visibleHeight);
 
   nsString footerLeft, footerCenter, footerRight;
-  mPD->mPrintSettings->GetFooterStrLeft(getter_Copies(footerLeft));
-  mPD->mPrintSettings->GetFooterStrCenter(getter_Copies(footerCenter));
-  mPD->mPrintSettings->GetFooterStrRight(getter_Copies(footerRight));
+  mPD->mPrintSettings->GetFooterStrLeft(footerLeft);
+  mPD->mPrintSettings->GetFooterStrCenter(footerCenter);
+  mPD->mPrintSettings->GetFooterStrRight(footerRight);
   DrawHeaderFooter(aRenderingContext, *fontMet, eFooter,
                    footerLeft, footerCenter, footerRight,
                    rect, ascent, visibleHeight);
 }
 
 void
 nsPageFrame::SetSharedPageData(nsSharedPageData* aPD)
 {
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -1006,29 +1006,29 @@ nsPrintEngine::CheckForPrinters(nsIPrint
   if (!XRE_IsParentProcess()) {
     return NS_OK;
   }
 #endif
   NS_ENSURE_ARG_POINTER(aPrintSettings);
 
   // See if aPrintSettings already has a printer
   nsString printerName;
-  nsresult rv = aPrintSettings->GetPrinterName(getter_Copies(printerName));
+  nsresult rv = aPrintSettings->GetPrinterName(printerName);
   if (NS_SUCCEEDED(rv) && !printerName.IsEmpty()) {
     return NS_OK;
   }
 
   // aPrintSettings doesn't have a printer set. Try to fetch the default.
   nsCOMPtr<nsIPrintSettingsService> printSettingsService =
     do_GetService(sPrintSettingsServiceContractID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = printSettingsService->GetDefaultPrinterName(getter_Copies(printerName));
+  rv = printSettingsService->GetDefaultPrinterName(printerName);
   if (NS_SUCCEEDED(rv) && !printerName.IsEmpty()) {
-    rv = aPrintSettings->SetPrinterName(printerName.get());
+    rv = aPrintSettings->SetPrinterName(printerName);
   }
   return rv;
 #endif
 }
 
 //----------------------------------------------------------------------
 // Set up to use the "pluggable" Print Progress Dialog
 void
@@ -1450,31 +1450,18 @@ nsPrintEngine::GetDisplayTitleAndURL(con
     return;
 
   aTitle.Truncate();
   aURLStr.Truncate();
 
   // First check to see if the PrintSettings has defined an alternate title
   // and use that if it did
   if (mPrt->mPrintSettings) {
-    char16_t * docTitleStrPS = nullptr;
-    char16_t * docURLStrPS   = nullptr;
-    mPrt->mPrintSettings->GetTitle(&docTitleStrPS);
-    mPrt->mPrintSettings->GetDocURL(&docURLStrPS);
-
-    if (docTitleStrPS) {
-      aTitle = docTitleStrPS;
-    }
-
-    if (docURLStrPS) {
-      aURLStr = docURLStrPS;
-    }
-
-    free(docTitleStrPS);
-    free(docURLStrPS);
+    mPrt->mPrintSettings->GetTitle(aTitle);
+    mPrt->mPrintSettings->GetDocURL(aURLStr);
   }
 
   nsAutoString docTitle;
   nsAutoString docUrl;
   GetDocumentTitleAndURL(aPO->mDocument, docTitle, docUrl);
 
   if (aURLStr.IsEmpty() && !docUrl.IsEmpty()) {
     aURLStr = docUrl;
@@ -1823,17 +1810,17 @@ nsPrintEngine::SetupToPrintContent()
   }
 
   nsAutoString fileNameStr;
   // check to see if we are printing to a file
   bool isPrintToFile = false;
   printData->mPrintSettings->GetPrintToFile(&isPrintToFile);
   if (isPrintToFile) {
     // On some platforms The BeginDocument needs to know the name of the file.
-    printData->mPrintSettings->GetToFileName(getter_Copies(fileNameStr));
+    printData->mPrintSettings->GetToFileName(fileNameStr);
   }
 
   nsAutoString docTitleStr;
   nsAutoString docURLStr;
   GetDisplayTitleAndURL(printData->mPrintObject, docTitleStr, docURLStr,
                         eDocTitleDefURLDoc);
 
   int32_t startPage = 1;
--- a/toolkit/components/printingui/ipc/PrintingParent.cpp
+++ b/toolkit/components/printingui/ipc/PrintingParent.cpp
@@ -132,36 +132,35 @@ PrintingParent::ShowPrintDialog(PBrowser
 
   rv = mPrintSettingsSvc->DeserializeToPrintSettings(aData, settings);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = settings->SetPrintSilent(printSilently);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsString printerName;
-  settings->GetPrinterName(getter_Copies(printerName));
+  settings->GetPrinterName(printerName);
 #ifdef MOZ_X11
   // Requesting the default printer name on Linux has been removed in the child,
   // because it was causing a sandbox violation (see Bug 1329216).
   // If no printer name is set at this point, use the print settings service
   // to get the default printer name.
   if (printerName.IsEmpty()) {
-    mPrintSettingsSvc->GetDefaultPrinterName(getter_Copies(printerName));
-    settings->SetPrinterName(printerName.get());
+    mPrintSettingsSvc->GetDefaultPrinterName(printerName);
+    settings->SetPrinterName(printerName);
   }
-  mPrintSettingsSvc->InitPrintSettingsFromPrinter(printerName.get(), settings);
+  mPrintSettingsSvc->InitPrintSettingsFromPrinter(printerName, settings);
 #endif
 
   // If this is for print preview or we are printing silently then we just need
   // to initialize the print settings with anything specific from the printer.
   if (isPrintPreview || printSilently ||
       Preferences::GetBool("print.always_print_silent", printSilently)) {
     settings->SetIsInitializedFromPrinter(false);
-    mPrintSettingsSvc->InitPrintSettingsFromPrinter(printerName.get(),
-                                                    settings);
+    mPrintSettingsSvc->InitPrintSettingsFromPrinter(printerName, settings);
   } else {
     rv = pps->ShowPrintDialog(parentWin, wbp, settings);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (isPrintPreview) {
     // For print preview we don't want a RemotePrintJob just the settings.
     rv = mPrintSettingsSvc->SerializeToPrintData(settings, nullptr, aResult);
--- a/toolkit/components/printingui/win/nsPrintDialogUtil.cpp
+++ b/toolkit/components/printingui/win/nsPrintDialogUtil.cpp
@@ -530,17 +530,17 @@ CreateGlobalDevModeAndInit(const nsStrin
 }
 
 //------------------------------------------------------------------
 // helper
 static void GetDefaultPrinterNameFromGlobalPrinters(nsAString &printerName)
 {
   nsCOMPtr<nsIPrinterEnumerator> prtEnum = do_GetService("@mozilla.org/gfx/printerenumerator;1");
   if (prtEnum) {
-    prtEnum->GetDefaultPrinterName(getter_Copies(printerName));
+    prtEnum->GetDefaultPrinterName(printerName);
   }
 }
 
 // Determine whether we have a completely native dialog
 // or whether we cshould extend it
 static bool ShouldExtendPrintDialog()
 {
   nsresult rv;
@@ -565,17 +565,17 @@ ShowNativePrintDialog(HWND              
 {
   //NS_ENSURE_ARG_POINTER(aHWnd);
   NS_ENSURE_ARG_POINTER(aPrintSettings);
 
   gDialogWasExtended  = false;
 
   // Get the Print Name to be used
   nsString printerName;
-  aPrintSettings->GetPrinterName(getter_Copies(printerName));
+  aPrintSettings->GetPrinterName(printerName);
 
   // If there is no name then use the default printer
   if (printerName.IsEmpty()) {
     GetDefaultPrinterNameFromGlobalPrinters(printerName);
   } else {
     HANDLE hPrinter = nullptr;
     if(!::OpenPrinterW(const_cast<wchar_t*>(static_cast<const wchar_t*>(printerName.get())),
                        &hPrinter, nullptr)) {
@@ -691,39 +691,39 @@ ShowNativePrintDialog(HWND              
     // NOTE:
     // As per Microsoft SDK documentation the returned value offset from
     // devnames->wOutputOffset is either "FILE:" or nullptr
     // if the "Print To File" checkbox is checked it MUST be "FILE:"
     // We assert as an extra safety check.
     if (prntdlg.Flags & PD_PRINTTOFILE) {
       char16ptr_t fileName = &(((wchar_t *)devnames)[devnames->wOutputOffset]);
       NS_ASSERTION(wcscmp(fileName, L"FILE:") == 0, "FileName must be `FILE:`");
-      aPrintSettings->SetToFileName(fileName);
+      aPrintSettings->SetToFileName(nsDependentString(fileName));
       aPrintSettings->SetPrintToFile(true);
     } else {
       // clear "print to file" info
       aPrintSettings->SetPrintToFile(false);
-      aPrintSettings->SetToFileName(nullptr);
+      aPrintSettings->SetToFileName(EmptyString());
     }
 
     nsCOMPtr<nsIPrintSettingsWin> psWin(do_QueryInterface(aPrintSettings));
     if (!psWin) {
       return NS_ERROR_FAILURE;
     }
 
     // Setup local Data members
-    psWin->SetDeviceName(device);
-    psWin->SetDriverName(driver);
+    psWin->SetDeviceName(nsDependentString(device));
+    psWin->SetDriverName(nsDependentString(driver));
 
 #if defined(DEBUG_rods) || defined(DEBUG_dcone)
     wprintf(L"printer: driver %s, device %s  flags: %d\n", driver, device, prntdlg.Flags);
 #endif
     // fill the print options with the info from the dialog
 
-    aPrintSettings->SetPrinterName(device);
+    aPrintSettings->SetPrinterName(nsDependentString(device));
 
     if (prntdlg.Flags & PD_SELECTION) {
       aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSelection);
 
     } else if (prntdlg.Flags & PD_PAGENUMS) {
       aPrintSettings->SetPrintRange(nsIPrintSettings::kRangeSpecifiedPageRange);
       aPrintSettings->SetStartPageRange(prntdlg.nFromPage);
       aPrintSettings->SetEndPageRange(prntdlg.nToPage);
--- a/widget/android/nsDeviceContextAndroid.cpp
+++ b/widget/android/nsDeviceContextAndroid.cpp
@@ -57,17 +57,17 @@ nsDeviceContextSpecAndroid::BeginDocumen
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDeviceContextSpecAndroid::EndDocument()
 {
   nsString targetPath;
   nsCOMPtr<nsIFile> destFile;
-  mPrintSettings->GetToFileName(getter_Copies(targetPath));
+  mPrintSettings->GetToFileName(targetPath);
 
   nsresult rv = NS_NewLocalFile(targetPath, false, getter_AddRefs(destFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoString destLeafName;
   rv = destFile->GetLeafName(destLeafName);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/widget/android/nsPrintOptionsAndroid.cpp
+++ b/widget/android/nsPrintOptionsAndroid.cpp
@@ -7,18 +7,17 @@
 #include "nsPrintSettingsImpl.h"
 
 class nsPrintSettingsAndroid : public nsPrintSettings {
 public:
   nsPrintSettingsAndroid()
   {
     // The aim here is to set up the objects enough that silent printing works
     SetOutputFormat(nsIPrintSettings::kOutputFormatPDF);
-    SetPrinterName(u"PDF printer");
-    
+    SetPrinterName(NS_LITERAL_STRING("PDF printer"));
   }
 };
 
 nsPrintOptionsAndroid::nsPrintOptionsAndroid()
 {
 }
 
 nsPrintOptionsAndroid::~nsPrintOptionsAndroid()
--- a/widget/cocoa/nsPrintDialogX.mm
+++ b/widget/cocoa/nsPrintDialogX.mm
@@ -510,42 +510,42 @@ static const char sHeaderFooterTags[][4]
   [self addLabel:"pageFootersTitleMac" withFrame:NSMakeRect(0, 0, 151, 22)];
   [self addCenteredLabel:"left" withFrame:NSMakeRect(156, 22, 100, 22)];
   [self addCenteredLabel:"center" withFrame:NSMakeRect(256, 22, 100, 22)];
   [self addCenteredLabel:"right" withFrame:NSMakeRect(356, 22, 100, 22)];
 
   // Lists
   nsString sel;
 
-  mSettings->GetHeaderStrLeft(getter_Copies(sel));
+  mSettings->GetHeaderStrLeft(sel);
   mHeaderLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 44, 100, 22)
                                            selectedItem:sel];
   [self addSubview:mHeaderLeftList];
 
-  mSettings->GetHeaderStrCenter(getter_Copies(sel));
+  mSettings->GetHeaderStrCenter(sel);
   mHeaderCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 44, 100, 22)
                                              selectedItem:sel];
   [self addSubview:mHeaderCenterList];
 
-  mSettings->GetHeaderStrRight(getter_Copies(sel));
+  mSettings->GetHeaderStrRight(sel);
   mHeaderRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 44, 100, 22)
                                             selectedItem:sel];
   [self addSubview:mHeaderRightList];
 
-  mSettings->GetFooterStrLeft(getter_Copies(sel));
+  mSettings->GetFooterStrLeft(sel);
   mFooterLeftList = [self headerFooterItemListWithFrame:NSMakeRect(156, 0, 100, 22)
                                            selectedItem:sel];
   [self addSubview:mFooterLeftList];
 
-  mSettings->GetFooterStrCenter(getter_Copies(sel));
+  mSettings->GetFooterStrCenter(sel);
   mFooterCenterList = [self headerFooterItemListWithFrame:NSMakeRect(256, 0, 100, 22)
                                              selectedItem:sel];
   [self addSubview:mFooterCenterList];
 
-  mSettings->GetFooterStrRight(getter_Copies(sel));
+  mSettings->GetFooterStrRight(sel);
   mFooterRightList = [self headerFooterItemListWithFrame:NSMakeRect(356, 0, 100, 22)
                                             selectedItem:sel];
   [self addSubview:mFooterRightList];
 }
 
 // Export settings
 
 - (int16_t)chosenFrameSetting
@@ -565,32 +565,32 @@ static const char sHeaderFooterTags[][4]
   NS_ASSERTION(index < NSInteger(ArrayLength(sHeaderFooterTags)), "Index of dropdown is higher than expected!");
   return sHeaderFooterTags[index];
 }
 
 - (void)exportHeaderFooterSettings
 {
   const char* headerFooterStr;
   headerFooterStr = [self headerFooterStringForList:mHeaderLeftList];
-  mSettings->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr).get());
+  mSettings->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr));
 
   headerFooterStr = [self headerFooterStringForList:mHeaderCenterList];
-  mSettings->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr).get());
+  mSettings->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr));
 
   headerFooterStr = [self headerFooterStringForList:mHeaderRightList];
-  mSettings->SetHeaderStrRight(NS_ConvertUTF8toUTF16(headerFooterStr).get());
+  mSettings->SetHeaderStrRight(NS_ConvertUTF8toUTF16(headerFooterStr));
 
   headerFooterStr = [self headerFooterStringForList:mFooterLeftList];
-  mSettings->SetFooterStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr).get());
+  mSettings->SetFooterStrLeft(NS_ConvertUTF8toUTF16(headerFooterStr));
 
   headerFooterStr = [self headerFooterStringForList:mFooterCenterList];
-  mSettings->SetFooterStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr).get());
+  mSettings->SetFooterStrCenter(NS_ConvertUTF8toUTF16(headerFooterStr));
 
   headerFooterStr = [self headerFooterStringForList:mFooterRightList];
-  mSettings->SetFooterStrRight(NS_ConvertUTF8toUTF16(headerFooterStr).get());
+  mSettings->SetFooterStrRight(NS_ConvertUTF8toUTF16(headerFooterStr));
 }
 
 // Summary
 
 - (NSString*)summaryValueForCheckbox:(NSButton*)aCheckbox
 {
   if (![aCheckbox isEnabled])
     return [self localizedString:"summaryNAValue"];
--- a/widget/cocoa/nsPrintSettingsX.h
+++ b/widget/cocoa/nsPrintSettingsX.h
@@ -63,17 +63,17 @@ public:
   nsresult InitAdjustedPaperSize();
 
   void SetInchesScale(float aWidthScale, float aHeightScale);
   void GetInchesScale(float *aWidthScale, float *aHeightScale);
 
   NS_IMETHOD SetScaling(double aScaling) override;
   NS_IMETHOD GetScaling(double *aScaling) override;
 
-  NS_IMETHOD SetToFileName(const char16_t * aToFileName) override;
+  NS_IMETHOD SetToFileName(const nsAString& aToFileName) override;
 
   NS_IMETHOD GetOrientation(int32_t *aOrientation) override;
   NS_IMETHOD SetOrientation(int32_t aOrientation) override;
 
   NS_IMETHOD SetUnwriteableMarginTop(double aUnwriteableMarginTop) override;
   NS_IMETHOD SetUnwriteableMarginLeft(double aUnwriteableMarginLeft) override;
   NS_IMETHOD SetUnwriteableMarginBottom(double aUnwriteableMarginBottom) override;
   NS_IMETHOD SetUnwriteableMarginRight(double aUnwriteableMarginRight) override;
--- a/widget/cocoa/nsPrintSettingsX.mm
+++ b/widget/cocoa/nsPrintSettingsX.mm
@@ -323,33 +323,32 @@ nsPrintSettingsX::GetScaling(double *aSc
   *aScaling = round(*aScaling * 100.0) / 100.0;
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsX::SetToFileName(const char16_t *aToFileName)
+nsPrintSettingsX::SetToFileName(const nsAString& aToFileName)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   if (XRE_IsContentProcess() &&
       Preferences::GetBool("print.print_via_parent")) {
     // On content sandbox, NSPrintJobSavingURL will returns error since
     // sandbox disallows file access.
     return nsPrintSettings::SetToFileName(aToFileName);
   }
 
   NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
 
-  if (aToFileName && aToFileName[0]) {
+  if (!aToFileName.IsEmpty()) {
     NSURL* jobSavingURL =
-        [NSURL fileURLWithPath: nsCocoaUtils::ToNSString(
-                                  nsDependentString(aToFileName))];
+        [NSURL fileURLWithPath: nsCocoaUtils::ToNSString(aToFileName)];
     if (jobSavingURL) {
       [printInfoDict setObject: NSPrintSaveJob forKey: NSPrintJobDisposition];
       [printInfoDict setObject: jobSavingURL forKey: NSPrintJobSavingURL];
     }
     mToFileName = aToFileName;
   } else {
     mToFileName.Truncate();
   }
--- a/widget/gtk/nsDeviceContextSpecG.cpp
+++ b/widget/gtk/nsDeviceContextSpecG.cpp
@@ -58,17 +58,17 @@ public:
 
   void      FreeGlobalPrinters();
   nsresult  InitializeGlobalPrinters();
 
   bool      PrintersAreAllocated()       { return mGlobalPrinterList != nullptr; }
   uint32_t  GetNumPrinters()
     { return mGlobalPrinterList ? mGlobalPrinterList->Length() : 0; }
   nsString* GetStringAt(int32_t aInx)    { return &mGlobalPrinterList->ElementAt(aInx); }
-  void      GetDefaultPrinterName(char16_t **aDefaultPrinterName);
+  void      GetDefaultPrinterName(nsAString& aDefaultPrinterName);
 
 protected:
   GlobalPrinters() {}
 
   static GlobalPrinters mGlobalPrinters;
   static nsTArray<nsString>* mGlobalPrinterList;
 };
 
@@ -241,17 +241,17 @@ ns_release_macro(gpointer aData) {
 /* static */
 gboolean nsDeviceContextSpecGTK::PrinterEnumerator(GtkPrinter *aPrinter,
                                                    gpointer aData) {
   nsDeviceContextSpecGTK *spec = (nsDeviceContextSpecGTK*)aData;
 
   // Find the printer whose name matches the one inside the settings.
   nsString printerName;
   nsresult rv =
-    spec->mPrintSettings->GetPrinterName(getter_Copies(printerName));
+    spec->mPrintSettings->GetPrinterName(printerName);
   if (NS_SUCCEEDED(rv) && !printerName.IsVoid()) {
     NS_ConvertUTF16toUTF8 requestedName(printerName);
     const char* currentName = gtk_printer_get_name(aPrinter);
     if (requestedName.Equals(currentName)) {
       spec->mPrintSettings->SetGtkPrinter(aPrinter);
 
       // Bug 1145916 - attempting to kick off a print job for this printer
       // during this tick of the event loop will result in the printer backend
@@ -323,17 +323,17 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::En
         NewRunnableMethod("nsDeviceContextSpecGTK::EnumeratePrinters",
                           this,
                           &nsDeviceContextSpecGTK::EnumeratePrinters));
     }
   } else {
     // Handle print-to-file ourselves for the benefit of embedders
     nsString targetPath;
     nsCOMPtr<nsIFile> destFile;
-    mPrintSettings->GetToFileName(getter_Copies(targetPath));
+    mPrintSettings->GetToFileName(targetPath);
 
     nsresult rv = NS_NewLocalFile(targetPath, false, getter_AddRefs(destFile));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsAutoString destLeafName;
     rv = destFile->GetLeafName(destLeafName);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -383,28 +383,29 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::Ge
   {
     printers->AppendElement(*GlobalPrinters::GetInstance()->GetStringAt(count++));
   }
   GlobalPrinters::GetInstance()->FreeGlobalPrinters();
 
   return NS_NewAdoptingStringEnumerator(aPrinterNameList, printers);
 }
 
-NS_IMETHODIMP nsPrinterEnumeratorGTK::GetDefaultPrinterName(char16_t **aDefaultPrinterName)
+NS_IMETHODIMP nsPrinterEnumeratorGTK::GetDefaultPrinterName(nsAString& aDefaultPrinterName)
 {
   DO_PR_DEBUG_LOG(("nsPrinterEnumeratorGTK::GetDefaultPrinterName()\n"));
-  NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
 
   GlobalPrinters::GetInstance()->GetDefaultPrinterName(aDefaultPrinterName);
 
-  DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n", NS_ConvertUTF16toUTF8(*aDefaultPrinterName).get()));
+  DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n", NS_ConvertUTF16toUTF8(aDefaultPrinterName).get()));
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const char16_t *aPrinterName, nsIPrintSettings *aPrintSettings)
+NS_IMETHODIMP
+nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const nsAString& aPrinterName,
+                                                     nsIPrintSettings *aPrintSettings)
 {
   DO_PR_DEBUG_LOG(("nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter()"));
 
   NS_ENSURE_ARG_POINTER(aPrintSettings);
 
   /* Set filename */
   nsAutoCString filename;
   const char *path;
@@ -413,17 +414,17 @@ NS_IMETHODIMP nsPrinterEnumeratorGTK::In
     path = PR_GetEnv("HOME");
   
   if (path)
     filename = nsPrintfCString("%s/mozilla.pdf", path);
   else
     filename.AssignLiteral("mozilla.pdf");
 
   DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get()));
-  aPrintSettings->SetToFileName(NS_ConvertUTF8toUTF16(filename).get());
+  aPrintSettings->SetToFileName(NS_ConvertUTF8toUTF16(filename));
 
   aPrintSettings->SetIsInitializedFromPrinter(true);
 
   return NS_OK;    
 }
 
 //----------------------------------------------------------------------
 nsresult GlobalPrinters::InitializeGlobalPrinters ()
@@ -465,32 +466,32 @@ void GlobalPrinters::FreeGlobalPrinters(
 {
   if (mGlobalPrinterList) {
     delete mGlobalPrinterList;
     mGlobalPrinterList = nullptr;
   }  
 }
 
 void 
-GlobalPrinters::GetDefaultPrinterName(char16_t **aDefaultPrinterName)
+GlobalPrinters::GetDefaultPrinterName(nsAString& aDefaultPrinterName)
 {
-  *aDefaultPrinterName = nullptr;
+  aDefaultPrinterName.Truncate();
   
   bool allocate = !GlobalPrinters::GetInstance()->PrintersAreAllocated();
   
   if (allocate) {
     nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters();
     if (NS_FAILED(rv)) {
       return;
     }
   }
   NS_ASSERTION(GlobalPrinters::GetInstance()->PrintersAreAllocated(), "no GlobalPrinters");
 
   if (GlobalPrinters::GetInstance()->GetNumPrinters() == 0)
     return;
   
-  *aDefaultPrinterName = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(0));
+  aDefaultPrinterName = *GlobalPrinters::GetInstance()->GetStringAt(0);
 
   if (allocate) {  
     GlobalPrinters::GetInstance()->FreeGlobalPrinters();
   }  
 }
 
--- a/widget/gtk/nsPrintDialogGTK.cpp
+++ b/widget/gtk/nsPrintDialogGTK.cpp
@@ -272,38 +272,38 @@ nsPrintDialogWidgetGTK::nsPrintDialogWid
   GtkWidget* header_footer_container = gtk_alignment_new(0, 0, 0, 0);
   gtk_alignment_set_padding(GTK_ALIGNMENT(header_footer_container), 8, 0, 12, 0);
 
 
   // --- Table for making the header and footer options ---
   GtkWidget* header_footer_table = gtk_table_new(3, 3, FALSE); // 3x3 table
   nsString header_footer_str[3];
 
-  aSettings->GetHeaderStrLeft(getter_Copies(header_footer_str[0]));
-  aSettings->GetHeaderStrCenter(getter_Copies(header_footer_str[1]));
-  aSettings->GetHeaderStrRight(getter_Copies(header_footer_str[2]));
+  aSettings->GetHeaderStrLeft(header_footer_str[0]);
+  aSettings->GetHeaderStrCenter(header_footer_str[1]);
+  aSettings->GetHeaderStrRight(header_footer_str[2]);
 
   for (unsigned int i = 0; i < ArrayLength(header_dropdown); i++) {
     header_dropdown[i] = ConstructHeaderFooterDropdown(header_footer_str[i].get());
     // Those 4 magic numbers in the middle provide the position in the table.
     // The last two numbers mean 2 px padding on every side.
     gtk_table_attach(GTK_TABLE(header_footer_table), header_dropdown[i], i, (i + 1),
                      0, 1, (GtkAttachOptions) 0, (GtkAttachOptions) 0, 2, 2);
   }
 
   const char labelKeys[][7] = {"left", "center", "right"};
   for (unsigned int i = 0; i < ArrayLength(labelKeys); i++) {
     gtk_table_attach(GTK_TABLE(header_footer_table),
                      gtk_label_new(GetUTF8FromBundle(labelKeys[i]).get()),
                      i, (i + 1), 1, 2, (GtkAttachOptions) 0, (GtkAttachOptions) 0, 2, 2);
   }
 
-  aSettings->GetFooterStrLeft(getter_Copies(header_footer_str[0]));
-  aSettings->GetFooterStrCenter(getter_Copies(header_footer_str[1]));
-  aSettings->GetFooterStrRight(getter_Copies(header_footer_str[2]));
+  aSettings->GetFooterStrLeft(header_footer_str[0]);
+  aSettings->GetFooterStrCenter(header_footer_str[1]);
+  aSettings->GetFooterStrRight(header_footer_str[2]);
 
   for (unsigned int i = 0; i < ArrayLength(footer_dropdown); i++) {
     footer_dropdown[i] = ConstructHeaderFooterDropdown(header_footer_str[i].get());
     gtk_table_attach(GTK_TABLE(header_footer_table), footer_dropdown[i], i, (i + 1),
                      2, 3, (GtkAttachOptions) 0, (GtkAttachOptions) 0, 2, 2);
   }
   // ---
 
@@ -366,32 +366,32 @@ nsPrintDialogWidgetGTK::ExportFramePrint
     aNS->SetPrintFrameType(nsIPrintSettings::kNoFrames);
 }
 
 void
 nsPrintDialogWidgetGTK::ExportHeaderFooter(nsIPrintSettings *aNS)
 {
   const char* header_footer_str;
   header_footer_str = OptionWidgetToString(header_dropdown[0]);
-  aNS->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(header_footer_str).get());
+  aNS->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(header_footer_str));
 
   header_footer_str = OptionWidgetToString(header_dropdown[1]);
-  aNS->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(header_footer_str).get());
+  aNS->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(header_footer_str));
 
   header_footer_str = OptionWidgetToString(header_dropdown[2]);
-  aNS->SetHeaderStrRight(NS_ConvertUTF8toUTF16(header_footer_str).get());
+  aNS->SetHeaderStrRight(NS_ConvertUTF8toUTF16(header_footer_str));
 
   header_footer_str = OptionWidgetToString(footer_dropdown[0]);
-  aNS->SetFooterStrLeft(NS_ConvertUTF8toUTF16(header_footer_str).get());
+  aNS->SetFooterStrLeft(NS_ConvertUTF8toUTF16(header_footer_str));
 
   header_footer_str = OptionWidgetToString(footer_dropdown[1]);
-  aNS->SetFooterStrCenter(NS_ConvertUTF8toUTF16(header_footer_str).get());
+  aNS->SetFooterStrCenter(NS_ConvertUTF8toUTF16(header_footer_str));
 
   header_footer_str = OptionWidgetToString(footer_dropdown[2]);
-  aNS->SetFooterStrRight(NS_ConvertUTF8toUTF16(header_footer_str).get());
+  aNS->SetFooterStrRight(NS_ConvertUTF8toUTF16(header_footer_str));
 }
 
 nsresult
 nsPrintDialogWidgetGTK::ImportSettings(nsIPrintSettings *aNSSettings)
 {
   NS_PRECONDITION(aNSSettings, "aSettings must not be null");
   NS_ENSURE_TRUE(aNSSettings, NS_ERROR_FAILURE);
 
@@ -578,20 +578,20 @@ nsPrintDialogServiceGTK::ShowPageSetup(n
   nsCOMPtr<nsPrintSettingsGTK> aNSSettingsGTK(do_QueryInterface(aNSSettings));
   if (!aNSSettingsGTK)
     return NS_ERROR_FAILURE;
 
   // We need to init the prefs here because aNSSettings in its current form is a dummy in both uses of the word
   nsCOMPtr<nsIPrintSettingsService> psService = do_GetService("@mozilla.org/gfx/printsettings-service;1");
   if (psService) {
     nsString printName;
-    aNSSettings->GetPrinterName(getter_Copies(printName));
+    aNSSettings->GetPrinterName(printName);
     if (printName.IsVoid()) {
-      psService->GetDefaultPrinterName(getter_Copies(printName));
-      aNSSettings->SetPrinterName(printName.get());
+      psService->GetDefaultPrinterName(printName);
+      aNSSettings->SetPrinterName(printName);
     }
     psService->InitPrintSettingsFromPrefs(aNSSettings, true, nsIPrintSettings::kInitSaveAll);
   }
 
   GtkPrintSettings* gtkSettings = aNSSettingsGTK->GetGtkPrintSettings();
   GtkPageSetup* oldPageSetup = aNSSettingsGTK->GetGtkPageSetup();
 
   GtkPageSetup* newPageSetup = gtk_print_run_page_setup_dialog(gtkParent, oldPageSetup, gtkSettings);
--- a/widget/gtk/nsPrintSettingsGTK.cpp
+++ b/widget/gtk/nsPrintSettingsGTK.cpp
@@ -404,93 +404,86 @@ nsPrintSettingsGTK::SetOrientation(int32
     gtkOrient = GTK_PAGE_ORIENTATION_PORTRAIT;
 
   gtk_print_settings_set_orientation(mPrintSettings, gtkOrient);
   gtk_page_setup_set_orientation(mPageSetup, gtkOrient);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetToFileName(char16_t * *aToFileName)
+nsPrintSettingsGTK::GetToFileName(nsAString& aToFileName)
 {
   // Get the gtk output filename
   const char* gtk_output_uri = gtk_print_settings_get(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI);
   if (!gtk_output_uri) {
-    *aToFileName = ToNewUnicode(mToFileName);
+    aToFileName = mToFileName;
     return NS_OK;
   }
 
   // Convert to an nsIFile
   nsCOMPtr<nsIFile> file;
   nsresult rv = NS_GetFileFromURLSpec(nsDependentCString(gtk_output_uri),
                                       getter_AddRefs(file));
   if (NS_FAILED(rv))
     return rv;
 
   // Extract the path
-  nsAutoString path;
-  rv = file->GetPath(path);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  *aToFileName = ToNewUnicode(path);
-  return NS_OK;
+  return file->GetPath(aToFileName);
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetToFileName(const char16_t * aToFileName)
+nsPrintSettingsGTK::SetToFileName(const nsAString& aToFileName)
 {
-  if (aToFileName[0] == 0) {
+  if (aToFileName.IsEmpty()) {
     mToFileName.SetLength(0);
     gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI,
                            nullptr);
     return NS_OK;
   }
 
-  if (StringEndsWith(nsDependentString(aToFileName), NS_LITERAL_STRING(".ps"))) {
+  if (StringEndsWith(aToFileName, NS_LITERAL_STRING(".ps"))) {
     gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "ps");
   } else {
     gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT, "pdf");
   }
 
   nsCOMPtr<nsIFile> file;
-  nsresult rv = NS_NewLocalFile(nsDependentString(aToFileName), true,
-                                getter_AddRefs(file));
+  nsresult rv = NS_NewLocalFile(aToFileName, true, getter_AddRefs(file));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Convert the nsIFile to a URL
   nsAutoCString url;
   rv = NS_GetURLSpecFromFile(file, url);
   NS_ENSURE_SUCCESS(rv, rv);
 
   gtk_print_settings_set(mPrintSettings, GTK_PRINT_SETTINGS_OUTPUT_URI, url.get());
   mToFileName = aToFileName;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetPrinterName(char16_t * *aPrinter)
+nsPrintSettingsGTK::GetPrinterName(nsAString& aPrinter)
 {
   const char* gtkPrintName = gtk_print_settings_get_printer(mPrintSettings);
   if (!gtkPrintName) {
     if (GTK_IS_PRINTER(mGTKPrinter)) {
       gtkPrintName = gtk_printer_get_name(mGTKPrinter);
     } else {
       // This mimics what nsPrintSettingsImpl does when we try to Get before we Set
-      nsString nullPrintName;
-      *aPrinter = ToNewUnicode(nullPrintName);
+      aPrinter.Truncate();
       return NS_OK;
     }
   }
-  *aPrinter = UTF8ToNewUnicode(nsDependentCString(gtkPrintName));
+  aPrinter = NS_ConvertUTF8toUTF16(gtkPrintName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetPrinterName(const char16_t * aPrinter)
+nsPrintSettingsGTK::SetPrinterName(const nsAString& aPrinter)
 {
   NS_ConvertUTF16toUTF8 gtkPrinter(aPrinter);
 
   if (StringBeginsWith(gtkPrinter, NS_LITERAL_CSTRING("CUPS/"))) {
     // Strip off "CUPS/"; GTK might recognize the rest
     gtkPrinter.Cut(0, strlen("CUPS/"));
   }
 
@@ -532,26 +525,25 @@ nsPrintSettingsGTK::GetScaling(double *a
 NS_IMETHODIMP
 nsPrintSettingsGTK::SetScaling(double aScaling)
 {
   gtk_print_settings_set_scale(mPrintSettings, aScaling * 100.0);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrintSettingsGTK::GetPaperName(char16_t * *aPaperName)
+nsPrintSettingsGTK::GetPaperName(nsAString& aPaperName)
 {
-  NS_ENSURE_ARG_POINTER(aPaperName);
   const gchar* name =
     gtk_paper_size_get_name(gtk_page_setup_get_paper_size(mPageSetup));
-  *aPaperName = ToNewUnicode(NS_ConvertUTF8toUTF16(name));
+  aPaperName = NS_ConvertUTF8toUTF16(name);
   return NS_OK;
 }
 NS_IMETHODIMP
-nsPrintSettingsGTK::SetPaperName(const char16_t * aPaperName)
+nsPrintSettingsGTK::SetPaperName(const nsAString& aPaperName)
 {
   NS_ConvertUTF16toUTF8 gtkPaperName(aPaperName);
 
   // Convert these Gecko names to GTK names
   if (gtkPaperName.EqualsIgnoreCase("letter"))
     gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LETTER);
   else if (gtkPaperName.EqualsIgnoreCase("legal"))
     gtkPaperName.AssignLiteral(GTK_PAPER_NAME_LEGAL);
--- a/widget/gtk/nsPrintSettingsGTK.h
+++ b/widget/gtk/nsPrintSettingsGTK.h
@@ -63,34 +63,34 @@ public:
   NS_IMETHOD SetPrintReversed(bool aPrintReversed) override;
 
   NS_IMETHOD GetPrintInColor(bool *aPrintInColor) override;
   NS_IMETHOD SetPrintInColor(bool aPrintInColor) override;
 
   NS_IMETHOD GetOrientation(int32_t *aOrientation) override;
   NS_IMETHOD SetOrientation(int32_t aOrientation) override;
 
-  NS_IMETHOD GetToFileName(char16_t * *aToFileName) override;
-  NS_IMETHOD SetToFileName(const char16_t * aToFileName) override;
+  NS_IMETHOD GetToFileName(nsAString& aToFileName) override;
+  NS_IMETHOD SetToFileName(const nsAString& aToFileName) override;
 
   // Gets/Sets the printer name in the GtkPrintSettings. If no printer name is specified there,
   // you will get back the name of the current internal GtkPrinter.
-  NS_IMETHOD GetPrinterName(char16_t * *aPrinter) override;
-  NS_IMETHOD SetPrinterName(const char16_t * aPrinter) override;
+  NS_IMETHOD GetPrinterName(nsAString& Printer) override;
+  NS_IMETHOD SetPrinterName(const nsAString& aPrinter) override;
 
   // Number of copies is stored/gotten from the GtkPrintSettings.
   NS_IMETHOD GetNumCopies(int32_t *aNumCopies) override;
   NS_IMETHOD SetNumCopies(int32_t aNumCopies) override;
 
   NS_IMETHOD GetScaling(double *aScaling) override;
   NS_IMETHOD SetScaling(double aScaling) override;
 
   // A name recognised by GTK is strongly advised here, as this is used to create a GtkPaperSize.
-  NS_IMETHOD GetPaperName(char16_t * *aPaperName) override;
-  NS_IMETHOD SetPaperName(const char16_t * aPaperName) override;
+  NS_IMETHOD GetPaperName(nsAString& aPaperName) override;
+  NS_IMETHOD SetPaperName(const nsAString& aPaperName) override;
 
   NS_IMETHOD SetUnwriteableMarginInTwips(nsIntMargin& aUnwriteableMargin) override;
   NS_IMETHOD SetUnwriteableMarginTop(double aUnwriteableMarginTop) override;
   NS_IMETHOD SetUnwriteableMarginLeft(double aUnwriteableMarginLeft) override;
   NS_IMETHOD SetUnwriteableMarginBottom(double aUnwriteableMarginBottom) override;
   NS_IMETHOD SetUnwriteableMarginRight(double aUnwriteableMarginRight) override;
 
   NS_IMETHOD GetPaperWidth(double *aPaperWidth) override;
--- a/widget/nsIPrintSettings.idl
+++ b/widget/nsIPrintSettings.idl
@@ -197,51 +197,51 @@ interface nsIPrintSettings : nsISupports
   attribute double  unwriteableMarginRight;
 
   attribute double  scaling;      /* values 0.0 - 1.0 */
   attribute boolean printBGColors; /* Print Background Colors */
   attribute boolean printBGImages; /* Print Background Images */
 
   attribute short   printRange; 
 
-  attribute wstring title;
-  attribute wstring docURL;
+  attribute AString title;
+  attribute AString docURL;
 
-  attribute wstring headerStrLeft;
-  attribute wstring headerStrCenter;
-  attribute wstring headerStrRight;
+  attribute AString headerStrLeft;
+  attribute AString headerStrCenter;
+  attribute AString headerStrRight;
 
-  attribute wstring footerStrLeft;
-  attribute wstring footerStrCenter;
-  attribute wstring footerStrRight;
+  attribute AString footerStrLeft;
+  attribute AString footerStrCenter;
+  attribute AString footerStrRight;
 
   attribute short   howToEnableFrameUI;  /* indicates how to enable the frameset UI            */
   attribute boolean isCancelled;         /* indicates whether the print job has been cancelled */
   attribute short   printFrameTypeUsage; /* indicates whether to use the interal value or not  */
   attribute short   printFrameType;
   attribute boolean printSilent;	     /* print without putting up the dialog */
   attribute boolean shrinkToFit;	     /* shrinks content to fit on page      */
   attribute boolean showPrintProgress;   /* indicates whether the progress dialog should be shown */
 
   /* Additional XP Related */
-  attribute wstring paperName;     /* name of paper */
+  attribute AString paperName;     /* name of paper */
   attribute short   paperData;     /* native data value */
   attribute double  paperWidth;    /* width of the paper in inches or mm */
   attribute double  paperHeight;   /* height of the paper in inches or mm */
   attribute short   paperSizeUnit; /* paper is in inches or mm */
 
   attribute boolean printReversed;
   attribute boolean printInColor;  /* a false means grayscale */
   attribute long    orientation;   /*  see orientation consts */
   attribute long    numCopies;
 
-  attribute wstring printerName;   /* name of destination printer */
+  attribute AString printerName;   /* name of destination printer */
 
   attribute boolean printToFile;
-  attribute wstring toFileName;
+  attribute AString toFileName;
   attribute short   outputFormat;
 
   attribute long    printPageDelay; /* in milliseconds */
 
   attribute long    resolution;     /* print resolution (dpi) */
 
   attribute long    duplex;         /* duplex mode */
 
--- a/widget/nsIPrintSettingsService.idl
+++ b/widget/nsIPrintSettingsService.idl
@@ -53,27 +53,28 @@ interface nsIPrintSettingsService : nsIS
    * (Note: this may not happen if there is an OS specific implementation.)
    *
    */
   readonly attribute nsIPrintSettings newPrintSettings;
 
   /**
    * The name of the last printer used, or else the system default printer.
    */
-  readonly attribute wstring defaultPrinterName;
+  readonly attribute AString defaultPrinterName;
 
   /**
    * Initializes certain settings from the native printer into the PrintSettings
    * if aPrinterName is null then it uses the default printer name if it can
    * These settings include, but are not limited to:
    *   Page Orientation
    *   Page Size
    *   Number of Copies
    */
-  void initPrintSettingsFromPrinter(in wstring aPrinterName, in nsIPrintSettings aPrintSettings);
+  void initPrintSettingsFromPrinter(in AString aPrinterName,
+                                    in nsIPrintSettings aPrintSettings);
 
   /**
    * Reads PrintSettings values from Prefs,
    * the values to be read are indicated by the "flags" arg.
    *
    * aPrintSettings should be initialized with the name of a printer. First
    * it reads in the PrintSettings from the last print job. Then it uses the
    * PrinterName in the PrinterSettings to read any settings that were saved
--- a/widget/nsIPrintSettingsWin.idl
+++ b/widget/nsIPrintSettingsWin.idl
@@ -30,18 +30,18 @@ interface nsIPrintSettingsWin : nsISuppo
    * you own the memory.
    *
    * The following three pieces of data are needed
    * to create a DC for printing. These are typcially 
    * gotten via the PrintDLG call ro can be obtained
    * via the "m_pd" data member of the CPrintDialog
    * in MFC.
    */
-  [noscript] attribute wstring deviceName;
-  [noscript] attribute wstring driverName;
+  [noscript] attribute AString deviceName;
+  [noscript] attribute AString driverName;
 
   [noscript] attribute nsDevMode devMode;
 
   /**
    * On Windows we use the printable width and height for the printing surface.
    * We don't want to have to create native print device contexts in the content
    * process, so we need to store these in the settings.
    * Storing in Inches is most convenient as they are retrieved from the device
--- a/widget/nsIPrinterEnumerator.idl
+++ b/widget/nsIPrinterEnumerator.idl
@@ -13,25 +13,26 @@ interface nsIStringEnumerator;
 interface nsIPrinterEnumerator : nsISupports
 {
   /**
    * The name of the system default printer. This name should also be
    * present in printerNameList below. This is not necessarily gecko's
    * default printer; see nsIPrintSettingsService.defaultPrinterName
    * for that.
    */
-  readonly attribute wstring defaultPrinterName;
+  readonly attribute AString defaultPrinterName;
 
   /**
    * Initializes certain settings from the native printer into the PrintSettings
    * These settings include, but are not limited to:
    *   Page Orientation
    *   Page Size
    *   Number of Copies
    */
-  void initPrintSettingsFromPrinter(in wstring aPrinterName, in nsIPrintSettings aPrintSettings);
+  void initPrintSettingsFromPrinter(in AString aPrinterName,
+                                    in nsIPrintSettings aPrintSettings);
 
   /**
    * The list of printer names
    */
   readonly attribute nsIStringEnumerator printerNameList;
 };
 
--- a/widget/nsPrintOptionsImpl.cpp
+++ b/widget/nsPrintOptionsImpl.cpp
@@ -133,83 +133,52 @@ nsPrintOptions::SerializeToPrintData(nsI
   aSettings->GetUnwriteableMarginRight(&data->unwriteableMarginRight());
 
   aSettings->GetScaling(&data->scaling());
 
   aSettings->GetPrintBGColors(&data->printBGColors());
   aSettings->GetPrintBGImages(&data->printBGImages());
   aSettings->GetPrintRange(&data->printRange());
 
-  // I have no idea if I'm doing this string copying correctly...
-  nsString title;
-  aSettings->GetTitle(getter_Copies(title));
-  data->title() = title;
-
-  nsString docURL;
-  aSettings->GetDocURL(getter_Copies(docURL));
-  data->docURL() = docURL;
-
-  // Header strings...
-  nsString headerStrLeft;
-  aSettings->GetHeaderStrLeft(getter_Copies(headerStrLeft));
-  data->headerStrLeft() = headerStrLeft;
+  aSettings->GetTitle(data->title());
+  aSettings->GetDocURL(data->docURL());
 
-  nsString headerStrCenter;
-  aSettings->GetHeaderStrCenter(getter_Copies(headerStrCenter));
-  data->headerStrCenter() = headerStrCenter;
-
-  nsString headerStrRight;
-  aSettings->GetHeaderStrRight(getter_Copies(headerStrRight));
-  data->headerStrRight() = headerStrRight;
+  aSettings->GetHeaderStrLeft(data->headerStrLeft());
+  aSettings->GetHeaderStrCenter(data->headerStrCenter());
+  aSettings->GetHeaderStrRight(data->headerStrRight());
 
-  // Footer strings...
-  nsString footerStrLeft;
-  aSettings->GetFooterStrLeft(getter_Copies(footerStrLeft));
-  data->footerStrLeft() = footerStrLeft;
-
-  nsString footerStrCenter;
-  aSettings->GetFooterStrCenter(getter_Copies(footerStrCenter));
-  data->footerStrCenter() = footerStrCenter;
-
-  nsString footerStrRight;
-  aSettings->GetFooterStrRight(getter_Copies(footerStrRight));
-  data->footerStrRight() = footerStrRight;
+  aSettings->GetFooterStrLeft(data->footerStrLeft());
+  aSettings->GetFooterStrCenter(data->footerStrCenter());
+  aSettings->GetFooterStrRight(data->footerStrRight());
 
   aSettings->GetHowToEnableFrameUI(&data->howToEnableFrameUI());
   aSettings->GetIsCancelled(&data->isCancelled());
   aSettings->GetPrintFrameTypeUsage(&data->printFrameTypeUsage());
   aSettings->GetPrintFrameType(&data->printFrameType());
   aSettings->GetPrintSilent(&data->printSilent());
   aSettings->GetShrinkToFit(&data->shrinkToFit());
   aSettings->GetShowPrintProgress(&data->showPrintProgress());
 
-  nsString paperName;
-  aSettings->GetPaperName(getter_Copies(paperName));
-  data->paperName() = paperName;
-
+  aSettings->GetPaperName(data->paperName());
   aSettings->GetPaperData(&data->paperData());
   aSettings->GetPaperWidth(&data->paperWidth());
   aSettings->GetPaperHeight(&data->paperHeight());
   aSettings->GetPaperSizeUnit(&data->paperSizeUnit());
 
   aSettings->GetPrintReversed(&data->printReversed());
   aSettings->GetPrintInColor(&data->printInColor());
   aSettings->GetOrientation(&data->orientation());
 
   aSettings->GetNumCopies(&data->numCopies());
 
-  nsString printerName;
-  aSettings->GetPrinterName(getter_Copies(printerName));
-  data->printerName() = printerName;
+  aSettings->GetPrinterName(data->printerName());
 
   aSettings->GetPrintToFile(&data->printToFile());
 
-  nsString toFileName;
-  aSettings->GetToFileName(getter_Copies(toFileName));
-  data->toFileName() = toFileName;
+  aSettings->GetToFileName(data->toFileName());
 
   aSettings->GetOutputFormat(&data->outputFormat());
   aSettings->GetPrintPageDelay(&data->printPageDelay());
   aSettings->GetResolution(&data->resolution());
   aSettings->GetDuplex(&data->duplex());
   aSettings->GetIsInitializedFromPrinter(&data->isInitializedFromPrinter());
   aSettings->GetIsInitializedFromPrefs(&data->isInitializedFromPrefs());
 
@@ -271,56 +240,55 @@ nsPrintOptions::DeserializeToPrintSettin
   settings->SetUnwriteableMarginRight(data.unwriteableMarginRight());
 
   settings->SetScaling(data.scaling());
 
   settings->SetPrintBGColors(data.printBGColors());
   settings->SetPrintBGImages(data.printBGImages());
   settings->SetPrintRange(data.printRange());
 
-  // I have no idea if I'm doing this string copying correctly...
-  settings->SetTitle(data.title().get());
-  settings->SetDocURL(data.docURL().get());
+  settings->SetTitle(data.title());
+  settings->SetDocURL(data.docURL());
 
   // Header strings...
-  settings->SetHeaderStrLeft(data.headerStrLeft().get());
-  settings->SetHeaderStrCenter(data.headerStrCenter().get());
-  settings->SetHeaderStrRight(data.headerStrRight().get());
+  settings->SetHeaderStrLeft(data.headerStrLeft());
+  settings->SetHeaderStrCenter(data.headerStrCenter());
+  settings->SetHeaderStrRight(data.headerStrRight());
 
   // Footer strings...
-  settings->SetFooterStrLeft(data.footerStrLeft().get());
-  settings->SetFooterStrCenter(data.footerStrCenter().get());
-  settings->SetFooterStrRight(data.footerStrRight().get());
+  settings->SetFooterStrLeft(data.footerStrLeft());
+  settings->SetFooterStrCenter(data.footerStrCenter());
+  settings->SetFooterStrRight(data.footerStrRight());
 
   settings->SetHowToEnableFrameUI(data.howToEnableFrameUI());
   settings->SetIsCancelled(data.isCancelled());
   settings->SetPrintFrameTypeUsage(data.printFrameTypeUsage());
   settings->SetPrintFrameType(data.printFrameType());
   settings->SetPrintSilent(data.printSilent());
   settings->SetShrinkToFit(data.shrinkToFit());
   settings->SetShowPrintProgress(data.showPrintProgress());
 
-  settings->SetPaperName(data.paperName().get());
+  settings->SetPaperName(data.paperName());
 
   settings->SetPaperData(data.paperData());
   settings->SetPaperWidth(data.paperWidth());
   settings->SetPaperHeight(data.paperHeight());
   settings->SetPaperSizeUnit(data.paperSizeUnit());
 
   settings->SetPrintReversed(data.printReversed());
   settings->SetPrintInColor(data.printInColor());
   settings->SetOrientation(data.orientation());
 
   settings->SetNumCopies(data.numCopies());
 
-  settings->SetPrinterName(data.printerName().get());
+  settings->SetPrinterName(data.printerName());
 
   settings->SetPrintToFile(data.printToFile());
 
-  settings->SetToFileName(data.toFileName().get());
+  settings->SetToFileName(data.toFileName());
 
   settings->SetOutputFormat(data.outputFormat());
   settings->SetPrintPageDelay(data.printPageDelay());
   settings->SetResolution(data.resolution());
   settings->SetDuplex(data.duplex());
   settings->SetIsInitializedFromPrinter(data.isInitializedFromPrinter());
   settings->SetIsInitializedFromPrefs(data.isInitializedFromPrefs());
 
@@ -528,17 +496,17 @@ nsPrintOptions::ReadPrefs(nsIPrintSettin
 
     if (success) {
       aPS->SetPaperSizeUnit(sizeUnit);
       DUMP_INT(kReadStr, kPrintPaperSizeUnit, sizeUnit);
       aPS->SetPaperWidth(width);
       DUMP_DBL(kReadStr, kPrintPaperWidth, width);
       aPS->SetPaperHeight(height);
       DUMP_DBL(kReadStr, kPrintPaperHeight, height);
-      aPS->SetPaperName(str.get());
+      aPS->SetPaperName(str);
       DUMP_STR(kReadStr, kPrintPaperName, str.get());
 #if defined(XP_WIN)
       if (saveSanitizedSizePrefs) {
         SavePrintSettingsToPrefs(aPS, !aPrinterName.IsEmpty(),
                                  nsIPrintSettings::kInitSavePaperSize);
       }
 #endif
     }
@@ -555,52 +523,52 @@ nsPrintOptions::ReadPrefs(nsIPrintSettin
     if (GETBOOLPREF(kPrintOddPages, &b)) {
       aPS->SetPrintOptions(nsIPrintSettings::kPrintOddPages, b);
       DUMP_BOOL(kReadStr, kPrintOddPages, b);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveHeaderLeft) {
     if (GETSTRPREF(kPrintHeaderStrLeft, str)) {
-      aPS->SetHeaderStrLeft(str.get());
+      aPS->SetHeaderStrLeft(str);
       DUMP_STR(kReadStr, kPrintHeaderStrLeft, str.get());
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveHeaderCenter) {
     if (GETSTRPREF(kPrintHeaderStrCenter, str)) {
-      aPS->SetHeaderStrCenter(str.get());
+      aPS->SetHeaderStrCenter(str);
       DUMP_STR(kReadStr, kPrintHeaderStrCenter, str.get());
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveHeaderRight) {
     if (GETSTRPREF(kPrintHeaderStrRight, str)) {
-      aPS->SetHeaderStrRight(str.get());
+      aPS->SetHeaderStrRight(str);
       DUMP_STR(kReadStr, kPrintHeaderStrRight, str.get());
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveFooterLeft) {
     if (GETSTRPREF(kPrintFooterStrLeft, str)) {
-      aPS->SetFooterStrLeft(str.get());
+      aPS->SetFooterStrLeft(str);
       DUMP_STR(kReadStr, kPrintFooterStrLeft, str.get());
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveFooterCenter) {
     if (GETSTRPREF(kPrintFooterStrCenter, str)) {
-      aPS->SetFooterStrCenter(str.get());
+      aPS->SetFooterStrCenter(str);
       DUMP_STR(kReadStr, kPrintFooterStrCenter, str.get());
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveFooterRight) {
     if (GETSTRPREF(kPrintFooterStrRight, str)) {
-      aPS->SetFooterStrRight(str.get());
+      aPS->SetFooterStrRight(str);
       DUMP_STR(kReadStr, kPrintFooterStrRight, str.get());
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveBGColors) {
     if (GETBOOLPREF(kPrintBGColors, &b)) {
       aPS->SetPrintBGColors(b);
       DUMP_BOOL(kReadStr, kPrintBGColors, b);
@@ -646,17 +614,17 @@ nsPrintOptions::ReadPrefs(nsIPrintSettin
     if (GETBOOLPREF(kPrintToFile, &b)) {
       aPS->SetPrintToFile(b);
       DUMP_BOOL(kReadStr, kPrintToFile, b);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveToFileName) {
     if (GETSTRPREF(kPrintToFileName, str)) {
-      aPS->SetToFileName(str.get());
+      aPS->SetToFileName(str);
       DUMP_STR(kReadStr, kPrintToFileName, str.get());
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSavePageDelay) {
     if (GETINTPREF(kPrintPageDelay, &iVal)) {
       aPS->SetPrintPageDelay(iVal);
       DUMP_INT(kReadStr, kPrintPageDelay, iVal);
@@ -766,17 +734,17 @@ nsPrintOptions::WritePrefs(nsIPrintSetti
     int16_t sizeUnit;
     double width, height;
     nsString name;
 
     if (
       NS_SUCCEEDED(aPS->GetPaperSizeUnit(&sizeUnit)) &&
       NS_SUCCEEDED(aPS->GetPaperWidth(&width)) &&
       NS_SUCCEEDED(aPS->GetPaperHeight(&height)) &&
-      NS_SUCCEEDED(aPS->GetPaperName(getter_Copies(name)))
+      NS_SUCCEEDED(aPS->GetPaperName(name))
     ) {
       DUMP_INT(kWriteStr, kPrintPaperSizeUnit, sizeUnit);
       Preferences::SetInt(GetPrefName(kPrintPaperSizeUnit, aPrinterName),
                           int32_t(sizeUnit));
       DUMP_DBL(kWriteStr, kPrintPaperWidth, width);
       WritePrefDouble(GetPrefName(kPrintPaperWidth, aPrinterName), width);
       DUMP_DBL(kWriteStr, kPrintPaperHeight, height);
       WritePrefDouble(GetPrefName(kPrintPaperHeight, aPrinterName), height);
@@ -817,57 +785,57 @@ nsPrintOptions::WritePrefs(nsIPrintSetti
     if (NS_SUCCEEDED(aPS->GetPrintOptions(nsIPrintSettings::kPrintOddPages,
                                           &b))) {
           DUMP_BOOL(kWriteStr, kPrintOddPages, b);
           Preferences::SetBool(GetPrefName(kPrintOddPages, aPrinterName), b);
         }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveHeaderLeft) {
-    if (NS_SUCCEEDED(aPS->GetHeaderStrLeft(getter_Copies(uStr)))) {
+    if (NS_SUCCEEDED(aPS->GetHeaderStrLeft(uStr))) {
       DUMP_STR(kWriteStr, kPrintHeaderStrLeft, uStr.get());
       Preferences::SetString(GetPrefName(kPrintHeaderStrLeft, aPrinterName),
                              uStr);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveHeaderCenter) {
-    if (NS_SUCCEEDED(aPS->GetHeaderStrCenter(getter_Copies(uStr)))) {
+    if (NS_SUCCEEDED(aPS->GetHeaderStrCenter(uStr))) {
       DUMP_STR(kWriteStr, kPrintHeaderStrCenter, uStr.get());
       Preferences::SetString(GetPrefName(kPrintHeaderStrCenter, aPrinterName),
                              uStr);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveHeaderRight) {
-    if (NS_SUCCEEDED(aPS->GetHeaderStrRight(getter_Copies(uStr)))) {
+    if (NS_SUCCEEDED(aPS->GetHeaderStrRight(uStr))) {
       DUMP_STR(kWriteStr, kPrintHeaderStrRight, uStr.get());
       Preferences::SetString(GetPrefName(kPrintHeaderStrRight, aPrinterName),
                              uStr);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveFooterLeft) {
-    if (NS_SUCCEEDED(aPS->GetFooterStrLeft(getter_Copies(uStr)))) {
+    if (NS_SUCCEEDED(aPS->GetFooterStrLeft(uStr))) {
       DUMP_STR(kWriteStr, kPrintFooterStrLeft, uStr.get());
       Preferences::SetString(GetPrefName(kPrintFooterStrLeft, aPrinterName),
                              uStr);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveFooterCenter) {
-    if (NS_SUCCEEDED(aPS->GetFooterStrCenter(getter_Copies(uStr)))) {
+    if (NS_SUCCEEDED(aPS->GetFooterStrCenter(uStr))) {
       DUMP_STR(kWriteStr, kPrintFooterStrCenter, uStr.get());
       Preferences::SetString(GetPrefName(kPrintFooterStrCenter, aPrinterName),
                              uStr);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveFooterRight) {
-    if (NS_SUCCEEDED(aPS->GetFooterStrRight(getter_Copies(uStr)))) {
+    if (NS_SUCCEEDED(aPS->GetFooterStrRight(uStr))) {
       DUMP_STR(kWriteStr, kPrintFooterStrRight, uStr.get());
       Preferences::SetString(GetPrefName(kPrintFooterStrRight, aPrinterName),
                              uStr);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveBGColors) {
     if (NS_SUCCEEDED(aPS->GetPrintBGColors(&b))) {
@@ -910,31 +878,31 @@ nsPrintOptions::WritePrefs(nsIPrintSetti
       DUMP_INT(kWriteStr, kPrintOrientation, iVal);
       Preferences::SetInt(GetPrefName(kPrintOrientation, aPrinterName), iVal);
     }
   }
 
   // Only the general version of this pref is saved
   if ((aFlags & nsIPrintSettings::kInitSavePrinterName)
       && aPrinterName.IsEmpty()) {
-    if (NS_SUCCEEDED(aPS->GetPrinterName(getter_Copies(uStr)))) {
+    if (NS_SUCCEEDED(aPS->GetPrinterName(uStr))) {
       DUMP_STR(kWriteStr, kPrinterName, uStr.get());
       Preferences::SetString(kPrinterName, uStr);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSavePrintToFile) {
     if (NS_SUCCEEDED(aPS->GetPrintToFile(&b))) {
       DUMP_BOOL(kWriteStr, kPrintToFile, b);
       Preferences::SetBool(GetPrefName(kPrintToFile, aPrinterName), b);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveToFileName) {
-    if (NS_SUCCEEDED(aPS->GetToFileName(getter_Copies(uStr)))) {
+    if (NS_SUCCEEDED(aPS->GetToFileName(uStr))) {
       DUMP_STR(kWriteStr, kPrintToFileName, uStr.get());
       Preferences::SetString(GetPrefName(kPrintToFileName, aPrinterName), uStr);
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSavePageDelay) {
     if (NS_SUCCEEDED(aPS->GetPrintPageDelay(&iVal))) {
       DUMP_INT(kWriteStr, kPrintPageDelay, iVal);
@@ -980,19 +948,19 @@ nsresult nsPrintOptions::_CreatePrintSet
 {
   // does not initially ref count
   nsPrintSettings * printSettings = new nsPrintSettings();
   NS_ENSURE_TRUE(printSettings, NS_ERROR_OUT_OF_MEMORY);
 
   NS_ADDREF(*_retval = printSettings); // ref count
 
   nsString printerName;
-  nsresult rv = GetDefaultPrinterName(getter_Copies(printerName));
+  nsresult rv = GetDefaultPrinterName(printerName);
   NS_ENSURE_SUCCESS(rv, rv);
-  (*_retval)->SetPrinterName(printerName.get());
+  (*_retval)->SetPrinterName(printerName);
 
   (void)InitPrintSettingsFromPrefs(*_retval, false,
                                    nsIPrintSettings::kInitSaveAll);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -1010,17 +978,17 @@ nsPrintOptions::GetGlobalPrintSettings(n
 
 NS_IMETHODIMP
 nsPrintOptions::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings)
 {
   return _CreatePrintSettings(aNewPrintSettings);
 }
 
 NS_IMETHODIMP
-nsPrintOptions::GetDefaultPrinterName(char16_t * *aDefaultPrinterName)
+nsPrintOptions::GetDefaultPrinterName(nsAString& aDefaultPrinterName)
 {
   nsresult rv;
   nsCOMPtr<nsIPrinterEnumerator> prtEnum =
            do_GetService(NS_PRINTER_ENUMERATOR_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Look up the printer from the last print job
   nsAutoString lastPrinterName;
@@ -1035,43 +1003,42 @@ nsPrintOptions::GetDefaultPrinterName(ch
       while (NS_SUCCEEDED(printers->HasMore(&hasMore)) && hasMore) {
         nsAutoString printer;
         if (NS_SUCCEEDED(printers->GetNext(printer)) && lastPrinterName.Equals(printer)) {
           isValid = true;
           break;
         }
       }
       if (isValid) {
-        *aDefaultPrinterName = ToNewUnicode(lastPrinterName);
+        aDefaultPrinterName = lastPrinterName;
         return NS_OK;
       }
     }
   }
 
   // There is no last printer preference, or it doesn't name a valid printer.
   // Return the default from the printer enumeration.
   return prtEnum->GetDefaultPrinterName(aDefaultPrinterName);
 }
 
 NS_IMETHODIMP
-nsPrintOptions::InitPrintSettingsFromPrinter(const char16_t *aPrinterName,
+nsPrintOptions::InitPrintSettingsFromPrinter(const nsAString& aPrinterName,
                                              nsIPrintSettings *aPrintSettings)
 {
   // Don't get print settings from the printer in the child when printing via
   // parent, these will be retrieved in the parent later in the print process.
   if (XRE_IsContentProcess() && Preferences::GetBool("print.print_via_parent")) {
     return NS_OK;
   }
 
   NS_ENSURE_ARG_POINTER(aPrintSettings);
-  NS_ENSURE_ARG_POINTER(aPrinterName);
 
 #ifdef DEBUG
   nsString printerName;
-  aPrintSettings->GetPrinterName(getter_Copies(printerName));
+  aPrintSettings->GetPrinterName(printerName);
   if (!printerName.Equals(aPrinterName)) {
     NS_WARNING("Printer names should match!");
   }
 #endif
 
   bool isInitialized;
   aPrintSettings->GetIsInitializedFromPrinter(&isInitialized);
   if (isInitialized)
@@ -1100,17 +1067,17 @@ GetAdjustedPrinterName(nsIPrintSettings*
   NS_ENSURE_ARG_POINTER(aPS);
 
   aPrinterName.Truncate();
   if (!aUsePNP)
     return NS_OK;
 
   // Get the Printer Name from the PrintSettings
   // to use as a prefix for Pref Names
-  nsresult rv = aPS->GetPrinterName(getter_Copies(aPrinterName));
+  nsresult rv = aPS->GetPrinterName(aPrinterName);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Convert any whitespaces, carriage returns or newlines to _
   // The below algorithm is supposedly faster than using iterators
   NS_NAMED_LITERAL_STRING(replSubstr, "_");
   const char* replaceStr = " \n\r";
 
   int32_t x;
--- a/widget/nsPrintSettingsImpl.cpp
+++ b/widget/nsPrintSettingsImpl.cpp
@@ -187,29 +187,25 @@ NS_IMETHODIMP nsPrintSettings::GetDuplex
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetDuplex(const int32_t aDuplex)
 {
   mDuplex = aDuplex;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetPrinterName(char16_t * *aPrinter)
+NS_IMETHODIMP nsPrintSettings::GetPrinterName(nsAString& aPrinter)
 {
-   NS_ENSURE_ARG_POINTER(aPrinter);
-
-   *aPrinter = ToNewUnicode(mPrinter);
-   NS_ENSURE_TRUE(*aPrinter, NS_ERROR_OUT_OF_MEMORY);
-
+   aPrinter = mPrinter;
    return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::SetPrinterName(const char16_t * aPrinter)
+NS_IMETHODIMP nsPrintSettings::SetPrinterName(const nsAString& aPrinter)
 {
-  if (!aPrinter || !mPrinter.Equals(aPrinter)) {
+  if (!mPrinter.Equals(aPrinter)) {
     mIsInitedFromPrinter = false;
     mIsInitedFromPrefs   = false;
   }
 
   mPrinter.Assign(aPrinter);
   return NS_OK;
 }
 
@@ -232,29 +228,24 @@ NS_IMETHODIMP nsPrintSettings::GetPrintT
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetPrintToFile(bool aPrintToFile)
 {
   mPrintToFile = aPrintToFile;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetToFileName(char16_t * *aToFileName)
+NS_IMETHODIMP nsPrintSettings::GetToFileName(nsAString& aToFileName)
 {
-  //NS_ENSURE_ARG_POINTER(aToFileName);
-  *aToFileName = ToNewUnicode(mToFileName);
+  aToFileName = mToFileName;
   return NS_OK;
 }
-NS_IMETHODIMP nsPrintSettings::SetToFileName(const char16_t * aToFileName)
+NS_IMETHODIMP nsPrintSettings::SetToFileName(const nsAString& aToFileName)
 {
-  if (aToFileName) {
-    mToFileName = aToFileName;
-  } else {
-    mToFileName.SetLength(0);
-  }
+  mToFileName = aToFileName;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPrintSettings::GetOutputFormat(int16_t *aOutputFormat)
 {
   NS_ENSURE_ARG_POINTER(aOutputFormat);
   *aOutputFormat = mOutputFormat;
   return NS_OK;
@@ -496,53 +487,35 @@ NS_IMETHODIMP nsPrintSettings::GetPrintR
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetPrintRange(int16_t aPrintRange)
 {
   mPrintRange = aPrintRange;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetTitle(char16_t * *aTitle)
+NS_IMETHODIMP nsPrintSettings::GetTitle(nsAString& aTitle)
 {
-  NS_ENSURE_ARG_POINTER(aTitle);
-  if (!mTitle.IsEmpty()) {
-    *aTitle = ToNewUnicode(mTitle);
-  } else {
-    *aTitle = nullptr;
-  }
+  aTitle = mTitle;
   return NS_OK;
 }
-NS_IMETHODIMP nsPrintSettings::SetTitle(const char16_t * aTitle)
+NS_IMETHODIMP nsPrintSettings::SetTitle(const nsAString& aTitle)
 {
-  if (aTitle) {
-    mTitle = aTitle;
-  } else {
-    mTitle.SetLength(0);
-  }
+  mTitle = aTitle;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetDocURL(char16_t * *aDocURL)
+NS_IMETHODIMP nsPrintSettings::GetDocURL(nsAString& aDocURL)
 {
-  NS_ENSURE_ARG_POINTER(aDocURL);
-  if (!mURL.IsEmpty()) {
-    *aDocURL = ToNewUnicode(mURL);
-  } else {
-    *aDocURL = nullptr;
-  }
+  aDocURL = mURL;
   return NS_OK;
 }
-NS_IMETHODIMP nsPrintSettings::SetDocURL(const char16_t * aDocURL)
+NS_IMETHODIMP nsPrintSettings::SetDocURL(const nsAString& aDocURL)
 {
-  if (aDocURL) {
-    mURL = aDocURL;
-  } else {
-    mURL.SetLength(0);
-  }
+  mURL = aDocURL;
   return NS_OK;
 }
 
 /** ---------------------------------------------------
  *  See documentation in nsPrintSettingsImpl.h
  *	@update 1/12/01 rods
  */
 NS_IMETHODIMP 
@@ -581,113 +554,80 @@ nsPrintSettings::GetPrintOptionsBits(int
 
 NS_IMETHODIMP
 nsPrintSettings::SetPrintOptionsBits(int32_t aBits)
 {
   mPrintOptions = aBits;
   return NS_OK;
 }
 
-nsresult 
-nsPrintSettings::GetMarginStrs(char16_t * *aTitle, 
-                              nsHeaderFooterEnum aType, 
-                              int16_t aJust)
+NS_IMETHODIMP nsPrintSettings::GetHeaderStrLeft(nsAString& aTitle)
 {
-  NS_ENSURE_ARG_POINTER(aTitle);
-  *aTitle = nullptr;
-  if (aType == eHeader) {
-    switch (aJust) {
-      case kJustLeft:   *aTitle = ToNewUnicode(mHeaderStrs[0]);break;
-      case kJustCenter: *aTitle = ToNewUnicode(mHeaderStrs[1]);break;
-      case kJustRight:  *aTitle = ToNewUnicode(mHeaderStrs[2]);break;
-    } //switch
-  } else {
-    switch (aJust) {
-      case kJustLeft:   *aTitle = ToNewUnicode(mFooterStrs[0]);break;
-      case kJustCenter: *aTitle = ToNewUnicode(mFooterStrs[1]);break;
-      case kJustRight:  *aTitle = ToNewUnicode(mFooterStrs[2]);break;
-    } //switch
-  }
+  aTitle = mHeaderStrs[0];
+  return NS_OK;
+}
+NS_IMETHODIMP nsPrintSettings::SetHeaderStrLeft(const nsAString& aTitle)
+{
+  mHeaderStrs[0] = aTitle;
   return NS_OK;
 }
 
-nsresult
-nsPrintSettings::SetMarginStrs(const char16_t * aTitle, 
-                              nsHeaderFooterEnum aType, 
-                              int16_t aJust)
+NS_IMETHODIMP nsPrintSettings::GetHeaderStrCenter(nsAString& aTitle)
 {
-  NS_ENSURE_ARG_POINTER(aTitle);
-  if (aType == eHeader) {
-    switch (aJust) {
-      case kJustLeft:   mHeaderStrs[0] = aTitle;break;
-      case kJustCenter: mHeaderStrs[1] = aTitle;break;
-      case kJustRight:  mHeaderStrs[2] = aTitle;break;
-    } //switch
-  } else {
-    switch (aJust) {
-      case kJustLeft:   mFooterStrs[0] = aTitle;break;
-      case kJustCenter: mFooterStrs[1] = aTitle;break;
-      case kJustRight:  mFooterStrs[2] = aTitle;break;
-    } //switch
-  }
+  aTitle = mHeaderStrs[1];
+  return NS_OK;
+}
+NS_IMETHODIMP nsPrintSettings::SetHeaderStrCenter(const nsAString& aTitle)
+{
+  mHeaderStrs[1] = aTitle;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetHeaderStrLeft(char16_t * *aTitle)
+NS_IMETHODIMP nsPrintSettings::GetHeaderStrRight(nsAString& aTitle)
 {
-  return GetMarginStrs(aTitle, eHeader, kJustLeft);
-}
-NS_IMETHODIMP nsPrintSettings::SetHeaderStrLeft(const char16_t * aTitle)
-{
-  return SetMarginStrs(aTitle, eHeader, kJustLeft);
+  aTitle = mHeaderStrs[2];
+  return NS_OK;
 }
-
-NS_IMETHODIMP nsPrintSettings::GetHeaderStrCenter(char16_t * *aTitle)
+NS_IMETHODIMP nsPrintSettings::SetHeaderStrRight(const nsAString& aTitle)
 {
-  return GetMarginStrs(aTitle, eHeader, kJustCenter);
-}
-NS_IMETHODIMP nsPrintSettings::SetHeaderStrCenter(const char16_t * aTitle)
-{
-  return SetMarginStrs(aTitle, eHeader, kJustCenter);
+  mHeaderStrs[2] = aTitle;
+  return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetHeaderStrRight(char16_t * *aTitle)
+NS_IMETHODIMP nsPrintSettings::GetFooterStrLeft(nsAString& aTitle)
 {
-  return GetMarginStrs(aTitle, eHeader, kJustRight);
+  aTitle = mFooterStrs[0];
+  return NS_OK;
 }
-NS_IMETHODIMP nsPrintSettings::SetHeaderStrRight(const char16_t * aTitle)
+NS_IMETHODIMP nsPrintSettings::SetFooterStrLeft(const nsAString& aTitle)
 {
-  return SetMarginStrs(aTitle, eHeader, kJustRight);
+  mFooterStrs[0] = aTitle;
+  return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetFooterStrLeft(char16_t * *aTitle)
+NS_IMETHODIMP nsPrintSettings::GetFooterStrCenter(nsAString& aTitle)
 {
-  return GetMarginStrs(aTitle, eFooter, kJustLeft);
+  aTitle = mFooterStrs[1];
+  return NS_OK;
 }
-NS_IMETHODIMP nsPrintSettings::SetFooterStrLeft(const char16_t * aTitle)
+NS_IMETHODIMP nsPrintSettings::SetFooterStrCenter(const nsAString& aTitle)
 {
-  return SetMarginStrs(aTitle, eFooter, kJustLeft);
+  mFooterStrs[1] = aTitle;
+  return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetFooterStrCenter(char16_t * *aTitle)
+NS_IMETHODIMP nsPrintSettings::GetFooterStrRight(nsAString& aTitle)
 {
-  return GetMarginStrs(aTitle, eFooter, kJustCenter);
-}
-NS_IMETHODIMP nsPrintSettings::SetFooterStrCenter(const char16_t * aTitle)
-{
-  return SetMarginStrs(aTitle, eFooter, kJustCenter);
+  aTitle = mFooterStrs[2];
+  return NS_OK;
 }
-
-NS_IMETHODIMP nsPrintSettings::GetFooterStrRight(char16_t * *aTitle)
+NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const nsAString& aTitle)
 {
-  return GetMarginStrs(aTitle, eFooter, kJustRight);
-}
-NS_IMETHODIMP nsPrintSettings::SetFooterStrRight(const char16_t * aTitle)
-{
-  return SetMarginStrs(aTitle, eFooter, kJustRight);
+  mFooterStrs[2] = aTitle;
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsPrintSettings::GetPrintFrameTypeUsage(int16_t *aPrintFrameTypeUsage)
 {
   NS_ENSURE_ARG_POINTER(aPrintFrameTypeUsage);
   *aPrintFrameTypeUsage = mPrintFrameTypeUsage;
   return NS_OK;
 }
@@ -740,33 +680,24 @@ NS_IMETHODIMP nsPrintSettings::GetShowPr
   return NS_OK;
 }
 NS_IMETHODIMP nsPrintSettings::SetShowPrintProgress(bool aShowPrintProgress)
 {
   mShowPrintProgress = aShowPrintProgress;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettings::GetPaperName(char16_t * *aPaperName)
+NS_IMETHODIMP nsPrintSettings::GetPaperName(nsAString& aPaperName)
 {
-  NS_ENSURE_ARG_POINTER(aPaperName);
-  if (!mPaperName.IsEmpty()) {
-    *aPaperName = ToNewUnicode(mPaperName);
-  } else {
-    *aPaperName = nullptr;
-  }
+  aPaperName = mPaperName;
   return NS_OK;
 }
-NS_IMETHODIMP nsPrintSettings::SetPaperName(const char16_t * aPaperName)
+NS_IMETHODIMP nsPrintSettings::SetPaperName(const nsAString& aPaperName)
 {
-  if (aPaperName) {
-    mPaperName = aPaperName;
-  } else {
-    mPaperName.SetLength(0);
-  }
+  mPaperName = aPaperName;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsPrintSettings::GetHowToEnableFrameUI(int16_t *aHowToEnableFrameUI)
 {
   NS_ENSURE_ARG_POINTER(aHowToEnableFrameUI);
   *aHowToEnableFrameUI = mHowToEnableFrameUI;
   return NS_OK;
--- a/widget/nsPrintSettingsImpl.h
+++ b/widget/nsPrintSettingsImpl.h
@@ -37,19 +37,16 @@ protected:
   virtual nsresult _Assign(nsIPrintSettings *aPS);
   
   typedef enum {
     eHeader,
     eFooter
   } nsHeaderFooterEnum;
 
 
-  nsresult GetMarginStrs(char16_t * *aTitle, nsHeaderFooterEnum aType, int16_t aJust);
-  nsresult SetMarginStrs(const char16_t * aTitle, nsHeaderFooterEnum aType, int16_t aJust);
-
   // Members
   nsWeakPtr     mSession; // Should never be touched by Clone or Assign
  
   // mMargin, mEdge, and mUnwriteableMargin are stored in twips
   nsIntMargin   mMargin;
   nsIntMargin   mEdge;
   nsIntMargin   mUnwriteableMargin;
 
--- a/widget/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/windows/nsDeviceContextSpecWin.cpp
@@ -63,17 +63,17 @@ public:
   static GlobalPrinters* GetInstance() { return &mGlobalPrinters; }
   ~GlobalPrinters() { FreeGlobalPrinters(); }
 
   void FreeGlobalPrinters();
 
   bool         PrintersAreAllocated() { return mPrinters != nullptr; }
   LPWSTR       GetItemFromList(int32_t aInx) { return mPrinters?mPrinters->ElementAt(aInx):nullptr; }
   nsresult     EnumeratePrinterList();
-  void         GetDefaultPrinterName(nsString& aDefaultPrinterName);
+  void         GetDefaultPrinterName(nsAString& aDefaultPrinterName);
   uint32_t     GetNumPrinters() { return mPrinters?mPrinters->Length():0; }
 
 protected:
   GlobalPrinters() {}
   nsresult EnumerateNativePrinters();
   void     ReallocatePrinters();
 
   static GlobalPrinters    mGlobalPrinters;
@@ -89,18 +89,16 @@ struct AutoFreeGlobalPrinters
   ~AutoFreeGlobalPrinters() {
     GlobalPrinters::GetInstance()->FreeGlobalPrinters();
   }
 };
 
 //----------------------------------------------------------------------------------
 nsDeviceContextSpecWin::nsDeviceContextSpecWin()
 {
-  mDriverName    = nullptr;
-  mDeviceName    = nullptr;
   mDevMode       = nullptr;
 #ifdef MOZ_ENABLE_SKIA_PDF
   mPrintViaSkPDF          = false;
   mDC                     = NULL;
   mPDFPageCount           = 0;
   mPDFCurrentPageNum      = 0;
   mPrintViaPDFInProgress  = false;
 #endif
@@ -108,46 +106,34 @@ nsDeviceContextSpecWin::nsDeviceContextS
 
 
 //----------------------------------------------------------------------------------
 
 NS_IMPL_ISUPPORTS(nsDeviceContextSpecWin, nsIDeviceContextSpec)
 
 nsDeviceContextSpecWin::~nsDeviceContextSpecWin()
 {
-  SetDeviceName(nullptr);
-  SetDriverName(nullptr);
   SetDevMode(nullptr);
 
   nsCOMPtr<nsIPrintSettingsWin> psWin(do_QueryInterface(mPrintSettings));
   if (psWin) {
-    psWin->SetDeviceName(nullptr);
-    psWin->SetDriverName(nullptr);
+    psWin->SetDeviceName(EmptyString());
+    psWin->SetDriverName(EmptyString());
     psWin->SetDevMode(nullptr);
   }
 
 #ifdef MOZ_ENABLE_SKIA_PDF
   if (mPrintViaSkPDF ) {
     CleanupPrintViaPDF();
   }
 #endif
   // Free them, we won't need them for a while
   GlobalPrinters::GetInstance()->FreeGlobalPrinters();
 }
 
-
-//------------------------------------------------------------------
-// helper
-static char16_t * GetDefaultPrinterNameFromGlobalPrinters()
-{
-  nsAutoString printerName;
-  GlobalPrinters::GetInstance()->GetDefaultPrinterName(printerName);
-  return ToNewUnicode(printerName);
-}
-
 //----------------------------------------------------------------------------------
 NS_IMETHODIMP nsDeviceContextSpecWin::Init(nsIWidget* aWidget,
                                            nsIPrintSettings* aPrintSettings,
                                            bool aIsPrintPreview)
 {
   mPrintSettings = aPrintSettings;
 
   nsresult rv = NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE;
@@ -166,91 +152,68 @@ NS_IMETHODIMP nsDeviceContextSpecWin::In
     if ((XRE_IsContentProcess() &&
          Preferences::GetBool("print.print_via_parent")) ||
         mOutputFormat == nsIPrintSettings::kOutputFormatPDF) {
       return NS_OK;
     }
 
     nsCOMPtr<nsIPrintSettingsWin> psWin(do_QueryInterface(aPrintSettings));
     if (psWin) {
-      char16_t* deviceName;
-      char16_t* driverName;
-      psWin->GetDeviceName(&deviceName); // creates new memory (makes a copy)
-      psWin->GetDriverName(&driverName); // creates new memory (makes a copy)
+      nsAutoString deviceName;
+      nsAutoString driverName;
+      psWin->GetDeviceName(deviceName);
+      psWin->GetDriverName(driverName);
 
       LPDEVMODEW devMode;
       psWin->GetDevMode(&devMode);       // creates new memory (makes a copy)
 
-      if (deviceName && driverName && devMode) {
+      if (!deviceName.IsEmpty() && !driverName.IsEmpty() && devMode) {
         // Scaling is special, it is one of the few
         // devMode items that we control in layout
         if (devMode->dmFields & DM_SCALE) {
           double scale = double(devMode->dmScale) / 100.0f;
           if (scale != 1.0) {
             aPrintSettings->SetScaling(scale);
             devMode->dmScale = 100;
           }
         }
 
         SetDeviceName(deviceName);
         SetDriverName(driverName);
         SetDevMode(devMode);
 
-        // clean up
-        free(deviceName);
-        free(driverName);
-
         return NS_OK;
       } else {
         PR_PL(("***** nsDeviceContextSpecWin::Init - deviceName/driverName/devMode was NULL!\n"));
-        if (deviceName) free(deviceName);
-        if (driverName) free(driverName);
         if (devMode) ::HeapFree(::GetProcessHeap(), 0, devMode);
       }
     }
   } else {
     PR_PL(("***** nsDeviceContextSpecWin::Init - aPrintSettingswas NULL!\n"));
   }
 
   // Get the Printer Name to be used and output format.
-  char16_t * printerName = nullptr;
+  nsAutoString printerName;
   if (mPrintSettings) {
-    mPrintSettings->GetPrinterName(&printerName);
+    mPrintSettings->GetPrinterName(printerName);
   }
 
   // If there is no name then use the default printer
-  if (!printerName || (printerName && !*printerName)) {
-    printerName = GetDefaultPrinterNameFromGlobalPrinters();
+  if (printerName.IsEmpty()) {
+    GlobalPrinters::GetInstance()->GetDefaultPrinterName(printerName);
   }
 
-  NS_ASSERTION(printerName, "We have to have a printer name");
-  if (!printerName || !*printerName) return rv;
+  if (printerName.IsEmpty()) {
+    return rv;
+  }
 
   return GetDataFromPrinter(printerName, mPrintSettings);
 }
 
 //----------------------------------------------------------
-// Helper Function - Free and reallocate the string
-static void CleanAndCopyString(wchar_t*& aStr, const wchar_t* aNewStr)
-{
-  if (aStr != nullptr) {
-    if (aNewStr != nullptr && wcslen(aStr) > wcslen(aNewStr)) { // reuse it if we can
-      wcscpy(aStr, aNewStr);
-      return;
-    } else {
-      free(aStr);
-      aStr = nullptr;
-    }
-  }
-
-  if (nullptr != aNewStr) {
-    aStr = (wchar_t*) malloc(sizeof(wchar_t) * (wcslen(aNewStr) + 1));
-    wcscpy(aStr, aNewStr);
-  }
-}
 
 already_AddRefed<PrintTarget> nsDeviceContextSpecWin::MakePrintTarget()
 {
   NS_ASSERTION(mDevMode, "DevMode can't be NULL here");
 
 #ifdef MOZ_ENABLE_SKIA_PDF
   if (mPrintViaSkPDF) {
     double width, height;
@@ -261,17 +224,17 @@ already_AddRefed<PrintTarget> nsDeviceCo
 
     // convert twips to points
     width  /= TWIPS_PER_POINT_FLOAT;
     height /= TWIPS_PER_POINT_FLOAT;
     IntSize size = IntSize::Truncate(width, height);
 
     if (mOutputFormat == nsIPrintSettings::kOutputFormatPDF) {
       nsString filename;
-      mPrintSettings->GetToFileName(getter_Copies(filename));
+      mPrintSettings->GetToFileName(filename);
 
       nsAutoCString printFile(NS_ConvertUTF16toUTF8(filename).get());
       auto skStream = MakeUnique<SkFILEWStream>(printFile.get());
       return PrintTargetSkPDF::CreateOrNull(Move(skStream), size);
     }
 
     if (mDevMode) {
       // When printing to a printer via Skia PDF we open a temporary file that
@@ -306,17 +269,17 @@ already_AddRefed<PrintTarget> nsDeviceCo
       auto skStream = MakeUnique<SkFILEWStream>(filePath.get());
       return PrintTargetSkPDF::CreateOrNull(Move(skStream), size);
     }
   }
 #endif
 
   if (mOutputFormat == nsIPrintSettings::kOutputFormatPDF) {
     nsString filename;
-    mPrintSettings->GetToFileName(getter_Copies(filename));
+    mPrintSettings->GetToFileName(filename);
 
     double width, height;
     mPrintSettings->GetEffectivePageSize(&width, &height);
     if (width <= 0 || height <= 0) {
       return nullptr;
     }
 
     // convert twips to points
@@ -334,18 +297,18 @@ already_AddRefed<PrintTarget> nsDeviceCo
     if (NS_FAILED(rv)) {
       return nullptr;
     }
 
     return PrintTargetPDF::CreateOrNull(stream, IntSize::Truncate(width, height));
   }
 
   if (mDevMode) {
-    NS_WARNING_ASSERTION(mDriverName, "No driver!");
-    HDC dc = ::CreateDCW(mDriverName, mDeviceName, nullptr, mDevMode);
+    NS_WARNING_ASSERTION(!mDriverName.IsEmpty(), "No driver!");
+    HDC dc = ::CreateDCW(mDriverName.get(), mDeviceName.get(), nullptr, mDevMode);
     if (!dc) {
       gfxCriticalError(gfxCriticalError::DefaultOptions(false))
         << "Failed to create device context in GetSurfaceForPrinter";
       return nullptr;
     }
 
     // The PrintTargetWindows takes over ownership of this DC
     return PrintTargetWindows::CreateOrNull(dc);
@@ -452,18 +415,18 @@ nsDeviceContextSpecWin::BeginDocument(co
                                       int32_t          aEndPage)
 {
 #ifdef MOZ_ENABLE_SKIA_PDF
   if (mPrintViaSkPDF && (mOutputFormat != nsIPrintSettings::kOutputFormatPDF)) {
     // Here we create mDC which we'll draw each page from our temporary PDF file
     // to once we reach EndDocument. The only reason we create it here rather
     // than in EndDocument is so that we don't need to store aTitle and
     // aPrintToFileName as member data.
-    NS_WARNING_ASSERTION(mDriverName, "No driver!");
-    mDC = ::CreateDCW(mDriverName, mDeviceName, nullptr, mDevMode);
+    NS_WARNING_ASSERTION(!mDriverName.IsEmpty(), "No driver!");
+    mDC = ::CreateDCW(mDriverName.get(), mDeviceName.get(), nullptr, mDevMode);
     if (mDC == NULL) {
       gfxCriticalError(gfxCriticalError::DefaultOptions(false))
         << "Failed to create device context in GetSurfaceForPrinter";
       return NS_ERROR_FAILURE;
     }
 
     const uint32_t DOC_TITLE_LENGTH = MAX_PATH - 1;
     nsString title(aTitle);
@@ -522,25 +485,25 @@ nsDeviceContextSpecWin::EndDocument()
       NS_WARNING("Failed to dispatch to the current thread!");
     }
   }
 #endif
   return rv;
 }
 
 //----------------------------------------------------------------------------------
-void nsDeviceContextSpecWin::SetDeviceName(char16ptr_t aDeviceName)
+void nsDeviceContextSpecWin::SetDeviceName(const nsAString& aDeviceName)
 {
-  CleanAndCopyString(mDeviceName, aDeviceName);
+  mDeviceName = aDeviceName;
 }
 
 //----------------------------------------------------------------------------------
-void nsDeviceContextSpecWin::SetDriverName(char16ptr_t aDriverName)
+void nsDeviceContextSpecWin::SetDriverName(const nsAString& aDriverName)
 {
-  CleanAndCopyString(mDriverName, aDriverName);
+  mDriverName = aDriverName;
 }
 
 //----------------------------------------------------------------------------------
 void nsDeviceContextSpecWin::SetDevMode(LPDEVMODEW aDevMode)
 {
   if (mDevMode) {
     ::HeapFree(::GetProcessHeap(), 0, mDevMode);
   }
@@ -555,46 +518,48 @@ nsDeviceContextSpecWin::GetDevMode(LPDEV
   aDevMode = mDevMode;
 }
 
 #define DISPLAY_LAST_ERROR
 
 //----------------------------------------------------------------------------------
 // Setup the object's data member with the selected printer's data
 nsresult
-nsDeviceContextSpecWin::GetDataFromPrinter(char16ptr_t aName, nsIPrintSettings* aPS)
+nsDeviceContextSpecWin::GetDataFromPrinter(const nsAString& aName,
+                                           nsIPrintSettings* aPS)
 {
   nsresult rv = NS_ERROR_FAILURE;
 
   if (!GlobalPrinters::GetInstance()->PrintersAreAllocated()) {
     rv = GlobalPrinters::GetInstance()->EnumeratePrinterList();
     if (NS_FAILED(rv)) {
       PR_PL(("***** nsDeviceContextSpecWin::GetDataFromPrinter - Couldn't enumerate printers!\n"));
       DISPLAY_LAST_ERROR
     }
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsHPRINTER hPrinter = nullptr;
-  wchar_t *name = (wchar_t*)aName; // Windows APIs use non-const name argument
+  const nsString& flat = PromiseFlatString(aName);
+  wchar_t* name = (wchar_t*)flat.get(); // Windows APIs use non-const name argument
 
   BOOL status = ::OpenPrinterW(name, &hPrinter, nullptr);
   if (status) {
     nsAutoPrinter autoPrinter(hPrinter);
 
     LPDEVMODEW   pDevMode;
 
     // Allocate a buffer of the correct size.
     LONG needed = ::DocumentPropertiesW(nullptr, hPrinter, name, nullptr,
                                         nullptr, 0);
     if (needed < 0) {
       PR_PL(("**** nsDeviceContextSpecWin::GetDataFromPrinter - Couldn't get "
              "size of DEVMODE using DocumentPropertiesW(pDeviceName = \"%s\"). "
              "GetLastEror() = %08x\n",
-             aName ? NS_ConvertUTF16toUTF8(aName).get() : "", GetLastError()));
+             NS_ConvertUTF16toUTF8(aName).get(), GetLastError()));
       return NS_ERROR_FAILURE;
     }
 
     pDevMode = (LPDEVMODEW)::HeapAlloc(::GetProcessHeap(), HEAP_ZERO_MEMORY,
                                        needed);
     if (!pDevMode) return NS_ERROR_FAILURE;
 
     // Get the default DevMode for the printer and modify it for our needs.
@@ -609,17 +574,17 @@ nsDeviceContextSpecWin::GetDataFromPrint
       ret = ::DocumentPropertiesW(nullptr, hPrinter, name,
                                   pDevMode, pDevMode,
                                   DM_IN_BUFFER | DM_OUT_BUFFER);
 
       // We need to copy the final DEVMODE settings back to our print settings,
       // because they may have been set from invalid prefs.
       if (ret == IDOK) {
         // We need to get information from the device as well.
-        nsAutoHDC printerDC(::CreateICW(kDriverName, aName, nullptr, pDevMode));
+        nsAutoHDC printerDC(::CreateICW(kDriverName, name, nullptr, pDevMode));
         if (NS_WARN_IF(!printerDC)) {
           ::HeapFree(::GetProcessHeap(), 0, pDevMode);
           return NS_ERROR_FAILURE;
         }
 
         psWin->CopyFromNative(printerDC, pDevMode);
       }
     }
@@ -630,17 +595,17 @@ nsDeviceContextSpecWin::GetDataFromPrint
       DISPLAY_LAST_ERROR
       return NS_ERROR_FAILURE;
     }
 
     SetDevMode(pDevMode); // cache the pointer and takes responsibility for the memory
 
     SetDeviceName(aName);
 
-    SetDriverName(kDriverName);
+    SetDriverName(nsDependentString(kDriverName));
 
     rv = NS_OK;
   } else {
     rv = NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND;
     PR_PL(("***** nsDeviceContextSpecWin::GetDataFromPrinter - Couldn't open printer: [%s]\n", NS_ConvertUTF16toUTF8(aName).get()));
     DISPLAY_LAST_ERROR
   }
   return rv;
@@ -659,32 +624,29 @@ nsPrinterEnumeratorWin::~nsPrinterEnumer
   // GlobalPrinters::GetInstance()->FreeGlobalPrinters();
 }
 
 NS_IMPL_ISUPPORTS(nsPrinterEnumeratorWin, nsIPrinterEnumerator)
 
 //----------------------------------------------------------------------------------
 // Return the Default Printer name
 NS_IMETHODIMP
-nsPrinterEnumeratorWin::GetDefaultPrinterName(char16_t * *aDefaultPrinterName)
+nsPrinterEnumeratorWin::GetDefaultPrinterName(nsAString& aDefaultPrinterName)
 {
-  NS_ENSURE_ARG_POINTER(aDefaultPrinterName);
-
-  *aDefaultPrinterName = GetDefaultPrinterNameFromGlobalPrinters(); // helper
-
+  GlobalPrinters::GetInstance()->GetDefaultPrinterName(aDefaultPrinterName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPrinterEnumeratorWin::InitPrintSettingsFromPrinter(const char16_t *aPrinterName, nsIPrintSettings *aPrintSettings)
+nsPrinterEnumeratorWin::InitPrintSettingsFromPrinter(const nsAString& aPrinterName,
+                                                     nsIPrintSettings *aPrintSettings)
 {
-  NS_ENSURE_ARG_POINTER(aPrinterName);
   NS_ENSURE_ARG_POINTER(aPrintSettings);
 
-  if (!*aPrinterName) {
+  if (aPrinterName.IsEmpty()) {
     return NS_OK;
   }
 
   // When printing to PDF on Windows there is no associated printer driver.
   int16_t outputFormat;
   aPrintSettings->GetOutputFormat(&outputFormat);
   if (outputFormat == nsIPrintSettings::kOutputFormatPDF) {
     return NS_OK;
@@ -719,17 +681,18 @@ nsPrinterEnumeratorWin::InitPrintSetting
   devSpecWin->GetDevMode(devmode);
   if (NS_WARN_IF(!devmode)) {
     return NS_ERROR_FAILURE;
   }
 
   aPrintSettings->SetPrinterName(aPrinterName);
 
   // We need to get information from the device as well.
-  char16ptr_t printerName = aPrinterName;
+  const nsString& flat = PromiseFlatString(aPrinterName);
+  char16ptr_t printerName = flat.get();
   HDC dc = ::CreateICW(kDriverName, printerName, nullptr, devmode);
   if (NS_WARN_IF(!dc)) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsIPrintSettingsWin> psWin = do_QueryInterface(aPrintSettings);
   MOZ_ASSERT(psWin);
   psWin->CopyFromNative(dc, devmode);
@@ -828,17 +791,17 @@ GlobalPrinters::EnumerateNativePrinters(
   }
   PR_PL(("-----------------------\n"));
   return rv;
 }
 
 //------------------------------------------------------------------
 // Uses the GetProfileString to get the default printer from the registry
 void
-GlobalPrinters::GetDefaultPrinterName(nsString& aDefaultPrinterName)
+GlobalPrinters::GetDefaultPrinterName(nsAString& aDefaultPrinterName)
 {
   aDefaultPrinterName.Truncate();
   WCHAR szDefaultPrinterName[1024];
   DWORD status = GetProfileStringW(L"windows", L"device", 0,
                                    szDefaultPrinterName,
                                    ArrayLength(szDefaultPrinterName));
   if (status > 0) {
     WCHAR comma = ',';
@@ -848,17 +811,18 @@ GlobalPrinters::GetDefaultPrinterName(ns
     if (*sPtr == comma) {
       *sPtr = 0;
     }
     aDefaultPrinterName = szDefaultPrinterName;
   } else {
     aDefaultPrinterName = EmptyString();
   }
 
-  PR_PL(("DEFAULT PRINTER [%s]\n", aDefaultPrinterName.get()));
+  PR_PL(("DEFAULT PRINTER [%s]\n",
+         PromiseFlatString(aDefaultPrinterName).get()));
 }
 
 //----------------------------------------------------------------------------------
 // This goes and gets the list of available printers and puts
 // the default printer at the beginning of the list
 nsresult
 GlobalPrinters::EnumeratePrinterList()
 {
--- a/widget/windows/nsDeviceContextSpecWin.h
+++ b/widget/windows/nsDeviceContextSpecWin.h
@@ -46,38 +46,39 @@ public:
   NS_IMETHOD EndPage() override { return NS_OK; }
 
   NS_IMETHOD Init(nsIWidget* aWidget, nsIPrintSettings* aPS, bool aIsPrintPreview) override;
 
   float GetDPI() final;
 
   float GetPrintingScale() final;
 
-  void GetDriverName(wchar_t *&aDriverName) const   { aDriverName = mDriverName;     }
-  void GetDeviceName(wchar_t *&aDeviceName) const   { aDeviceName = mDeviceName;     }
+  void GetDriverName(nsAString& aDriverName) const { aDriverName = mDriverName; }
+  void GetDeviceName(nsAString& aDeviceName) const { aDeviceName = mDeviceName; }
 
   // The GetDevMode will return a pointer to a DevMode
   // whether it is from the Global memory handle or just the DevMode
   // To get the DevMode from the Global memory Handle it must lock it 
   // So this call must be paired with a call to UnlockGlobalHandle
   void GetDevMode(LPDEVMODEW &aDevMode);
 
   // helper functions
-  nsresult GetDataFromPrinter(char16ptr_t aName, nsIPrintSettings* aPS = nullptr);
+  nsresult GetDataFromPrinter(const nsAString& aName,
+                              nsIPrintSettings* aPS = nullptr);
 
 protected:
 
-  void SetDeviceName(char16ptr_t aDeviceName);
-  void SetDriverName(char16ptr_t aDriverName);
+  void SetDeviceName(const nsAString& aDeviceName);
+  void SetDriverName(const nsAString& aDriverName);
   void SetDevMode(LPDEVMODEW aDevMode);
 
   virtual ~nsDeviceContextSpecWin();
 
-  wchar_t*      mDriverName;
-  wchar_t*      mDeviceName;
+  nsString mDriverName;
+  nsString mDeviceName;
   LPDEVMODEW mDevMode;
 
   nsCOMPtr<nsIPrintSettings> mPrintSettings;
   int16_t mOutputFormat = nsIPrintSettings::kOutputFormatNative;
 
 #ifdef MOZ_ENABLE_SKIA_PDF
   void  FinishPrintViaPDF();
   void  CleanupPrintViaPDF();
--- a/widget/windows/nsPrintOptionsWin.cpp
+++ b/widget/windows/nsPrintOptionsWin.cpp
@@ -50,28 +50,25 @@ nsPrintOptionsWin::SerializeToPrintData(
     aWBP->GetIsRangeSelection(&data->isRangeSelection());
   }
 
   nsCOMPtr<nsIPrintSettingsWin> psWin = do_QueryInterface(aSettings);
   if (!psWin) {
     return NS_ERROR_FAILURE;
   }
 
-  char16_t* deviceName;
-  char16_t* driverName;
+  nsAutoString deviceName;
+  nsAutoString driverName;
 
-  psWin->GetDeviceName(&deviceName);
-  psWin->GetDriverName(&driverName);
+  psWin->GetDeviceName(deviceName);
+  psWin->GetDriverName(driverName);
 
   data->deviceName().Assign(deviceName);
   data->driverName().Assign(driverName);
 
-  free(deviceName);
-  free(driverName);
-
   // When creating the print dialog on Windows, we only need to send certain
   // print settings information from the parent to the child not vice versa.
   if (XRE_IsParentProcess()) {
     psWin->GetPrintableWidthInInches(&data->printableWidthInInches());
     psWin->GetPrintableHeightInInches(&data->printableHeightInInches());
 
     // A DEVMODE can actually be of arbitrary size. If it turns out that it'll
     // make our IPC message larger than the limit, then we'll error out.
@@ -112,18 +109,18 @@ nsPrintOptionsWin::DeserializeToPrintSet
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIPrintSettingsWin> psWin = do_QueryInterface(settings);
   if (!settings) {
     return NS_ERROR_FAILURE;
   }
 
   if (XRE_IsContentProcess()) {
-    psWin->SetDeviceName(data.deviceName().get());
-    psWin->SetDriverName(data.driverName().get());
+    psWin->SetDeviceName(data.deviceName());
+    psWin->SetDriverName(data.driverName());
 
     psWin->SetPrintableWidthInInches(data.printableWidthInInches());
     psWin->SetPrintableHeightInInches(data.printableHeightInInches());
 
     if (data.devModeData().IsEmpty()) {
       psWin->SetDevMode(nullptr);
     } else {
       // Check minimum length of DEVMODE data.
--- a/widget/windows/nsPrintSettingsWin.cpp
+++ b/widget/windows/nsPrintSettingsWin.cpp
@@ -149,62 +149,50 @@ nsPrintSettingsWin::nsPrintSettingsWin()
 {
 
 }
 
 /** ---------------------------------------------------
  *  See documentation in nsPrintSettingsWin.h
  *	@update 
  */
-nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin& aPS) :
-  mDeviceName(nullptr),
-  mDriverName(nullptr),
-  mDevMode(nullptr)
+nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin& aPS)
+  : mDevMode(nullptr)
 {
   *this = aPS;
 }
 
 /** ---------------------------------------------------
  *  See documentation in nsPrintSettingsWin.h
  *	@update 
  */
 nsPrintSettingsWin::~nsPrintSettingsWin()
 {
-  if (mDeviceName) free(mDeviceName);
-  if (mDriverName) free(mDriverName);
   if (mDevMode) ::HeapFree(::GetProcessHeap(), 0, mDevMode);
 }
 
-NS_IMETHODIMP nsPrintSettingsWin::SetDeviceName(const char16_t * aDeviceName)
+NS_IMETHODIMP nsPrintSettingsWin::SetDeviceName(const nsAString& aDeviceName)
 {
-  if (mDeviceName) {
-    free(mDeviceName);
-  }
-  mDeviceName = aDeviceName?wcsdup(char16ptr_t(aDeviceName)):nullptr;
+  mDeviceName = aDeviceName;
   return NS_OK;
 }
-NS_IMETHODIMP nsPrintSettingsWin::GetDeviceName(char16_t **aDeviceName)
+NS_IMETHODIMP nsPrintSettingsWin::GetDeviceName(nsAString& aDeviceName)
 {
-  NS_ENSURE_ARG_POINTER(aDeviceName);
-  *aDeviceName = mDeviceName?reinterpret_cast<char16_t*>(wcsdup(mDeviceName)):nullptr;
+  aDeviceName = mDeviceName;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsPrintSettingsWin::SetDriverName(const char16_t * aDriverName)
+NS_IMETHODIMP nsPrintSettingsWin::SetDriverName(const nsAString& aDriverName)
 {
-  if (mDriverName) {
-    free(mDriverName);
-  }
-  mDriverName = aDriverName?wcsdup(char16ptr_t(aDriverName)):nullptr;
+  mDriverName = aDriverName;
   return NS_OK;
 }
-NS_IMETHODIMP nsPrintSettingsWin::GetDriverName(char16_t **aDriverName)
+NS_IMETHODIMP nsPrintSettingsWin::GetDriverName(nsAString& aDriverName)
 {
-  NS_ENSURE_ARG_POINTER(aDriverName);
-  *aDriverName = mDriverName?reinterpret_cast<char16_t*>(wcsdup(mDriverName)):nullptr;
+  aDriverName = mDriverName;
   return NS_OK;
 }
 
 void nsPrintSettingsWin::CopyDevMode(DEVMODEW* aInDevMode, DEVMODEW *& aOutDevMode)
 {
   aOutDevMode = nullptr;
   size_t size = aInDevMode->dmSize + aInDevMode->dmDriverExtra;
   aOutDevMode = (LPDEVMODEW)::HeapAlloc (::GetProcessHeap(), HEAP_ZERO_MEMORY, size);
@@ -420,31 +408,23 @@ nsPrintSettingsWin::_Clone(nsIPrintSetti
 nsPrintSettingsWin& nsPrintSettingsWin::operator=(const nsPrintSettingsWin& rhs)
 {
   if (this == &rhs) {
     return *this;
   }
 
   ((nsPrintSettings&) *this) = rhs;
 
-  if (mDeviceName) {
-    free(mDeviceName);
-  }
-
-  if (mDriverName) {
-    free(mDriverName);
-  }
-
   // Use free because we used the native malloc to create the memory
   if (mDevMode) {
     ::HeapFree(::GetProcessHeap(), 0, mDevMode);
   }
 
-  mDeviceName = rhs.mDeviceName?wcsdup(rhs.mDeviceName):nullptr;
-  mDriverName = rhs.mDriverName?wcsdup(rhs.mDriverName):nullptr;
+  mDeviceName = rhs.mDeviceName;
+  mDriverName = rhs.mDriverName;
 
   if (rhs.mDevMode) {
     CopyDevMode(rhs.mDevMode, mDevMode);
   } else {
     mDevMode = nullptr;
   }
 
   return *this;
--- a/widget/windows/nsPrintSettingsWin.h
+++ b/widget/windows/nsPrintSettingsWin.h
@@ -42,18 +42,18 @@ public:
    */
   nsPrintSettingsWin& operator=(const nsPrintSettingsWin& rhs);
 
   NS_IMETHOD GetEffectivePageSize(double *aWidth, double *aHeight) override;
 
 protected:
   void CopyDevMode(DEVMODEW* aInDevMode, DEVMODEW *& aOutDevMode);
 
-  wchar_t*      mDeviceName;
-  wchar_t*      mDriverName;
+  nsString      mDeviceName;
+  nsString      mDriverName;
   LPDEVMODEW mDevMode;
   double mPrintableWidthInInches = 0l;
   double mPrintableHeightInInches = 0l;
 };
 
 
 
 #endif /* nsPrintSettingsWin_h__ */