Bug 1489531 Expose telemetry client_id header to about:addons r=aswan
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 17 Jan 2019 17:48:32 +0000
changeset 511420 4ddef07cfb17ed568a321165746546de93259b64
parent 511419 230f156b2393e214874269515b1c0059fe14431b
child 511421 24982570fc8338ba51f32f142c7d0e6f342cce7d
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1489531
milestone66.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 1489531 Expose telemetry client_id header to about:addons r=aswan m-c patch to add header to request on about:addons Differential Revision: https://phabricator.services.mozilla.com/D16601
toolkit/content/widgets/browser-custom-element.js
toolkit/mozapps/extensions/content/extensions.js
--- a/toolkit/content/widgets/browser-custom-element.js
+++ b/toolkit/content/widgets/browser-custom-element.js
@@ -796,23 +796,25 @@ class MozBrowser extends MozElementMixin
     }
 
     let {
       flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
         referrerURI,
         referrerPolicy = Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
         triggeringPrincipal,
         postData,
+        headers,
     } = aParams || {};
     let loadURIOptions = {
       triggeringPrincipal,
       referrerURI,
       loadFlags: flags,
       referrerPolicy,
       postData,
+      headers,
     };
     this._wrapURIChangeCall(() =>
       this.webNavigation.loadURI(aURI, loadURIOptions));
   }
 
   gotoIndex(aIndex) {
     this._wrapURIChangeCall(() => this.webNavigation.gotoIndex(aIndex));
   }
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -15,24 +15,22 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/addons/AddonRepository.jsm");
 ChromeUtils.import("resource://gre/modules/addons/AddonSettings.jsm");
 
 ChromeUtils.defineModuleGetter(this, "E10SUtils", "resource://gre/modules/E10SUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "Extension",
                                "resource://gre/modules/Extension.jsm");
 ChromeUtils.defineModuleGetter(this, "ExtensionParent",
                                "resource://gre/modules/ExtensionParent.jsm");
-ChromeUtils.defineModuleGetter(this, "Preferences",
-                               "resource://gre/modules/Preferences.jsm");
-
-
 ChromeUtils.defineModuleGetter(this, "PluralForm",
                                "resource://gre/modules/PluralForm.jsm");
 ChromeUtils.defineModuleGetter(this, "Preferences",
                                "resource://gre/modules/Preferences.jsm");
+ChromeUtils.defineModuleGetter(this, "ClientID",
+                               "resource://gre/modules/ClientID.jsm");
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "WEBEXT_PERMISSION_PROMPTS",
                                       "extensions.webextPermissionPrompts", false);
 XPCOMUtils.defineLazyPreferenceGetter(this, "XPINSTALL_ENABLED",
                                       "xpinstall.enabled", true);
 
 XPCOMUtils.defineLazyPreferenceGetter(this, "SUPPORT_URL", "app.support.baseURL",
                                       "", null, val => Services.urlFormatter.formatURL(val));
@@ -2005,21 +2003,38 @@ var gDiscoverView = {
   loaded: false,
   _browser: null,
   _loading: null,
   _error: null,
   homepageURL: null,
   _loadListeners: [],
   hideHeader: true,
 
+  get clientIdDiscoveryEnabled() {
+    // These prefs match Discovery.jsm for enabling clientId cookies.
+    return Services.prefs.getBoolPref("datareporting.healthreport.uploadEnabled", false) &&
+           Services.prefs.getBoolPref("browser.discovery.enabled", false);
+  },
+
+  async getClientHeader() {
+    if (!this.clientIdDiscoveryEnabled) {
+      return undefined;
+    }
+    let clientId = await ClientID.getClientIdHash();
+
+    let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsISupportsCString);
+    stream.data = `Moz-Client-Id: ${clientId}\r\n`;
+    return stream;
+  },
+
   async initialize() {
     this.enabled = isDiscoverEnabled();
     if (!this.enabled) {
       gCategories.get("addons://discover/").hidden = true;
-      return;
+      return null;
     }
 
     this.node = document.getElementById("discover-view");
     this._loading = document.getElementById("discover-loading");
     this._error = document.getElementById("discover-error");
     this._browser = document.getElementById("discover-browser");
 
     let compatMode = "normal";
@@ -2027,37 +2042,38 @@ var gDiscoverView = {
       compatMode = "ignore";
     else if (AddonManager.strictCompatibility)
       compatMode = "strict";
 
     var url = Services.prefs.getCharPref(PREF_DISCOVERURL);
     url = url.replace("%COMPATIBILITY_MODE%", compatMode);
     url = Services.urlFormatter.formatURL(url);
 
-    let setURL = (aURL) => {
+    let setURL = async (aURL) => {
       try {
         this.homepageURL = Services.io.newURI(aURL);
       } catch (e) {
         this.showError();
         notifyInitialized();
         return;
       }
 
       this._browser.addProgressListener(this);
 
-      if (this.loaded)
+      if (this.loaded) {
         this._loadURL(this.homepageURL.spec, false, notifyInitialized,
-                      Services.scriptSecurityManager.getSystemPrincipal());
-      else
+                      Services.scriptSecurityManager.getSystemPrincipal(),
+                      await this.getClientHeader());
+      } else {
         notifyInitialized();
+      }
     };
 
     if (!Services.prefs.getBoolPref(PREF_GETADDONS_CACHE_ENABLED)) {
-      setURL(url);
-      return;
+      return setURL(url);
     }
 
     gPendingInitializations++;
     let aAddons = await AddonManager.getAddonsByTypes(["extension", "theme"]);
     var list = {};
     for (let addon of aAddons) {
       var prefName = PREF_GETADDONS_CACHE_ID_ENABLED.replace("%ID%",
                                                              addon.id);
@@ -2070,28 +2086,28 @@ var gDiscoverView = {
         version: addon.version,
         type: addon.type,
         userDisabled: addon.userDisabled,
         isCompatible: addon.isCompatible,
         isBlocklisted: addon.blocklistState == Ci.nsIBlocklistService.STATE_BLOCKED,
       };
     }
 
-    setURL(url + "#" + JSON.stringify(list));
+    return setURL(url + "#" + JSON.stringify(list));
   },
 
   destroy() {
     try {
       this._browser.removeProgressListener(this);
     } catch (e) {
       // Ignore the case when the listener wasn't already registered
     }
   },
 
-  show(aParam, aRequest, aState, aIsRefresh) {
+  async show(aParam, aRequest, aState, aIsRefresh) {
     gViewController.updateCommands();
 
     // If we're being told to load a specific URL then just do that
     if (aState && "url" in aState) {
       this.loaded = true;
       this._loadURL(aState.url);
     }
 
@@ -2110,17 +2126,18 @@ var gDiscoverView = {
     // loaded once initialization is complete
     if (!this.homepageURL) {
       this._loadListeners.push(gViewController.notifyViewChanged.bind(gViewController));
       return;
     }
 
     this._loadURL(this.homepageURL.spec, aIsRefresh,
                   gViewController.notifyViewChanged.bind(gViewController),
-                  Services.scriptSecurityManager.getSystemPrincipal());
+                  Services.scriptSecurityManager.getSystemPrincipal(),
+                  await this.getClientHeader());
   },
 
   canRefresh() {
     if (this._browser.currentURI &&
         this._browser.currentURI.spec == this.homepageURL.spec)
       return false;
     return true;
   },
@@ -2130,33 +2147,34 @@ var gDiscoverView = {
   },
 
   hide() { },
 
   showError() {
     this.node.selectedPanel = this._error;
   },
 
-  _loadURL(aURL, aKeepHistory, aCallback, aPrincipal) {
+  _loadURL(aURL, aKeepHistory, aCallback, aPrincipal, headers) {
     if (this._browser.currentURI && this._browser.currentURI.spec == aURL) {
       if (aCallback)
         aCallback();
       return;
     }
 
     if (aCallback)
       this._loadListeners.push(aCallback);
 
     var flags = 0;
     if (!aKeepHistory)
       flags |= Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY;
 
     this._browser.loadURI(aURL, {
       flags,
       triggeringPrincipal: aPrincipal || Services.scriptSecurityManager.createNullPrincipal({}),
+      headers,
     });
   },
 
   onLocationChange(aWebProgress, aRequest, aLocation, aFlags) {
     // Ignore the about:blank load
     if (aLocation.spec == "about:blank")
       return;