Bug 1180801 - Replace setDefaultBrowser and isDefaultBrowser with getConfiguration/setConfiguration options. r=MattN

This commit is contained in:
Jared Wein 2015-07-07 18:19:33 -04:00
parent fffcaec06e
commit 7d28d95bcd
3 changed files with 23 additions and 29 deletions

View File

@ -289,15 +289,6 @@ if (typeof Mozilla == 'undefined') {
_sendEvent('toggleReaderMode');
};
Mozilla.UITour.setDefaultBrowser = function() {
_sendEvent('setDefaultBrowser');
}
Mozilla.UITour.isDefaultBrowser = function(callback) {
_sendEvent('isDefaultBrowser', {
callbackID: _waitForCallback(callback),
});
}
})();
// Make this library Require-able.

View File

@ -615,7 +615,7 @@ this.UITour = {
return false;
}
this.setConfiguration(data.configuration, data.value);
this.setConfiguration(window, data.configuration, data.value);
break;
}
@ -718,21 +718,6 @@ this.UITour = {
});
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)) {
@ -1729,6 +1714,14 @@ this.UITour = {
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":
@ -1763,8 +1756,18 @@ this.UITour = {
}
},
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);

View File

@ -48,7 +48,7 @@ let tests = [
is not actually replacing the original ShellService.
taskify(function* test_setDefaultBrowser() {
try {
gContentAPI.setDefaultBrowser();
gContentAPI.setConfiguration("defaultBrowser");
ok(setDefaultBrowserCalled, "setDefaultBrowser called");
} finally {
mockShellService.unregister();
@ -60,8 +60,8 @@ let tests = [
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();
});
})