Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsDOMStorageList Class Reference

#include <nsDOMStorage.h>

Inheritance diagram for nsDOMStorageList:
Inheritance graph
[legend]
Collaboration diagram for nsDOMStorageList:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsDOMStorageList ()
virtual ~nsDOMStorageList ()
nsIDOMStorage namedItem (in DOMString domain)
 Returns a storage object for a particular domain.

Static Public Member Functions

NS_DECL_ISUPPORTS static
NS_DECL_NSIDOMSTORAGELIST
PRBool 
CanAccessDomain (const nsAString &aRequestedDomain, const nsAString &aCurrentDomain)
 Check whether aCurrentDomain has access to aRequestedDomain.

Protected Member Functions

nsresult GetStorageForDomain (nsIURI *aURI, const nsAString &aRequestedDomain, const nsAString &aCurrentDomain, PRBool aNoCurrentDomainCheck, nsIDOMStorage **aStorage)
 Return the global nsIDOMStorage for a particular domain.

Static Protected Member Functions

static PRBool ConvertDomainToArray (const nsAString &aDomain, nsStringArray *aArray)
 Convert the domain into an array of its component parts.

Protected Attributes

nsInterfaceHashtable
< nsStringHashKey,
nsIDOMStorage
mStorages

Detailed Description

Definition at line 196 of file nsDOMStorage.h.


Constructor & Destructor Documentation

Definition at line 199 of file nsDOMStorage.h.

  {
    mStorages.Init();
  };

Here is the call graph for this function:

virtual nsDOMStorageList::~nsDOMStorageList ( ) [inline, virtual]

Definition at line 204 of file nsDOMStorage.h.

{};

Member Function Documentation

PRBool nsDOMStorageList::CanAccessDomain ( const nsAString &  aRequestedDomain,
const nsAString &  aCurrentDomain 
) [static]

Check whether aCurrentDomain has access to aRequestedDomain.

Definition at line 893 of file nsDOMStorage.cpp.

{
  PRNetAddr address;
  PRStatus status = PR_StringToNetAddr(NS_ConvertUTF16toUTF8(aCurrentDomain).get(), &address);

  if (status == PR_SUCCESS) {
    // An IP address must match exactly. IPv6: when location is e.g. "::1" and we require
    // "0:0:0:0:0:1" then access will be denied. 
    return aRequestedDomain == aCurrentDomain;
  }

  nsStringArray requestedDomainArray, currentDomainArray;
  PRBool ok = ConvertDomainToArray(aRequestedDomain, &requestedDomainArray);
  if (!ok)
    return PR_FALSE;

  ok = ConvertDomainToArray(aCurrentDomain, &currentDomainArray);
  if (!ok)
    return PR_FALSE;

  if (currentDomainArray.Count() == 1)
    currentDomainArray.AppendString(NS_LITERAL_STRING("localdomain"));

  // need to use the shorter of the two arrays
  PRInt32 currentPos = 0;
  PRInt32 requestedPos = 0;
  PRInt32 length = requestedDomainArray.Count();
  if (currentDomainArray.Count() > length)
    currentPos = currentDomainArray.Count() - length;
  else if (currentDomainArray.Count() < length)
    requestedPos = length - currentDomainArray.Count();

  // If the current domain is different in any of the parts from the
  // requested domain, a security exception is raised
  for (; requestedPos < length; requestedPos++, currentPos++) {
    if (*requestedDomainArray[requestedPos] != *currentDomainArray[currentPos])
      return PR_FALSE;
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsDOMStorageList::ConvertDomainToArray ( const nsAString &  aDomain,
nsStringArray *  aArray 
) [static, protected]

Convert the domain into an array of its component parts.

Definition at line 988 of file nsDOMStorage.cpp.

{
  PRInt32 length = aDomain.Length();
  PRInt32 n = 0;
  while (n < length) {
    PRInt32 dotpos = aDomain.FindChar('.', n);
    nsAutoString domain;

    if (dotpos == -1) // no more dots
      domain.Assign(Substring(aDomain, n));
    else if (dotpos - n == 0) // no point continuing in this case
      return false;
    else if (dotpos >= 0)
      domain.Assign(Substring(aDomain, n, dotpos - n));

    ToLowerCase(domain);
    aArray->AppendString(domain);

    if (dotpos == -1)
      break;

    n = dotpos + 1;
  }

  // if n equals the length, there is a dot at the end, so treat it as invalid
  return (n != length);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDOMStorageList::GetStorageForDomain ( nsIURI aURI,
const nsAString &  aRequestedDomain,
const nsAString &  aCurrentDomain,
PRBool  aNoCurrentDomainCheck,
nsIDOMStorage **  aStorage 
) [protected]

Return the global nsIDOMStorage for a particular domain.

aNoCurrentDomainCheck may be true to skip the domain comparison; this is used for chrome code so that it may retrieve data from any domain.

Parameters:
aRequestedDomaindomain to return
aCurrentDomaindomain of current caller
aNoCurrentDomainChecktrue to skip domain comparison

Definition at line 937 of file nsDOMStorage.cpp.

{
  // fail if the domain contains no periods.
  // XXXndeakin update this when bug 342314 is fixed so that we can check
  // for top-level domain names properly
  nsAutoString trimmedDomain(aRequestedDomain);
  trimmedDomain.Trim(".");
  if (trimmedDomain.FindChar('.') == kNotFound)
    return NS_ERROR_DOM_SECURITY_ERR;

  if (!aNoCurrentDomainCheck && !CanAccessDomain(aRequestedDomain,
                                                 aCurrentDomain)) {
    return NS_ERROR_DOM_SECURITY_ERR;
  }

  nsStringArray requestedDomainArray;
  PRBool ok = ConvertDomainToArray(aRequestedDomain, &requestedDomainArray);
  if (!ok)
    return NS_ERROR_DOM_SECURITY_ERR;
  
  // now rebuild a string for the domain.
  nsAutoString usedDomain;
  PRInt32 requestedPos = 0;
  for (requestedPos = 0; requestedPos < requestedDomainArray.Count();
       requestedPos++) {
    if (!usedDomain.IsEmpty())
      usedDomain.AppendLiteral(".");
    usedDomain.Append(*requestedDomainArray[requestedPos]);
  }

  // now have a valid domain, so look it up in the storage table
  if (!mStorages.Get(usedDomain, aStorage)) {
    nsCOMPtr<nsIDOMStorage> newstorage = new nsDOMStorage(aURI, usedDomain, PR_TRUE);
    if (!newstorage)
      return NS_ERROR_OUT_OF_MEMORY;

    if (!mStorages.Put(usedDomain, newstorage))
      return NS_ERROR_OUT_OF_MEMORY;

    newstorage.swap(*aStorage);
  }

  return NS_OK;
}

Here is the call graph for this function:

nsIDOMStorage nsIDOMStorageList::namedItem ( in DOMString  domain) [inherited]

Returns a storage object for a particular domain.

Parameters:
domaindomain to retrieve
Returns:
a storage area for the given domain

Member Data Documentation

Definition at line 245 of file nsDOMStorage.h.


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