[Pkg-mozext-commits] [requestpolicy] 217/280: pass the <browser> to `observeBlockedTopLevelDocRequest`

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:30 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 5affb7bf67e2f662e88ba7cf53bf3130811c54a5
Author: Martin Kimmerle <dev at 256k.de>
Date:   Tue Feb 10 16:16:13 2015 +0100

    pass the <browser> to `observeBlockedTopLevelDocRequest`
    
    The browser object is already available through the request's
    context, so it can be passed to the function that will show the
    redirect notification. This ensures that the notification is
    shown in the correct tab.
---
 src/content/lib/request-processor.jsm | 26 ++++++++++++--------------
 src/content/ui/overlay.js             | 32 ++++++++------------------------
 2 files changed, 20 insertions(+), 38 deletions(-)

diff --git a/src/content/lib/request-processor.jsm b/src/content/lib/request-processor.jsm
index 01a7d37..5738afd 100644
--- a/src/content/lib/request-processor.jsm
+++ b/src/content/lib/request-processor.jsm
@@ -126,17 +126,6 @@ let RequestProcessor = (function(self) {
     }
   }
 
-  function notifyBlockedTopLevelDocRequest(originUri, destUri) {
-    // TODO: this probably could be done async.
-    for (var i = 0; i < internal.requestObservers.length; i++) {
-      if (!internal.requestObservers[i]) {
-        continue;
-      }
-      internal.requestObservers[i].observeBlockedTopLevelDocRequest(originUri,
-          destUri);
-    }
-  }
-
 
 
 
@@ -159,11 +148,20 @@ let RequestProcessor = (function(self) {
     cacheShouldLoadResult(CP_REJECT, request.originURI, request.destURI);
     internal.recordRejectedRequest(request);
 
-    if (Ci.nsIContentPolicy.TYPE_DOCUMENT == request.aContentType) {
+    if (Ci.nsIContentPolicy.TYPE_DOCUMENT === request.aContentType) {
       // This was a blocked top-level document request. This may be due to
       // a blocked attempt by javascript to set the document location.
-      // TODO: pass requestResult?
-      notifyBlockedTopLevelDocRequest(request.originURI, request.destURI);
+
+      let browser = request.getBrowser();
+      let window = request.getChromeWindow();
+
+      if (!browser || !window) {
+        Logger.warning(Logger.TYPE_CONTENT, "The user could not be notified " +
+            "about the blocked top-level document request!");
+      } else {
+        window.requestpolicy.overlay.observeBlockedTopLevelDocRequest(
+            browser, request.originURI, request.destURI);
+      }
     }
 
     return CP_REJECT;
diff --git a/src/content/ui/overlay.js b/src/content/ui/overlay.js
index cb2a86f..0e82364 100644
--- a/src/content/ui/overlay.js
+++ b/src/content/ui/overlay.js
@@ -710,36 +710,20 @@ requestpolicy.overlay = (function() {
   };
 
   /**
-   * If the RP service noticed a blocked top-level document request, look for
-   * a tab where the current location is the same as the origin of the blocked
-   * request. If we find one, show a redirect notification. Note that if there
-   * is more than one tab in this window open to the same origin, then we only
-   * show the notification in the first one we find. However, if there are
-   * multiple windows open and two different windows have a tab open to this
-   * same origin, then the first tab at that location in each window will show
-   * the redirect notification. This is because the RP service informs each
-   * window separately to look for a document to show a notification in.
+   * This function gets called when a top-level document request has been
+   * blocked.
+   * This function is called during shouldLoad(). As shouldLoad shoudn't be
+   * blocked, it's better to set a timeout here.
    */
-  self.observeBlockedTopLevelDocRequest = function (originUri, destUri) {
-    const browser = self._getBrowserAtUri(originUri);
-    if (!browser) {
-      return;
-    }
-    // We're called indirectly from shouldLoad so we can't block.
+  self.observeBlockedTopLevelDocRequest = function (browser, originUri,
+                                                    destUri) {
+    // This function is called during shouldLoad() so set a timeout to
+    // avoid blocking shouldLoad.
     window.setTimeout(function() {
       requestpolicy.overlay._showRedirectNotification(browser, destUri, 0);
     }, 0);
   };
 
-  self._getBrowserAtUri = function(uri) {
-    for (let i = 0, len = gBrowser.browsers.length; i < len; i++) {
-      if (gBrowser.getBrowserAtIndex(i).currentURI.spec == uri) {
-        return gBrowser.getBrowserAtIndex(i);
-      }
-    }
-    return null;
-  };
-
   // TODO: observeBlockedFormSubmissionRedirect
 
   self._updateNotificationDueToBlockedContent = function() {

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