From 16ff5db8f4a258ac06a2a272ecc8c699d5de1444 Mon Sep 17 00:00:00 2001 From: AlexVallat Date: Tue, 10 Mar 2015 18:44:31 +0000 Subject: [PATCH] Trying to fix merge --- platform/firefox/vapi-background.js | 418 ++++++++++++++-------------- 1 file changed, 213 insertions(+), 205 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 47d80fd..ce792d1 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -1090,9 +1090,9 @@ var httpObserver = { } var result = vAPI.tabs.onPopup({ - tabId: tabId, - sourceTabId: sourceTabId, - url: URI.asciiSpec + targetTabId: tabId, + openerTabId: sourceTabId, + targetURL: URI.asciiSpec }); return result === true; @@ -1403,7 +1403,7 @@ if (vAPI.fennec) { } } return label; - } + }; vAPI.toolbarButton.init = function() { // Only actually expecting one window under Fennec (note, not tabs, windows) @@ -1412,7 +1412,7 @@ if (vAPI.fennec) { } cleanupTasks.push(this.cleanUp); - } + }; vAPI.toolbarButton.addToWindow = function(win, label) { var id = win.NativeWindow.menu.add({ @@ -1420,13 +1420,7 @@ if (vAPI.fennec) { callback: this.onClick }); this.menuItemIds.set(win, id); - } - - vAPI.toolbarButton.cleanUp = function() { - for (var win of vAPI.tabs.getWindows()) { - vAPI.toolbarButton.removeFromWindow(win); - } - } + }; vAPI.toolbarButton.removeFromWindow = function(win) { var id = this.menuItemIds.get(win); @@ -1434,251 +1428,231 @@ if (vAPI.fennec) { win.NativeWindow.menu.remove(id); this.menuItemIds.delete(win); } - } + }; - vAPI.toolbarButton.updateState = function (win, tabId) { + vAPI.toolbarButton.updateState = function(win, tabId) { var id = this.menuItemIds.get(win); if (!id) { return; } win.NativeWindow.menu.update(id, { name: this.getMenuItemLabel(tabId) }); - } + }; vAPI.toolbarButton.onClick = function() { var win = Services.wm.getMostRecentWindow('navigator:browser'); var curTabId = vAPI.tabs.getTabId(getTabBrowser(win).selectedTab); - vAPI.tabs.open({ url: vAPI.getURL("popup.html?tabId=" + curTabId), index: -1, select: true }); - } + vAPI.tabs.open({ url: "popup.html?tabId=" + curTabId, index: -1, select: true }); + }; } else { - // Toolbar button UI - - /******************************************************************************/ - - vAPI.toolbarButton.init = function() { - var CustomizableUI; - try { - CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI; - } catch (ex) { - return; - } +// Toolbar button UI +vAPI.toolbarButton.init = function() { + var CustomizableUI; + try { + CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI; + } catch (ex) { + return; + } - this.defaultArea = CustomizableUI.AREA_NAVBAR; - this.styleURI = [ - '#' + this.id + ' {', - 'list-style-image: url(', - vAPI.getURL('img/browsericons/icon16-off.svg'), - ');', - '}', - '#' + this.viewId + ', #' + this.viewId + ' > iframe {', - 'width: 160px;', - 'height: 290px;', - 'overflow: hidden !important;', + this.defaultArea = CustomizableUI.AREA_NAVBAR; + this.styleURI = [ + '#' + this.id + ' {', + 'list-style-image: url(', + vAPI.getURL('img/browsericons/icon16-off.svg'), + ');', + '}', + '#' + this.viewId + ', #' + this.viewId + ' > iframe {', + 'width: 160px;', + 'height: 290px;', + 'overflow: hidden !important;', + '}' + ]; + + var platformVersion = Services.appinfo.platformVersion; + + if ( Services.vc.compare(platformVersion, '36.0') < 0 ) { + this.styleURI.push( + '#' + this.id + '[badge]:not([badge=""])::after {', + 'position: absolute;', + 'margin-left: -16px;', + 'margin-top: 3px;', + 'padding: 1px 2px;', + 'font-size: 9px;', + 'font-weight: bold;', + 'color: #fff;', + 'background: #666;', + 'content: attr(badge);', '}' - ]; - - var platformVersion = Services.appinfo.platformVersion; - - if ( Services.vc.compare(platformVersion, '36.0') < 0 ) { - this.styleURI.push( - '#' + this.id + '[badge]:not([badge=""])::after {', - 'position: absolute;', - 'margin-left: -16px;', - 'margin-top: 3px;', - 'padding: 1px 2px;', - 'font-size: 9px;', - 'font-weight: bold;', - 'color: #fff;', - 'background: #666;', - 'content: attr(badge);', - '}' - ); - } else { - this.CUIEvents = {}; + ); + } else { + this.CUIEvents = {}; - this.CUIEvents.onCustomizeEnd = function() { - var wId = vAPI.toolbarButton.id; - var buttonInPanel = CustomizableUI.getWidget(wId).areaType === CustomizableUI.TYPE_MENU_PANEL; - - for ( var win of vAPI.tabs.getWindows() ) { - var button = win.document.getElementById(wId); - if ( buttonInPanel ) { - button.classList.remove('badged-button'); - continue; - } - if ( button === null ) { - continue; - } - button.classList.add('badged-button'); - } + var updateBadge = function() { + var wId = vAPI.toolbarButton.id; + var buttonInPanel = CustomizableUI.getWidget(wId).areaType === CustomizableUI.TYPE_MENU_PANEL; + for ( var win of vAPI.tabs.getWindows() ) { + var button = win.document.getElementById(wId); if ( buttonInPanel ) { - return; + button.classList.remove('badged-button'); + continue; } + if ( button === null ) { + continue; + } + button.classList.add('badged-button'); + } - // Anonymous elements need some time to be reachable - setTimeout(this.updateBadgeStyle, 250); - }.bind(this.CUIEvents); + if ( buttonInPanel ) { + return; + } - this.CUIEvents.updateBadgeStyle = function() { - var css = [ - 'background: #666', - 'color: #fff' - ].join(';'); + // Anonymous elements need some time to be reachable + setTimeout(this.updateBadgeStyle, 50); + }.bind(this.CUIEvents); - for ( var win of vAPI.tabs.getWindows() ) { - var button = win.document.getElementById(vAPI.toolbarButton.id); - if ( button === null ) { - continue; - } - var badge = button.ownerDocument.getAnonymousElementByAttribute( - button, - 'class', - 'toolbarbutton-badge' - ); - if ( !badge ) { - return; - } + this.CUIEvents.onCustomizeEnd = updateBadge; + this.CUIEvents.onWidgetUnderflow = updateBadge; + + this.CUIEvents.updateBadgeStyle = function() { + var css = [ + 'background: #666', + 'color: #fff' + ].join(';'); - badge.style.cssText = css; + for ( var win of vAPI.tabs.getWindows() ) { + var button = win.document.getElementById(vAPI.toolbarButton.id); + if ( button === null ) { + continue; + } + var badge = button.ownerDocument.getAnonymousElementByAttribute( + button, + 'class', + 'toolbarbutton-badge' + ); + if ( !badge ) { + return; } - }; - this.onCreated = function(button) { - button.setAttribute('badge', ''); - setTimeout(this.CUIEvents.onCustomizeEnd, 250); - }; + badge.style.cssText = css; + } + }; - CustomizableUI.addListener(this.CUIEvents); - } + this.onCreated = function(button) { + button.setAttribute('badge', ''); + setTimeout(this.CUIEvents.onCustomizeEnd, 50); + }; + + CustomizableUI.addListener(this.CUIEvents); + } + + this.styleURI = Services.io.newURI( + 'data:text/css,' + encodeURIComponent(this.styleURI.join('')), + null, + null + ); - this.styleURI = Services.io.newURI( - 'data:text/css,' + encodeURIComponent(this.styleURI.join('')), - null, - null + this.closePopup = function({target}) { + CustomizableUI.hidePanelForNode( + target.ownerDocument.getElementById(vAPI.toolbarButton.viewId) ); + }; - this.closePopup = function({target}) { - CustomizableUI.hidePanelForNode( - target.ownerDocument.getElementById(vAPI.toolbarButton.viewId) - ); - }; + CustomizableUI.createWidget(this); + vAPI.messaging.globalMessageManager.addMessageListener( + location.host + ':closePopup', + this.closePopup + ); - CustomizableUI.createWidget(this); - vAPI.messaging.globalMessageManager.addMessageListener( + cleanupTasks.push(function() { + if ( this.CUIEvents ) { + CustomizableUI.removeListener(this.CUIEvents); + } + + CustomizableUI.destroyWidget(this.id); + vAPI.messaging.globalMessageManager.removeMessageListener( location.host + ':closePopup', this.closePopup ); - cleanupTasks.push(function() { - if ( this.CUIEvents ) { - CustomizableUI.removeListener(this.CUIEvents); - } - - CustomizableUI.destroyWidget(this.id); - vAPI.messaging.globalMessageManager.removeMessageListener( - location.host + ':closePopup', - this.closePopup - ); + for ( var win of vAPI.tabs.getWindows() ) { + var panel = win.document.getElementById(this.viewId); + panel.parentNode.removeChild(panel); + win.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils) + .removeSheet(this.styleURI, 1); + } + }.bind(this)); +}; - for ( var win of vAPI.tabs.getWindows() ) { - var panel = win.document.getElementById(this.viewId); - panel.parentNode.removeChild(panel); - win.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindowUtils) - .removeSheet(this.styleURI, 1); - } - }.bind(this)); - }; - /******************************************************************************/ +/******************************************************************************/ - vAPI.toolbarButton.onBeforeCreated = function(doc) { - var panel = doc.createElement('panelview'); - panel.setAttribute('id', this.viewId); +vAPI.toolbarButton.onBeforeCreated = function(doc) { + var panel = doc.createElement('panelview'); + panel.setAttribute('id', this.viewId); - var iframe = doc.createElement('iframe'); - iframe.setAttribute('type', 'content'); + var iframe = doc.createElement('iframe'); + iframe.setAttribute('type', 'content'); - doc.getElementById('PanelUI-multiView') - .appendChild(panel) - .appendChild(iframe); + doc.getElementById('PanelUI-multiView') + .appendChild(panel) + .appendChild(iframe); - var updateTimer = null; - var delayedResize = function() { + var updateTimer = null; + var delayedResize = function() { if ( updateTimer ) { - return; - } + return; + } - updateTimer = setTimeout(resizePopup, 10); - }; - var resizePopup = function() { - updateTimer = null; - var body = iframe.contentDocument.body; - panel.parentNode.style.maxWidth = 'none'; - // https://github.com/gorhill/uBlock/issues/730 - // Voodoo programming: this recipe works - panel.style.height = iframe.style.height = body.clientHeight.toString() + 'px'; - panel.style.width = iframe.style.width = body.clientWidth.toString() + 'px'; + updateTimer = setTimeout(resizePopup, 10); + }; + var resizePopup = function() { + updateTimer = null; + var body = iframe.contentDocument.body; + panel.parentNode.style.maxWidth = 'none'; + // https://github.com/gorhill/uBlock/issues/730 + // Voodoo programming: this recipe works + panel.style.height = iframe.style.height = body.clientHeight.toString() + 'px'; + panel.style.width = iframe.style.width = body.clientWidth.toString() + 'px'; if ( iframe.clientHeight !== body.clientHeight || iframe.clientWidth !== body.clientWidth ) { - delayedResize(); - } - }; - var onPopupReady = function() { - var win = this.contentWindow; - - if ( !win || win.location.host !== location.host ) { - return; - } - - new win.MutationObserver(delayedResize).observe(win.document.body, { - attributes: true, - characterData: true, - subtree: true - }); - delayedResize(); - }; - - iframe.addEventListener('load', onPopupReady, true); - - doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindowUtils) - .loadSheet(this.styleURI, 1); + } }; + var onPopupReady = function() { + var win = this.contentWindow; - /******************************************************************************/ - - vAPI.toolbarButton.onViewShowing = function({target}) { - target.firstChild.setAttribute('src', vAPI.getURL('popup.html')); - }; + if ( !win || win.location.host !== location.host ) { + return; + } - /******************************************************************************/ + new win.MutationObserver(delayedResize).observe(win.document.body, { + attributes: true, + characterData: true, + subtree: true + }); - vAPI.toolbarButton.onViewHiding = function({target}) { - target.parentNode.style.maxWidth = ''; - target.firstChild.setAttribute('src', 'about:blank'); + delayedResize(); }; - vAPI.toolbarButton.updateState = function(win, tabId) { - var button = win.document.getElementById(this.id); + iframe.addEventListener('load', onPopupReady, true); - if ( !button ) { - return; - } + doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils) + .loadSheet(this.styleURI, 1); +}; - var icon = this.tabs[tabId]; - button.setAttribute('badge', icon && icon.badge || ''); +/******************************************************************************/ - if ( !icon || !icon.img ) { - icon = ''; - } - else { - icon = 'url(' + vAPI.getURL('img/browsericons/icon16.svg') + ')'; - } +vAPI.toolbarButton.onViewShowing = function({target}) { + target.firstChild.setAttribute('src', vAPI.getURL('popup.html')); +}; - button.style.listStyleImage = icon; - } -} +/******************************************************************************/ + +vAPI.toolbarButton.onViewHiding = function({target}) { + target.parentNode.style.maxWidth = ''; + target.firstChild.setAttribute('src', 'about:blank'); +}; /******************************************************************************/ @@ -1876,6 +1850,40 @@ vAPI.punycodeURL = function(url) { /******************************************************************************/ +vAPI.optionsObserver = { + register: function () { + var obs = Components.classes['@mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService); + obs.addObserver(this, "addon-options-displayed", false); + + cleanupTasks.push(this.unregister.bind(this)); + }, + + observe: function (aSubject, aTopic, aData) { + if (aTopic === "addon-options-displayed" && aData === "{2b10c1c8-a11f-4bad-fe9c-1c11e82cac42}") { + var doc = aSubject; + this.setupOptionsButton(doc, "showDashboardButton", "dashboard.html"); + this.setupOptionsButton(doc, "showNetworkLogButton", "devtools.html"); + } + }, + setupOptionsButton: function (doc, id, page) { + var button = doc.getElementById(id); + button.addEventListener("command", function () { + vAPI.tabs.open({ url: page, index: -1 }); + }); + button.label = vAPI.i18n(id); + }, + + unregister: function () { + var obs = Components.classes['@mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService); + obs.removeObserver(this, "addon-options-displayed"); + }, +}; + +vAPI.optionsObserver.register(); + +/******************************************************************************/ + + // clean up when the extension is disabled window.addEventListener('unload', function() {