From c996b9fb653e3e17bfd241bcce7d188edc0c4b92 Mon Sep 17 00:00:00 2001 From: "harishd%netscape.com" Date: Thu, 18 Apr 2002 22:11:17 +0000 Subject: [PATCH] Prevent charset loading for document.write content because the content is already in unicode. b=125317, r=ftang, sr=jst git-svn-id: svn://10.0.0.236/trunk@119320 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/document/src/nsHTMLContentSink.cpp | 12 +++++++++--- .../html/document/src/nsHTMLDocument.h | 2 ++ .../html/document/src/nsIHTMLDocument.h | 4 +++- .../composer/src/nsEditorParserObserver.cpp | 3 ++- .../composer/src/nsEditorParserObserver.h | 3 ++- .../htmlparser/public/nsIElementObserver.h | 4 +++- mozilla/htmlparser/public/nsIParserService.h | 3 ++- mozilla/htmlparser/src/nsDTDUtils.cpp | 5 +++-- mozilla/htmlparser/src/nsDTDUtils.h | 3 ++- .../chardet/src/nsMetaCharsetObserver.cpp | 19 ++++++++++++++----- .../intl/chardet/src/nsMetaCharsetObserver.h | 3 ++- .../intl/chardet/src/nsXMLEncodingObserver.h | 3 ++- .../htmlparser/public/nsIElementObserver.h | 4 +++- .../htmlparser/public/nsIParserService.h | 3 ++- mozilla/parser/htmlparser/src/nsDTDUtils.cpp | 5 +++-- mozilla/parser/htmlparser/src/nsDTDUtils.h | 3 ++- 16 files changed, 56 insertions(+), 23 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 5fd39e818a9..9bbbc45d45c 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -153,6 +153,9 @@ #include "nsEscape.h" + +#include "nsIElementObserver.h" + static NS_DEFINE_CID(kLayoutHistoryStateCID, NS_LAYOUT_HISTORY_STATE_CID); #ifdef ALLOW_ASYNCH_STYLE_SHEETS @@ -3955,12 +3958,15 @@ PRInt32 oldMaxTokenProcessingTime = GetMaxTokenProcessingTime(); return NS_OK; } -#include "nsIElementObserver.h" - NS_IMETHODIMP HTMLContentSink::NotifyTagObservers(nsIParserNode* aNode) { - return mObservers? mObservers->Notify(aNode,mParser,mWebShell) : NS_OK; + // Bug 125317 + // Inform observers that we're handling a document.write. + // This information is necessary for the charset observer, atleast, + // to make a decision whether a new charset loading is required or not. + PRUint32 flag = mHTMLDocument && mHTMLDocument->IsWriting() ? nsIElementObserver::IS_DOCUMENT_WRITE : 0; + return mObservers? mObservers->Notify(aNode, mParser, mWebShell, flag) : NS_OK; } void diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 7df8119c165..6609113a431 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -125,6 +125,8 @@ public: NS_IMETHOD GetDTDMode(nsDTDMode& aMode); NS_IMETHOD SetDTDMode(nsDTDMode aMode); + NS_IMETHOD_(PRBool) IsWriting() { return mWriteLevel != PRUint32(0); } + NS_IMETHOD ContentAppended(nsIContent* aContainer, PRInt32 aNewIndexInContainer); NS_IMETHOD ContentInserted(nsIContent* aContainer, diff --git a/mozilla/content/html/document/src/nsIHTMLDocument.h b/mozilla/content/html/document/src/nsIHTMLDocument.h index 7671c036cc0..5f6d6ab51b3 100644 --- a/mozilla/content/html/document/src/nsIHTMLDocument.h +++ b/mozilla/content/html/document/src/nsIHTMLDocument.h @@ -92,7 +92,9 @@ public: NS_IMETHOD GetFormControlElements(nsIDOMNodeList** aReturn) = 0; - NS_IMETHOD GetBodyElement(nsIDOMHTMLBodyElement** aBody) = 0; + NS_IMETHOD GetBodyElement(nsIDOMHTMLBodyElement** aBody) = 0; + + NS_IMETHOD_(PRBool) IsWriting() = 0; }; diff --git a/mozilla/editor/composer/src/nsEditorParserObserver.cpp b/mozilla/editor/composer/src/nsEditorParserObserver.cpp index fe826413357..2babb5d95cd 100644 --- a/mozilla/editor/composer/src/nsEditorParserObserver.cpp +++ b/mozilla/editor/composer/src/nsEditorParserObserver.cpp @@ -95,7 +95,8 @@ NS_IMETHODIMP nsEditorParserObserver::Notify(nsISupports* aWebShell, nsISupports* aChannel, const PRUnichar* aTag, const nsStringArray* aKeys, - const nsStringArray* aValues) + const nsStringArray* aValues, + const PRUint32 aFlags) { Notify(); return NS_OK; diff --git a/mozilla/editor/composer/src/nsEditorParserObserver.h b/mozilla/editor/composer/src/nsEditorParserObserver.h index a46310acabc..6c8eda3b8c9 100644 --- a/mozilla/editor/composer/src/nsEditorParserObserver.h +++ b/mozilla/editor/composer/src/nsEditorParserObserver.h @@ -66,7 +66,8 @@ public: nsISupports* aChannel, const PRUnichar* aTag, const nsStringArray* aKeys, - const nsStringArray* aValues); + const nsStringArray* aValues, + const PRUint32 aFlags); /* methods for nsIObserver */ NS_DECL_NSIOBSERVER diff --git a/mozilla/htmlparser/public/nsIElementObserver.h b/mozilla/htmlparser/public/nsIElementObserver.h index e3f9a0ba39a..34dc470485f 100644 --- a/mozilla/htmlparser/public/nsIElementObserver.h +++ b/mozilla/htmlparser/public/nsIElementObserver.h @@ -61,6 +61,7 @@ class nsIElementObserver : public nsISupports { public: static const nsIID& GetIID() { static nsIID iid = NS_IELEMENTOBSERVER_IID; return iid; } + enum { IS_DOCUMENT_WRITE = 1U }; /* * Subject call observer when the parser hit the tag * @param aDocumentID- ID of the document @@ -81,7 +82,8 @@ public: nsISupports* aChannel, const PRUnichar* aTag, const nsStringArray* aKeys, - const nsStringArray* aValues) = 0; + const nsStringArray* aValues, + const PRUint32 aFlags) = 0; }; diff --git a/mozilla/htmlparser/public/nsIParserService.h b/mozilla/htmlparser/public/nsIParserService.h index f5d2ed36636..3478ef6f738 100644 --- a/mozilla/htmlparser/public/nsIParserService.h +++ b/mozilla/htmlparser/public/nsIParserService.h @@ -62,7 +62,8 @@ class nsIObserverEntry : public nsISupports { NS_IMETHOD Notify(nsIParserNode* aNode, nsIParser* aParser, - nsISupports* aWebShell) = 0; + nsISupports* aWebShell, + const PRUint32 aFlags) = 0; }; diff --git a/mozilla/htmlparser/src/nsDTDUtils.cpp b/mozilla/htmlparser/src/nsDTDUtils.cpp index beb72c1c542..e6e72d3fa6e 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/htmlparser/src/nsDTDUtils.cpp @@ -1523,7 +1523,8 @@ nsObserverEntry::~nsObserverEntry() { NS_IMETHODIMP nsObserverEntry::Notify(nsIParserNode* aNode, nsIParser* aParser, - nsISupports* aWebShell) + nsISupports* aWebShell, + const PRUint32 aFlags) { NS_ENSURE_ARG_POINTER(aNode); NS_ENSURE_ARG_POINTER(aParser); @@ -1573,7 +1574,7 @@ nsObserverEntry::Notify(nsIParserNode* aNode, if (observer) { result = observer->Notify(aWebShell, channel, nsHTMLTags::GetStringValue(theTag), - &keys, &values); + &keys, &values, aFlags); if (NS_FAILED(result)) { break; } diff --git a/mozilla/htmlparser/src/nsDTDUtils.h b/mozilla/htmlparser/src/nsDTDUtils.h index ef915c592b3..7d4ede429b4 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.h +++ b/mozilla/htmlparser/src/nsDTDUtils.h @@ -571,7 +571,8 @@ public: NS_IMETHOD Notify(nsIParserNode* aNode, nsIParser* aParser, - nsISupports* aWebShell); + nsISupports* aWebShell, + const PRUint32 aFlags); nsresult AddObserver(nsIElementObserver* aObserver,eHTMLTags aTag); void RemoveObserver(nsIElementObserver* aObserver); diff --git a/mozilla/intl/chardet/src/nsMetaCharsetObserver.cpp b/mozilla/intl/chardet/src/nsMetaCharsetObserver.cpp index 285de17d35a..50544a3725a 100644 --- a/mozilla/intl/chardet/src/nsMetaCharsetObserver.cpp +++ b/mozilla/intl/chardet/src/nsMetaCharsetObserver.cpp @@ -146,13 +146,22 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify( nsISupports* aWebShell, nsISupports* aChannel, const PRUnichar* aTag, - const nsStringArray* keys, const nsStringArray* values) + const nsStringArray* keys, + const nsStringArray* values, + const PRUint32 aFlags) { + nsresult result = NS_OK; + // bug 125317 - document.write content is already an unicode content. + if (!(aFlags & nsIElementObserver::IS_DOCUMENT_WRITE)) { if(!nsDependentString(aTag).Equals(NS_LITERAL_STRING("META"), - nsCaseInsensitiveStringComparator())) - return NS_ERROR_ILLEGAL_VALUE; - else - return Notify(aWebShell, aChannel, keys, values); + nsCaseInsensitiveStringComparator())) { + result = NS_ERROR_ILLEGAL_VALUE; + } + else { + result = Notify(aWebShell, aChannel, keys, values); + } + } + return result; } #define IS_SPACE_CHARS(ch) (ch == ' ' || ch == '\b' || ch == '\r' || ch == '\n') diff --git a/mozilla/intl/chardet/src/nsMetaCharsetObserver.h b/mozilla/intl/chardet/src/nsMetaCharsetObserver.h index df7e9f5a627..2d66381c451 100644 --- a/mozilla/intl/chardet/src/nsMetaCharsetObserver.h +++ b/mozilla/intl/chardet/src/nsMetaCharsetObserver.h @@ -78,7 +78,8 @@ public: nsISupports* aChannel, const PRUnichar* aTag, const nsStringArray* keys, - const nsStringArray* values); + const nsStringArray* values, + const PRUint32 aFlags); NS_DECL_ISUPPORTS diff --git a/mozilla/intl/chardet/src/nsXMLEncodingObserver.h b/mozilla/intl/chardet/src/nsXMLEncodingObserver.h index 4105189bb9a..fd2d7e5862a 100644 --- a/mozilla/intl/chardet/src/nsXMLEncodingObserver.h +++ b/mozilla/intl/chardet/src/nsXMLEncodingObserver.h @@ -73,7 +73,8 @@ public: nsISupports* aChannel, const PRUnichar* aTag, const nsStringArray* keys, - const nsStringArray* values) + const nsStringArray* values, + const PRUint32 aFlags) { return NS_ERROR_NOT_IMPLEMENTED; } NS_DECL_ISUPPORTS diff --git a/mozilla/parser/htmlparser/public/nsIElementObserver.h b/mozilla/parser/htmlparser/public/nsIElementObserver.h index e3f9a0ba39a..34dc470485f 100644 --- a/mozilla/parser/htmlparser/public/nsIElementObserver.h +++ b/mozilla/parser/htmlparser/public/nsIElementObserver.h @@ -61,6 +61,7 @@ class nsIElementObserver : public nsISupports { public: static const nsIID& GetIID() { static nsIID iid = NS_IELEMENTOBSERVER_IID; return iid; } + enum { IS_DOCUMENT_WRITE = 1U }; /* * Subject call observer when the parser hit the tag * @param aDocumentID- ID of the document @@ -81,7 +82,8 @@ public: nsISupports* aChannel, const PRUnichar* aTag, const nsStringArray* aKeys, - const nsStringArray* aValues) = 0; + const nsStringArray* aValues, + const PRUint32 aFlags) = 0; }; diff --git a/mozilla/parser/htmlparser/public/nsIParserService.h b/mozilla/parser/htmlparser/public/nsIParserService.h index f5d2ed36636..3478ef6f738 100644 --- a/mozilla/parser/htmlparser/public/nsIParserService.h +++ b/mozilla/parser/htmlparser/public/nsIParserService.h @@ -62,7 +62,8 @@ class nsIObserverEntry : public nsISupports { NS_IMETHOD Notify(nsIParserNode* aNode, nsIParser* aParser, - nsISupports* aWebShell) = 0; + nsISupports* aWebShell, + const PRUint32 aFlags) = 0; }; diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp index beb72c1c542..e6e72d3fa6e 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp @@ -1523,7 +1523,8 @@ nsObserverEntry::~nsObserverEntry() { NS_IMETHODIMP nsObserverEntry::Notify(nsIParserNode* aNode, nsIParser* aParser, - nsISupports* aWebShell) + nsISupports* aWebShell, + const PRUint32 aFlags) { NS_ENSURE_ARG_POINTER(aNode); NS_ENSURE_ARG_POINTER(aParser); @@ -1573,7 +1574,7 @@ nsObserverEntry::Notify(nsIParserNode* aNode, if (observer) { result = observer->Notify(aWebShell, channel, nsHTMLTags::GetStringValue(theTag), - &keys, &values); + &keys, &values, aFlags); if (NS_FAILED(result)) { break; } diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.h b/mozilla/parser/htmlparser/src/nsDTDUtils.h index ef915c592b3..7d4ede429b4 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.h +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.h @@ -571,7 +571,8 @@ public: NS_IMETHOD Notify(nsIParserNode* aNode, nsIParser* aParser, - nsISupports* aWebShell); + nsISupports* aWebShell, + const PRUint32 aFlags); nsresult AddObserver(nsIElementObserver* aObserver,eHTMLTags aTag); void RemoveObserver(nsIElementObserver* aObserver);