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
Родитель 111389da29
Коммит 09d917d15c
2 изменённых файлов: 26 добавлений и 12 удалений

Просмотреть файл

@ -391,11 +391,25 @@
if (!item.hasAttribute("url")) if (!item.hasAttribute("url"))
continue; 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) { for (let badgeHost in self._badges) {
if (itemHost == badgeHost) { 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]; let handler = self._badges[badgeHost];
handler.updateBadge ? handler.updateBadge(item) : handler(item); handler.updateBadge ? handler.updateBadge(wrapper) : handler(wrapper);
break; break;
} }
} }
@ -1216,15 +1230,15 @@
tabs.push({ name: client.clientName }); tabs.push({ name: client.clientName });
client.tabs.forEach(function({title, urlHistory, icon}) { client.tabs.forEach(function({title, urlHistory, icon}) {
let pageUrl = urlHistory[0]; let pageURL = urlHistory[0];
// Skip tabs that are already open // Skip tabs that are already open
if (engine.locallyOpenTabMatchesURL(pageUrl)) if (engine.locallyOpenTabMatchesURL(pageURL))
return; return;
tabs.push({ tabs.push({
title: title || pageUrl, title: title || pageURL,
uri: pageUrl, uri: pageURL,
icon: Weave.Utils.getIcon(icon, "chrome://browser/skin/images/tab.png") icon: Weave.Utils.getIcon(icon, "chrome://browser/skin/images/tab.png")
}); });
}); });

Просмотреть файл

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