Bug 1458617 - Add telemetry to detect if a user has a custom about:newtab/home page. r=Mardak
☠☠ backed out by f6726096117e ☠ ☠
authorNan Jiang <najiang@mozilla.com>
Tue, 15 May 2018 13:47:56 -0400
changeset 419901 2de498d1e77e272766410f176a3dc9fbf2200b07
parent 419900 402934c0f826bf306053ed51493dc3cee4209c5f
child 419902 ae756063903dda9401fac5bf0b8fb3a5e81ef9f0
push id34053
push userdluca@mozilla.com
push dateSat, 26 May 2018 04:07:01 +0000
treeherdermozilla-central@e0beb6560ec9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1458617
milestone62.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 1458617 - Add telemetry to detect if a user has a custom about:newtab/home page. r=Mardak MozReview-Commit-ID: 9aMEEc7yHhQ
browser/components/nsBrowserGlue.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -73,17 +73,20 @@ ChromeUtils.import("resource://gre/modul
 
   let { TelemetryTimestamps } =
     ChromeUtils.import("resource://gre/modules/TelemetryTimestamps.jsm", {});
   TelemetryTimestamps.add("blankWindowShown");
 })();
 
 Cu.importGlobalProperties(["fetch"]);
 
-XPCOMUtils.defineLazyServiceGetter(this, "WindowsUIUtils", "@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils");
+XPCOMUtils.defineLazyServiceGetters(this, {
+  WindowsUIUtils: ["@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils"],
+  aboutNewTabService: ["@mozilla.org/browser/aboutnewtab-service;1", "nsIAboutNewTabService"]
+});
 XPCOMUtils.defineLazyGetter(this, "WeaveService", () =>
   Cc["@mozilla.org/weave/service;1"].getService().wrappedJSObject
 );
 
 // lazy module getters
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   AddonManager: "resource://gre/modules/AddonManager.jsm",
@@ -365,21 +368,58 @@ BrowserGlue.prototype = {
   get browserErrorReporter() {
     Object.defineProperty(this, "browserErrorReporter", {
       value: new BrowserErrorReporter(),
     });
     return this.browserErrorReporter;
   },
 
   _sendMainPingCentrePing() {
-    const ACTIVITY_STREAM_ID = "activity-stream";
+    let newTabSetting;
+    let homePageSetting;
+
+    // Check whether or not about:home and about:newtab have been overridden at this point.
+    // Different settings are encoded as follows:
+    //   * Value 0: default
+    //   * Value 1: about:blank
+    //   * Value 2: web extension
+    //   * Value 3: other custom URL(s)
+    // Settings for about:newtab and about:home are combined in a bitwise manner.
+
+    // Note that a user could use about:blank and web extension at the same time
+    // to overwrite the about:newtab, but the web extension takes priority, so the
+    // ordering matters in the following check.
+    if (Services.prefs.getBoolPref("browser.newtabpage.enabled") &&
+                                   !aboutNewTabService.overridden) {
+      newTabSetting = 0;
+    } else if (aboutNewTabService.newTabURL.startsWith("moz-extension://")) {
+      newTabSetting = 2;
+    } else if (!Services.prefs.getBoolPref("browser.newtabpage.enabled")) {
+      newTabSetting = 1;
+    } else {
+      newTabSetting = 3;
+    }
+
+    const homePageURL = Services.prefs.getComplexValue("browser.startup.homepage",
+                                                       Ci.nsIPrefLocalizedString).data;
+    if (homePageURL === "about:home") {
+      homePageSetting = 0;
+    } else if (homePageURL === "about:blank") {
+      homePageSetting = 1;
+    } else if (homePageURL.startsWith("moz-extension://")) {
+      homePageSetting = 2;
+    } else {
+      homePageSetting = 3;
+    }
+
     const payload = {
       event: "AS_ENABLED",
-      value: true
+      value: newTabSetting | (homePageSetting << 2)
     };
+    const ACTIVITY_STREAM_ID = "activity-stream";
     const options = {filter: ACTIVITY_STREAM_ID};
     this.pingCentre.sendPing(payload, options);
   },
 
   // nsIObserver implementation
   observe: async function BG_observe(subject, topic, data) {
     switch (topic) {
       case "notifications-open-settings":