Bug 348227. Live Bookmarks should take metadata from the Feed, not the page. r=mano

This commit is contained in:
sayrer%gmail.com 2006-08-28 17:24:28 +00:00
Родитель f180935b18
Коммит 3633149ca8
5 изменённых файлов: 63 добавлений и 32 удалений

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

@ -187,20 +187,33 @@ var PlacesCommandHook = {
/**
* Adds a Live Bookmark to a feed associated with the current page.
* @param url
* The nsIURI of the page the feed was attached to
* @param url
* The nsIURI of the page the feed was attached to
* @title title
* The title of the feed. Optional.
* @subtitle subtitle
* A short description of the feed. Optional.
* Not yet used. TODO: implement description annotation
*/
addLiveBookmark: function PCH_addLiveBookmark(url) {
addLiveBookmark: function PCH_addLiveBookmark(url, feedTitle, feedSubtitle) {
var ios =
Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var feedURI = ios.newURI(url, null, null);
var browser = gBrowser.selectedBrowser;
var title = (arguments.length > 1) ? feedTitle :
browser.contentDocument.title;
// TODO: implement description annotation
//var description = this._getDescriptionFromDocument(doc);
var title = browser.contentDocument.title;
#if 0
var description;
if (arguments.length > 2)
description = feedSubtitle;
else
description = BookmarksUtils.getDescriptionFromDocument(doc);
#endif
// TODO: add dialog for filing/confirmation
var bms = PlacesController.bookmarks;

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

@ -6566,13 +6566,21 @@ var FeedHandler = {
#ifndef MOZ_PLACES
/**
* Adds a Live Bookmark to a feed
* @param url
* The URL of the feed being bookmarked
* @param url
* The URL of the feed being bookmarked
* @title title
* The title of the feed. Optional.
* @subtitle subtitle
* A short description of the feed. Optional.
*/
addLiveBookmark: function(url) {
addLiveBookmark: function(url, feedTitle, feedSubtitle) {
var doc = gBrowser.selectedBrowser.contentDocument;
var title = doc.title;
var description = BookmarksUtils.getDescriptionFromDocument(doc);
var title = (arguments.length > 1) ? feedTitle : doc.title;
var description;
if (arguments.length > 2)
description = feedSubtitle;
else
description = BookmarksUtils.getDescriptionFromDocument(doc);
BookmarksUtils.addLivemark(doc.baseURI, url, title, description);
},
#endif

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

@ -45,7 +45,7 @@ interface nsIFeedResult;
* nsIFeedResultService provides a globally-accessible object for retreiving
* the results of feed processing.
*/
[scriptable, uuid(96dadf57-6a1d-44d3-83fa-6af22f6cae31)]
[scriptable, uuid(f3262589-48b2-4019-9947-90e5269bbfb9)]
interface nsIFeedResultService : nsISupports
{
/**
@ -57,12 +57,16 @@ interface nsIFeedResultService : nsISupports
/**
* Adds a URI to the user's specified external feed handler, or live
* bookmarks.
* @param request
* The request for the feed document
* @param uri
* The uri of the feed to add.
* @param title
* The title of the feed to add.
* @param subtitle
* The subtitle of the feed to add.
*/
void addToClientReader(in nsIRequest request, in AString uri);
void addToClientReader(in AUTF8String uri,
in AString title,
in AString subtitle);
/**
* Registers a Feed Result object with a globally accessible service

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

@ -206,7 +206,10 @@ FeedConverter.prototype = {
case "bookmarks":
case "client":
try {
feedService.addToClientReader(this._request, result.uri.spec);
var feed = result.doc.QueryInterface(Ci.nsIFeed);
var title = feed.title ? feed.title.plainText() : "";
var desc = feed.subtitle ? feed.subtitle.plainText() : "";
feedService.addToClientReader(result.uri.spec, title, desc);
return;
} catch(ex) { /* fallback to preview mode */ }
}
@ -334,7 +337,7 @@ var FeedResultService = {
/**
* See nsIFeedService.idl
*/
addToClientReader: function FRS_addToClientReader(request, spec) {
addToClientReader: function FRS_addToClientReader(spec, title, subtitle) {
var prefs =
Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
@ -383,9 +386,9 @@ var FeedResultService = {
getService(Ci.nsIWindowMediator);
var topWindow = wm.getMostRecentWindow("navigator:browser");
#ifdef MOZ_PLACES
topWindow.PlacesCommandHook.addLiveBookmark(spec);
topWindow.PlacesCommandHook.addLiveBookmark(spec, title, subtitle);
#else
topWindow.FeedHandler.addLiveBookmark(spec);
topWindow.FeedHandler.addLiveBookmark(spec, title, subtitle);
#endif
break;
}

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

@ -74,6 +74,9 @@ const FW_CLASSID = Components.ID("{49bb6593-3aff-4eb3-a068-2712c28bd58e}");
const FW_CLASSNAME = "Feed Writer";
const FW_CONTRACTID = "@mozilla.org/browser/feeds/result-writer;1";
const TITLE_ID = "feedTitleText";
const SUBTITLE_ID = "feedSubtitleText";
function FeedWriter() {
}
FeedWriter.prototype = {
@ -146,14 +149,14 @@ FeedWriter.prototype = {
* The feed container
*/
_setTitleText: function FW__setTitleText(container) {
if(container.title) {
this._setContentText("feedTitleText", container.title.plainText());
if (container.title) {
this._setContentText(TITLE_ID, container.title.plainText());
this._document.title = container.title.plainText();
}
var feed = container.QueryInterface(Ci.nsIFeed);
if(feed && feed.subtitle)
this._setContentText("feedSubtitleText", container.subtitle.plainText());
if (feed && feed.subtitle)
this._setContentText(SUBTITLE_ID, container.subtitle.plainText());
},
/**
@ -779,20 +782,20 @@ FeedWriter.prototype = {
prefs.setCharPref(PREF_SELECTED_READER, "bookmarks");
break;
}
var request = this._window
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.currentDocumentChannel;
var feedService = Cc["@mozilla.org/browser/feeds/result-service;1"].
getService(Ci.nsIFeedResultService);
feedService.addToClientReader(request, this._window.location.href);
// Pull the title and subtitle out of the document
var feedTitle = this._document.getElementById(TITLE_ID).textContent;
var feedSubtitle =
this._document.getElementById(SUBTITLE_ID).textContent;
feedService.addToClientReader(this._window.location.href,
feedTitle, feedSubtitle);
}
// If "Always use..." is checked, we should set PREF_SELECTED_ACTION
// to either "reader" (If a web reader or if an application is selected), or
// to "bookmarks" (if the live bookmarks option is selected).
// to either "reader" (If a web reader or if an application is selected),
// or to "bookmarks" (if the live bookmarks option is selected).
// Otherwise, we should set it to "ask"
if (useAsDefault)
prefs.setCharPref(PREF_SELECTED_ACTION, defaultHandler);