diff --git a/content/html/document/src/nsWyciwygChannel.cpp b/content/html/document/src/nsWyciwygChannel.cpp
index 88790eeb1b2b..069b7494217b 100644
--- a/content/html/document/src/nsWyciwygChannel.cpp
+++ b/content/html/document/src/nsWyciwygChannel.cpp
@@ -57,7 +57,7 @@ PRLogModuleInfo * gWyciwygLog = nsnull;
nsWyciwygChannel::nsWyciwygChannel()
: mStatus(NS_OK),
mIsPending(PR_FALSE),
- mCharsetSet(PR_FALSE),
+ mNeedToWriteCharset(PR_FALSE),
mCharsetSource(kCharsetUninitialized),
mContentLength(-1),
mLoadFlags(LOAD_NORMAL)
@@ -350,12 +350,9 @@ nsWyciwygChannel::WriteToCacheEntry(const nsAString &aData)
mCacheEntry->SetSecurityInfo(mSecurityInfo);
}
- if (mCharsetSet) {
- mCacheEntry->SetMetaDataElement("charset", mCharset.get());
-
- nsCAutoString source;
- source.AppendInt(mCharsetSource);
- mCacheEntry->SetMetaDataElement("charset-source", source.get());
+ if (mNeedToWriteCharset) {
+ WriteCharsetAndSourceToCache(mCharsetSource, mCharset);
+ mNeedToWriteCharset = PR_FALSE;
}
PRUint32 out;
@@ -406,9 +403,13 @@ nsWyciwygChannel::SetCharsetAndSource(PRInt32 aSource,
{
NS_ENSURE_ARG(!aCharset.IsEmpty());
- mCharsetSet = PR_TRUE;
- mCharsetSource = aSource;
- mCharset = aCharset;
+ if (mCacheEntry) {
+ WriteCharsetAndSourceToCache(aSource, PromiseFlatCString(aCharset));
+ } else {
+ mNeedToWriteCharset = PR_TRUE;
+ mCharsetSource = aSource;
+ mCharset = aCharset;
+ }
return NS_OK;
}
@@ -638,4 +639,17 @@ nsWyciwygChannel::ReadFromCache()
return mPump->AsyncRead(this, nsnull);
}
+void
+nsWyciwygChannel::WriteCharsetAndSourceToCache(PRInt32 aSource,
+ const nsCString& aCharset)
+{
+ NS_PRECONDITION(mCacheEntry, "Better have cache entry!");
+
+ mCacheEntry->SetMetaDataElement("charset", aCharset.get());
+
+ nsCAutoString source;
+ source.AppendInt(aSource);
+ mCacheEntry->SetMetaDataElement("charset-source", source.get());
+}
+
// vim: ts=2 sw=2
diff --git a/content/html/document/src/nsWyciwygChannel.h b/content/html/document/src/nsWyciwygChannel.h
index af0affc5406c..cb0a7fc433eb 100644
--- a/content/html/document/src/nsWyciwygChannel.h
+++ b/content/html/document/src/nsWyciwygChannel.h
@@ -83,10 +83,13 @@ public:
protected:
nsresult ReadFromCache();
nsresult OpenCacheEntry(const nsACString & aCacheKey, nsCacheAccessMode aWriteAccess, PRBool * aDelayFlag = nsnull);
+
+ void WriteCharsetAndSourceToCache(PRInt32 aSource,
+ const nsCString& aCharset);
nsresult mStatus;
PRPackedBool mIsPending;
- PRPackedBool mCharsetSet;
+ PRPackedBool mNeedToWriteCharset;
PRInt32 mCharsetSource;
nsCString mCharset;
PRInt32 mContentLength;