Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jul 13, 2016
1 parent 9e7fbb8 commit d7ff5a5
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions platform/firefox/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,14 +621,31 @@ vAPI.storage = (function() {
// This must be executed/setup early.

var winWatcher = (function() {
var chromeWindowType = vAPI.thunderbird ? 'mail:3pane' : 'navigator:browser';
var windowToIdMap = new Map();
var windowIdGenerator = 1;
var api = {
onOpenWindow: null,
onCloseWindow: null
};

// https://github.com/gorhill/uMatrix/issues/586
// This is necessary hack because on SeaMonkey 2.40, for unknown reasons
// private windows do not have the attribute `windowtype` set to
// `navigator:browser`. As a fallback, the code here will also test whether
// the id attribute is `main-window`.
api.toBrowserWindow = function(win) {
var docElement = win && win.document && win.document.documentElement;
if ( !docElement ) {
return null;
}
if ( vAPI.thunderbird ) {
return docElement.getAttribute('windowtype') === 'mail:3pane' ? win : null;
}
return docElement.getAttribute('windowtype') === 'navigator:browser' ||
docElement.getAttribute('id') === 'main-window' ?
win : null;
};

api.getWindows = function() {
return windowToIdMap.keys();
};
Expand All @@ -638,7 +655,7 @@ var winWatcher = (function() {
};

api.getCurrentWindow = function() {
return Services.wm.getMostRecentWindow(chromeWindowType) || null;
return this.toBrowserWindow(Services.wm.getMostRecentWindow(null));
};

var addWindow = function(win) {
Expand Down Expand Up @@ -1366,8 +1383,7 @@ var tabWatcher = (function() {
return false;
}

var docElement = document.documentElement;
return docElement && docElement.getAttribute('windowtype') === 'navigator:browser';
return winWatcher.toBrowserWindow(window) !== null;
};

var onWindowLoad = function(win) {
Expand Down

0 comments on commit d7ff5a5

Please sign in to comment.