diff --git a/mailnews/addrbook/resources/content/abCardViewOverlay.js b/mailnews/addrbook/resources/content/abCardViewOverlay.js index e3ab85ad7aa..6b3e9faba84 100644 --- a/mailnews/addrbook/resources/content/abCardViewOverlay.js +++ b/mailnews/addrbook/resources/content/abCardViewOverlay.js @@ -30,12 +30,9 @@ var gPrefs = Components.classes["@mozilla.org/preferences-service;1"]; gPrefs = gPrefs.getService(); gPrefs = gPrefs.QueryInterface(Components.interfaces.nsIPrefBranch); - -var gProfile = Components.classes["@mozilla.org/profile/manager;1"].getService(Components.interfaces.nsIProfileInternal); -var gProfileDirURL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL); -gProfileDirURL.file = gProfile.getProfileDir(gProfile.currentProfile); -var gIconFileURL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL); +var gProfileDirURL; +var gIconFileURL; var gMapItURLFormat = gPrefs.getComplexValue("mail.addr_book.mapit_url.format", Components.interfaces.nsIPrefLocalizedString).data; @@ -339,11 +336,22 @@ function setBuddyIcon(card, buddyIcon) try { var myScreenName = gPrefs.getCharPref("aim.session.screenname"); if (myScreenName && card.primaryEmail) { + if (!gProfileDirURL) { + // lazily create these file urls, and keep them around + gProfileDirURL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL); + gIconFileURL = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIFileURL); + var profile = Components.classes["@mozilla.org/profile/manager;1"].getService(Components.interfaces.nsIProfileInternal); + gProfileDirURL.file = profile.getProfileDir(profile.currentProfile); + } + + // if we did have a buddy icon on disk for this screenname, this would be the file url spec for it var iconURLStr = gProfileDirURL.spec + "/NIM/" + myScreenName + "/picture/" + card.aimScreenName + ".gif"; // check if the file exists gIconFileURL.spec = iconURLStr; + // check if the file exists + // is this a perf hit? (how expensive is stat()?) if (gIconFileURL.file.exists()) { buddyIcon.setAttribute("src", iconURLStr); return true;