Bug 872147 - Make FeedHandler use async prompts. r=mfinkle
☠☠ backed out by b11bffd58de9 ☠ ☠
authorWes Johnston <wjohnston@mozilla.com>
Mon, 03 Jun 2013 09:20:45 -0700
changeset 133817 c3b5567f1271c88ebc991c6155a35e3db5121d34
parent 133816 d3106edd4a5a31029afad97c1c3fa4bf13eb2fd6
child 133818 80455a25276b4eed1fbe9067c901860ae08c1a3d
push id28907
push userwjohnston@mozilla.com
push dateMon, 03 Jun 2013 16:22:12 +0000
treeherdermozilla-inbound@8904d2bf5da0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs872147
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 872147 - Make FeedHandler use async prompts. r=mfinkle
mobile/android/chrome/content/FeedHandler.js
--- a/mobile/android/chrome/content/FeedHandler.js
+++ b/mobile/android/chrome/content/FeedHandler.js
@@ -67,74 +67,53 @@ var FeedHandler = {
       let browser = tab.browser;
       let feeds = browser.feeds;
       if (feeds == null)
         return;
 
       // First, let's decide on which feed to subscribe
       let feedIndex = -1;
       if (feeds.length > 1) {
-        // JSON for Prompt
-        let feedResult = {
-          type: "Prompt:Show",
-          multiple: false,
-          selected: [],
-          listitems: []
-        };
+        let p = new Prompt({
+          window: browser.contentWindow,
+        }).setSingleChoiceItems(feeds.map(function(feed) {
+          return { label: feed.title || feed.href }
+        })).show((function(data) {
+          feedIndex = data.button;
+          if (feedIndex == -1)
+            return;
 
-        // Build the list of feeds
-        for (let i = 0; i < feeds.length; i++) {
-          let item = {
-            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;
+          this.loadFeed(feeds[feedIndex], browser);
+        }).bind(this));
+        return;
       }
 
-      if (feedIndex == -1)
-        return;
-      let feedURL = feeds[feedIndex].href;
+      this.loadFeed(feeds[0], browser);
+    }
+  },
+
+  loadFeed: function fh_loadFeed(aFeed, aBrowser) {
+      let feedURL = aFeed.href;
 
       // Next, we decide on which service to send the feed
       let handlers = this.getContentHandlers(this.TYPE_MAYBE_FEED);
       if (handlers.length == 0)
         return;
 
       // JSON for Prompt
-      let handlerResult = {
-        type: "Prompt:Show",
-        multiple: false,
-        selected: [],
-        listitems: []
-      };
+      let p = new Prompt({
+        window: aBrowser.contentWindow
+      }).setSingleChoiceItems(handlers.map(function(handler) {
+        return { label: handler.name };
+      })).show(function(data) {
+        if (data.button == -1)
+          return;
 
-      // Build the list of handlers
-      for (let i = 0; i < handlers.length; ++i) {
-        let item = {
-          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
+        let readerURL = handlers[data.button].uri;
+        readerURL = readerURL.replace(/%s/gi, encodeURIComponent(feedURL));
 
-      // Merge the handler URL and the feed URL
-      let readerURL = handlers[handlerIndex].uri;
-      readerURL = readerURL.replace(/%s/gi, encodeURIComponent(feedURL));
+        // Open the resultant URL in a new tab
+        BrowserApp.addTab(readerURL, { parentId: BrowserApp.selectedTab.id });
+      });
 
-      // Open the resultant URL in a new tab
-      BrowserApp.addTab(readerURL, { parentId: BrowserApp.selectedTab.id });
-    }
   }
 };