зеркало из https://github.com/mozilla/gecko-dev.git
fix for bug 164575 - clean nsIPersistentProperties interface to reduce UTF8/UCS2 conversions
r=dougt, sr=darin
This commit is contained in:
Родитель
9bdca7c014
Коммит
2dded12ab7
|
@ -504,20 +504,20 @@ InitFontEncodingProperties(void)
|
|||
|
||||
// Helper to determine if a font has a private encoding that we know something about
|
||||
static nsresult
|
||||
GetEncoding(const nsString& aFontName, nsString& aValue)
|
||||
GetEncoding(const nsCString& aFontName, nsString& aValue)
|
||||
{
|
||||
// see if we should init the property
|
||||
if (! gFontEncodingProperties) {
|
||||
// but bail out for common fonts used at startup...
|
||||
if (aFontName.Equals(NS_LITERAL_STRING("Lucida Grande")) ||
|
||||
aFontName.Equals(NS_LITERAL_STRING("Charcoal")) ||
|
||||
aFontName.Equals(NS_LITERAL_STRING("Chicago")) ||
|
||||
aFontName.Equals(NS_LITERAL_STRING("Capitals")) ||
|
||||
aFontName.Equals(NS_LITERAL_STRING("Gadget")) ||
|
||||
aFontName.Equals(NS_LITERAL_STRING("Sand")) ||
|
||||
aFontName.Equals(NS_LITERAL_STRING("Techno")) ||
|
||||
aFontName.Equals(NS_LITERAL_STRING("Textile")) ||
|
||||
aFontName.Equals(NS_LITERAL_STRING("Geneva")) )
|
||||
if (aFontName.Equals(NS_LITERAL_CSTRING("Lucida Grande")) ||
|
||||
aFontName.Equals(NS_LITERAL_CSTRING("Charcoal")) ||
|
||||
aFontName.Equals(NS_LITERAL_CSTRING("Chicago")) ||
|
||||
aFontName.Equals(NS_LITERAL_CSTRING("Capitals")) ||
|
||||
aFontName.Equals(NS_LITERAL_CSTRING("Gadget")) ||
|
||||
aFontName.Equals(NS_LITERAL_CSTRING("Sand")) ||
|
||||
aFontName.Equals(NS_LITERAL_CSTRING("Techno")) ||
|
||||
aFontName.Equals(NS_LITERAL_CSTRING("Textile")) ||
|
||||
aFontName.Equals(NS_LITERAL_CSTRING("Geneva")) )
|
||||
return NS_ERROR_NOT_AVAILABLE; // error mean do not get a special encoding
|
||||
|
||||
// init the property now
|
||||
|
@ -526,10 +526,9 @@ GetEncoding(const nsString& aFontName, nsString& aValue)
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsAutoString name;
|
||||
name.Assign(NS_LITERAL_STRING("encoding."));
|
||||
name.Append(aFontName);
|
||||
name.Append(NS_LITERAL_STRING(".ttf"));
|
||||
nsCAutoString name(NS_LITERAL_CSTRING("encoding.") +
|
||||
aFontName +
|
||||
NS_LITERAL_CSTRING(".ttf"));
|
||||
name.StripWhitespace();
|
||||
ToLowerCase(name);
|
||||
|
||||
|
@ -540,7 +539,7 @@ GetEncoding(const nsString& aFontName, nsString& aValue)
|
|||
// the converter for the font whose name is given. The CCM caches the converter.
|
||||
// The caller holds a reference and should take care of the release.
|
||||
static nsresult
|
||||
GetConverter(const nsString& aFontName, nsIUnicodeEncoder** aConverter)
|
||||
GetConverter(const nsCString& aFontName, nsIUnicodeEncoder** aConverter)
|
||||
{
|
||||
*aConverter = nsnull;
|
||||
|
||||
|
@ -591,7 +590,7 @@ nsresult
|
|||
nsMacUnicodeFontInfo::GetConverterAndCCMap(const nsString& aFontName, nsIUnicodeEncoder** aConverter,
|
||||
PRUint16** aCCMap)
|
||||
{
|
||||
if(NS_SUCCEEDED(GetConverter(aFontName, aConverter)) && *aConverter)
|
||||
if(NS_SUCCEEDED(GetConverter(NS_ConvertUCS2toUTF8(aFontName), aConverter)) && *aConverter)
|
||||
{
|
||||
// make sure we have the hashtable
|
||||
if(!gFontMaps)
|
||||
|
|
|
@ -2890,10 +2890,8 @@ nsPostScriptObj::GetUnixPrinterSetting(const nsCAutoString& aKey, char** aVal)
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
nsAutoString key;
|
||||
key.AssignWithConversion(aKey.get());
|
||||
nsAutoString oValue;
|
||||
nsresult res = mPrinterProps->GetStringProperty(key, oValue);
|
||||
nsresult res = mPrinterProps->GetStringProperty(aKey, oValue);
|
||||
if (NS_FAILED(res)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
|
|
@ -1149,10 +1149,7 @@ GetEncoding(const char* aFontName, nsString& aValue)
|
|||
(!strcmp(aFontName, mspgothic )) )
|
||||
return NS_ERROR_NOT_AVAILABLE; // error mean do not get a special encoding
|
||||
|
||||
nsAutoString name;
|
||||
name.Assign(NS_LITERAL_STRING("encoding."));
|
||||
name.AppendWithConversion(aFontName);
|
||||
name.Append(NS_LITERAL_STRING(".ttf"));
|
||||
nsCAutoString name(NS_LITERAL_CSTRING("encoding.") + nsDependentCString(aFontName) + NS_LITERAL_CSTRING(".ttf"));
|
||||
name.StripWhitespace();
|
||||
ToLowerCase(name);
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#include "prenv.h"
|
||||
|
||||
static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID);
|
||||
static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
|
||||
|
||||
// XXX investigate need for proper locking in this module
|
||||
//static PRInt32 gLockCount = 0;
|
||||
|
@ -296,7 +297,7 @@ nsresult
|
|||
nsStringBundle::GetStringFromID(PRInt32 aID, nsAString& aResult)
|
||||
{
|
||||
nsAutoCMonitor(this);
|
||||
nsAutoString name;
|
||||
nsCAutoString name;
|
||||
name.AppendInt(aID, 10);
|
||||
nsresult rv = mProps->GetStringProperty(name, aResult);
|
||||
|
||||
|
@ -316,7 +317,7 @@ nsStringBundle::GetStringFromName(const nsAString& aName,
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = mProps->GetStringProperty(aName, aResult);
|
||||
rv = mProps->GetStringProperty(NS_ConvertUCS2toUTF8(aName), aResult);
|
||||
#ifdef DEBUG_tao_
|
||||
char *s = ToNewCString(aResult),
|
||||
*ss = ToNewCString(aName);
|
||||
|
@ -411,7 +412,7 @@ nsStringBundle::GetSimpleEnumeration(nsISimpleEnumerator** elements)
|
|||
rv = LoadProperties();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mProps->SimpleEnumerateProperties(elements);
|
||||
return mProps->Enumerate(elements);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include <iostream.h>
|
||||
|
|
|
@ -304,7 +304,7 @@ public:
|
|||
nsRect* aClipRect = nsnull);
|
||||
|
||||
private:
|
||||
PRUnichar GetAnnotation(nsMathMLChar* aChar, PRInt32 aPosition);
|
||||
char GetAnnotation(nsMathMLChar* aChar, PRInt32 aPosition);
|
||||
nsGlyphCode ElementAt(nsIPresContext* aPresContext, nsMathMLChar* aChar, PRUint32 aPosition);
|
||||
|
||||
// The type is either NS_TABLE_TYPE_UNICODE or NS_TABLE_TYPE_GLYPH_INDEX
|
||||
|
@ -341,7 +341,7 @@ private:
|
|||
PRUnichar mCharCache;
|
||||
};
|
||||
|
||||
PRUnichar
|
||||
char
|
||||
nsGlyphTable::GetAnnotation(nsMathMLChar* aChar, PRInt32 aPosition)
|
||||
{
|
||||
NS_ASSERTION(aChar->mDirection == NS_STRETCH_DIRECTION_VERTICAL ||
|
||||
|
@ -353,9 +353,9 @@ nsGlyphTable::GetAnnotation(nsMathMLChar* aChar, PRInt32 aPosition)
|
|||
// return an ASCII digit for the size=0,1,2,...
|
||||
return PRUnichar('0' + aPosition - 4);
|
||||
}
|
||||
return (aChar->mDirection == NS_STRETCH_DIRECTION_VERTICAL)
|
||||
? PRUnichar(kVertical[aPosition])
|
||||
: PRUnichar(kHorizontal[aPosition]);
|
||||
return (aChar->mDirection == NS_STRETCH_DIRECTION_VERTICAL) ?
|
||||
kVertical[aPosition] :
|
||||
kHorizontal[aPosition];
|
||||
}
|
||||
|
||||
nsGlyphCode
|
||||
|
@ -385,9 +385,10 @@ nsGlyphTable::ElementAt(nsIPresContext* aPresContext, nsMathMLChar* aChar, PRUin
|
|||
mState = NS_TABLE_STATE_READY;
|
||||
|
||||
// see if there are external fonts needed for certain chars in this table
|
||||
nsAutoString key, value;
|
||||
nsCAutoString key;
|
||||
nsAutoString value;
|
||||
for (PRInt32 i = 1; ; i++) {
|
||||
key.Assign(NS_LITERAL_STRING("external."));
|
||||
key.Assign(NS_LITERAL_CSTRING("external."));
|
||||
key.AppendInt(i, 10);
|
||||
rv = mGlyphProperties->GetStringProperty(key, value);
|
||||
if (NS_FAILED(rv)) break;
|
||||
|
@ -403,9 +404,12 @@ nsGlyphTable::ElementAt(nsIPresContext* aPresContext, nsMathMLChar* aChar, PRUin
|
|||
// Update our cache if it is not associated to this character
|
||||
PRUnichar uchar = aChar->mData[0];
|
||||
if (mCharCache != uchar) {
|
||||
// The key in the property file is interpreted as ASCII and kept as such ...
|
||||
// The key in the property file is interpreted as ASCII and kept
|
||||
// as such ...
|
||||
char cbuf[10]; PR_snprintf(cbuf, sizeof(cbuf), "\\u%04X", uchar);
|
||||
nsAutoString key, value; key.AssignWithConversion(cbuf);
|
||||
nsDependentCString key(cbuf);
|
||||
|
||||
nsAutoString value;
|
||||
nsresult rv = mGlyphProperties->GetStringProperty(key, value);
|
||||
if (NS_FAILED(rv)) return kNullGlyph;
|
||||
Clean(value);
|
||||
|
@ -415,7 +419,8 @@ nsGlyphTable::ElementAt(nsIPresContext* aPresContext, nsMathMLChar* aChar, PRUin
|
|||
// as combined pairs of 'code@font', excluding the '@' separator. This means that
|
||||
// mGlyphCache[2*k] will later be rendered with mFontName[mGlyphCache[2*k+1]-'0']
|
||||
// Note: font identifier is internally an ASCII digit to avoid the null char issue
|
||||
nsAutoString buffer, puaKey, puaValue;
|
||||
nsAutoString buffer, puaValue;
|
||||
nsCAutoString puaKey;
|
||||
PRInt32 length = value.Length();
|
||||
for (PRInt32 i = 0, j = 0; i < length; i++, j++) {
|
||||
PRUnichar code = value[i];
|
||||
|
@ -429,7 +434,7 @@ nsGlyphTable::ElementAt(nsIPresContext* aPresContext, nsMathMLChar* aChar, PRUin
|
|||
// the PUA, and lookup "key.[TLMBRG1-9]" in the PUA
|
||||
else if (code == PRUnichar(0xF8FF)) {
|
||||
puaKey.Assign(key);
|
||||
puaKey.Append(PRUnichar('.'));
|
||||
puaKey.Append('.');
|
||||
puaKey.Append(GetAnnotation(aChar, j));
|
||||
rv = gPUAProperties->GetStringProperty(puaKey, puaValue);
|
||||
if (NS_FAILED(rv) || !puaValue.Length()) return kNullGlyph;
|
||||
|
@ -440,9 +445,9 @@ nsGlyphTable::ElementAt(nsIPresContext* aPresContext, nsMathMLChar* aChar, PRUin
|
|||
else if ((i+2 < length) && (value[i+1] == PRUnichar('.'))) {
|
||||
i += 2;
|
||||
PR_snprintf(cbuf, sizeof(cbuf), "\\u%04X", code);
|
||||
puaKey.AssignWithConversion(cbuf);
|
||||
puaKey.Append(PRUnichar('.'));
|
||||
puaKey.Append(value[i]);
|
||||
puaKey.Assign(cbuf);
|
||||
puaKey.Append('.');
|
||||
puaKey.Append(char(value[i])); // safe cast, it's ascii
|
||||
rv = gPUAProperties->GetStringProperty(puaKey, puaValue);
|
||||
if (NS_FAILED(rv) || !puaValue.Length()) return kNullGlyph;
|
||||
code = puaValue[0];
|
||||
|
@ -1022,12 +1027,12 @@ PreferredFontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData)
|
|||
|
||||
// Store the list of preferred extension fonts for this char
|
||||
static void
|
||||
SetPreferredTableList(PRUnichar aChar, nsString& aExtension, nsString& aFamilyList)
|
||||
SetPreferredTableList(PRUnichar aChar, nsACString& aExtension, nsString& aFamilyList)
|
||||
{
|
||||
PRBool isFontForParts;
|
||||
if (aExtension.Equals(NS_LITERAL_STRING(".parts")))
|
||||
if (aExtension.Equals(NS_LITERAL_CSTRING(".parts")))
|
||||
isFontForParts = PR_TRUE;
|
||||
else if (aExtension.Equals(NS_LITERAL_STRING(".variants")))
|
||||
else if (aExtension.Equals(NS_LITERAL_CSTRING(".variants")))
|
||||
isFontForParts = PR_FALSE;
|
||||
else return; // input is not applicable
|
||||
|
||||
|
@ -1120,7 +1125,8 @@ InitGlobals(nsIPresContext* aPresContext)
|
|||
It will be deleted at shutdown, even if a failure happens below.
|
||||
*/
|
||||
|
||||
nsAutoString key, value;
|
||||
nsCAutoString key;
|
||||
nsAutoString value;
|
||||
nsCOMPtr<nsIPersistentProperties> mathfontProp;
|
||||
|
||||
// Add the math fonts in the gGlyphTableList in order of preference ...
|
||||
|
@ -1148,7 +1154,8 @@ InitGlobals(nsIPresContext* aPresContext)
|
|||
}
|
||||
if (familyList.IsEmpty()) {
|
||||
// fallback to the default list
|
||||
rv = mathfontProp->GetStringProperty(NS_LITERAL_STRING("mathfont-family"), value);
|
||||
rv = mathfontProp->GetStringProperty(NS_LITERAL_CSTRING("mathfont-family"),
|
||||
value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
font.name.Assign(value);
|
||||
}
|
||||
|
@ -1170,15 +1177,13 @@ InitGlobals(nsIPresContext* aPresContext)
|
|||
|
||||
// Let the particular characters have their preferred extension tables
|
||||
nsCOMPtr<nsISimpleEnumerator> iterator;
|
||||
if (NS_SUCCEEDED(mathfontProp->SimpleEnumerateProperties(getter_AddRefs(iterator)))) {
|
||||
if (NS_SUCCEEDED(mathfontProp->Enumerate(getter_AddRefs(iterator)))) {
|
||||
PRBool more;
|
||||
while ((NS_SUCCEEDED(iterator->HasMoreElements(&more))) && more) {
|
||||
nsCOMPtr<nsIPropertyElement> element;
|
||||
if (NS_SUCCEEDED(iterator->GetNext(getter_AddRefs(element)))) {
|
||||
nsXPIDLString xkey, xvalue;
|
||||
if (NS_SUCCEEDED(element->GetKey(getter_Copies(xkey))) &&
|
||||
NS_SUCCEEDED(element->GetValue(getter_Copies(xvalue)))) {
|
||||
key.Assign(xkey);
|
||||
if (NS_SUCCEEDED(element->GetKey(key)) &&
|
||||
NS_SUCCEEDED(element->GetValue(value))) {
|
||||
// expected key: "mathfont-family.\uNNNN.parts" or
|
||||
// "mathfont-family.\uNNNN.variants"
|
||||
if ((22 <= key.Length()) && (0 == key.Find("mathfont-family.\\u"))) {
|
||||
|
@ -1187,7 +1192,6 @@ InitGlobals(nsIPresContext* aPresContext)
|
|||
PRUnichar uchar = key.ToInteger(&error, 16);
|
||||
if (error) continue;
|
||||
key.Cut(0, 4); // the digits of the unicode point ("NNNN")
|
||||
value.Assign(xvalue);
|
||||
Clean(value);
|
||||
SetPreferredTableList(uchar, key, value);
|
||||
}
|
||||
|
|
|
@ -169,8 +169,8 @@ SetProperty(OperatorData* aOperatorData,
|
|||
PRBool
|
||||
SetOperator(OperatorData* aOperatorData,
|
||||
nsOperatorFlags aForm,
|
||||
nsString aOperator,
|
||||
nsString aAttributes)
|
||||
const nsCString& aOperator,
|
||||
nsString& aAttributes)
|
||||
|
||||
{
|
||||
// aOperator is in the expanded format \uNNNN\uNNNN ...
|
||||
|
@ -298,9 +298,9 @@ InitOperators(void)
|
|||
|
||||
// Get the list of invariant chars
|
||||
for (PRInt32 i = 0; i < nsMathMLOperators::eMATHVARIANT_COUNT; ++i) {
|
||||
nsAutoString key, value;
|
||||
key.Assign(NS_LITERAL_STRING("mathvariant."));
|
||||
key.AppendWithConversion(kMathVariant_name[i]);
|
||||
nsCAutoString key(NS_LITERAL_CSTRING("mathvariant."));
|
||||
key.Append(kMathVariant_name[i]);
|
||||
nsAutoString value;
|
||||
mathfontProp->GetStringProperty(key, value);
|
||||
gInvariantCharArray->AppendString(value); // i.e., gInvariantCharArray[i] holds this list
|
||||
}
|
||||
|
@ -312,18 +312,16 @@ InitOperators(void)
|
|||
OperatorData dummyData;
|
||||
OperatorData* operatorData = &dummyData;
|
||||
nsCOMPtr<nsISimpleEnumerator> iterator;
|
||||
if (NS_SUCCEEDED(mathfontProp->SimpleEnumerateProperties(getter_AddRefs(iterator)))) {
|
||||
if (NS_SUCCEEDED(mathfontProp->Enumerate(getter_AddRefs(iterator)))) {
|
||||
PRBool more;
|
||||
PRInt32 index = 0;
|
||||
nsAutoString name, attributes;
|
||||
nsCAutoString name;
|
||||
nsAutoString attributes;
|
||||
while ((NS_SUCCEEDED(iterator->HasMoreElements(&more))) && more) {
|
||||
nsCOMPtr<nsIPropertyElement> element;
|
||||
if (NS_SUCCEEDED(iterator->GetNext(getter_AddRefs(element)))) {
|
||||
nsXPIDLString xkey, xvalue;
|
||||
if (NS_SUCCEEDED(element->GetKey(getter_Copies(xkey))) &&
|
||||
NS_SUCCEEDED(element->GetValue(getter_Copies(xvalue)))) {
|
||||
name.Assign(xkey);
|
||||
attributes.Assign(xvalue);
|
||||
if (NS_SUCCEEDED(element->GetKey(name)) &&
|
||||
NS_SUCCEEDED(element->GetValue(attributes))) {
|
||||
// expected key: operator.\uNNNN.{infix,postfix,prefix}
|
||||
if ((21 <= name.Length()) && (0 == name.Find("operator.\\u"))) {
|
||||
name.Cut(0, 9); // 9 is the length of "operator.";
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
#define TEST_URL "resource:/res/test.properties"
|
||||
static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID);
|
||||
|
@ -110,7 +111,7 @@ main(int argc, char* argv[])
|
|||
name[0] = 0;
|
||||
sprintf(name, "%d", i);
|
||||
nsAutoString v;
|
||||
ret = props->GetStringProperty(NS_ConvertASCIItoUCS2(name), v);
|
||||
ret = props->GetStringProperty(nsDependentCString(name), v);
|
||||
if (NS_FAILED(ret) || (!v.Length())) {
|
||||
break;
|
||||
}
|
||||
|
@ -125,56 +126,45 @@ main(int argc, char* argv[])
|
|||
i++;
|
||||
}
|
||||
|
||||
nsIBidirectionalEnumerator* propEnum = nsnull;
|
||||
ret = props->EnumerateProperties(&propEnum);
|
||||
nsCOMPtr<nsISimpleEnumerator> propEnum;
|
||||
ret = props->Enumerate(getter_AddRefs(propEnum));
|
||||
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("cannot enumerate properties\n");
|
||||
return 1;
|
||||
}
|
||||
ret = propEnum->First();
|
||||
if (NS_FAILED(ret))
|
||||
{
|
||||
printf("enumerator is empty\n");
|
||||
return 1;
|
||||
printf("cannot enumerate properties\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
cout << endl << "Key" << "\t" << "Value" << endl;
|
||||
cout << "---" << "\t" << "-----" << endl;
|
||||
while (NS_SUCCEEDED(ret))
|
||||
{
|
||||
nsIPropertyElement* propElem = nsnull;
|
||||
ret = propEnum->CurrentItem((nsISupports**)&propElem);
|
||||
|
||||
PRBool hasMore;
|
||||
while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
nsCOMPtr<nsISupports> sup;
|
||||
ret = propEnum->GetNext(getter_AddRefs(sup));
|
||||
|
||||
nsCOMPtr<nsIPropertyElement> propElem = do_QueryInterface(sup, &ret);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current item\n");
|
||||
return 1;
|
||||
printf("failed to get current item\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
PRUnichar *pKey = nsnull;
|
||||
PRUnichar *pVal = nsnull;
|
||||
nsCAutoString key;
|
||||
nsAutoString value;
|
||||
|
||||
ret = propElem->GetKey(&pKey);
|
||||
ret = propElem->GetKey(key);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current element's key\n");
|
||||
return 1;
|
||||
}
|
||||
ret = propElem->GetValue(&pVal);
|
||||
ret = propElem->GetValue(value);
|
||||
if (NS_FAILED(ret)) {
|
||||
printf("failed to get current element's value\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
nsAutoString keyAdjustedLengthBuff(pKey);
|
||||
nsAutoString valAdjustedLengthBuff(pVal);
|
||||
|
||||
char* keyCStr = ToNewCString(keyAdjustedLengthBuff);
|
||||
char* valCStr = ToNewCString(valAdjustedLengthBuff);
|
||||
if (keyCStr && valCStr)
|
||||
cout << keyCStr << "\t" << valCStr << endl;
|
||||
delete[] keyCStr;
|
||||
delete[] valCStr;
|
||||
delete[] pKey;
|
||||
delete[] pVal;
|
||||
ret = propEnum->Next();
|
||||
cout << key.get() << "\t" << value.get() << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -36,25 +36,28 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{C++
|
||||
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIProperties.h"
|
||||
#include "nsID.h"
|
||||
#include "nsString.h"
|
||||
|
||||
%}
|
||||
|
||||
[ptr] native nsStringPtr(nsString);
|
||||
#include "nsIProperties.idl"
|
||||
#include "nsIInputStream.idl"
|
||||
#include "nsIOutputStream.idl"
|
||||
#include "nsISimpleEnumerator.idl"
|
||||
|
||||
[scriptable, uuid(283EE646-1AEF-11D4-98B3-00C04fA0CE9A)]
|
||||
interface nsIPropertyElement : nsISupports {
|
||||
attribute wstring key;
|
||||
attribute wstring value;
|
||||
attribute AUTF8String key;
|
||||
attribute AString value;
|
||||
};
|
||||
|
||||
[scriptable, uuid(1A180F60-93B2-11d2-9B8B-00805F8A16D9)]
|
||||
interface nsIPersistentProperties : nsIProperties
|
||||
{
|
||||
void load(in nsIInputStream input);
|
||||
void save(in nsIOutputStream output, in AUTF8String header);
|
||||
void subclass(in nsIPersistentProperties superclass);
|
||||
|
||||
nsISimpleEnumerator enumerate();
|
||||
|
||||
AString getStringProperty(in AUTF8String key);
|
||||
AString setStringProperty(in AUTF8String key, in AString value);
|
||||
};
|
||||
|
||||
|
||||
|
@ -64,42 +67,13 @@ interface nsIPropertyElement : nsISupports {
|
|||
#define NS_IPROPERTYELEMENT_CID \
|
||||
{ 0x283ee645, 0x1aef, 0x11d4, \
|
||||
{ 0x98, 0xb3, 0x0, 0xc0, 0x4f, 0xa0, 0xce, 0x9a } }
|
||||
static NS_DEFINE_CID(kPropertyElementCID, NS_IPROPERTYELEMENT_CID);
|
||||
|
||||
// {1A180F60-93B2-11d2-9B8B-00805F8A16D9}
|
||||
#define NS_IPERSISTENTPROPERTIES_IID \
|
||||
{ 0x1a180f60, 0x93b2, 0x11d2, \
|
||||
{ 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9 } }
|
||||
|
||||
#define NS_IPERSISTENTPROPERTIES_CID \
|
||||
{ 0x2245e573, 0x9464, 0x11d2, \
|
||||
{ 0x9b, 0x8b, 0x0, 0x80, 0x5f, 0x8a, 0x16, 0xd9 } }
|
||||
static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
|
||||
|
||||
#define NS_PERSISTENTPROPERTIES_CONTRACTID "@mozilla.org/persistent-properties;1"
|
||||
#define NS_PERSISTENTPROPERTIES_CLASSNAME "Persistent Properties"
|
||||
|
||||
class nsIPersistentProperties : public nsIProperties
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPERSISTENTPROPERTIES_IID)
|
||||
|
||||
NS_IMETHOD Load(nsIInputStream* aIn) = 0;
|
||||
NS_IMETHOD Save(nsIOutputStream* aOut, const nsString& aHeader) = 0;
|
||||
NS_IMETHOD Subclass(nsIPersistentProperties* aSubclass) = 0;
|
||||
|
||||
/**
|
||||
* Enumerates the properties in the supplied enumerator.
|
||||
* @return NS_ERROR_FAILURE if no properties to enumerate
|
||||
*/
|
||||
NS_IMETHOD EnumerateProperties(nsIBidirectionalEnumerator** aResult) = 0;
|
||||
NS_IMETHOD SimpleEnumerateProperties(nsISimpleEnumerator** aResult) = 0;
|
||||
|
||||
// XXX these 2 methods will be subsumed by the ones from
|
||||
// nsIProperties once we figure this all out
|
||||
NS_IMETHOD GetStringProperty(const nsAString& aKey, nsAString& aValue) = 0;
|
||||
NS_IMETHOD SetStringProperty(const nsAString& aKey, nsAString& aNewValue,
|
||||
nsAString& aOldValue) = 0;
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn)
|
|||
else {
|
||||
nsAutoString key;
|
||||
while ((c >= 0) && (c != '=') && (c != ':')) {
|
||||
key.Append((PRUnichar) c);
|
||||
key.Append(PRUnichar(c));
|
||||
c = Read();
|
||||
}
|
||||
if (c < 0) {
|
||||
|
@ -253,7 +253,7 @@ nsPersistentProperties::Load(nsIInputStream *aIn)
|
|||
|
||||
value.Trim(trimThese, PR_TRUE, PR_TRUE);
|
||||
nsAutoString oldValue;
|
||||
mSubclass->SetStringProperty(key, value, oldValue);
|
||||
mSubclass->SetStringProperty(NS_ConvertUCS2toUTF8(key), value, oldValue);
|
||||
}
|
||||
}
|
||||
mIn->Close();
|
||||
|
@ -263,14 +263,16 @@ nsPersistentProperties::Load(nsIInputStream *aIn)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::SetStringProperty(const nsAString& aKey, nsAString& aNewValue,
|
||||
nsAString& aOldValue)
|
||||
nsPersistentProperties::SetStringProperty(const nsACString& aKey,
|
||||
const nsAString& aNewValue,
|
||||
nsAString& aOldValue)
|
||||
{
|
||||
#if 0
|
||||
cout << "will add " << NS_LossyConvertUCS2toASCII(aKey).get() << "=" << NS_LossyConvertUCS2ToASCII(aNewValue).get() << endl;
|
||||
cout << "will add " << aKey.get() << "=" <<
|
||||
NS_LossyConvertUCS2ToASCII(aNewValue).get() << endl;
|
||||
#endif
|
||||
|
||||
NS_ConvertUCS2toUTF8 flatKey(aKey);
|
||||
const nsAFlatCString& flatKey = PromiseFlatCString(aKey);
|
||||
propertyTableEntry *entry =
|
||||
NS_STATIC_CAST(propertyTableEntry*,
|
||||
PL_DHashTableOperate(&mTable, flatKey.get(), PL_DHASH_ADD));
|
||||
|
@ -279,7 +281,7 @@ nsPersistentProperties::SetStringProperty(const nsAString& aKey, nsAString& aNew
|
|||
aOldValue = entry->mValue;
|
||||
NS_WARNING(nsPrintfCString(aKey.Length() + 30,
|
||||
"the property %s already exists\n",
|
||||
NS_ConvertUCS2toUTF8(aKey).get()).get());
|
||||
flatKey.get()).get());
|
||||
}
|
||||
|
||||
entry->mKey = ArenaStrdup(flatKey, &mArena);
|
||||
|
@ -289,7 +291,7 @@ nsPersistentProperties::SetStringProperty(const nsAString& aKey, nsAString& aNew
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::Save(nsIOutputStream* aOut, const nsString& aHeader)
|
||||
nsPersistentProperties::Save(nsIOutputStream* aOut, const nsACString& aHeader)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
@ -305,9 +307,10 @@ nsPersistentProperties::Subclass(nsIPersistentProperties* aSubclass)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::GetStringProperty(const nsAString& aKey, nsAString& aValue)
|
||||
nsPersistentProperties::GetStringProperty(const nsACString& aKey,
|
||||
nsAString& aValue)
|
||||
{
|
||||
NS_ConvertUCS2toUTF8 flatKey(aKey);
|
||||
const nsAFlatCString& flatKey = PromiseFlatCString(aKey);
|
||||
|
||||
propertyTableEntry *entry =
|
||||
NS_STATIC_CAST(propertyTableEntry*,
|
||||
|
@ -329,8 +332,8 @@ AddElemToArray(PLDHashTable* table, PLDHashEntryHdr *hdr,
|
|||
NS_STATIC_CAST(propertyTableEntry*, hdr);
|
||||
|
||||
nsPropertyElement *element =
|
||||
new nsPropertyElement(NS_ConvertUTF8toUCS2(entry->mKey).get(),
|
||||
entry->mValue);
|
||||
new nsPropertyElement(nsDependentCString(entry->mKey),
|
||||
nsDependentString(entry->mValue));
|
||||
if (!element)
|
||||
return PL_DHASH_STOP;
|
||||
|
||||
|
@ -340,30 +343,9 @@ AddElemToArray(PLDHashTable* table, PLDHashEntryHdr *hdr,
|
|||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::EnumerateProperties(nsIBidirectionalEnumerator** aResult)
|
||||
{
|
||||
nsISupportsArray* propArray;
|
||||
nsresult rv = NS_NewISupportsArray(&propArray);
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
|
||||
// Step through hash entries populating a transient array
|
||||
PRUint32 n =
|
||||
PL_DHashTableEnumerate(&mTable, AddElemToArray, (void *)propArray);
|
||||
if ( n < mTable.entryCount )
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Convert array into enumerator
|
||||
rv = NS_NewISupportsArrayEnumerator(propArray, aResult);
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPersistentProperties::SimpleEnumerateProperties(nsISimpleEnumerator** aResult)
|
||||
nsPersistentProperties::Enumerate(nsISimpleEnumerator** aResult)
|
||||
{
|
||||
nsCOMPtr<nsIBidirectionalEnumerator> iterator;
|
||||
|
||||
|
@ -488,38 +470,28 @@ nsPropertyElement::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|||
NS_IMPL_ISUPPORTS1(nsPropertyElement, nsIPropertyElement)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPropertyElement::GetKey(PRUnichar **aReturnKey)
|
||||
nsPropertyElement::GetKey(nsACString& aReturnKey)
|
||||
{
|
||||
if (aReturnKey)
|
||||
{
|
||||
*aReturnKey = ToNewUnicode(mKey);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
aReturnKey = mKey;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPropertyElement::GetValue(PRUnichar **aReturnValue)
|
||||
nsPropertyElement::GetValue(nsAString& aReturnValue)
|
||||
{
|
||||
if (aReturnValue)
|
||||
{
|
||||
*aReturnValue = ToNewUnicode(mValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
aReturnValue = mValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPropertyElement::SetKey(const PRUnichar* aKey)
|
||||
nsPropertyElement::SetKey(const nsACString& aKey)
|
||||
{
|
||||
mKey = aKey;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPropertyElement::SetValue(const PRUnichar* aValue)
|
||||
nsPropertyElement::SetValue(const nsAString& aValue)
|
||||
{
|
||||
mValue = aValue;
|
||||
return NS_OK;
|
||||
|
|
|
@ -41,9 +41,13 @@
|
|||
#include "nsIPersistentProperties2.h"
|
||||
#include "pldhash.h"
|
||||
#include "plarena.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsIUnicharInputStream;
|
||||
|
||||
static NS_DEFINE_CID(kPropertyElementCID, NS_IPROPERTYELEMENT_CID);
|
||||
static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
|
||||
|
||||
class nsPersistentProperties : public nsIPersistentProperties
|
||||
{
|
||||
public:
|
||||
|
@ -52,19 +56,8 @@ public:
|
|||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPROPERTIES
|
||||
NS_DECL_NSIPERSISTENTPROPERTIES
|
||||
|
||||
// nsIPersistentProperties methods:
|
||||
NS_IMETHOD Load(nsIInputStream* aIn);
|
||||
NS_IMETHOD Save(nsIOutputStream* aOut, const nsString& aHeader);
|
||||
NS_IMETHOD Subclass(nsIPersistentProperties* aSubclass);
|
||||
NS_IMETHOD EnumerateProperties(nsIBidirectionalEnumerator* *aResult);
|
||||
NS_IMETHOD SimpleEnumerateProperties(nsISimpleEnumerator** aResult);
|
||||
|
||||
// XXX these 2 methods will be subsumed by the ones from
|
||||
// nsIProperties once we figure this all out
|
||||
NS_IMETHOD GetStringProperty(const nsAString& aKey, nsAString& aValue);
|
||||
NS_IMETHOD SetStringProperty(const nsAString& aKey, nsAString& aNewValue,
|
||||
nsAString& aOldValue);
|
||||
|
||||
// nsPersistentProperties methods:
|
||||
PRInt32 Read();
|
||||
|
@ -91,7 +84,7 @@ public:
|
|||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsPropertyElement(const PRUnichar *aKey, const PRUnichar *aValue)
|
||||
nsPropertyElement(const nsACString& aKey, const nsAString& aValue)
|
||||
: mKey(aKey), mValue(aValue)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
@ -100,18 +93,13 @@ public:
|
|||
virtual ~nsPropertyElement() {}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPROPERTYELEMENT
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
// nsIPropertyElement methods:
|
||||
NS_IMETHOD GetKey(PRUnichar **aReturnKey);
|
||||
NS_IMETHOD GetValue(PRUnichar **aReturnValue);
|
||||
NS_IMETHOD SetKey(const PRUnichar* aKey);
|
||||
NS_IMETHOD SetValue(const PRUnichar* aValue);
|
||||
|
||||
protected:
|
||||
nsString mKey;
|
||||
nsCString mKey;
|
||||
nsString mValue;
|
||||
};
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#include "nsRegisterItem.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "ScheduledTasks.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsProxiedService.h"
|
||||
|
@ -1236,24 +1237,20 @@ nsInstall::LoadResources(JSContext* cx, const nsString& aBaseName, jsval* aRetur
|
|||
if (!propElem)
|
||||
continue;
|
||||
|
||||
nsXPIDLString pKey;
|
||||
nsXPIDLString pVal;
|
||||
|
||||
ret = propElem->GetKey(getter_Copies(pKey));
|
||||
nsAutoString pVal;
|
||||
nsCAutoString pKey;
|
||||
ret = propElem->GetKey(pKey);
|
||||
if (NS_FAILED(ret))
|
||||
goto cleanup;
|
||||
ret = propElem->GetValue(getter_Copies(pVal));
|
||||
ret = propElem->GetValue(pVal);
|
||||
if (NS_FAILED(ret))
|
||||
goto cleanup;
|
||||
|
||||
nsXPIDLCString keyCStr;
|
||||
keyCStr.Adopt(ToNewCString(pKey));
|
||||
|
||||
if (keyCStr.get() && pVal.get())
|
||||
if (!pKey.IsEmpty() && !pKey.IsEmpty())
|
||||
{
|
||||
JSString* propValJSStr = JS_NewUCStringCopyZ(cx, NS_REINTERPRET_CAST(const jschar*, pVal.get()));
|
||||
jsval propValJSVal = STRING_TO_JSVAL(propValJSStr);
|
||||
JS_SetProperty(cx, res, keyCStr.get(), &propValJSVal);
|
||||
JS_SetProperty(cx, res, pKey.get(), &propValJSVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
#include "nsIEventQueueService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsIZipReader.h"
|
||||
#include "nsIChromeRegistry.h"
|
||||
|
|
Загрузка…
Ссылка в новой задаче