Fix for bug #37543, a=ftang, r=nhotta.

git-svn-id: svn://10.0.0.236/trunk@75618 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
cata%netscape.com 2000-08-05 00:07:03 +00:00
parent 078c67b29e
commit 99abc99837
5 changed files with 119 additions and 0 deletions

View File

@ -752,6 +752,19 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
}
}
if (kCharsetFromParentFrame > charsetSource) {
if (dcInfo) {
nsCOMPtr<nsIAtom> csAtom;
dcInfo->GetParentCharset(getter_AddRefs(csAtom));
if (csAtom) {
csAtom->ToString(charset);
charsetSource = kCharsetFromParentFrame;
// printf("### 0 >>> Having parent CS = %s\n", charset.ToNewCString());
}
}
}
if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector)
{
nsCOMPtr <nsICharsetDetector> cdet = do_CreateInstance(g_detector_progid,

View File

@ -79,6 +79,7 @@ static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
static NS_DEFINE_CID(kDocumentCharsetInfoCID, NS_DOCUMENTCHARSETINFO_CID);
//*****************************************************************************
//*** nsDocShell: Object Management
@ -459,6 +460,14 @@ NS_IMETHODIMP nsDocShell::GetDocumentCharsetInfo(nsIDocumentCharsetInfo**
{
NS_ENSURE_ARG_POINTER(aDocumentCharsetInfo);
// if the mDocumentCharsetInfo does not exist already, we create it now
if (!mDocumentCharsetInfo) {
nsresult res = nsComponentManager::CreateInstance(kDocumentCharsetInfoCID,
NULL, NS_GET_IID(nsIDocumentCharsetInfo),
getter_AddRefs(mDocumentCharsetInfo));
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
}
*aDocumentCharsetInfo = mDocumentCharsetInfo;
NS_IF_ADDREF(*aDocumentCharsetInfo);
return NS_OK;
@ -889,6 +898,40 @@ NS_IMETHODIMP nsDocShell::AddChild(nsIDocShellTreeItem *aChild)
}
}
// Now take this document's charset and set the parentCharset field of the
// child's DocumentCharsetInfo to it. We'll later use that field, in the
// loading process, for the charset choosing algorithm.
// If we fail, at any point, we just return NS_OK.
// This code has some performance impact. But this will be reduced when
// the current charset will finally be stored as an Atom, avoiding the
// alias resolution extra look-up.
// we are NOT going to propagate the charset is this Chrome's docshell
if (mItemType == nsIDocShellTreeItem::typeChrome) return NS_OK;
nsresult res = NS_OK;
// get the child's docCSInfo object
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo = NULL;
res = childAsDocShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
if (NS_FAILED(res) || (!dcInfo)) return NS_OK;
// get the parent's current charset
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
if (!docv) return NS_OK;
nsCOMPtr<nsIDocument> doc;
res = docv->GetDocument(*getter_AddRefs(doc));
if (NS_FAILED(res) || (!doc)) return NS_OK;
nsAutoString parentCS;
res = doc->GetDocumentCharacterSet(parentCS);
if (NS_FAILED(res)) return NS_OK;
// set the child's parentCharset
res = dcInfo->SetParentCharset(&parentCS);
if (NS_FAILED(res)) return NS_OK;
// printf("### 1 >>> Adding child. Parent CS = %s. ItemType = %d.\n", parentCS.ToNewCString(), mItemType);
return NS_OK;
}

View File

@ -38,6 +38,8 @@
"component://netscape/document-charset-info"
// XXX doc me
// XXX make this interface IDL
// XXX mark the right params "const"
class nsIDocumentCharsetInfo : public nsISupports
{
@ -46,8 +48,19 @@ public:
NS_IMETHOD SetForcedCharset(nsIAtom * aCharset) = 0;
NS_IMETHOD GetForcedCharset(nsIAtom ** aResult) = 0;
NS_IMETHOD SetForcedDetector(PRBool aForced) = 0;
NS_IMETHOD GetForcedDetector(PRBool * aResult) = 0;
NS_IMETHOD SetParentCharset(nsIAtom * aCharset) = 0;
NS_IMETHOD GetParentCharset(nsIAtom ** aResult) = 0;
/**
* You should NOT use this method!!! It will very soon be deprecated. I only
* added it here for convenience in the ongoing transition to Atoms. Use
* SetParentCharset(nsIAtom *) instead.
*/
NS_IMETHOD SetParentCharset(nsString * aCharset) = 0;
};
#endif // nsIDocumentCharsetInfo_h__

View File

@ -21,11 +21,16 @@
*/
#include "nsCharDetDll.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include "nsDocumentCharsetInfo.h"
#include "nsCOMPtr.h"
// XXX doc me
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
class nsDocumentCharsetInfo : public nsIDocumentCharsetInfo
{
NS_DECL_ISUPPORTS
@ -37,11 +42,17 @@ public:
NS_IMETHOD SetForcedCharset(nsIAtom * aCharset);
NS_IMETHOD GetForcedCharset(nsIAtom ** aResult);
NS_IMETHOD SetForcedDetector(PRBool aForced);
NS_IMETHOD GetForcedDetector(PRBool * aResult);
NS_IMETHOD SetParentCharset(nsIAtom * aCharset);
NS_IMETHOD GetParentCharset(nsIAtom ** aResult);
NS_IMETHOD SetParentCharset(nsString * aCharset);
private:
nsCOMPtr<nsIAtom> mForcedCharset;
nsCOMPtr<nsIAtom> mParentCharset;
};
class nsDocumentCharsetInfoFactory : public nsIFactory
@ -101,6 +112,32 @@ NS_IMETHODIMP nsDocumentCharsetInfo::GetForcedDetector(PRBool * aResult)
return NS_OK;
}
NS_IMETHODIMP nsDocumentCharsetInfo::SetParentCharset(nsIAtom * aCharset)
{
mParentCharset = aCharset;
return NS_OK;
}
NS_IMETHODIMP nsDocumentCharsetInfo::GetParentCharset(nsIAtom ** aResult)
{
*aResult = mParentCharset;
if (mParentCharset) NS_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP nsDocumentCharsetInfo::SetParentCharset(nsString * aCharset)
{
nsresult res = NS_OK;
NS_WITH_SERVICE(nsICharsetConverterManager2, ccMan, kCharsetConverterManagerCID, &res);
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
nsCOMPtr<nsIAtom> csAtom;
res = ccMan->GetCharsetAtom(aCharset->GetUnicode(), getter_AddRefs(csAtom));
if (NS_FAILED(res)) return NS_ERROR_FAILURE;
return SetParentCharset(csAtom);
}
NS_IMPL_ISUPPORTS(nsDocumentCharsetInfoFactory, NS_GET_IID(nsIFactory));
NS_IMETHODIMP nsDocumentCharsetInfoFactory::CreateInstance(

View File

@ -752,6 +752,19 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
}
}
if (kCharsetFromParentFrame > charsetSource) {
if (dcInfo) {
nsCOMPtr<nsIAtom> csAtom;
dcInfo->GetParentCharset(getter_AddRefs(csAtom));
if (csAtom) {
csAtom->ToString(charset);
charsetSource = kCharsetFromParentFrame;
// printf("### 0 >>> Having parent CS = %s\n", charset.ToNewCString());
}
}
}
if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector)
{
nsCOMPtr <nsICharsetDetector> cdet = do_CreateInstance(g_detector_progid,