1 From 193c50c03aa61eef5415d0476467c22941022a11 Mon Sep 17 00:00:00 2001
2 From: Mike Perry <mikeperry-git@torproject.org>
3 Date: Wed, 1 Feb 2012 15:45:16 -0800
4 Subject: [PATCH 02/13] Make Permissions Manager memory-only
6 This patch exposes a pref 'permissions.memory_only' that properly isolates the
7 permissions manager to memory, which is responsible for all user specified
8 site permissions, as well as stored STS policy.
10 The pref does successfully clear the permissions manager memory if toggled. It
11 does not need to be set in prefs.js, and can be handled by Torbutton.
13 https://trac.torproject.org/projects/tor/ticket/2950
15 extensions/cookie/nsPermissionManager.cpp | 34 ++++++++++++++++++++++++++--
16 1 files changed, 31 insertions(+), 3 deletions(-)
18 diff --git a/extensions/cookie/nsPermissionManager.cpp b/extensions/cookie/nsPermissionManager.cpp
19 index 67eb216..12cc7cf 100644
20 --- a/extensions/cookie/nsPermissionManager.cpp
21 +++ b/extensions/cookie/nsPermissionManager.cpp
23 #include "mozStorageHelper.h"
24 #include "mozStorageCID.h"
25 #include "nsXULAppAPI.h"
26 +#include "nsCOMPtr.h"
27 +#include "nsIPrefService.h"
28 +#include "nsIPrefBranch.h"
29 +#include "nsIPrefBranch2.h"
31 static nsPermissionManager *gPermissionManager = nsnull;
33 @@ -203,6 +207,11 @@ nsPermissionManager::Init()
34 mObserverService->AddObserver(this, "profile-do-change", true);
37 + nsCOMPtr<nsIPrefBranch2> pbi = do_GetService(NS_PREFSERVICE_CONTRACTID);
39 + pbi->AddObserver("permissions.", this, PR_FALSE);
42 if (IsChildProcess()) {
43 // Get the permissions from the parent process
44 InfallibleTArray<IPC::Permission> perms;
45 @@ -251,8 +260,18 @@ nsPermissionManager::InitDB(bool aRemoveFile)
47 return NS_ERROR_UNEXPECTED;
49 + bool memory_db = false;
50 + nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
52 + prefs->GetBoolPref("permissions.memory_only", &memory_db);
55 // cache a connection to the hosts database
56 - rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
58 + rv = storage->OpenSpecialDatabase("memory", getter_AddRefs(mDBConn));
60 + rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
62 NS_ENSURE_SUCCESS(rv, rv);
65 @@ -262,7 +281,11 @@ nsPermissionManager::InitDB(bool aRemoveFile)
66 rv = permissionsFile->Remove(false);
67 NS_ENSURE_SUCCESS(rv, rv);
69 - rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
71 + rv = storage->OpenSpecialDatabase("memory", getter_AddRefs(mDBConn));
73 + rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
75 NS_ENSURE_SUCCESS(rv, rv);
77 mDBConn->GetConnectionReady(&ready);
78 @@ -783,7 +806,12 @@ NS_IMETHODIMP nsPermissionManager::Observe(nsISupports *aSubject, const char *aT
80 ENSURE_NOT_CHILD_PROCESS;
82 - if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
83 + if (nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0) {
84 + if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("permissions.memory_only").get())) {
85 + // XXX: Should we remove the file? Probably not..
88 + } else if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
89 // The profile is about to change,
90 // or is going away because the application is shutting down.
91 if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {