Bug 944049 - Collect UITelemetry on bookmarks toolbar usage. r=Gijs, a=lsblakk.
authorMike Conley <mconley@mozilla.com>
Mon, 16 Dec 2013 11:45:53 -0500
changeset 167722 4ebfdf4aa3311cbe86b7127f937bbe92904c276d
parent 167721 bb07aea479a83a6bd0f72c43eca4567408ead55d
child 167723 d7915b7643020df7903667900bcfe9a6f7b0f99f
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, lsblakk
bugs944049
milestone27.0
Bug 944049 - Collect UITelemetry on bookmarks toolbar usage. r=Gijs, a=lsblakk.
browser/modules/BrowserUITelemetry.jsm
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -207,16 +207,22 @@ XPCOMUtils.defineLazyGetter(this, "ALL_B
     "urlbar-go-button",
     "urlbar-reload-button",
     "searchbar:child"
   ]
   return DEFAULT_ITEMS.concat(PALETTE_ITEMS)
                       .concat(SPECIAL_CASES);
 });
 
+const OTHER_MOUSEUP_MONITORED_ITEMS = [
+   "appmenu-button",
+   "PlacesChevron",
+   "PlacesToolbarItems",
+];
+
 this.BrowserUITelemetry = {
   init: function() {
     UITelemetry.addSimpleMeasureFunction("toolbars",
                                          this.getToolbarMeasures.bind(this));
     Services.obs.addObserver(this, "browser-delayed-startup-finished", false);
   },
 
   observe: function(aSubject, aTopic, aData) {
@@ -238,40 +244,44 @@ this.BrowserUITelemetry = {
     }
     categoryEvents[aAction]++;
   },
 
   _registerWindow: function(aWindow) {
     aWindow.addEventListener("unload", this);
     let document = aWindow.document;
 
-    let appMenuButton = document.getElementById("appmenu-button");
-    if (appMenuButton) {
-      appMenuButton.addEventListener("mouseup", this);
-    }
-
     let toolbars = document.querySelectorAll("toolbar[customizable=true]");
     for (let toolbar of toolbars) {
       toolbar.addEventListener("mouseup", this);
     }
+
+    for (let itemID of OTHER_MOUSEUP_MONITORED_ITEMS) {
+      let item = document.getElementById(itemID);
+      if (item) {
+        item.addEventListener("mouseup", this);
+      }
+    }
   },
 
   _unregisterWindow: function(aWindow) {
     aWindow.removeEventListener("unload", this);
     let document = aWindow.document;
 
-    let appMenuButton = document.getElementById("appmenu-button");
-    if (appMenuButton) {
-      appMenuButton.removeEventListener("mouseup", this);
-    }
-
     let toolbars = document.querySelectorAll("toolbar[customizable=true]");
     for (let toolbar of toolbars) {
       toolbar.removeEventListener("mouseup", this);
     }
+
+    for (let itemID of OTHER_MOUSEUP_MONITORED_ITEMS) {
+      let item = document.getElementById(itemID);
+      if (item) {
+        item.removeEventListener("mouseup", this);
+      }
+    }
   },
 
   handleEvent: function(aEvent) {
     switch(aEvent.type) {
       case "unload":
         this._unregisterWindow(aEvent.currentTarget);
         break;
       case "mouseup":
@@ -282,16 +292,22 @@ this.BrowserUITelemetry = {
 
   _handleMouseUp: function(aEvent) {
     let targetID = aEvent.currentTarget.id;
 
     switch (targetID) {
       case "appmenu-button":
         this._appmenuMouseUp(aEvent);
         break;
+      case "PlacesToolbarItems":
+        this._PlacesToolbarItemsMouseUp(aEvent);
+        break;
+      case "PlacesChevron":
+        this._PlacesChevronMouseUp(aEvent);
+        break;
       default:
         this._checkForBuiltinItem(aEvent);
     }
   },
 
   _appmenuMouseUp: function(aEvent) {
     let itemId;
 
@@ -316,16 +332,33 @@ this.BrowserUITelemetry = {
         (APPMENU_WHITELIST.indexOf(candidate) != -1 ||
          APPMENU_PREFIX_WHITELIST.some( s => candidate.startsWith(s) ))) {
       return candidate;
     }
 
     return "unrecognized";
   },
 
+  _PlacesChevronMouseUp: function(aEvent) {
+    let target = aEvent.originalTarget;
+    let result = target.id == "PlacesChevron" ? "chevron" : "overflowed-item";
+    this._countEvent("click-bookmarks-bar", result);
+  },
+
+  _PlacesToolbarItemsMouseUp: function(aEvent) {
+    let target = aEvent.originalTarget;
+    // If this isn't a bookmark-item, we don't care about it.
+    if (!target.classList.contains("bookmark-item")) {
+      return;
+    }
+
+    let result = target.hasAttribute("container") ? "container" : "item";
+    this._countEvent("click-bookmarks-bar", result);
+  },
+
   _checkForBuiltinItem: function(aEvent) {
     let item = aEvent.originalTarget;
     // Perhaps we're seeing one of the default toolbar items
     // being clicked.
     if (ALL_BUILTIN_ITEMS.indexOf(item.id) != -1) {
       // Base case - we clicked directly on one of our built-in items,
       // and we can go ahead and register that click.
       this._countEvent("click-builtin-item", item.id);
@@ -360,16 +393,20 @@ this.BrowserUITelemetry = {
 
     let document = win.document;
     let result = {};
 
     // Determine if the add-on bar is currently visible
     let addonBar = document.getElementById("addon-bar");
     result.addonBarEnabled = addonBar && !addonBar.collapsed;
 
+    // Determine if the Bookmarks bar is currently visible
+    let bookmarksBar = document.getElementById("PersonalToolbar");
+    result.bookmarksBarEnabled = bookmarksBar && !bookmarksBar.collapsed;
+
     // Examine the default toolbars and see what default items
     // are present and missing.
     let defaultKept = [];
     let defaultMoved = [];
     let nondefaultAdded = [];
 
     let toolbars = document.querySelectorAll("toolbar[customizable=true]");
     for (let toolbar of toolbars) {