From 3f23cb5ab37c315680ce9c989af6651a6a8bbea6 Mon Sep 17 00:00:00 2001 From: "ftang%netscape.com" Date: Tue, 25 May 1999 02:30:03 +0000 Subject: [PATCH] fix bug 6740. approved by christ hofmann git-svn-id: svn://10.0.0.236/trunk@32576 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLDocument.cpp | 14 ++++++-- .../chardet/src/nsMetaCharsetObserver.cpp | 34 ++----------------- .../html/document/src/nsHTMLDocument.cpp | 14 ++++++-- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 04c7948713d..9ac83ed1b1b 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -308,6 +308,9 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL, nsAutoString charset = "ISO-8859-1"; // fallback value in case webShell return error nsCharsetSource charsetSource = kCharsetFromDocTypeDefault; + const PRUnichar* requestCharset = nsnull; + nsCharsetSource requestCharsetSource = kCharsetUninitialized; + #ifdef rickgdebug nsString outString; // added out. Redirect to stdout if desired -- gpk 04/01/99 @@ -324,6 +327,15 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL, charset = defaultCharsetFromWebShell; charsetSource = kCharsetFromUserDefault; } + // for html, we need to find out the Meta tag from the hint. + rv = webShell->GetCharacterSetHint(&requestCharset, &requestCharsetSource); + if(NS_SUCCEEDED(rv)) { + if(requestCharsetSource > charsetSource) + { + charsetSource = requestCharsetSource; + charset = requestCharset; + } + } } NS_IF_RELEASE(webShell); #endif @@ -331,8 +343,6 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL, // XXXX // We should take care two more cases here // 1. The charset attribute from HTTP header - // 2. The charset parameter from the META Tag - - // which explicit pass to nsWebShell from nsCharsetObserver if (NS_SUCCEEDED(rv)) { rv = this->SetDocumentCharacterSet(charset); diff --git a/mozilla/intl/chardet/src/nsMetaCharsetObserver.cpp b/mozilla/intl/chardet/src/nsMetaCharsetObserver.cpp index c83386f489e..a1a42507c30 100644 --- a/mozilla/intl/chardet/src/nsMetaCharsetObserver.cpp +++ b/mozilla/intl/chardet/src/nsMetaCharsetObserver.cpp @@ -19,7 +19,7 @@ #include "nsICharsetAlias.h" #undef NS_IMPL_IDS -#define DONT_INFORM_WEBSHELL +//#define DONT_INFORM_WEBSHELL #include "nsMetaCharsetObserver.h" #include "nsIMetaCharsetService.h" @@ -34,7 +34,6 @@ #include "nsIServiceManager.h" #include "nsIDocumentLoader.h" #include "nsIWebShellServices.h" -#include "nsIWebShell.h" #include "nsIContentViewerContainer.h" static NS_DEFINE_IID(kIElementObserverIID, NS_IELEMENTOBSERVER_IID); @@ -46,7 +45,6 @@ static NS_DEFINE_IID(kIMetaCharsetServiceIID, NS_IMETA_CHARSET_SERVICE_IID); static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID); static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID); static NS_DEFINE_IID(kIWebShellServicesIID, NS_IWEB_SHELL_SERVICES_IID); -static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); //========================================================================== // // Class declaration for the class @@ -285,12 +283,7 @@ NS_IMETHODIMP nsMetaCharsetObserver::NotifyWebShell( nsIDocumentLoader * docLoader = nsnull; nsIContentViewerContainer * cvc = nsnull; nsIWebShellServices* wss = nsnull; - nsIWebShell* iws = nsnull; - const PRUnichar* theURL = nsnull; - PRInt32 historyIdx = -1; - nsAutoString urlStr; - const char* urlCStr = nsnull; - + if(NS_FAILED(res =nsServiceManager::GetService(kDocLoaderServiceCID, kIDocumentLoaderIID, (nsISupports**)&docLoader))) @@ -302,23 +295,6 @@ NS_IMETHODIMP nsMetaCharsetObserver::NotifyWebShell( if(NS_FAILED( res = cvc->QueryInterface(kIWebShellServicesIID, (void**)&wss))) goto done; - if(NS_FAILED( res = wss->QueryInterface(kIWebShellIID, (void**)&iws))) - goto done; - - - if(NS_FAILED( res = iws->GetHistoryIndex(historyIdx) )) - goto done; - - // ask the webshelle about the current URL - if(NS_FAILED( res = iws->GetURL(historyIdx, &theURL) )) - goto done; - - // convert the PRUnichar* to const char* - urlStr = theURL; - urlCStr = urlStr.ToNewCString(); - if(nsnull == urlCStr) - goto done; - #ifndef DONT_INFORM_WEBSHELL // ask the webshellservice to load the URL if(NS_FAILED( res = wss->SetRendering(PR_TRUE) )) @@ -327,18 +303,14 @@ NS_IMETHODIMP nsMetaCharsetObserver::NotifyWebShell( if(NS_FAILED(res = wss->StopDocumentLoad())) goto done; - if(NS_FAILED(res = wss->LoadDocument(urlCStr, charset, source))) + if(NS_FAILED(res = wss->ReloadDocument(charset, source))) goto done; #endif done: - if(urlCStr) { - delete [] (char*) urlCStr; - } if(docLoader) { nsServiceManager::ReleaseService(kDocLoaderServiceCID,docLoader); } - NS_IF_RELEASE(iws); NS_IF_RELEASE(cvc); NS_IF_RELEASE(wss); return res; diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index 04c7948713d..9ac83ed1b1b 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -308,6 +308,9 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL, nsAutoString charset = "ISO-8859-1"; // fallback value in case webShell return error nsCharsetSource charsetSource = kCharsetFromDocTypeDefault; + const PRUnichar* requestCharset = nsnull; + nsCharsetSource requestCharsetSource = kCharsetUninitialized; + #ifdef rickgdebug nsString outString; // added out. Redirect to stdout if desired -- gpk 04/01/99 @@ -324,6 +327,15 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL, charset = defaultCharsetFromWebShell; charsetSource = kCharsetFromUserDefault; } + // for html, we need to find out the Meta tag from the hint. + rv = webShell->GetCharacterSetHint(&requestCharset, &requestCharsetSource); + if(NS_SUCCEEDED(rv)) { + if(requestCharsetSource > charsetSource) + { + charsetSource = requestCharsetSource; + charset = requestCharset; + } + } } NS_IF_RELEASE(webShell); #endif @@ -331,8 +343,6 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL, // XXXX // We should take care two more cases here // 1. The charset attribute from HTTP header - // 2. The charset parameter from the META Tag - - // which explicit pass to nsWebShell from nsCharsetObserver if (NS_SUCCEEDED(rv)) { rv = this->SetDocumentCharacterSet(charset);