Commit cde3d4a8 authored by Nick Alexander's avatar Nick Alexander
Browse files

Bug 1835352 - Part 3: Record telemetry event when Firefox is launched from WDBA. r=nrishel

This uses the existing `browser.launched_to_handle ::
system_notification` event.  This is expedient and looks ahead to
making the WDBA a background task, where we likely will set the
privileged `name` of the toast to `default-browser-agent` or similar.

The alternative is to add a `browser.launched_to_handle ::
default_browser_agent` event.  I started with this and it's simply
duplication.  The data analysis phase will look almost identical with
either implementation: it's either filtering on the event name or on
the `name` key in the event extras.

Differential Revision: https://phabricator.services.mozilla.com/D179257
parent 1a431cbe
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -280,6 +280,9 @@ pref("browser.shell.setDefaultPDFHandler", true);
// is a known browser, and not when existing handler is another PDF handler such
// as Acrobat Reader or Nitro PDF.
pref("browser.shell.setDefaultPDFHandler.onlyReplaceBrowsers", true);
// URL to navigate to when launching Firefox after accepting the Windows Default
// Browser Agent "Set Firefox as default" call to action.
pref("browser.shell.defaultBrowserAgent.thanksURL", "https://www.mozilla.org/%LOCALE%/firefox/set-as-default/thanks/");
#endif


+22 −0
Original line number Diff line number Diff line
@@ -1202,6 +1202,28 @@ nsDefaultCommandLineHandler.prototype = {
      console.error(e);
    }

    if (
      AppConstants.platform == "win" &&
      cmdLine.handleFlag("to-handle-default-browser-agent", false)
    ) {
      // The Default Browser Agent launches Firefox in response to a Windows
      // native notification, but it does so in a non-standard manner.
      Services.telemetry.setEventRecordingEnabled(
        "browser.launched_to_handle",
        true
      );
      Glean.browserLaunchedToHandle.systemNotification.record({
        name: "default-browser-agent",
      });

      let thanksURI = Services.io.newURI(
        Services.urlFormatter.formatURLPref(
          "browser.shell.defaultBrowserAgent.thanksURL"
        )
      );
      urilist.push(thanksURI);
    }

    if (cmdLine.findFlag("screenshot", true) != -1) {
      lazy.HeadlessShell.handleCmdLineArgs(
        cmdLine,
+2 −0
Original line number Diff line number Diff line
@@ -20,5 +20,7 @@ skip-if = os == 'mac'
[browser_quit_multiple_tabs.js]
[browser_quit_shortcut_warning.js]
[browser_startup_homepage.js]
[browser_system_notification_telemetry.js]
run-if = os == 'win'
[browser_to_handle_telemetry.js]
run-if = os == 'win'
+54 −0
Original line number Diff line number Diff line
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

async function handleCommandLine(args, state) {
  let newWinPromise;
  let target = Services.urlFormatter.formatURLPref(
    "browser.shell.defaultBrowserAgent.thanksURL"
  );

  const EXISTING_FILE = Cc["@mozilla.org/file/local;1"].createInstance(
    Ci.nsIFile
  );
  EXISTING_FILE.initWithPath(getTestFilePath("dummy.pdf"));

  if (state == Ci.nsICommandLine.STATE_INITIAL_LAUNCH) {
    newWinPromise = BrowserTestUtils.waitForNewWindow({
      url: target, // N.b.: trailing slashes matter when matching.
    });
  }

  let cmdLineHandler = Cc["@mozilla.org/browser/final-clh;1"].getService(
    Ci.nsICommandLineHandler
  );

  let fakeCmdLine = Cu.createCommandLine(args, EXISTING_FILE.parent, state);
  cmdLineHandler.handle(fakeCmdLine);

  if (newWinPromise) {
    let newWin = await newWinPromise;
    await BrowserTestUtils.closeWindow(newWin);
  } else {
    BrowserTestUtils.removeTab(gBrowser.selectedTab);
  }
}

// Launching from the WDBA should open the "thanks" page and should send a
// telemetry event.
add_task(async function test_launched_to_handle_default_browser_agent() {
  await handleCommandLine(
    ["-to-handle-default-browser-agent"],
    Ci.nsICommandLine.STATE_INITIAL_LAUNCH
  );

  TelemetryTestUtils.assertEvents(
    [{ extra: { name: "default-browser-agent" } }],
    {
      category: "browser.launched_to_handle",
      method: "system_notification",
      object: "toast",
    }
  );
});