Firefox: don't close popups after user interaction

This commit is contained in:
Deathamns 2015-01-28 21:08:24 +01:00
parent 50e621d4ee
commit ee5a023e03
1 changed files with 21 additions and 5 deletions

View File

@ -54,6 +54,7 @@ const contentObserver = {
MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT, MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
contentBaseURI: 'chrome://' + hostName + '/content/js/', contentBaseURI: 'chrome://' + hostName + '/content/js/',
cpMessageName: hostName + ':shouldLoad', cpMessageName: hostName + ':shouldLoad',
ignoredPopups: new WeakMap(),
get componentRegistrar() { get componentRegistrar() {
return Components.manager.QueryInterface(Ci.nsIComponentRegistrar); return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
@ -134,11 +135,10 @@ const contentObserver = {
if ( type === this.MAIN_FRAME ) { if ( type === this.MAIN_FRAME ) {
context = context.contentWindow || context; context = context.contentWindow || context;
try { if ( context.opener && context.opener !== context
if ( context !== context.opener ) { && this.ignoredPopups.has(context) === false ) {
openerURL = context.opener.location.href; openerURL = context.opener.location.href;
} }
} catch (ex) {}
} else { } else {
context = (context.ownerDocument || context).defaultView; context = (context.ownerDocument || context).defaultView;
} }
@ -250,6 +250,17 @@ const contentObserver = {
return sandbox; 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) { observe: function(subject) {
let win = subject.defaultView; let win = subject.defaultView;
@ -257,6 +268,11 @@ const contentObserver = {
return; 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; let loc = win.location;
if ( loc.protocol !== 'http:' && loc.protocol !== 'https:' ) { if ( loc.protocol !== 'http:' && loc.protocol !== 'https:' ) {