Bug 1180801 - Replace setDefaultBrowser and isDefaultBrowser with getConfiguration/setConfiguration options. r=MattN
authorJared Wein <jwein@mozilla.com>
Tue, 07 Jul 2015 18:19:33 -0400
changeset 251783 076cfc368b0016fd0305925a2f7f175dbfa5a845
parent 251782 dc7c99a616b9ea330e49e44ecc2f366e7e1d7e38
child 251809 c3bf029b1fa3a059255df74484922b0946688d06
push id13890
push userjwein@mozilla.com
push dateTue, 07 Jul 2015 22:19:37 +0000
treeherderfx-team@076cfc368b00 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1180801
milestone42.0a1
Bug 1180801 - Replace setDefaultBrowser and isDefaultBrowser with getConfiguration/setConfiguration options. r=MattN
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();
     });
   })
 ];