[Pkg-mozext-commits] [firebug] 31/68: Manual port of: Issue 6168: Update Firebug to use the new Private Browsing APIs

David Prévot taffit at moszumanska.debian.org
Mon Mar 31 22:45:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to tag fbtest-1.11.4
in repository firebug.

commit abe197064a09911e9c0baa6cc21606e67966c84f
Author: Jan Odvarko <odvarko at gmail.com>
Date:   Fri Mar 29 14:54:42 2013 +0100

    Manual port of: Issue 6168: 	Update Firebug to use the new Private Browsing APIs
---
 extension/content/firebug/chrome/annotations.js    |  2 +
 extension/content/firebug/chrome/privacy.js        | 47 ++++++++++++++----
 .../content/firebug/console/commandLineInclude.js  |  8 ++-
 extension/modules/storageService.js                | 58 +++++++++++++++++++---
 tests/content/lib/storageService.js                |  4 +-
 5 files changed, 98 insertions(+), 21 deletions(-)

diff --git a/extension/content/firebug/chrome/annotations.js b/extension/content/firebug/chrome/annotations.js
index dc52dd1..052f3d0 100644
--- a/extension/content/firebug/chrome/annotations.js
+++ b/extension/content/firebug/chrome/annotations.js
@@ -207,6 +207,8 @@ var Annotations = Obj.extend(Firebug.Module,
 
     resetAllOptions: function()
     {
+        // "Reset all options" removes all annotations even if the browser window
+        // is currently in private mode.
         this.clear();
         this.flush(true);
     }
diff --git a/extension/content/firebug/chrome/privacy.js b/extension/content/firebug/chrome/privacy.js
index d021113..eb57042 100644
--- a/extension/content/firebug/chrome/privacy.js
+++ b/extension/content/firebug/chrome/privacy.js
@@ -11,14 +11,18 @@ function(FBTrace, Obj, Arr, Events) {
 // ********************************************************************************************* //
 // Constants
 
-const Cc = Components.classes;
-const Ci = Components.interfaces;
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
 
 // ********************************************************************************************* //
 
 /**
  * No data should be written if Firefox is set to privatebrowsing.
  * don't forget to check it before access (issue 2923).
+ * 
+ * xxxHonza: as soon as Fx 22 is the min for Firebug most of the methods can be removed.
+ * The most important one will be the isPrivateBrowsing
  */
 var Privacy = Obj.extend(Firebug.Module,
 {
@@ -27,8 +31,8 @@ var Privacy = Obj.extend(Firebug.Module,
         if (this.observerService)
             return;
 
-        this.observerService = Components.classes["@mozilla.org/observer-service;1"]
-            .getService(Components.interfaces.nsIObserverService);
+        this.observerService = Cc["@mozilla.org/observer-service;1"]
+            .getService(Ci.nsIObserverService);
 
         this.observerService.addObserver(this, "private-browsing", false);
 
@@ -44,8 +48,10 @@ var Privacy = Obj.extend(Firebug.Module,
     {
         try
         {
-            var pbs = Components.classes["@mozilla.org/privatebrowsing;1"]
-                .getService(Components.interfaces.nsIPrivateBrowsingService);
+            // xxxHonza: this component has been removed in Firefox 22
+            // https://bugzilla.mozilla.org/show_bug.cgi?id=845063
+            var pbs = Cc["@mozilla.org/privatebrowsing;1"]
+                .getService(Ci.nsIPrivateBrowsingService);
 
             this.privateBrowsingEnabled = pbs.privateBrowsingEnabled;
 
@@ -57,8 +63,10 @@ var Privacy = Obj.extend(Firebug.Module,
         }
         catch (e)
         {
-            if (FBTrace.DBG_ERRORS)
-                FBTrace.sysout("Privacy.update EXCEPTION " + e, e);
+            // nsIPrivateBrowsingService has been removed since Fx 22 so, don't display
+            // the error message.
+            //if (FBTrace.DBG_ERRORS)
+            //    FBTrace.sysout("Privacy.update EXCEPTION " + e, e);
         }
     },
 
@@ -70,8 +78,27 @@ var Privacy = Obj.extend(Firebug.Module,
 
     isPrivateBrowsing: function()
     {
-        return this.privateBrowsingEnabled;
-    },
+        // In case where nsIPrivateBrowsingService still exists and the following
+        // property is properly initialized in update() method (before Fx22)
+        if (typeof this.privateBrowsingEnabled != "undefined")
+            return this.privateBrowsingEnabled;
+
+        try
+        {
+            // For Fx 22+
+            Cu["import"]("resource://gre/modules/PrivateBrowsingUtils.jsm");
+
+            // Get firebugFrame.xul and check privaate mode (it's the same as
+            // for the top parent window).
+            var win = Firebug.chrome.window;
+            return PrivateBrowsingUtils.isWindowPrivate(win);
+        }
+        catch (e)
+        {
+            if (FBTrace.DBG_ERRORS)
+                FBTrace.sysout("Privacy.isPrivateBrowsing; EXCEPTION " + e, e);
+        }
+    }
 });
 
 // ********************************************************************************************* //
diff --git a/extension/content/firebug/console/commandLineInclude.js b/extension/content/firebug/console/commandLineInclude.js
index cffee45..7d30508 100644
--- a/extension/content/firebug/console/commandLineInclude.js
+++ b/extension/content/firebug/console/commandLineInclude.js
@@ -339,7 +339,13 @@ var CommandLineInclude = Obj.extend(Firebug.Module,
     getStore: function()
     {
         if (!this.store)
-            this.store = storageScope.StorageService.getStorage("includeAliases.json");
+        {
+            // Pass also the parent window to the new storage. The window will be
+            // used to figure out whether the browser is running in private mode.
+            // If yes, no data will be persisted.
+            this.store = storageScope.StorageService.getStorage("includeAliases.json",
+                Firebug.chrome.window);
+        }
 
         // let's log when the store could not be opened:
         if (!this.store)
diff --git a/extension/modules/storageService.js b/extension/modules/storageService.js
index 1465b3d..3ab4a56 100644
--- a/extension/modules/storageService.js
+++ b/extension/modules/storageService.js
@@ -16,9 +16,15 @@ var EXPORTED_SYMBOLS = ["Storage", "StorageService", "TextService"];
 Cu.import("resource://firebug/fbtrace.js");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 
+var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
+
 // ********************************************************************************************* //
 // Implementation
 
+// xxxHonza: the entire JSM should be converted into AMD.
+// But there could be extensions
+// see: https://groups.google.com/d/msg/firebug/C5dlQ2S1e0U/ZJ76nxtUAAMJ
+
 /**
  * http://dev.w3.org/html5/webstorage/#storage-0
  * interface Storage {
@@ -30,9 +36,11 @@ Cu.import("resource://gre/modules/FileUtils.jsm");
  *     void clear();
  * };
  */
-function Storage(leafName)
+function Storage(leafName, win)
 {
     this.leafName = leafName;
+    this.win = win;
+
     this.objectTable = {};
 }
 
@@ -104,9 +112,9 @@ Storage.prototype =
  */
 var StorageService =
 {
-    getStorage: function(leafName)
+    getStorage: function(leafName, win)
     {
-        var store = new Storage(leafName);
+        var store = new Storage(leafName, win);
 
         try
         {
@@ -131,10 +139,13 @@ var StorageService =
         if (!store || !store.leafName || !store.objectTable)
             throw new Error("StorageService.setStorage requires Storage Object argument");
 
+        // xxxHonza: writeNow() doesn't check private browsing mode, which is not safe.
+        // But |now| is currently set to true only in clear() method, which works
+        // (and should work I guess) even in private browsing mode.
         if (now)
             ObjectPersister.writeNow(store.leafName,  store.objectTable);
         else
-            ObjectPersister.writeObject(store.leafName,  store.objectTable);
+            ObjectPersister.writeObject(store.leafName,  store.objectTable, store.win);
     },
 
     removeStorage: function(leafName)
@@ -221,9 +232,9 @@ var ObjectPersister =
     // Batch the writes for each event loop
     writeDelay: 250,
 
-    writeObject: function(leafName, obj)
+    writeObject: function(leafName, obj, win)
     {
-        if (this.isPrivateBrowsing())
+        if (this.isPrivateBrowsing(win))
             throw new Error("No storage is written while in private browsing mode");
 
         if (ObjectPersister.flushTimeout)
@@ -294,14 +305,17 @@ var ObjectPersister =
         }
     },
 
-    isPrivateBrowsing: function()
+    // xxxHonza: this entire method is duplicated from firebug/lib/privacy module
+    // As soon as this JSM is AMD we should just use firebug/lib/privacy.
+    isPrivateBrowsing: function(win)
     {
         try
         {
             // Unfortunatelly the "firebug/chrome/privacy" module can't be used
             // since this scope is JavaScript code module.
             // xxxHonza: storageService should be converted into AMD (but it's used
-            // in firebug-service, which is also JS code module).
+            // in firebug-service.js, which is also JS code module).
+            // firebug-service.js is gone in JSD2 branch
             var pbs = Components.classes["@mozilla.org/privatebrowsing;1"]
                 .getService(Components.interfaces.nsIPrivateBrowsingService);
             return pbs.privateBrowsingEnabled;
@@ -310,6 +324,34 @@ var ObjectPersister =
         {
         }
 
+        try
+        {
+            // If |win| is null, the top most window is used to figure out
+            // whether the private mode is on or off.
+            if (!win)
+                win = wm.getMostRecentWindow("navigator:browser");
+        }
+        catch (e)
+        {
+            if (FBTrace.DBG_ERRORS)
+                FBTrace.sysout("storageService.isPrivateBrowsing; EXCEPTION " + e, e);
+        }
+
+        try
+        {
+            // For Fx 22+
+            Cu["import"]("resource://gre/modules/PrivateBrowsingUtils.jsm");
+
+            // Get firebugFrame.xul and check privaate mode (it's the same as
+            // for the top parent window).
+            return PrivateBrowsingUtils.isWindowPrivate(win);
+        }
+        catch (e)
+        {
+            if (FBTrace.DBG_ERRORS)
+                FBTrace.sysout("storageService.isPrivateBrowsing; EXCEPTION " + e, e);
+        }
+
         return false;
     }
 };
diff --git a/tests/content/lib/storageService.js b/tests/content/lib/storageService.js
index 2884da3..d6bf5ac 100644
--- a/tests/content/lib/storageService.js
+++ b/tests/content/lib/storageService.js
@@ -5,7 +5,7 @@ function runTest() {
     FBTest.progress("Testing StorageService");
 
     var url = "test.json";
-    var store = StorageService.getStorage(url);
+    var store = StorageService.getStorage(url, FW.Firebug.chrome.window);
     FBTest.ok(store, "StorageService.getStorage(url);");
 
     var bar = {first:"time", last:"best"};
@@ -18,7 +18,7 @@ function runTest() {
 
     setTimeout(function restoreFromDisk()
     {
-        var restore = StorageService.getStorage(url);
+        var restore = StorageService.getStorage(url, FW.Firebug.chrome.window);
 
         FBTest.compare(1, restore.length, "one item should be restored from "+url);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firebug.git



More information about the Pkg-mozext-commits mailing list