Bug 943606 - [Holly] Add simple measurement to BrowserUITelemetry for toolbar contents. r=Gijs.
authorMike Conley <mconley@mozilla.com>
Mon, 02 Dec 2013 18:54:09 -0500
changeset 174016 3831bd01eb417ced6620c4ba35e50e6066efec8a
parent 174015 1153ef40e4d7cf4f6ec4b22d4c32b40031401bfc
child 174017 ab1336aaf9db35df0950a9c35bf11a4a7936dde8
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs943606
milestone28.0a1
Bug 943606 - [Holly] Add simple measurement to BrowserUITelemetry for toolbar contents. r=Gijs.
browser/modules/BrowserUITelemetry.jsm
browser/modules/moz.build
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -132,16 +132,76 @@ const APPMENU_WHITELIST = [
     "appmenu_about",
 ];
 
 const APPMENU_PREFIX_WHITELIST = [
   'appmenu_developer_charset',
   'appmenu_charset',
 ];
 
+const DEFAULT_TOOLBAR_SETS = {
+#ifndef XP_MACOSX
+  "toolbar-menubar": [
+    "menubar-items"
+  ],
+#endif
+  "nav-bar": [
+    "unified-back-forward-button",
+    "urlbar-container",
+    "reload-button",
+    "stop-button",
+    "search-container",
+    "webrtc-status-button",
+    "bookmarks-menu-button",
+    "downloads-button",
+    "home-button",
+    "window-controls"
+  ],
+  "PersonalToolbar": [
+    "personal-bookmarks"
+  ],
+  "TabsToolbar": [
+#ifndef CAN_DRAW_IN_TITLEBAR
+    "appmenu-toolbar-button",
+#endif
+    "tabbrowser-tabs",
+    "new-tab-button",
+    "alltabs-button",
+    "tabs-closebutton"
+  ],
+  "addon-bar": [
+    "addonbar-closebutton",
+    "status-bar"
+  ],
+};
+
+const PALETTE_ITEMS = [
+  "print-button",
+  "history-button",
+  "bookmarks-button",
+  "new-window-button",
+  "fullscreen-button",
+  "zoom-controls",
+  "feed-button",
+  "cut-button",
+  "copy-button",
+  "paste-button",
+  "sync-button",
+  "navigator-throbber",
+  "tabview-button",
+];
+
+XPCOMUtils.defineLazyGetter(this, "DEFAULT_ITEMS", function() {
+  let result = [];
+  for (let [, buttons] of Iterator(DEFAULT_TOOLBAR_SETS)) {
+    result = result.concat(buttons);
+  }
+  return result;
+});
+
 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) {
@@ -229,16 +289,64 @@ 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;
 
+    // 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) {
+      let toolbarID = toolbar.id;
+      let currentset = toolbar.currentSet;
+      // It's possible add-ons might have wiped out the currentSet property,
+      // so we'll be a little defensive here.
+      currentset = (currentset && currentset.split(",")) || [];
+
+      for (let item of currentset) {
+        // Is this a default item?
+        if (DEFAULT_ITEMS.indexOf(item) != -1) {
+          // Ok, it's a default item - but is it in its default
+          // toolbar? We use Array.isArray instead of checking for
+          // toolbarID in DEFAULT_TOOLBAR_SETS because an add-on might
+          // be clever and give itself the id of "toString" or something.
+          if (Array.isArray(DEFAULT_TOOLBAR_SETS[toolbarID]) &&
+              DEFAULT_TOOLBAR_SETS[toolbarID].indexOf(item) != -1) {
+            // The item is in its default toolbar
+            defaultKept.push(item);
+          } else {
+            defaultMoved.push(item);
+          }
+        } else if (PALETTE_ITEMS.indexOf(item) != -1) {
+          // It's a palette item that's been moved into a toolbar
+          nondefaultAdded.push(item);
+        }
+        // else, it's a generated item (like springs, spacers, etc), or
+        // provided by an add-on, and we won't record it.
+      }
+    }
+
+    // Now go through the items in the palette to see what default
+    // items are in there.
+    let paletteChildren = win.gNavToolbox.palette.childNodes;
+    let defaultRemoved = [node.id for (node of paletteChildren)
+                          if (DEFAULT_ITEMS.indexOf(node.id) != -1)];
+
+    result.defaultKept = defaultKept;
+    result.defaultMoved = defaultMoved;
+    result.nondefaultAdded = nondefaultAdded;
+    result.defaultRemoved = defaultRemoved;
+
     return result;
   },
 };
 
 /**
  * Returns the id of the first ancestor of aNode that has an id, with
  * ":child" appended to it. If aNode has no parent, or no ancestor has an
  * id, returns null.
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -3,17 +3,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 TEST_DIRS += ['test']
 
 EXTRA_JS_MODULES += [
     'BrowserNewTabPreloader.jsm',
-    'BrowserUITelemetry.jsm',
     'CharsetMenu.jsm',
     'ContentClick.jsm',
     'NetworkPrioritizer.jsm',
     'offlineAppCache.jsm',
     'openLocationLastURL.jsm',
     'SharedFrame.jsm',
     'SignInToWebsite.jsm',
     'SitePermissions.jsm',
@@ -27,13 +26,14 @@ EXTRA_JS_MODULES += [
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     EXTRA_JS_MODULES += [
         'WindowsJumpLists.jsm',
         'WindowsPreviewPerTab.jsm',
     ]
 
 EXTRA_PP_JS_MODULES += [
     'AboutHome.jsm',
+    'BrowserUITelemetry.jsm',
     'RecentWindow.jsm',
 ]
 
 if CONFIG['MOZILLA_OFFICIAL']:
     DEFINES['MOZILLA_OFFICIAL'] = 1