162 lines
5.3 KiB
Diff
162 lines
5.3 KiB
Diff
# HG changeset patch
|
|
# User Matthew Gregan <kinetik@flim.org>
|
|
# Date 1293624205 -3600
|
|
# Node ID ffa1ef8ab52b4081e27aa2b24d14a550386f90db
|
|
# Parent 9e561d402701f46eb56dbadb96b6963f4518cdd0
|
|
Bug 573039 - Construct nsCUPSShim statically and avoid calling PR_UnloadLibrary on libcups after it has been initialized. r=karlt a=clegnitto
|
|
|
|
diff --git a/mozilla/gfx/src/psshared/nsCUPSShim.cpp b/mozilla/gfx/src/psshared/nsCUPSShim.cpp
|
|
--- a/mozilla/gfx/src/psshared/nsCUPSShim.cpp
|
|
+++ b/mozilla/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/mozilla/gfx/src/psshared/nsCUPSShim.h b/mozilla/gfx/src/psshared/nsCUPSShim.h
|
|
--- a/mozilla/gfx/src/psshared/nsCUPSShim.h
|
|
+++ b/mozilla/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/mozilla/gfx/src/psshared/nsPSPrinters.cpp b/mozilla/gfx/src/psshared/nsPSPrinters.cpp
|
|
--- a/mozilla/gfx/src/psshared/nsPSPrinters.cpp
|
|
+++ b/mozilla/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<nsCString>& 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/mozilla/gfx/src/psshared/nsPSPrinters.h b/mozilla/gfx/src/psshared/nsPSPrinters.h
|
|
--- a/mozilla/gfx/src/psshared/nsPSPrinters.h
|
|
+++ b/mozilla/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 <type> portion as described for GetPrinterList().
|
|
* @return The PrinterType value for this name.
|
|
*/
|
|
static PrinterType GetPrinterType(const nsACString& aName);
|
|
|
|
private:
|
|
nsCOMPtr<nsIPrefService> mPrefSvc;
|
|
nsCOMPtr<nsIPrefBranch> mPref;
|
|
- nsCUPSShim mCups;
|
|
};
|
|
|
|
#endif /* nsPSPrinters_h___ */
|
|
|
|
|