Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsXMLFragmentContentSink.cpp File Reference
#include "nsCOMPtr.h"
#include "nsXMLContentSink.h"
#include "nsIFragmentContentSink.h"
#include "nsIXMLContentSink.h"
#include "nsContentSink.h"
#include "nsIExpatSink.h"
#include "nsIParser.h"
#include "nsIDocument.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIXMLContent.h"
#include "nsHTMLAtoms.h"
#include "nsINodeInfo.h"
#include "nsNodeInfoManager.h"
#include "nsContentCreatorFunctions.h"
#include "nsDOMError.h"
#include "nsIConsoleService.h"
#include "nsServiceManagerUtils.h"
#include "nsContentUtils.h"
#include "nsIScriptSecurityManager.h"
#include "nsNetUtil.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
#include "nsTArray.h"

Go to the source code of this file.

Classes

class  nsXMLFragmentContentSink
class  nsXHTMLParanoidFragmentSink

Functions

static nsresult NewXMLFragmentContentSinkHelper (PRBool aAllContent, nsIFragmentContentSink **aResult)
nsresult NS_NewXMLFragmentContentSink2 (nsIFragmentContentSink **aResult)
nsresult NS_NewXMLFragmentContentSink (nsIFragmentContentSink **aResult)
 NS_IMPL_ISUPPORTS_INHERITED1 (nsXMLFragmentContentSink, nsXMLContentSink, nsIFragmentContentSink) NS_IMETHODIMP nsXMLFragmentContentSink
nsresult NS_NewXHTMLParanoidFragmentSink (nsIFragmentContentSink **aResult)
void NS_XHTMLParanoidFragmentSinkShutdown ()
 NS_IMPL_ISUPPORTS_INHERITED0 (nsXHTMLParanoidFragmentSink, nsXMLFragmentContentSink) nsresult nsXHTMLParanoidFragmentSink

Function Documentation

static nsresult NewXMLFragmentContentSinkHelper ( PRBool  aAllContent,
nsIFragmentContentSink **  aResult 
) [static]

Definition at line 132 of file nsXMLFragmentContentSink.cpp.

{
  nsXMLFragmentContentSink* it = new nsXMLFragmentContentSink(aAllContent);
  if (!it) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  
  NS_ADDREF(*aResult = it);
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 570 of file nsXMLFragmentContentSink.cpp.

{
  nsresult rv;

  // use this to check for safe URIs in the few attributes that allow them
  nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
  nsCOMPtr<nsIURI> baseURI;
  PRUint32 flags = nsIScriptSecurityManager::DISALLOW_SCRIPT_OR_DATA;

  // scrub URI attributes that point at dangerous content
  // We have to do this here, because this is where we have a base URI,
  // but we can't do all the scrubbing here, because other parts of the
  // code get the attributes before this method is called.
  nsTArray<const PRUnichar *> allowedAttrs;
  PRInt32 nameSpaceID;
  nsCOMPtr<nsIAtom> prefix, localName;
  nsCOMPtr<nsINodeInfo> nodeInfo;
  while (*aAtts) {
    nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
                                   getter_AddRefs(localName), &nameSpaceID);
    rv = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID,
                                       getter_AddRefs(nodeInfo));
    NS_ENSURE_SUCCESS(rv, rv);
    // check the attributes we allow that contain URIs
    if (IsAttrURI(nodeInfo->NameAtom())) {
      if (!aAtts[1])
        rv = NS_ERROR_FAILURE;
      if (!baseURI)
        baseURI = aContent->GetBaseURI();
      nsCOMPtr<nsIURI> attrURI;
      rv = NS_NewURI(getter_AddRefs(attrURI), nsDependentString(aAtts[1]),
                     nsnull, baseURI);
      if (NS_SUCCEEDED(rv)) {
        rv = secMan->CheckLoadURIWithPrincipal(mTargetDocument->GetPrincipal(),
                                               attrURI, flags);
      }
    }

    if (NS_SUCCEEDED(rv)) {
      allowedAttrs.AppendElement(aAtts[0]);
      allowedAttrs.AppendElement(aAtts[1]);
    }

    aAtts += 2;
  }
  allowedAttrs.AppendElement((const PRUnichar*) nsnull);

  return nsXMLFragmentContentSink::AddAttributes(allowedAttrs.Elements(),
                                                 aContent);
}

Here is the call graph for this function:

Definition at line 165 of file nsXMLFragmentContentSink.cpp.

{
  if (mRoot) {
    return NS_OK;
  }

  mState = eXMLContentSinkState_InDocumentElement;

  NS_ASSERTION(mTargetDocument, "Need a document!");

  nsCOMPtr<nsIDOMDocumentFragment> frag;
  nsresult rv = NS_NewDocumentFragment(getter_AddRefs(frag), mNodeInfoManager);
  NS_ENSURE_SUCCESS(rv, rv);

  mRoot = do_QueryInterface(frag);
  
  if (mAllContent) {
    // Preload content stack because we know all content goes in the fragment
    PushContent(mRoot);
  }

  return rv;
}

Here is the call graph for this function:

Definition at line 551 of file nsXMLFragmentContentSink.cpp.

Here is the call graph for this function:

Definition at line 151 of file nsXMLFragmentContentSink.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 145 of file nsXMLFragmentContentSink.cpp.

Here is the call graph for this function:

Definition at line 565 of file nsXMLFragmentContentSink.cpp.

Here is the call graph for this function:

Here is the caller graph for this function: