Bug 1299350 - If there is a homepage, show it at the end of the wizard. r=rnewman, a=lizzard
authorMichael Kaply <mozilla@kaply.com>
Fri, 02 Sep 2016 10:48:50 -0700
changeset 342573 101e643d0f730b8256c4a8ef8270e57757efa502
parent 342572 813d1273fa611d5e2a0675ddae432662fae33e35
child 342574 77a60bbacb97c2f36815b2c395958a354aa581c9
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lizzard
bugs1299350
milestone49.0
Bug 1299350 - If there is a homepage, show it at the end of the wizard. r=rnewman, a=lizzard
mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
+++ b/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
@@ -219,17 +219,24 @@ public class Distribution {
 
     private static Distribution init(final Distribution distribution) {
         // Read/write preferences and files on the background thread.
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
                 boolean distributionSet = distribution.doInit();
                 if (distributionSet) {
-                    GeckoAppShell.notifyObservers("Distribution:Set", "");
+                    String preferencesJSON = "";
+                    try {
+                        final File descFile = distribution.getDistributionFile("preferences.json");
+                        preferencesJSON = FileUtils.getFileContents(descFile);
+                    } catch (IOException e) {
+                        // Just send empty string
+                    }
+                    GeckoAppShell.notifyObservers("Distribution:Set", preferencesJSON);
                 }
             }
         });
 
         return distribution;
     }
 
     /**
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -7119,16 +7119,18 @@ var ExternalApps = {
     delete this._pageActionId;
   },
 };
 
 var Distribution = {
   // File used to store campaign data
   _file: null,
 
+  _preferencesJSON: null,
+
   init: function dc_init() {
     Services.obs.addObserver(this, "Distribution:Changed", false);
     Services.obs.addObserver(this, "Distribution:Set", false);
     Services.obs.addObserver(this, "prefservice:after-app-defaults", false);
     Services.obs.addObserver(this, "Campaign:Set", false);
 
     // Look for file outside the APK:
     // /data/data/org.mozilla.xxx/distribution.json
@@ -7141,19 +7143,28 @@ var Distribution = {
     switch (aTopic) {
       case "Distribution:Changed":
         // Re-init the search service.
         try {
           Services.search._asyncReInit();
         } catch (e) {
           console.log("Unable to reinit search service.");
         }
+        // Make sure we don't reuse the original preferences
+        this._preferencesJSON = null;
         // Fall through.
 
       case "Distribution:Set":
+        if (aData) {
+          try {
+            this._preferencesJSON = JSON.parse(aData);
+          } catch (e) {
+            console.log("Invalid distribution JSON.");
+          }
+        }
         // Reload the default prefs so we can observe "prefservice:after-app-defaults"
         Services.prefs.QueryInterface(Ci.nsIObserver).observe(null, "reload-default-prefs", null);
         this.installDistroAddons();
         break;
 
       case "prefservice:after-app-defaults":
         this.getPrefs();
         break;
@@ -7178,16 +7189,21 @@ var Distribution = {
   update: function dc_update(aData) {
     // Force the distribution preferences on the default branch
     let defaults = Services.prefs.getDefaultBranch(null);
     defaults.setCharPref("distribution.id", aData.id);
     defaults.setCharPref("distribution.version", aData.version);
   },
 
   getPrefs: function dc_getPrefs() {
+    if (this._preferencesJSON) {
+        this.applyPrefs(this._preferencesJSON);
+        return;
+    }
+
     // Get the distribution directory, and bail if it doesn't exist.
     let file = FileUtils.getDir("XREAppDist", [], false);
     if (!file.exists())
       return;
 
     file.append("preferences.json");
     this.readJSON(file, this.applyPrefs);
   },