Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsDOMSerializer.cpp File Reference
#include "nsDOMSerializer.h"
#include "nsIDOMNode.h"
#include "nsIDOMClassInfo.h"
#include "nsIOutputStream.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDocumentEncoder.h"
#include "nsIComponentManager.h"
#include "nsIContentSerializer.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsIURI.h"
#include "nsContentUtils.h"

Go to the source code of this file.

Functions

static NS_INTERFACE_MAP_END
nsresult 
SetUpEncoder (nsIDOMNode *aRoot, const nsACString &aCharset, nsIDocumentEncoder **aEncoder)
static nsresult CheckSameOrigin (nsIDOMNode *aRoot)

Function Documentation

static nsresult CheckSameOrigin ( nsIDOMNode aRoot) [static]

Definition at line 129 of file nsDOMSerializer.cpp.

{
  // Make sure that the caller has permission to access the root

  // Be sure to QI to either nsIContent or nsIDocument to make sure
  // we're passed a naitve object.

  nsCOMPtr<nsIContent> content(do_QueryInterface(aRoot));
  nsCOMPtr<nsIDocument> doc;

  if (content) {
    doc = content->GetOwnerDoc();

    if (!doc) {
      // Orphan node, permit access.

      return NS_OK;
    }
  } else {
    doc = do_QueryInterface(aRoot);

    if (!doc) {
      // We got a non-native object.

      return NS_ERROR_INVALID_POINTER;
    }
  }

  nsIPrincipal *principal = doc->GetPrincipal();

  if (principal) {
    nsresult rv;
    nsCOMPtr<nsIScriptSecurityManager> secMan = 
      do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    PRBool ubrEnabled = PR_FALSE;
    rv = secMan->IsCapabilityEnabled("UniversalBrowserRead", &ubrEnabled);
    NS_ENSURE_SUCCESS(rv, rv);

    if (ubrEnabled) {
      // UniversalBrowserRead is enabled (or we're not called from
      // script), permit access.
      return NS_OK;
    }

    nsCOMPtr<nsIPrincipal> subject;
    rv = secMan->GetSubjectPrincipal(getter_AddRefs(subject));
    NS_ENSURE_SUCCESS(rv, rv);

    // Since UBR is not enabled, we better have a subject principal,
    // but just in case...
    if (subject) {
      // Check if the caller is from the same origin that the root is from.
      return secMan->CheckSameOriginPrincipal(subject, principal);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

static NS_INTERFACE_MAP_END nsresult SetUpEncoder ( nsIDOMNode aRoot,
const nsACString &  aCharset,
nsIDocumentEncoder **  aEncoder 
) [static]

Definition at line 78 of file nsDOMSerializer.cpp.

{
  *aEncoder = nsnull;
   
  nsresult rv;
  nsCOMPtr<nsIDocumentEncoder> encoder =
    do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", &rv);
  if (NS_FAILED(rv))
    return rv;

  PRBool entireDocument = PR_TRUE;
  nsCOMPtr<nsIDocument> document(do_QueryInterface(aRoot));
  if (!document) {
    entireDocument = PR_FALSE;
    nsCOMPtr<nsIDOMDocument> domDoc;
    rv = aRoot->GetOwnerDocument(getter_AddRefs(domDoc));
    if (NS_FAILED(rv))
      return rv;
    document = do_QueryInterface(domDoc);
  }

  // This method will fail if no document
  rv = encoder->Init(document, NS_LITERAL_STRING("text/xml"),
                     nsIDocumentEncoder::OutputEncodeBasicEntities);
  if (NS_FAILED(rv))
    return rv;

  nsCAutoString charset(aCharset);
  if (charset.IsEmpty()) {
    charset = document->GetDocumentCharacterSet();
  }
  rv = encoder->SetCharset(charset);
  if (NS_FAILED(rv))
    return rv;

  // If we are working on the entire document we do not need to
  // specify which part to serialize
  if (!entireDocument) {
    rv = encoder->SetNode(aRoot);
  }

  if (NS_SUCCEEDED(rv)) {
    *aEncoder = encoder.get();
    NS_ADDREF(*aEncoder);
  }

  return rv;
}

Here is the call graph for this function: