Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsDOMStorage.cpp File Reference
#include "prnetdb.h"
#include "nsCOMPtr.h"
#include "nsDOMError.h"
#include "nsDOMClassInfo.h"
#include "nsUnicharUtils.h"
#include "nsIDocument.h"
#include "nsDOMStorage.h"
#include "nsContentUtils.h"
#include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h"
#include "nsIURI.h"
#include "nsReadableUtils.h"
#include "nsIObserverService.h"
#include "nsIJARURI.h"
#include "nsIPrefBranch.h"
#include "nsICookiePermission.h"
#include "nsIPermissionManager.h"

Go to the source code of this file.

Classes

class  ItemCounterState
class  IndexFinderData
struct  KeysArrayBuilderStruct

Functions

static PRBool IsCallerSecure ()
static PRInt32 GetQuota (const nsAString &domain)
 ClearStorage (nsDOMStorageEntry *aEntry, void *userArg)
NS_INTERFACE_MAP_END NS_IMETHODIMP NS_NewDOMStorage (nsISupports *aOuter, REFNSIID aIID, void **aResult)
 ItemCounter (nsSessionStorageEntry *aEntry, void *userArg)
 IndexFinder (nsSessionStorageEntry *aEntry, void *userArg)
 ClearStorageItem (nsSessionStorageEntry *aEntry, void *userArg)
 CopyStorageItems (nsSessionStorageEntry *aEntry, void *userArg)
 KeysArrayBuilder (nsSessionStorageEntry *aEntry, void *userArg)
nsresult NS_NewDOMStorageList (nsIDOMStorageList **aResult)

Variables

static const PRUint32 ASK_BEFORE_ACCEPT = 1
static const PRUint32 ACCEPT_SESSION = 2
static const PRUint32 BEHAVIOR_REJECT = 2
static const PRUint32 DEFAULT_QUOTA = 5 * 1024
static const char kPermissionType [] = "cookie"
static const char kStorageEnabled [] = "dom.storage.enabled"
static const char kDefaultQuota [] = "dom.storage.default_quota"
static const char kCookiesBehavior [] = "network.cookie.cookieBehavior"
static const char kCookiesLifetimePolicy [] = "network.cookie.lifetimePolicy"

Class Documentation

struct KeysArrayBuilderStruct

Definition at line 788 of file nsDOMStorage.cpp.

Collaboration diagram for KeysArrayBuilderStruct:
Class Members
PRBool callerIsSecure
nsTArray< nsString > * keys

Function Documentation

ClearStorage ( nsDOMStorageEntry aEntry,
void userArg 
)

Definition at line 173 of file nsDOMStorage.cpp.

{
  aEntry->mStorage->ClearAll();
  return PL_DHASH_REMOVE;
}
ClearStorageItem ( nsSessionStorageEntry aEntry,
void userArg 
)

Definition at line 742 of file nsDOMStorage.cpp.

{
  aEntry->mItem->SetValueInternal(EmptyString());
  return PL_DHASH_NEXT;
}

Here is the caller graph for this function:

CopyStorageItems ( nsSessionStorageEntry aEntry,
void userArg 
)

Definition at line 755 of file nsDOMStorage.cpp.

{
  nsDOMStorage* newstorage = NS_STATIC_CAST(nsDOMStorage*, userArg);

  newstorage->SetItem(aEntry->GetKey(), aEntry->mItem->GetValueInternal());

  if (aEntry->mItem->IsSecure()) {
    newstorage->SetSecure(aEntry->GetKey(), PR_TRUE);
  }

  return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRInt32 GetQuota ( const nsAString &  domain) [static]

Definition at line 112 of file nsDOMStorage.cpp.

{
  // FIXME: per-domain quotas?
  return ((PRInt32)nsContentUtils::GetIntPref(kDefaultQuota, DEFAULT_QUOTA) * 1024);
}

Here is the call graph for this function:

Here is the caller graph for this function:

IndexFinder ( nsSessionStorageEntry aEntry,
void userArg 
)

Definition at line 406 of file nsDOMStorage.cpp.

{
  IndexFinderData *data = (IndexFinderData *)userArg;

  if (data->mIndex == data->mWantedIndex &&
      (data->mIsCallerSecure || !aEntry->mItem->IsSecure())) {
    data->mItem = aEntry;

    return PL_DHASH_STOP;
  }

  ++data->mIndex;

  return PL_DHASH_NEXT;
}
static PRBool IsCallerSecure ( ) [static]

Definition at line 75 of file nsDOMStorage.cpp.

{
  nsCOMPtr<nsIPrincipal> subjectPrincipal;
  nsContentUtils::GetSecurityManager()->
    GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));

  if (!subjectPrincipal) {
    // No subject principal means no code is running. Default to not
    // being secure in that case.

    return PR_FALSE;
  }

  nsCOMPtr<nsIURI> codebase;
  subjectPrincipal->GetURI(getter_AddRefs(codebase));

  if (!codebase) {
    return PR_FALSE;
  }

  nsCOMPtr<nsIJARURI> jarURI;
  nsCOMPtr<nsIURI> innerUri(codebase);
  while((jarURI = do_QueryInterface(innerUri))) {
    jarURI->GetJARFile(getter_AddRefs(innerUri));
  }

  if (!innerUri) {
    return PR_FALSE;
  }

  PRBool isHttps = PR_FALSE;
  nsresult rv = innerUri->SchemeIs("https", &isHttps);

  return NS_SUCCEEDED(rv) && isHttps;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ItemCounter ( nsSessionStorageEntry aEntry,
void userArg 
)

Definition at line 358 of file nsDOMStorage.cpp.

{
  ItemCounterState *state = (ItemCounterState *)userArg;

  if (state->mIsCallerSecure || !aEntry->mItem->IsSecure()) {
    ++state->mCount;
  }

  return PL_DHASH_NEXT;
}
KeysArrayBuilder ( nsSessionStorageEntry aEntry,
void userArg 
)

Definition at line 795 of file nsDOMStorage.cpp.

{
  KeysArrayBuilderStruct *keystruct = (KeysArrayBuilderStruct *)userArg;
  
  if (keystruct->callerIsSecure || !aEntry->mItem->IsSecure())
    keystruct->keys->AppendElement(aEntry->GetKey());

  return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_INTERFACE_MAP_END NS_IMETHODIMP NS_NewDOMStorage ( nsISupports *  aOuter,
REFNSIID  aIID,
void **  aResult 
)

Definition at line 247 of file nsDOMStorage.cpp.

{
  nsDOMStorage* storage = new nsDOMStorage();
  if (!storage)
    return NS_ERROR_OUT_OF_MEMORY;

  NS_ADDREF(storage);
  *aResult = storage;

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 1018 of file nsDOMStorage.cpp.

{
  *aResult = new nsDOMStorageList();
  if (!*aResult)
    return NS_ERROR_OUT_OF_MEMORY;

  NS_ADDREF(*aResult);
  return NS_OK;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 59 of file nsDOMStorage.cpp.

Definition at line 58 of file nsDOMStorage.cpp.

Definition at line 60 of file nsDOMStorage.cpp.

const PRUint32 DEFAULT_QUOTA = 5 * 1024 [static]

Definition at line 62 of file nsDOMStorage.cpp.

const char kCookiesBehavior[] = "network.cookie.cookieBehavior" [static]

Definition at line 67 of file nsDOMStorage.cpp.

const char kCookiesLifetimePolicy[] = "network.cookie.lifetimePolicy" [static]

Definition at line 68 of file nsDOMStorage.cpp.

const char kDefaultQuota[] = "dom.storage.default_quota" [static]

Definition at line 66 of file nsDOMStorage.cpp.

const char kPermissionType[] = "cookie" [static]

Definition at line 64 of file nsDOMStorage.cpp.

const char kStorageEnabled[] = "dom.storage.enabled" [static]

Definition at line 65 of file nsDOMStorage.cpp.