Trying to fix merge

pull/2/head
AlexVallat 10 years ago committed by gorhill
parent c9a8c8d6df
commit 16ff5db8f4

@ -1090,9 +1090,9 @@ var httpObserver = {
} }
var result = vAPI.tabs.onPopup({ var result = vAPI.tabs.onPopup({
tabId: tabId, targetTabId: tabId,
sourceTabId: sourceTabId, openerTabId: sourceTabId,
url: URI.asciiSpec targetURL: URI.asciiSpec
}); });
return result === true; return result === true;
@ -1403,7 +1403,7 @@ if (vAPI.fennec) {
} }
} }
return label; return label;
} };
vAPI.toolbarButton.init = function() { vAPI.toolbarButton.init = function() {
// Only actually expecting one window under Fennec (note, not tabs, windows) // Only actually expecting one window under Fennec (note, not tabs, windows)
@ -1412,7 +1412,7 @@ if (vAPI.fennec) {
} }
cleanupTasks.push(this.cleanUp); cleanupTasks.push(this.cleanUp);
} };
vAPI.toolbarButton.addToWindow = function(win, label) { vAPI.toolbarButton.addToWindow = function(win, label) {
var id = win.NativeWindow.menu.add({ var id = win.NativeWindow.menu.add({
@ -1420,13 +1420,7 @@ if (vAPI.fennec) {
callback: this.onClick callback: this.onClick
}); });
this.menuItemIds.set(win, id); 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) { vAPI.toolbarButton.removeFromWindow = function(win) {
var id = this.menuItemIds.get(win); var id = this.menuItemIds.get(win);
@ -1434,251 +1428,231 @@ if (vAPI.fennec) {
win.NativeWindow.menu.remove(id); win.NativeWindow.menu.remove(id);
this.menuItemIds.delete(win); this.menuItemIds.delete(win);
} }
} };
vAPI.toolbarButton.updateState = function (win, tabId) { vAPI.toolbarButton.updateState = function(win, tabId) {
var id = this.menuItemIds.get(win); var id = this.menuItemIds.get(win);
if (!id) { if (!id) {
return; return;
} }
win.NativeWindow.menu.update(id, { name: this.getMenuItemLabel(tabId) }); win.NativeWindow.menu.update(id, { name: this.getMenuItemLabel(tabId) });
} };
vAPI.toolbarButton.onClick = function() { vAPI.toolbarButton.onClick = function() {
var win = Services.wm.getMostRecentWindow('navigator:browser'); var win = Services.wm.getMostRecentWindow('navigator:browser');
var curTabId = vAPI.tabs.getTabId(getTabBrowser(win).selectedTab); 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 { } else {
// Toolbar button UI // Toolbar button UI
vAPI.toolbarButton.init = function() {
/******************************************************************************/ var CustomizableUI;
try {
vAPI.toolbarButton.init = function() { CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI;
var CustomizableUI; } catch (ex) {
try { return;
CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI; }
} catch (ex) {
return;
}
this.defaultArea = CustomizableUI.AREA_NAVBAR; this.defaultArea = CustomizableUI.AREA_NAVBAR;
this.styleURI = [ this.styleURI = [
'#' + this.id + ' {', '#' + this.id + ' {',
'list-style-image: url(', 'list-style-image: url(',
vAPI.getURL('img/browsericons/icon16-off.svg'), vAPI.getURL('img/browsericons/icon16-off.svg'),
');', ');',
'}', '}',
'#' + this.viewId + ', #' + this.viewId + ' > iframe {', '#' + this.viewId + ', #' + this.viewId + ' > iframe {',
'width: 160px;', 'width: 160px;',
'height: 290px;', 'height: 290px;',
'overflow: hidden !important;', '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);',
'}' '}'
]; );
} else {
var platformVersion = Services.appinfo.platformVersion; this.CUIEvents = {};
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 = {};
this.CUIEvents.onCustomizeEnd = function() { var updateBadge = function() {
var wId = vAPI.toolbarButton.id; var wId = vAPI.toolbarButton.id;
var buttonInPanel = CustomizableUI.getWidget(wId).areaType === CustomizableUI.TYPE_MENU_PANEL; 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');
}
for ( var win of vAPI.tabs.getWindows() ) {
var button = win.document.getElementById(wId);
if ( buttonInPanel ) { 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 if ( buttonInPanel ) {
setTimeout(this.updateBadgeStyle, 250); return;
}.bind(this.CUIEvents); }
this.CUIEvents.updateBadgeStyle = function() { // Anonymous elements need some time to be reachable
var css = [ setTimeout(this.updateBadgeStyle, 50);
'background: #666', }.bind(this.CUIEvents);
'color: #fff'
].join(';');
for ( var win of vAPI.tabs.getWindows() ) { this.CUIEvents.onCustomizeEnd = updateBadge;
var button = win.document.getElementById(vAPI.toolbarButton.id); this.CUIEvents.onWidgetUnderflow = updateBadge;
if ( button === null ) {
continue; this.CUIEvents.updateBadgeStyle = function() {
} var css = [
var badge = button.ownerDocument.getAnonymousElementByAttribute( 'background: #666',
button, 'color: #fff'
'class', ].join(';');
'toolbarbutton-badge'
);
if ( !badge ) {
return;
}
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) { badge.style.cssText = css;
button.setAttribute('badge', ''); }
setTimeout(this.CUIEvents.onCustomizeEnd, 250); };
};
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( this.closePopup = function({target}) {
'data:text/css,' + encodeURIComponent(this.styleURI.join('')), CustomizableUI.hidePanelForNode(
null, target.ownerDocument.getElementById(vAPI.toolbarButton.viewId)
null
); );
};
this.closePopup = function({target}) { CustomizableUI.createWidget(this);
CustomizableUI.hidePanelForNode( vAPI.messaging.globalMessageManager.addMessageListener(
target.ownerDocument.getElementById(vAPI.toolbarButton.viewId) location.host + ':closePopup',
); this.closePopup
}; );
CustomizableUI.createWidget(this); cleanupTasks.push(function() {
vAPI.messaging.globalMessageManager.addMessageListener( if ( this.CUIEvents ) {
CustomizableUI.removeListener(this.CUIEvents);
}
CustomizableUI.destroyWidget(this.id);
vAPI.messaging.globalMessageManager.removeMessageListener(
location.host + ':closePopup', location.host + ':closePopup',
this.closePopup this.closePopup
); );
cleanupTasks.push(function() { for ( var win of vAPI.tabs.getWindows() ) {
if ( this.CUIEvents ) { var panel = win.document.getElementById(this.viewId);
CustomizableUI.removeListener(this.CUIEvents); panel.parentNode.removeChild(panel);
} win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
CustomizableUI.destroyWidget(this.id); .removeSheet(this.styleURI, 1);
vAPI.messaging.globalMessageManager.removeMessageListener( }
location.host + ':closePopup', }.bind(this));
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));
};
/******************************************************************************/ /******************************************************************************/
vAPI.toolbarButton.onBeforeCreated = function(doc) { vAPI.toolbarButton.onBeforeCreated = function(doc) {
var panel = doc.createElement('panelview'); var panel = doc.createElement('panelview');
panel.setAttribute('id', this.viewId); panel.setAttribute('id', this.viewId);
var iframe = doc.createElement('iframe'); var iframe = doc.createElement('iframe');
iframe.setAttribute('type', 'content'); iframe.setAttribute('type', 'content');
doc.getElementById('PanelUI-multiView') doc.getElementById('PanelUI-multiView')
.appendChild(panel) .appendChild(panel)
.appendChild(iframe); .appendChild(iframe);
var updateTimer = null; var updateTimer = null;
var delayedResize = function() { var delayedResize = function() {
if ( updateTimer ) { if ( updateTimer ) {
return; return;
} }
updateTimer = setTimeout(resizePopup, 10); updateTimer = setTimeout(resizePopup, 10);
}; };
var resizePopup = function() { var resizePopup = function() {
updateTimer = null; updateTimer = null;
var body = iframe.contentDocument.body; var body = iframe.contentDocument.body;
panel.parentNode.style.maxWidth = 'none'; panel.parentNode.style.maxWidth = 'none';
// https://github.com/gorhill/uBlock/issues/730 // https://github.com/gorhill/uBlock/issues/730
// Voodoo programming: this recipe works // Voodoo programming: this recipe works
panel.style.height = iframe.style.height = body.clientHeight.toString() + 'px'; panel.style.height = iframe.style.height = body.clientHeight.toString() + 'px';
panel.style.width = iframe.style.width = body.clientWidth.toString() + 'px'; panel.style.width = iframe.style.width = body.clientWidth.toString() + 'px';
if ( iframe.clientHeight !== body.clientHeight || iframe.clientWidth !== body.clientWidth ) { 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(); 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;
/******************************************************************************/ if ( !win || win.location.host !== location.host ) {
return;
vAPI.toolbarButton.onViewShowing = function({target}) { }
target.firstChild.setAttribute('src', vAPI.getURL('popup.html'));
};
/******************************************************************************/ new win.MutationObserver(delayedResize).observe(win.document.body, {
attributes: true,
characterData: true,
subtree: true
});
vAPI.toolbarButton.onViewHiding = function({target}) { delayedResize();
target.parentNode.style.maxWidth = '';
target.firstChild.setAttribute('src', 'about:blank');
}; };
vAPI.toolbarButton.updateState = function(win, tabId) { iframe.addEventListener('load', onPopupReady, true);
var button = win.document.getElementById(this.id);
if ( !button ) { doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
return; .getInterface(Ci.nsIDOMWindowUtils)
} .loadSheet(this.styleURI, 1);
};
var icon = this.tabs[tabId]; /******************************************************************************/
button.setAttribute('badge', icon && icon.badge || '');
if ( !icon || !icon.img ) { vAPI.toolbarButton.onViewShowing = function({target}) {
icon = ''; target.firstChild.setAttribute('src', vAPI.getURL('popup.html'));
} };
else {
icon = 'url(' + vAPI.getURL('img/browsericons/icon16.svg') + ')';
}
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 // clean up when the extension is disabled
window.addEventListener('unload', function() { window.addEventListener('unload', function() {

Loading…
Cancel
Save