Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Static Public Member Functions | Static Private Member Functions | Static Private Attributes
nsContentUtils Class Reference

#include <nsContentUtils.h>

Collaboration diagram for nsContentUtils:
Collaboration graph
[legend]

List of all members.

Public Types

enum  PropertiesFile {
  eCSS_PROPERTIES, eXBL_PROPERTIES, eXUL_PROPERTIES, eLAYOUT_PROPERTIES,
  eFORMS_PROPERTIES, ePRINTING_PROPERTIES, eDOM_PROPERTIES, eBRAND_PROPERTIES,
  PropertiesFile_COUNT
}
 Report a localized error message to the error console. More...

Static Public Member Functions

static nsresult Init ()
static nsresult ReparentContentWrapper (nsIContent *aContent, nsIContent *aNewParent, nsIDocument *aNewDocument, nsIDocument *aOldDocument)
static nsresult ReparentContentWrappersInScope (nsIScriptGlobalObject *aOldScope, nsIScriptGlobalObject *aNewScope)
 When a document's scope changes (e.g., from document.open(), call this function to move all content wrappers from the old scope to the new one.
static PRBool IsCallerChrome ()
static PRBool IsCallerTrustedForRead ()
static PRBool IsCallerTrustedForWrite ()
static PRBool IsCallerTrustedForCapability (const char *aCapability)
 Check whether a caller is trusted to have aCapability.
static PRBool InSameDoc (nsIDOMNode *aNode, nsIDOMNode *aOther)
static PRBool ContentIsDescendantOf (nsIContent *aPossibleDescendant, nsIContent *aPossibleAncestor)
 Do not ever pass null pointers to this method.
static nsresult GetAncestors (nsIDOMNode *aNode, nsVoidArray *aArray)
static nsresult GetAncestorsAndOffsets (nsIDOMNode *aNode, PRInt32 aOffset, nsVoidArray *aAncestorNodes, nsVoidArray *aAncestorOffsets)
static nsresult GetCommonAncestor (nsIDOMNode *aNode, nsIDOMNode *aOther, nsIDOMNode **aCommonAncestor)
static nsresult GetFirstDifferentAncestors (nsIDOMNode *aNode, nsIDOMNode *aOther, nsCOMArray< nsIDOMNode > &aDifferentNodes)
static PRUint16 ComparePositionWithAncestors (nsIDOMNode *aNode, nsIDOMNode *aOther)
 Compares the document position of nodes which may have parents.
static PRUint16 ReverseDocumentPosition (PRUint16 aDocumentPosition)
 Reverses the document position flags passed in.
static PRUint32 CopyNewlineNormalizedUnicodeTo (const nsAString &aSource, PRUint32 aSrcOffset, PRUnichar *aDest, PRUint32 aLength, PRBool &aLastCharCR)
static PRUint32 CopyNewlineNormalizedUnicodeTo (nsReadingIterator< PRUnichar > &aSrcStart, const nsReadingIterator< PRUnichar > &aSrcEnd, nsAString &aDest)
static nsISupports * GetClassInfoInstance (nsDOMClassInfoID aID)
static const nsDependentSubstring TrimCharsInSet (const char *aSet, const nsAString &aValue)
 This method strips leading/trailing chars, in given set, from string.
static const nsDependentSubstring TrimWhitespace (const nsAString &aStr, PRBool aTrimTrailing=PR_TRUE)
 This method strips leading and trailing whitespace from a string.
static void Shutdown ()
static nsresult CheckSameOrigin (nsIDOMNode *aTrustedNode, nsIDOMNode *aUnTrustedNode)
 Checks whether two nodes come from the same origin.
static PRBool CanCallerAccess (nsIDOMNode *aNode)
static PRBool CanCallerAccess (nsPIDOMWindow *aWindow)
static nsIDocShellGetDocShellFromCaller ()
 Get the docshell through the JS context that's currently on the stack.
static nsIDOMDocumentGetDocumentFromCaller ()
 The two GetDocumentFrom* functions below allow a caller to get at a document that is relevant to the currently executing script.
static nsIDOMDocumentGetDocumentFromContext ()
 Get the document through the JS context that's currently on the stack.
static PRBool InProlog (nsIDOMNode *aNode)
static nsIParserServiceGetParserServiceWeakRef ()
 Access a cached parser service.
static nsINameSpaceManagerGetNSManagerWeakRef ()
static nsIIOServiceGetIOServiceWeakRef ()
static imgILoaderGetImgLoader ()
static nsIScriptSecurityManagerGetSecurityManager ()
static nsresult GenerateStateKey (nsIContent *aContent, nsIDocument *aDocument, nsIStatefulFrame::SpecialStateID aID, nsACString &aKey)
static nsresult NewURIWithDocumentCharset (nsIURI **aResult, const nsAString &aSpec, nsIDocument *aDocument, nsIURI *aBaseURI)
 Create a new nsIURI from aSpec, using aBaseURI as the base.
static PRBool BelongsInForm (nsIDOMHTMLFormElement *aForm, nsIContent *aContent)
 Determine whether aContent is in some way associated with aForm.
static nsresult CheckQName (const nsAString &aQualifiedName, PRBool aNamespaceAware=PR_TRUE)
static nsresult SplitQName (nsIContent *aNamespaceResolver, const nsAFlatString &aQName, PRInt32 *aNamespace, nsIAtom **aLocalName)
static nsresult LookupNamespaceURI (nsIContent *aNamespaceResolver, const nsAString &aNamespacePrefix, nsAString &aNamespaceURI)
static nsresult GetNodeInfoFromQName (const nsAString &aNamespaceURI, const nsAString &aQualifiedName, nsNodeInfoManager *aNodeInfoManager, nsINodeInfo **aNodeInfo)
static void SplitExpatName (const PRUnichar *aExpatName, nsIAtom **aPrefix, nsIAtom **aTagName, PRInt32 *aNameSpaceID)
static nsAdoptingCString GetCharPref (const char *aPref)
static PRPackedBool GetBoolPref (const char *aPref, PRBool aDefault=PR_FALSE)
static PRInt32 GetIntPref (const char *aPref, PRInt32 aDefault=0)
static nsAdoptingString GetLocalizedStringPref (const char *aPref)
static nsAdoptingString GetStringPref (const char *aPref)
static void RegisterPrefCallback (const char *aPref, PrefChangedFunc aCallback, void *aClosure)
static void UnregisterPrefCallback (const char *aPref, PrefChangedFunc aCallback, void *aClosure)
static nsIPrefBranchGetPrefBranch ()
static nsresult GetDocumentAndPrincipal (nsIDOMNode *aNode, nsIDocument **aDocument, nsIPrincipal **aPrincipal)
static PRBool CanLoadImage (nsIURI *aURI, nsISupports *aContext, nsIDocument *aLoadingDocument, PRInt16 *aImageBlockingStatus=nsnull)
 Method to do security and content policy checks on the image URI.
static nsresult LoadImage (nsIURI *aURI, nsIDocument *aLoadingDocument, nsIURI *aReferrer, imgIDecoderObserver *aObserver, PRInt32 aLoadFlags, imgIRequest **aRequest)
 Method to start an image load.
static already_AddRefed< nsIImageGetImageFromContent (nsIImageLoadingContent *aContent, imgIRequest **aRequest=nsnull)
 Method to get an nsIImage from an image loading content.
static PRBool ContentIsDraggable (nsIContent *aContent)
 Method that decides whether a content node is draggable.
static PRBool IsDraggableImage (nsIContent *aContent)
 Method that decides whether a content node is a draggable image.
static PRBool IsDraggableLink (nsIContent *aContent)
 Method that decides whether a content node is a draggable link.
static already_AddRefed< nsIURIGetLinkURI (nsIContent *aContent)
 Method that gets the URI of the link content.
static already_AddRefed< nsIURIGetXLinkURI (nsIContent *aContent)
 Method that gets the XLink uri for a content node, if it's an XLink.
static nsresult NameChanged (nsINodeInfo *aNodeInfo, nsIAtom *aName, nsINodeInfo **aResult)
 Convenience method to create a new nodeinfo that differs only by name from aNodeInfo.
static nsresult PrefixChanged (nsINodeInfo *aNodeInfo, nsIAtom *aPrefix, nsINodeInfo **aResult)
 Convenience method to create a new nodeinfo that differs only by prefix from aNodeInfo.
static nsIDocumentGetDocument (nsINodeInfo *aNodeInfo)
 Retrieve a pointer to the document that owns aNodeInfo.
static const char * GetEventArgName (PRInt32 aNameSpaceID)
 Returns the appropriate event argument name for the specified namespace.
static nsIXPConnectXPConnect ()
 Return the nsIXPConnect service.
static nsresult ReportToConsole (PropertiesFile aFile, const char *aMessageName, const PRUnichar **aParams, PRUint32 aParamsLength, nsIURI *aURI, const nsAFlatString &aSourceLine, PRUint32 aLineNumber, PRUint32 aColumnNumber, PRUint32 aErrorFlags, const char *aCategory)
static nsresult GetLocalizedString (PropertiesFile aFile, const char *aKey, nsXPIDLString &aResult)
 Get the localized string named |aKey| in properties file |aFile|.
static nsresult FormatLocalizedString (PropertiesFile aFile, const char *aKey, const PRUnichar **aParams, PRUint32 aParamsLength, nsXPIDLString &aResult)
 Fill (with the parameters given) the localized string named |aKey| in properties file |aFile|.
static already_AddRefed
< nsContentList
GetFormControlElements (nsIDocument *aDocument)
 Returns a list containing all elements in the document that are of type nsIContent::eHTML_FORM_CONTROL.
static PRBool IsChromeDoc (nsIDocument *aDocument)
 Returns true if aDocument is a chrome document.
static void NotifyXPCIfExceptionPending (JSContext *aCx)
 Notify XPConnect if an exception is pending on aCx.
static nsresult ReleasePtrOnShutdown (nsISupports **aSupportsPtr)
 Release *aSupportsPtr when the shutdown notification is received.
static nsresult AddJSGCRoot (jsval *aPtr, const char *aName)
 Make sure that whatever value *aPtr contains at any given moment is protected from JS GC until we remove the GC root.
static nsresult AddJSGCRoot (JSObject **aPtr, const char *aName)
 Make sure that whatever object *aPtr is pointing to at any given moment is protected from JS GC until we remove the GC root.
static nsresult AddJSGCRoot (void *aPtr, const char *aName)
 Make sure that whatever object *aPtr is pointing to at any given moment is protected from JS GC until we remove the GC root.
static nsresult RemoveJSGCRoot (jsval *aPtr)
 Remove aPtr as a JS GC root.
static nsresult RemoveJSGCRoot (JSObject **aPtr)
static nsresult RemoveJSGCRoot (void *aPtr)
static PRBool IsNativeAnonymous (nsIContent *aContent)

Static Private Member Functions

static nsresult doReparentContentWrapper (nsIContent *aChild, JSContext *cx, JSObject *aOldGlobal, JSObject *aNewGlobal)
static nsresult EnsureStringBundle (PropertiesFile aFile)

Static Private Attributes

static nsIDOMScriptObjectFactorysDOMScriptObjectFactory = nsnull
static nsIXPConnectsXPConnect = nsnull
static nsIScriptSecurityManagersSecurityManager = nsnull
static nsIThreadJSContextStacksThreadJSContextStack = nsnull
static nsIParserServicesParserService = nsnull
static nsINameSpaceManagersNameSpaceManager = nsnull
static nsIIOServicesIOService = nsnull
static nsIPrefBranchsPrefBranch = nsnull
static nsIPrefsPref = nsnull
static imgILoadersImgLoader = nsnull
static nsIConsoleServicesConsoleService
static nsIStringBundleServicesStringBundleService
static nsIStringBundlesStringBundles [PropertiesFile_COUNT]
static nsVoidArraysPtrsToPtrsToRelease
static nsIJSRuntimeServicesJSRuntimeService
static JSRuntimesScriptRuntime
static PRInt32 sScriptRootCount = 0
static PRBool sInitialized = PR_FALSE

Detailed Description

Definition at line 88 of file nsContentUtils.h.


Member Enumeration Documentation

Report a localized error message to the error console.

Parameters:
aFileProperties file containing localized message.
aMessageNameName of localized message.
aParamsParameters to be substituted into localized message.
aParamsLengthLength of aParams.
aURIURI of resource containing error (may be null).
aSourceLineThe text of the line that contains the error (may be empty).
aLineNumberLine number within resource containing error.
aColumnNumberColumn number within resource containing error.
aErrorFlagsSee nsIScriptError.
aCategoryName of module reporting error.
Enumerator:
eCSS_PROPERTIES 
eXBL_PROPERTIES 
eXUL_PROPERTIES 
eLAYOUT_PROPERTIES 
eFORMS_PROPERTIES 
ePRINTING_PROPERTIES 
eDOM_PROPERTIES 
eBRAND_PROPERTIES 
PropertiesFile_COUNT 

Definition at line 548 of file nsContentUtils.h.


Member Function Documentation

static nsresult nsContentUtils::AddJSGCRoot ( jsval aPtr,
const char *  aName 
) [inline, static]

Make sure that whatever value *aPtr contains at any given moment is protected from JS GC until we remove the GC root.

A call to this that succeeds MUST be matched by a call to RemoveJSGCRoot to avoid leaking.

Definition at line 618 of file nsContentUtils.h.

                                                              {
    return AddJSGCRoot((void*)aPtr, aName);
  }

Here is the caller graph for this function:

static nsresult nsContentUtils::AddJSGCRoot ( JSObject **  aPtr,
const char *  aName 
) [inline, static]

Make sure that whatever object *aPtr is pointing to at any given moment is protected from JS GC until we remove the GC root.

A call to this that succeeds MUST be matched by a call to RemoveJSGCRoot to avoid leaking.

Definition at line 627 of file nsContentUtils.h.

                                                                  {
    return AddJSGCRoot((void*)aPtr, aName);
  }

Here is the call graph for this function:

nsresult nsContentUtils::AddJSGCRoot ( void aPtr,
const char *  aName 
) [static]

Make sure that whatever object *aPtr is pointing to at any given moment is protected from JS GC until we remove the GC root.

A call to this that succeeds MUST be matched by a call to RemoveJSGCRoot to avoid leaking.

Definition at line 2574 of file nsContentUtils.cpp.

{
  if (!sScriptRuntime) {
    nsresult rv = CallGetService("@mozilla.org/js/xpc/RuntimeService;1",
                                 &sJSRuntimeService);
    NS_ENSURE_TRUE(sJSRuntimeService, rv);

    sJSRuntimeService->GetRuntime(&sScriptRuntime);
    if (!sScriptRuntime) {
      NS_RELEASE(sJSRuntimeService);
      NS_WARNING("Unable to get JS runtime from JS runtime service");
      return NS_ERROR_FAILURE;
    }
  }

  PRBool ok;
  ok = ::JS_AddNamedRootRT(sScriptRuntime, aPtr, aName);
  if (!ok) {
    if (sScriptRootCount == 0) {
      // We just got the runtime... Just null things out, since no
      // one's expecting us to have a runtime yet
      NS_RELEASE(sJSRuntimeService);
      sScriptRuntime = nsnull;
    }
    NS_WARNING("JS_AddNamedRootRT failed");
    return NS_ERROR_OUT_OF_MEMORY;
  }

  // We now have one more root we added to the runtime
  ++sScriptRootCount;

  return NS_OK;
}

Here is the call graph for this function:

PRBool nsContentUtils::BelongsInForm ( nsIDOMHTMLFormElement aForm,
nsIContent aContent 
) [static]

Determine whether aContent is in some way associated with aForm.

If the form is a container the only elements that are considered to be associated with a form are the elements that are contained within the form. If the form is a leaf element then all elements will be accepted into this list, since this can happen due to content fixup when a form spans table rows or table cells.

Definition at line 1732 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aForm, "Must have a form");
  NS_PRECONDITION(aContent, "Must have a content node");

  nsCOMPtr<nsIContent> form(do_QueryInterface(aForm));

  if (!form) {
    NS_ERROR("This should not happen, form is not an nsIContent!");

    return PR_TRUE;
  }

  if (form == aContent) {
    // A form does not belong inside itself, so we return false here

    return PR_FALSE;
  }

  nsIContent* content = aContent->GetParent();

  while (content) {
    if (content == form) {
      // aContent is contained within the form so we return true.

      return PR_TRUE;
    }

    if (content->Tag() == nsHTMLAtoms::form &&
        content->IsContentOfType(nsIContent::eHTML)) {
      // The child is contained within a form, but not the right form
      // so we ignore it.

      return PR_FALSE;
    }

    content = content->GetParent();
  }

  if (form->GetChildCount() > 0) {
    // The form is a container but aContent wasn't inside the form,
    // return false

    return PR_FALSE;
  }

  // The form is a leaf and aContent wasn't inside any other form so
  // we check whether the content comes after the form.  If it does,
  // return true.  If it does not, then it couldn't have been inside
  // the form in the HTML.
  nsCOMPtr<nsIDOM3Node> contentAsDOM3(do_QueryInterface(aContent));
  PRUint16 comparisonFlags = 0;
  nsresult rv = NS_OK;
  if (contentAsDOM3) {
    rv = contentAsDOM3->CompareDocumentPosition(aForm, &comparisonFlags);
  }
  if (NS_FAILED(rv) ||
      comparisonFlags & nsIDOM3Node::DOCUMENT_POSITION_PRECEDING) {
    // We could be in this form!
    // In the future, we may want to get document.forms, look at the
    // form after aForm, and if aContent is after that form after
    // aForm return false here....
    return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 665 of file nsContentUtils.cpp.

{
  nsCOMPtr<nsIPrincipal> subjectPrincipal;
  sSecurityManager->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));

  if (!subjectPrincipal) {
    // we're running as system, grant access to the node.

    return PR_TRUE;
  }

  nsCOMPtr<nsIPrincipal> systemPrincipal;
  sSecurityManager->GetSystemPrincipal(getter_AddRefs(systemPrincipal));

  if (subjectPrincipal == systemPrincipal) {
    // we're running as system, grant access to the node.

    return PR_TRUE;
  }

  nsCOMPtr<nsIDocument> document;
  nsCOMPtr<nsIPrincipal> principal;

  nsresult rv = GetDocumentAndPrincipal(aNode,
                                        getter_AddRefs(document),
                                        getter_AddRefs(principal));
  NS_ENSURE_SUCCESS(rv, PR_FALSE);

  if (!document && !principal) {
    // We can't get hold of the principal for this node. This should happen
    // very rarely, like for textnodes out of the tree and <option>s created
    // using 'new Option'.
    // If we didn't allow access to nodes like this you wouldn't be able to
    // insert these nodes into a document.

    return PR_TRUE;
  }

  PRBool enabled = PR_FALSE;
  if (principal == systemPrincipal) {
    // we know subjectPrincipal != systemPrincipal so we can only
    // access the object if UniversalXPConnect is enabled. We can
    // avoid wasting time in CheckSameOriginPrincipal

    rv = sSecurityManager->IsCapabilityEnabled("UniversalXPConnect", &enabled);
    return NS_SUCCEEDED(rv) && enabled;
  }

  rv = sSecurityManager->CheckSameOriginPrincipal(subjectPrincipal, principal);
  if (NS_SUCCEEDED(rv)) {
    return PR_TRUE;
  }

  // see if the caller has otherwise been given the ability to touch
  // input args to DOM methods

  rv = sSecurityManager->IsCapabilityEnabled("UniversalBrowserRead", &enabled);
  return NS_SUCCEEDED(rv) && enabled;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 727 of file nsContentUtils.cpp.

{
  nsCOMPtr<nsIPrincipal> subjectPrincipal;
  sSecurityManager->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));

  if (!subjectPrincipal) {
    // we're running as system, grant access to the node.

    return PR_TRUE;
  }

  nsCOMPtr<nsIPrincipal> systemPrincipal;
  sSecurityManager->GetSystemPrincipal(getter_AddRefs(systemPrincipal));

  if (subjectPrincipal == systemPrincipal) {
    // we're running as system, grant access to the node.

    return PR_TRUE;
  }

  nsCOMPtr<nsIScriptObjectPrincipal> scriptObject =
    do_QueryInterface(aWindow->IsOuterWindow() ?
                      aWindow->GetCurrentInnerWindow() : aWindow);
  NS_ENSURE_TRUE(scriptObject, PR_FALSE);
  nsIPrincipal* principal = scriptObject->GetPrincipal();
  NS_ENSURE_TRUE(principal, PR_FALSE);

  PRBool enabled = PR_FALSE;
  nsresult rv;
  if (principal == systemPrincipal) {
    // we know subjectPrincipal != systemPrincipal so we can only
    // access the object if UniversalXPConnect is enabled. We can
    // avoid wasting time in CheckSameOriginPrincipal

    rv = sSecurityManager->IsCapabilityEnabled("UniversalXPConnect", &enabled);
    return NS_SUCCEEDED(rv) && enabled;
  }

  rv = sSecurityManager->CheckSameOriginPrincipal(subjectPrincipal, principal);
  if (NS_SUCCEEDED(rv)) {
    return PR_TRUE;
  }

  // see if the caller has otherwise been given the ability to touch
  // input args to DOM methods

  rv = sSecurityManager->IsCapabilityEnabled("UniversalBrowserRead", &enabled);
  return NS_SUCCEEDED(rv) && enabled;
}

Here is the call graph for this function:

PRBool nsContentUtils::CanLoadImage ( nsIURI aURI,
nsISupports *  aContext,
nsIDocument aLoadingDocument,
PRInt16 aImageBlockingStatus = nsnull 
) [static]

Method to do security and content policy checks on the image URI.

Parameters:
aURIuri of the image to be loaded
aContextthe context the image is loaded in (eg an element)
aLoadingDocumentthe document we belong to
aImageBlockingStatusthe nsIContentPolicy blocking status for this image. This will be set even if a security check fails for the image, to some reasonable REJECT_* value. This out param will only be set if it's non-null.
Returns:
PR_TRUE if the load can proceed, or PR_FALSE if it is blocked. Note that aImageBlockingStatus, if set will always be an ACCEPT status if PR_TRUE is returned and always be a REJECT_* status if PR_FALSE is returned.

Definition at line 1991 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aURI, "Must have a URI");
  NS_PRECONDITION(aLoadingDocument, "Must have a document");

  nsresult rv;

  PRUint32 appType = nsIDocShell::APP_TYPE_UNKNOWN;

  {
    nsCOMPtr<nsISupports> container = aLoadingDocument->GetContainer();
    nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
      do_QueryInterface(container);

    if (docShellTreeItem) {
      nsCOMPtr<nsIDocShellTreeItem> root;
      docShellTreeItem->GetRootTreeItem(getter_AddRefs(root));

      nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(root));

      if (!docShell || NS_FAILED(docShell->GetAppType(&appType))) {
        appType = nsIDocShell::APP_TYPE_UNKNOWN;
      }
    }
  }

  if (appType != nsIDocShell::APP_TYPE_EDITOR) {
    // Editor apps get special treatment here, editors can load images
    // from anywhere.
    rv = sSecurityManager->
      CheckLoadURIWithPrincipal(aLoadingDocument->GetPrincipal(), aURI,
                                nsIScriptSecurityManager::ALLOW_CHROME);
    if (NS_FAILED(rv)) {
      if (aImageBlockingStatus) {
        // Reject the request itself, not all requests to the relevant
        // server...
        *aImageBlockingStatus = nsIContentPolicy::REJECT_REQUEST;
      }
      return PR_FALSE;
    }
  }

  PRInt16 decision = nsIContentPolicy::ACCEPT;

  rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_IMAGE,
                                 aURI,
                                 aLoadingDocument->GetDocumentURI(),
                                 aContext,
                                 EmptyCString(), //mime guess
                                 nsnull,         //extra
                                 &decision);

  if (aImageBlockingStatus) {
    *aImageBlockingStatus =
      NS_FAILED(rv) ? nsIContentPolicy::REJECT_REQUEST : decision;
  }
  return NS_FAILED(rv) ? PR_FALSE : NS_CP_ACCEPTED(decision);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::CheckQName ( const nsAString &  aQualifiedName,
PRBool  aNamespaceAware = PR_TRUE 
) [static]

Definition at line 1803 of file nsContentUtils.cpp.

{
  nsIParserService *parserService = GetParserServiceWeakRef();
  NS_ENSURE_TRUE(parserService, NS_ERROR_FAILURE);

  const PRUnichar *colon;
  return parserService->CheckQName(PromiseFlatString(aQualifiedName),
                                   aNamespaceAware, &colon);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::CheckSameOrigin ( nsIDOMNode aTrustedNode,
nsIDOMNode aUnTrustedNode 
) [static]

Checks whether two nodes come from the same origin.

aTrustedNode is considered 'safe' in that a user can operate on it and that it isn't a js-object that implements nsIDOMNode. Never call this function with the first node provided by script, it must always be known to be a 'real' node!

Definition at line 555 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aTrustedNode, "There must be a trusted node");

  PRBool isSystem = PR_FALSE;
  sSecurityManager->SubjectPrincipalIsSystem(&isSystem);
  if (isSystem) {
    // we're running as system, grant access to the node.

    return NS_OK;
  }

  /*
   * Get hold of each node's document or principal
   */

  // In most cases this is a document, so lets try that first
  nsCOMPtr<nsIDocument> trustedDoc = do_QueryInterface(aTrustedNode);
  nsIPrincipal* trustedPrincipal = nsnull;

  if (!trustedDoc) {
#ifdef DEBUG
    nsCOMPtr<nsIContent> trustCont = do_QueryInterface(aTrustedNode);
    NS_ASSERTION(trustCont,
                 "aTrustedNode is neither nsIContent nor nsIDocument!");
#endif
    nsCOMPtr<nsIDOMDocument> domDoc;
    aTrustedNode->GetOwnerDocument(getter_AddRefs(domDoc));

    if (!domDoc) {
      // In theory this should never happen. But since theory and reality are
      // different for XUL elements we'll try to get the principal from the
      // nsNodeInfoManager.

      nsCOMPtr<nsIContent> cont = do_QueryInterface(aTrustedNode);
      NS_ENSURE_TRUE(cont, NS_ERROR_UNEXPECTED);

      nsINodeInfo *ni = cont->GetNodeInfo();
      NS_ENSURE_TRUE(ni, NS_ERROR_UNEXPECTED);

      trustedPrincipal = ni->NodeInfoManager()->GetDocumentPrincipal();

      if (!trustedPrincipal) {
        // Can't get principal of aTrustedNode so we can't check security
        // against it

        return NS_ERROR_UNEXPECTED;
      }
    } else {
      trustedDoc = do_QueryInterface(domDoc);
      NS_ASSERTION(trustedDoc, "QI to nsIDocument failed");
    }
  }

  nsCOMPtr<nsIDocument> unTrustedDoc;
  nsCOMPtr<nsIPrincipal> unTrustedPrincipal;

  nsresult rv = GetDocumentAndPrincipal(aUnTrustedNode,
                                        getter_AddRefs(unTrustedDoc),
                                        getter_AddRefs(unTrustedPrincipal));
  NS_ENSURE_SUCCESS(rv, rv);

  if (!unTrustedDoc && !unTrustedPrincipal) {
    // We can't get hold of the principal for this node. This should happen
    // very rarely, like for textnodes out of the tree and <option>s created
    // using 'new Option'.
    // If we didn't allow access to nodes like this you wouldn't be able to
    // insert these nodes into a document.

    return NS_OK;
  }

  /*
   * Compare the principals
   */

  // If they are in the same document then everything is just fine
  if (trustedDoc == unTrustedDoc && trustedDoc) {
    return NS_OK;
  }

  if (!trustedPrincipal) {
    trustedPrincipal = trustedDoc->GetPrincipal();

    if (!trustedPrincipal) {
      // If the trusted node doesn't have a principal we can't check
      // security against it

      return NS_ERROR_DOM_SECURITY_ERR;
    }
  }

  if (!unTrustedPrincipal) {
    unTrustedPrincipal = unTrustedDoc->GetPrincipal();

    if (!unTrustedPrincipal) {
      // If the trusted node doesn't have a principal we can't check
      // security against it

      return NS_ERROR_DOM_SECURITY_ERR;
    }
  }

  return sSecurityManager->CheckSameOriginPrincipal(trustedPrincipal,
                                                    unTrustedPrincipal);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Compares the document position of nodes which may have parents.

DO NOT pass in nodes that cannot have a parentNode. In other words: DO NOT pass in Attr, Document, DocumentFragment, Entity, or Notation! The results will be completely wrong!

Parameters:
aNodeThe node to which you are comparing.
aOtherThe reference node to which aNode is compared.
Returns:
The document position flags of the nodes.
See also:
nsIDOMNode
nsIDOM3Node

Definition at line 1319 of file nsContentUtils.cpp.

{
#ifdef DEBUG
  PRUint16 nodeType = 0;
  PRUint16 otherType = 0;
  aNode->GetNodeType(&nodeType);
  aOther->GetNodeType(&otherType);

  NS_PRECONDITION(nodeType != nsIDOMNode::ATTRIBUTE_NODE &&
                  nodeType != nsIDOMNode::DOCUMENT_NODE &&
                  nodeType != nsIDOMNode::DOCUMENT_FRAGMENT_NODE &&
                  nodeType != nsIDOMNode::ENTITY_NODE &&
                  nodeType != nsIDOMNode::NOTATION_NODE &&
                  otherType != nsIDOMNode::ATTRIBUTE_NODE &&
                  otherType != nsIDOMNode::DOCUMENT_NODE &&
                  otherType != nsIDOMNode::DOCUMENT_FRAGMENT_NODE &&
                  otherType != nsIDOMNode::ENTITY_NODE &&
                  otherType != nsIDOMNode::NOTATION_NODE,
                  "Bad.  Go read the documentation in the header!");
#endif // DEBUG

  PRUint16 mask = 0;

  nsCOMArray<nsIDOMNode> nodeAncestors;

  nsresult rv =
    nsContentUtils::GetFirstDifferentAncestors(aNode, aOther, nodeAncestors);

  if (NS_FAILED(rv)) {
    // If there is no common container node, then the order is based upon
    // order between the root container of each node that is in no container.
    // In this case, the result is disconnected and implementation-dependent.
    mask = (nsIDOM3Node::DOCUMENT_POSITION_DISCONNECTED |
            nsIDOM3Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);

    return mask;
  }

  nsIDOMNode* commonAncestor = nodeAncestors[0];

  if (commonAncestor == aNode) {
    mask = (nsIDOM3Node::DOCUMENT_POSITION_CONTAINED_BY |
            nsIDOM3Node::DOCUMENT_POSITION_FOLLOWING);

    return mask;
  }

  if (commonAncestor == aOther) {
    mask |= (nsIDOM3Node::DOCUMENT_POSITION_CONTAINS |
             nsIDOM3Node::DOCUMENT_POSITION_PRECEDING);

    return mask;
  }

  // GetFirstDifferentAncestors should only succeed if one of the
  // two nodes is the common ancestor, or if we have a common ancestor
  // and the two first different ancestors.  We checked the case above
  // where one of the two nodes were the common ancestor, so we must
  // have three items in our array now.
  NS_ASSERTION(commonAncestor && nodeAncestors.Count() == 3,
               "Something's wrong");

  nsIDOMNode* nodeAncestor = nodeAncestors[1];
  nsIDOMNode* otherAncestor = nodeAncestors[2];

  if (nodeAncestor && otherAncestor) {
    // Find out which of the two nodes comes first in the document order.
    // First get the children of the common ancestor.
    nsCOMPtr<nsIDOMNodeList> children;
    commonAncestor->GetChildNodes(getter_AddRefs(children));
    PRUint32 numKids;
    children->GetLength(&numKids);
    for (PRUint32 i = 0; i < numKids; ++i) {
      // Then go through the children one at a time to see which we hit first.
      nsCOMPtr<nsIDOMNode> childNode;
      children->Item(i, getter_AddRefs(childNode));
      if (childNode == nodeAncestor) {
        mask |= nsIDOM3Node::DOCUMENT_POSITION_FOLLOWING;
        break;
      }

      if (childNode == otherAncestor) {
        mask |= nsIDOM3Node::DOCUMENT_POSITION_PRECEDING;
        break;
      }
    }
  }

  return mask;
}

Here is the call graph for this function:

PRBool nsContentUtils::ContentIsDescendantOf ( nsIContent aPossibleDescendant,
nsIContent aPossibleAncestor 
) [static]

Do not ever pass null pointers to this method.

If one of your nsIContents is null, you have to decide for yourself what "IsDescendantOf" really means.

Parameters:
aPossibleDescendantnode to test for being a descendant of aPossibleAncestor
aPossibleAncestornode to test for being an ancestor of aPossibleDescendant
Returns:
PR_TRUE if aPossibleDescendant is a descendant of aPossibleAncestor (or is aPossibleAncestor). PR_FALSE otherwise.

Definition at line 1145 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aPossibleDescendant, "The possible descendant is null!");
  NS_PRECONDITION(aPossibleAncestor, "The possible ancestor is null!");

  do {
    if (aPossibleDescendant == aPossibleAncestor)
      return PR_TRUE;
    aPossibleDescendant = aPossibleDescendant->GetParent();
  } while (aPossibleDescendant);

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool nsContentUtils::ContentIsDraggable ( nsIContent aContent) [inline, static]

Method that decides whether a content node is draggable.

Parameters:
aContentThe content node to test.
Returns:
whether it's draggable

Definition at line 448 of file nsContentUtils.h.

                                                         {
    return IsDraggableImage(aContent) || IsDraggableLink(aContent);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRUint32 nsContentUtils::CopyNewlineNormalizedUnicodeTo ( const nsAString &  aSource,
PRUint32  aSrcOffset,
PRUnichar aDest,
PRUint32  aLength,
PRBool aLastCharCR 
) [static]

Definition at line 383 of file nsContentUtils.cpp.

{
  typedef NormalizeNewlinesCharTraits<PRUnichar*> sink_traits;

  sink_traits dest_traits(aDest);
  CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits,aLastCharCR);
  nsReadingIterator<PRUnichar> fromBegin, fromEnd;
  copy_string(aSource.BeginReading(fromBegin).advance( PRInt32(aSrcOffset) ),
              aSource.BeginReading(fromEnd).advance( PRInt32(aSrcOffset+aLength) ),
              normalizer);
  aLastCharCR = normalizer.IsLastCharCR();
  return normalizer.GetCharsWritten();
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRUint32 nsContentUtils::CopyNewlineNormalizedUnicodeTo ( nsReadingIterator< PRUnichar > &  aSrcStart,
const nsReadingIterator< PRUnichar > &  aSrcEnd,
nsAString &  aDest 
) [static]

Definition at line 403 of file nsContentUtils.cpp.

{
  typedef nsWritingIterator<PRUnichar> WritingIterator;
  typedef NormalizeNewlinesCharTraits<WritingIterator> sink_traits;

  WritingIterator iter;
  aDest.BeginWriting(iter);
  sink_traits dest_traits(iter);
  CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits);
  copy_string(aSrcStart, aSrcEnd, normalizer);
  return normalizer.GetCharsWritten();
}

Here is the call graph for this function:

nsresult nsContentUtils::doReparentContentWrapper ( nsIContent aChild,
JSContext cx,
JSObject aOldGlobal,
JSObject aNewGlobal 
) [static, private]

Definition at line 818 of file nsContentUtils.cpp.

{
  nsCOMPtr<nsIXPConnectJSObjectHolder> old_wrapper;

  nsresult rv;

  rv = sXPConnect->ReparentWrappedNativeIfFound(cx, aOldGlobal, aNewGlobal,
                                                aNode,
                                                getter_AddRefs(old_wrapper));
  NS_ENSURE_SUCCESS(rv, rv);

  // Whether or not aChild is already wrapped we must iterate through
  // its descendants since there's no guarantee that a descendant isn't
  // wrapped even if this child is not wrapped. That used to be true
  // when every DOM node's JSObject was parented at the DOM node's
  // parent's JSObject, but that's no longer the case.

  PRUint32 i, count = aNode->GetChildCount();

  for (i = 0; i < count; i++) {
    nsIContent *child = aNode->GetChildAt(i);
    NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);

    rv = doReparentContentWrapper(child, cx, aOldGlobal, aNewGlobal);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2436 of file nsContentUtils.cpp.

{
  if (!sStringBundles[aFile]) {
    if (!sStringBundleService) {
      nsresult rv =
        CallGetService(NS_STRINGBUNDLE_CONTRACTID, &sStringBundleService);
      NS_ENSURE_SUCCESS(rv, rv);
    }
    nsIStringBundle *bundle;
    nsresult rv =
      sStringBundleService->CreateBundle(gPropertiesFiles[aFile], &bundle);
    NS_ENSURE_SUCCESS(rv, rv);
    sStringBundles[aFile] = bundle; // transfer ownership
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::FormatLocalizedString ( PropertiesFile  aFile,
const char *  aKey,
const PRUnichar **  aParams,
PRUint32  aParamsLength,
nsXPIDLString aResult 
) [static]

Fill (with the parameters given) the localized string named |aKey| in properties file |aFile|.

Definition at line 2467 of file nsContentUtils.cpp.

{
  nsresult rv = EnsureStringBundle(aFile);
  NS_ENSURE_SUCCESS(rv, rv);
  nsIStringBundle *bundle = sStringBundles[aFile];

  return bundle->FormatStringFromName(NS_ConvertASCIItoUCS2(aKey).get(),
                                      aParams, aParamsLength,
                                      getter_Copies(aResult));
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::GenerateStateKey ( nsIContent aContent,
nsIDocument aDocument,
nsIStatefulFrame::SpecialStateID  aID,
nsACString &  aKey 
) [static]

Definition at line 1579 of file nsContentUtils.cpp.

{
  aKey.Truncate();

  PRUint32 partID = aDocument ? aDocument->GetPartID() : 0;

  // SpecialStateID case - e.g. scrollbars around the content window
  // The key in this case is the special state id (always < min(contentID))
  if (nsIStatefulFrame::eNoID != aID) {
    KeyAppendInt(partID, aKey);  // first append a partID
    KeyAppendInt(aID, aKey);
    return NS_OK;
  }

  // We must have content if we're not using a special state id
  NS_ENSURE_TRUE(aContent, NS_ERROR_FAILURE);

  // Don't capture state for anonymous content
  PRUint32 contentID = aContent->ContentID();
  if (!contentID) {
    return NS_OK;
  }

  nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aContent));
  if (element && IsAutocompleteOff(element)) {
    return NS_OK;
  }

  nsCOMPtr<nsIHTMLDocument> htmlDocument(do_QueryInterface(aContent->GetCurrentDoc()));

  KeyAppendInt(partID, aKey);  // first append a partID
  PRBool generatedUniqueKey = PR_FALSE;

  if (htmlDocument) {
    // Flush our content model so it'll be up to date
    aContent->GetCurrentDoc()->FlushPendingNotifications(Flush_Content);

    nsContentList *htmlForms = htmlDocument->GetForms();
    nsRefPtr<nsContentList> htmlFormControls =
      GetFormControlElements(aDocument);

    NS_ENSURE_TRUE(htmlForms && htmlFormControls, NS_ERROR_OUT_OF_MEMORY);

    // If we have a form control and can calculate form information, use
    // that as the key - it is more reliable than contentID.
    // Important to have a unique key, and tag/type/name may not be.
    //
    // If the control has a form, the format of the key is:
    // type>IndOfFormInDoc>IndOfControlInForm>FormName>name
    // else:
    // type>IndOfControlInDoc>name
    //
    // XXX We don't need to use index if name is there
    //
    nsCOMPtr<nsIFormControl> control(do_QueryInterface(aContent));
    if (control && htmlFormControls && htmlForms) {

      // Append the control type
      KeyAppendInt(control->GetType(), aKey);

      // If in a form, add form name / index of form / index in form
      PRInt32 index = -1;
      nsCOMPtr<nsIDOMHTMLFormElement> formElement;
      control->GetForm(getter_AddRefs(formElement));
      if (formElement) {

        if (IsAutocompleteOff(formElement)) {
          aKey.Truncate();
          return NS_OK;
        }

        // Append the index of the form in the document
        nsCOMPtr<nsIContent> formContent(do_QueryInterface(formElement));
        index = htmlForms->IndexOf(formContent, PR_FALSE);
        if (index <= -1) {
          //
          // XXX HACK this uses some state that was dumped into the document
          // specifically to fix bug 138892.  What we are trying to do is *guess*
          // which form this control's state is found in, with the highly likely
          // guess that the highest form parsed so far is the one.
          // This code should not be on trunk, only branch.
          //
          index = htmlDocument->GetNumFormsSynchronous() - 1;
        }
        if (index > -1) {
          KeyAppendInt(index, aKey);

          // Append the index of the control in the form
          nsCOMPtr<nsIForm> form(do_QueryInterface(formElement));
          form->IndexOfControl(control, &index);

          if (index > -1) {
            KeyAppendInt(index, aKey);
            generatedUniqueKey = PR_TRUE;
          }
        }

        // Append the form name
        nsAutoString formName;
        formElement->GetName(formName);
        KeyAppendString(formName, aKey);

      } else {

        // If not in a form, add index of control in document
        // Less desirable than indexing by form info.

        // Hash by index of control in doc (we are not in a form)
        // These are important as they are unique, and type/name may not be.

        // Note that we've already flushed content, so there's no
        // reason to flush it again.
        index = htmlFormControls->IndexOf(aContent, PR_FALSE);
        if (index > -1) {
          KeyAppendInt(index, aKey);
          generatedUniqueKey = PR_TRUE;
        }
      }

      // Append the control name
      nsAutoString name;
      aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, name);
      KeyAppendString(name, aKey);
    }
  }

  if (!generatedUniqueKey) {

    // Either we didn't have a form control or we aren't in an HTML document
    // so we can't figure out form info, hash by content ID instead :(
    KeyAppendInt(contentID, aKey);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::GetAncestors ( nsIDOMNode aNode,
nsVoidArray aArray 
) [static]

Definition at line 1163 of file nsContentUtils.cpp.

{
  NS_ENSURE_ARG_POINTER(aNode);

  nsCOMPtr<nsIDOMNode> node(aNode);
  nsCOMPtr<nsIDOMNode> ancestor;

  do {
    aArray->AppendElement(node.get());
    node->GetParentNode(getter_AddRefs(ancestor));
    node.swap(ancestor);
  } while (node);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::GetAncestorsAndOffsets ( nsIDOMNode aNode,
PRInt32  aOffset,
nsVoidArray aAncestorNodes,
nsVoidArray aAncestorOffsets 
) [static]

Definition at line 1182 of file nsContentUtils.cpp.

{
  NS_ENSURE_ARG_POINTER(aNode);

  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));

  if (!content) {
    return NS_ERROR_FAILURE;
  }

  if (aAncestorNodes->Count() != 0) {
    NS_WARNING("aAncestorNodes is not empty");
    aAncestorNodes->Clear();
  }

  if (aAncestorOffsets->Count() != 0) {
    NS_WARNING("aAncestorOffsets is not empty");
    aAncestorOffsets->Clear();
  }

  // insert the node itself
  aAncestorNodes->AppendElement(content.get());
  aAncestorOffsets->AppendElement(NS_INT32_TO_PTR(aOffset));

  // insert all the ancestors
  nsIContent* child = content;
  nsIContent* parent = child->GetParent();
  while (parent) {
    aAncestorNodes->AppendElement(parent);
    aAncestorOffsets->AppendElement(NS_INT32_TO_PTR(parent->IndexOf(child)));
    child = parent;
    parent = parent->GetParent();
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRPackedBool nsContentUtils::GetBoolPref ( const char *  aPref,
PRBool  aDefault = PR_FALSE 
) [static]

Definition at line 2223 of file nsContentUtils.cpp.

{
  PRBool result;

  if (!sPrefBranch ||
      NS_FAILED(sPrefBranch->GetBoolPref(aPref, &result))) {
    result = aDefault;
  }

  return (PRPackedBool)result;
}
nsAdoptingCString nsContentUtils::GetCharPref ( const char *  aPref) [static]

Definition at line 2210 of file nsContentUtils.cpp.

{
  nsAdoptingCString result;

  if (sPrefBranch) {
    sPrefBranch->GetCharPref(aPref, getter_Copies(result));
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsISupports * nsContentUtils::GetClassInfoInstance ( nsDOMClassInfoID  aID) [static]

Definition at line 456 of file nsContentUtils.cpp.

{
  if (!sDOMScriptObjectFactory) {
    static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
                         NS_DOM_SCRIPT_OBJECT_FACTORY_CID);

    CallGetService(kDOMScriptObjectFactoryCID, &sDOMScriptObjectFactory);

    if (!sDOMScriptObjectFactory) {
      return nsnull;
    }
  }

  return sDOMScriptObjectFactory->GetClassInfoInstance(aID);
}

Here is the call graph for this function:

nsresult nsContentUtils::GetCommonAncestor ( nsIDOMNode aNode,
nsIDOMNode aOther,
nsIDOMNode **  aCommonAncestor 
) [static]

Definition at line 1224 of file nsContentUtils.cpp.

{
  *aCommonAncestor = nsnull;

  nsCOMArray<nsIDOMNode> nodeArray;
  nsresult rv = GetFirstDifferentAncestors(aNode, aOther, nodeArray);
  NS_ENSURE_SUCCESS(rv, rv);

  nsIDOMNode *common = nodeArray[0];

  NS_ASSERTION(common, "The common ancestor is null!  Very bad!");

  *aCommonAncestor = common;
  NS_IF_ADDREF(*aCommonAncestor);

  return NS_OK;
}

Here is the call graph for this function:

Get the docshell through the JS context that's currently on the stack.

If there's no JS context currently on the stack aDocShell will be null.

Parameters:
aDocShellThe docshell or null if no JS context

Definition at line 1004 of file nsContentUtils.cpp.

{
  if (!sThreadJSContextStack) {
    return nsnull;
  }

  JSContext *cx = nsnull;
  sThreadJSContextStack->Peek(&cx);

  if (cx) {
    nsIScriptGlobalObject *sgo = nsJSUtils::GetDynamicScriptGlobal(cx);

    if (sgo) {
      return sgo->GetDocShell();
    }
  }

  return nsnull;
}

Here is the call graph for this function:

static nsIDocument* nsContentUtils::GetDocument ( nsINodeInfo aNodeInfo) [inline, static]

Retrieve a pointer to the document that owns aNodeInfo.

Definition at line 514 of file nsContentUtils.h.

  {
    return aNodeInfo->NodeInfoManager()->GetDocument();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::GetDocumentAndPrincipal ( nsIDOMNode aNode,
nsIDocument **  aDocument,
nsIPrincipal **  aPrincipal 
) [static]

Definition at line 474 of file nsContentUtils.cpp.

{
  // For performance reasons it's important to try to QI the node to
  // nsIContent before trying to QI to nsIDocument since a QI miss on
  // a node is potentially expensive.
  nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
  nsCOMPtr<nsIAttribute> attr;

  if (!content) {
    CallQueryInterface(aNode, aDocument);

    if (!*aDocument) {
      attr = do_QueryInterface(aNode);
      if (!attr) {
        // aNode is not a nsIContent, a nsIAttribute or a nsIDocument,
        // something weird is going on...

        NS_ERROR("aNode is not nsIContent, nsIAttribute or nsIDocument!");

        return NS_ERROR_UNEXPECTED;
      }
    }
  }

  if (!*aDocument) {
    nsCOMPtr<nsIDOMDocument> domDoc;
    aNode->GetOwnerDocument(getter_AddRefs(domDoc));
    if (!domDoc) {
      // if we can't get a doc then lets try to get principal through nodeinfo
      // manager
      nsINodeInfo *ni;
      if (content) {
        ni = content->GetNodeInfo();
      }
      else {
        ni = attr->NodeInfo();
      }

      if (!ni) {
        // we can't get to the principal so we'll give up

        return NS_OK;
      }

      *aPrincipal = ni->NodeInfoManager()->GetDocumentPrincipal();
      if (!*aPrincipal) {
        // we can't get to the principal so we'll give up

        return NS_OK;
      }

      NS_ADDREF(*aPrincipal);
    }
    else {
      CallQueryInterface(domDoc, aDocument);
      if (!*aDocument) {
        NS_ERROR("QI to nsIDocument failed");

        return NS_ERROR_UNEXPECTED;
      }
    }
  }

  if (!*aPrincipal) {
    NS_IF_ADDREF(*aPrincipal = (*aDocument)->GetPrincipal());
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

The two GetDocumentFrom* functions below allow a caller to get at a document that is relevant to the currently executing script.

GetDocumentFromCaller gets its document by looking at the last called function and finding the document that the function itself relates to. For example, consider two windows A and B in the same origin. B has a function which does something that ends up needing the current document. If a script in window A were to call B's function, GetDocumentFromCaller would find that function (in B) and return B's document.

GetDocumentFromContext gets its document by looking at the currently executing context's global object and returning its document. Thus, given the example above, GetDocumentFromCaller would see that the currently executing script was in window A, and return A's document. Get the document from the currently executing function. This will return the document that the currently executing function is in/from.

Returns:
The document or null if no JS Context.

Definition at line 1025 of file nsContentUtils.cpp.

{
  JSContext *cx = nsnull;
  sThreadJSContextStack->Peek(&cx);

  nsIDOMDocument *doc = nsnull;

  if (cx) {
    JSObject *callee = nsnull;
    JSStackFrame *fp = nsnull;
    while (!callee && (fp = ::JS_FrameIterator(cx, &fp))) {
      callee = ::JS_GetFrameCalleeObject(cx, fp);
    }

    nsCOMPtr<nsPIDOMWindow> win =
      do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(cx, callee));
    if (win) {
      doc = win->GetExtantDocument();
    }
  }

  return doc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get the document through the JS context that's currently on the stack.

If there's no JS context currently on the stack it will return null. This will return the document of the calling script.

Returns:
The document or null if no JS context

Definition at line 1050 of file nsContentUtils.cpp.

{
  if (!sThreadJSContextStack) {
    return nsnull;
  }

  JSContext *cx = nsnull;
  sThreadJSContextStack->Peek(&cx);

  nsCOMPtr<nsIDOMDocument> doc;

  if (cx) {
    nsIScriptGlobalObject *sgo = nsJSUtils::GetDynamicScriptGlobal(cx);

    nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(sgo));
    if (win) {
      win->GetDocument(getter_AddRefs(doc));
    }
  }

  // This will return a pointer to something we're about to release,
  // but that's ok here.
  return doc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char * nsContentUtils::GetEventArgName ( PRInt32  aNameSpaceID) [static]

Returns the appropriate event argument name for the specified namespace.

Added because we need to switch between SVG's "evt" and the rest of the world's "event".

Definition at line 2311 of file nsContentUtils.cpp.

{
  if (aNameSpaceID == kNameSpaceID_SVG)
    return gSVGEventName;

  return gEventName;
}

Here is the caller graph for this function:

nsresult nsContentUtils::GetFirstDifferentAncestors ( nsIDOMNode aNode,
nsIDOMNode aOther,
nsCOMArray< nsIDOMNode > &  aDifferentNodes 
) [static]

Definition at line 1246 of file nsContentUtils.cpp.

{
  NS_ENSURE_ARG_POINTER(aNode);
  NS_ENSURE_ARG_POINTER(aOther);

  if (aDifferentNodes.Count() != 0) {
    NS_WARNING("The aDifferentNodes array passed in is not empty!");
    aDifferentNodes.Clear();
  }

  // Test if both are the same node.
  if (aNode == aOther) {
    aDifferentNodes.AppendObject(aNode);
    return NS_OK;
  }

  nsCOMArray<nsIDOMNode> nodeAncestors;
  nsCOMArray<nsIDOMNode> otherAncestors;

  // Insert all the ancestors of |aNode|
  nsCOMPtr<nsIDOMNode> node(aNode);
  nsCOMPtr<nsIDOMNode> ancestor(node);
  do {
    nodeAncestors.AppendObject(node);
    node->GetParentNode(getter_AddRefs(ancestor));
    if (ancestor == aOther) {
      aDifferentNodes.AppendObject(aOther);
      return NS_OK;
    }
    node.swap(ancestor);
  } while (node);

  // Insert all the ancestors of |aOther|
  nsCOMPtr<nsIDOMNode> other(aOther);
  ancestor = other;
  do {
    otherAncestors.AppendObject(other);
    other->GetParentNode(getter_AddRefs(ancestor));
    if (ancestor == aNode) {
      aDifferentNodes.AppendObject(aNode);
      return NS_OK;
    }
    other.swap(ancestor);
  } while (other);

  PRInt32 nodeIdx  = nodeAncestors.Count() - 1;
  PRInt32 otherIdx = otherAncestors.Count() - 1;

  if (nodeAncestors[nodeIdx] != otherAncestors[otherIdx]) {
    // These two nodes are disconnected.  We can't get a common ancestor.
    return NS_ERROR_FAILURE;
  }

  // Go back through the ancestors, starting from the root,
  // until the first different ancestor found.
  do {
    --nodeIdx;
    --otherIdx;
  } while (nodeAncestors[nodeIdx] == otherAncestors[otherIdx]);

  NS_ASSERTION(nodeIdx >= 0 && otherIdx >= 0,
               "Something's wrong: our indices should not be negative here!");

  aDifferentNodes.AppendObject(nodeAncestors[nodeIdx + 1]);
  aDifferentNodes.AppendObject(nodeAncestors[nodeIdx]);
  aDifferentNodes.AppendObject(otherAncestors[otherIdx]);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns a list containing all elements in the document that are of type nsIContent::eHTML_FORM_CONTROL.

Definition at line 2529 of file nsContentUtils.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Method to get an nsIImage from an image loading content.

Parameters:
aContentThe image loading content. Must not be null.
aRequestThe image request [out]
Returns:
the nsIImage corresponding to the first frame of the image

Definition at line 2088 of file nsContentUtils.cpp.

{
  if (aRequest) {
    *aRequest = nsnull;
  }

  NS_ENSURE_TRUE(aContent, nsnull);

  nsCOMPtr<imgIRequest> imgRequest;
  aContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                      getter_AddRefs(imgRequest));
  if (!imgRequest) {
    return nsnull;
  }

  nsCOMPtr<imgIContainer> imgContainer;
  imgRequest->GetImage(getter_AddRefs(imgContainer));

  if (!imgContainer) {
    return nsnull;
  }

  nsCOMPtr<gfxIImageFrame> imgFrame;
  imgContainer->GetFrameAt(0, getter_AddRefs(imgFrame));

  if (!imgFrame) {
    return nsnull;
  }

  nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(imgFrame);

  if (!ir) {
    return nsnull;
  }

  if (aRequest) {
    imgRequest.swap(*aRequest);
  }

  nsIImage* image = nsnull;
  CallGetInterface(ir.get(), &image);
  return image;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static imgILoader* nsContentUtils::GetImgLoader ( ) [inline, static]

Definition at line 318 of file nsContentUtils.h.

  {
    return sImgLoader;
  }

Here is the caller graph for this function:

PRInt32 nsContentUtils::GetIntPref ( const char *  aPref,
PRInt32  aDefault = 0 
) [static]

Definition at line 2237 of file nsContentUtils.cpp.

{
  PRInt32 result;

  if (!sPrefBranch ||
      NS_FAILED(sPrefBranch->GetIntPref(aPref, &result))) {
    result = aDefault;
  }

  return result;
}

Here is the caller graph for this function:

static nsIIOService* nsContentUtils::GetIOServiceWeakRef ( ) [inline, static]

Definition at line 313 of file nsContentUtils.h.

  {
    return sIOService;
  }

Here is the caller graph for this function:

Method that gets the URI of the link content.

If the content isn't a link, return null.

Parameters:
aContentThe link content
Returns:
the URI the link points to

Definition at line 2164 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aContent, "Must have content node to work with");

  nsCOMPtr<nsILink> link(do_QueryInterface(aContent));
  if (link) {
    nsIURI* uri = nsnull;
    link->GetHrefURI(&uri);
    if (uri) {
      return uri;
    }
  }

  // It could still be an XLink
  return GetXLinkURI(aContent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::GetLocalizedString ( PropertiesFile  aFile,
const char *  aKey,
nsXPIDLString aResult 
) [static]

Get the localized string named |aKey| in properties file |aFile|.

Definition at line 2454 of file nsContentUtils.cpp.

{
  nsresult rv = EnsureStringBundle(aFile);
  NS_ENSURE_SUCCESS(rv, rv);
  nsIStringBundle *bundle = sStringBundles[aFile];

  return bundle->GetStringFromName(NS_ConvertASCIItoUCS2(aKey).get(),
                                   getter_Copies(aResult));
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsAdoptingString nsContentUtils::GetLocalizedStringPref ( const char *  aPref) [static]

Definition at line 2251 of file nsContentUtils.cpp.

{
  nsAdoptingString result;

  if (sPrefBranch) {
    nsCOMPtr<nsIPrefLocalizedString> prefLocalString;
    sPrefBranch->GetComplexValue(aPref, NS_GET_IID(nsIPrefLocalizedString),
                                 getter_AddRefs(prefLocalString));
    if (prefLocalString) {
      prefLocalString->GetData(getter_Copies(result));
    }
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::GetNodeInfoFromQName ( const nsAString &  aNamespaceURI,
const nsAString &  aQualifiedName,
nsNodeInfoManager aNodeInfoManager,
nsINodeInfo **  aNodeInfo 
) [static]

Definition at line 1876 of file nsContentUtils.cpp.

{
  nsIParserService* parserService = GetParserServiceWeakRef();
  NS_ENSURE_TRUE(parserService, NS_ERROR_FAILURE);

  const nsAFlatString& qName = PromiseFlatString(aQualifiedName);
  const PRUnichar* colon;
  nsresult rv = parserService->CheckQName(qName, PR_TRUE, &colon);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 nsID;
  sNameSpaceManager->RegisterNameSpace(aNamespaceURI, nsID);
  if (colon) {
    const PRUnichar* end;
    qName.EndReading(end);

    nsCOMPtr<nsIAtom> prefix = do_GetAtom(Substring(qName.get(), colon));

    rv = aNodeInfoManager->GetNodeInfo(Substring(colon + 1, end), prefix,
                                       nsID, aNodeInfo);
  }
  else {
    rv = aNodeInfoManager->GetNodeInfo(aQualifiedName, nsnull, nsID,
                                       aNodeInfo);
  }
  NS_ENSURE_SUCCESS(rv, rv);

  nsIAtom* prefix = (*aNodeInfo)->GetPrefixAtom();
  nsIAtom* nil = nsnull;

  // NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified name,
  // if the qualifiedName has a prefix and the namespaceURI is null, if the
  // qualifiedName has a prefix that is "xml" and the namespaceURI is different
  // from "http://www.w3.org/XML/1998/namespace", if the qualifiedName or its
  // prefix is "xmlns" and the namespaceURI is different from
  // "http://www.w3.org/2000/xmlns/", or if the namespaceURI is
  // "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor its
  // prefix is "xmlns".
  PRBool xmlPrefix = prefix == nsLayoutAtoms::xmlNameSpace;
  PRBool xmlns = (*aNodeInfo)->Equals(nsLayoutAtoms::xmlnsNameSpace, nil) ||
                 prefix == nsLayoutAtoms::xmlnsNameSpace;

  return (prefix && DOMStringIsNull(aNamespaceURI)) ||
         (xmlPrefix && nsID != kNameSpaceID_XML) ||
         (xmlns && nsID != kNameSpaceID_XMLNS) ||
         (nsID == kNameSpaceID_XMLNS && !xmlns) ?
         NS_ERROR_DOM_NAMESPACE_ERR : NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 308 of file nsContentUtils.h.

  {
    return sNameSpaceManager;
  }

Here is the caller graph for this function:

Access a cached parser service.

Don't addref. We need only one reference to it and this class has that one.

Definition at line 218 of file nsContentUtils.cpp.

{
  // XXX: This isn't accessed from several threads, is it?
  if (!sParserService) {
    // Lock, recheck sCachedParserService and aquire if this should be
    // safe for multiple threads.
    nsresult rv = CallGetService(kParserServiceCID, &sParserService);
    if (NS_FAILED(rv)) {
      sParserService = nsnull;
    }
  }

  return sParserService;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIPrefBranch* nsContentUtils::GetPrefBranch ( ) [inline, static]

Definition at line 389 of file nsContentUtils.h.

  {
    return sPrefBranch;
  }

Here is the caller graph for this function:

Definition at line 327 of file nsContentUtils.h.

  {
    return sSecurityManager;
  }

Here is the caller graph for this function:

nsAdoptingString nsContentUtils::GetStringPref ( const char *  aPref) [static]

Definition at line 2269 of file nsContentUtils.cpp.

{
  nsAdoptingString result;

  if (sPrefBranch) {
    nsCOMPtr<nsISupportsString> theString;
    sPrefBranch->GetComplexValue(aPref, NS_GET_IID(nsISupportsString),
                                 getter_AddRefs(theString));
    if (theString) {
      theString->ToString(getter_Copies(result));
    }
  }

  return result;
}

Here is the call graph for this function:

Method that gets the XLink uri for a content node, if it's an XLink.

Parameters:
aContentThe content node, possibly an XLink
Returns:
Null if aContent is not an XLink, the URI it points to otherwise

Definition at line 2183 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aContent, "Must have content node to work with");

  nsAutoString value;
  aContent->GetAttr(kNameSpaceID_XLink, nsHTMLAtoms::type, value);
  if (value.EqualsLiteral("simple")) {
    // Check that we have a URI
    aContent->GetAttr(kNameSpaceID_XLink, nsHTMLAtoms::href, value);

    if (!value.IsEmpty()) {
      //  Resolve it relative to aContent's base URI.
      nsCOMPtr<nsIURI> baseURI = aContent->GetBaseURI();

      nsIURI* uri = nsnull;
      nsContentUtils::NewURIWithDocumentCharset(&uri, value,
                                                aContent->GetDocument(),
                                                baseURI);
      return uri;
    }
  }

  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 153 of file nsContentUtils.cpp.

{
  if (sInitialized) {
    NS_WARNING("Init() called twice");

    return NS_OK;
  }

  nsresult rv = CallGetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID,
                               &sSecurityManager);
  NS_ENSURE_SUCCESS(rv, rv);

  // It's ok to not have a pref service.
  CallGetService(NS_PREFSERVICE_CONTRACTID, &sPrefBranch);

  // It's ok to not have prefs too.
  CallGetService(NS_PREF_CONTRACTID, &sPref);

  rv = NS_GetNameSpaceManager(&sNameSpaceManager);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = nsGenericElement::InitHashes();
  NS_ENSURE_SUCCESS(rv, rv);

  rv = CallGetService(nsIXPConnect::GetCID(), &sXPConnect);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = CallGetService(kJSStackContractID, &sThreadJSContextStack);
  if (NS_FAILED(rv) && sXPConnect) {
    // However, if we can't get a context stack after getting
    // an nsIXPConnect, things are broken, so let's fail here.

    return rv;
  }

  rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
  if (NS_FAILED(rv)) {
    // This makes life easier, but we can live without it.

    sIOService = nsnull;
  }

  // Ignore failure and just don't load images
  rv = CallGetService("@mozilla.org/image/loader;1", &sImgLoader);
  if (NS_FAILED(rv)) {
    // no image loading for us.  Oh, well.
    sImgLoader = nsnull;
  }

  sPtrsToPtrsToRelease = new nsVoidArray();
  if (!sPtrsToPtrsToRelease) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  sInitialized = PR_TRUE;

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 779 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aNode, "missing node to nsContentUtils::InProlog");

  // Check that there is an ancestor and that it is a document
  nsCOMPtr<nsIDOMNode> parent;
  aNode->GetParentNode(getter_AddRefs(parent));
  if (!parent) {
    return PR_FALSE;
  }

  PRUint16 type;
  parent->GetNodeType(&type);
  if (type != nsIDOMNode::DOCUMENT_NODE) {
    return PR_FALSE;
  }

  nsCOMPtr<nsIDocument> doc = do_QueryInterface(parent);
  NS_ASSERTION(doc, "document doesn't implement nsIDocument");
  nsCOMPtr<nsIContent> cont = do_QueryInterface(aNode);
  NS_ASSERTION(cont, "node doesn't implement nsIContent");

  // Check that there are no elements before aNode to make sure we are not
  // in the epilog
  PRInt32 pos = doc->IndexOf(cont);

  while (pos > 0) {
    --pos;
    nsIContent *sibl = doc->GetChildAt(pos);
    if (sibl->IsContentOfType(nsIContent::eELEMENT)) {
      return PR_FALSE;
    }
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsContentUtils::InSameDoc ( nsIDOMNode aNode,
nsIDOMNode aOther 
) [static]

Definition at line 1124 of file nsContentUtils.cpp.

{
  if (!aNode || !aOther) {
    return PR_FALSE;
  }

  nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
  nsCOMPtr<nsIContent> other(do_QueryInterface(aOther));

  if (content && other) {
    // XXXcaa Don't bother to check that either node is in a
    // document.  Editor relies on us returning true if neither
    // node is in a document.  See bug 154401.
    return content->GetDocument() == other->GetDocument();
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Definition at line 1076 of file nsContentUtils.cpp.

{
  PRBool is_caller_chrome = PR_FALSE;

  if (sSecurityManager) {
    nsresult rv = sSecurityManager->SubjectPrincipalIsSystem(&is_caller_chrome);
    if (NS_FAILED(rv)) {
      return PR_FALSE;
    }
  }

  return is_caller_chrome;
}

Here is the caller graph for this function:

PRBool nsContentUtils::IsCallerTrustedForCapability ( const char *  aCapability) [static]

Check whether a caller is trusted to have aCapability.

This also checks for UniversalXPConnect in addition to aCapability.

Definition at line 1091 of file nsContentUtils.cpp.

{
  if (nsContentUtils::IsCallerChrome())
    return PR_TRUE;

  // The secman really should handle UniversalXPConnect case, since that
  // should include UniversalBrowserRead... doesn't right now, though.
  PRBool hasCap;
  nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
  if (NS_FAILED(ssm->IsCapabilityEnabled(aCapability, &hasCap)))
    return PR_FALSE;
  if (hasCap)
    return PR_TRUE;
    
  if (NS_FAILED(ssm->IsCapabilityEnabled("UniversalXPConnect", &hasCap)))
    return PR_FALSE;
  return hasCap;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1111 of file nsContentUtils.cpp.

{
  return IsCallerTrustedForCapability("UniversalBrowserRead");
}

Here is the call graph for this function:

Definition at line 1117 of file nsContentUtils.cpp.

{
  return IsCallerTrustedForCapability("UniversalBrowserWrite");
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsContentUtils::IsChromeDoc ( nsIDocument aDocument) [static]

Returns true if aDocument is a chrome document.

Definition at line 2538 of file nsContentUtils.cpp.

{
  nsIPrincipal *principal;
  if (!aDocument || !(principal = aDocument->GetPrincipal())) {
    return PR_FALSE;
  }

  nsCOMPtr<nsIPrincipal> systemPrincipal;
  sSecurityManager->GetSystemPrincipal(getter_AddRefs(systemPrincipal));

  return principal == systemPrincipal;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Method that decides whether a content node is a draggable image.

Parameters:
aContentThe content node to test.
Returns:
whether it's a draggable image

Definition at line 2135 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aContent, "Must have content node to test");

  nsCOMPtr<nsIImageLoadingContent> imageContent(do_QueryInterface(aContent));
  if (!imageContent) {
    return PR_FALSE;
  }

  nsCOMPtr<imgIRequest> imgRequest;
  imageContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
                           getter_AddRefs(imgRequest));

  // XXXbz It may be draggable even if the request resulted in an error.  Why?
  // Not sure; that's what the old nsContentAreaDragDrop/nsFrame code did.
  return imgRequest != nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Method that decides whether a content node is a draggable link.

Parameters:
aContentThe content node to test.
Returns:
whether it's a draggable link

Definition at line 2155 of file nsContentUtils.cpp.

                                                    {
  nsCOMPtr<nsIURI> linkURI = GetLinkURI(aContent);

  // Does it have a URI?  If not, it's not draggable
  return linkURI != nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2628 of file nsContentUtils.cpp.

{
  while (aContent) {
    nsIContent* bindingParent = aContent->GetBindingParent();
    if (bindingParent == aContent) {
      return PR_TRUE;
    }
    if (aContent->IsContentOfType(nsIContent::eTEXT)) {
      aContent = aContent->GetParent();
    } else {
      aContent = bindingParent;
    }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

nsresult nsContentUtils::LoadImage ( nsIURI aURI,
nsIDocument aLoadingDocument,
nsIURI aReferrer,
imgIDecoderObserver aObserver,
PRInt32  aLoadFlags,
imgIRequest **  aRequest 
) [static]

Method to start an image load.

This does not do any security checks.

Parameters:
aURIuri of the image to be loaded
aLoadingDocumentthe document we belong to
aObserverthe observer for the image load
aLoadFlagsthe load flags to use. See nsIRequest
Returns:
the imgIRequest for the image load

Definition at line 2054 of file nsContentUtils.cpp.

{
  NS_PRECONDITION(aURI, "Must have a URI");
  NS_PRECONDITION(aLoadingDocument, "Must have a document");
  NS_PRECONDITION(aRequest, "Null out param");

  if (!sImgLoader) {
    // nothing we can do here
    return NS_OK;
  }

  nsCOMPtr<nsILoadGroup> loadGroup = aLoadingDocument->GetDocumentLoadGroup();
  NS_WARN_IF_FALSE(loadGroup, "Could not get loadgroup; onload may fire too early");

  nsIURI *documentURI = aLoadingDocument->GetDocumentURI();

  // XXXbz using "documentURI" for the initialDocumentURI is not quite
  // right, but the best we can do here...
  return sImgLoader->LoadImage(aURI,                 /* uri to load */
                               documentURI,          /* initialDocumentURI */
                               aReferrer,            /* referrer */
                               loadGroup,            /* loadgroup */
                               aObserver,            /* imgIDecoderObserver */
                               aLoadingDocument,     /* uniquification key */
                               aLoadFlags,           /* load flags */
                               nsnull,               /* cache key */
                               nsnull,               /* existing request*/
                               aRequest);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::LookupNamespaceURI ( nsIContent aNamespaceResolver,
const nsAString &  aNamespacePrefix,
nsAString &  aNamespaceURI 
) [static]

Definition at line 1851 of file nsContentUtils.cpp.

{
  nsCOMPtr<nsIAtom> name;
  if (!aNamespacePrefix.IsEmpty()) {
    name = do_GetAtom(aNamespacePrefix);
    NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
  }
  else {
    name = nsLayoutAtoms::xmlnsNameSpace;
  }
  // Trace up the content parent chain looking for the namespace
  // declaration that declares aNamespacePrefix.
  for (nsIContent* content = aNamespaceResolver; content;
       content = content->GetParent()) {
    if (content->GetAttr(kNameSpaceID_XMLNS, name, aNamespaceURI) ==
        NS_CONTENT_ATTR_HAS_VALUE)
      return NS_OK;
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsContentUtils::NameChanged ( nsINodeInfo aNodeInfo,
nsIAtom aName,
nsINodeInfo **  aResult 
) [inline, static]

Convenience method to create a new nodeinfo that differs only by name from aNodeInfo.

Definition at line 489 of file nsContentUtils.h.

  {
    nsNodeInfoManager *niMgr = aNodeInfo->NodeInfoManager();

    return niMgr->GetNodeInfo(aName, aNodeInfo->GetPrefixAtom(),
                              aNodeInfo->NamespaceID(), aResult);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::NewURIWithDocumentCharset ( nsIURI **  aResult,
const nsAString &  aSpec,
nsIDocument aDocument,
nsIURI aBaseURI 
) [static]

Create a new nsIURI from aSpec, using aBaseURI as the base.

The origin charset of the new nsIURI will be the document charset of aDocument.

Definition at line 1720 of file nsContentUtils.cpp.

{
  return NS_NewURI(aResult, aSpec,
                   aDocument ? aDocument->GetDocumentCharacterSet().get() : nsnull,
                   aBaseURI, sIOService);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Notify XPConnect if an exception is pending on aCx.

Definition at line 2552 of file nsContentUtils.cpp.

{
  if (!::JS_IsExceptionPending(aCx)) {
    return;
  }

  nsCOMPtr<nsIXPCNativeCallContext> nccx;
  XPConnect()->GetCurrentNativeCallContext(getter_AddRefs(nccx));
  if (nccx) {
    // Check to make sure that the JSContext that nccx will mess with is the
    // same as the JSContext we've set an exception on.  If they're not the
    // same, don't mess with nccx.
    JSContext* cx;
    nccx->GetJSContext(&cx);
    if (cx == aCx) {
      nccx->SetExceptionWasThrown(PR_TRUE);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsContentUtils::PrefixChanged ( nsINodeInfo aNodeInfo,
nsIAtom aPrefix,
nsINodeInfo **  aResult 
) [inline, static]

Convenience method to create a new nodeinfo that differs only by prefix from aNodeInfo.

Definition at line 502 of file nsContentUtils.h.

  {
    nsNodeInfoManager *niMgr = aNodeInfo->NodeInfoManager();

    return niMgr->GetNodeInfo(aNodeInfo->NameAtom(), aPrefix,
                              aNodeInfo->NamespaceID(), aResult);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsContentUtils::RegisterPrefCallback ( const char *  aPref,
PrefChangedFunc  aCallback,
void aClosure 
) [static]

Definition at line 2287 of file nsContentUtils.cpp.

{
  if (sPref)
    sPref->RegisterCallback(aPref, aCallback, aClosure);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsContentUtils::ReleasePtrOnShutdown ( nsISupports **  aSupportsPtr) [inline, static]

Release *aSupportsPtr when the shutdown notification is received.

Definition at line 607 of file nsContentUtils.h.

                                                                   {
    NS_ASSERTION(aSupportsPtr, "Expect to crash!");
    NS_ASSERTION(*aSupportsPtr, "Expect to crash!");
    return sPtrsToPtrsToRelease->AppendElement(aSupportsPtr) ? NS_OK :
      NS_ERROR_OUT_OF_MEMORY;
  }

Here is the caller graph for this function:

static nsresult nsContentUtils::RemoveJSGCRoot ( jsval aPtr) [inline, static]

Remove aPtr as a JS GC root.

Definition at line 641 of file nsContentUtils.h.

                                              {
    return RemoveJSGCRoot((void*)aPtr);
  }

Here is the caller graph for this function:

static nsresult nsContentUtils::RemoveJSGCRoot ( JSObject **  aPtr) [inline, static]

Definition at line 644 of file nsContentUtils.h.

                                                  {
    return RemoveJSGCRoot((void*)aPtr);
  }

Here is the call graph for this function:

Definition at line 2610 of file nsContentUtils.cpp.

{
  if (!sScriptRuntime) {
    NS_NOTREACHED("Trying to remove a JS GC root when none were added");
    return NS_ERROR_UNEXPECTED;
  }

  ::JS_RemoveRootRT(sScriptRuntime, aPtr);

  if (--sScriptRootCount == 0) {
    NS_RELEASE(sJSRuntimeService);
    sScriptRuntime = nsnull;
  }

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsContentUtils::ReparentContentWrapper ( nsIContent aContent,
nsIContent aNewParent,
nsIDocument aNewDocument,
nsIDocument aOldDocument 
) [static]

Definition at line 883 of file nsContentUtils.cpp.

{
  if (!aNewDocument || aNewDocument == aOldDocument) {
    return NS_OK;
  }


  nsCOMPtr<nsIDocument_MOZILLA_1_8_0_BRANCH> doc18 =
    do_QueryInterface(aNewDocument);
  if (!doc18) {
    NS_ERROR("Crazy document passed in");
    return NS_ERROR_UNEXPECTED;
  }
  nsIScriptGlobalObject *newSGO = doc18->GetScopeObject();
  JSObject *newScope;

  // If we can't find our old document we don't know what our old
  // scope was so there's no way to find the old wrapper, and if there
  // is no new scope there's no reason to reparent.
  if (!aOldDocument || !newSGO || !(newScope = newSGO->GetGlobalJSObject())) {
    return NS_OK;
  }

  NS_ENSURE_TRUE(sXPConnect, NS_ERROR_NOT_INITIALIZED);

  // Make sure to get our hands on the right scope object, since
  // GetWrappedNativeOfNativeObject doesn't call PreCreate and hence won't get
  // the right scope if we pass in something bogus.  The right scope lives on
  // the script global of the old document.
  // XXXbz note that if GetWrappedNativeOfNativeObject did call PreCreate it
  // would get the wrong scope (that of the _new_ document), so we should be
  // glad it doesn't!
  JSObject *globalObj;
  JSContext *cx = GetContextFromDocument(aOldDocument, &globalObj);

  if (!globalObj) {
    // No global object around; can't find the old wrapper w/o the old
    // global object

    return NS_OK;
  }

  if (!cx) {
    JSObject *dummy;
    cx = GetContextFromDocument(aNewDocument, &dummy);

    if (!cx) {
      // No context reachable from the old or new document, use the
      // calling context, or the safe context if no caller can be
      // found.

      sThreadJSContextStack->Peek(&cx);

      if (!cx) {
        sThreadJSContextStack->GetSafeJSContext(&cx);
      }
    }
  }

  return doReparentContentWrapper(aContent, cx, globalObj, newScope);
}

Here is the call graph for this function:

Here is the caller graph for this function:

When a document's scope changes (e.g., from document.open(), call this function to move all content wrappers from the old scope to the new one.

Definition at line 949 of file nsContentUtils.cpp.

{
  JSContext *cx = nsnull;

  // Try really hard to find a context to work on.
  nsIScriptContext *context = aOldScope->GetContext();
  if (context) {
    cx = NS_STATIC_CAST(JSContext *, context->GetNativeContext());
  }

  if (!cx) {
    context = aNewScope->GetContext();
    if (context) {
      cx = NS_STATIC_CAST(JSContext *, context->GetNativeContext());
    }

    if (!cx) {
      sThreadJSContextStack->Peek(&cx);

      if (!cx) {
        sThreadJSContextStack->GetSafeJSContext(&cx);

        if (!cx) {
          // Wow, this is really bad!
          NS_WARNING("No context reachable in ReparentContentWrappers()!");

          return NS_ERROR_NOT_AVAILABLE;
        }
      }
    }
  }

  // Now that we have a context, let's get the global objects from the two
  // scopes and ask XPConnect to do the rest of the work.

  JSObject *oldScopeObj = aOldScope->GetGlobalJSObject();
  JSObject *newScopeObj = aNewScope->GetGlobalJSObject();

  if (!newScopeObj || !oldScopeObj) {
    // We can't really do anything without the JSObjects.

    return NS_ERROR_NOT_AVAILABLE;
  }

  nsCOMPtr<nsIXPConnect_MOZILLA_1_8_BRANCH> xpconnect18 =
    do_QueryInterface(sXPConnect);
  if (!xpconnect18) {
    NS_ERROR("Weird things are happening in XPConnect");
    return NS_ERROR_FAILURE;
  }
  return xpconnect18->ReparentScopeAwareWrappers(cx, oldScopeObj, newScopeObj);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::ReportToConsole ( PropertiesFile  aFile,
const char *  aMessageName,
const PRUnichar **  aParams,
PRUint32  aParamsLength,
nsIURI aURI,
const nsAFlatString aSourceLine,
PRUint32  aLineNumber,
PRUint32  aColumnNumber,
PRUint32  aErrorFlags,
const char *  aCategory 
) [static]

Definition at line 2483 of file nsContentUtils.cpp.

{
  nsresult rv;
  if (!sConsoleService) { // only need to bother null-checking here
    rv = CallGetService(NS_CONSOLESERVICE_CONTRACTID, &sConsoleService);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  nsXPIDLString errorText;
  rv = FormatLocalizedString(aFile, aMessageName, aParams, aParamsLength,
                             errorText);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString spec;
  if (aURI)
    aURI->GetSpec(spec);

  nsCOMPtr<nsIScriptError> errorObject =
      do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = errorObject->Init(errorText.get(),
                         NS_ConvertUTF8toUTF16(spec).get(), // file name
                         aSourceLine.get(),
                         aLineNumber, aColumnNumber,
                         aErrorFlags, aCategory);
  NS_ENSURE_SUCCESS(rv, rv);

  return sConsoleService->LogMessage(errorObject);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reverses the document position flags passed in.

Parameters:
aDocumentPositionThe document position flags to be reversed.
Returns:
The reversed document position flags.
See also:
nsIDOMNode
nsIDOM3Node

Definition at line 1412 of file nsContentUtils.cpp.

{
  // Disconnected and implementation-specific flags cannot be reversed.
  // Keep them.
  PRUint16 reversedPosition =
    aDocumentPosition & (nsIDOM3Node::DOCUMENT_POSITION_DISCONNECTED |
                         nsIDOM3Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC);

  // Following/preceding
  if (aDocumentPosition & nsIDOM3Node::DOCUMENT_POSITION_FOLLOWING) {
    reversedPosition |= nsIDOM3Node::DOCUMENT_POSITION_PRECEDING;
  }
  else if (aDocumentPosition & nsIDOM3Node::DOCUMENT_POSITION_PRECEDING) {
    reversedPosition |= nsIDOM3Node::DOCUMENT_POSITION_FOLLOWING;
  }

  // Is contained/contains.
  if (aDocumentPosition & nsIDOM3Node::DOCUMENT_POSITION_CONTAINS) {
    reversedPosition |= nsIDOM3Node::DOCUMENT_POSITION_CONTAINED_BY;
  }
  else if (aDocumentPosition & nsIDOM3Node::DOCUMENT_POSITION_CONTAINED_BY) {
    reversedPosition |= nsIDOM3Node::DOCUMENT_POSITION_CONTAINS;
  }

  return reversedPosition;
}
void nsContentUtils::SplitExpatName ( const PRUnichar aExpatName,
nsIAtom **  aPrefix,
nsIAtom **  aTagName,
PRInt32 aNameSpaceID 
) [static]

Expat can send the following: localName namespaceURI<separator>localName namespaceURI<separator>localName<separator>prefix

and we use 0xFFFF for the <separator>.

Definition at line 1930 of file nsContentUtils.cpp.

{
  const PRUnichar *uriEnd = nsnull;
  const PRUnichar *nameEnd = nsnull;
  const PRUnichar *pos;
  for (pos = aExpatName; *pos; ++pos) {
    if (*pos == 0xFFFF) {
      if (uriEnd) {
        nameEnd = pos;
      }
      else {
        uriEnd = pos;
      }
    }
  }

  const PRUnichar *nameStart;
  if (uriEnd) {
    if (sNameSpaceManager) {
      sNameSpaceManager->RegisterNameSpace(nsDependentSubstring(aExpatName,
                                                                uriEnd),
                                           *aNameSpaceID);
    }
    else {
      *aNameSpaceID = kNameSpaceID_Unknown;
    }

    nameStart = (uriEnd + 1);
    if (nameEnd)  {
      const PRUnichar *prefixStart = nameEnd + 1;
      *aPrefix = NS_NewAtom(NS_ConvertUTF16toUTF8(prefixStart,
                                                  pos - prefixStart));
    }
    else {
      nameEnd = pos;
      *aPrefix = nsnull;
    }
  }
  else {
    *aNameSpaceID = kNameSpaceID_None;
    nameStart = aExpatName;
    nameEnd = pos;
    *aPrefix = nsnull;
  }
  *aLocalName = NS_NewAtom(NS_ConvertUTF16toUTF8(nameStart,
                                                 nameEnd - nameStart));
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsContentUtils::SplitQName ( nsIContent aNamespaceResolver,
const nsAFlatString aQName,
PRInt32 aNamespace,
nsIAtom **  aLocalName 
) [static]

Definition at line 1816 of file nsContentUtils.cpp.

{
  nsIParserService* parserService = GetParserServiceWeakRef();
  NS_ENSURE_TRUE(parserService, NS_ERROR_FAILURE);

  const PRUnichar* colon;
  nsresult rv = parserService->CheckQName(aQName, PR_TRUE, &colon);
  NS_ENSURE_SUCCESS(rv, rv);

  if (colon) {
    const PRUnichar* end;
    aQName.EndReading(end);
    nsAutoString nameSpace;
    rv = LookupNamespaceURI(aNamespaceResolver, Substring(aQName.get(), colon),
                            nameSpace);
    NS_ENSURE_SUCCESS(rv, rv);

    GetNSManagerWeakRef()->GetNameSpaceID(nameSpace, aNamespace);
    if (*aNamespace == kNameSpaceID_Unknown)
      return NS_ERROR_FAILURE;

    *aLocalName = NS_NewAtom(Substring(colon + 1, end));
  }
  else {
    *aNamespace = kNameSpaceID_None;
    *aLocalName = NS_NewAtom(aQName);
  }
  NS_ENSURE_TRUE(aLocalName, NS_ERROR_OUT_OF_MEMORY);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const nsDependentSubstring nsContentUtils::TrimCharsInSet ( const char *  aSet,
const nsAString &  aValue 
) [static]

This method strips leading/trailing chars, in given set, from string.

Definition at line 1459 of file nsContentUtils.cpp.

{
  nsAString::const_iterator valueCurrent, valueEnd;

  aValue.BeginReading(valueCurrent);
  aValue.EndReading(valueEnd);

  // Skip charaters in the beginning
  while (valueCurrent != valueEnd) {
    if (!IsCharInSet(aSet, *valueCurrent)) {
      break;
    }
    ++valueCurrent;
  }

  if (valueCurrent != valueEnd) {
    for (;;) {
      --valueEnd;
      if (!IsCharInSet(aSet, *valueEnd)) {
        break;
      }
    }
    ++valueEnd; // Step beyond the last character we want in the value.
  }

  // valueEnd should point to the char after the last to copy
  return Substring(valueCurrent, valueEnd);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const nsDependentSubstring nsContentUtils::TrimWhitespace ( const nsAString &  aStr,
PRBool  aTrimTrailing = PR_TRUE 
) [static]

This method strips leading and trailing whitespace from a string.

Definition at line 1495 of file nsContentUtils.cpp.

{
  nsAString::const_iterator start, end;

  aStr.BeginReading(start);
  aStr.EndReading(end);

  // Skip whitespace charaters in the beginning
  while (start != end && nsCRT::IsAsciiSpace(*start)) {
    ++start;
  }

  if (aTrimTrailing) {
    // Skip whitespace characters in the end.
    while (end != start) {
      --end;

      if (!nsCRT::IsAsciiSpace(*end)) {
        // Step back to the last non-whitespace character.
        ++end;

        break;
      }
    }
  }

  // Return a substring for the string w/o leading and/or trailing
  // whitespace

  return Substring(start, end);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsContentUtils::UnregisterPrefCallback ( const char *  aPref,
PrefChangedFunc  aCallback,
void aClosure 
) [static]

Definition at line 2297 of file nsContentUtils.cpp.

{
  if (sPref)
    sPref->UnregisterCallback(aPref, aCallback, aClosure);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIXPConnect* nsContentUtils::XPConnect ( ) [inline, static]

Return the nsIXPConnect service.

Definition at line 529 of file nsContentUtils.h.

  {
    return sXPConnect;
  }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 684 of file nsContentUtils.h.

Definition at line 660 of file nsContentUtils.h.

Definition at line 682 of file nsContentUtils.h.

Definition at line 698 of file nsContentUtils.h.

Definition at line 672 of file nsContentUtils.h.

Definition at line 694 of file nsContentUtils.h.

Definition at line 670 of file nsContentUtils.h.

Definition at line 668 of file nsContentUtils.h.

nsIPref * nsContentUtils::sPref = nsnull [static, private]

Definition at line 680 of file nsContentUtils.h.

Definition at line 678 of file nsContentUtils.h.

Definition at line 690 of file nsContentUtils.h.

Definition at line 696 of file nsContentUtils.h.

Definition at line 695 of file nsContentUtils.h.

Definition at line 664 of file nsContentUtils.h.

Definition at line 687 of file nsContentUtils.h.

Definition at line 686 of file nsContentUtils.h.

Definition at line 666 of file nsContentUtils.h.

Definition at line 662 of file nsContentUtils.h.


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