Bug 1392324 - Add pref to enable Activity Stream on about:home. draft
authorAndrei Oprea <andrei.br92@gmail.com>
Wed, 23 Aug 2017 10:37:33 +0200
changeset 651193 500b666db8e98ad6f288ba459b3c4da248ef77e4
parent 649871 c7c96eebbcb91e5e0c8ef0dbbb5324812fa1e476
child 727617 b1d35c9a47073b884feadd1f7b670ab5e77cb67e
push id75627
push userbmo:andrei.br92@gmail.com
push dateWed, 23 Aug 2017 10:08:36 +0000
bugs1392324
milestone57.0a1
Bug 1392324 - Add pref to enable Activity Stream on about:home. MozReview-Commit-ID: 8aRn6vWWpF0
browser/app/profile/firefox.js
browser/components/about/AboutRedirector.cpp
browser/components/about/AboutRedirector.h
browser/extensions/activity-stream/lib/ActivityStreamMessageChannel.jsm
browser/modules/AboutNewTab.jsm
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1275,16 +1275,18 @@ pref("browser.newtabpage.directory.sourc
 
 // activates Activity Stream
 #ifdef NIGHTLY_BUILD
 pref("browser.newtabpage.activity-stream.enabled", true);
 #else
 pref("browser.newtabpage.activity-stream.enabled", false);
 #endif
 
+pref("browser.newtabpage.activity-stream.disableHome", false);
+
 // Enable the DOM fullscreen API.
 pref("full-screen-api.enabled", true);
 
 // Startup Crash Tracking
 // number of startup crashes that can occur before starting into safe mode automatically
 // (this pref has no effect if more than 6 hours have passed since the last crash)
 pref("toolkit.startup.max_resumed_crashes", 3);
 
--- a/browser/components/about/AboutRedirector.cpp
+++ b/browser/components/about/AboutRedirector.cpp
@@ -18,16 +18,17 @@
 
 namespace mozilla {
 namespace browser {
 
 NS_IMPL_ISUPPORTS(AboutRedirector, nsIAboutModule)
 
 bool AboutRedirector::sUseOldPreferences = false;
 bool AboutRedirector::sActivityStreamEnabled = false;
+bool AboutRedirector::sActivityStreamDisableHome = false;
 
 struct RedirEntry {
   const char* id;
   const char* url;
   uint32_t flags;
 };
 
 /*
@@ -135,30 +136,36 @@ AboutRedirector::NewChannel(nsIURI* aURI
   nsresult rv;
   nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   static bool sPrefCacheInited = false;
   if (!sPrefCacheInited) {
     Preferences::AddBoolVarCache(&sUseOldPreferences,
                                  "browser.preferences.useOldOrganization");
+    Preferences::AddBoolVarCache(&sActivityStreamDisableHome,
+                                 "browser.newtabpage.activity-stream.disableHome");
     sPrefCacheInited = true;
   }
 
   for (auto & redir : kRedirMap) {
     if (!strcmp(path.get(), redir.id)) {
       nsAutoCString url;
 
       if (path.EqualsLiteral("newtab")) {
         // let the aboutNewTabService decide where to redirect
         nsCOMPtr<nsIAboutNewTabService> aboutNewTabService =
           do_GetService("@mozilla.org/browser/aboutnewtab-service;1", &rv);
         NS_ENSURE_SUCCESS(rv, rv);
         rv = aboutNewTabService->GetDefaultURL(url);
         NS_ENSURE_SUCCESS(rv, rv);
+      } else if (path.EqualsLiteral("home")) {
+        if (sActivityStreamDisableHome) { // Override about:home and set it to Activity Stream.
+          url.AssignASCII("resource://activity-stream/data/content/activity-stream.html");
+        }
       } else if (path.EqualsLiteral("preferences") && !sUseOldPreferences) {
         url.AssignASCII("chrome://browser/content/preferences/in-content-new/preferences.xul");
       }
       // fall back to the specified url in the map
       if (url.IsEmpty()) {
         url.AssignASCII(redir.url);
       }
 
--- a/browser/components/about/AboutRedirector.h
+++ b/browser/components/about/AboutRedirector.h
@@ -23,14 +23,15 @@ public:
     Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
 
 protected:
   virtual ~AboutRedirector() {}
 
 private:
   static bool sUseOldPreferences;
   static bool sActivityStreamEnabled;
+  static bool sActivityStreamDisableHome;
 };
 
 } // namespace browser
 } // namespace mozilla
 
 #endif // AboutRedirector_h__
--- a/browser/extensions/activity-stream/lib/ActivityStreamMessageChannel.jsm
+++ b/browser/extensions/activity-stream/lib/ActivityStreamMessageChannel.jsm
@@ -6,16 +6,17 @@
 
 const {utils: Cu} = Components;
 Cu.import("resource:///modules/AboutNewTab.jsm");
 Cu.import("resource://gre/modules/RemotePageManager.jsm");
 
 const {actionCreators: ac, actionTypes: at, actionUtils: au} = Cu.import("resource://activity-stream/common/Actions.jsm", {});
 
 const ABOUT_NEW_TAB_URL = "about:newtab";
+const ABOUT_HOME_URL = "about:home";
 
 const DEFAULT_OPTIONS = {
   dispatch(action) {
     throw new Error(`\nMessageChannel: Received action ${action.type}, but no dispatcher was defined.\n`);
   },
   pageURL: ABOUT_NEW_TAB_URL,
   outgoingMessageName: "ActivityStream:MainToContent",
   incomingMessageName: "ActivityStream:ContentToMain"
@@ -123,17 +124,17 @@ this.ActivityStreamMessageChannel = clas
 
   /**
    * createChannel - Create RemotePages channel to establishing message passing
    *                 between the main process and child pages
    */
   createChannel() {
     //  Receive AboutNewTab's Remote Pages instance, if it exists, on override
     const channel = this.pageURL === ABOUT_NEW_TAB_URL && AboutNewTab.override(true);
-    this.channel = channel || new RemotePages(this.pageURL);
+    this.channel = channel || new RemotePages([ABOUT_HOME_URL, ABOUT_NEW_TAB_URL]);
     this.channel.addMessageListener("RemotePage:Init", this.onNewTabInit);
     this.channel.addMessageListener("RemotePage:Load", this.onNewTabLoad);
     this.channel.addMessageListener("RemotePage:Unload", this.onNewTabUnload);
     this.channel.addMessageListener(this.incomingMessageName, this.onMessage);
 
     // Some pages might have already loaded, so we won't get the usual message
     for (const {loaded, portID} of this.channel.messagePorts) {
       if (loaded) {
--- a/browser/modules/AboutNewTab.jsm
+++ b/browser/modules/AboutNewTab.jsm
@@ -25,17 +25,17 @@ var AboutNewTab = {
   pageListener: null,
 
   isOverridden: false,
 
   init(pageListener) {
     if (this.isOverridden) {
       return;
     }
-    this.pageListener = pageListener || new RemotePages("about:newtab");
+    this.pageListener = pageListener || new RemotePages(["about:home", "about:newtab"]);
     this.pageListener.addMessageListener("NewTab:Customize", this.customize);
     this.pageListener.addMessageListener("NewTab:MaybeShowMigrateMessage",
       this.maybeShowMigrateMessage);
   },
 
   maybeShowMigrateMessage({ target }) {
     AutoMigrate.shouldShowMigratePrompt(target.browser).then((prompt) => {
       if (prompt) {