Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsCookiePermission.cpp File Reference
#include "nsCookiePermission.h"
#include "nsICookie2.h"
#include "nsIServiceManager.h"
#include "nsICookiePromptService.h"
#include "nsICookieManager2.h"
#include "nsNetUtil.h"
#include "nsIURI.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsILoadGroup.h"
#include "nsIChannel.h"
#include "nsIDOMWindow.h"
#include "nsString.h"
#include "nsCRT.h"

Go to the source code of this file.

Defines

#define USEC_PER_SEC   (nsInt64(1000000))
#define NOW_IN_SECONDS   (nsInt64(PR_Now()) / USEC_PER_SEC)
#define PREF_CHANGED(_P)   (!aPref || !strcmp(aPref, _P))

Functions

 NS_IMPL_ISUPPORTS2 (nsCookiePermission, nsICookiePermission, nsIObserver) nsresult nsCookiePermission

Variables

static const PRUint32 ACCEPT_NORMALLY = 0
static const PRUint32 ASK_BEFORE_ACCEPT = 1
static const PRUint32 ACCEPT_SESSION = 2
static const PRUint32 ACCEPT_FOR_N_DAYS = 3
static const PRBool kDefaultPolicy = PR_TRUE
static const char kCookiesLifetimePolicy [] = "network.cookie.lifetimePolicy"
static const char kCookiesLifetimeDays [] = "network.cookie.lifetime.days"
static const char kCookiesAlwaysAcceptSession [] = "network.cookie.alwaysAcceptSessionCookies"
static const char kCookiesPrefsMigrated [] = "network.cookie.prefsMigrated"
static const char kCookiesLifetimeEnabled [] = "network.cookie.lifetime.enabled"
static const char kCookiesLifetimeBehavior [] = "network.cookie.lifetime.behavior"
static const char kCookiesAskPermission [] = "network.cookie.warnAboutCookies"
static const char kPermissionType [] = "cookie"

Define Documentation

Definition at line 93 of file nsCookiePermission.cpp.

#define PREF_CHANGED (   _P)    (!aPref || !strcmp(aPref, _P))
#define USEC_PER_SEC   (nsInt64(1000000))

Definition at line 92 of file nsCookiePermission.cpp.


Function Documentation

Definition at line 111 of file nsCookiePermission.cpp.

{
  nsresult rv;
  mPermMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
  if (NS_FAILED(rv)) return rv;

  // failure to access the pref service is non-fatal...
  nsCOMPtr<nsIPrefBranch2> prefBranch =
      do_GetService(NS_PREFSERVICE_CONTRACTID);
  if (prefBranch) {
    prefBranch->AddObserver(kCookiesLifetimePolicy, this, PR_FALSE);
    prefBranch->AddObserver(kCookiesLifetimeDays, this, PR_FALSE);
    prefBranch->AddObserver(kCookiesAlwaysAcceptSession, this, PR_FALSE);
#ifdef MOZ_MAIL_NEWS
    prefBranch->AddObserver(kCookiesDisabledForMailNews, this, PR_FALSE);
#endif
    PrefChanged(prefBranch, nsnull);

    // migration code for original cookie prefs
    PRBool migrated;
    rv = prefBranch->GetBoolPref(kCookiesPrefsMigrated, &migrated);
    if (NS_FAILED(rv) || !migrated) {
      PRBool warnAboutCookies = PR_FALSE;
      prefBranch->GetBoolPref(kCookiesAskPermission, &warnAboutCookies);

      // if the user is using ask before accepting, we'll use that
      if (warnAboutCookies)
        prefBranch->SetIntPref(kCookiesLifetimePolicy, ASK_BEFORE_ACCEPT);
        
      PRBool lifetimeEnabled = PR_FALSE;
      prefBranch->GetBoolPref(kCookiesLifetimeEnabled, &lifetimeEnabled);
      
      // if they're limiting lifetime and not using the prompts, use the 
      // appropriate limited lifetime pref
      if (lifetimeEnabled && !warnAboutCookies) {
        PRInt32 lifetimeBehavior;
        prefBranch->GetIntPref(kCookiesLifetimeBehavior, &lifetimeBehavior);
        if (lifetimeBehavior)
          prefBranch->SetIntPref(kCookiesLifetimePolicy, ACCEPT_FOR_N_DAYS);
        else
          prefBranch->SetIntPref(kCookiesLifetimePolicy, ACCEPT_SESSION);
      }
      prefBranch->SetBoolPref(kCookiesPrefsMigrated, PR_TRUE);
    }
  }

  return NS_OK;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 72 of file nsCookiePermission.cpp.

Definition at line 69 of file nsCookiePermission.cpp.

Definition at line 71 of file nsCookiePermission.cpp.

Definition at line 70 of file nsCookiePermission.cpp.

const char kCookiesAlwaysAcceptSession[] = "network.cookie.alwaysAcceptSessionCookies" [static]

Definition at line 77 of file nsCookiePermission.cpp.

const char kCookiesAskPermission[] = "network.cookie.warnAboutCookies" [static]

Definition at line 86 of file nsCookiePermission.cpp.

const char kCookiesLifetimeBehavior[] = "network.cookie.lifetime.behavior" [static]

Definition at line 85 of file nsCookiePermission.cpp.

const char kCookiesLifetimeDays[] = "network.cookie.lifetime.days" [static]

Definition at line 76 of file nsCookiePermission.cpp.

const char kCookiesLifetimeEnabled[] = "network.cookie.lifetime.enabled" [static]

Definition at line 84 of file nsCookiePermission.cpp.

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

Definition at line 75 of file nsCookiePermission.cpp.

const char kCookiesPrefsMigrated[] = "network.cookie.prefsMigrated" [static]

Definition at line 82 of file nsCookiePermission.cpp.

Definition at line 74 of file nsCookiePermission.cpp.

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

Definition at line 88 of file nsCookiePermission.cpp.