]> Pileus Git - ~andy/sunrise/blob - www-client/torbrowser/files/0002-Make-Permissions-Manager-memory-only.patch
ecd1e323680c9f1c289e76c2890da234b351c500
[~andy/sunrise] / www-client / torbrowser / files / 0002-Make-Permissions-Manager-memory-only.patch
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
5
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.
9
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.
12
13 https://trac.torproject.org/projects/tor/ticket/2950
14 ---
15  extensions/cookie/nsPermissionManager.cpp |   34 ++++++++++++++++++++++++++--
16  1 files changed, 31 insertions(+), 3 deletions(-)
17
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
22 @@ -58,6 +58,10 @@
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"
30  
31  static nsPermissionManager *gPermissionManager = nsnull;
32  
33 @@ -203,6 +207,11 @@ nsPermissionManager::Init()
34      mObserverService->AddObserver(this, "profile-do-change", true);
35    }
36  
37 +  nsCOMPtr<nsIPrefBranch2> pbi = do_GetService(NS_PREFSERVICE_CONTRACTID);
38 +  if (pbi) {
39 +    pbi->AddObserver("permissions.", this, PR_FALSE);
40 +  }
41 +
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)
46    if (!storage)
47      return NS_ERROR_UNEXPECTED;
48  
49 +  bool memory_db = false;
50 +  nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
51 +  if (prefs) {
52 +    prefs->GetBoolPref("permissions.memory_only", &memory_db); 
53 +  }
54 +
55    // cache a connection to the hosts database
56 -  rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
57 +  if (memory_db) {
58 +    rv = storage->OpenSpecialDatabase("memory", getter_AddRefs(mDBConn));
59 +  } else {
60 +    rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
61 +  }
62    NS_ENSURE_SUCCESS(rv, rv);
63  
64    bool ready;
65 @@ -262,7 +281,11 @@ nsPermissionManager::InitDB(bool aRemoveFile)
66      rv = permissionsFile->Remove(false);
67      NS_ENSURE_SUCCESS(rv, rv);
68  
69 -    rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
70 +    if (memory_db) {
71 +      rv = storage->OpenSpecialDatabase("memory", getter_AddRefs(mDBConn));
72 +    } else {
73 +      rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
74 +    }
75      NS_ENSURE_SUCCESS(rv, rv);
76  
77      mDBConn->GetConnectionReady(&ready);
78 @@ -783,7 +806,12 @@ NS_IMETHODIMP nsPermissionManager::Observe(nsISupports *aSubject, const char *aT
79  {
80    ENSURE_NOT_CHILD_PROCESS;
81  
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..
86 +      InitDB(PR_FALSE);
87 +    }
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())) {
92 -- 
93 1.7.5.4
94