зеркало из https://github.com/mozilla/pjs.git
fix bug 117422. a=asa r=jkeiser sr=jst
make the fallback handling of unicode converter compatable with IE6.
This commit is contained in:
Родитель
a44caaf0da
Коммит
7ef8b5e248
|
@ -35,6 +35,7 @@
|
||||||
#include "nsDOMError.h"
|
#include "nsDOMError.h"
|
||||||
#include "nsHTMLValue.h"
|
#include "nsHTMLValue.h"
|
||||||
#include "nsGenericElement.h"
|
#include "nsGenericElement.h"
|
||||||
|
#include "nsISaveAsCharset.h"
|
||||||
|
|
||||||
// JBK added for submit move from content frame
|
// JBK added for submit move from content frame
|
||||||
#include "nsIFile.h"
|
#include "nsIFile.h"
|
||||||
|
@ -46,7 +47,6 @@ static NS_DEFINE_CID(kFormProcessorCID, NS_FORMPROCESSOR_CID);
|
||||||
#include "nsIURI.h"
|
#include "nsIURI.h"
|
||||||
#include "nsNetUtil.h"
|
#include "nsNetUtil.h"
|
||||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||||
#include "nsIUnicodeEncoder.h"
|
|
||||||
#include "nsIPref.h"
|
#include "nsIPref.h"
|
||||||
#include "nsSpecialSystemDirectory.h"
|
#include "nsSpecialSystemDirectory.h"
|
||||||
#include "nsLinebreakConverter.h"
|
#include "nsLinebreakConverter.h"
|
||||||
|
@ -82,7 +82,7 @@ class nsFormSubmission : public nsIFormSubmission {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
nsFormSubmission(const nsAString& aCharset,
|
nsFormSubmission(const nsAString& aCharset,
|
||||||
nsIUnicodeEncoder* aEncoder,
|
nsISaveAsCharset* aEncoder,
|
||||||
nsIFormProcessor* aFormProcessor,
|
nsIFormProcessor* aFormProcessor,
|
||||||
PRInt32 aBidiOptions)
|
PRInt32 aBidiOptions)
|
||||||
: mCharset(aCharset),
|
: mCharset(aCharset),
|
||||||
|
@ -115,10 +115,10 @@ protected:
|
||||||
// Encoding Helpers
|
// Encoding Helpers
|
||||||
char* EncodeVal(const nsAString& aIn);
|
char* EncodeVal(const nsAString& aIn);
|
||||||
char* UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen,
|
char* UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen,
|
||||||
nsIUnicodeEncoder* aEncoder);
|
nsISaveAsCharset* aEncoder);
|
||||||
|
|
||||||
nsString mCharset;
|
nsString mCharset;
|
||||||
nsCOMPtr<nsIUnicodeEncoder> mEncoder;
|
nsCOMPtr<nsISaveAsCharset> mEncoder;
|
||||||
nsCOMPtr<nsIFormProcessor> mFormProcessor;
|
nsCOMPtr<nsIFormProcessor> mFormProcessor;
|
||||||
PRInt32 mBidiOptions;
|
PRInt32 mBidiOptions;
|
||||||
|
|
||||||
|
@ -129,9 +129,8 @@ public:
|
||||||
nsAString& oCharset);
|
nsAString& oCharset);
|
||||||
static nsresult GetEncoder(nsIForm* form,
|
static nsresult GetEncoder(nsIForm* form,
|
||||||
nsIPresContext* aPresContext,
|
nsIPresContext* aPresContext,
|
||||||
PRUint8 aCtrlsModAtSubmit,
|
|
||||||
const nsAString& aCharset,
|
const nsAString& aCharset,
|
||||||
nsIUnicodeEncoder** encoder);
|
nsISaveAsCharset** encoder);
|
||||||
static nsresult GetEnumAttr(nsIForm* form, nsIAtom* atom, PRInt32* aValue);
|
static nsresult GetEnumAttr(nsIForm* form, nsIAtom* atom, PRInt32* aValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -143,7 +142,7 @@ class nsFSURLEncoded : public nsFormSubmission
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsFSURLEncoded(const nsAString& aCharset,
|
nsFSURLEncoded(const nsAString& aCharset,
|
||||||
nsIUnicodeEncoder* aEncoder,
|
nsISaveAsCharset* aEncoder,
|
||||||
nsIFormProcessor* aFormProcessor,
|
nsIFormProcessor* aFormProcessor,
|
||||||
PRInt32 aBidiOptions,
|
PRInt32 aBidiOptions,
|
||||||
PRInt32 aMethod)
|
PRInt32 aMethod)
|
||||||
|
@ -361,7 +360,7 @@ class nsFSMultipartFormData : public nsFormSubmission
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsFSMultipartFormData(const nsAString& aCharset,
|
nsFSMultipartFormData(const nsAString& aCharset,
|
||||||
nsIUnicodeEncoder* aEncoder,
|
nsISaveAsCharset* aEncoder,
|
||||||
nsIFormProcessor* aFormProcessor,
|
nsIFormProcessor* aFormProcessor,
|
||||||
PRInt32 aBidiOptions);
|
PRInt32 aBidiOptions);
|
||||||
virtual ~nsFSMultipartFormData() { }
|
virtual ~nsFSMultipartFormData() { }
|
||||||
|
@ -407,7 +406,7 @@ NS_IMPL_QUERY_INTERFACE_INHERITED0(nsFSMultipartFormData, nsFormSubmission)
|
||||||
// Constructor
|
// Constructor
|
||||||
//
|
//
|
||||||
nsFSMultipartFormData::nsFSMultipartFormData(const nsAString& aCharset,
|
nsFSMultipartFormData::nsFSMultipartFormData(const nsAString& aCharset,
|
||||||
nsIUnicodeEncoder* aEncoder,
|
nsISaveAsCharset* aEncoder,
|
||||||
nsIFormProcessor* aFormProcessor,
|
nsIFormProcessor* aFormProcessor,
|
||||||
PRInt32 aBidiOptions)
|
PRInt32 aBidiOptions)
|
||||||
: nsFormSubmission(aCharset, aEncoder, aFormProcessor, aBidiOptions)
|
: nsFormSubmission(aCharset, aEncoder, aFormProcessor, aBidiOptions)
|
||||||
|
@ -684,8 +683,8 @@ GetSubmissionFromForm(nsIForm* aForm,
|
||||||
nsFormSubmission::GetSubmitCharset(aForm, ctrlsModAtSubmit, charset);
|
nsFormSubmission::GetSubmitCharset(aForm, ctrlsModAtSubmit, charset);
|
||||||
|
|
||||||
// Get unicode encoder
|
// Get unicode encoder
|
||||||
nsCOMPtr<nsIUnicodeEncoder> encoder;
|
nsCOMPtr<nsISaveAsCharset> encoder;
|
||||||
nsFormSubmission::GetEncoder(aForm, aPresContext, ctrlsModAtSubmit, charset,
|
nsFormSubmission::GetEncoder(aForm, aPresContext, charset,
|
||||||
getter_AddRefs(encoder));
|
getter_AddRefs(encoder));
|
||||||
|
|
||||||
// Get form processor
|
// Get form processor
|
||||||
|
@ -766,9 +765,6 @@ nsFormSubmission::GetSubmitCharset(nsIForm* form,
|
||||||
value.GetStringValue(acceptCharsetValue);
|
value.GetStringValue(acceptCharsetValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_ftang
|
|
||||||
printf("accept-charset = %s\n", acceptCharsetValue.ToNewUTF8String());
|
|
||||||
#endif
|
|
||||||
PRInt32 charsetLen = acceptCharsetValue.Length();
|
PRInt32 charsetLen = acceptCharsetValue.Length();
|
||||||
if (charsetLen > 0) {
|
if (charsetLen > 0) {
|
||||||
PRInt32 offset=0;
|
PRInt32 offset=0;
|
||||||
|
@ -785,9 +781,6 @@ nsFormSubmission::GetSubmitCharset(nsIForm* form,
|
||||||
if (cnt > 0) {
|
if (cnt > 0) {
|
||||||
nsAutoString charset;
|
nsAutoString charset;
|
||||||
acceptCharsetValue.Mid(charset, offset, cnt);
|
acceptCharsetValue.Mid(charset, offset, cnt);
|
||||||
#ifdef DEBUG_ftang
|
|
||||||
printf("charset[i] = %s\n",charset.ToNewUTF8String());
|
|
||||||
#endif
|
|
||||||
if (NS_SUCCEEDED(calias->GetPreferred(charset, oCharset)))
|
if (NS_SUCCEEDED(calias->GetPreferred(charset, oCharset)))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -838,41 +831,34 @@ nsFormSubmission::GetSubmitCharset(nsIForm* form,
|
||||||
nsresult
|
nsresult
|
||||||
nsFormSubmission::GetEncoder(nsIForm* form,
|
nsFormSubmission::GetEncoder(nsIForm* form,
|
||||||
nsIPresContext* aPresContext,
|
nsIPresContext* aPresContext,
|
||||||
PRUint8 aCtrlsModAtSubmit,
|
|
||||||
const nsAString& aCharset,
|
const nsAString& aCharset,
|
||||||
nsIUnicodeEncoder** encoder)
|
nsISaveAsCharset** aEncoder)
|
||||||
{
|
{
|
||||||
*encoder = nsnull;
|
*aEncoder = nsnull;
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
#ifdef DEBUG_ftang
|
|
||||||
printf("charset=%s\n", ToNewCString(charset));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Get Charset, get the encoder.
|
nsAutoString charset(aCharset);
|
||||||
nsCOMPtr<nsICharsetConverterManager> ccm(
|
if(charset.Equals(NS_LITERAL_STRING("ISO-8859-1")))
|
||||||
do_GetService(kCharsetConverterManagerCID, &rv));
|
charset.Assign(NS_LITERAL_STRING("windows-1252"));
|
||||||
|
|
||||||
|
rv = CallCreateInstance( NS_SAVEASCHARSET_CONTRACTID, aEncoder);
|
||||||
|
NS_ASSERTION(NS_SUCCEEDED(rv), "create nsISaveAsCharset failed");
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
if (ccm) {
|
|
||||||
nsString charset(aCharset);
|
rv = (*aEncoder)->Init(NS_ConvertUCS2toUTF8(charset).get(),
|
||||||
if (charset.Equals(NS_LITERAL_STRING("ISO-8859-1")))
|
(nsISaveAsCharset::attr_EntityAfterCharsetConv +
|
||||||
charset.Assign(NS_LITERAL_STRING("windows-1252"));
|
nsISaveAsCharset::attr_FallbackDecimalNCR),
|
||||||
rv = ccm->GetUnicodeEncoder(&charset, encoder);
|
0);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ASSERTION(NS_SUCCEEDED(rv), "initialize nsISaveAsCharset failed");
|
||||||
// XXX Commenting this out for now since it was never called up until now
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
// and no one appears to have noticed. But it appears to be useful stuff,
|
|
||||||
// so it stays for the day when we realize we're doing it wrong.
|
|
||||||
// rv = (*encoder)->SetOutputErrorBehavior(
|
|
||||||
// nsIUnicodeEncoder::kOnError_Replace,
|
|
||||||
// nsnull,
|
|
||||||
// (PRUnichar)'?');
|
|
||||||
}
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// i18n helper routines
|
// i18n helper routines
|
||||||
char*
|
char*
|
||||||
nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen,
|
nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen,
|
||||||
nsIUnicodeEncoder* aEncoder)
|
nsISaveAsCharset* aEncoder)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
@ -932,28 +918,14 @@ nsFormSubmission::UnicodeToNewBytes(const PRUnichar* aSrc, PRUint32 aLen,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
char* res = nsnull;
|
char* res = nsnull;
|
||||||
rv = aEncoder->Reset();
|
if(aSrc && aSrc[0]) {
|
||||||
if (NS_FAILED(rv)) {
|
rv = aEncoder->Convert(aSrc, &res);
|
||||||
return nsnull;
|
NS_ASSERTION(NS_SUCCEEDED(rv), "conversion failed");
|
||||||
}
|
}
|
||||||
|
if(! res)
|
||||||
PRInt32 maxByteLen = 0;
|
res = nsCRT::strdup("");
|
||||||
rv = aEncoder->GetMaxLength(aSrc, (PRInt32)aLen, &maxByteLen);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
return nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = new char[maxByteLen+1];
|
|
||||||
if (res) {
|
|
||||||
PRInt32 reslen = maxByteLen;
|
|
||||||
PRInt32 reslen2;
|
|
||||||
PRInt32 srclen = aLen;
|
|
||||||
aEncoder->Convert(aSrc, &srclen, res, &reslen);
|
|
||||||
reslen2 = maxByteLen - reslen;
|
|
||||||
aEncoder->Finish(res + reslen, &reslen2);
|
|
||||||
res[reslen+reslen2] = '\0';
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче