Bug 944147 - [Australis] Collect UITelemetry on bookmark star usage. r=jaws.
authorMike Conley <mconley@mozilla.com>
Tue, 17 Dec 2013 23:57:36 -0500
changeset 161009 3fab9a65035e04eb09eaaea0bf83179eea6761d6
parent 161008 fb2697d854d01d40a7dbb74a6994a6072035b32e
child 161010 195453582f94feb1afbd9d3b70d1e6a098e6d427
push id25862
push usercbook@mozilla.com
push dateWed, 18 Dec 2013 11:40:53 +0000
treeherdermozilla-central@60373454fc52 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs944147
milestone29.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 944147 - [Australis] Collect UITelemetry on bookmark star usage. r=jaws.
browser/modules/BrowserUITelemetry.jsm
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -16,16 +16,17 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
   "resource:///modules/RecentWindow.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
   "resource:///modules/CustomizableUI.jsm");
 
 const ALL_BUILTIN_ITEMS = [
   "fullscreen-button",
   "switch-to-metro-button",
+  "bookmarks-menu-button",
 ];
 
 const OTHER_MOUSEUP_MONITORED_ITEMS = [
   "PlacesChevron",
   "PlacesToolbarItems",
 ];
 
 this.BrowserUITelemetry = {
@@ -177,18 +178,53 @@ this.BrowserUITelemetry = {
     if (!target.classList.contains("bookmark-item")) {
       return;
     }
 
     let result = target.hasAttribute("container") ? "container" : "item";
     this._countMouseUpEvent("click-bookmarks-bar", result, aEvent.button);
   },
 
+  _bookmarksMenuButtonMouseUp: function(aEvent) {
+    let bookmarksWidget = CustomizableUI.getWidget("bookmarks-menu-button");
+    if (bookmarksWidget.areaType == CustomizableUI.TYPE_MENU_PANEL) {
+      // In the menu panel, only the star is visible, and that opens up the
+      // bookmarks subview.
+      this._countMouseUpEvent("click-bookmarks-menu-button", "in-panel",
+                              aEvent.button);
+    } else {
+      let clickedItem = aEvent.originalTarget;
+      // Did we click on the star, or the dropmarker? The star
+      // has an anonid of "button". If we don't find that, we'll
+      // assume we clicked on the dropmarker.
+      let action = "menu";
+      if (clickedItem.getAttribute("anonid") == "button") {
+        // We clicked on the star - now we just need to record
+        // whether or not we're adding a bookmark or editing an
+        // existing one.
+        let bookmarksMenuNode =
+          bookmarksWidget.forWindow(aEvent.target.ownerGlobal).node;
+        action = bookmarksMenuNode.hasAttribute("starred") ? "edit" : "add";
+      }
+      this._countMouseUpEvent("click-bookmarks-menu-button", action,
+                              aEvent.button);
+    }
+  },
+
   _checkForBuiltinItem: function(aEvent) {
     let item = aEvent.originalTarget;
+
+    // We special-case the bookmarks-menu-button, since we want to
+    // monitor more than just clicks on it.
+    if (item.id == "bookmarks-menu-button" ||
+        getIDBasedOnFirstIDedAncestor(item) == "bookmarks-menu-button") {
+      this._bookmarksMenuButtonMouseUp(aEvent);
+      return;
+    }
+
     // 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._countMouseUpEvent("click-builtin-item", item.id, aEvent.button);
     }
   },
@@ -213,8 +249,25 @@ this.BrowserUITelemetry = {
     let bookmarksBar = document.getElementById("PersonalToolbar");
     result.bookmarksBarEnabled = bookmarksBar && !bookmarksBar.collapsed;
 
     result.countableEvents = this._countableEvents;
 
     return result;
   },
 };
+
+/**
+ * Returns the id of the first ancestor of aNode that has an id. If aNode
+ * has no parent, or no ancestor has an id, returns null.
+ *
+ * @param aNode the node to find the first ID'd ancestor of
+ */
+function getIDBasedOnFirstIDedAncestor(aNode) {
+  while (!aNode.id) {
+    aNode = aNode.parentNode;
+    if (!aNode) {
+      return null;
+    }
+  }
+
+  return aNode.id;
+}