Bug 1180801 - Replace setDefaultBrowser and isDefaultBrowser with getConfiguration/setConfiguration options. r=MattN, a=lmandel
authorJared Wein <jwein@mozilla.com>
Tue, 07 Jul 2015 18:19:33 -0400
changeset 281432 39fdfdfbf83060116960eb08e6f3d0aec01a5c6f
parent 281431 4ace51e5f532caf2e4083139d5365066b7751b93
child 281433 f89d2e9d776a6b14a0eaee103001a87a348213b3
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, lmandel
bugs1180801
milestone41.0a2
Bug 1180801 - Replace setDefaultBrowser and isDefaultBrowser with getConfiguration/setConfiguration options. r=MattN, a=lmandel
browser/components/uitour/UITour-lib.js
browser/components/uitour/UITour.jsm
browser/components/uitour/test/browser_UITour_defaultBrowser.js
--- a/browser/components/uitour/UITour-lib.js
+++ b/browser/components/uitour/UITour-lib.js
@@ -284,23 +284,14 @@ if (typeof Mozilla == 'undefined') {
 	Mozilla.UITour.forceShowReaderIcon = function() {
 		_sendEvent('forceShowReaderIcon');
 	};
 
 	Mozilla.UITour.toggleReaderMode = function(feature) {
 		_sendEvent('toggleReaderMode');
 	};
 
-	Mozilla.UITour.setDefaultBrowser = function() {
-		_sendEvent('setDefaultBrowser');
-	}
-
-	Mozilla.UITour.isDefaultBrowser = function(callback) {
-		_sendEvent('isDefaultBrowser', {
-			callbackID: _waitForCallback(callback),
-		});
-	}
 })();
 
 // Make this library Require-able.
 if (typeof module !== 'undefined' && module.exports) {
   module.exports = Mozilla.UITour;
 }
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -610,17 +610,17 @@ this.UITour = {
       }
 
       case "setConfiguration": {
         if (typeof data.configuration != "string") {
           log.warn("setConfiguration: No configuration option specified");
           return false;
         }
 
-        this.setConfiguration(data.configuration, data.value);
+        this.setConfiguration(window, data.configuration, data.value);
         break;
       }
 
       case "showFirefoxAccounts": {
         // 'signup' is the only action that makes sense currently, so we don't
         // accept arbitrary actions just to be safe...
         // We want to replace the current tab.
         browser.loadURI("about:accounts?action=signup&entrypoint=uitour");
@@ -713,31 +713,16 @@ this.UITour = {
 
       case "toggleReaderMode": {
         let targetPromise = this.getTarget(window, "readerMode-urlBar");
         targetPromise.then(target => {
           ReaderParent.toggleReaderMode({target: target.node});
         });
         break;
       }
-
-      case "setDefaultBrowser": {
-        let shell = Components.classes["@mozilla.org/browser/shell-service;1"]
-                              .getService(Components.interfaces.nsIShellService);
-        shell.setDefaultBrowser(true, false);
-        break;
-      }
-
-      case "isDefaultBrowser": {
-        let shell = Components.classes["@mozilla.org/browser/shell-service;1"]
-                              .getService(Components.interfaces.nsIShellService);
-        let isDefault = shell.isDefaultBrowser(false);
-        this.sendPageCallback(messageManager, data.callbackID, { value: isDefault });
-        break;
-      }
     }
 
     if (!this.tourBrowsersByWindow.has(window)) {
       this.tourBrowsersByWindow.set(window, new Set());
     }
     this.tourBrowsersByWindow.get(window).add(browser);
 
     Services.obs.addObserver(this, "message-manager-close", false);
@@ -1724,16 +1709,24 @@ this.UITour = {
   },
 
   getConfiguration: function(aMessageManager, aWindow, aConfiguration, aCallbackID) {
     switch (aConfiguration) {
       case "appinfo":
         let props = ["defaultUpdateChannel", "version"];
         let appinfo = {};
         props.forEach(property => appinfo[property] = Services.appinfo[property]);
+        let isDefaultBrowser = null;
+        try {
+          let shell = aWindow.getShellService();
+          if (shell) {
+            isDefaultBrowser = shell.isDefaultBrowser(false);
+          }
+        } catch (e) {}
+        appinfo["defaultBrowser"] = isDefaultBrowser;
         this.sendPageCallback(aMessageManager, aCallbackID, appinfo);
         break;
       case "availableTargets":
         this.getAvailableTargets(aMessageManager, aWindow, aCallbackID);
         break;
       case "loop":
         this.sendPageCallback(aMessageManager, aCallbackID, {
           gettingStartedSeen: Services.prefs.getBoolPref("loop.gettingStarted.seen"),
@@ -1758,18 +1751,28 @@ this.UITour = {
         });
         break;
       default:
         log.error("getConfiguration: Unknown configuration requested: " + aConfiguration);
         break;
     }
   },
 
-  setConfiguration: function(aConfiguration, aValue) {
+  setConfiguration: function(aWindow, aConfiguration, aValue) {
     switch (aConfiguration) {
+      case "defaultBrowser":
+        // Ignore aValue in this case because the default browser can only
+        // be set, not unset.
+        try {
+          let shell = aWindow.getShellService();
+          if (shell) {
+            shell.setDefaultBrowser(true, false);
+          }
+        } catch (e) {}
+        break;
       case "Loop:ResumeTourOnFirstJoin":
         // Ignore aValue in this case to avoid accidentally setting it to false.
         Services.prefs.setBoolPref("loop.gettingStarted.resumeOnFirstJoin", true);
         break;
       default:
         log.error("setConfiguration: Unknown configuration requested: " + aConfiguration);
         break;
     }
--- a/browser/components/uitour/test/browser_UITour_defaultBrowser.js
+++ b/browser/components/uitour/test/browser_UITour_defaultBrowser.js
@@ -43,26 +43,26 @@ function test() {
 }
 
 let tests = [
 
   /* This test is disabled (bug 1180714) since the MockObjectRegisterer
      is not actually replacing the original ShellService.
   taskify(function* test_setDefaultBrowser() {
     try {
-      gContentAPI.setDefaultBrowser();
+      gContentAPI.setConfiguration("defaultBrowser");
       ok(setDefaultBrowserCalled, "setDefaultBrowser called");
     } finally {
       mockShellService.unregister();
     }
   }),
   */
 
   taskify(function* test_isDefaultBrowser(done) {
     let shell = Components.classes["@mozilla.org/browser/shell-service;1"]
                           .getService(Components.interfaces.nsIShellService);
     let isDefault = shell.isDefaultBrowser(false);
-    gContentAPI.isDefaultBrowser(function(data) {
-      is(data.value, isDefault, "gContentAPI.isDefaultBrowser should match shellService.isDefaultBrowser");
+    gContentAPI.getConfiguration("appinfo", (data) => {
+      is(data.value, data.defaultBrowser, "gContentAPI result should match shellService.isDefaultBrowser");
       done();
     });
   })
 ];