diff options
author | Deathamns <deathamns@gmail.com> | 2014-12-25 14:53:30 +0100 |
---|---|---|
committer | Deathamns <deathamns@gmail.com> | 2015-01-13 07:29:44 +0100 |
commit | b301ac031e0c2e9a99cb6f8953319d44e22f33d2 (patch) | |
tree | 01145811f45f7ff10e6843956ba42e27ff05a932 /platform | |
parent | dbfacad8a6cdf292692452d2a68ca1e2c0a50ddd (diff) | |
download | uBlock-b301ac031e0c2e9a99cb6f8953319d44e22f33d2.zip uBlock-b301ac031e0c2e9a99cb6f8953319d44e22f33d2.tar.gz uBlock-b301ac031e0c2e9a99cb6f8953319d44e22f33d2.tar.bz2 |
Popup related changes
Diffstat (limited to 'platform')
-rw-r--r-- | platform/chromium/vapi-common.js | 16 | ||||
-rw-r--r-- | platform/firefox/vapi-background.js | 49 | ||||
-rw-r--r-- | platform/firefox/vapi-common.js | 8 | ||||
-rw-r--r-- | platform/safari/vapi-background.js | 13 | ||||
-rw-r--r-- | platform/safari/vapi-common.js | 17 |
5 files changed, 67 insertions, 36 deletions
diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index 7797452..9fcffc8 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -73,18 +73,22 @@ vAPI.download = function(details) { /******************************************************************************/ -vAPI.getURL = function(path) { - return chrome.runtime.getURL(path); -}; +vAPI.getURL = chrome.runtime.getURL; -vAPI.i18n = function(s) { - return chrome.i18n.getMessage(s); -}; +/******************************************************************************/ + +vAPI.i18n = chrome.i18n.getMessage; setScriptDirection(vAPI.i18n('@@ui_locale')); /******************************************************************************/ +vAPI.closePopup = function() { + window.open('','_self').close(); +}; + +/******************************************************************************/ + })(); /******************************************************************************/ diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 6f4b334..01ee3a1 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -432,14 +432,14 @@ vAPI.tabs.get = function(tabId, callback) { /******************************************************************************/ vAPI.tabs.getAll = function(window) { - var tabs = []; + var win, tab, tabs = []; - for (var win of this.getWindows()) { + for (win of this.getWindows()) { if (window && window !== win) { continue; } - for (var tab of win.gBrowser.tabs) { + for (tab of win.gBrowser.tabs) { tabs.push(tab); } } @@ -643,8 +643,23 @@ vAPI.toolbarButton.init = function() { } }); + this.closePopup = function({target}) { + CustomizableUI.hidePanelForNode( + target.ownerDocument.getElementById(vAPI.toolbarButton.panelId) + ); + }; + + vAPI.messaging.globalMessageManager.addMessageListener( + location.host + ':closePopup', + this.closePopup + ); + vAPI.unload.push(function() { CustomizableUI.destroyWidget(vAPI.toolbarButton.widgetId); + vAPI.messaging.globalMessageManager.addMessageListener( + location.host + ':closePopup', + vAPI.toolbarButton.closePopup + ); }); }; @@ -763,19 +778,19 @@ vAPI.messaging.listen = function(listenerName, callback) { /******************************************************************************/ -vAPI.messaging.onMessage = function(request) { - var messageManager = request.target.messageManager; +vAPI.messaging.onMessage = function({target, data}) { + var messageManager = target.messageManager; if (!messageManager) { // Message came from a popup, and its message manager is not usable. // So instead we broadcast to the parent window. - messageManager = request.target + messageManager = target .webNavigation.QueryInterface(Ci.nsIDocShell) .chromeEventHandler.ownerDocument.defaultView.messageManager; } - var listenerId = request.data.portName.split('|'); - var requestId = request.data.requestId; + var listenerId = data.portName.split('|'); + var requestId = data.requestId; var portName = listenerId[1]; listenerId = listenerId[0]; @@ -799,7 +814,7 @@ vAPI.messaging.onMessage = function(request) { var sender = { tab: { - id: vAPI.tabs.getTabId(request.target) + id: vAPI.tabs.getTabId(target) } }; @@ -807,19 +822,19 @@ vAPI.messaging.onMessage = function(request) { var r = vAPI.messaging.UNHANDLED; var listener = vAPI.messaging.listeners[portName]; if ( typeof listener === 'function' ) { - r = listener(request.data.msg, sender, callback); + r = listener(data.msg, sender, callback); } if ( r !== vAPI.messaging.UNHANDLED ) { return; } // Default handler - r = vAPI.messaging.defaultHandler(request.data.msg, sender, callback); + r = vAPI.messaging.defaultHandler(data.msg, sender, callback); if ( r !== vAPI.messaging.UNHANDLED ) { return; } - console.error('µBlock> messaging > unknown request: %o', request.data); + console.error('µBlock> messaging > unknown request: %o', data); // Unhandled: // Need to callback anyways in case caller expected an answer, or @@ -883,11 +898,11 @@ var httpObserver = { parentFrameId: null }, observe: function(httpChannel, topic) { + // if this check is performed, it doesn't need to be QueryInterfaced? if (!(httpChannel instanceof Ci.nsIHttpChannel)) { return; } - httpChannel = httpChannel.QueryInterface(Ci.nsIHttpChannel); var URI = httpChannel.URI, tabId, result; // the first distinct character @@ -912,10 +927,10 @@ var httpObserver = { return; } - var header = 'Content-Security-Policy'; + var CSPHeader = 'Content-Security-Policy'; try { - result = httpChannel.getResponseHeader(header); + result = httpChannel.getResponseHeader(CSPHeader); } catch (ex) { result = null; } @@ -924,12 +939,12 @@ var httpObserver = { url: URI.spec, tabId: tabId, parentFrameId: -1, - responseHeaders: result ? [{name: header, value: result}] : [] + responseHeaders: result ? [{name: CSPHeader, value: result}] : [] }); if (result) { httpChannel.setResponseHeader( - header, + CSPHeader, result.responseHeaders[0].value, true ); diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index cbe6dc7..949b7e9 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -19,6 +19,8 @@ Home: https://github.com/gorhill/uBlock */ +/* global sendAsyncMessage */ + // For background page or non-background pages /******************************************************************************/ @@ -92,6 +94,12 @@ setScriptDirection(navigator.language); /******************************************************************************/ +vAPI.closePopup = function() { + sendAsyncMessage(location.host + ':closePopup'); +}; + +/******************************************************************************/ + })(); /******************************************************************************/ diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index f027bd5..678fbe5 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -408,19 +408,6 @@ safari.application.addEventListener('close', function(e) { // update badge when tab is activated safari.application.addEventListener('activate', function(e) { - // hide popover, since in some cases won't close by itself - var items = safari.extension.toolbarItems; - - for (var i = 0; i < items.length; ++i) { - if (items[i].browserWindow === safari.application.activeBrowserWindow) { - if (items[i].popover) { - items[i].popover.hide(); - } - - break; - } - } - // ignore windows if (!(e.target instanceof SafariBrowserTab)) { return; diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index 820a168..85e6f77 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -106,6 +106,23 @@ vAPI.i18n = function(s) { /******************************************************************************/ +vAPI.closePopup = function() { + var safr = safari.extension.globalPage.contentWindow.safari; + var items = safr.extension.toolbarItems; + + for (var i = 0; i < items.length; i++) { + if (items[i].browserWindow !== safr.application.activeBrowserWindow) { + continue; + } + + if (items[i].popover && items[i].popover.visible) { + items[i].popover.hide(); + } + } +}; + +/******************************************************************************/ + })(); /******************************************************************************/ |