# HG changeset patch # Parent a2ae8b0e65ee046b94e5bacbecdc9ce7b197f896 diff --git a/gfx/src/psshared/nsCUPSShim.cpp b/gfx/src/psshared/nsCUPSShim.cpp --- a/gfx/src/psshared/nsCUPSShim.cpp +++ b/gfx/src/psshared/nsCUPSShim.cpp @@ -83,14 +83,8 @@ nsCUPSShim::Init() #endif PR_UnloadLibrary(mCupsLib); mCupsLib = nsnull; return PR_FALSE; } } return PR_TRUE; } - -nsCUPSShim::~nsCUPSShim() -{ - if (mCupsLib) - PR_UnloadLibrary(mCupsLib); -} diff --git a/gfx/src/psshared/nsCUPSShim.h b/gfx/src/psshared/nsCUPSShim.h --- a/gfx/src/psshared/nsCUPSShim.h +++ b/gfx/src/psshared/nsCUPSShim.h @@ -81,17 +81,16 @@ typedef int (PR_CALLBACK *CupsAddOptionT int num_options, cups_option_t **options); struct PRLibrary; class NS_PSSHARED nsCUPSShim { public: nsCUPSShim() : mCupsLib(nsnull) { } - ~nsCUPSShim(); /** * Initialize this object. Attempt to load the CUPS shared * library and find function pointers for the supported * functions (see below). * @return PR_FALSE if the shared library could not be loaded, or if * any of the functions could not be found. * PR_TRUE for successful initialization. diff --git a/gfx/src/psshared/nsPSPrinters.cpp b/gfx/src/psshared/nsPSPrinters.cpp --- a/gfx/src/psshared/nsPSPrinters.cpp +++ b/gfx/src/psshared/nsPSPrinters.cpp @@ -51,32 +51,34 @@ #include "plstr.h" #define NS_CUPS_PRINTER "CUPS/" #define NS_CUPS_PRINTER_LEN (sizeof(NS_CUPS_PRINTER) - 1) /* dummy printer name for the gfx/src/ps driver */ #define NS_POSTSCRIPT_DRIVER_NAME "PostScript/" +nsCUPSShim gCupsShim; + /* Initialize the printer manager object */ nsresult nsPSPrinterList::Init() { nsresult rv; mPrefSvc = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) rv = mPrefSvc->GetBranch("print.", getter_AddRefs(mPref)); NS_ENSURE_SUCCESS(rv, NS_ERROR_NOT_INITIALIZED); // Should we try cups? PRBool useCups = PR_TRUE; rv = mPref->GetBoolPref("postscript.cups.enabled", &useCups); - if (useCups) - mCups.Init(); + if (useCups && !gCupsShim.IsInitialized()) + gCupsShim.Init(); return NS_OK; } /* Check whether the PostScript module has been disabled at runtime */ PRBool nsPSPrinterList::Enabled() { @@ -94,35 +96,35 @@ nsPSPrinterList::Enabled() /* Fetch a list of printers handled by the PostsScript module */ void nsPSPrinterList::GetPrinterList(nsTArray& aList) { aList.Clear(); // Query CUPS for a printer list. The default printer goes to the // head of the output list; others are appended. - if (mCups.IsInitialized()) { + if (gCupsShim.IsInitialized()) { cups_dest_t *dests; - int num_dests = (mCups.mCupsGetDests)(&dests); + int num_dests = (gCupsShim.mCupsGetDests)(&dests); if (num_dests) { for (int i = 0; i < num_dests; i++) { nsCAutoString fullName(NS_CUPS_PRINTER); fullName.Append(dests[i].name); if (dests[i].instance != NULL) { fullName.Append("/"); fullName.Append(dests[i].instance); } if (dests[i].is_default) aList.InsertElementAt(0, fullName); else aList.AppendElement(fullName); } } - (mCups.mCupsFreeDests)(num_dests, dests); + (gCupsShim.mCupsFreeDests)(num_dests, dests); } // Build the "classic" list of printers -- those accessed by running // an opaque command. This list always contains a printer named "default". // In addition, we look for either an environment variable // MOZILLA_POSTSCRIPT_PRINTER_LIST or a preference setting // print.printer_list, which contains a space-separated list of printer // names. diff --git a/gfx/src/psshared/nsPSPrinters.h b/gfx/src/psshared/nsPSPrinters.h --- a/gfx/src/psshared/nsPSPrinters.h +++ b/gfx/src/psshared/nsPSPrinters.h @@ -37,17 +37,16 @@ * ***** END LICENSE BLOCK ***** */ #ifndef nsPSPrinters_h___ #define nsPSPrinters_h___ #include "nsString.h" #include "nsTArray.h" #include "prtypes.h" -#include "nsCUPSShim.h" #include "psSharedCore.h" class nsIPrefService; class nsIPrefBranch; class nsCUPSShim; class NS_PSSHARED nsPSPrinterList { public: @@ -91,12 +90,11 @@ class NS_PSSHARED nsPSPrinterList { * the portion as described for GetPrinterList(). * @return The PrinterType value for this name. */ static PrinterType GetPrinterType(const nsACString& aName); private: nsCOMPtr mPrefSvc; nsCOMPtr mPref; - nsCUPSShim mCups; }; #endif /* nsPSPrinters_h___ */