Bug 1673961 - Add Set default browser action in SpecialMessage actions r=pdahiya,nanj
authorAndrei Oprea <andrei.br92@gmail.com>
Wed, 04 Nov 2020 14:52:07 +0000
changeset 555913 0813e326069ddb877fad0b8a83e5265660790b38
parent 555912 81e8f84c8ec04bf67cef598e7643851368eaa2fe
child 555914 ce44a8d69f761464c191e4cb69a33ebf305bac35
push id130208
push useraoprea@mozilla.com
push dateWed, 04 Nov 2020 20:43:31 +0000
treeherderautoland@0813e326069d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspdahiya, nanj
bugs1673961
milestone84.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1673961 - Add Set default browser action in SpecialMessage actions r=pdahiya,nanj Differential Revision: https://phabricator.services.mozilla.com/D95239
toolkit/components/messaging-system/lib/SpecialMessageActions.jsm
toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/SpecialMessageActionSchemas.json
toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/index.md
toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser.ini
toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_default_browser.js
toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/head.js
--- a/toolkit/components/messaging-system/lib/SpecialMessageActions.jsm
+++ b/toolkit/components/messaging-system/lib/SpecialMessageActions.jsm
@@ -75,16 +75,25 @@ const SpecialMessageActions = {
         install
       );
     } catch (e) {
       Cu.reportError(e);
     }
   },
 
   /**
+   *  Set browser as the operating system default browser.
+   *
+   *  @param {Window} window Reference to a window object
+   */
+  setDefaultBrowser(window) {
+    window.getShellService().setAsDefault();
+  },
+
+  /**
    * Reset browser homepage and newtab to default with a certain section configuration
    *
    * @param {"default"|null} home Value to set for browser homepage
    * @param {"default"|null} newtab Value to set for browser newtab
    * @param {obj} layout Configuration options for newtab sections
    * @returns {undefined}
    */
   configureHomepage({ homePage = null, newtab = null, layout = null }) {
@@ -214,16 +223,19 @@ const SpecialMessageActions = {
         break;
       case "INSTALL_ADDON_FROM_URL":
         await this.installAddonFromURL(
           browser,
           action.data.url,
           action.data.telemetrySource
         );
         break;
+      case "SET_DEFAULT_BROWSER":
+        this.setDefaultBrowser(window);
+        break;
       case "PIN_CURRENT_TAB":
         let tab = window.gBrowser.selectedTab;
         window.gBrowser.pinTab(tab);
         window.ConfirmationHint.show(tab, "pinTab", {
           showDescription: true,
         });
         break;
       case "SHOW_FIREFOX_ACCOUNTS":
--- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/SpecialMessageActionSchemas.json
+++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/SpecialMessageActionSchemas.json
@@ -309,16 +309,28 @@
           },
           "required": ["type"],
           "additionalProperties": false,
           "description": "Dismiss DOH doorhanger notification"
         },
         {
           "type": "object",
           "properties": {
+            "type": {
+              "type": "string",
+              "enum": ["SET_DEFAULT_BROWSER"]
+            }
+          },
+          "required": ["type"],
+          "additionalProperties": false,
+          "description": "Message action to set Firefox as default browser"
+        },
+        {
+          "type": "object",
+          "properties": {
             "data": {
               "type": "object",
               "properties": {
                 "homePage": {
                   "type": "string",
                   "description": "Should reset homepage pref",
                   "enum": ["default"]
                 },
--- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/index.md
+++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/index.md
@@ -230,8 +230,14 @@ Action for configuring the user homepage
     search: boolean;
     topsites: boolean;
     highlights: boolean;
     topstories: boolean;
     snippets: boolean;
   }
 }
 ```
+
+### `SET_DEFAULT_BROWSER`
+
+Action for configuring the default browser to Firefox on the user's system.
+
+* args: (none)
--- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser.ini
+++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser.ini
@@ -15,8 +15,9 @@ support-files =
 [browser_sma_show_firefox_accounts.js]
 [browser_sma_show_migration_wizard.js]
 [browser_sma.js]
 [browser_sma_docs.js]
 [browser_sma_accept_doh.js]
 [browser_sma_disable_doh.js]
 [browser_sma_cfrmessageprovider.js]
 [browser_sma_configure_homepage.js]
+[browser_sma_default_browser.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_default_browser.js
@@ -0,0 +1,22 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function test_set_default_browser() {
+  const sandbox = sinon.createSandbox();
+  const stub = sandbox.stub();
+
+  await SMATestUtils.executeAndValidateAction(
+    { type: "SET_DEFAULT_BROWSER" },
+    {
+      ownerGlobal: {
+        getShellService: () => ({
+          setAsDefault: stub,
+        }),
+      },
+    }
+  );
+
+  Assert.equal(stub.callCount, 1, "setAsDefault was called by the action");
+});
--- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/head.js
+++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/head.js
@@ -1,16 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const { XPCOMUtils } = ChromeUtils.import(
   "resource://gre/modules/XPCOMUtils.jsm"
 );
+const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
 
 ChromeUtils.defineModuleGetter(
   this,
   "SpecialMessageActions",
   "resource://messaging-system/lib/SpecialMessageActions.jsm"
 );
 
 ChromeUtils.defineModuleGetter(