Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
nsXMLEncodingObserver Class Reference

#include <nsXMLEncodingObserver.h>

Inheritance diagram for nsXMLEncodingObserver:
Inheritance graph
[legend]
Collaboration diagram for nsXMLEncodingObserver:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { IS_DOCUMENT_WRITE = 1U }

Public Member Functions

 nsXMLEncodingObserver ()
virtual ~nsXMLEncodingObserver ()
NS_IMETHOD Notify (PRUint32 aDocumentID, eHTMLTags aTag, PRUint32 numOfAttributes, 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 *aWebShell, nsISupports *aChannel, const PRUnichar *aTag, const nsStringArray *keys, const nsStringArray *values, const PRUint32 aFlags)
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER NS_IMETHOD 
Start ()
NS_IMETHOD End ()
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Protected Member Functions

NS_IMETHOD NotifyWebShell (nsISupports *aWebShell, nsISupports *aChannel, const char *charset, PRInt32 source)

Private Member Functions

NS_IMETHOD Notify (PRUint32 aDocumentID, PRUint32 numOfAttributes, const PRUnichar *nameArray[], const PRUnichar *valueArray[])

Private Attributes

PRBool bXMLEncodingObserverStarted

Detailed Description

Definition at line 48 of file nsXMLEncodingObserver.h.


Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
IS_DOCUMENT_WRITE 

Definition at line 63 of file nsIElementObserver.h.


Constructor & Destructor Documentation

Definition at line 68 of file nsXMLEncodingObserver.cpp.

{
  // call to end the ObserverService
  if (bXMLEncodingObserverStarted == PR_TRUE) {
    End();
  }
}

Here is the call graph for this function:


Member Function Documentation

Implements nsIXMLEncodingService.

Definition at line 217 of file nsXMLEncodingObserver.cpp.

{
    nsresult res = NS_OK;
    
    if (bXMLEncodingObserverStarted == PR_FALSE) 
      return res;

    nsCOMPtr<nsIObserverService> anObserverService = do_GetService("@mozilla.org/observer-service;1", &res);
    if (NS_SUCCEEDED(res)) {
      res = anObserverService->RemoveObserver(this, "xmlparser");

      bXMLEncodingObserverStarted = PR_FALSE;
    }

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsXMLEncodingObserver::Notify ( PRUint32  aDocumentID,
eHTMLTags  aTag,
PRUint32  numOfAttributes,
const PRUnichar nameArray[],
const PRUnichar valueArray[] 
) [virtual]

Implements nsIElementObserver.

Definition at line 101 of file nsXMLEncodingObserver.cpp.

{
    if(eHTMLTag_meta != aTag) 
        return NS_ERROR_ILLEGAL_VALUE;
    else 
        return Notify(aDocumentID, numOfAttributes, nameArray, valueArray);
}
NS_IMETHOD nsXMLEncodingObserver::Notify ( PRUint32  aDocumentID,
const PRUnichar aTag,
PRUint32  numOfAttributes,
const PRUnichar nameArray[],
const PRUnichar valueArray[] 
) [virtual]

Implements nsIElementObserver.

NS_IMETHOD nsXMLEncodingObserver::Notify ( nsISupports *  aWebShell,
nsISupports *  aChannel,
const PRUnichar aTag,
const nsStringArray *  keys,
const nsStringArray *  values,
const PRUint32  aFlags 
) [inline, virtual]

Implements nsIElementObserver.

Definition at line 71 of file nsXMLEncodingObserver.h.

NS_IMETHODIMP nsXMLEncodingObserver::Notify ( PRUint32  aDocumentID,
PRUint32  numOfAttributes,
const PRUnichar nameArray[],
const PRUnichar valueArray[] 
) [private]

Definition at line 114 of file nsXMLEncodingObserver.cpp.

{

    nsresult res = NS_OK;
    PRUint32 i;

    if(numOfAttributes >= 3)
    {
      PRBool bGotCurrentCharset=PR_FALSE;
      PRBool bGotCurrentCharsetSource = PR_FALSE;
      PRBool bGotEncoding = PR_FALSE;

      nsCAutoString currentCharset(NS_LITERAL_CSTRING("unknown"));
      nsAutoString charsetSourceStr(NS_LITERAL_STRING("unknown"));
      nsCAutoString encoding(NS_LITERAL_CSTRING("unknown"));

      for(i=0; i < numOfAttributes; i++) 
      {
         if(0==nsCRT::strcmp(nameArray[i], NS_LITERAL_STRING("charset").get())) 
         {
           bGotCurrentCharset = PR_TRUE;
           CopyUCS2toASCII(nsDependentString(valueArray[i]), currentCharset);
         } else if(0==nsCRT::strcmp(nameArray[i], NS_LITERAL_STRING("charsetSource").get())) {
           bGotCurrentCharsetSource = PR_TRUE;
           charsetSourceStr = valueArray[i];
         } else if(nsDependentString(nameArray[i]).LowerCaseEqualsLiteral("encoding")) { 
           bGotEncoding = PR_TRUE;
           CopyUCS2toASCII(nsDependentString(valueArray[i]), encoding);
         }
      }

      // if we cannot find currentCharset or currentCharsetSource
      // return error.
      if( ! (bGotCurrentCharset && bGotCurrentCharsetSource))
      {
         return NS_ERROR_ILLEGAL_VALUE;
      }

      PRInt32 err;
      PRInt32 charsetSourceInt = charsetSourceStr.ToInteger(&err);

      // if we cannot convert the string into PRInt32, return error
      if(NS_FAILED(err))
         return NS_ERROR_ILLEGAL_VALUE;

      PRInt32 currentCharsetSource = charsetSourceInt;

      if(kCharsetFromMetaTag > currentCharsetSource)
      {
           if(! encoding.Equals(currentCharset)) 
           {
              nsCOMPtr<nsICharsetAlias> calias = do_GetService(kCharsetAliasCID, &res);
               if(NS_SUCCEEDED(res) && (nsnull != calias) ) 
               {
                    PRBool same = PR_FALSE;
                    res = calias->Equals( encoding, currentCharset, &same);
                    if(NS_SUCCEEDED(res) && (! same))
                    {
                          nsCAutoString preferred;
                          res = calias->GetPreferred(encoding,
                                                     preferred);
                          if(NS_SUCCEEDED(res))
                          {
                            res = NotifyWebShell(0,0, preferred.get(), kCharsetFromMetaTag );
                            return res;
                          } // if check for GetPreferred
                    } // if check res for Equals
                } // if check res for GetService
            } // if Equals
       } // if 
    } // if 

    return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsObserverBase::NotifyWebShell ( nsISupports *  aWebShell,
nsISupports *  aChannel,
const char *  charset,
PRInt32  source 
) [protected, inherited]

Definition at line 49 of file nsObserverBase.cpp.

{

   nsresult rv  = NS_OK;
   nsresult res = NS_OK;

   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel,&res));
   if (NS_SUCCEEDED(res)) {
     nsCAutoString method;
     httpChannel->GetRequestMethod(method);
     if (method.EqualsLiteral("POST")) { // XXX What about PUT, etc?
       return NS_OK;
     }
   }

   nsCOMPtr<nsIWebShellServices> wss;
   wss = do_QueryInterface(aWebShell,&res);
   if (NS_SUCCEEDED(res)) {

#ifndef DONT_INFORM_WEBSHELL
     // ask the webshellservice to load the URL
     if (NS_FAILED( res = wss->SetRendering(PR_FALSE) ))
       rv = res;

     // XXX nisheeth, uncomment the following two line to see the reent problem

     else if (NS_FAILED(res = wss->StopDocumentLoad())){
             rv = wss->SetRendering(PR_TRUE); // turn on the rendering so at least we will see something.
     }
     else if (NS_FAILED(res = wss->ReloadDocument(charset, source))) {
             rv = wss->SetRendering(PR_TRUE); // turn on the rendering so at least we will see something.
     }
     else {
       rv = NS_ERROR_HTMLPARSER_STOPPARSING; // We're reloading a new document...stop loading the current.
     }
#endif
   }

   //if our reload request is not accepted, we should tell parser to go on
  if (rv != NS_ERROR_HTMLPARSER_STOPPARSING) 
    rv = NS_ERROR_HTMLPARSER_CONTINUE;

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Implements nsIXMLEncodingService.

Definition at line 199 of file nsXMLEncodingObserver.cpp.

{
    nsresult res = NS_OK;

    if (bXMLEncodingObserverStarted == PR_TRUE) 
      return res;

    nsCOMPtr<nsIObserverService> anObserverService = do_GetService("@mozilla.org/observer-service;1", &res);

    if (NS_SUCCEEDED(res)) {
      res = anObserverService->AddObserver(this, "xmlparser", PR_TRUE);

      bXMLEncodingObserverStarted = PR_TRUE;
    }

    return res;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 92 of file nsXMLEncodingObserver.h.


The documentation for this class was generated from the following files: