From 1e6f29e64ed877d59bfa4f093d11bc59147667de Mon Sep 17 00:00:00 2001 From: Deathamns Date: Wed, 28 Jan 2015 21:08:24 +0100 Subject: [PATCH] Firefox: don't close popups after user interaction --- platform/firefox/frameModule.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js index d0effae..489af23 100644 --- a/platform/firefox/frameModule.js +++ b/platform/firefox/frameModule.js @@ -54,6 +54,7 @@ const contentObserver = { MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT, contentBaseURI: 'chrome://' + hostName + '/content/js/', cpMessageName: hostName + ':shouldLoad', + ignoredPopups: new WeakMap(), get componentRegistrar() { return Components.manager.QueryInterface(Ci.nsIComponentRegistrar); @@ -134,11 +135,10 @@ const contentObserver = { if ( type === this.MAIN_FRAME ) { context = context.contentWindow || context; - try { - if ( context !== context.opener ) { - openerURL = context.opener.location.href; - } - } catch (ex) {} + if ( context.opener && context.opener !== context + && this.ignoredPopups.has(context) === false ) { + openerURL = context.opener.location.href; + } } else { context = (context.ownerDocument || context).defaultView; } @@ -250,6 +250,17 @@ const contentObserver = { return sandbox; }, + ignorePopup: function(e) { + if ( e.isTrusted === false ) { + return; + } + + let contObs = contentObserver; + contObs.ignoredPopups.set(this, true); + this.removeEventListener('keydown', contObs.ignorePopup, true); + this.removeEventListener('mousedown', contObs.ignorePopup, true); + }, + observe: function(subject) { let win = subject.defaultView; @@ -257,6 +268,11 @@ const contentObserver = { return; } + if ( win.opener && this.ignoredPopups.has(win) === false ) { + win.addEventListener('keydown', this.ignorePopup, true); + win.addEventListener('mousedown', this.ignorePopup, true); + } + let loc = win.location; if ( loc.protocol !== 'http:' && loc.protocol !== 'https:' ) {