Browse Source

Trying to fix merge

pull/2/head
AlexVallat 10 years ago
committed by gorhill
parent
commit
16ff5db8f4
  1. 94
      platform/firefox/vapi-background.js

94
platform/firefox/vapi-background.js

@ -1090,9 +1090,9 @@ var httpObserver = {
} }
var result = vAPI.tabs.onPopup({ var result = vAPI.tabs.onPopup({
tabId: tabId,
sourceTabId: sourceTabId,
url: URI.asciiSpec
targetTabId: tabId,
openerTabId: sourceTabId,
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,7 +1428,7 @@ 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);
@ -1442,18 +1436,15 @@ if (vAPI.fennec) {
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() { vAPI.toolbarButton.init = function() {
var CustomizableUI; var CustomizableUI;
try { try {
@ -1495,7 +1486,7 @@ if (vAPI.fennec) {
} else { } else {
this.CUIEvents = {}; 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;
@ -1516,9 +1507,12 @@ if (vAPI.fennec) {
} }
// Anonymous elements need some time to be reachable // Anonymous elements need some time to be reachable
setTimeout(this.updateBadgeStyle, 250);
setTimeout(this.updateBadgeStyle, 50);
}.bind(this.CUIEvents); }.bind(this.CUIEvents);
this.CUIEvents.onCustomizeEnd = updateBadge;
this.CUIEvents.onWidgetUnderflow = updateBadge;
this.CUIEvents.updateBadgeStyle = function() { this.CUIEvents.updateBadgeStyle = function() {
var css = [ var css = [
'background: #666', 'background: #666',
@ -1545,7 +1539,7 @@ if (vAPI.fennec) {
this.onCreated = function(button) { this.onCreated = function(button) {
button.setAttribute('badge', ''); button.setAttribute('badge', '');
setTimeout(this.CUIEvents.onCustomizeEnd, 250);
setTimeout(this.CUIEvents.onCustomizeEnd, 50);
}; };
CustomizableUI.addListener(this.CUIEvents); CustomizableUI.addListener(this.CUIEvents);
@ -1590,6 +1584,7 @@ if (vAPI.fennec) {
}.bind(this)); }.bind(this));
}; };
/******************************************************************************/ /******************************************************************************/
vAPI.toolbarButton.onBeforeCreated = function(doc) { vAPI.toolbarButton.onBeforeCreated = function(doc) {
@ -1659,27 +1654,6 @@ if (vAPI.fennec) {
target.firstChild.setAttribute('src', 'about:blank'); target.firstChild.setAttribute('src', 'about:blank');
}; };
vAPI.toolbarButton.updateState = function(win, tabId) {
var button = win.document.getElementById(this.id);
if ( !button ) {
return;
}
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') + ')';
}
button.style.listStyleImage = icon;
}
}
/******************************************************************************/ /******************************************************************************/
vAPI.toolbarButton.init(); vAPI.toolbarButton.init();
@ -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