cleanup for bug 405105, r=gavin

This commit is contained in:
Serge Gautherie 2008-07-12 12:07:51 +02:00
Родитель 31d8086891
Коммит 675cc0333d
1 изменённых файлов: 16 добавлений и 9 удалений

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

@ -348,9 +348,9 @@ function resetPageInfo()
/* Reset Media tab */ /* Reset Media tab */
var mediaTab = document.getElementById("mediaTab"); var mediaTab = document.getElementById("mediaTab");
if (!mediaTab.hidden) { if (!mediaTab.hidden) {
var os = Components.classes["@mozilla.org/observer-service;1"] Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService); .getService(Components.interfaces.nsIObserverService)
os.removeObserver(imagePermissionObserver, "perm-changed"); .removeObserver(imagePermissionObserver, "perm-changed");
mediaTab.hidden = true; mediaTab.hidden = true;
} }
gImageView.clear(); gImageView.clear();
@ -370,10 +370,11 @@ function resetPageInfo()
function onUnloadPageInfo() function onUnloadPageInfo()
{ {
// Remove the observer, only if there is at least 1 image.
if (!document.getElementById("mediaTab").hidden) { if (!document.getElementById("mediaTab").hidden) {
var os = Components.classes["@mozilla.org/observer-service;1"] Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService); .getService(Components.interfaces.nsIObserverService)
os.removeObserver(imagePermissionObserver, "perm-changed"); .removeObserver(imagePermissionObserver, "perm-changed");
} }
/* Call registered overlay unload functions */ /* Call registered overlay unload functions */
@ -542,6 +543,7 @@ function doGrab(iterator)
processFrames(); processFrames();
return; return;
} }
setTimeout(doGrab, 16, iterator); setTimeout(doGrab, 16, iterator);
} }
@ -557,6 +559,7 @@ function addImage(url, type, alt, elem, isBg)
{ {
if (!url) if (!url)
return; return;
if (!gImageHash.hasOwnProperty(url)) if (!gImageHash.hasOwnProperty(url))
gImageHash[url] = { }; gImageHash[url] = { };
if (!gImageHash[url].hasOwnProperty(type)) if (!gImageHash[url].hasOwnProperty(type))
@ -584,11 +587,13 @@ function addImage(url, type, alt, elem, isBg)
else else
sizeText = gStrings.unknown; sizeText = gStrings.unknown;
gImageView.addRow([url, type, sizeText, alt, 1, elem, isBg]); gImageView.addRow([url, type, sizeText, alt, 1, elem, isBg]);
// Add the observer, only once.
if (gImageView.data.length == 1) { if (gImageView.data.length == 1) {
document.getElementById("mediaTab").hidden = false; document.getElementById("mediaTab").hidden = false;
var os = Components.classes["@mozilla.org/observer-service;1"] Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService); .getService(Components.interfaces.nsIObserverService)
os.addObserver(imagePermissionObserver, "perm-changed", false); .addObserver(imagePermissionObserver, "perm-changed", false);
} }
} }
else { else {
@ -665,6 +670,7 @@ function onBeginLinkDrag(event,urlField,descField)
.createInstance(Components.interfaces.nsISupportsArray); .createInstance(Components.interfaces.nsISupportsArray);
if (!transArray) if (!transArray)
return; return;
var trans = Components.classes[TRANSFERABLE_CONTRACTID] var trans = Components.classes[TRANSFERABLE_CONTRACTID]
.createInstance(Components.interfaces.nsITransferable); .createInstance(Components.interfaces.nsITransferable);
if (!trans) if (!trans)
@ -1017,6 +1023,7 @@ var imagePermissionObserver = {
{ {
if (document.getElementById("mediaPreviewBox").collapsed) if (document.getElementById("mediaPreviewBox").collapsed)
return; return;
if (aTopic == "perm-changed") { if (aTopic == "perm-changed") {
var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission); var permission = aSubject.QueryInterface(Components.interfaces.nsIPermission);
if (permission.type == "image") { if (permission.type == "image") {