change observer interfaces. Temp move the casting code of PRInt32 into these class untill

we change the docloader interface. r=harishd
This commit is contained in:
ftang%netscape.com 2000-03-22 21:02:40 +00:00
parent b3c6c2dd07
commit 3add6e13f0
4 changed files with 51 additions and 133 deletions

View File

@ -19,6 +19,7 @@
*
* Contributor(s):
*/
#include "nsDeque.h"
#include "nsICharsetAlias.h"
#include "nsMetaCharsetObserver.h"
#include "nsIMetaCharsetService.h"
@ -73,16 +74,22 @@ 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, nsDeque& keys, nsDeque& values);
/* methode for nsIObserver */
NS_DECL_NSIOBSERVER
/* methode for nsIMetaCharsetService */
NS_IMETHOD Start();
NS_IMETHOD End();
private:
NS_IMETHOD Notify(PRUint32 aDocumentID, PRUint32 numOfAttributes,
const PRUnichar* nameArray[], const PRUnichar* valueArray[]);
NS_IMETHOD Notify(nsISupports* aDocumentID, nsDeque& keys, nsDeque& values);
nsICharsetAlias *mAlias;
};
@ -156,14 +163,39 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
else
return Notify(aDocumentID, numOfAttributes, nameArray, valueArray);
}
//-------------------------------------------------------------------------
NS_IMETHODIMP nsMetaCharsetObserver::Notify(
PRUint32 aDocumentID,
PRUint32 numOfAttributes,
const PRUnichar* nameArray[],
const PRUnichar* valueArray[])
{
#if 1 // perfor rewrite fix bug 17409
nsDeque keys(0);
nsDeque values(0);
PRUint32 i;
for(i=0;i<numOfAttributes;i++)
{
keys.Push((void*)nameArray[i]);
values.Push((void*)valueArray[i]);
}
return Notify((nsISupports*)aDocumentID, keys, values);
}
NS_IMETHODIMP nsMetaCharsetObserver::Notify(
nsISupports* aDocumentID,
const PRUnichar* aTag,
nsDeque& keys, nsDeque& values)
{
if(0 != nsCRT::strcasecmp(aTag, "META"))
return NS_ERROR_ILLEGAL_VALUE;
else
return Notify(aDocumentID, keys, values);
}
NS_IMETHODIMP nsMetaCharsetObserver::Notify(
nsISupports* aDocumentID,
nsDeque& keys, nsDeque& values)
{
PRInt32 numOfAttributes = keys.GetSize();
NS_ASSERTION( numOfAttributes == values.GetSize(), "size mismatch");
nsresult res=NS_OK;
#ifdef DEBUG
PRUnichar Uxcommand[]={'X','_','C','O','M','M','A','N','D','\0'};
@ -171,11 +203,11 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
{'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,nameArray[numOfAttributes-1]),
NS_ASSERTION(0==nsCRT::strcmp(Uxcommand,(const PRUnichar*)keys.ObjectAt(numOfAttributes-1)),
"last name should be 'X_COMMAND'" );
NS_ASSERTION(0==nsCRT::strcmp(UcharsetSource,nameArray[numOfAttributes-2]),
NS_ASSERTION(0==nsCRT::strcmp(UcharsetSource,(const PRUnichar*)keys.ObjectAt(numOfAttributes-2)),
"2nd last name should be 'charsetSource'" );
NS_ASSERTION(0==nsCRT::strcmp(Ucharset,nameArray[numOfAttributes-3]),
NS_ASSERTION(0==nsCRT::strcmp(Ucharset,(const PRUnichar*)keys.ObjectAt(numOfAttributes-3)),
"3rd last name should be 'charset'" );
#endif
NS_ASSERTION(mAlias, "Didn't get nsICharsetAlias in constructor");
@ -186,8 +218,8 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
// we need at least 5 - HTTP-EQUIV, CONTENT and 3 private
if(numOfAttributes >= 5 )
{
const PRUnichar *charset = valueArray[numOfAttributes-3];
const PRUnichar *source = valueArray[numOfAttributes-2];
const PRUnichar *charset = (const PRUnichar*)values.ObjectAt(numOfAttributes-3);
const PRUnichar *source = (const PRUnichar*)values.ObjectAt(numOfAttributes-2);
PRInt32 err;
nsAutoString srcStr(source);
nsCharsetSource src = (nsCharsetSource) srcStr.ToInteger(&err);
@ -199,15 +231,15 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
if(kCharsetFromMetaTag <= src)
return NS_OK; // current charset have higher priority. do bother to do the following
PRUint32 i;
PRInt32 i;
const PRUnichar *httpEquivValue=nsnull;
const PRUnichar *contentValue=nsnull;
for(i=0;i<(numOfAttributes-3);i++)
{
if(0 == nsCRT::strcasecmp(nameArray[i], "HTTP-EQUIV"))
httpEquivValue=valueArray[i];
else if(0 == nsCRT::strcasecmp(nameArray[i], "content"))
contentValue=valueArray[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);
}
static nsAutoString contenttype("Content-Type");
static nsAutoString texthtml("text/html");
@ -270,123 +302,6 @@ NS_IMETHODIMP nsMetaCharsetObserver::Notify(
} // if
}
return NS_OK;
#else // old code
nsresult res = NS_OK;
PRUint32 i;
char command[256];
command[0]='\0';
// Only process if we get the HTTP-EQUIV=Content-Type in meta
// We totaly need 4 attributes
// HTTP-EQUIV
// CONTENT
// currentCharset - pseudo attribute fake by parser
// currentCharsetSource - pseudo attribute fake by parser
// X_COMMAND - pseudo attribute fake by parser
if((numOfAttributes >= 4) &&
(0 == nsCRT::strcasecmp(nameArray[0], "HTTP-EQUIV")) &&
(0 == nsCRT::strncasecmp(((('\'' == valueArray[0][0]) || ('\"' == valueArray[0][0]))
? (valueArray[0]+1)
: valueArray[0]),
"Content-Type",
12)))
{
PRBool bGotCharset = PR_FALSE;
PRBool bGotCharsetSource = PR_FALSE;
nsAutoString currentCharset("unknown");
nsAutoString charsetSourceStr("unknown");
for(i=0; i < numOfAttributes; i++)
{
if(0==nsCRT::strcmp(nameArray[i], "charset"))
{
bGotCharset = PR_TRUE;
currentCharset = valueArray[i];
} else if(0==nsCRT::strcmp(nameArray[i], "charsetSource")) {
bGotCharsetSource = PR_TRUE;
charsetSourceStr = valueArray[i];
} else if(0==nsCRT::strcmp(nameArray[i], "X_COMMAND")) {
nsAutoString tmp(valueArray[i]);
tmp.ToCString(command, 256);
}
}
// if we cannot find currentCharset or currentCharsetSource
// return error.
if(! ( bGotCharsetSource && bGotCharset ))
{
return NS_ERROR_ILLEGAL_VALUE;
}
PRInt32 err;
PRInt32 charsetSourceInt = charsetSourceStr.ToInteger(&err);
// if we cannot convert the string into nsCharsetSource, return error
if(NS_FAILED(err))
return NS_ERROR_ILLEGAL_VALUE;
nsCharsetSource currentCharsetSource = (nsCharsetSource)charsetSourceInt;
if(kCharsetFromMetaTag > currentCharsetSource)
{
for(i=0; i < numOfAttributes; i++)
{
if (0==nsCRT::strcasecmp(nameArray[i],"CONTENT"))
{
const PRUnichar *attr = valueArray[i] ;
if(('\"' == attr[0]) || ('\'' == attr[0]))
attr++;
nsAutoString content(attr);
nsAutoString type;
content.Left(type, 9); // length of "text/html" == 9
if(type.EqualsIgnoreCase("text/html"))
{
PRInt32 charsetValueStart = content.RFind("charset=", PR_TRUE ) ;
if(kNotFound != charsetValueStart)
{
charsetValueStart += 8; // 8 = "charset=".length
PRInt32 charsetValueEnd = content.FindCharInSet("\'\";", charsetValueStart );
if(kNotFound == charsetValueEnd )
charsetValueEnd = content.Length();
nsAutoString theCharset;
content.Mid(theCharset, charsetValueStart, charsetValueEnd - charsetValueStart);
if(! theCharset.Equals(currentCharset))
{
NS_WITH_SERVICE(nsICharsetAlias, calias, kCharsetAliasCID, &res);
if(NS_SUCCEEDED(res) && (nsnull != calias) )
{
PRBool same = PR_FALSE;
res = calias->Equals( theCharset, currentCharset, &same);
if(NS_SUCCEEDED(res) && (! same))
{
nsAutoString preferred;
res = calias->GetPreferred(theCharset, preferred);
if(NS_SUCCEEDED(res))
{
const char* charsetInCStr = preferred.ToNewCString();
if(nsnull != charsetInCStr) {
res = NotifyWebShell(aDocumentID, charsetInCStr, kCharsetFromMetaTag ,
command[0]?command:nsnull);
delete [] (char*)charsetInCStr;
return res;
}
} // if check for GetPreferred
} // if check res for Equals
} // if check res for GetService
} // if Equals
} // if check charset=
} // if check text/html
break;
} // if check CONTENT
} // for ( numOfAttributes )
} // if check nsCharsetSource
} // if
return NS_OK;
#endif
}
//-------------------------------------------------------------------------

View File

@ -37,7 +37,7 @@ static NS_DEFINE_IID(kIWebShellServicesIID, NS_IWEB_SHELL_SERVICES_IID);
//-------------------------------------------------------------------------
NS_IMETHODIMP nsObserverBase::NotifyWebShell(
PRUint32 aDocumentID, const char* charset, nsCharsetSource source)
nsISupports* aDocumentID, const char* charset, nsCharsetSource source)
{
nsresult res = NS_OK;
nsresult rv = NS_OK;
@ -51,7 +51,8 @@ NS_IMETHODIMP nsObserverBase::NotifyWebShell(
(nsISupports**)&docLoader)))
goto done;
if(NS_FAILED(rv =docLoader->GetContentViewerContainer(aDocumentID, &cvc)))
// temp change to (PRUint32) cast untill we change the GetContentViewerContainer interface
if(NS_FAILED(rv =docLoader->GetContentViewerContainer((PRUint32)aDocumentID, &cvc)))
goto done;
/* sspitzer: this was necessary to get printing of mail to work (sort of)

View File

@ -46,7 +46,7 @@ public:
*/
protected:
NS_IMETHOD NotifyWebShell(PRUint32 aDocumentID,
NS_IMETHOD NotifyWebShell(nsISupports* aDocumentID,
const char* charset,
nsCharsetSource source);

View File

@ -73,6 +73,8 @@ 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, nsDeque& keys, nsDeque& values)
{ return NS_ERROR_NOT_IMPLEMENTED; };
/* methode for nsIObserver */
NS_DECL_NSIOBSERVER
@ -220,7 +222,7 @@ NS_IMETHODIMP nsXMLEncodingObserver::Notify(
{
const char* charsetInCStr = preferred.ToNewCString();
if(nsnull != charsetInCStr) {
res = NotifyWebShell(aDocumentID, charsetInCStr, kCharsetFromMetaTag );
res = NotifyWebShell((nsISupports*)aDocumentID, charsetInCStr, kCharsetFromMetaTag );
delete [] (char*)charsetInCStr;
return res;
}