Bug 595639 - Prevent badges handlers to access the awesome row directly [r=mfinkle]

This commit is contained in:
Vivien Nicolas 2010-09-12 16:25:41 +02:00
parent 7b86e0447f
commit 8aadba5fd0
2 changed files with 26 additions and 12 deletions

View File

@ -391,11 +391,25 @@
if (!item.hasAttribute("url"))
continue;
let itemHost = self._getEffectiveHost(Services.io.newURI(item.getAttribute("url"), null, null));
let currentURL = item.getAttribute("url");
let itemHost = self._getEffectiveHost(Services.io.newURI(currentURL, null, null));
for (let badgeHost in self._badges) {
if (itemHost == badgeHost) {
// wrap the item to prevent setting a badge on a wrong item
let wrapper = {
set: function(aBadge) {
if (item.getAttribute("url") != currentURL)
return;
if (!aBadge || aBadge == "")
item.removeAttribute("badge");
else
item.setAttribute("badge", aBadge);
}
};
let handler = self._badges[badgeHost];
handler.updateBadge ? handler.updateBadge(item) : handler(item);
handler.updateBadge ? handler.updateBadge(wrapper) : handler(wrapper);
break;
}
}
@ -1216,15 +1230,15 @@
tabs.push({ name: client.clientName });
client.tabs.forEach(function({title, urlHistory, icon}) {
let pageUrl = urlHistory[0];
let pageURL = urlHistory[0];
// Skip tabs that are already open
if (engine.locallyOpenTabMatchesURL(pageUrl))
if (engine.locallyOpenTabMatchesURL(pageURL))
return;
tabs.push({
title: title || pageUrl,
uri: pageUrl,
title: title || pageURL,
uri: pageURL,
icon: Weave.Utils.getIcon(icon, "chrome://browser/skin/images/tab.png")
});
});

View File

@ -2512,11 +2512,11 @@ var BadgeHandlers = {
_lastUpdate: 0,
_lastCount: 0,
url: "http://mail.google.com",
updateBadge: function(aItem) {
updateBadge: function(aBadge) {
// Use the cache if possible
let now = Date.now();
if (this._lastCount && this._lastUpdate > now - 1000) {
aItem.setAttribute("badge", this._lastCount);
aBadge.set(this._lastCount);
return;
}
@ -2538,7 +2538,7 @@ var BadgeHandlers = {
} else {
this._lastCount = 0;
}
this._lastCount = BadgeHandlers.setNumberBadge(aItem, this._lastCount);
this._lastCount = BadgeHandlers.setNumberBadge(aBadge, this._lastCount);
}
};
req.send(null);
@ -2566,12 +2566,12 @@ var BadgeHandlers = {
return aValue;
},
setNumberBadge: function(aItem, aValue) {
setNumberBadge: function(aBadge, aValue) {
if (parseInt(aValue) != 0) {
aValue = this.clampBadge(aValue);
aItem.setAttribute("badge", aValue);
aBadge.set(aValue);
} else {
aItem.removeAttribute("badge");
aBadge.set("");
}
return aValue;
}