62754 - Fix meta charset that was getting ignored.

63234 - Fix up an infinite looping caused by embedded null chars.

r=ftang
sr=vidur


git-svn-id: svn://10.0.0.236/trunk@83950 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
harishd%netscape.com 2000-12-21 20:46:00 +00:00
parent 71eaa09bf0
commit 8ed69b648d
14 changed files with 99 additions and 176 deletions

View File

@ -83,7 +83,7 @@ NS_IMETHODIMP nsEditorParserObserver::Notify(
return NS_ERROR_ILLEGAL_VALUE;
}
NS_IMETHODIMP nsEditorParserObserver::Notify(nsISupports* aDocumentID, const PRUnichar* aTag,
const nsDeque* aKeys, const nsDeque* aValues)
const nsStringArray* aKeys, const nsStringArray* aValues)
{
Notify();
return NS_OK;

View File

@ -47,7 +47,7 @@ public:
NS_IMETHOD Notify(PRUint32 aDocumentID, const PRUnichar* aTag, PRUint32 numOfAttributes,
const PRUnichar* nameArray[], const PRUnichar* valueArray[]);
NS_IMETHOD Notify(nsISupports* aDocumentID, const PRUnichar* aTag,
const nsDeque* aKeys, const nsDeque* aValues);
const nsStringArray* aKeys, const nsStringArray* aValues);
/* methods for nsIObserver */
NS_DECL_NSIOBSERVER

View File

@ -83,7 +83,7 @@ NS_IMETHODIMP nsEditorParserObserver::Notify(
return NS_ERROR_ILLEGAL_VALUE;
}
NS_IMETHODIMP nsEditorParserObserver::Notify(nsISupports* aDocumentID, const PRUnichar* aTag,
const nsDeque* aKeys, const nsDeque* aValues)
const nsStringArray* aKeys, const nsStringArray* aValues)
{
Notify();
return NS_OK;

View File

@ -47,7 +47,7 @@ public:
NS_IMETHOD Notify(PRUint32 aDocumentID, const PRUnichar* aTag, PRUint32 numOfAttributes,
const PRUnichar* nameArray[], const PRUnichar* valueArray[]);
NS_IMETHOD Notify(nsISupports* aDocumentID, const PRUnichar* aTag,
const nsDeque* aKeys, const nsDeque* aValues);
const nsStringArray* aKeys, const nsStringArray* aValues);
/* methods for nsIObserver */
NS_DECL_NSIOBSERVER

View File

@ -1452,9 +1452,7 @@ public:
registering tags.
**************************************************************/
nsObserverTopic::nsObserverTopic(const nsString& aTopic) : mTopic(aTopic),
mKeys(0),
mValues(0) {
nsObserverTopic::nsObserverTopic(const nsString& aTopic) : mTopic(aTopic) {
nsCRT::zero(mObservers,sizeof(mObservers));
mCharsetKey.AssignWithConversion("charset");
@ -1512,43 +1510,47 @@ void nsObserverTopic::RegisterObserverForTag(nsIElementObserver *anObserver,eHTM
nsresult nsObserverTopic::Notify(eHTMLTags aTag,nsIParserNode& aNode,void* aUniqueID,nsIParser* aParser) {
nsresult result=NS_OK;
nsDeque* theDeque=GetObserversForTag(aTag);
if(theDeque){
nsDeque* theObservers=GetObserversForTag(aTag);
if(theObservers){
nsAutoString theCharsetValue;
nsCharsetSource theCharsetSource;
aParser->GetDocumentCharset(theCharsetValue,theCharsetSource);
PRInt32 theAttrCount =aNode.GetAttributeCount();
PRUint32 theDequeSize=theDeque->GetSize();
if(0<theDequeSize){
mKeys.Empty();
mValues.Empty();
int index = 0;
PRInt32 theObserversCount=theObservers->GetSize();
if(0<theObserversCount){
nsStringArray keys,values;
PRInt32 index;
for(index=0; index<theAttrCount; index++) {
mKeys.Push((void*)nsPromiseFlatString(aNode.GetKeyAt(index)).get());
mValues.Push((PRUnichar*)aNode.GetValueAt(index).GetUnicode());
keys.AppendString(aNode.GetKeyAt(index));
values.AppendString(aNode.GetValueAt(index));
}
nsAutoString intValue;
// Add pseudo attribute in the end
mKeys.Push((PRUnichar*)mCharsetKey.GetUnicode());
mValues.Push((PRUnichar*)theCharsetValue.GetUnicode());
keys.AppendString(mCharsetKey);
values.AppendString(theCharsetValue);
mKeys.Push((PRUnichar*)mSourceKey.GetUnicode());
keys.AppendString(mSourceKey);
intValue.AppendInt(PRInt32(theCharsetSource),10);
mValues.Push((PRUnichar*)intValue.GetUnicode());
values.AppendString(intValue);
mKeys.Push((PRUnichar*)mDTDKey.GetUnicode());
mValues.Push((PRUnichar*)mTopic.GetUnicode());
keys.AppendString(mDTDKey);
values.AppendString(mTopic);
nsAutoString theTagStr; theTagStr.AssignWithConversion(nsHTMLTags::GetStringValue(aTag));
nsObserverNotifier theNotifier(theTagStr.GetUnicode(),(nsISupports*)aUniqueID,&mKeys,&mValues);
theDeque->FirstThat(theNotifier);
result=theNotifier.mResult;
for(index=0;index<theObserversCount;index++) {
nsIElementObserver* observer=NS_STATIC_CAST(nsIElementObserver*,theObservers->ObjectAt(index));
if(observer) {
result=observer->Notify((nsISupports*)aUniqueID,theTagStr.GetUnicode(),&keys,&values);
if(NS_FAILED(result)) {
break;
}
}
}
}//if
}
return result;

View File

@ -43,6 +43,7 @@
#include "nsIElementObserver.h"
#include "nsIParserNode.h"
#include "nsFixedSizeAllocator.h"
#include "nsVoidArray.h"
#define IF_HOLD(_ptr) if(_ptr) { _ptr->AddRef(); }
#define IF_FREE(_ptr) if(_ptr) { _ptr->Release(); _ptr=0; } // recycles _ptr
@ -483,8 +484,6 @@ public:
nsresult Notify(eHTMLTags aTag,nsIParserNode& aNode,void* aUniqueID,nsIParser* aParser);
nsString mTopic;
nsDeque mKeys;
nsDeque mValues;
nsString mCharsetKey;
nsString mSourceKey;
nsString mDTDKey;
@ -518,39 +517,7 @@ protected:
nsDeque mTopics; //each topic holds a list of observers per tag.
};
/**************************************************************
Define the a functor used to notify observers...
**************************************************************/
class nsObserverNotifier: public nsDequeFunctor{
public:
nsObserverNotifier(const PRUnichar* aTagName,nsISupports* aUniqueKey,
const nsDeque* aKeys=0,const nsDeque* aValues=0){
mKeys=aKeys;
mValues=aValues;
mUniqueKey=aUniqueKey;
mTagName=aTagName;
}
virtual void* operator()(void* anObject) {
nsIElementObserver* theObserver= (nsIElementObserver*)anObject;
if(theObserver) {
mResult = theObserver->Notify(mUniqueKey,mTagName,mKeys,mValues);
}
if(NS_OK==mResult)
return 0;
return anObject;
}
const nsDeque* mKeys;
const nsDeque* mValues;
const PRUnichar* mTagName;
nsISupports* mUniqueKey;
nsresult mResult;
};
//*********************************************************************************************
//*********************************************************************************************
/*********************************************************************************************/
struct TagList {

View File

@ -33,7 +33,7 @@
#include "nsISupports.h"
#include "prtypes.h"
#include "nsHTMLTags.h"
#include "nsDeque.h"
#include "nsVoidArray.h"
// {4672AA04-F6AE-11d2-B3B7-00805F8A6670}
@ -67,7 +67,7 @@ public:
const PRUnichar* valueArray[]) = 0;
NS_IMETHOD Notify(nsISupports* aDocumentID, const PRUnichar* aTag,
const nsDeque* aKeys, const nsDeque* aValues) = 0;
const nsStringArray* aKeys, const nsStringArray* aValues) = 0;
};

View File

@ -745,9 +745,8 @@ nsresult nsScanner::GetIdentifier(nsString& aString,PRBool allowPunct) {
CopyUnicodeTo(mCurrentPosition, current, aString);
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -808,9 +807,8 @@ nsresult nsScanner::ReadIdentifier(nsString& aString,PRBool allowPunct) {
AppendUnicodeTo(mCurrentPosition, current, aString);
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -867,9 +865,8 @@ nsresult nsScanner::ReadIdentifier(nsReadingIterator<PRUnichar>& aStart,
aEnd = current;
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -925,9 +922,8 @@ nsresult nsScanner::ReadNumber(nsString& aString) {
AppendUnicodeTo(origin, current, aString);
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -976,9 +972,8 @@ nsresult nsScanner::ReadNumber(nsReadingIterator<PRUnichar>& aStart,
aEnd = current;
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -1036,9 +1031,8 @@ nsresult nsScanner::ReadWhitespace(nsString& aString) {
AppendUnicodeTo(origin, current, aString);
break;
}
current ++;
}
current ++;
}
SetPosition(current);
@ -1143,9 +1137,8 @@ nsresult nsScanner::ReadWhile(nsString& aString,
AppendUnicodeTo(origin, current, aString);
break;
}
current++;
}
current++;
}
SetPosition(current);

View File

@ -74,7 +74,7 @@ public:
NS_IMETHOD Notify(PRUint32 aDocumentID, const PRUnichar* aTag, PRUint32 numOfAttributes,
const PRUnichar* nameArray[], const PRUnichar* valueArray[]);
NS_IMETHOD Notify(nsISupports* aDocumentID, const PRUnichar* aTag, const nsDeque* keys, const nsDeque* values);
NS_IMETHOD Notify(nsISupports* aDocumentID, const PRUnichar* aTag, const nsStringArray* keys, const nsStringArray* values);
/* methode for nsIObserver */
NS_DECL_NSIOBSERVER
@ -88,7 +88,7 @@ private:
NS_IMETHOD Notify(PRUint32 aDocumentID, PRUint32 numOfAttributes,
const PRUnichar* nameArray[], const PRUnichar* valueArray[]);
NS_IMETHOD Notify(nsISupports* aDocumentID, const nsDeque* keys, const nsDeque* values);
NS_IMETHOD Notify(nsISupports* aDocumentID, const nsStringArray* keys, const nsStringArray* values);
nsICharsetAlias *mAlias;
@ -178,12 +178,12 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
keys.Push((void*)nameArray[i]);
values.Push((void*)valueArray[i]);
}
return Notify((nsISupports*)aDocumentID, &keys, &values);
return NS_OK;//Notify((nsISupports*)aDocumentID, &keys, &values);
}
NS_IMETHODIMP nsMetaCharsetObserver::Notify(
nsISupports* aDocumentID,
const PRUnichar* aTag,
const nsDeque* keys, const nsDeque* values)
const nsStringArray* keys, const nsStringArray* values)
{
if(0 != nsCRT::strcasecmp(aTag, "META"))
return NS_ERROR_ILLEGAL_VALUE;
@ -192,25 +192,24 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
}
NS_IMETHODIMP nsMetaCharsetObserver::Notify(
nsISupports* aDocumentID,
const nsDeque* keys, const nsDeque* values)
const nsStringArray* keys, const nsStringArray* values)
{
NS_PRECONDITION(keys!=nsnull && values!=nsnull,"Need key-value pair");
PRInt32 numOfAttributes = keys->GetSize();
NS_ASSERTION( numOfAttributes == values->GetSize(), "size mismatch");
PRInt32 numOfAttributes = keys->Count();
NS_ASSERTION( numOfAttributes == values->Count(), "size mismatch");
nsresult res=NS_OK;
#ifdef DEBUG
PRUnichar Uxcommand[]={'X','_','C','O','M','M','A','N','D','\0'};
PRUnichar UcharsetSource[]=
{'c','h','a','r','s','e','t','S','o','u','r','c','e','\0'};
PRUnichar UcharsetSource[]={'c','h','a','r','s','e','t','S','o','u','r','c','e','\0'};
PRUnichar Ucharset[]={'c','h','a','r','s','e','t','\0'};
NS_ASSERTION(numOfAttributes >= 3, "should have at least 3 private attribute");
NS_ASSERTION(0==nsCRT::strcmp(Uxcommand,(const PRUnichar*)keys->ObjectAt(numOfAttributes-1)),
"last name should be 'X_COMMAND'" );
NS_ASSERTION(0==nsCRT::strcmp(UcharsetSource,(const PRUnichar*)keys->ObjectAt(numOfAttributes-2)),
"2nd last name should be 'charsetSource'" );
NS_ASSERTION(0==nsCRT::strcmp(Ucharset,(const PRUnichar*)keys->ObjectAt(numOfAttributes-3)),
"3rd last name should be 'charset'" );
NS_ASSERTION(0==nsCRT::strcmp(Uxcommand,(keys->StringAt(numOfAttributes-1))->GetUnicode()),"last name should be 'X_COMMAND'" );
NS_ASSERTION(0==nsCRT::strcmp(UcharsetSource,(keys->StringAt(numOfAttributes-2))->GetUnicode()),"2nd last name should be 'charsetSource'" );
NS_ASSERTION(0==nsCRT::strcmp(Ucharset,(keys->StringAt(numOfAttributes-3))->GetUnicode()),"3rd last name should be 'charset'" );
#endif
NS_ASSERTION(mAlias, "Didn't get nsICharsetAlias in constructor");
@ -220,8 +219,8 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
// we need at least 5 - HTTP-EQUIV, CONTENT and 3 private
if(numOfAttributes >= 5 )
{
const PRUnichar *charset = (const PRUnichar*)values->ObjectAt(numOfAttributes-3);
const PRUnichar *source = (const PRUnichar*)values->ObjectAt(numOfAttributes-2);
const PRUnichar *charset = (values->StringAt(numOfAttributes-3))->GetUnicode();
const PRUnichar *source = (values->StringAt(numOfAttributes-2))->GetUnicode();
PRInt32 err;
nsAutoString srcStr(source);
nsCharsetSource src = (nsCharsetSource) srcStr.ToInteger(&err);
@ -238,10 +237,10 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
const PRUnichar *contentValue=nsnull;
for(i=0;i<(numOfAttributes-3);i++)
{
if(0 == nsCRT::strcasecmp((const PRUnichar*)keys->ObjectAt(i), "HTTP-EQUIV"))
httpEquivValue=(const PRUnichar*)values->ObjectAt(i);
else if(0 == nsCRT::strcasecmp((const PRUnichar*)keys->ObjectAt(i), "content"))
contentValue=(const PRUnichar*)values->ObjectAt(i);
if(0 == nsCRT::strcasecmp((keys->StringAt(i))->GetUnicode(), "HTTP-EQUIV"))
httpEquivValue=((values->StringAt(i))->GetUnicode());
else if(0 == nsCRT::strcasecmp((keys->StringAt(i))->GetUnicode(), "content"))
contentValue=(values->StringAt(i))->GetUnicode();
}
NS_NAMED_LITERAL_STRING(contenttype, "Content-Type");
NS_NAMED_LITERAL_STRING(texthtml, "text/html");

View File

@ -73,7 +73,7 @@ public:
const PRUnichar* nameArray[], const PRUnichar* valueArray[]);
NS_IMETHOD Notify(PRUint32 aDocumentID, const PRUnichar* aTag, PRUint32 numOfAttributes,
const PRUnichar* nameArray[], const PRUnichar* valueArray[]);
NS_IMETHOD Notify(nsISupports* aDocumentID, const PRUnichar* aTag, const nsDeque* keys, const nsDeque* values)
NS_IMETHOD Notify(nsISupports* aDocumentID, const PRUnichar* aTag, const nsStringArray* keys, const nsStringArray* values)
{ return NS_ERROR_NOT_IMPLEMENTED; }
/* methode for nsIObserver */

View File

@ -1452,9 +1452,7 @@ public:
registering tags.
**************************************************************/
nsObserverTopic::nsObserverTopic(const nsString& aTopic) : mTopic(aTopic),
mKeys(0),
mValues(0) {
nsObserverTopic::nsObserverTopic(const nsString& aTopic) : mTopic(aTopic) {
nsCRT::zero(mObservers,sizeof(mObservers));
mCharsetKey.AssignWithConversion("charset");
@ -1512,43 +1510,47 @@ void nsObserverTopic::RegisterObserverForTag(nsIElementObserver *anObserver,eHTM
nsresult nsObserverTopic::Notify(eHTMLTags aTag,nsIParserNode& aNode,void* aUniqueID,nsIParser* aParser) {
nsresult result=NS_OK;
nsDeque* theDeque=GetObserversForTag(aTag);
if(theDeque){
nsDeque* theObservers=GetObserversForTag(aTag);
if(theObservers){
nsAutoString theCharsetValue;
nsCharsetSource theCharsetSource;
aParser->GetDocumentCharset(theCharsetValue,theCharsetSource);
PRInt32 theAttrCount =aNode.GetAttributeCount();
PRUint32 theDequeSize=theDeque->GetSize();
if(0<theDequeSize){
mKeys.Empty();
mValues.Empty();
int index = 0;
PRInt32 theObserversCount=theObservers->GetSize();
if(0<theObserversCount){
nsStringArray keys,values;
PRInt32 index;
for(index=0; index<theAttrCount; index++) {
mKeys.Push((void*)nsPromiseFlatString(aNode.GetKeyAt(index)).get());
mValues.Push((PRUnichar*)aNode.GetValueAt(index).GetUnicode());
keys.AppendString(aNode.GetKeyAt(index));
values.AppendString(aNode.GetValueAt(index));
}
nsAutoString intValue;
// Add pseudo attribute in the end
mKeys.Push((PRUnichar*)mCharsetKey.GetUnicode());
mValues.Push((PRUnichar*)theCharsetValue.GetUnicode());
keys.AppendString(mCharsetKey);
values.AppendString(theCharsetValue);
mKeys.Push((PRUnichar*)mSourceKey.GetUnicode());
keys.AppendString(mSourceKey);
intValue.AppendInt(PRInt32(theCharsetSource),10);
mValues.Push((PRUnichar*)intValue.GetUnicode());
values.AppendString(intValue);
mKeys.Push((PRUnichar*)mDTDKey.GetUnicode());
mValues.Push((PRUnichar*)mTopic.GetUnicode());
keys.AppendString(mDTDKey);
values.AppendString(mTopic);
nsAutoString theTagStr; theTagStr.AssignWithConversion(nsHTMLTags::GetStringValue(aTag));
nsObserverNotifier theNotifier(theTagStr.GetUnicode(),(nsISupports*)aUniqueID,&mKeys,&mValues);
theDeque->FirstThat(theNotifier);
result=theNotifier.mResult;
for(index=0;index<theObserversCount;index++) {
nsIElementObserver* observer=NS_STATIC_CAST(nsIElementObserver*,theObservers->ObjectAt(index));
if(observer) {
result=observer->Notify((nsISupports*)aUniqueID,theTagStr.GetUnicode(),&keys,&values);
if(NS_FAILED(result)) {
break;
}
}
}
}//if
}
return result;

View File

@ -43,6 +43,7 @@
#include "nsIElementObserver.h"
#include "nsIParserNode.h"
#include "nsFixedSizeAllocator.h"
#include "nsVoidArray.h"
#define IF_HOLD(_ptr) if(_ptr) { _ptr->AddRef(); }
#define IF_FREE(_ptr) if(_ptr) { _ptr->Release(); _ptr=0; } // recycles _ptr
@ -483,8 +484,6 @@ public:
nsresult Notify(eHTMLTags aTag,nsIParserNode& aNode,void* aUniqueID,nsIParser* aParser);
nsString mTopic;
nsDeque mKeys;
nsDeque mValues;
nsString mCharsetKey;
nsString mSourceKey;
nsString mDTDKey;
@ -518,39 +517,7 @@ protected:
nsDeque mTopics; //each topic holds a list of observers per tag.
};
/**************************************************************
Define the a functor used to notify observers...
**************************************************************/
class nsObserverNotifier: public nsDequeFunctor{
public:
nsObserverNotifier(const PRUnichar* aTagName,nsISupports* aUniqueKey,
const nsDeque* aKeys=0,const nsDeque* aValues=0){
mKeys=aKeys;
mValues=aValues;
mUniqueKey=aUniqueKey;
mTagName=aTagName;
}
virtual void* operator()(void* anObject) {
nsIElementObserver* theObserver= (nsIElementObserver*)anObject;
if(theObserver) {
mResult = theObserver->Notify(mUniqueKey,mTagName,mKeys,mValues);
}
if(NS_OK==mResult)
return 0;
return anObject;
}
const nsDeque* mKeys;
const nsDeque* mValues;
const PRUnichar* mTagName;
nsISupports* mUniqueKey;
nsresult mResult;
};
//*********************************************************************************************
//*********************************************************************************************
/*********************************************************************************************/
struct TagList {

View File

@ -33,7 +33,7 @@
#include "nsISupports.h"
#include "prtypes.h"
#include "nsHTMLTags.h"
#include "nsDeque.h"
#include "nsVoidArray.h"
// {4672AA04-F6AE-11d2-B3B7-00805F8A6670}
@ -67,7 +67,7 @@ public:
const PRUnichar* valueArray[]) = 0;
NS_IMETHOD Notify(nsISupports* aDocumentID, const PRUnichar* aTag,
const nsDeque* aKeys, const nsDeque* aValues) = 0;
const nsStringArray* aKeys, const nsStringArray* aValues) = 0;
};

View File

@ -745,9 +745,8 @@ nsresult nsScanner::GetIdentifier(nsString& aString,PRBool allowPunct) {
CopyUnicodeTo(mCurrentPosition, current, aString);
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -808,9 +807,8 @@ nsresult nsScanner::ReadIdentifier(nsString& aString,PRBool allowPunct) {
AppendUnicodeTo(mCurrentPosition, current, aString);
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -867,9 +865,8 @@ nsresult nsScanner::ReadIdentifier(nsReadingIterator<PRUnichar>& aStart,
aEnd = current;
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -925,9 +922,8 @@ nsresult nsScanner::ReadNumber(nsString& aString) {
AppendUnicodeTo(origin, current, aString);
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -976,9 +972,8 @@ nsresult nsScanner::ReadNumber(nsReadingIterator<PRUnichar>& aStart,
aEnd = current;
break;
}
current++;
}
current++;
}
SetPosition(current);
@ -1036,9 +1031,8 @@ nsresult nsScanner::ReadWhitespace(nsString& aString) {
AppendUnicodeTo(origin, current, aString);
break;
}
current ++;
}
current ++;
}
SetPosition(current);
@ -1143,9 +1137,8 @@ nsresult nsScanner::ReadWhile(nsString& aString,
AppendUnicodeTo(origin, current, aString);
break;
}
current++;
}
current++;
}
SetPosition(current);