Bug 1098123 - Add telemetry for onbeforeunload usage. r=jst, a=lsblakk
authorJustin Dolske <dolske@mozilla.com>
Mon, 24 Nov 2014 13:50:04 -0800
changeset 235338 1228e88ac07bbb95bba331442530a5c45400816b
parent 235337 c2aec148f17eb4b3c86a847104e47a25dc34fdc0
child 235339 14db369bb36eb8ac1529ed4e5f06c8ba621255f5
push id611
push userraliiev@mozilla.com
push dateMon, 05 Jan 2015 23:23:16 +0000
treeherdermozilla-release@345cd3b9c445 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst, lsblakk
bugs1098123
milestone35.0a2
Bug 1098123 - Add telemetry for onbeforeunload usage. r=jst, a=lsblakk
layout/base/nsDocumentViewer.cpp
toolkit/components/telemetry/Histograms.json
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -117,16 +117,17 @@ static const char sPrintOptionsContractI
 #include "nsISHistoryInternal.h"
 #include "nsIWebNavigation.h"
 #include "nsXMLHttpRequest.h"
 
 //paint forcing
 #include <stdio.h>
 
 #include "mozilla/dom/Element.h"
+#include "mozilla/Telemetry.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #define BEFOREUNLOAD_DISABLED_PREFNAME "dom.disable_beforeunload"
 
 //-----------------------------------------------------
 // PR LOGGING
@@ -1202,36 +1203,40 @@ nsDocumentViewer::PermitUnloadInternal(b
       bool dummy = false;
       int32_t buttonPressed = 0;
       uint32_t buttonFlags = (nsIPrompt::BUTTON_POS_0_DEFAULT |
                              (nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_0) |
                              (nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_1));
 
       nsAutoSyncOperation sync(mDocument);
       mInPermitUnloadPrompt = true;
+      mozilla::Telemetry::Accumulate(mozilla::Telemetry::ONBEFOREUNLOAD_PROMPT_COUNT, 1);
       rv = prompt->ConfirmEx(title, message, buttonFlags,
                              leaveLabel, stayLabel, nullptr, nullptr,
                              &dummy, &buttonPressed);
       mInPermitUnloadPrompt = false;
 
       // If the prompt aborted, we tell our consumer that it is not allowed
       // to unload the page. One reason that prompts abort is that the user
       // performed some action that caused the page to unload while our prompt
       // was active. In those cases we don't want our consumer to also unload
       // the page.
       //
       // XXX: Are there other cases where prompts can abort? Is it ok to
       //      prevent unloading the page in those cases?
       if (NS_FAILED(rv)) {
+        mozilla::Telemetry::Accumulate(mozilla::Telemetry::ONBEFOREUNLOAD_PROMPT_ACTION, 2);
         *aPermitUnload = false;
         return NS_OK;
       }
 
       // Button 0 == leave, button 1 == stay
       *aPermitUnload = (buttonPressed == 0);
+      mozilla::Telemetry::Accumulate(mozilla::Telemetry::ONBEFOREUNLOAD_PROMPT_ACTION,
+        (*aPermitUnload ? 1 : 0));
       // If the user decided to go ahead, make sure not to prompt the user again
       // by toggling the internal prompting bool to false:
       if (*aPermitUnload) {
         *aShouldPrompt = false;
       }
     }
   }
 
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -6849,10 +6849,21 @@
     "expires_in_version": "40",
     "kind": "boolean",
     "description": "Whether a user who accepted e10s from the prompt is still using e10s"
   },
   "E10S_BLOCKED_FROM_RUNNING": {
     "expires_in_version": "40",
     "kind": "boolean",
     "description": "Whether the e10s pref was set but it was blocked from running due to blacklisted conditions"
+  },
+  "ONBEFOREUNLOAD_PROMPT_ACTION" : {
+    "expires_in_version": "45",
+    "kind": "enumerated",
+    "n_values": 3,
+    "description": "What button a user clicked in an onbeforeunload prompt.  (Stay on Page = 0, Leave Page = 1, prompt aborted = 2)"
+  },
+  "ONBEFOREUNLOAD_PROMPT_COUNT" : {
+    "expires_in_version": "45",
+    "kind": "count",
+    "description": "How many onbeforeunload prompts has the user encountered in their session?"
   }
 }