Bug 872147 - Make FeedHandler use async prompts. r=mfinkle

This commit is contained in:
Wes Johnston 2013-06-03 09:20:45 -07:00
parent 5b37bbda6b
commit 184a6d5e0a

View File

@ -72,34 +72,26 @@ var FeedHandler = {
// First, let's decide on which feed to subscribe // First, let's decide on which feed to subscribe
let feedIndex = -1; let feedIndex = -1;
if (feeds.length > 1) { if (feeds.length > 1) {
// JSON for Prompt let p = new Prompt({
let feedResult = { window: browser.contentWindow,
type: "Prompt:Show", }).setSingleChoiceItems(feeds.map(function(feed) {
multiple: false, return { label: feed.title || feed.href }
selected: [], })).show((function(data) {
listitems: [] feedIndex = data.button;
}; if (feedIndex == -1)
return;
// Build the list of feeds this.loadFeed(feeds[feedIndex], browser);
for (let i = 0; i < feeds.length; i++) { }).bind(this));
let item = { return;
label: feeds[i].title || feeds[i].href,
isGroup: false,
inGroup: false,
disabled: false,
id: i
};
feedResult.listitems.push(item);
}
feedIndex = JSON.parse(sendMessageToJava(feedResult)).button;
} else {
// Only a single feed on the page
feedIndex = 0;
} }
if (feedIndex == -1) this.loadFeed(feeds[0], browser);
return; }
let feedURL = feeds[feedIndex].href; },
loadFeed: function fh_loadFeed(aFeed, aBrowser) {
let feedURL = aFeed.href;
// Next, we decide on which service to send the feed // Next, we decide on which service to send the feed
let handlers = this.getContentHandlers(this.TYPE_MAYBE_FEED); let handlers = this.getContentHandlers(this.TYPE_MAYBE_FEED);
@ -107,34 +99,21 @@ var FeedHandler = {
return; return;
// JSON for Prompt // JSON for Prompt
let handlerResult = { let p = new Prompt({
type: "Prompt:Show", window: aBrowser.contentWindow
multiple: false, }).setSingleChoiceItems(handlers.map(function(handler) {
selected: [], return { label: handler.name };
listitems: [] })).show(function(data) {
}; if (data.button == -1)
return;
// Build the list of handlers // Merge the handler URL and the feed URL
for (let i = 0; i < handlers.length; ++i) { let readerURL = handlers[data.button].uri;
let item = { readerURL = readerURL.replace(/%s/gi, encodeURIComponent(feedURL));
label: handlers[i].name,
isGroup: false,
inGroup: false,
disabled: false,
id: i
};
handlerResult.listitems.push(item);
}
let handlerIndex = JSON.parse(sendMessageToJava(handlerResult)).button;
if (handlerIndex == -1)
return;
// Merge the handler URL and the feed URL // Open the resultant URL in a new tab
let readerURL = handlers[handlerIndex].uri; BrowserApp.addTab(readerURL, { parentId: BrowserApp.selectedTab.id });
readerURL = readerURL.replace(/%s/gi, encodeURIComponent(feedURL)); });
// Open the resultant URL in a new tab
BrowserApp.addTab(readerURL, { parentId: BrowserApp.selectedTab.id });
}
} }
}; };