[Pkg-mozext-commits] [firebug] 36/59: Issue 7585: Script panel loads POST-requested sources with GET, when Net panel is disabled

David Prévot taffit at moszumanska.debian.org
Thu Aug 14 14:52:56 UTC 2014


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

taffit pushed a commit to branch master
in repository firebug.

commit f5f027cb4fc1ef31062e07298a353213cad15527
Author: Simon Lindholm <simon.lindholm10 at gmail.com>
Date:   Thu Jul 31 01:09:42 2014 +0200

    Issue 7585: Script panel loads POST-requested sources with GET, when Net panel is disabled
    
    https://code.google.com/p/fbug/issues/detail?id=7585
---
 .../content/firebug/debugger/script/sourceFile.js  | 28 +++++--
 extension/content/firebug/net/sourceCache.js       | 86 +++++++++++-----------
 extension/content/firebug/net/tabCache.js          | 33 ++++++++-
 3 files changed, 94 insertions(+), 53 deletions(-)

diff --git a/extension/content/firebug/debugger/script/sourceFile.js b/extension/content/firebug/debugger/script/sourceFile.js
index 75bbec4..69f0aa2 100644
--- a/extension/content/firebug/debugger/script/sourceFile.js
+++ b/extension/content/firebug/debugger/script/sourceFile.js
@@ -140,29 +140,41 @@ SourceFile.prototype =
         }
 
         // This is the only place where source (the text) is loaded for specific URL.
-        // To avoid double POSTs or missing cookies we use sourceCache for the top
-        // window load (issue 7401).
-        var sourceClient = threadClient.source(this);
+        // To avoid double loads (with missing cookies, even) we use sourceCache for
+        // the top window load. See issue 7401.
         var sourceCache = this.context.sourceCache;
-        var url = this.href;
-        if (url === this.context.window.location.href &&
-            sourceCache.isCached(sourceCache.removeAnchor(url)))
+        var loadedSource = (this.href === this.context.window.location.href ?
+            this.loadFromSourceCache(sourceCache, this.href) : null);
+        if (loadedSource)
         {
             // Use a timeout to call onSourceLoaded asynchronously, otherwise
-            // syntax highlighing breaks somehow.
+            // syntax highlighing breaks (somehow).
             setTimeout(() => {
                 this.onSourceLoaded({
-                    source: sourceCache.loadText(url),
+                    source: loadedSource,
                     contentType: "text/html",
                 });
             });
         }
         else
         {
+            var sourceClient = threadClient.source(this);
             sourceClient.source(this.onSourceLoaded.bind(this));
         }
     },
 
+    loadFromSourceCache: function(sourceCache, url)
+    {
+        url = sourceCache.removeAnchor(url);
+        if (!sourceCache.isCached(url))
+        {
+            // Try to load things from the Firefox cache. If this succeeds, the
+            // response will be added to the sourceCache (synchronously).
+            sourceCache.loadText(url, undefined, undefined, {addPostData: true});
+        }
+        return sourceCache.isCached(url) ? sourceCache.loadText(url) : null;
+    },
+
     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
     // Private Helpers
 
diff --git a/extension/content/firebug/net/sourceCache.js b/extension/content/firebug/net/sourceCache.js
index b2255f4..67a1c89 100644
--- a/extension/content/firebug/net/sourceCache.js
+++ b/extension/content/firebug/net/sourceCache.js
@@ -49,13 +49,13 @@ Firebug.SourceCache.prototype = Obj.extend(new EventSource(),
         return (this.cache[url] ? true : false);
     },
 
-    loadText: function(url, method, file)
+    loadText: function(url, method, file, options)
     {
-        var lines = this.load(url, method, file);
+        var lines = this.load(url, method, file, options);
         return lines ? lines.join("") : null;
     },
 
-    load: function(url, method, file)
+    load: function(url, method, file, options)
     {
         if (FBTrace.DBG_CACHE)
         {
@@ -155,7 +155,7 @@ Firebug.SourceCache.prototype = Obj.extend(new EventSource(),
         // Unfortunately, the URL isn't available, so let's try to use FF cache.
         // Note that an additional network request to the server could be made
         // in this method (a double-load).
-        return this.loadFromCache(url, method, file);
+        return this.loadFromCache(url, method, file, options);
     },
 
     store: function(url, text)
@@ -238,7 +238,7 @@ Firebug.SourceCache.prototype = Obj.extend(new EventSource(),
 
             if (channel instanceof nsIUploadChannel)
             {
-                var postData = getPostStream(this.context);
+                var postData = this.getPostStream();
                 if (postData)
                 {
                     var uploadChannel = Xpcom.QI(channel, nsIUploadChannel);
@@ -252,7 +252,7 @@ Firebug.SourceCache.prototype = Obj.extend(new EventSource(),
             if (channel instanceof nsICachingChannel)
             {
                 var cacheChannel = Xpcom.QI(channel, nsICachingChannel);
-                cacheChannel.cacheKey = getCacheKey(this.context);
+                cacheChannel.cacheKey = this.getCacheKey();
                 if (FBTrace.DBG_CACHE)
                     FBTrace.sysout("sourceCache.load cacheChannel key" + cacheChannel.cacheKey);
             }
@@ -369,7 +369,42 @@ Firebug.SourceCache.prototype = Obj.extend(new EventSource(),
             return (lines.length == 1) ?
                 lines[0] : "(" + lineNo + " out of range " + lines.length + ")";
         }
-    }
+    },
+
+    getCacheKey: function()
+    {
+        try
+        {
+            var webNav = this.context.browser.webNavigation;
+            var descriptor = Xpcom.QI(webNav, Ci.nsIWebPageDescriptor).currentDescriptor;
+            var entry = Xpcom.QI(descriptor, Ci.nsISHEntry);
+            return entry.cacheKey;
+        }
+        catch (exc)
+        {
+        }
+    },
+
+    getPostStream: function()
+    {
+        try
+        {
+            var webNav = this.context.browser.webNavigation;
+            var descriptor = Xpcom.QI(webNav, Ci.nsIWebPageDescriptor).currentDescriptor;
+            var entry = Xpcom.QI(descriptor, Ci.nsISHEntry);
+
+            if (entry.postData)
+            {
+                // Seek to the beginning, or it will probably start reading at the end
+                var postStream = Xpcom.QI(entry.postData, Ci.nsISeekableStream);
+                postStream.seek(0, 0);
+                return postStream;
+            }
+         }
+         catch (exc)
+         {
+         }
+    },
 });
 
 // xxxHonza getPostText and Http.readPostTextFromRequest are copied from
@@ -387,43 +422,6 @@ function getPostText(file, context)
 }
 
 // ********************************************************************************************* //
-
-function getPostStream(context)
-{
-    try
-    {
-        var webNav = context.browser.webNavigation;
-        var descriptor = Xpcom.QI(webNav, Ci.nsIWebPageDescriptor).currentDescriptor;
-        var entry = Xpcom.QI(descriptor, Ci.nsISHEntry);
-
-        if (entry.postData)
-        {
-            // Seek to the beginning, or it will probably start reading at the end
-            var postStream = Xpcom.QI(entry.postData, Ci.nsISeekableStream);
-            postStream.seek(0, 0);
-            return postStream;
-        }
-     }
-     catch (exc)
-     {
-     }
-}
-
-function getCacheKey(context)
-{
-    try
-    {
-        var webNav = context.browser.webNavigation;
-        var descriptor = Xpcom.QI(webNav, Ci.nsIWebPageDescriptor).currentDescriptor;
-        var entry = Xpcom.QI(descriptor, Ci.nsISHEntry);
-        return entry.cacheKey;
-     }
-     catch (exc)
-     {
-     }
-}
-
-// ********************************************************************************************* //
 // Registration
 
 return Firebug.SourceCache;
diff --git a/extension/content/firebug/net/tabCache.js b/extension/content/firebug/net/tabCache.js
index 84a1e75..471d8d6 100644
--- a/extension/content/firebug/net/tabCache.js
+++ b/extension/content/firebug/net/tabCache.js
@@ -420,7 +420,7 @@ Firebug.TabCache.prototype = Obj.extend(SourceCache.prototype,
         return this.cache[url];
     },
 
-    loadFromCache: function(url, method, file)
+    loadFromCache: function(url, method, file, options)
     {
         // The ancestor implementation (SourceCache) uses ioService.newChannel, which
         // can result in additional request to the server (in case the response can't
@@ -462,6 +462,37 @@ Firebug.TabCache.prototype = Obj.extend(SourceCache.prototype,
             if (doc)
                 charset = doc.characterSet;
 
+            // XXX We could probably instead check
+            // (url == this.context.browser.contentWindow.location.href)
+            // here, just like sourceCache, but I'd rather avoid changing behavior
+            // of crufty-but-working legacy code.
+            if (options && options.addPostData)
+            {
+                if (FBTrace.DBG_CACHE)
+                    FBTrace.sysout("tabCache.load with post data");
+
+                if (channel instanceof Ci.nsIUploadChannel)
+                {
+                    var postData = this.getPostStream();
+                    if (postData)
+                    {
+                        var uploadChannel = Xpcom.QI(channel, Ci.nsIUploadChannel);
+                        uploadChannel.setUploadStream(postData, "", -1);
+
+                        if (FBTrace.DBG_CACHE)
+                            FBTrace.sysout("tabCache.load uploadChannel set");
+                    }
+                }
+
+                if (channel instanceof Ci.nsICachingChannel)
+                {
+                    var cacheChannel = Xpcom.QI(channel, Ci.nsICachingChannel);
+                    cacheChannel.cacheKey = this.getCacheKey();
+                    if (FBTrace.DBG_CACHE)
+                        FBTrace.sysout("tabCache.load cacheChannel key" + cacheChannel.cacheKey);
+                }
+            }
+
             stream = channel.open();
 
             // The response doesn't have to be in the browser cache.

-- 
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