Ticket #2950: memory-permissions.diff

File memory-permissions.diff, 2.5 KB (added by mikeperry, 8 years ago)

Diff against FF4.0.

  • extensions/cookie/nsPermissionManager.cpp

    diff -r f43e15acc6ca extensions/cookie/nsPermissionManager.cpp
    a b  
    6060#include "mozStorageHelper.h"
    6161#include "mozStorageCID.h"
    6262#include "nsXULAppAPI.h"
     63#include "nsCOMPtr.h"
     64#include "nsIPrefService.h"
     65#include "nsIPrefBranch.h"
     66#include "nsIPrefBranch2.h"
    6367
    6468static nsPermissionManager *gPermissionManager = nsnull;
    6569
     
    233237    mObserverService->AddObserver(this, "profile-do-change", PR_TRUE);
    234238  }
    235239
     240  nsCOMPtr<nsIPrefBranch2> pbi = do_GetService(NS_PREFSERVICE_CONTRACTID);
     241  if (pbi) {
     242    pbi->AddObserver("permissions.", this, PR_FALSE);
     243  }
     244
    236245#ifdef MOZ_IPC
    237246  if (IsChildProcess()) {
    238247    // Get the permissions from the parent process
     
    283292  if (!storage)
    284293    return NS_ERROR_UNEXPECTED;
    285294
     295  PRBool memory_db = false;
     296  nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
     297  if (prefs) {
     298    prefs->GetBoolPref("permissions.memory_only", &memory_db);
     299  }
     300
    286301  // cache a connection to the hosts database
    287   rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
     302  if (memory_db) {
     303    rv = storage->OpenSpecialDatabase("memory", getter_AddRefs(mDBConn));
     304  } else {
     305    rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
     306  }
    288307  NS_ENSURE_SUCCESS(rv, rv);
    289308
    290309  PRBool ready;
     
    294313    rv = permissionsFile->Remove(PR_FALSE);
    295314    NS_ENSURE_SUCCESS(rv, rv);
    296315
    297     rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
     316    if (memory_db) {
     317      rv = storage->OpenSpecialDatabase("memory", getter_AddRefs(mDBConn));
     318    } else {
     319      rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
     320    }
    298321    NS_ENSURE_SUCCESS(rv, rv);
    299322
    300323    mDBConn->GetConnectionReady(&ready);
     
    825848  ENSURE_NOT_CHILD_PROCESS;
    826849#endif
    827850
    828   if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
     851  if (nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0) {
     852    if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("permissions.memory_only").get())) {
     853      // XXX: Should we remove the file? Probably not..
     854      InitDB(PR_FALSE);
     855    }
     856  } else if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
    829857    // The profile is about to change,
    830858    // or is going away because the application is shutting down.
    831859    if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {