Bug 1450376 - Ignore blocked permission requests in permission prompt telemetry. r=jkt draft
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 16 May 2018 18:41:13 +0200
changeset 795845 e76f3b70ee9a7a25946ca85377e1a58af87498a9
parent 795657 3c9d69736f4a421218e5eb01b6571d535d38318a
push id110101
push userjhofmann@mozilla.com
push dateWed, 16 May 2018 18:07:59 +0000
reviewersjkt
bugs1450376
milestone62.0a1
Bug 1450376 - Ignore blocked permission requests in permission prompt telemetry. r=jkt MozReview-Commit-ID: 5ykJl0ZSytD
browser/components/nsBrowserGlue.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -2813,69 +2813,80 @@ ContentPermissionPrompt.prototype = {
    *
    * Any time an error is thrown, the nsIContentPermissionRequest is
    * cancelled automatically.
    *
    * @param {nsIContentPermissionRequest} request
    *        The request that we're to show a prompt for.
    */
   prompt(request) {
+    let type;
     try {
       // Only allow exactly one permission request here.
       let types = request.types.QueryInterface(Ci.nsIArray);
       if (types.length != 1) {
         throw Components.Exception(
           "Expected an nsIContentPermissionRequest with only 1 type.",
           Cr.NS_ERROR_UNEXPECTED);
       }
 
-      let type = types.queryElementAt(0, Ci.nsIContentPermissionType).type;
+      type = types.queryElementAt(0, Ci.nsIContentPermissionType).type;
       let combinedIntegration =
         Integration.contentPermission.getCombined(ContentPermissionIntegration);
 
       let permissionPrompt =
         combinedIntegration.createPermissionPrompt(type, request);
       if (!permissionPrompt) {
         throw Components.Exception(
           `Failed to handle permission of type ${type}`,
           Cr.NS_ERROR_FAILURE);
       }
 
       permissionPrompt.prompt();
 
-      let schemeHistogram = Services.telemetry.getKeyedHistogramById("PERMISSION_REQUEST_ORIGIN_SCHEME");
-      let scheme = 0;
+    } catch (ex) {
+      Cu.reportError(ex);
+      request.cancel();
+      throw ex;
+    }
+
+    let schemeHistogram = Services.telemetry.getKeyedHistogramById("PERMISSION_REQUEST_ORIGIN_SCHEME");
+    let scheme = 0;
+    try {
       // URI is null for system principals.
       if (request.principal.URI) {
         switch (request.principal.URI.scheme) {
           case "http":
             scheme = 1;
             break;
           case "https":
             scheme = 2;
             break;
         }
       }
-      schemeHistogram.add(type, scheme);
-
-      // request.element should be the browser element in e10s.
-      if (request.element && request.element.contentPrincipal) {
-        let thirdPartyHistogram = Services.telemetry.getKeyedHistogramById("PERMISSION_REQUEST_THIRD_PARTY_ORIGIN");
-        let isThirdParty = request.principal.origin != request.element.contentPrincipal.origin;
-        thirdPartyHistogram.add(type, isThirdParty);
+    } catch (ex) {
+      // If the request principal is not available at this point,
+      // the request has likely been cancelled before being shown to the
+      // user. We shouldn't record this request.
+      if (ex.result != Cr.NS_ERROR_FAILURE) {
+        Cu.reportError(ex);
       }
-
-      let userInputHistogram = Services.telemetry.getKeyedHistogramById("PERMISSION_REQUEST_HANDLING_USER_INPUT");
-      userInputHistogram.add(type, request.isHandlingUserInput);
-
-    } catch (ex) {
-      Cu.reportError(ex);
-      request.cancel();
-      throw ex;
+      return;
     }
+    schemeHistogram.add(type, scheme);
+
+    // request.element should be the browser element in e10s.
+    if (request.element && request.element.contentPrincipal) {
+      let thirdPartyHistogram = Services.telemetry.getKeyedHistogramById("PERMISSION_REQUEST_THIRD_PARTY_ORIGIN");
+      let isThirdParty = request.principal.origin != request.element.contentPrincipal.origin;
+      thirdPartyHistogram.add(type, isThirdParty);
+    }
+
+    let userInputHistogram = Services.telemetry.getKeyedHistogramById("PERMISSION_REQUEST_HANDLING_USER_INPUT");
+    userInputHistogram.add(type, request.isHandlingUserInput);
   },
 };
 
 var DefaultBrowserCheck = {
   get OPTIONPOPUP() { return "defaultBrowserNotificationPopup"; },
 
   closePrompt(aNode) {
     if (this._notification) {