[Pkg-mozext-commits] [requestpolicy] 168/280: split getLoadContext from getBrowser

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:18 UTC 2015


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

taffit pushed a commit to branch master
in repository requestpolicy.

commit b785fe108a35253fcf9557d592908f2ae132d0dd
Author: Martin Kimmerle <dev at 256k.de>
Date:   Thu Jan 22 18:52:29 2015 +0100

    split getLoadContext from getBrowser
---
 src/content/lib/http-response.jsm              | 45 ++++++++++++++++++--------
 src/content/lib/request-processor.redirects.js | 22 ++++---------
 2 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/src/content/lib/http-response.jsm b/src/content/lib/http-response.jsm
index 15878ac..c10b59c 100644
--- a/src/content/lib/http-response.jsm
+++ b/src/content/lib/http-response.jsm
@@ -53,6 +53,8 @@ function HttpResponse(aHttpChannel) {
   XPCOMUtils.defineLazyGetter(this, "rawDestString", getRawDestString);
   XPCOMUtils.defineLazyGetter(this, "destURI", getDestURI);
   XPCOMUtils.defineLazyGetter(this, "originURI", getOriginURI);
+
+  XPCOMUtils.defineLazyGetter(this, "loadContext", getLoadContext);
   XPCOMUtils.defineLazyGetter(this, "browser", getBrowser);
 }
 
@@ -124,26 +126,42 @@ function getOriginURI() {
   return Services.io.newURI(this.httpChannel.name, null, null);
 }
 
-/**
- * Get the <browser> (nsIDOMXULElement) related to this request.
- */
-function getBrowser() {
+function getLoadContext() {
+  // more info on the load context:
+  // https://developer.mozilla.org/en-US/Firefox/Releases/3.5/Updating_extensions
+
   /* start - be careful when editing here */
-  let loadContext = null;
   try {
-    loadContext = this.httpChannel.notificationCallbacks
-                                  .QueryInterface(Ci.nsIInterfaceRequestor)
-                                  .getInterface(Ci.nsILoadContext);
+    return this.httpChannel.notificationCallbacks
+                           .QueryInterface(Ci.nsIInterfaceRequestor)
+                           .getInterface(Ci.nsILoadContext);
   } catch (ex) {
     try {
-      loadContext = this.httpChannel.loadGroup.notificationCallbacks
-          .getInterface(Ci.nsILoadContext);
+      return this.httpChannel.loadGroup
+                             .notificationCallbacks
+                             .getInterface(Ci.nsILoadContext);
     } catch (ex2) {
+      // fixme: the Load Context can't be found in case a favicon
+      //        request is redirected, that is, the server responds
+      //        with a 'Location' header when the server's
+      //        `favicon.ico` is requested.
+      Logger.warning(Logger.TYPE_HEADER_REDIRECT, "The redirection's " +
+                     "Load Context couldn't be found! " + ex2);
       return null;
     }
   }
   /* end - be careful when editing here */
+}
+
+/**
+ * Get the <browser> (nsIDOMXULElement) related to this request.
+ */
+function getBrowser() {
+  let loadContext = this.loadContext;
 
+  if (loadContext === null) {
+    return null;
+  }
 
   try {
     if (loadContext.topFrameElement) {
@@ -155,8 +173,9 @@ function getBrowser() {
       return WindowUtils.getBrowserForWindow(loadContext.topWindow);
     }
   } catch (e) {
-    Logger.warning(Logger.TYPE_HEADER_REDIRECT, "The redirection's " +
-                   "Load Context couldn't be found! " + e);
+    Logger.warning(Logger.TYPE_HEADER_REDIRECT, "The browser for " +
+                   "the redirection's Load Context couldn't be " +
+                   "found! " + e);
     return null;
   }
-};
+}
diff --git a/src/content/lib/request-processor.redirects.js b/src/content/lib/request-processor.redirects.js
index 9f8b870..d9f0c25 100644
--- a/src/content/lib/request-processor.redirects.js
+++ b/src/content/lib/request-processor.redirects.js
@@ -351,7 +351,7 @@ let RequestProcessor = (function(self) {
     let originString = httpResponse.originURI.specIgnoringRef;
 
     // Allow redirects of requests from privileged code.
-    if (!isContentRequest(httpChannel)) {
+    if (!isContentRequest(httpResponse)) {
       // However, favicon requests that are redirected appear as non-content
       // requests. So, check if the original request was for a favicon.
       var originPath = httpResponse.originURI.path;
@@ -385,24 +385,14 @@ let RequestProcessor = (function(self) {
    * Checks whether a request is initiated by a content window. If it's from a
    * content window, then it's from unprivileged code.
    */
-  function isContentRequest(channel) {
-    var callbacks = [];
-    if (channel.notificationCallbacks) {
-      callbacks.push(channel.notificationCallbacks);
-    }
-    if (channel.loadGroup && channel.loadGroup.notificationCallbacks) {
-      callbacks.push(channel.loadGroup.notificationCallbacks);
-    }
+  function isContentRequest(httpResponse) {
+    let loadContext = httpResponse.loadContext;
 
-    for (var i = 0; i < callbacks.length; i++) {
-      var callback = callbacks[i];
-      try {
-        return callback.getInterface(Ci.nsILoadContext).isContent;
-      } catch (e) {
-      }
+    if (loadContext === null) {
+      return false;
     }
 
-    return false;
+    return !!loadContext.isContent;
   }
 
 

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



More information about the Pkg-mozext-commits mailing list