Bug 1183296 - feeds should display in e10s mode, r=billm, a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 17 Sep 2015 18:06:44 +0100
changeset 296260 5bacade79fc5d26ce8c2fc50adc1d084d342eab2
parent 296259 36b3f1e21a29b4429a913cb5db8eb7a21202d93d
child 296261 35b3e4d35d2910419ec5971c8b8771b38f197cb4
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm, lizzard
bugs1183296
milestone43.0a2
Bug 1183296 - feeds should display in e10s mode, r=billm, a=lizzard
browser/base/content/browser-feeds.js
browser/base/content/browser.js
browser/components/feeds/FeedWriter.js
browser/components/feeds/test/mochitest.ini
--- a/browser/base/content/browser-feeds.js
+++ b/browser/base/content/browser-feeds.js
@@ -162,10 +162,22 @@ var FeedHandler = {
     // background browsers, we'll update on tab switch.
     if (browserForLink == gBrowser.selectedBrowser) {
       // Batch updates to avoid updating the UI for multiple onLinkAdded events
       // fired within 100ms of each other.
       if (this._updateFeedTimeout)
         clearTimeout(this._updateFeedTimeout);
       this._updateFeedTimeout = setTimeout(this.updateFeeds.bind(this), 100);
     }
-  }
+  },
+
+  init() {
+    window.messageManager.addMessageListener("FeedWriter:ShownFirstRun", this);
+  },
+
+  receiveMessage(msg) {
+    switch (msg.name) {
+      case "FeedWriter:ShownFirstRun":
+        Services.prefs.setBoolPref("browser.feeds.showFirstRunUI", false);
+        break;
+    }
+  },
 };
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -960,16 +960,17 @@ var gBrowserInit = {
     // These routines add message listeners. They must run before
     // loading the frame script to ensure that we don't miss any
     // message sent between when the frame script is loaded and when
     // the listener is registered.
     DOMLinkHandler.init();
     gPageStyleMenu.init();
     LanguageDetectionListener.init();
     BrowserOnClick.init();
+    FeedHandler.init();
     DevEdition.init();
     AboutPrivateBrowsingListener.init();
     TrackingProtection.init();
 
     let mm = window.getGroupMessageManager("browsers");
     mm.loadFrameScript("chrome://browser/content/tab-content.js", true);
     mm.loadFrameScript("chrome://browser/content/content.js", true);
     mm.loadFrameScript("chrome://browser/content/content-UITour.js", true);
--- a/browser/components/feeds/FeedWriter.js
+++ b/browser/components/feeds/FeedWriter.js
@@ -4,16 +4,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
 
 const FEEDWRITER_CID = Components.ID("{49bb6593-3aff-4eb3-a068-2712c28bd58e}");
 const FEEDWRITER_CONTRACTID = "@mozilla.org/browser/feeds/result-writer;1";
 
 function LOG(str) {
   var prefB = Cc["@mozilla.org/preferences-service;1"].
               getService(Ci.nsIPrefBranch);
 
@@ -708,19 +709,17 @@ FeedWriter.prototype = {
     }
   },
 
   _setAlwaysUseCheckedState: function FW__setAlwaysUseCheckedState(feedType) {
     var checkbox = this._getUIElement("alwaysUse");
     if (checkbox) {
       var alwaysUse = false;
       try {
-        var prefs = Cc["@mozilla.org/preferences-service;1"].
-                    getService(Ci.nsIPrefBranch);
-        if (prefs.getCharPref(getPrefActionForType(feedType)) != "ask")
+        if (Services.prefs.getCharPref(getPrefActionForType(feedType)) != "ask")
           alwaysUse = true;
       }
       catch(ex) { }
       this._setCheckboxCheckedState(checkbox, alwaysUse);
     }
   },
 
   _setSubscribeUsingLabel: function FW__setSubscribeUsingLabel() {
@@ -798,20 +797,17 @@ FeedWriter.prototype = {
           break;
         default:
           this._setAlwaysUseLabel();
       }
     }
   },
 
   _setSelectedHandler: function FW__setSelectedHandler(feedType) {
-    var prefs =
-        Cc["@mozilla.org/preferences-service;1"].
-        getService(Ci.nsIPrefBranch);
-
+    var prefs = Services.prefs;
     var handler = "bookmarks";
     try {
       handler = prefs.getCharPref(getPrefReaderForType(feedType));
     }
     catch (ex) { }
 
     switch (handler) {
       case "web": {
@@ -894,20 +890,18 @@ FeedWriter.prototype = {
 
     // Last-selected application
     var menuItem = liveBookmarksMenuItem.cloneNode(false);
     menuItem.removeAttribute("selected");
     menuItem.setAttribute("anonid", "selectedAppMenuItem");
     menuItem.className = "menuitem-iconic selectedAppMenuItem";
     menuItem.setAttribute("handlerType", "client");
     try {
-      var prefs = Cc["@mozilla.org/preferences-service;1"].
-                  getService(Ci.nsIPrefBranch);
-      this._selectedApp = prefs.getComplexValue(getPrefAppForType(feedType),
-                                                Ci.nsILocalFile);
+      this._selectedApp = Services.prefs.getComplexValue(getPrefAppForType(feedType),
+                                                         Ci.nsILocalFile);
 
       if (this._selectedApp.exists())
         this._initMenuItemWithFile(menuItem, this._selectedApp);
       else {
         // Hide the menuitem if the last selected application doesn't exist
         menuItem.setAttribute("hidden", true);
       }
     }
@@ -953,35 +947,39 @@ FeedWriter.prototype = {
     menuItem.setAttribute("label", this._getString("chooseApplicationMenuItem"));
 
     handlersMenuPopup.appendChild(menuItem);
 
     // separator
     var chooseAppSep = liveBookmarksMenuItem.nextSibling.cloneNode(false);
     handlersMenuPopup.appendChild(chooseAppSep);
 
-    // List of web handlers
-    var wccr = Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
-               getService(Ci.nsIWebContentConverterService);
-    var handlers = wccr.getContentHandlers(this._getMimeTypeForFeedType(feedType));
-    if (handlers.length != 0) {
-      for (var i = 0; i < handlers.length; ++i) {
-        if (!handlers[i].uri) {
-          LOG("Handler with name " + handlers[i].name + " has no URI!? Skipping...");
-          continue;
+    // FIXME: getting a list of webhandlers doesn't work in the content process
+    // right now, see bug 1109714.
+    if (Services.appinfo.processType != Services.appinfo.PROCESS_TYPE_CONTENT) {
+      // List of web handlers
+      var wccr = Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
+                 getService(Ci.nsIWebContentConverterService);
+      var handlers = wccr.getContentHandlers(this._getMimeTypeForFeedType(feedType));
+      if (handlers.length != 0) {
+        for (var i = 0; i < handlers.length; ++i) {
+          if (!handlers[i].uri) {
+            LOG("Handler with name " + handlers[i].name + " has no URI!? Skipping...");
+            continue;
+          }
+          menuItem = liveBookmarksMenuItem.cloneNode(false);
+          menuItem.removeAttribute("selected");
+          menuItem.className = "menuitem-iconic";
+          menuItem.setAttribute("label", handlers[i].name);
+          menuItem.setAttribute("handlerType", "web");
+          menuItem.setAttribute("webhandlerurl", handlers[i].uri);
+          handlersMenuPopup.appendChild(menuItem);
+
+          this._setFaviconForWebReader(handlers[i].uri, menuItem);
         }
-        menuItem = liveBookmarksMenuItem.cloneNode(false);
-        menuItem.removeAttribute("selected");
-        menuItem.className = "menuitem-iconic";
-        menuItem.setAttribute("label", handlers[i].name);
-        menuItem.setAttribute("handlerType", "web");
-        menuItem.setAttribute("webhandlerurl", handlers[i].uri);
-        handlersMenuPopup.appendChild(menuItem);
-
-        this._setFaviconForWebReader(handlers[i].uri, menuItem);
       }
     }
 
     this._setSelectedHandler(feedType);
 
     // "Subscribe using..."
     this._setSubscribeUsingLabel();
 
@@ -995,17 +993,17 @@ FeedWriter.prototype = {
 
     // Set up the "Subscribe Now" button
     this._getUIElement("subscribeButton")
         .addEventListener("command", this, false);
 
     // first-run ui
     var showFirstRunUI = true;
     try {
-      showFirstRunUI = prefs.getBoolPref(PREF_SHOW_FIRST_RUN_UI);
+      showFirstRunUI = Services.prefs.getBoolPref(PREF_SHOW_FIRST_RUN_UI);
     }
     catch (ex) { }
     if (showFirstRunUI) {
       var textfeedinfo1, textfeedinfo2;
       switch (feedType) {
         case Ci.nsIFeed.TYPE_VIDEO:
           textfeedinfo1 = "feedSubscriptionVideoPodcast1";
           textfeedinfo2 = "feedSubscriptionVideoPodcast2";
@@ -1024,17 +1022,17 @@ FeedWriter.prototype = {
       var feedinfo2 = this._document.getElementById("feedSubscriptionInfo2");
       var feedinfo2Str = this._getString(textfeedinfo2);
 
       feedinfo1.textContent = feedinfo1Str;
       feedinfo2.textContent = feedinfo2Str;
 
       header.setAttribute('firstrun', 'true');
 
-      prefs.setBoolPref(PREF_SHOW_FIRST_RUN_UI, false);
+      this._mm.sendAsyncMessage("FeedWriter:ShownFirstRun");
     }
   },
 
   /**
    * Returns the original URI object of the feed and ensures that this
    * component is only ever invoked from the preview document.  
    * @param aWindow 
    *        The window of the document invoking the BrowserFeedWriter
@@ -1085,18 +1083,17 @@ FeedWriter.prototype = {
     var secman = Cc["@mozilla.org/scriptsecuritymanager;1"].
                  getService(Ci.nsIScriptSecurityManager);
     this._feedPrincipal = secman.getSimpleCodebasePrincipal(this._feedURI);
 
     LOG("Subscribe Preview: feed uri = " + this._window.location.href);
 
     // Set up the subscription UI
     this._initSubscriptionUI();
-    var prefs = Cc["@mozilla.org/preferences-service;1"].
-                getService(Ci.nsIPrefBranch);
+    let prefs = Services.prefs;
     prefs.addObserver(PREF_SELECTED_ACTION, this, false);
     prefs.addObserver(PREF_SELECTED_READER, this, false);
     prefs.addObserver(PREF_SELECTED_WEB, this, false);
     prefs.addObserver(PREF_SELECTED_APP, this, false);
     prefs.addObserver(PREF_VIDEO_SELECTED_ACTION, this, false);
     prefs.addObserver(PREF_VIDEO_SELECTED_READER, this, false);
     prefs.addObserver(PREF_VIDEO_SELECTED_WEB, this, false);
     prefs.addObserver(PREF_VIDEO_SELECTED_APP, this, false);
@@ -1128,18 +1125,17 @@ FeedWriter.prototype = {
 
   close: function FW_close() {
     this._getUIElement("handlersMenuPopup")
         .removeEventListener("command", this, false);
     this._getUIElement("subscribeButton")
         .removeEventListener("command", this, false);
     this._document = null;
     this._window = null;
-    var prefs = Cc["@mozilla.org/preferences-service;1"].
-                getService(Ci.nsIPrefBranch);
+    let prefs = Services.prefs;
     prefs.removeObserver(PREF_SELECTED_ACTION, this);
     prefs.removeObserver(PREF_SELECTED_READER, this);
     prefs.removeObserver(PREF_SELECTED_WEB, this);
     prefs.removeObserver(PREF_SELECTED_APP, this);
     prefs.removeObserver(PREF_VIDEO_SELECTED_ACTION, this);
     prefs.removeObserver(PREF_VIDEO_SELECTED_READER, this);
     prefs.removeObserver(PREF_VIDEO_SELECTED_WEB, this);
     prefs.removeObserver(PREF_VIDEO_SELECTED_APP, this);
@@ -1167,18 +1163,17 @@ FeedWriter.prototype = {
       this._feedURI = null;
     }
   },
 
   subscribe: function FW_subscribe() {
     var feedType = this._getFeedType();
 
     // Subscribe to the feed using the selected handler and save prefs
-    var prefs = Cc["@mozilla.org/preferences-service;1"].
-                getService(Ci.nsIPrefBranch);
+    var prefs = Services.prefs;
     var defaultHandler = "reader";
     var useAsDefault = this._getUIElement("alwaysUse").getAttribute("checked");
 
     var selectedItem = this._getSelectedItemFromMenulist(this._handlersMenuList);
     let subscribeCallback = function() {
       if (selectedItem.hasAttribute("webhandlerurl")) {
         var webURI = selectedItem.getAttribute("webhandlerurl");
         prefs.setCharPref(getPrefReaderForType(feedType), "web");
@@ -1315,15 +1310,24 @@ FeedWriter.prototype = {
         if (aDataLen > 0) {
           var dataURL = "data:" + aMimeType + ";base64," +
                         btoa(String.fromCharCode.apply(null, aData));
           aMenuItem.setAttribute('image', dataURL);
         }
       });
   },
 
+  get _mm() {
+    let mm = this._window.QueryInterface(Ci.nsIInterfaceRequestor).
+                          getInterface(Ci.nsIDocShell).
+                          QueryInterface(Ci.nsIInterfaceRequestor).
+                          getInterface(Ci.nsIContentFrameMessageManager);
+    delete this._mm;
+    return this._mm = mm;
+  },
+
   classID: FEEDWRITER_CID,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMEventListener, Ci.nsIObserver,
                                          Ci.nsINavHistoryObserver,
                                          Ci.nsIDOMGlobalPropertyInitializer])
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FeedWriter]);
--- a/browser/components/feeds/test/mochitest.ini
+++ b/browser/components/feeds/test/mochitest.ini
@@ -5,14 +5,11 @@ support-files =
   bug408328-data.xml
   bug436801-data.xml
   bug494328-data.xml
   bug589543-data.xml
   valid-feed.xml
   valid-unsniffable-feed.xml
 
 [test_bug436801.html]
-skip-if = e10s
 [test_bug494328.html]
-skip-if = e10s
 [test_bug589543.html]
-skip-if = e10s
 [test_registerHandler.html]