[Pkg-mozext-commits] [requestpolicy] 201/280: show the redirection bar asynchronously
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:30:26 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 b78286ae684212d5b5579cf7d6d46161ea3357d2
Author: Martin Kimmerle <dev at 256k.de>
Date: Mon Feb 2 07:25:54 2015 +0100
show the redirection bar asynchronously
---
src/content/lib/request-processor.redirects.js | 14 ++++++---
src/content/lib/utils.jsm | 43 ++++++++++++++++++++++++++
src/content/ui/overlay.js | 8 ++---
3 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/src/content/lib/request-processor.redirects.js b/src/content/lib/request-processor.redirects.js
index 52e7933..8e76b5f 100644
--- a/src/content/lib/request-processor.redirects.js
+++ b/src/content/lib/request-processor.redirects.js
@@ -315,10 +315,16 @@ let RequestProcessor = (function(self) {
return false;
}
- let window = browser.ownerGlobal;
- let overlay = window.requestpolicy.overlay;
- return overlay._showRedirectNotification(browser, request.destURI, 0,
- request.originURI);
+ var window = browser.ownerGlobal;
+
+ Utils.tryMultipleTimes(function() {
+ var showNotification = Utils.getObjectPath(window, 'requestpolicy',
+ 'overlay', '_showRedirectNotification');
+ if (!showNotification) {
+ return false;
+ }
+ return showNotification(browser, request.destURI, 0, request.originURI);
+ });
return true;
}
diff --git a/src/content/lib/utils.jsm b/src/content/lib/utils.jsm
index 28b40d1..c84bd12 100644
--- a/src/content/lib/utils.jsm
+++ b/src/content/lib/utils.jsm
@@ -75,6 +75,49 @@ let Utils = (function() {
"@mozilla.org/thread-manager;1", "nsIThreadManager");
+ /**
+ * Calls a function multiple times until it succeeds. The
+ * function must return TRUE on success.
+ *
+ * @param {function():boolean} aFunction
+ * @param {number} aTries - The number of tries.
+ */
+ self.tryMultipleTimes = function(aFunction, aTries=10) {
+ if (aTries <= 0) {
+ //console.log("no more tries!");
+ return;
+ }
+ self.runAsync(function() {
+ if (aFunction.call(null) !== true) {
+ self.tryMultipleTimes(aFunction, aTries - 1);
+ }
+ });
+ };
+
+ /**
+ * Return a nested property or `undefined` if it does not exist.
+ * Any element in the object chain may be undefined.
+ *
+ * Other implementations at http://stackoverflow.com/questions/2631001/javascript-test-for-existence-of-nested-object-key
+ *
+ * @param {Object} object
+ * @param {...string} properties
+ */
+ self.getObjectPath = function(object, ...properties) {
+ return properties.reduce(self.getObjectProperty, object);
+ };
+
+ /**
+ * @private
+ */
+ self.getObjectProperty = function(object, property) {
+ if (!!object && object.hasOwnProperty(property)) {
+ return object[property];
+ }
+ return undefined;
+ };
+
+
self.info = {};
diff --git a/src/content/ui/overlay.js b/src/content/ui/overlay.js
index b9d6643..02c892a 100644
--- a/src/content/ui/overlay.js
+++ b/src/content/ui/overlay.js
@@ -460,10 +460,10 @@ requestpolicy.overlay = (function() {
* or with headers).
*
* @param {<browser> element} browser
- * @param {String}
- * redirectTargetUri
- * @param {int}
- * delay
+ * @param {string} redirectTargetUri
+ * @param {number} delay
+ * @param {string=} redirectOriginUri
+ * @return {boolean} whether showing the notification succeeded
*/
// TODO, bad smell: Instead of the <browser> etc. hand over a `Request`
// object that contains everything. This requires
--
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