diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 83c776ea4..1ff5fad85 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -78,8 +78,10 @@ window.addEventListener('unload', function() { vAPI.app.onShutdown(); } - for ( var cleanup of cleanupTasks ) { - cleanup(); + // IMPORTANT: cleanup tasks must be executed using LIFO order. + var i = cleanupTasks.length; + while ( i-- ) { + cleanupTasks[i](); } if ( cleanupTasks.length < expectedNumberOfCleanups ) { @@ -2865,17 +2867,18 @@ vAPI.toolbarButton = { }; var shutdown = function() { - CustomizableUI.removeListener(CUIEvents); - CustomizableUI.destroyWidget(tbb.id); - for ( var win of winWatcher.getWindows() ) { var panel = win.document.getElementById(tbb.viewId); - panel.parentNode.removeChild(panel); + if ( panel !== null && panel.parentNode !== null ) { + panel.parentNode.removeChild(panel); + } win.QueryInterface(Ci.nsIInterfaceRequestor) .getInterface(Ci.nsIDOMWindowUtils) .removeSheet(styleURI, 1); } + CustomizableUI.removeListener(CUIEvents); + CustomizableUI.destroyWidget(tbb.id); vAPI.messaging.globalMessageManager.removeMessageListener( location.host + ':closePopup', diff --git a/src/js/popup.js b/src/js/popup.js index cddc69cb0..cbba06b0d 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -126,10 +126,12 @@ var cachePopupData = function(data) { continue; } domain = hostnameDict[hostname].domain; + prefix = hostname.slice(0, 0 - domain.length); + // Prefix with space char for 1st-party hostnames: this ensure these + // will come first in list. if ( domain === popupData.pageDomain ) { domain = '\u0020'; } - prefix = hostname.slice(0, 0 - domain.length); hostnameToSortableTokenMap[hostname] = domain + prefix.split('.').reverse().join('.'); } return popupData;