[tor-commits] [torbutton/master] Bug 8457: Tie session store blocking to disk pref

mikeperry at torproject.org mikeperry at torproject.org
Mon Apr 22 23:30:44 UTC 2013


commit 0239dd9f207b1d9885f119e0bc29852f949e9bfd
Author: Mike Perry <mikeperry-git at fscked.org>
Date:   Mon Apr 8 17:38:51 2013 -0700

    Bug 8457: Tie session store blocking to disk pref
---
 src/components/tbSessionStore.js |  125 +------------------------------------
 1 files changed, 4 insertions(+), 121 deletions(-)

diff --git a/src/components/tbSessionStore.js b/src/components/tbSessionStore.js
index 284a5cc..039e223 100644
--- a/src/components/tbSessionStore.js
+++ b/src/components/tbSessionStore.js
@@ -31,19 +31,6 @@ function TBSessionBlocker() {
     this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
         .getService(Components.interfaces.nsIPrefBranch);
 
-    // Determine if we are firefox 4 or not.. The session store formats broke
-    // in a backwards-incompatible way.
-    var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
-        .getService(Components.interfaces.nsIXULAppInfo);
-    var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
-        .getService(Components.interfaces.nsIVersionComparator);
-
-    if(versionChecker.compare(appInfo.version, "4.0a1") >= 0) {
-        this.is_ff4 = true;
-    } else {
-        this.is_ff4 = false;
-    }
-
     this.wrappedJSObject = this;
 }
 
@@ -106,122 +93,18 @@ TBSessionBlocker.prototype =
       // 
       // Simply block sessionstore writes entirely in Tor Browser
       try {
-        if (this.prefs.getCharPref("torbrowser.version")) {
+        if (this.prefs.getBoolPref("extensions.torbutton.block_disk")) {
           this.logger.log(3, "Blocking SessionStore write in Tor Browser");
           subject.data = null;
           return;
         }
       } catch(e) {
+          this.logger.log(5, "Error blocking SessionStore write in Tor Browser: "+e);
       }
 
-      // End 1506. Rest of this function can be ignored.
-
-      this.logger.log(2, "Parsing JSON: "+subject);
-
-      var state = this._safeJSONparse(subject);
-      if (!"windows" in state) {
-        this.logger.log(4, "Got a session store write but with no windows?");
-        return;
-      }
-      var bypass_tor = this.prefs.getBoolPref("extensions.torbutton.notor_sessionstore");
-      var bypass_nontor = this.prefs.getBoolPref("extensions.torbutton.nonontor_sessionstore");
-
-      // This is all debugging and should be removed
-      //this.logger.log(2, "Parsed Session Store: "+state);
-      //this._walkObj("state", state);
-
-      // XXX: It appears that if we filter out everything, firefox quits after restoring the
-      // blank store
-      for (let w in state.windows) {
-         // FIXME: Can we just kill state.windows.0._hosts and cookies?
-         // There seems to be no reason to store either of these in the session store..
-         state.windows[w]._hosts = {};
-         if (state.windows[w].cookies)
-           delete state.windows[w].cookies;
-
-         if (!"tabs" in state.windows[w]) {
-           this.logger.log(4, "Got a session store write for a window with no tabs?");
-           continue;
-         }
-         // Prune state.windows.0.tabs.0.extData.__tb_tor_fetched.0
-         for (let t = state.windows[w].tabs.length - 1; t >= 0; t--) {
-           if ("extData" in state.windows[w].tabs[t]
-               && "__tb_tor_fetched" in state.windows[w].tabs[t].extData) {
-             if((bypass_tor
-                 && state.windows[w].tabs[t].extData.__tb_tor_fetched == "true") ||
-                (bypass_nontor
-                 && state.windows[w].tabs[t].extData.__tb_tor_fetched == "false")) {
-               this.logger.log(3,
-                    "Blocking session store save of tab from opposite tor state:"
-                     +bypass_tor+", "+state.windows[w].tabs[t].extData.__tb_tor_fetched+", "
-                     +bypass_nontor+", "+state.windows[w].tabs[t].extData.__tb_tor_fetched);
-               state.windows[w].tabs.splice(t,1);
-             }
-           } else {
-             this.logger.log(4, "Got a tab with no extension data?");
-           }
-         }
-         if (!"_closedTabs" in state.windows[w]) {
-           this.logger.log(3, "Window has no closed tabs");
-           continue;
-         }
-         // Prune state.windows.0._closedTabs.0.state.extData.__tb_tor_fetched.1
-         for (let t = state.windows[w]._closedTabs.length - 1; t >= 0; t--) {
-           if ("extData" in state.windows[w]._closedTabs[t].state
-                   && "__tb_tor_fetched" in state.windows[w]._closedTabs[t].state.extData) {
-             if((bypass_tor
-                 && state.windows[w]._closedTabs[t].state.extData.__tb_tor_fetched == "true") ||
-                (bypass_nontor
-                 && state.windows[w]._closedTabs[t].state.extData.__tb_tor_fetched == "false")) {
-               this.logger.log(3, "Blocking session store save of closed tab from opposite tor state.");
-               state.windows[w]._closedTabs.splice(t,1);
-             }
-           } else {
-             this.logger.log(4, "Got a tab with no extension data?");
-           }
-         }
-      }
-      subject.data = this._toJSONString(state);
-      this.logger.log(2, "Filtered Session Store JSON: "+subject);
-
-      // This is all debugging and should be removed
-      //var state = this._safeJSONparse(subject);
-      //this.logger.log(2, "Parsed Session Store: "+state);
-      //this._walkObj("state", state);
-  },
-
-  _safeJSONparse: function(aStr) {
-    if (this.is_ff4) {
-      return JSON.parse(aStr);
-    } else {
-      return Cu.evalInSandbox(aStr, new Cu.Sandbox("about:blank"));
-    }
-  },
-
-  /**
-   * Converts a JavaScript object into a JSON string
-   * (see http://www.json.org/ for more information).
-   *
-   * This method is hacked due to bug 485563...
-   */
-  _toJSONString: function(aJSObject) {
-    // XXXzeniko drop the following keys used only for internal bookkeeping:
-    //           _tabStillLoading, _hosts, _formDataSaved
-    if (this.is_ff4) {
-      return JSON.stringify(aJSObject);
-    } else {
-      let jsonString = JSON.stringify(aJSObject);
-
-      if (/[\u2028\u2029]/.test(jsonString)) {
-        // work-around for bug 485563 until we can use JSON.parse
-        // instead of evalInSandbox everywhere
-        jsonString = jsonString.replace(/[\u2028\u2029]/g,
-                                        function($0) "\\u" + $0.charCodeAt(0).toString(16));
-      }
-
-      return "("+jsonString+")";
-    }
+      return;
   }
+
 };
 
 /**





More information about the tor-commits mailing list