Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
mozXMLTermUtils Class Reference

#include <mozXMLTermUtils.h>

List of all members.

Static Public Member Functions

static NS_EXPORT nsresult ConvertDocShellToDOMWindow (nsIDocShell *aDocShell, nsIDOMWindowInternal **aDOMWindow)
 Gets DOM window for doc shell.
static NS_EXPORT nsresult ConvertDOMWindowToDocShell (nsIDOMWindowInternal *aDOMWindow, nsIDocShell **aDocShell)
 Gets doc shell for DOM window.
static NS_EXPORT nsresult GetInnerDOMWindow (nsIDOMWindowInternal *outerDOMWindow, const nsString &innerFrameName, nsIDOMWindowInternal **innerDOMWindow)
 Locates named inner DOM window (frame) inside outer DOM window.
static NS_EXPORT nsresult GetPresContextScrollableView (nsPresContext *aPresContext, nsIScrollableView **aScrollableView)
 Gets the scrollable view for presentation context.
static NS_EXPORT nsresult GetPresContextDeviceContext (nsPresContext *aPresContext, nsIDeviceContext **aDeviceContext)
 Gets the device context for presentation context.
static NS_EXPORT nsresult GetScriptContext (nsIDOMDocument *aDOMDocument, nsIScriptContext **aScriptContext)
 Gets the script context for document.
static NS_EXPORT nsresult ExecuteScript (nsIDOMDocument *aDOMDocument, const nsString &aScript, nsString &aOutput)
 Executes script in specified document's context.
static NS_EXPORT nsresult GetNodeAttribute (nsIDOMNode *aDOMNode, const char *aAttName, nsString &aAttValue)
 Returns the specified attribute value associated with a DOM node, or a null string if the attribute is not defined, or if the DOM node is not an element.
static NS_EXPORT nsresult TimeStamp (PRInt32 deltaSec, PRTime &lastTime, nsString &aTimeStamp)
 Returns a timestamp string containing the local time, if at least deltaSec seconds have elapsed since the last timestamp.
static NS_EXPORT nsresult RandomCookie (nsString &aCookie)
 Returns a string containing a 11-digit random cookie based upon the current local time and the elapsed execution of the program.

Detailed Description

Definition at line 53 of file mozXMLTermUtils.h.


Member Function Documentation

Gets DOM window for doc shell.

Parameters:
aDocShelldoc shell
aDOMWindowreturned DOM window (frame)
Returns:
NS_OK on success

Definition at line 72 of file mozXMLTermUtils.cpp.

{
  XMLT_LOG(mozXMLTermUtils::ConvertDocShellToDOMWindow,30,("\n"));

  if (!aDOMWindow)
    return NS_ERROR_FAILURE;

  *aDOMWindow = nsnull;

  nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject(do_GetInterface(aDocShell));

  nsCOMPtr<nsIDOMWindowInternal> domWindow(do_QueryInterface(scriptGlobalObject));
  if (!domWindow)
    return NS_ERROR_FAILURE;

  *aDOMWindow = domWindow.get();
  NS_ADDREF(*aDOMWindow);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Gets doc shell for DOM window.

Parameters:
aDOMWindowDOM window (frame)
aDocShellreturned doc shell
Returns:
NS_OK on success

Definition at line 101 of file mozXMLTermUtils.cpp.

{
  XMLT_LOG(mozXMLTermUtils::ConvertDOMWindowToDocShell,30,("\n"));

  nsCOMPtr<nsIScriptGlobalObject> globalObject = do_QueryInterface(aDOMWindow);
  if (!globalObject)
    return NS_ERROR_FAILURE;

  *aDocShell = globalObject->GetDocShell();
  if (!*aDocShell)
    return NS_ERROR_FAILURE;

  NS_ADDREF(*aDocShell);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_EXPORT nsresult mozXMLTermUtils::ExecuteScript ( nsIDOMDocument aDOMDocument,
const nsString aScript,
nsString aOutput 
) [static]

Executes script in specified document's context.

Parameters:
aDOMDocumentdocument providing context for script execution
aScriptstring to be executed
aOutputoutput string produced by script execution
Returns:
NS_OK if script was valid and got executed properly

Definition at line 249 of file mozXMLTermUtils.cpp.

{
  nsresult result;

  XMLT_LOG(mozXMLTermUtils::ExecuteScript,20,("\n"));

  // Get document principal
  nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDocument);
  if (!doc)
    return NS_ERROR_FAILURE;

  nsIPrincipal *docPrincipal = doc->GetPrincipal();
  if (!docPrincipal) 
    return NS_ERROR_FAILURE;

  // Get document script context
  nsCOMPtr<nsIScriptContext> scriptContext;
  result = GetScriptContext(aDOMDocument, getter_AddRefs(scriptContext));
  if (NS_FAILED(result) || !scriptContext)
    return NS_ERROR_FAILURE;

  // Execute script
  PRBool isUndefined = PR_FALSE;
  const char* URL = "";
  result = scriptContext->EvaluateString(aScript, (void *) nsnull,
                                         docPrincipal, URL, 0, nsnull,
                                         &aOutput, &isUndefined);

  XMLT_LOG(mozXMLTermUtils::ExecuteScript,21,("result=0x%x,isUndefined=0x%x\n",
                                             result, isUndefined));

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_EXPORT nsresult mozXMLTermUtils::GetInnerDOMWindow ( nsIDOMWindowInternal outerDOMWindow,
const nsString innerFrameName,
nsIDOMWindowInternal **  innerDOMWindow 
) [static]

Locates named inner DOM window (frame) inside outer DOM window.

Parameters:
outerDOMWindowouter DOM window (frame)
innerFrameNamename of inner frame to be returned
innerDOMWindowreturned inner DOM window (frame)
Returns:
NS_OK on success

Definition at line 127 of file mozXMLTermUtils.cpp.

{
  nsresult result;

  XMLT_LOG(mozXMLTermUtils::GetInnerDOMWindow,30,("\n"));

  nsCOMPtr<nsIDOMWindowCollection> innerDOMWindowList;
  result = outerDOMWindow->GetFrames(getter_AddRefs(innerDOMWindowList));
  if (NS_FAILED(result) || !innerDOMWindowList)
    return NS_ERROR_FAILURE;

  PRUint32 frameCount = 0;
  result = innerDOMWindowList->GetLength(&frameCount);
  XMLT_LOG(mozXMLTermUtils::GetInnerDOMWindow,31,("frameCount=%d\n",
                                                   frameCount));

  result = innerDOMWindowList->NamedItem(innerFrameName, (nsIDOMWindow **)innerDOMWindow);
  if (NS_FAILED(result) || !*innerDOMWindow)
    return NS_ERROR_FAILURE;

  return NS_OK;
}

Here is the call graph for this function:

NS_EXPORT nsresult mozXMLTermUtils::GetNodeAttribute ( nsIDOMNode aDOMNode,
const char *  aAttName,
nsString aAttValue 
) [static]

Returns the specified attribute value associated with a DOM node, or a null string if the attribute is not defined, or if the DOM node is not an element.

Parameters:
aDOMNodenode whose attribute is to be determined
aAttNameattribute to be determined
aAttValueoutput attribute value
Returns:
NS_OK if no errors occurred
Parameters:
aDOMNodenode whose attribute is to be determined
aAttNameattribute to be determined. Must be ASCII.
aAttValueoutput attribute value
Returns:
NS_OK if no errors occurred

Definition at line 295 of file mozXMLTermUtils.cpp.

{
  XMLT_LOG(mozXMLTermUtils::GetNodeAttribute,20,("aAttName=%s\n", aAttName));

  nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(aDOMNode);
  if (!domElement) {
    aAttValue.SetLength(0);
    return NS_OK;
  }

  nsAutoString attName;
  attName.AssignASCII(aAttName);
  return domElement->GetAttribute(attName, aAttValue);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Gets the device context for presentation context.

Parameters:
aPresContextpresentation context
aDeviceContextreturned device context
Returns:
NS_OK on success

Definition at line 187 of file mozXMLTermUtils.cpp.

{
  nsresult result;

  XMLT_LOG(mozXMLTermUtils::GetPresContextScrollableView,30,("\n"));

  if (!aDeviceContext)
    return NS_ERROR_FAILURE;

  *aDeviceContext = nsnull;

  nsIViewManager* viewManager = aPresContext->GetViewManager();
  if (!viewManager)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIDeviceContext> deviceContext;
  result = viewManager->GetDeviceContext(*getter_AddRefs(deviceContext));
  if (NS_FAILED(result) || !deviceContext)
    return NS_ERROR_FAILURE;

  *aDeviceContext = deviceContext.get();
  NS_ADDREF(*aDeviceContext);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Gets the scrollable view for presentation context.

Parameters:
aPresContextpresentation context
aScrollableViewreturned scrollable view
Returns:
NS_OK on success

Definition at line 159 of file mozXMLTermUtils.cpp.

{
  XMLT_LOG(mozXMLTermUtils::GetPresContextScrollableView,30,("\n"));

  if (!aScrollableView)
    return NS_ERROR_FAILURE;

  *aScrollableView = nsnull;

  nsIPresShell *presShell = aPresContext->GetPresShell();
  if (!presShell)
    return NS_ERROR_FAILURE;

  nsIViewManager* viewManager = presShell->GetViewManager();
  if (!viewManager)
    return NS_ERROR_FAILURE;

  return viewManager->GetRootScrollableView(aScrollableView);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_EXPORT nsresult mozXMLTermUtils::GetScriptContext ( nsIDOMDocument aDOMDocument,
nsIScriptContext **  aScriptContext 
) [static]

Gets the script context for document.

Parameters:
aDOMDocumentdocument providing context
aScriptContextreturned script context
Returns:
NS_OK on success

Definition at line 221 of file mozXMLTermUtils.cpp.

{
  XMLT_LOG(mozXMLTermUtils::GetScriptContext,20,("\n"));

  nsCOMPtr<nsIDocument> doc ( do_QueryInterface(aDOMDocument) );
  if (!doc)
    return NS_ERROR_FAILURE;

  nsIScriptGlobalObject *scriptGlobalObject = doc->GetScriptGlobalObject();

  if (!scriptGlobalObject)
    return NS_ERROR_FAILURE;

  *aScriptContext = scriptGlobalObject->GetContext();
  NS_IF_ADDREF(*aScriptContext);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Returns a string containing a 11-digit random cookie based upon the current local time and the elapsed execution of the program.

Parameters:
aCookiereturned cookie string
Returns:
NS_OK on success

Definition at line 365 of file mozXMLTermUtils.cpp.

{
  // Current local time
  PRExplodedTime localTime;
  PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &localTime);

  PRInt32        randomNumberA = localTime.tm_sec*1000000+localTime.tm_usec;
  PRIntervalTime randomNumberB = PR_IntervalNow();

  XMLT_LOG(mozXMLTermUtils::RandomCookie,30,("ranA=0x%x, ranB=0x%x\n",
                                        randomNumberA, randomNumberB));
  PR_ASSERT(randomNumberA >= 0);
  PR_ASSERT(randomNumberB >= 0);

  static const char cookieDigits[17] = "0123456789abcdef";
  char cookie[12];
  int j;

  for (j=0; j<6; j++) {
    cookie[j] = cookieDigits[randomNumberA%16];
    randomNumberA = randomNumberA/16;
  }
  for (j=6; j<11; j++) {
    cookie[j] = cookieDigits[randomNumberB%16];
    randomNumberB = randomNumberB/16;
  }
  cookie[11] = '\0';

  aCookie.AssignASCII(cookie);

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP mozXMLTermUtils::TimeStamp ( PRInt32  deltaSec,
PRTime lastTime,
nsString aTimeStamp 
) [static]

Returns a timestamp string containing the local time, if at least deltaSec seconds have elapsed since the last timestamp.

Otherwise, a null string is returned.

Parameters:
deltaSecminimum elapsed seconds since last timestamp (>=0)
lastTimein/out parameter containing time of last timestamp
aTimeStampreturned timestamp string
Returns:
NS_OK on success

Definition at line 321 of file mozXMLTermUtils.cpp.

{
  static const PRInt32 DATE_LEN = 19;
  PRTime deltaTime ;
  char dateStr[DATE_LEN+1];
  PRTime curTime, difTime;

  curTime = PR_Now();
  LL_SUB(difTime, curTime, lastTime);

  LL_I2L(deltaTime, deltaSec*1000000);
  if (LL_CMP(difTime, <, deltaTime)) {
    // Not enough time has elapsed for a new time stamp
    aTimeStamp.SetLength(0);
    return NS_OK;
  }

  lastTime = curTime;

  // Current local time
  PRExplodedTime localTime;
  PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime);

  PRInt32 nWritten = PR_snprintf(dateStr, DATE_LEN+1,
                     "%02d:%02d:%02d %02d/%02d/%04d", // XXX i18n!
                   localTime.tm_hour, localTime.tm_min, localTime.tm_sec,
                   localTime.tm_mday, localTime.tm_month+1, localTime.tm_year);

  if (nWritten != DATE_LEN)
    return NS_ERROR_FAILURE;

  XMLT_LOG(mozXMLTermUtils::LocalTime,99,("localTime=%s\n", dateStr));

  aTimeStamp.AssignASCII(dateStr);
  return NS_OK;
}

Here is the call graph for this function:


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