fixes bug 270110 "Add versions of nsDependentString and friends to the Gecko SDK" r=bsmedberg

This commit is contained in:
darin%meer.net 2004-11-30 00:57:24 +00:00
Родитель fc0cee9787
Коммит ae5692eef4
9 изменённых файлов: 819 добавлений и 682 удалений

Просмотреть файл

@ -39,7 +39,10 @@
#define nsColor_h___
#include "gfxCore.h"
#include "nsStringFwd.h"
class nsAString;
class nsString;
class nsCString;
// A color is a 32 bit unsigned integer with four components: R, G, B
// and A.
@ -95,7 +98,7 @@ extern "C" NS_GFX_(PRBool) NS_LooseHexToRGB(const nsString& aBuf, nscolor* aResu
// The returned string is always 7 characters including a '#' character.
extern "C" NS_GFX_(void) NS_RGBToHex(nscolor aColor, nsAString& aResult);
extern "C" NS_GFX_(void) NS_RGBToASCIIHex(nscolor aColor,
nsAFlatCString& aResult);
nsCString& aResult);
// Translate a color name to a color. Return true if it parses ok,
// otherwise return false.

Просмотреть файл

@ -40,108 +40,12 @@
#ifndef nsEmbedString_h___
#define nsEmbedString_h___
#ifndef MOZILLA_STRICT_API
#error nsEmbedString requires defining MOZILLA_STRICT_API
#endif
#include "nsStringAPI.h"
class nsEmbedString : public nsStringContainer
{
public:
typedef nsEmbedString self_type;
typedef nsAString abstract_string_type;
nsEmbedString()
{
NS_StringContainerInit(*this);
}
/**
* compatibility
*/
typedef nsString nsEmbedString;
typedef nsCString nsEmbedCString;
nsEmbedString(const self_type& aString)
{
NS_StringContainerInit(*this);
NS_StringCopy(*this, aString);
}
explicit
nsEmbedString(const abstract_string_type& aReadable)
{
NS_StringContainerInit(*this);
NS_StringCopy(*this, aReadable);
}
explicit
nsEmbedString(const char_type* aData, size_type aLength = PR_UINT32_MAX)
{
NS_StringContainerInit(*this);
NS_StringSetData(*this, aData, aLength);
}
~nsEmbedString()
{
NS_StringContainerFinish(*this);
}
const char_type* get() const
{
const char_type* data;
NS_StringGetData(*this, &data);
return data;
}
self_type& operator=(const self_type& aString) { Assign(aString); return *this; }
self_type& operator=(const abstract_string_type& aReadable) { Assign(aReadable); return *this; }
self_type& operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
self_type& operator=(char_type aChar) { Assign(aChar); return *this; }
};
class nsEmbedCString : public nsCStringContainer
{
public:
typedef nsEmbedCString self_type;
typedef nsACString abstract_string_type;
nsEmbedCString()
{
NS_CStringContainerInit(*this);
}
nsEmbedCString(const self_type& aString)
{
NS_CStringContainerInit(*this);
NS_CStringCopy(*this, aString);
}
explicit
nsEmbedCString(const abstract_string_type& aReadable)
{
NS_CStringContainerInit(*this);
NS_CStringCopy(*this, aReadable);
}
explicit
nsEmbedCString(const char_type* aData, size_type aLength = PR_UINT32_MAX)
{
NS_CStringContainerInit(*this);
NS_CStringSetData(*this, aData, aLength);
}
~nsEmbedCString()
{
NS_CStringContainerFinish(*this);
}
const char_type* get() const
{
const char_type* data;
NS_CStringGetData(*this, &data);
return data;
}
self_type& operator=(const self_type& aString) { Assign(aString); return *this; }
self_type& operator=(const abstract_string_type& aReadable) { Assign(aReadable); return *this; }
self_type& operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
self_type& operator=(char_type aChar) { Assign(aChar); return *this; }
};
#endif // !defined(nsEmbedString_h___)
#endif

Просмотреть файл

@ -788,6 +788,11 @@ public:
return NS_StringGetData(*this, &data);
}
NS_HIDDEN_(PRBool) IsEmpty() const
{
return Length() == 0;
}
NS_HIDDEN_(void) Assign(const self_type& aString)
{
NS_StringCopy(*this, aString);
@ -870,6 +875,11 @@ public:
return NS_CStringGetData(*this, &data);
}
NS_HIDDEN_(PRBool) IsEmpty() const
{
return Length() == 0;
}
NS_HIDDEN_(void) Assign(const self_type& aString)
{
NS_CStringCopy(*this, aString);
@ -953,4 +963,639 @@ public:
nsCStringContainer() {} // MSVC6 needs this
};
/* ------------------------------------------------------------------------- */
/**
* Below we define a number of inlined helper classes that make the frozen
* string API easier to use.
*/
#ifdef MOZILLA_STRICT_API
#include "nsDebug.h"
/**
* Rename symbols to avoid conflicting with internal versions.
*/
#define nsString nsString_external
#define nsCString nsCString_external
#define nsDependentString nsDependentString_external
#define nsDependentCString nsDependentCString_external
#define NS_ConvertASCIItoUTF16 NS_ConvertASCIItoUTF16_external
#define NS_ConvertUTF8toUTF16 NS_ConvertUTF8toUTF16_external
#define NS_ConvertUTF16toUTF8 NS_ConvertUTF16toUTF8_external
#define NS_LossyConvertUTF16toASCII NS_LossyConvertUTF16toASCII_external
#define nsGetterCopies nsGetterCopies_external
#define nsCGetterCopies nsCGetterCopies_external
#define nsDependentSubstring nsDependentSubstring_external
#define nsDependentCSubstring nsDependentCSubstring_external
/**
* basic strings
*/
class nsString : public nsStringContainer
{
public:
typedef nsString self_type;
typedef nsAString abstract_string_type;
nsString()
{
NS_StringContainerInit(*this);
}
nsString(const self_type& aString)
{
NS_StringContainerInit(*this);
NS_StringCopy(*this, aString);
}
explicit
nsString(const abstract_string_type& aReadable)
{
NS_StringContainerInit(*this);
NS_StringCopy(*this, aReadable);
}
explicit
nsString(const char_type* aData, size_type aLength = PR_UINT32_MAX)
{
NS_StringContainerInit2(*this, aData, aLength, 0);
}
~nsString()
{
NS_StringContainerFinish(*this);
}
const char_type* get() const
{
const char_type* data;
NS_StringGetData(*this, &data);
return data;
}
self_type& operator=(const self_type& aString) { Assign(aString); return *this; }
self_type& operator=(const abstract_string_type& aReadable) { Assign(aReadable); return *this; }
self_type& operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
self_type& operator=(char_type aChar) { Assign(aChar); return *this; }
void Adopt(const char_type *aData, size_type aLength = PR_UINT32_MAX)
{
NS_StringContainerFinish(*this);
NS_StringContainerInit2(*this, aData, aLength,
NS_STRING_CONTAINER_INIT_ADOPT);
}
protected:
nsString(const char_type* aData, size_type aLength, PRUint32 aFlags)
{
NS_StringContainerInit2(*this, aData, aLength, aFlags);
}
};
class nsCString : public nsCStringContainer
{
public:
typedef nsCString self_type;
typedef nsACString abstract_string_type;
nsCString()
{
NS_CStringContainerInit(*this);
}
nsCString(const self_type& aString)
{
NS_CStringContainerInit(*this);
NS_CStringCopy(*this, aString);
}
explicit
nsCString(const abstract_string_type& aReadable)
{
NS_CStringContainerInit(*this);
NS_CStringCopy(*this, aReadable);
}
explicit
nsCString(const char_type* aData, size_type aLength = PR_UINT32_MAX)
{
NS_CStringContainerInit(*this);
NS_CStringSetData(*this, aData, aLength);
}
~nsCString()
{
NS_CStringContainerFinish(*this);
}
const char_type* get() const
{
const char_type* data;
NS_CStringGetData(*this, &data);
return data;
}
self_type& operator=(const self_type& aString) { Assign(aString); return *this; }
self_type& operator=(const abstract_string_type& aReadable) { Assign(aReadable); return *this; }
self_type& operator=(const char_type* aPtr) { Assign(aPtr); return *this; }
self_type& operator=(char_type aChar) { Assign(aChar); return *this; }
void Adopt(const char_type *aData, size_type aLength = PR_UINT32_MAX)
{
NS_CStringContainerFinish(*this);
NS_CStringContainerInit2(*this, aData, aLength,
NS_CSTRING_CONTAINER_INIT_ADOPT);
}
protected:
nsCString(const char_type* aData, size_type aLength, PRUint32 aFlags)
{
NS_CStringContainerInit2(*this, aData, aLength, aFlags);
}
};
/**
* dependent strings
*/
class nsDependentString : public nsString
{
public:
typedef nsDependentString self_type;
nsDependentString() {}
explicit
nsDependentString(const char_type* aData, size_type aLength = PR_UINT32_MAX)
: nsString(aData, aLength, NS_CSTRING_CONTAINER_INIT_DEPEND)
{}
void Rebind(const char_type* aData, size_type aLength = PR_UINT32_MAX)
{
NS_StringContainerFinish(*this);
NS_StringContainerInit2(*this, aData, aLength,
NS_STRING_CONTAINER_INIT_DEPEND);
}
private:
self_type& operator=(const self_type& aString); // NOT IMPLEMENTED
};
class nsDependentCString : public nsCString
{
public:
typedef nsDependentCString self_type;
nsDependentCString() {}
explicit
nsDependentCString(const char_type* aData, size_type aLength = PR_UINT32_MAX)
: nsCString(aData, aLength, NS_CSTRING_CONTAINER_INIT_DEPEND)
{}
void Rebind(const char_type* aData, size_type aLength = PR_UINT32_MAX)
{
NS_CStringContainerFinish(*this);
NS_CStringContainerInit2(*this, aData, aLength,
NS_CSTRING_CONTAINER_INIT_DEPEND);
}
private:
self_type& operator=(const self_type& aString); // NOT IMPLEMENTED
};
/**
* conversion classes
*/
class NS_ConvertASCIItoUTF16 : public nsString
{
public:
typedef NS_ConvertASCIItoUTF16 self_type;
explicit
NS_ConvertASCIItoUTF16(const nsACString& aStr)
{
NS_CStringToUTF16(aStr, NS_CSTRING_ENCODING_ASCII, *this);
}
explicit
NS_ConvertASCIItoUTF16(const char* aData, PRUint32 aLength = PR_UINT32_MAX)
{
NS_CStringToUTF16(nsDependentCString(aData, aLength),
NS_CSTRING_ENCODING_ASCII, *this);
}
private:
self_type& operator=(const self_type& aString); // NOT IMPLEMENTED
};
class NS_ConvertUTF8toUTF16 : public nsString
{
public:
typedef NS_ConvertUTF8toUTF16 self_type;
explicit
NS_ConvertUTF8toUTF16(const nsACString& aStr)
{
NS_CStringToUTF16(aStr, NS_CSTRING_ENCODING_UTF8, *this);
}
explicit
NS_ConvertUTF8toUTF16(const char* aData, PRUint32 aLength = PR_UINT32_MAX)
{
NS_CStringToUTF16(nsDependentCString(aData, aLength),
NS_CSTRING_ENCODING_UTF8, *this);
}
private:
self_type& operator=(const self_type& aString); // NOT IMPLEMENTED
};
class NS_ConvertUTF16toUTF8 : public nsCString
{
public:
typedef NS_ConvertUTF16toUTF8 self_type;
explicit
NS_ConvertUTF16toUTF8(const nsAString& aStr)
{
NS_UTF16ToCString(aStr, NS_CSTRING_ENCODING_UTF8, *this);
}
explicit
NS_ConvertUTF16toUTF8(const PRUnichar* aData, PRUint32 aLength = PR_UINT32_MAX)
{
NS_UTF16ToCString(nsDependentString(aData, aLength),
NS_CSTRING_ENCODING_UTF8, *this);
}
private:
self_type& operator=(const self_type& aString); // NOT IMPLEMENTED
};
class NS_LossyConvertUTF16toASCII : public nsCString
{
public:
typedef NS_LossyConvertUTF16toASCII self_type;
explicit
NS_LossyConvertUTF16toASCII(const nsAString& aStr)
{
NS_UTF16ToCString(aStr, NS_CSTRING_ENCODING_ASCII, *this);
}
explicit
NS_LossyConvertUTF16toASCII(const PRUnichar* aData, PRUint32 aLength = PR_UINT32_MAX)
{
NS_UTF16ToCString(nsDependentString(aData, aLength),
NS_CSTRING_ENCODING_ASCII, *this);
}
private:
self_type& operator=(const self_type& aString); // NOT IMPLEMENTED
};
/**
* literal strings
*
* NOTE: HAVE_CPP_2BYTE_WCHAR_T may be automatically defined for some platforms
* in nscore.h. On other platforms, it may be defined in xpcom-config.h.
* Under GCC, this define should only be set if compiling with -fshort-wchar.
*/
#ifdef HAVE_CPP_2BYTE_WCHAR_T
#define NS_LL(s) L##s
#define NS_MULTILINE_LITERAL_STRING(s) nsDependentString(NS_REINTERPRET_CAST(const nsAString::char_type*, s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
#define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(NS_REINTERPRET_CAST(const nsAString::char_type*, s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const nsDependentString n(NS_REINTERPRET_CAST(const nsAString::char_type*, s), PRUint32((sizeof(s)/sizeof(wchar_t))-1))
typedef nsDependentString nsLiteralString;
#else
#define NS_LL(s) s
#define NS_MULTILINE_LITERAL_STRING(s) NS_ConvertASCIItoUTF16(s, PRUint32(sizeof(s)-1))
#define NS_MULTILINE_LITERAL_STRING_INIT(n,s) n(s, PRUint32(sizeof(s)-1))
#define NS_NAMED_MULTILINE_LITERAL_STRING(n,s) const NS_ConvertASCIItoUTF16 n(s, PRUint32(sizeof(s)-1))
typedef NS_ConvertASCIItoUTF16 nsLiteralString;
#endif
/*
* Macro arguments used in concatenation or stringification won't be expanded.
* Therefore, in order for |NS_L(FOO)| to work as expected (which is to expand
* |FOO| before doing whatever |NS_L| needs to do to it) a helper macro needs
* to be inserted in between to allow the macro argument to expand.
* See "3.10.6 Separate Expansion of Macro Arguments" of the CPP manual for a
* more accurate and precise explanation.
*/
#define NS_L(s) NS_LL(s)
#define NS_LITERAL_STRING(s) NS_STATIC_CAST(const nsString&, NS_MULTILINE_LITERAL_STRING(NS_LL(s)))
#define NS_LITERAL_STRING_INIT(n,s) NS_MULTILINE_LITERAL_STRING_INIT(n, NS_LL(s))
#define NS_NAMED_LITERAL_STRING(n,s) NS_NAMED_MULTILINE_LITERAL_STRING(n, NS_LL(s))
#define NS_LITERAL_CSTRING(s) NS_STATIC_CAST(const nsDependentCString&, nsDependentCString(s, PRUint32(sizeof(s)-1)))
#define NS_LITERAL_CSTRING_INIT(n,s) n(s, PRUint32(sizeof(s)-1))
#define NS_NAMED_LITERAL_CSTRING(n,s) const nsDependentCString n(s, PRUint32(sizeof(s)-1))
typedef nsDependentCString nsLiteralCString;
/**
* getter_Copies support
*
* NS_IMETHOD GetBlah(PRUnichar**);
*
* void some_function()
* {
* nsString blah;
* GetBlah(getter_Copies(blah));
* // ...
* }
*/
class nsGetterCopies
{
public:
typedef PRUnichar char_type;
nsGetterCopies(nsString& aStr)
: mString(aStr), mData(nsnull)
{}
~nsGetterCopies()
{
mString.Adopt(mData);
}
operator char_type**()
{
return &mData;
}
private:
nsString& mString;
char_type* mData;
};
inline nsGetterCopies
getter_Copies(nsString& aString)
{
return nsGetterCopies(aString);
}
class nsCGetterCopies
{
public:
typedef char char_type;
nsCGetterCopies(nsCString& aStr)
: mString(aStr), mData(nsnull)
{}
~nsCGetterCopies()
{
mString.Adopt(mData);
}
operator char_type**()
{
return &mData;
}
private:
nsCString& mString;
char_type* mData;
};
inline nsCGetterCopies
getter_Copies(nsCString& aString)
{
return nsCGetterCopies(aString);
}
/**
* substrings
*/
class nsDependentSubstring : public nsStringContainer
{
public:
typedef nsDependentSubstring self_type;
typedef nsAString abstract_string_type;
~nsDependentSubstring()
{
NS_StringContainerFinish(*this);
}
nsDependentSubstring()
{
NS_StringContainerInit(*this);
}
nsDependentSubstring(const char_type *aStart, PRUint32 aLength)
{
NS_StringContainerInit2(*this, aStart, aLength,
NS_STRING_CONTAINER_INIT_DEPEND |
NS_STRING_CONTAINER_INIT_SUBSTRING);
}
nsDependentSubstring(const abstract_string_type& aStr,
PRUint32 aStartPos)
{
const PRUnichar* data;
PRUint32 len = NS_StringGetData(aStr, &data);
NS_StringContainerInit2(*this, data + aStartPos, len - aStartPos,
NS_STRING_CONTAINER_INIT_DEPEND |
NS_STRING_CONTAINER_INIT_SUBSTRING);
}
nsDependentSubstring(const abstract_string_type& aStr,
PRUint32 aStartPos, PRUint32 aLength)
{
const PRUnichar* data;
PRUint32 len = NS_StringGetData(aStr, &data);
NS_ASSERTION(aStartPos + aLength <= len, "bad length");
NS_StringContainerInit2(*this, data + aStartPos, aLength,
NS_STRING_CONTAINER_INIT_DEPEND |
NS_STRING_CONTAINER_INIT_SUBSTRING);
}
void Rebind(const char_type *aStart, PRUint32 aLength)
{
NS_StringContainerFinish(*this);
NS_StringContainerInit2(*this, aStart, aLength,
NS_STRING_CONTAINER_INIT_DEPEND |
NS_STRING_CONTAINER_INIT_SUBSTRING);
}
private:
self_type& operator=(const self_type& aString); // NOT IMPLEMENTED
};
class nsDependentCSubstring : public nsCStringContainer
{
public:
typedef nsDependentCSubstring self_type;
typedef nsACString abstract_string_type;
~nsDependentCSubstring()
{
NS_CStringContainerFinish(*this);
}
nsDependentCSubstring()
{
NS_CStringContainerInit(*this);
}
nsDependentCSubstring(const char_type *aStart, PRUint32 aLength)
{
NS_CStringContainerInit2(*this, aStart, aLength,
NS_CSTRING_CONTAINER_INIT_DEPEND |
NS_CSTRING_CONTAINER_INIT_SUBSTRING);
}
nsDependentCSubstring(const abstract_string_type& aStr,
PRUint32 aStartPos)
{
const char* data;
PRUint32 len = NS_CStringGetData(aStr, &data);
NS_CStringContainerInit2(*this, data + aStartPos, len - aStartPos,
NS_CSTRING_CONTAINER_INIT_DEPEND |
NS_CSTRING_CONTAINER_INIT_SUBSTRING);
}
nsDependentCSubstring(const abstract_string_type& aStr,
PRUint32 aStartPos, PRUint32 aLength)
{
const char* data;
PRUint32 len = NS_CStringGetData(aStr, &data);
NS_ASSERTION(aStartPos + aLength <= len, "bad length");
NS_CStringContainerInit2(*this, data + aStartPos, aLength,
NS_CSTRING_CONTAINER_INIT_DEPEND |
NS_CSTRING_CONTAINER_INIT_SUBSTRING);
}
void Rebind(const char_type *aStart, PRUint32 aLength)
{
NS_CStringContainerFinish(*this);
NS_CStringContainerInit2(*this, aStart, aLength,
NS_CSTRING_CONTAINER_INIT_DEPEND |
NS_CSTRING_CONTAINER_INIT_SUBSTRING);
}
private:
self_type& operator=(const self_type& aString); // NOT IMPLEMENTED
};
/**
* Various nsDependentC?Substring constructor functions
*/
// PRUnichar
inline
const nsDependentSubstring
Substring( const nsAString& str, PRUint32 startPos )
{
return nsDependentSubstring(str, startPos);
}
inline
const nsDependentSubstring
Substring( const nsAString& str, PRUint32 startPos, PRUint32 length )
{
return nsDependentSubstring(str, startPos, length);
}
inline
const nsDependentSubstring
Substring( const PRUnichar* start, const PRUnichar* end )
{
return nsDependentSubstring(start, end - start);
}
inline
const nsDependentSubstring
Substring( const PRUnichar* start, PRUint32 length )
{
return nsDependentSubstring(start, length);
}
inline
const nsDependentSubstring
StringHead( const nsAString& str, PRUint32 count )
{
return nsDependentSubstring(str, 0, count);
}
inline
const nsDependentSubstring
StringTail( const nsAString& str, PRUint32 count )
{
return nsDependentSubstring(str, str.Length() - count, count);
}
// char
inline
const nsDependentCSubstring
Substring( const nsACString& str, PRUint32 startPos )
{
return nsDependentCSubstring(str, startPos);
}
inline
const nsDependentCSubstring
Substring( const nsACString& str, PRUint32 startPos, PRUint32 length )
{
return nsDependentCSubstring(str, startPos, length);
}
inline
const nsDependentCSubstring
Substring( const char* start, const char* end )
{
return nsDependentCSubstring(start, end - start);
}
inline
const nsDependentCSubstring
Substring( const char* start, PRUint32 length )
{
return nsDependentCSubstring(start, length);
}
inline
const nsDependentCSubstring
StringHead( const nsACString& str, PRUint32 count )
{
return nsDependentCSubstring(str, 0, count);
}
inline
const nsDependentCSubstring
StringTail( const nsACString& str, PRUint32 count )
{
return nsDependentCSubstring(str, str.Length() - count, count);
}
/*
* Canonical empty strings
*/
#define EmptyCString() nsCString()
#define EmptyString() nsString()
#endif // MOZILLA_STRICT_API
#endif // nsStringAPI_h__

Просмотреть файл

@ -39,11 +39,10 @@
#ifdef XPCOM_GLUE
#include "nsXPCOMGlue.h"
#include "nsStringSupport.h"
#else
#include "nsString.h"
#endif
#include "nsStringSupport.h"
#include "nsXPCOM.h"
#include "nsIServiceManager.h"
#include "nsServiceManagerUtils.h"
@ -532,11 +531,11 @@ static nsresult OpenWindow(const nsCString& aChromeURL,
nsCAutoString features("chrome,dialog=no,all");
if (aHeight != nsIAppShellService::SIZE_TO_CONTENT) {
features.Append(",height=");
features.AppendInt(aHeight);
AppendIntToString(features, aHeight);
}
if (aWidth != nsIAppShellService::SIZE_TO_CONTENT) {
features.Append(",width=");
features.AppendInt(aWidth);
AppendIntToString(features, aWidth);
}
#ifdef DEBUG_CMD_LINE
@ -570,13 +569,13 @@ static void DumpArbitraryHelp()
rv = catman->GetCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS,
entryString.get(),
getter_Copies(contractidString));
if (NS_FAILED(rv) || !((const char *)contractidString)) break;
if (NS_FAILED(rv) || contractidString.IsEmpty()) break;
#ifdef DEBUG_CMD_LINE
printf("cmd line handler contractid = %s\n", (const char *)contractidString);
printf("cmd line handler contractid = %s\n", contractidString.get());
#endif /* DEBUG_CMD_LINE */
nsCOMPtr <nsICmdLineHandler> handler(do_GetService((const char *)contractidString, &rv));
nsCOMPtr <nsICmdLineHandler> handler(do_GetService(contractidString.get(), &rv));
if (handler) {
nsXPIDLCString commandLineArg;
@ -587,16 +586,16 @@ static void DumpArbitraryHelp()
rv = handler->GetHelpText(getter_Copies(helpText));
if (NS_FAILED(rv)) continue;
if ((const char *)commandLineArg) {
printf("%s%s", HELP_SPACER_1,(const char *)commandLineArg);
if (!commandLineArg.IsEmpty()) {
printf("%s%s", HELP_SPACER_1, commandLineArg.get());
PRBool handlesArgs = PR_FALSE;
rv = handler->GetHandlesArgs(&handlesArgs);
if (NS_SUCCEEDED(rv) && handlesArgs) {
printf(" <url>");
}
if ((const char *)helpText) {
printf("%s%s\n",HELP_SPACER_2,(const char *)helpText);
if (!helpText.IsEmpty()) {
printf("%s%s\n", HELP_SPACER_2, helpText.get());
}
}
}
@ -635,27 +634,27 @@ LaunchApplicationWithArgs(const char *commandLineArg,
if (NS_FAILED(rv)) return rv;
#ifdef DEBUG_CMD_LINE
printf("XXX got this one:\t%s\n\t%s\n\n",commandLineArg,(const char *)chromeUrlForTask);
printf("XXX got this one:\t%s\n\t%s\n\n",commandLineArg,chromeUrlForTask.get());
#endif /* DEBUG_CMD_LINE */
nsXPIDLCString cmdResult;
rv = cmdLineArgs->GetCmdLineValue(commandLineArg, getter_Copies(cmdResult));
if (NS_FAILED(rv)) return rv;
#ifdef DEBUG_CMD_LINE
printf("%s, cmdResult = %s\n",commandLineArg,(const char *)cmdResult);
printf("%s, cmdResult = %s\n",commandLineArg,cmdResult.get());
#endif /* DEBUG_CMD_LINE */
PRBool handlesArgs = PR_FALSE;
rv = handler->GetHandlesArgs(&handlesArgs);
if (handlesArgs) {
if ((const char *)cmdResult) {
if (PL_strcmp("1",(const char *)cmdResult)) {
if (!cmdResult.IsEmpty()) {
if (strcmp("1", cmdResult.get())) {
PRBool openWindowWithArgs = PR_TRUE;
rv = handler->GetOpenWindowWithArgs(&openWindowWithArgs);
if (NS_FAILED(rv)) return rv;
if (openWindowWithArgs) {
nsAutoString cmdArgs; cmdArgs.AssignWithConversion(cmdResult);
NS_ConvertASCIItoUTF16 cmdArgs(cmdResult);
#ifdef DEBUG_CMD_LINE
printf("opening %s with %s\n", chromeUrlForTask.get(), "OpenWindow");
#endif /* DEBUG_CMD_LINE */
@ -686,8 +685,8 @@ LaunchApplicationWithArgs(const char *commandLineArg,
}
}
else {
if (NS_SUCCEEDED(rv) && (const char*)cmdResult) {
if (PL_strcmp("1",cmdResult) == 0) {
if (NS_SUCCEEDED(rv) && !cmdResult.IsEmpty()) {
if (strcmp("1", cmdResult.get()) == 0) {
rv = OpenWindow(chromeUrlForTask, width, height);
if (NS_FAILED(rv)) return rv;
}
@ -821,7 +820,7 @@ static char kMatchOSLocalePref[] = "intl.locale.matchOS";
nsresult
getCountry(const nsAString& lc_name, nsAString& aCountry)
{
#ifdef XPCOM_GLUE
#ifdef MOZILLA_STRICT_API
const PRUnichar *begin = lc_name.BeginReading();
const PRUnichar *end = lc_name.EndReading();
while (begin != end) {
@ -880,38 +879,36 @@ static nsresult InstallGlobalLocale(nsICmdLineService *cmdLineArgs)
nsXPIDLCString cmdUI;
rv = cmdLineArgs->GetCmdLineValue(UILOCALE_CMD_LINE_ARG, getter_Copies(cmdUI));
if (NS_SUCCEEDED(rv)){
if (cmdUI) {
nsCAutoString UILocaleName(cmdUI);
if (!cmdUI.IsEmpty()) {
nsCOMPtr<nsIChromeRegistrySea> chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
if (chromeRegistry)
rv = chromeRegistry->SelectLocale(UILocaleName, PR_FALSE);
rv = chromeRegistry->SelectLocale(cmdUI, PR_FALSE);
}
}
// match OS when no cmdline override
if (!cmdUI && matchOS) {
if (cmdUI.IsEmpty() && matchOS) {
nsCOMPtr<nsIChromeRegistrySea> chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
if (chromeRegistry) {
chromeRegistry->SetRuntimeProvider(PR_TRUE);
rv = chromeRegistry->SelectLocale(NS_ConvertUCS2toUTF8(uiLang), PR_FALSE);
rv = chromeRegistry->SelectLocale(NS_ConvertUTF16toUTF8(uiLang), PR_FALSE);
}
}
nsXPIDLCString cmdContent;
rv = cmdLineArgs->GetCmdLineValue(CONTENTLOCALE_CMD_LINE_ARG, getter_Copies(cmdContent));
if (NS_SUCCEEDED(rv)){
if (cmdContent) {
nsCAutoString contentLocaleName(cmdContent);
if (!cmdContent.IsEmpty()) {
nsCOMPtr<nsIChromeRegistrySea> chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
if(chromeRegistry)
rv = chromeRegistry->SelectLocale(contentLocaleName, PR_FALSE);
rv = chromeRegistry->SelectLocale(cmdContent, PR_FALSE);
}
}
// match OS when no cmdline override
if (!cmdContent && matchOS) {
if (cmdContent.IsEmpty() && matchOS) {
nsCOMPtr<nsIChromeRegistrySea> chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
if (chromeRegistry) {
chromeRegistry->SetRuntimeProvider(PR_TRUE);
rv = chromeRegistry->SelectLocale(NS_ConvertUCS2toUTF8(country), PR_FALSE);
rv = chromeRegistry->SelectLocale(NS_ConvertUTF16toUTF8(country), PR_FALSE);
}
}
@ -951,7 +948,7 @@ static nsresult InitializeProfileService(nsICmdLineService *cmdLineArgs)
if (shouldShowUI) {
nsXPIDLCString arg;
if (NS_SUCCEEDED(cmdLineArgs->GetCmdLineValue("-silent", getter_Copies(arg)))) {
if ((const char*)arg) {
if (!arg.IsEmpty()) {
shouldShowUI = PR_FALSE;
}
}
@ -1277,7 +1274,7 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp )
if (obsService)
{
nsAutoString userMessage; userMessage.AssignLiteral("Creating first window...");
NS_NAMED_LITERAL_STRING(userMessage, "Creating first window...");
obsService->NotifyObservers(nsnull, "startup_user_notifcations", userMessage.get());
}

Просмотреть файл

@ -36,11 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#ifdef XPCOM_GLUE
#include "nsStringSupport.h"
#else
#include "nsString.h"
#endif
#include "nsNativeAppSupportBase.h"
#include "nsIObserver.h"

Просмотреть файл

@ -1,164 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* syd@netscape.com 2/12/00.
* pavlov@netscape.com 2/13/00.
* bryner@brianryner.com 11/20/01.
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifdef XPCOM_GLUE
#include "nsStringSupport.h"
#else
#include "nsString.h"
#endif
#include "nsNativeAppSupportBase.h"
#include "gdk/gdk.h"
#include "prenv.h"
#ifdef MOZ_XUL_APP
extern char* splash_xpm[];
#else
#include SPLASH_XPM
#endif
class nsSplashScreenGtk : public nsISplashScreen {
public:
nsSplashScreenGtk();
virtual ~nsSplashScreenGtk();
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_DECL_ISUPPORTS
private:
GdkWindow *mDialog;
}; // class nsSplashScreenGtk
class nsNativeAppSupportGtk : public nsNativeAppSupportBase {
// We don't have any methods to override.
};
NS_IMPL_ISUPPORTS1(nsSplashScreenGtk, nsISplashScreen)
nsSplashScreenGtk::nsSplashScreenGtk()
{
}
nsSplashScreenGtk::~nsSplashScreenGtk()
{
Hide();
}
NS_IMETHODIMP nsSplashScreenGtk::Show()
{
#ifdef MOZ_XUL_APP
if (!splash_xpm[0])
return NS_OK;
#endif
nsCAutoString path(PR_GetEnv("MOZILLA_FIVE_HOME"));
if (path.IsEmpty()) {
path.Assign("splash.xpm");
} else {
path.Append("/splash.xpm");
}
/* See if the user has a custom splash screen */
GdkPixmap* pmap = gdk_pixmap_colormap_create_from_xpm(NULL,
gdk_colormap_get_system(),
NULL, NULL, path.get());
if (!pmap) {
/* create a pixmap based on xpm data */
pmap = gdk_pixmap_colormap_create_from_xpm_d(NULL,
gdk_colormap_get_system(),
NULL, NULL, splash_xpm);
}
if (!pmap) {
gdk_window_destroy(mDialog);
mDialog = nsnull;
return NS_ERROR_FAILURE;
}
gint width, height;
gdk_window_get_size(pmap, &width, &height);
GdkWindowAttr attr;
attr.window_type = GDK_WINDOW_TEMP;
attr.wclass = GDK_INPUT_OUTPUT;
attr.x = (gdk_screen_width() >> 1) - (width >> 1);
attr.y = (gdk_screen_height() >> 1) - (height >> 1);
attr.width = width;
attr.height = height;
attr.event_mask = GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
mDialog = gdk_window_new(NULL, &attr, GDK_WA_X | GDK_WA_Y);
gdk_window_set_back_pixmap(mDialog, pmap, FALSE);
gdk_pixmap_unref(pmap);
gdk_window_show(mDialog);
return NS_OK;
}
NS_IMETHODIMP nsSplashScreenGtk::Hide()
{
if (mDialog) {
gdk_window_destroy(mDialog);
mDialog = nsnull;
}
return NS_OK;
}
nsresult NS_CreateNativeAppSupport(nsINativeAppSupport** aNativeApp) {
*aNativeApp = new nsNativeAppSupportGtk;
NS_ADDREF(*aNativeApp);
return NS_OK;
}
nsresult NS_CreateSplashScreen(nsISplashScreen** aSplash) {
*aSplash = new nsSplashScreenGtk;
NS_ADDREF(*aSplash);
return NS_OK;
}
PRBool NS_CanRun()
{
return PR_TRUE;
}

Просмотреть файл

@ -44,6 +44,8 @@
#define INCL_DOSERRORS
#include <os2.h>
#include "nsStringSupport.h"
#include "nsNativeAppSupportBase.h"
#include "nsNativeAppSupportOS2.h"
#include "nsICmdLineService.h"
@ -75,12 +77,6 @@
#include "nsIObserverService.h"
#include "nsXPFEComponentsCID.h"
#ifdef XPCOM_GLUE
#include "nsStringSupport.h"
#else
#include "nsString.h"
#endif
// These are needed to load a URL in a browser window.
#include "nsIDOMLocation.h"
#include "nsIJSContextStack.h"
@ -1475,7 +1471,7 @@ static void escapeQuotes( nsString &aString ) {
PRInt32 offset = -1;
while( 1 ) {
// Find next '"'.
offset = aString.FindChar( '"', ++offset );
offset = FindCharInString( aString, '"', ++offset );
if ( offset == kNotFound ) {
// No more quotes, exit.
break;
@ -1772,7 +1768,7 @@ void nsNativeAppSupportOS2::ParseDDEArg( const char* args, int index, nsCString&
// If this arg is quoted, then go to closing quote.
offset = advanceToEndOfQuotedArg( args, offset, argLen);
// Find next comma.
offset = temp.FindChar( ',', offset );
offset = FindCharInString( temp, ',', offset );
if ( offset == kNotFound ) {
// No more commas, give up.
aString = args;
@ -1789,7 +1785,7 @@ void nsNativeAppSupportOS2::ParseDDEArg( const char* args, int index, nsCString&
// the argument we want.
PRInt32 end = advanceToEndOfQuotedArg( args, offset++, argLen );
// Find next comma (or end of string).
end = temp.FindChar( ',', end );
end = FindCharInString( temp, ',', end );
if ( end == kNotFound ) {
// Arg is the rest of the string.
end = argLen;
@ -1874,13 +1870,13 @@ nsNativeAppSupportOS2::HandleRequest( LPBYTE request, PRBool newWindow ) {
// first see if there is a url
nsXPIDLCString arg;
rv = args->GetURLToLoad(getter_Copies(arg));
if (NS_SUCCEEDED(rv) && (const char*)arg ) {
if (NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {
// Launch browser.
#if MOZ_DEBUG_DDE
printf( "Launching browser on url [%s]...\n", (const char*)arg );
printf( "Launching browser on url [%s]...\n", arg.get() );
#endif
if (NS_SUCCEEDED(nativeApp->EnsureProfile(args)))
(void)OpenBrowserWindow( arg, newWindow );
(void)OpenBrowserWindow( arg.get(), newWindow );
return;
}
@ -1983,14 +1979,10 @@ nsNativeAppSupportOS2::HandleRequest( LPBYTE request, PRBool newWindow ) {
nsXPIDLString defaultArgs;
rv = handler->GetDefaultArgs(getter_Copies(defaultArgs));
if (NS_FAILED(rv) || !defaultArgs) return;
if (NS_FAILED(rv) || defaultArgs.IsEmpty()) return;
if (defaultArgs) {
NS_LossyConvertUCS2toASCII url( defaultArgs );
OpenBrowserWindow(url.get());
} else {
OpenBrowserWindow("about:blank");
}
NS_LossyConvertUCS2toASCII url( defaultArgs );
OpenBrowserWindow(url.get());
}
// Parse command line args according to MS spec
@ -2176,7 +2168,7 @@ nsNativeAppSupportOS2::EnsureProfile(nsICmdLineService* args)
PRBool canInteract = PR_TRUE;
nsXPIDLCString arg;
if (NS_SUCCEEDED(args->GetCmdLineValue("-silent", getter_Copies(arg)))) {
if ((const char*)arg) {
if (!arg.IsEmpty()) {
canInteract = PR_FALSE;
}
}
@ -2348,7 +2340,7 @@ nsNativeAppSupportOS2::OpenBrowserWindow( const char *args, PRBool newWindow ) {
if (NS_FAILED(rv)) return rv;
// Last resort is to open a brand new window.
return OpenWindow( chromeUrlForTask, args );
return OpenWindow( chromeUrlForTask.get(), args );
}
// This opens a special browser window for purposes of priming the pump for

Просмотреть файл

@ -36,6 +36,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsStringSupport.h"
// For server mode systray icon.
#include "nsIStringBundle.h"
@ -73,12 +75,6 @@
struct JSContext;
#ifdef XPCOM_GLUE
#include "nsStringSupport.h"
#else
#include "nsString.h"
#endif
// These are needed to load a URL in a browser window.
#include "nsIDOMLocation.h"
#include "nsIJSContextStack.h"
@ -677,7 +673,8 @@ nsNativeAppSupportWin::CheckConsole() {
int rv = ::GetModuleFileName( NULL, fileName, sizeof fileName );
nsCAutoString regvalueholder;
regvalueholder.Assign((char *) regvalue);
if ((regvalueholder.Find(fileName, PR_TRUE) != kNotFound) && (regvalueholder.Find("-turbo", PR_TRUE) != kNotFound) ) {
if ((FindInString(regvalueholder, fileName, PR_TRUE) != kNotFound) &&
(FindInString(regvalueholder, "-turbo", PR_TRUE) != kNotFound) ) {
mServerMode = PR_TRUE;
mShouldShowUI = PR_TRUE;
}
@ -936,7 +933,7 @@ struct MessageWindow {
1, getter_Copies( dialogTitle ) );
}
if ( dialogMsg.get() && dialogTitle.get() && brandName.get() ) {
if ( !dialogMsg.IsEmpty() && !dialogTitle.IsEmpty() && !brandName.IsEmpty() ) {
nsCOMPtr<nsIPromptService> dialog( do_GetService( "@mozilla.org/embedcomp/prompt-service;1" ) );
if ( dialog ) {
PRBool reallyDisable;
@ -1364,7 +1361,7 @@ static void escapeQuotes( nsString &aString ) {
PRInt32 offset = -1;
while( 1 ) {
// Find next '"'.
offset = aString.FindChar( '"', ++offset );
offset = FindCharInString(aString, '"', ++offset );
if ( offset == kNotFound ) {
// No more quotes, exit.
break;
@ -1431,7 +1428,7 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t
nsCAutoString windowID;
ParseDDEArg(hsz2, 2, windowID);
// "0" means to open the URL in a new window.
if ( windowID.Equals( "0" ) ) {
if ( strcmp(windowID.get(), "0" ) == 0 ) {
new_window = PR_TRUE;
}
@ -1515,12 +1512,12 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t
nsCAutoString outpt( NS_LITERAL_CSTRING("\"") );
// Now copy the URL converting the Unicode string
// to a single-byte ASCII string
outpt.Append( NS_LossyConvertUCS2toASCII( url ) );
outpt.Append( NS_LossyConvertUTF16toASCII( url ) );
// Add the "," used to separate the URL and the page
// title
outpt.Append( NS_LITERAL_CSTRING("\",\"") );
// Now copy the current page title to the return string
outpt.Append( NS_LossyConvertUCS2toASCII( title ));
outpt.Append( NS_LossyConvertUTF16toASCII( title ));
// Fill out the return string with the remainin ",""
outpt.Append( NS_LITERAL_CSTRING( "\",\"\"" ));
@ -1542,8 +1539,9 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t
ParseDDEArg(hsz2, 0, windowID);
// 4294967295 is decimal for 0xFFFFFFFF which is also a
// correct value to do that Activate last window stuff
if ( windowID.Equals( "-1" ) ||
windowID.Equals( "4294967295" ) ) {
const char *wid = windowID.get();
if ( strcmp(wid, "-1" ) == 0 ||
strcmp(wid, "4294967295" ) == 0 ) {
// We only support activating the most recent window (or a new one).
ActivateLastWindow();
// Return pseudo window ID.
@ -1601,7 +1599,7 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t
ParseDDEArg((const char*) request, 2, windowID);
// "0" means to open the URL in a new window.
if ( windowID.Equals( "0" ) ) {
if ( strcmp(windowID.get(), "0" ) == 0 ) {
new_window = PR_TRUE;
}
@ -1660,7 +1658,7 @@ void nsNativeAppSupportWin::ParseDDEArg( const char* args, int index, nsCString&
// If this arg is quoted, then go to closing quote.
offset = advanceToEndOfQuotedArg( args, offset, argLen);
// Find next comma.
offset = temp.FindChar( ',', offset );
offset = FindCharInString(temp, ',', offset );
if ( offset == kNotFound ) {
// No more commas, give up.
aString = args;
@ -1677,7 +1675,7 @@ void nsNativeAppSupportWin::ParseDDEArg( const char* args, int index, nsCString&
// the argument we want.
PRInt32 end = advanceToEndOfQuotedArg( args, offset++, argLen );
// Find next comma (or end of string).
end = temp.FindChar( ',', end );
end = FindCharInString(temp, ',', end );
if ( end == kNotFound ) {
// Arg is the rest of the string.
end = argLen;
@ -1763,26 +1761,26 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) {
// first see if there is a url
nsXPIDLCString arg;
rv = args->GetURLToLoad(getter_Copies(arg));
if (NS_SUCCEEDED(rv) && (const char*)arg ) {
if (NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {
// Launch browser.
#if MOZ_DEBUG_DDE
printf( "Launching browser on url [%s]...\n", (const char*)arg );
printf( "Launching browser on url [%s]...\n", arg.get() );
#endif
if (NS_SUCCEEDED(nativeApp->EnsureProfile(args)))
(void)OpenBrowserWindow( arg, newWindow );
(void)OpenBrowserWindow( arg.get(), newWindow );
return;
}
// ok, let's try the -chrome argument
rv = args->GetCmdLineValue("-chrome", getter_Copies(arg));
if (NS_SUCCEEDED(rv) && (const char*)arg ) {
if (NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {
// Launch chrome.
#if MOZ_DEBUG_DDE
printf( "Launching chrome url [%s]...\n", (const char*)arg );
printf( "Launching chrome url [%s]...\n", arg.get() );
#endif
if (NS_SUCCEEDED(nativeApp->EnsureProfile(args)))
(void)OpenWindow( arg, "" );
(void)OpenWindow( arg.get(), "" );
return;
}
@ -1790,7 +1788,7 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) {
// profile manager to appear, but only if there are no windows open
rv = args->GetCmdLineValue( "-profilemanager", getter_Copies(arg));
if ( NS_SUCCEEDED(rv) && (const char*)arg ) { // -profilemanager on command line
if ( NS_SUCCEEDED(rv) && !arg.IsEmpty() ) { // -profilemanager on command line
nsCOMPtr<nsIDOMWindowInternal> window;
GetMostRecentWindow(0, getter_AddRefs(window));
if (!window) { // there are no open windows
@ -1800,7 +1798,7 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) {
// try for the "-kill" argument, to shut down the server
rv = args->GetCmdLineValue( "-kill", getter_Copies(arg));
if ( NS_SUCCEEDED(rv) && (const char*)arg ) {
if ( NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {
// Turn off server mode.
nsCOMPtr<nsIAppStartup> appStartup
(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));
@ -1821,7 +1819,7 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) {
// check wheather it is a MAPI request. If yes, don't open any new
// windows and just return.
rv = args->GetCmdLineValue(MAPI_STARTUP_ARG, getter_Copies(arg));
if (NS_SUCCEEDED(rv) && (const char*)arg) {
if (NS_SUCCEEDED(rv) && !arg.IsEmpty()) {
nativeApp->EnsureProfile(args);
return;
}
@ -1880,14 +1878,10 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) {
nsXPIDLString defaultArgs;
rv = handler->GetDefaultArgs(getter_Copies(defaultArgs));
if (NS_FAILED(rv) || !defaultArgs) return;
if (NS_FAILED(rv) || defaultArgs.IsEmpty()) return;
if (defaultArgs) {
NS_LossyConvertUCS2toASCII url( defaultArgs );
OpenBrowserWindow(url.get());
} else {
OpenBrowserWindow("about:blank");
}
NS_LossyConvertUTF16toASCII url( defaultArgs );
OpenBrowserWindow(url.get());
}
// Parse command line args according to MS spec
@ -2121,7 +2115,7 @@ printf( "Setting ddexec subkey entries\n" );
PRBool canInteract = PR_TRUE;
nsXPIDLCString arg;
if (NS_SUCCEEDED(args->GetCmdLineValue("-silent", getter_Copies(arg)))) {
if ((const char*)arg) {
if (!arg.IsEmpty()) {
canInteract = PR_FALSE;
}
}
@ -2318,7 +2312,7 @@ nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow ) {
break;
}
// Set href.
nsAutoString url; url.AssignWithConversion( args );
NS_ConvertASCIItoUTF16 url( args );
if ( NS_FAILED( location->SetHref( url ) ) ) {
break;
}
@ -2334,7 +2328,7 @@ nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow ) {
if (NS_FAILED(rv)) return rv;
// Last resort is to open a brand new window.
return OpenWindow( chromeUrlForTask, args );
return OpenWindow( chromeUrlForTask.get(), args );
}
void AppendMenuItem( HMENU& menu, PRInt32 aIdentifier, const nsString& aText ) {
@ -2371,7 +2365,7 @@ nsNativeAppSupportWin::SetupSysTrayIcon() {
brandBundle->GetStringFromName( NS_LITERAL_STRING( "brandShortName" ).get(),
getter_Copies( tooltip ) );
::strncpy( mIconData.szTip,
NS_LossyConvertUCS2toASCII(tooltip).get(),
NS_LossyConvertUTF16toASCII(tooltip).get(),
sizeof mIconData.szTip - 1 );
}
// Build menu.
@ -2394,44 +2388,44 @@ nsNativeAppSupportWin::SetupSysTrayIcon() {
const PRUnichar* formatStrings[] = { tooltip.get() };
turboBundle->FormatStringFromName( NS_LITERAL_STRING( "Exit" ).get(), formatStrings, 1,
getter_Copies( text ) );
exitText = (const PRUnichar*)text;
exitText = text;
}
turboBundle->GetStringFromName( NS_LITERAL_STRING( "Disable" ).get(),
getter_Copies( text ) );
disableText = (const PRUnichar*)text;
disableText = text;
turboBundle->GetStringFromName( NS_LITERAL_STRING( "Navigator" ).get(),
getter_Copies( text ) );
navigatorText = (const PRUnichar*)text;
navigatorText = text;
turboBundle->GetStringFromName( NS_LITERAL_STRING( "Editor" ).get(),
getter_Copies( text ) );
editorText = (const PRUnichar*)text;
editorText = text;
}
if (isMail) {
mailBundle->GetStringFromName( NS_LITERAL_STRING( "MailNews" ).get(),
getter_Copies( text ) );
mailText = (const PRUnichar*)text;
mailText = text;
mailBundle->GetStringFromName( NS_LITERAL_STRING( "Addressbook" ).get(),
getter_Copies( text ) );
addressbookText = (const PRUnichar*)text;
addressbookText = text;
}
if ( exitText.IsEmpty() )
exitText.AssignLiteral( "E&xit Mozilla" );
exitText.Assign( NS_LITERAL_STRING("E&xit Mozilla") );
if ( disableText.IsEmpty() )
disableText.AssignLiteral( "&Disable Quick Launch" );
disableText.Assign( NS_LITERAL_STRING("&Disable Quick Launch") );
if ( navigatorText.IsEmpty() )
navigatorText.AssignLiteral( "&Navigator" );
navigatorText.Assign( NS_LITERAL_STRING("&Navigator") );
if ( editorText.IsEmpty() )
editorText.AssignLiteral( "&Composer" );
editorText.Assign( NS_LITERAL_STRING("&Composer") );
if ( isMail ) {
if ( mailText.IsEmpty() )
mailText.AssignLiteral( "&Mail && Newsgroups" );
mailText.Assign( NS_LITERAL_STRING("&Mail && Newsgroups") );
if ( addressbookText.IsEmpty() )
addressbookText.AssignLiteral( "&Address Book" );
addressbookText.Assign( NS_LITERAL_STRING("&Address Book") );
}
// Create menu and add item.
mTrayIconMenu = ::CreatePopupMenu();

Просмотреть файл

@ -37,321 +37,91 @@
#ifndef nsStringSupport_h__
#define nsStringSupport_h__
/**
* This file attempts to implement the subset of string classes and methods
* used by xpfe/bootstrap in terms of the frozen string API.
*
* This code exists to allow xpfe/bootstrap to be optionally compiled as a
* standalone embedder of the GRE. However, since the module can also be built
* statically or as a non-GRE application, it is necessary to support compiling
* it directly against the internal xpcom string classes. Hence, this layer of
* indirection ;-)
*/
#ifdef MOZILLA_STRICT_API
#include "nsEmbedString.h"
#include "nsStringAPI.h"
#include "nsMemory.h"
#include "prprf.h"
#include "plstr.h"
// rename class names that are redefined here
#define nsCString nsCString_local
#define nsCAutoString nsCAutoString_local
#define nsDependentCString nsDependentCString_local
#define nsXPIDLCString nsXPIDLCString_local
#define nsCGetterCopies nsCGetterCopies_local
#define nsString nsString_local
#define nsAutoString nsAutoString_local
#define nsDependentString nsDependentString_local
#define nsXPIDLString nsXPIDLString_local
#define nsGetterCopies nsGetterCopies_local
#define NS_ConvertUCS2toUTF8 NS_ConvertUCS2toUTF8_local
#define NS_ConvertASCIItoUTF16 NS_ConvertASCIItoUTF16_local
#define NS_LossyConvertUCS2toASCII NS_LossyConvertUCS2toASCII_local
#define getter_Copies getter_Copies_local
#ifndef kNotFound
#define kNotFound -1
class nsCString : public nsEmbedCString
{
public:
nsCString() {}
nsCString(const char *s)
{
Assign(s);
}
void AppendInt(PRInt32 value)
{
char buf[32];
PR_snprintf(buf, sizeof(buf), "%d", value);
Append(buf);
}
PRBool IsEmpty()
{
return Length() == 0;
}
PRInt32 FindChar(char c, PRUint32 offset = 0)
{
NS_ASSERTION(offset <= Length(), "invalid offset");
const char *data = get();
for (const char *p = data + offset; *p; ++p)
if (*p == c)
return p - data;
return kNotFound;
}
PRInt32 Find(const char *needle, PRBool ignoreCase = PR_FALSE)
{
const char *data = get(), *p;
if (ignoreCase)
p = PL_strcasestr(data, needle);
else
p = PL_strstr(data, needle);
return p ? p - data : kNotFound;
}
PRBool Equals(const char *s)
{
return strcmp(get(), s) == 0;
}
};
class nsDependentCString : public nsCString
{
public:
nsDependentCString(const char *data)
{
Assign(data); // XXX forced to copy
}
nsDependentCString(const char *data, PRUint32 len)
{
Assign(data, len); // XXX forced to copy
}
};
class nsCAutoString : public nsCString
{
public:
nsCAutoString() {}
nsCAutoString(const char *data)
{
Assign(data);
}
nsCAutoString(const nsCString &s)
{
Assign(s);
}
};
class nsString : public nsEmbedString
{
public:
nsString() {}
PRBool IsEmpty()
{
return Length() == 0;
}
PRInt32 FindChar(PRUnichar c, PRUint32 offset = 0)
{
NS_ASSERTION(offset <= Length(), "invalid offset");
const PRUnichar *data = get();
for (const PRUnichar *p = data + offset; *p; ++p)
if (*p == c)
return p - data;
return kNotFound;
}
};
class nsDependentString : public nsString
{
public:
nsDependentString(const PRUnichar *data)
{
Assign(data); // XXX forced to copy
}
};
class nsAutoString : public nsString
{
public:
void AssignWithConversion(const char *data)
{
AssignLiteral(data);
}
void AssignLiteral(const char *data)
{
NS_CStringToUTF16(nsEmbedCString(data), NS_CSTRING_ENCODING_ASCII, *this);
}
nsAutoString &operator=(const PRUnichar *s)
{
Assign(s);
return *this;
}
};
class nsXPIDLCString : public nsCString
{
public:
nsXPIDLCString() : mVoided(PR_TRUE) {}
const char *get() const
{
return mVoided ? nsnull : nsEmbedCString::get();
}
operator const char*() const
{
return get();
}
void Adopt(char *data)
{
if (data)
{
// XXX unfortunately, we don't have a better way to do this.
Assign(data);
nsMemory::Free(data);
mVoided = PR_FALSE;
}
else
{
Cut(0, PR_UINT32_MAX);
mVoided = PR_TRUE;
}
}
private:
PRBool mVoided;
};
class nsCGetterCopies
{
public:
typedef char char_type;
nsCGetterCopies(nsXPIDLCString& str)
: mString(str), mData(nsnull) {}
~nsCGetterCopies()
{
mString.Adopt(mData); // OK if mData is null
}
operator char_type**()
{
return &mData;
}
private:
nsXPIDLCString& mString;
char_type* mData;
};
inline
nsCGetterCopies
getter_Copies( nsXPIDLCString& aString )
{
return nsCGetterCopies(aString);
}
class nsXPIDLString : public nsString
{
public:
nsXPIDLString() : mVoided(PR_TRUE) {}
const PRUnichar *get() const
{
return mVoided ? nsnull : nsEmbedString::get();
}
operator const PRUnichar*() const
{
return get();
}
void Adopt(PRUnichar *data)
{
if (data)
{
// XXX unfortunately, we don't have a better way to do this.
Assign(data);
nsMemory::Free(data);
mVoided = PR_FALSE;
}
else
{
Cut(0, PR_UINT32_MAX);
mVoided = PR_TRUE;
}
}
private:
PRBool mVoided;
};
class nsGetterCopies
{
public:
typedef PRUnichar char_type;
nsGetterCopies(nsXPIDLString& str)
: mString(str), mData(nsnull) {}
~nsGetterCopies()
{
mString.Adopt(mData); // OK if mData is null
}
operator char_type**()
{
return &mData;
}
private:
nsXPIDLString& mString;
char_type* mData;
};
inline
nsGetterCopies
getter_Copies( nsXPIDLString& aString )
{
return nsGetterCopies(aString);
}
class NS_ConvertUCS2toUTF8 : public nsCString
{
public:
NS_ConvertUCS2toUTF8(const nsAString &str)
{
NS_UTF16ToCString(str, NS_CSTRING_ENCODING_UTF8, *this);
}
};
class NS_LossyConvertUCS2toASCII : public nsCString
{
public:
NS_LossyConvertUCS2toASCII(const nsAString &str)
{
NS_UTF16ToCString(str, NS_CSTRING_ENCODING_ASCII, *this);
}
};
class NS_ConvertASCIItoUTF16 : public nsString
{
public:
NS_ConvertASCIItoUTF16(const char *str, PRUint32 len)
{
nsEmbedCString temp;
temp.Assign(str, len);
NS_CStringToUTF16(temp, NS_CSTRING_ENCODING_ASCII, *this);
}
};
#define NS_LITERAL_CSTRING(s) nsDependentCString(s)
#ifdef HAVE_CPP_2BYTE_WCHAR_T
#define NS_LITERAL_STRING(s) nsDependentString((const PRUnichar*)L##s)
#else
#define NS_LITERAL_STRING(s) NS_ConvertASCIItoUTF16(s, sizeof(s)-1)
#endif
#define EmptyCString() nsCString()
#define EmptyString() nsString()
inline void
AppendIntToString(nsCString &str, PRInt32 value)
{
char buf[32];
PR_snprintf(buf, sizeof(buf), "%d", value);
str.Append(buf);
}
inline PRInt32
FindCharInString(nsCString &str, char c, PRUint32 offset = 0)
{
NS_ASSERTION(offset <= str.Length(), "invalid offset");
const char *data = str.get();
for (const char *p = data + offset; *p; ++p)
if (*p == c)
return p - data;
return kNotFound;
}
inline PRInt32
FindCharInString(nsString &str, PRUnichar c, PRUint32 offset = 0)
{
NS_ASSERTION(offset <= str.Length(), "invalid offset");
const PRUnichar *data = str.get();
for (const PRUnichar *p = data + offset; *p; ++p)
if (*p == c)
return p - data;
return kNotFound;
}
inline PRInt32
FindInString(nsCString &str, const char *needle, PRBool ignoreCase = PR_FALSE)
{
const char *data = str.get(), *p;
if (ignoreCase)
p = PL_strcasestr(data, needle);
else
p = PL_strstr(data, needle);
return p ? p - data : kNotFound;
}
typedef nsCString nsCAutoString;
typedef nsString nsAutoString;
typedef nsCString nsXPIDLCString;
typedef nsString nsXPIDLString;
#else // MOZILLA_STRICT_API
#include "nsString.h"
inline void
AppendIntToString(nsCString &str, PRInt32 value)
{
str.AppendInt(value);
}
inline PRInt32
FindCharInString(nsCString &str, char c, PRUint32 offset = 0)
{
return str.FindChar(c, offset);
}
inline PRInt32
FindCharInString(nsString &str, PRUnichar c, PRUint32 offset = 0)
{
return str.FindChar(c, offset);
}
inline PRInt32
FindInString(nsCString &str, const char *needle, PRBool ignoreCase = PR_FALSE)
{
return str.Find(needle, ignoreCase);
}
#endif // MOZILLA_STRICT_API
#endif // !nsStringSupport_h__