diff --git a/browser/components/microsummaries/public/nsIMicrosummaryService.idl b/browser/components/microsummaries/public/nsIMicrosummaryService.idl index ebe985ce417..a0253736bd7 100644 --- a/browser/components/microsummaries/public/nsIMicrosummaryService.idl +++ b/browser/components/microsummaries/public/nsIMicrosummaryService.idl @@ -338,3 +338,18 @@ interface nsIMicrosummaryService : nsISupports */ nsIMicrosummary refreshMicrosummary(in nsISupports bookmarkID); }; + +[scriptable, uuid(f9e577a8-19d9-4ca0-a140-b9e43f014470)] +interface nsILiveTitleNotificationSubject : nsISupports +{ + // The ID of the bookmark displaying this title. + // Note: in the old bookmarks code, this is an RDF resource. In Places + // it is currently a URI, but after the fix for bug 360133 lands it will + // become an integer. + readonly attribute nsISupports bookmarkID; + + // The microsummary being displayed as the live title for the bookmark. + // The actual value of the microsummary (i.e. the string that gets displayed + // to the user) is stored in the content property of this object. + readonly attribute nsIMicrosummary microsummary; +}; diff --git a/browser/components/microsummaries/src/nsMicrosummaryService.js b/browser/components/microsummaries/src/nsMicrosummaryService.js index 2c185860379..94b1830af17 100644 --- a/browser/components/microsummaries/src/nsMicrosummaryService.js +++ b/browser/components/microsummaries/src/nsMicrosummaryService.js @@ -296,12 +296,35 @@ MicrosummaryService.prototype = { }, _updateMicrosummary: function MSS__updateMicrosummary(bookmarkID, microsummary) { - this._setField(bookmarkID, FIELD_GENERATED_TITLE, microsummary.content); + // Get the current live title to see if it's actually changed. + var oldValue = this._getField(bookmarkID, FIELD_GENERATED_TITLE); + + // A string identifying the bookmark to use when logging the update. + var bookmarkIdentity = +#ifdef MOZ_PLACES_BOOKMARKS + bookmarkID.spec; +#else + bookmarkID.Value + " (" + microsummary.pageURI.spec + ")"; +#endif + + if (oldValue == null || oldValue != microsummary.content) { + this._setField(bookmarkID, FIELD_GENERATED_TITLE, microsummary.content); + var subject = new LiveTitleNotificationSubject(bookmarkID, microsummary); + LOG("updated live title for " + bookmarkIdentity + + " from '" + (oldValue == null ? "" : oldValue) + + "' to '" + microsummary.content + "'"); + this._obs.notifyObservers(subject, "microsummary-livetitle-updated", oldValue); + } + else { + LOG("didn't update live title for " + bookmarkIdentity + "; it hasn't changed"); + } + + // Whether or not the title itself has changed, we still save any changes + // to the update interval, since the interval represents how long to wait + // before checking again for updates, and that can vary across updates, + // even when the title itself hasn't changed. this._setField(bookmarkID, FIELD_MICSUM_EXPIRATION, Date.now() + (microsummary.updateInterval || this._updateInterval)); - - LOG("updated microsummary for page " + microsummary.pageURI.spec + - " to " + microsummary.content); }, /** @@ -1099,6 +1122,30 @@ MicrosummaryService.prototype = { +function LiveTitleNotificationSubject(bookmarkID, microsummary) { + this.bookmarkID = bookmarkID; + this.microsummary = microsummary; +} + +LiveTitleNotificationSubject.prototype = { + bookmarkID: null, + microsummary: null, + + interfaces: [Ci.nsILiveTitleNotificationSubject, Ci.nsISupports], + + // nsISupports + + QueryInterface: function (iid) { + if (!this.interfaces.some( function(v) { return iid.equals(v) } )) + throw Components.results.NS_ERROR_NO_INTERFACE; + return this; + } +}; + + + + + function Microsummary(aPageURI, aGenerator) { this._observers = []; this._pageURI = aPageURI || null;