зеркало из https://github.com/mozilla/pjs.git
bug 212125 : factor out loading |nsIPersistentProperties|' from a URI/URIspec and add helper
functions to nsNetUtil.h (r=rbs, sr=darin)
This commit is contained in:
Родитель
45c2cc7cf9
Коммит
6612ac1a1e
|
@ -61,7 +61,6 @@
|
|||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsCompressedCharMap.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURI.h"
|
||||
#include "plhash.h"
|
||||
|
||||
#include <gdk/gdkx.h>
|
||||
|
@ -370,7 +369,6 @@ static nsresult GetEncoding(const char* aFontName,
|
|||
static nsresult GetConverter(const char* aEncoding,
|
||||
nsIUnicodeEncoder** aConverter);
|
||||
static nsresult FreeGlobals(void);
|
||||
static nsresult InitFontEncodingProperties(void);
|
||||
static nsFontXftInfo* GetFontXftInfo(FcPattern* aPattern);
|
||||
|
||||
static PLHashNumber HashKey(const void* aString);
|
||||
|
@ -2845,7 +2843,8 @@ GetEncoding(const char *aFontName, char **aEncoding, nsXftFontType &aType,
|
|||
|
||||
// if we have not init the property yet, init it right now.
|
||||
if (!gFontEncodingProperties)
|
||||
InitFontEncodingProperties();
|
||||
NS_LoadPersistentPropertiesFromURISpec(&gFontEncodingProperties,
|
||||
NS_LITERAL_CSTRING("resource:/res/fonts/fontEncoding.properties"));
|
||||
|
||||
nsAutoString encoding;
|
||||
*aEncoding = nsnull;
|
||||
|
@ -2953,35 +2952,6 @@ FreeGlobals(void)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsresult
|
||||
InitFontEncodingProperties(void)
|
||||
{
|
||||
nsresult rv;
|
||||
// load the special encoding resolver
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri),
|
||||
"resource:/res/fonts/fontEncoding.properties");
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
rv = NS_OpenURI(getter_AddRefs(in), uri);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = nsComponentManager::
|
||||
CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID, nsnull,
|
||||
NS_GET_IID(nsIPersistentProperties),
|
||||
(void**)&gFontEncodingProperties);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = gFontEncodingProperties->Load(in);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* static */
|
||||
nsFontXftInfo*
|
||||
GetFontXftInfo(FcPattern* aPattern)
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsHashtable.h"
|
||||
#include <ATSTypes.h>
|
||||
#include <SFNTTypes.h>
|
||||
|
@ -477,30 +476,6 @@ static PRUint16* InitGlobalCCMap()
|
|||
return map;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
InitFontEncodingProperties(void)
|
||||
{
|
||||
// load the special encoding resolver
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri),
|
||||
"resource:/res/fonts/fontEncoding.properties");
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
rv = NS_OpenURI(getter_AddRefs(in), uri);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = nsComponentManager::
|
||||
CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID, nsnull,
|
||||
NS_GET_IID(nsIPersistentProperties),
|
||||
(void**)&gFontEncodingProperties);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = gFontEncodingProperties->Load(in);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Helper to determine if a font has a private encoding that we know something about
|
||||
static nsresult
|
||||
GetEncoding(const nsCString& aFontName, nsACString& aValue)
|
||||
|
@ -521,7 +496,8 @@ GetEncoding(const nsCString& aFontName, nsACString& aValue)
|
|||
return NS_ERROR_NOT_AVAILABLE; // error mean do not get a special encoding
|
||||
|
||||
// init the property now
|
||||
rv = InitFontEncodingProperties();
|
||||
rv = NS_LoadPersistentPropertiesFromURISpec(&gFontEncodingProperties,
|
||||
NS_LITERAL_CSTRING("resource:/res/fonts/fontEncoding.properties"));
|
||||
if NS_FAILED(rv)
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#include "nsReadableUtils.h"
|
||||
|
||||
#include "nsICharsetAlias.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsCRT.h"
|
||||
|
@ -1933,7 +1932,8 @@ FILE *f;
|
|||
fprintf(f, "\n");
|
||||
|
||||
// read the printer properties file
|
||||
InitUnixPrinterProps();
|
||||
NS_LoadPersistentPropertiesFromURISpec(getter_AddRefs(mPrinterProps),
|
||||
NS_LITERAL_CSTRING("resource:/res/unixpsfonts.properties"));
|
||||
|
||||
// setup prolog for each langgroup
|
||||
initlanggroup();
|
||||
|
@ -2866,24 +2866,6 @@ nsPostScriptObj::setlanggroup(nsIAtom * aLangGroup)
|
|||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsPostScriptObj::InitUnixPrinterProps()
|
||||
{
|
||||
nsCOMPtr<nsIPersistentProperties> printerprops_tmp;
|
||||
const char propertyURL[] = "resource:/res/unixpsfonts.properties";
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING(propertyURL)), PR_FALSE);
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(in), uri), PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(
|
||||
NS_PERSISTENTPROPERTIES_CONTRACTID, nsnull,
|
||||
NS_GET_IID(nsIPersistentProperties), getter_AddRefs(printerprops_tmp)),
|
||||
PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(printerprops_tmp->Load(in), PR_FALSE);
|
||||
mPrinterProps = printerprops_tmp;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsPostScriptObj::GetUnixPrinterSetting(const nsCAutoString& aKey, char** aVal)
|
||||
{
|
||||
|
|
|
@ -437,7 +437,6 @@ public:
|
|||
void settitle(PRUnichar * aTitle);
|
||||
|
||||
FILE * GetPrintFile();
|
||||
PRBool InitUnixPrinterProps();
|
||||
PRBool GetUnixPrinterSetting(const nsCAutoString&, char**);
|
||||
PrintSetup *mPrintSetup;
|
||||
private:
|
||||
|
|
|
@ -54,7 +54,6 @@
|
|||
#include "nsIFontPackageProxy.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURI.h"
|
||||
#include "prmem.h"
|
||||
#include "plhash.h"
|
||||
#include "prprf.h"
|
||||
|
@ -261,29 +260,6 @@ NS_IMETHODIMP nsFontCleanupObserver::Observe(nsISupports *aSubject, const char *
|
|||
|
||||
static nsFontCleanupObserver *gFontCleanupObserver;
|
||||
|
||||
static nsresult
|
||||
InitFontEncodingProperties(void)
|
||||
{
|
||||
nsresult rv;
|
||||
// load the special encoding resolver
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), "resource:/res/fonts/fontEncoding.properties");
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
rv = NS_OpenURI(getter_AddRefs(in), uri);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = nsComponentManager::
|
||||
CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID, nsnull,
|
||||
NS_GET_IID(nsIPersistentProperties),
|
||||
(void**)&gFontEncodingProperties);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = gFontEncodingProperties->Load(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
InitGlobals(void)
|
||||
{
|
||||
|
@ -1290,8 +1266,9 @@ GetEncoding(const char* aFontName, nsCString& aValue)
|
|||
ToLowerCase(name);
|
||||
|
||||
// if we have not init the property yet, init it right now.
|
||||
if (! gFontEncodingProperties)
|
||||
InitFontEncodingProperties();
|
||||
if (!gFontEncodingProperties)
|
||||
NS_LoadPersistentPropertiesFromURISpec(&gFontEncodingProperties,
|
||||
NS_LITERAL_CSTRING("resource:/res/fonts/fontEncoding.properties"));
|
||||
|
||||
if (gFontEncodingProperties) {
|
||||
nsAutoString prop;
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "nsIObserverService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
|
@ -195,24 +194,13 @@ static nsresult
|
|||
LoadProperties(const nsString& aName,
|
||||
nsCOMPtr<nsIPersistentProperties>& aProperties)
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoString uriStr;
|
||||
uriStr.Assign(NS_LITERAL_STRING("resource:/res/fonts/mathfont"));
|
||||
uriStr.Append(aName);
|
||||
uriStr.StripWhitespace(); // that may come from aName
|
||||
uriStr.Append(NS_LITERAL_STRING(".properties"));
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), uriStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
rv = NS_OpenURI(getter_AddRefs(in), uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = nsComponentManager::
|
||||
CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID, nsnull,
|
||||
NS_GET_IID(nsIPersistentProperties),
|
||||
getter_AddRefs(aProperties));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return aProperties->Load(in);
|
||||
return NS_LoadPersistentPropertiesFromURISpec(getter_AddRefs(aProperties),
|
||||
NS_ConvertUTF16toUTF8(uriStr));
|
||||
}
|
||||
|
||||
// helper to get the stretchy direction of a char
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsMathMLOperators.h"
|
||||
|
@ -279,21 +278,9 @@ InitOperators(void)
|
|||
{
|
||||
// Load the property file containing the Operator Dictionary
|
||||
nsresult rv;
|
||||
nsAutoString uriStr;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
uriStr.Assign(NS_LITERAL_STRING("resource:/res/fonts/mathfont.properties"));
|
||||
rv = NS_NewURI(getter_AddRefs(uri), uriStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
rv = NS_OpenURI(getter_AddRefs(in), uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIPersistentProperties> mathfontProp;
|
||||
rv = nsComponentManager::
|
||||
CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID, nsnull,
|
||||
NS_GET_IID(nsIPersistentProperties),
|
||||
getter_AddRefs(mathfontProp));
|
||||
if NS_FAILED(rv) return rv;
|
||||
rv = mathfontProp->Load(in);
|
||||
rv = NS_LoadPersistentPropertiesFromURISpec(getter_AddRefs(mathfontProp),
|
||||
NS_LITERAL_CSTRING("resource:/res/fonts/mathfont.properties"));
|
||||
if NS_FAILED(rv) return rv;
|
||||
|
||||
// Get the list of invariant chars
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
#include "nsIBufferedStreams.h"
|
||||
#include "nsIInputStreamPump.h"
|
||||
#include "nsIAsyncStreamCopier.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
|
||||
// Helper, to simplify getting the I/O service.
|
||||
inline const nsGetServiceByCID
|
||||
|
@ -793,4 +794,40 @@ NS_NewPostDataStream(nsIInputStream **result,
|
|||
return NS_NewCStringInputStream(result, data);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_LoadPersistentPropertiesFromURI(nsIPersistentProperties **result,
|
||||
nsIURI *uri,
|
||||
nsIIOService *ioService = nsnull)
|
||||
{
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
nsresult rv = NS_OpenURI(getter_AddRefs(in), uri, ioService);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIPersistentProperties> properties =
|
||||
do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = properties->Load(in);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
NS_ADDREF(*result = properties);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_LoadPersistentPropertiesFromURISpec(nsIPersistentProperties **result,
|
||||
const nsACString &spec,
|
||||
const char *charset = nsnull,
|
||||
nsIURI *baseURI = nsnull,
|
||||
nsIIOService *ioService = nsnull)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv =
|
||||
NS_NewURI(getter_AddRefs(uri), spec, charset, baseURI, ioService);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = NS_LoadPersistentPropertiesFromURI(result, uri, ioService);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endif // !nsNetUtil_h__
|
||||
|
|
Загрузка…
Ссылка в новой задаче