[Pkg-mozext-commits] [requestpolicy] 04/10: Show the redirection bar only when meaningful
David Prévot
taffit at moszumanska.debian.org
Sun May 10 03:19:37 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 be41aa5eb51d27bf4eadccb66d6eb1f991570519
Author: Martin Kimmerle <dev at 256k.de>
Date: Thu May 7 13:37:11 2015 +0200
Show the redirection bar only when meaningful
The redirection notification is now only shown to the user in
case of a top-level document redirection.
Fixes #561, fixes #630.
---
src/content/lib/http-response.jsm | 21 ++++++++-
src/content/lib/request-processor.redirects.js | 65 ++++++++++++++++++++------
2 files changed, 70 insertions(+), 16 deletions(-)
diff --git a/src/content/lib/http-response.jsm b/src/content/lib/http-response.jsm
index c10b59c..a9ac4dc 100644
--- a/src/content/lib/http-response.jsm
+++ b/src/content/lib/http-response.jsm
@@ -56,6 +56,7 @@ function HttpResponse(aHttpChannel) {
XPCOMUtils.defineLazyGetter(this, "loadContext", getLoadContext);
XPCOMUtils.defineLazyGetter(this, "browser", getBrowser);
+ XPCOMUtils.defineLazyGetter(this, "docShell", getDocShell);
}
HttpResponse.headerTypes = ["Location", "Refresh"];
@@ -154,7 +155,8 @@ function getLoadContext() {
}
/**
- * Get the <browser> (nsIDOMXULElement) related to this request.
+ * Get the <browser> related to this request.
+ * @return {?nsIDOMXULElement}
*/
function getBrowser() {
let loadContext = this.loadContext;
@@ -179,3 +181,20 @@ function getBrowser() {
return null;
}
}
+
+/**
+ * Get the DocShell related to this request.
+ * @return {?nsIDocShell}
+ */
+function getDocShell() {
+ try {
+ return this.httpChannel.notificationCallbacks
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDocShell);
+ } catch (e) {
+ Logger.warning(Logger.TYPE_HEADER_REDIRECT,
+ "The redirection's DocShell 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 a6ea9e4..685bc77 100644
--- a/src/content/lib/request-processor.redirects.js
+++ b/src/content/lib/request-processor.redirects.js
@@ -244,21 +244,7 @@ let RequestProcessor = (function(self) {
// show the URL of the previously displayed page.
httpChannel.cancel(Cr.NS_BINDING_ABORTED);
- // TODO: show the redirect notification *only* when
- // a) a link has been clicked
- // b) an url has been entered.
- // In any other case the redirect should *not* cause a notific.
- // bar to be displayed, because the redirect hasn't been caused by
- // *explicit* user interaction.
- // Examples for such other cases are inline elements whose
- // destination causes a redirect (via a HTTP Header), e.g. <img>.
- // Note: As soon as this is fixed, enable this mozmill test:
- // tests/mozmill/tests/testRedirect/testInlineRedirect.js
- showRedirectNotification(request) || Logger.warning(
- Logger.TYPE_HEADER_REDIRECT,
- "A redirect has been observed, but it was not possible to notify " +
- "the user! The redirect was from page <" + request.originURI + "> " +
- "to <" + request.destURI + ">.");
+ eventuallyShowRedirectNotification(request);
// We try to trace the blocked redirect back to a link click or form
// submission if we can. It may indicate, for example, a link that
@@ -330,6 +316,55 @@ let RequestProcessor = (function(self) {
return true;
}
+ /**
+ * @param {RedirectRequest} aRequest
+ */
+ function eventuallyShowRedirectNotification(aRequest) {
+ var httpResponse = aRequest.httpResponse;
+
+ // Check whether the request is associated with a `document` element.
+ {
+ let docShell = httpResponse.docShell;
+
+ if (docShell === null) {
+ return;
+ }
+
+ let busyFlags = docShell.busyFlags;
+ const expectedFlags = Ci.nsIDocShell.BUSY_FLAGS_BUSY
+ | Ci.nsIDocShell.BUSY_FLAGS_BEFORE_PAGE_LOAD;
+
+ // The document is loading AND nothing has been received yet.
+ let isDocumentRequest = (busyFlags & expectedFlags) === expectedFlags;
+
+ if (isDocumentRequest === false) {
+ // This is probably a redirect of an "inline" element, e.g. <img>.
+ return;
+ }
+ }
+
+ // Check whether it's the top-level document that is being loaded.
+ {
+ let loadContext = httpResponse.loadContext;
+
+ if (loadContext === null) {
+ return;
+ }
+
+ if (loadContext.associatedWindow !== loadContext.topWindow) {
+ // this request belongs to a sub-document, e.g. an iframe.
+ return;
+ }
+ }
+
+ showRedirectNotification(aRequest) || Logger.warning(
+ Logger.TYPE_HEADER_REDIRECT,
+ "A redirection of a top-level document has been observed, " +
+ "but it was not possible to notify the user! The redirection " +
+ "was from page <" + request.originURI + "> " +
+ "to <" + request.destURI + ">.");
+ }
+
--
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