Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
XULContentSinkImpl Class Reference
Inheritance diagram for XULContentSinkImpl:
Inheritance graph
[legend]
Collaboration diagram for XULContentSinkImpl:
Collaboration graph
[legend]

List of all members.

Classes

class  ContextStack

Public Types

enum  State { eInProlog, eInDocumentElement, eInScript, eInEpilog }

Public Member Functions

 XULContentSinkImpl (nsresult &aRV)
virtual ~XULContentSinkImpl ()
NS_DECL_ISUPPORTS
NS_DECL_NSIEXPATSINK
NS_IMETHOD 
WillBuildModel (void)
 This method gets called when the parser begins the process of building the content model via the content sink.
NS_IMETHOD DidBuildModel (void)
 This method gets called when the parser concludes the process of building the content model via the content sink.
NS_IMETHOD WillInterrupt (void)
 This method gets called when the parser gets i/o blocked, and wants to notify the sink that it may be a while before more data is available.
NS_IMETHOD WillResume (void)
 This method gets called when the parser i/o gets unblocked, and we're about to start dumping content again to the sink.
NS_IMETHOD SetParser (nsIParser *aParser)
 This method gets called by the parser so that the content sink can retain a reference to the parser.
virtual void FlushPendingNotifications (mozFlushType aType)
 Flush content so that the content model is in sync with the state of the sink.
NS_IMETHOD SetDocumentCharset (nsACString &aCharset)
 Set the document character set.
virtual nsISupports * GetTarget ()
 Returns the target object (often a document object) into which the content built by this content sink is being added, if any (IOW, may return null).
NS_IMETHOD Init (nsIDocument *aDocument, nsIXULPrototypeDocument *aPrototype)
 Initialize the content sink, giving it an nsIDocument object with which to communicate with the outside world, and an nsIXULPrototypeDocument to build.
void HandleStartElement (in wstring aName,[array, size_is(aAttsCount)] in wstring aAtts, in unsigned long aAttsCount, in long aIndex, in unsigned long aLineNumber)
 Called to handle the opening tag of an element.
void HandleEndElement (in wstring aName)
 Called to handle the closing tag of an element.
void HandleComment (in wstring aCommentText)
 Called to handle a comment.
void HandleCDataSection ([size_is(aLength)] in wstring aData, in unsigned long aLength)
 Called to handle a CDATA section.
void HandleDoctypeDecl (in AString aSubset, in AString aName, in AString aSystemId, in AString aPublicId, in nsISupports aCatalogData)
 Called to handle the doctype declaration.
void HandleCharacterData ([size_is(aLength)] in wstring aData, in unsigned long aLength)
 Called to handle character data.
void HandleProcessingInstruction (in wstring aTarget, in wstring aData)
 Called to handle a processing instruction.
void HandleXMLDeclaration (in wstring aVersion, in wstring aEncoding, in long aStandalone)
 Handle the XML Declaration.
void ReportError (in wstring aErrorText, in wstring aSourceText)

Protected Member Functions

nsresult AddAttributes (const PRUnichar **aAttributes, const PRUint32 aAttrLen, nsXULPrototypeElement *aElement)
nsresult OpenRoot (const PRUnichar **aAttributes, const PRUint32 aAttrLen, nsINodeInfo *aNodeInfo)
nsresult OpenTag (const PRUnichar **aAttributes, const PRUint32 aAttrLen, const PRUint32 aLineNumber, nsINodeInfo *aNodeInfo)
nsresult OpenScript (const PRUnichar **aAttributes, const PRUint32 aLineNumber)
nsresult FlushText (PRBool aCreateTextNode=PR_TRUE)
nsresult AddText (const PRUnichar *aText, PRInt32 aLength)
nsresult NormalizeAttributeString (const PRUnichar *aExpatName, nsAttrName &aName)
nsresult CreateElement (nsINodeInfo *aNodeInfo, nsXULPrototypeElement **aResult)
nsresult ProcessStyleLink (nsIContent *aElement, const nsString &aHref, PRBool aAlternate, const nsString &aTitle, const nsString &aType, const nsString &aMedia)

Static Protected Member Functions

static PRBool IsDataInBuffer (PRUnichar *aBuffer, PRInt32 aLength)

Protected Attributes

PRUnicharmText
PRInt32 mTextLength
PRInt32 mTextSize
PRBool mConstrainSize
nsRefPtr< nsNodeInfoManagermNodeInfoManager
State mState
ContextStack mContextStack
nsWeakPtr mDocument
nsCOMPtr< nsIURImDocumentURL
nsCOMPtr< nsIXULPrototypeDocumentmPrototype
nsIParsermParser
nsString mPreferredStyle
nsCOMPtr< nsICSSLoadermCSSLoader
nsCOMPtr< nsICSSParsermCSSParser
nsCOMPtr
< nsIScriptSecurityManager
mSecMan

Static Protected Attributes

static nsrefcnt gRefCnt
static nsIXULPrototypeCachegXULCache

Friends

class ContextStack

Detailed Description

Definition at line 119 of file nsXULContentSink.cpp.


Member Enumeration Documentation

Enumerator:
eInProlog 
eInDocumentElement 
eInScript 
eInEpilog 

Definition at line 194 of file nsXULContentSink.cpp.


Constructor & Destructor Documentation

Definition at line 318 of file nsXULContentSink.cpp.

    : mText(nsnull),
      mTextLength(0),
      mTextSize(0),
      mConstrainSize(PR_TRUE),
      mState(eInProlog),
      mParser(nsnull)
{

    if (gRefCnt++ == 0) {
        rv = CallGetService(kXULPrototypeCacheCID, &gXULCache);
    }

#ifdef PR_LOGGING
    if (! gLog)
        gLog = PR_NewLogModule("nsXULContentSink");
#endif

    rv = NS_OK;
}

Here is the call graph for this function:

Definition at line 340 of file nsXULContentSink.cpp.

{
    NS_IF_RELEASE(mParser); // XXX should've been released by now, unless error.

    // Pop all of the elements off of the context stack, and delete
    // any remaining content elements. The context stack _should_ be
    // empty, unless something has gone wrong.
    while (mContextStack.Depth()) {
        nsresult rv;

        nsVoidArray* children;
        rv = mContextStack.GetTopChildren(&children);
        if (NS_SUCCEEDED(rv)) {
            for (PRInt32 i = children->Count() - 1; i >= 0; --i) {
                nsXULPrototypeNode* child =
                    NS_REINTERPRET_CAST(nsXULPrototypeNode*, children->ElementAt(i));

                delete child;
            }
        }

        nsXULPrototypeNode* node;
        rv = mContextStack.GetTopNode(&node);
        if (NS_SUCCEEDED(rv)) delete node;

        State state;
        mContextStack.Pop(&state);
    }

    PR_FREEIF(mText);

    if (--gRefCnt == 0) {
        NS_IF_RELEASE(gXULCache);
    }
}

Here is the call graph for this function:


Member Function Documentation

nsresult XULContentSinkImpl::AddAttributes ( const PRUnichar **  aAttributes,
const PRUint32  aAttrLen,
nsXULPrototypeElement aElement 
) [protected]

Definition at line 1331 of file nsXULContentSink.cpp.

{
  // Add tag attributes to the element
  nsresult rv;

  // Create storage for the attributes
  nsXULPrototypeAttribute* attrs = nsnull;
  if (aAttrLen > 0) {
    attrs = new nsXULPrototypeAttribute[aAttrLen];
    if (! attrs)
      return NS_ERROR_OUT_OF_MEMORY;
  }

  aElement->mAttributes    = attrs;
  aElement->mNumAttributes = aAttrLen;

  // Copy the attributes into the prototype
  PRUint32 i;
  for (i = 0; i < aAttrLen; ++i) {
      rv = NormalizeAttributeString(aAttributes[i * 2], attrs[i].mName);
      NS_ENSURE_SUCCESS(rv, rv);

      rv = aElement->SetAttrAt(i, nsDependentString(aAttributes[i * 2 + 1]),
                               mDocumentURL);
      NS_ENSURE_SUCCESS(rv, rv);

#ifdef PR_LOGGING
      if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {
          nsAutoString extraWhiteSpace;
          PRInt32 cnt = mContextStack.Depth();
          while (--cnt >= 0)
              extraWhiteSpace.AppendLiteral("  ");
          nsAutoString qnameC,valueC;
          qnameC.Assign(aAttributes[0]);
          valueC.Assign(aAttributes[1]);
          PR_LOG(gLog, PR_LOG_DEBUG,
                 ("xul: %.5d. %s    %s=%s",
                  -1, // XXX pass in line number
                  NS_ConvertUCS2toUTF8(extraWhiteSpace).get(),
                  NS_ConvertUCS2toUTF8(qnameC).get(),
                  NS_ConvertUCS2toUTF8(valueC).get()));
      }
#endif
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XULContentSinkImpl::AddText ( const PRUnichar aText,
PRInt32  aLength 
) [protected]

Definition at line 1382 of file nsXULContentSink.cpp.

{
  // Create buffer when we first need it
  if (0 == mTextSize) {
      mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * 4096);
      if (nsnull == mText) {
          return NS_ERROR_OUT_OF_MEMORY;
      }
      mTextSize = 4096;
  }

  // Copy data from string into our buffer; flush buffer when it fills up
  PRInt32 offset = 0;
  while (0 != aLength) {
    PRInt32 amount = mTextSize - mTextLength;
    if (amount > aLength) {
        amount = aLength;
    }
    if (0 == amount) {
      if (mConstrainSize) {
        nsresult rv = FlushText();
        if (NS_OK != rv) {
            return rv;
        }
      }
      else {
        mTextSize += aLength;
        mText = (PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * mTextSize);
        if (nsnull == mText) {
            return NS_ERROR_OUT_OF_MEMORY;
        }
      }
    }
    memcpy(&mText[mTextLength],aText + offset, sizeof(PRUnichar) * amount);
    
    mTextLength += amount;
    offset += amount;
    aLength -= amount;
  }

  return NS_OK;
}

Here is the call graph for this function:

nsresult XULContentSinkImpl::CreateElement ( nsINodeInfo aNodeInfo,
nsXULPrototypeElement **  aResult 
) [protected]

Definition at line 674 of file nsXULContentSink.cpp.

{
    nsXULPrototypeElement* element = new nsXULPrototypeElement();
    if (! element)
        return NS_ERROR_OUT_OF_MEMORY;

    element->mNodeInfo    = aNodeInfo;
    
    *aResult = element;
    return NS_OK;
}

Here is the caller graph for this function:

This method gets called when the parser concludes the process of building the content model via the content sink.

5/7/98 gess

Implements nsIContentSink.

Definition at line 403 of file nsXULContentSink.cpp.

{
    nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
    if (doc) {
        doc->EndLoad();
        mDocument = nsnull;
    }

    // Drop our reference to the parser to get rid of a circular
    // reference.
    NS_IF_RELEASE(mParser);
    return NS_OK;
}

Here is the call graph for this function:

virtual void XULContentSinkImpl::FlushPendingNotifications ( mozFlushType  aType) [inline, virtual]

Flush content so that the content model is in sync with the state of the sink.

Parameters:
aTypethe type of flush to perform

Implements nsIContentSink.

Definition at line 136 of file nsXULContentSink.cpp.

{ }
nsresult XULContentSinkImpl::FlushText ( PRBool  aCreateTextNode = PR_TRUE) [protected]

Definition at line 588 of file nsXULContentSink.cpp.

{
    nsresult rv;

    do {
        // Don't do anything if there's no text to create a node from, or
        // if they've told us not to create a text node
        if (! mTextLength)
            break;

        if (! aCreateTextNode)
            break;

        nsXULPrototypeNode* node;
        rv = mContextStack.GetTopNode(&node);
        if (NS_FAILED(rv)) return rv;

        PRBool stripWhitespace = PR_FALSE;
        if (node->mType == nsXULPrototypeNode::eType_Element) {
            nsINodeInfo *nodeInfo =
                NS_STATIC_CAST(nsXULPrototypeElement*, node)->mNodeInfo;

            if (nodeInfo->NamespaceEquals(kNameSpaceID_XUL))
                stripWhitespace = !nodeInfo->Equals(nsXULAtoms::label) &&
                                  !nodeInfo->Equals(nsXULAtoms::description);
        }

        // Don't bother if there's nothing but whitespace.
        if (stripWhitespace && ! IsDataInBuffer(mText, mTextLength))
            break;

        // Don't bother if we're not in XUL document body
        if (mState != eInDocumentElement || mContextStack.Depth() == 0)
            break;

        nsXULPrototypeText* text = new nsXULPrototypeText();
        if (! text)
            return NS_ERROR_OUT_OF_MEMORY;

        text->mValue.Assign(mText, mTextLength);
        if (stripWhitespace)
            text->mValue.Trim(" \t\n\r");

        // hook it up
        nsVoidArray* children;
        rv = mContextStack.GetTopChildren(&children);
        if (NS_FAILED(rv)) return rv;

        // transfer ownership of 'text' to the children array
        children->AppendElement(text);
    } while (0);

    // Reset our text buffer
    mTextLength = 0;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsISupports * XULContentSinkImpl::GetTarget ( ) [virtual]

Returns the target object (often a document object) into which the content built by this content sink is being added, if any (IOW, may return null).

Implements nsIContentSink.

Definition at line 518 of file nsXULContentSink.cpp.

Here is the call graph for this function:

void nsIExpatSink::HandleCDataSection ( [size_is(aLength)] in wstring  aData,
in unsigned long  aLength 
) [inherited]

Called to handle a CDATA section.

Parameters:
aDatathe text in the CDATA section. This is null-terminated.
aLengththe length of the aData string
void nsIExpatSink::HandleCharacterData ( [size_is(aLength)] in wstring  aData,
in unsigned long  aLength 
) [inherited]

Called to handle character data.

Note that this does NOT get called for the contents of CDATA sections.

Parameters:
aDatathe data to handle. aData is NOT NULL-TERMINATED.
aLengththe length of the aData string
void nsIExpatSink::HandleComment ( in wstring  aCommentText) [inherited]

Called to handle a comment.

Parameters:
aCommentTextthe text of the comment (not including the "<!--" and "-->")
void nsIExpatSink::HandleDoctypeDecl ( in AString  aSubset,
in AString  aName,
in AString  aSystemId,
in AString  aPublicId,
in nsISupports  aCatalogData 
) [inherited]

Called to handle the doctype declaration.

void nsIExpatSink::HandleEndElement ( in wstring  aName) [inherited]

Called to handle the closing tag of an element.

Parameters:
aNamethe fully qualified tagname of the element
void nsIExpatSink::HandleProcessingInstruction ( in wstring  aTarget,
in wstring  aData 
) [inherited]

Called to handle a processing instruction.

Parameters:
aTargetthe PI target (e.g. xml-stylesheet)
aDataall the rest of the data in the PI
void nsIExpatSink::HandleStartElement ( in wstring  aName,
[array, size_is(aAttsCount)] in wstring  aAtts,
in unsigned long  aAttsCount,
in long  aIndex,
in unsigned long  aLineNumber 
) [inherited]

Called to handle the opening tag of an element.

Parameters:
aNamethe fully qualified tagname of the element
aAttsthe array of attribute names and values. There are aAttsCount/2 names and aAttsCount/2 values, so the total number of elements in the array is aAttsCount. The names and values alternate. Thus, if we number attributes starting with 0, aAtts[2*k] is the name of the k-th attribute and aAtts[2*k+1] is the value of that attribute Both explicitly specified attributes and attributes that are defined to have default values in a DTD are present in aAtts.
aAttsCountthe number of elements in aAtts.
aIndexIf the element has an attribute of type ID, then aAtts[aIndex] is the name of that attribute. Otherwise, aIndex is -1
aLineNumberthe line number of the start tag in the data stream.
void nsIExpatSink::HandleXMLDeclaration ( in wstring  aVersion,
in wstring  aEncoding,
in long  aStandalone 
) [inherited]

Handle the XML Declaration.

Parameters:
aVersionThe version string, can be null if not specified.
aEncodingThe encoding string, can be null if not specified.
aStandalone-1, 0, or 1 indicating respectively that there was no standalone parameter in the declaration, that it was given as no, or that it was given as yes.
NS_IMETHODIMP XULContentSinkImpl::Init ( nsIDocument aDocument,
nsIXULPrototypeDocument aPrototype 
) [virtual]

Initialize the content sink, giving it an nsIDocument object with which to communicate with the outside world, and an nsIXULPrototypeDocument to build.

Implements nsIXULContentSink.

Definition at line 530 of file nsXULContentSink.cpp.

{
    NS_PRECONDITION(aDocument != nsnull, "null ptr");
    if (! aDocument)
        return NS_ERROR_NULL_POINTER;
    
    nsresult rv;

    mDocument    = do_GetWeakReference(aDocument);
    mPrototype   = aPrototype;

    rv = mPrototype->GetURI(getter_AddRefs(mDocumentURL));
    if (NS_FAILED(rv)) return rv;

    // XXX this presumes HTTP header info is already set in document
    // XXX if it isn't we need to set it here...
    nsCOMPtr<nsIAtom> defaultStyle = do_GetAtom("default-style");
    if (! defaultStyle)
        return NS_ERROR_OUT_OF_MEMORY;

    rv = mPrototype->GetHeaderData(defaultStyle, mPreferredStyle);
    if (NS_FAILED(rv)) return rv;

    // Get the CSS loader from the document so we can load
    // stylesheets
    mCSSLoader = aDocument->CSSLoader();

    mNodeInfoManager = aPrototype->GetNodeInfoManager();
    if (! mNodeInfoManager)
        return NS_ERROR_UNEXPECTED;

    mState = eInProlog;
    return NS_OK;
}

Here is the call graph for this function:

PRBool XULContentSinkImpl::IsDataInBuffer ( PRUnichar aBuffer,
PRInt32  aLength 
) [static, protected]

Definition at line 572 of file nsXULContentSink.cpp.

{
    for (PRInt32 i = 0; i < length; ++i) {
        if (buffer[i] == ' ' ||
            buffer[i] == '\t' ||
            buffer[i] == '\n' ||
            buffer[i] == '\r')
            continue;

        return PR_TRUE;
    }
    return PR_FALSE;
}

Here is the caller graph for this function:

Definition at line 648 of file nsXULContentSink.cpp.

{
    PRInt32 nameSpaceID;
    nsCOMPtr<nsIAtom> prefix, localName;
    nsContentUtils::SplitExpatName(aExpatName, getter_AddRefs(prefix),
                                   getter_AddRefs(localName), &nameSpaceID);

    if (nameSpaceID == kNameSpaceID_None) {
        aName.SetTo(localName);

        return NS_OK;
    }

    nsCOMPtr<nsINodeInfo> ni;
    nsresult rv = mNodeInfoManager->GetNodeInfo(localName, prefix,
                                                nameSpaceID,
                                                getter_AddRefs(ni));
    NS_ENSURE_SUCCESS(rv, rv);

    aName.SetTo(ni);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XULContentSinkImpl::OpenRoot ( const PRUnichar **  aAttributes,
const PRUint32  aAttrLen,
nsINodeInfo aNodeInfo 
) [protected]

Definition at line 1051 of file nsXULContentSink.cpp.

{
    NS_ASSERTION(mState == eInProlog, "how'd we get here?");
    if (mState != eInProlog)
        return NS_ERROR_UNEXPECTED;

    nsresult rv;

    if (aNodeInfo->Equals(nsHTMLAtoms::script, kNameSpaceID_XHTML) || 
        aNodeInfo->Equals(nsHTMLAtoms::script, kNameSpaceID_XUL)) {
        PR_LOG(gLog, PR_LOG_ERROR,
               ("xul: script tag not allowed as root content element"));

        return NS_ERROR_UNEXPECTED;
    }

    // Create the element
    nsXULPrototypeElement* element;
    rv = CreateElement(aNodeInfo, &element);

    if (NS_FAILED(rv)) {
#ifdef PR_LOGGING
        if (PR_LOG_TEST(gLog, PR_LOG_ERROR)) {
            nsAutoString anodeC;
            aNodeInfo->GetName(anodeC);
            PR_LOG(gLog, PR_LOG_ERROR,
                   ("xul: unable to create element '%s' at line %d",
                    NS_ConvertUCS2toUTF8(anodeC).get(),
                    -1)); // XXX pass in line number
        }
#endif

        return rv;
    }

    // Push the element onto the context stack, so that child
    // containers will hook up to us as their parent.
    rv = mContextStack.Push(element, mState);
    if (NS_FAILED(rv)) {
        delete element;
        return rv;
    }

    // Add the attributes
    rv = AddAttributes(aAttributes, aAttrLen, element);
    if (NS_FAILED(rv)) return rv;

    mState = eInDocumentElement;
    return NS_OK;
}

Here is the call graph for this function:

nsresult XULContentSinkImpl::OpenScript ( const PRUnichar **  aAttributes,
const PRUint32  aLineNumber 
) [protected]

Definition at line 1162 of file nsXULContentSink.cpp.

{
  nsresult rv = NS_OK;
  PRBool isJavaScript = PR_TRUE;
  PRBool hasE4XOption = PR_TRUE;
  const char* jsVersionString = nsnull;

  // Look for SRC attribute and look for a LANGUAGE attribute
  nsAutoString src;
  while (*aAttributes) {
      const nsDependentString key(aAttributes[0]);
      if (key.EqualsLiteral("src")) {
          src.Assign(aAttributes[1]);
      }
      else if (key.EqualsLiteral("type")) {
          nsCOMPtr<nsIMIMEHeaderParam> mimeHdrParser =
              do_GetService("@mozilla.org/network/mime-hdrparam;1");
          NS_ENSURE_TRUE(mimeHdrParser, NS_ERROR_FAILURE);

          NS_ConvertUTF16toUTF8 typeAndParams(aAttributes[1]);

          nsAutoString mimeType;
          rv = mimeHdrParser->GetParameter(typeAndParams, nsnull,
                                           EmptyCString(), PR_FALSE, nsnull,
                                           mimeType);
          NS_ENSURE_SUCCESS(rv, rv);

          // Table ordered from most to least likely JS MIME types. For .xul
          // files that we host, the likeliest type is application/x-javascript.
          // See bug 62485, feel free to add <script type="..."> survey data to it,
          // or to a new bug once 62485 is closed.
          static const char *jsTypes[] = {
              "application/x-javascript",
              "text/javascript",
              "text/ecmascript",
              "application/javascript",
              "application/ecmascript",
              nsnull
          };

          isJavaScript = PR_FALSE;
          for (PRInt32 i = 0; jsTypes[i]; i++) {
              if (mimeType.LowerCaseEqualsASCII(jsTypes[i])) {
                  isJavaScript = PR_TRUE;
                  break;
              }
          }

          if (isJavaScript) {
              JSVersion jsVersion = JSVERSION_DEFAULT;
              nsAutoString value;
              rv = mimeHdrParser->GetParameter(typeAndParams, "version",
                                               EmptyCString(), PR_FALSE, nsnull,
                                               value);
              if (NS_FAILED(rv)) {
                  if (rv != NS_ERROR_INVALID_ARG)
                      return rv;
              } else {
                  if (value.Length() != 3 || value[0] != '1' || value[1] != '.')
                      jsVersion = JSVERSION_UNKNOWN;
                  else switch (value[2]) {
                      case '0': jsVersion = JSVERSION_1_0; break;
                      case '1': jsVersion = JSVERSION_1_1; break;
                      case '2': jsVersion = JSVERSION_1_2; break;
                      case '3': jsVersion = JSVERSION_1_3; break;
                      case '4': jsVersion = JSVERSION_1_4; break;
                      case '5': jsVersion = JSVERSION_1_5; break;
                      case '6': jsVersion = JSVERSION_1_6; break;
                      case '7': jsVersion = JSVERSION_1_7; break;
                      default:  jsVersion = JSVERSION_UNKNOWN;
                  }
              }
              jsVersionString = ::JS_VersionToString(jsVersion);

              rv = mimeHdrParser->GetParameter(typeAndParams, "e4x",
                                               EmptyCString(), PR_FALSE, nsnull,
                                               value);
              if (NS_FAILED(rv)) {
                  if (rv != NS_ERROR_INVALID_ARG)
                      return rv;
              } else {
                  if (value.Length() == 1 && value[0] == '0')
                      hasE4XOption = PR_FALSE;
              }
          }
      }
      else if (key.EqualsLiteral("language")) {
          nsAutoString lang(aAttributes[1]);
          isJavaScript =
              nsParserUtils::IsJavaScriptLanguage(lang, &jsVersionString);
      }
      aAttributes += 2;
  }

  // Don't process scripts that aren't JavaScript
  if (isJavaScript) {
      nsXULPrototypeScript* script =
          new nsXULPrototypeScript(aLineNumber, jsVersionString, hasE4XOption,
                                   &rv);
      if (! script)
          return NS_ERROR_OUT_OF_MEMORY;
      if (NS_FAILED(rv)) {
          delete script;
          return rv;
      }      

      // If there is a SRC attribute...
      if (! src.IsEmpty()) {
          // Use the SRC attribute value to load the URL
          rv = NS_NewURI(getter_AddRefs(script->mSrcURI), src, nsnull, mDocumentURL);

          // Check if this document is allowed to load a script from this source
          // NOTE: if we ever allow scripts added via the DOM to run, we need to
          // add a CheckLoadURI call for that as well.
          if (NS_SUCCEEDED(rv)) {
              if (!mSecMan)
                  mSecMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
              if (NS_SUCCEEDED(rv)) {
                  nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument, &rv);

                  if (NS_SUCCEEDED(rv)) {
                      rv = mSecMan->
                          CheckLoadURIWithPrincipal(doc->GetPrincipal(),
                                                    script->mSrcURI,
                                                    nsIScriptSecurityManager::ALLOW_CHROME);
                  }
              }
          }

          if (NS_FAILED(rv)) {
              delete script;
              return rv;
          }

          // Attempt to deserialize an out-of-line script from the FastLoad
          // file right away.  Otherwise we'll end up reloading the script and
          // corrupting the FastLoad file trying to serialize it, in the case
          // where it's already there.
          nsCOMPtr<nsIDocument> doc(do_QueryReferent(mDocument));
          if (doc) {
              nsIScriptGlobalObject* globalObject = doc->GetScriptGlobalObject();
              if (globalObject) {
                  nsIScriptContext *scriptContext = globalObject->GetContext();
                  if (scriptContext)
                      script->DeserializeOutOfLine(nsnull, scriptContext);
              }
          }
      }

      nsVoidArray* children;
      rv = mContextStack.GetTopChildren(&children);
      if (NS_FAILED(rv)) {
          delete script;
          return rv;
      }

      children->AppendElement(script);

      mConstrainSize = PR_FALSE;

      mContextStack.Push(script, mState);
      mState = eInScript;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult XULContentSinkImpl::OpenTag ( const PRUnichar **  aAttributes,
const PRUint32  aAttrLen,
const PRUint32  aLineNumber,
nsINodeInfo aNodeInfo 
) [protected]

Definition at line 1105 of file nsXULContentSink.cpp.

{
    nsresult rv;

    // Create the element
    nsXULPrototypeElement* element;
    rv = CreateElement(aNodeInfo, &element);

    if (NS_FAILED(rv)) {
#ifdef PR_LOGGING
        if (PR_LOG_TEST(gLog, PR_LOG_ERROR)) {
            nsAutoString anodeC;
            aNodeInfo->GetName(anodeC);
            PR_LOG(gLog, PR_LOG_ERROR,
                   ("xul: unable to create element '%s' at line %d",
                    NS_ConvertUCS2toUTF8(anodeC).get(),
                    aLineNumber));
        }
#endif

        return rv;
    }

    // Link this element to its parent.
    nsVoidArray* children;
    rv = mContextStack.GetTopChildren(&children);
    if (NS_FAILED(rv)) {
        delete element;
        return rv;
    }

    // Add the attributes
    rv = AddAttributes(aAttributes, aAttrLen, element);
    if (NS_FAILED(rv)) return rv;

    children->AppendElement(element);

    if (aNodeInfo->Equals(nsHTMLAtoms::script, kNameSpaceID_XHTML) || 
        aNodeInfo->Equals(nsHTMLAtoms::script, kNameSpaceID_XUL)) {
        // Do scripty things now.  OpenScript will push the
        // nsPrototypeScriptElement onto the stack, so we're done after this.
        return OpenScript(aAttributes, aLineNumber);
    }

    // Push the element onto the context stack, so that child
    // containers will hook up to us as their parent.
    rv = mContextStack.Push(element, mState);
    if (NS_FAILED(rv)) return rv;

    mState = eInDocumentElement;
    return NS_OK;
}

Here is the call graph for this function:

nsresult XULContentSinkImpl::ProcessStyleLink ( nsIContent aElement,
const nsString aHref,
PRBool  aAlternate,
const nsString aTitle,
const nsString aType,
const nsString aMedia 
) [protected]

Definition at line 441 of file nsXULContentSink.cpp.

{
    static const char kCSSType[] = "text/css";

    nsresult rv = NS_OK;

    if (aAlternate) { // if alternate, does it have title?
        if (aTitle.IsEmpty()) { // alternates must have title
            return NS_OK; //return without error, for now
        }
    }

    nsAutoString mimeType;
    nsAutoString params;
    nsParserUtils::SplitMimeType(aType, mimeType, params);

    if ((mimeType.IsEmpty()) || mimeType.EqualsIgnoreCase(kCSSType)) {
        nsCOMPtr<nsIURI> url;
        rv = NS_NewURI(getter_AddRefs(url), aHref, nsnull, mDocumentURL);
        if (NS_OK != rv) {
            return NS_OK; // The URL is bad, move along, don't propagate the error (for now)
        }

        // Add the style sheet reference to the prototype
        mPrototype->AddStyleSheetReference(url);

        // Nope, we need to load it asynchronously
        PRBool blockParser = PR_FALSE;
        if (! aAlternate) {
            if (!aTitle.IsEmpty()) {  // possibly preferred sheet
                if (mPreferredStyle.IsEmpty()) {
                    mPreferredStyle = aTitle;
                    mCSSLoader->SetPreferredSheet(aTitle);
                    nsCOMPtr<nsIAtom> defaultStyle = do_GetAtom("default-style");
                    if (defaultStyle) {
                        mPrototype->SetHeaderData(defaultStyle, aTitle);
                    }
                }
            }
            else {  // persistent sheet, block
                blockParser = PR_TRUE;
            }
        }

        nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
        if (! doc)
            return NS_ERROR_FAILURE; // doc went away!

        PRBool doneLoading;
        rv = mCSSLoader->LoadStyleLink(aElement, url, aTitle, aMedia,
                                       ((blockParser) ? mParser : nsnull),
                                       doneLoading, nsnull);
        if (NS_SUCCEEDED(rv) && blockParser && (! doneLoading)) {
          rv = NS_ERROR_HTMLPARSER_BLOCK;
        }
    }

    return rv;
}

Here is the call graph for this function:

void nsIExpatSink::ReportError ( in wstring  aErrorText,
in wstring  aSourceText 
) [inherited]
NS_IMETHODIMP XULContentSinkImpl::SetDocumentCharset ( nsACString &  aCharset) [virtual]

Set the document character set.

This should be passed on to the document itself.

Implements nsIContentSink.

Definition at line 507 of file nsXULContentSink.cpp.

{
    nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
    if (doc) {
        doc->SetDocumentCharacterSet(aCharset);
    }
  
    return NS_OK;
}

Here is the call graph for this function:

This method gets called by the parser so that the content sink can retain a reference to the parser.

The expectation is that the content sink will drop the reference when it gets the DidBuildModel notification i.e. when parsing is done.

Implements nsIContentSink.

Definition at line 432 of file nsXULContentSink.cpp.

This method gets called when the parser begins the process of building the content model via the content sink.

5/7/98 gess

Implements nsIContentSink.

This method gets called when the parser gets i/o blocked, and wants to notify the sink that it may be a while before more data is available.

5/7/98 gess

Implements nsIContentSink.

Definition at line 418 of file nsXULContentSink.cpp.

{
    // XXX Notify the docshell, if necessary
    return NS_OK;
}

This method gets called when the parser i/o gets unblocked, and we're about to start dumping content again to the sink.

5/7/98 gess

Implements nsIContentSink.

Definition at line 425 of file nsXULContentSink.cpp.

{
    // XXX Notify the docshell, if necessary
    return NS_OK;
}

Friends And Related Function Documentation

friend class ContextStack [friend]

Definition at line 226 of file nsXULContentSink.cpp.


Member Data Documentation

Definition at line 145 of file nsXULContentSink.cpp.

Definition at line 146 of file nsXULContentSink.cpp.

Definition at line 151 of file nsXULContentSink.cpp.

Definition at line 227 of file nsXULContentSink.cpp.

Definition at line 236 of file nsXULContentSink.cpp.

Definition at line 237 of file nsXULContentSink.cpp.

Definition at line 229 of file nsXULContentSink.cpp.

Definition at line 230 of file nsXULContentSink.cpp.

Definition at line 177 of file nsXULContentSink.cpp.

Definition at line 233 of file nsXULContentSink.cpp.

Definition at line 235 of file nsXULContentSink.cpp.

Definition at line 232 of file nsXULContentSink.cpp.

Definition at line 238 of file nsXULContentSink.cpp.

Definition at line 197 of file nsXULContentSink.cpp.

Definition at line 148 of file nsXULContentSink.cpp.

Definition at line 149 of file nsXULContentSink.cpp.

Definition at line 150 of file nsXULContentSink.cpp.


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