2013-12-10 11:49:02 -08:00
|
|
|
// 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/.
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["BrowserUITelemetry"];
|
|
|
|
|
2013-12-18 13:54:59 -08:00
|
|
|
const {interfaces: Ci, utils: Cu} = Components;
|
2013-12-10 11:49:02 -08:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry",
|
|
|
|
"resource://gre/modules/UITelemetry.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
|
|
|
|
"resource:///modules/RecentWindow.jsm");
|
2013-12-10 11:49:24 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
|
|
|
|
"resource:///modules/CustomizableUI.jsm");
|
|
|
|
|
2014-01-15 00:40:12 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREA_PLACEMENTS", function() {
|
2013-12-18 13:54:59 -08:00
|
|
|
let result = {
|
|
|
|
"PanelUI-contents": [
|
|
|
|
"edit-controls",
|
|
|
|
"zoom-controls",
|
|
|
|
"new-window-button",
|
|
|
|
"privatebrowsing-button",
|
|
|
|
"save-page-button",
|
|
|
|
"print-button",
|
|
|
|
"history-panelmenu",
|
|
|
|
"fullscreen-button",
|
|
|
|
"find-button",
|
|
|
|
"preferences-button",
|
|
|
|
"add-ons-button",
|
2014-01-15 00:51:32 -08:00
|
|
|
"developer-button",
|
2013-12-18 13:54:59 -08:00
|
|
|
],
|
|
|
|
"nav-bar": [
|
|
|
|
"urlbar-container",
|
|
|
|
"search-container",
|
|
|
|
"webrtc-status-button",
|
|
|
|
"bookmarks-menu-button",
|
|
|
|
"downloads-button",
|
|
|
|
"home-button",
|
|
|
|
"social-share-button",
|
|
|
|
],
|
|
|
|
// It's true that toolbar-menubar is not visible
|
|
|
|
// on OS X, but the XUL node is definitely present
|
|
|
|
// in the document.
|
|
|
|
"toolbar-menubar": [
|
|
|
|
"menubar-items",
|
|
|
|
],
|
|
|
|
"TabsToolbar": [
|
|
|
|
"tabbrowser-tabs",
|
|
|
|
"new-tab-button",
|
|
|
|
"alltabs-button",
|
|
|
|
"tabs-closebutton",
|
|
|
|
],
|
|
|
|
"PersonalToolbar": [
|
|
|
|
"personal-bookmarks",
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
let showCharacterEncoding = Services.prefs.getComplexValue(
|
|
|
|
"browser.menu.showCharacterEncoding",
|
|
|
|
Ci.nsIPrefLocalizedString
|
|
|
|
).data;
|
|
|
|
if (showCharacterEncoding == "true") {
|
|
|
|
result["PanelUI-contents"].push("characterencoding-button");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Services.sysinfo.getProperty("hasWindowsTouchInterface")) {
|
|
|
|
result["PanelUI-contents"].push("switch-to-metro-button");
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
2014-01-15 00:40:12 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "DEFAULT_AREAS", function() {
|
|
|
|
return Object.keys(DEFAULT_AREA_PLACEMENTS);
|
|
|
|
});
|
|
|
|
|
2013-12-18 13:54:59 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "PALETTE_ITEMS", function() {
|
|
|
|
let result = [
|
|
|
|
"open-file-button",
|
|
|
|
"developer-button",
|
|
|
|
"feed-button",
|
|
|
|
"email-link-button",
|
|
|
|
"sync-button",
|
|
|
|
"tabview-button",
|
|
|
|
];
|
|
|
|
|
2014-01-15 00:40:12 -08:00
|
|
|
let panelPlacements = DEFAULT_AREA_PLACEMENTS["PanelUI-contents"];
|
2013-12-18 13:54:59 -08:00
|
|
|
if (panelPlacements.indexOf("characterencoding-button") == -1) {
|
|
|
|
result.push("characterencoding-button");
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "DEFAULT_ITEMS", function() {
|
|
|
|
let result = [];
|
2014-01-15 00:40:12 -08:00
|
|
|
for (let [, buttons] of Iterator(DEFAULT_AREA_PLACEMENTS)) {
|
2013-12-18 13:54:59 -08:00
|
|
|
result = result.concat(buttons);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
2013-12-20 11:15:50 -08:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "ALL_BUILTIN_ITEMS", function() {
|
|
|
|
// These special cases are for click events on built-in items that are
|
|
|
|
// contained within customizable items (like the navigation widget).
|
|
|
|
const SPECIAL_CASES = [
|
|
|
|
"back-button",
|
|
|
|
"forward-button",
|
|
|
|
"urlbar-stop-button",
|
|
|
|
"urlbar-go-button",
|
|
|
|
"urlbar-reload-button",
|
|
|
|
"searchbar",
|
|
|
|
"cut-button",
|
|
|
|
"copy-button",
|
|
|
|
"paste-button",
|
|
|
|
"zoom-out-button",
|
|
|
|
"zoom-reset-button",
|
|
|
|
"zoom-in-button",
|
2014-01-17 07:12:47 -08:00
|
|
|
"BMB_bookmarksPopup",
|
|
|
|
"BMB_unsortedBookmarksPopup",
|
|
|
|
"BMB_bookmarksToolbarPopup",
|
2013-12-20 11:15:50 -08:00
|
|
|
]
|
|
|
|
return DEFAULT_ITEMS.concat(PALETTE_ITEMS)
|
|
|
|
.concat(SPECIAL_CASES);
|
|
|
|
});
|
2013-12-10 11:49:02 -08:00
|
|
|
|
2013-12-17 14:00:13 -08:00
|
|
|
const OTHER_MOUSEUP_MONITORED_ITEMS = [
|
|
|
|
"PlacesChevron",
|
|
|
|
"PlacesToolbarItems",
|
2014-01-20 08:51:32 -08:00
|
|
|
"menubar-items",
|
2013-12-17 14:00:13 -08:00
|
|
|
];
|
|
|
|
|
2014-01-20 13:33:21 -08:00
|
|
|
// Items that open arrow panels will often be overlapped by
|
|
|
|
// the panel that they're opening by the time the mouseup
|
|
|
|
// event is fired, so for these items, we monitor mousedown.
|
|
|
|
const MOUSEDOWN_MONITORED_ITEMS = [
|
|
|
|
"PanelUI-menu-button",
|
|
|
|
];
|
|
|
|
|
2014-01-14 06:44:20 -08:00
|
|
|
// Weakly maps browser windows to objects whose keys are relative
|
|
|
|
// timestamps for when some kind of session started. For example,
|
|
|
|
// when a customization session started. That way, when the window
|
|
|
|
// exits customization mode, we can determine how long the session
|
|
|
|
// lasted.
|
|
|
|
const WINDOW_DURATION_MAP = new WeakMap();
|
|
|
|
|
2013-12-10 11:49:02 -08:00
|
|
|
this.BrowserUITelemetry = {
|
|
|
|
init: function() {
|
|
|
|
UITelemetry.addSimpleMeasureFunction("toolbars",
|
|
|
|
this.getToolbarMeasures.bind(this));
|
2014-01-02 16:02:46 -08:00
|
|
|
Services.obs.addObserver(this, "sessionstore-windows-restored", false);
|
2013-12-10 11:49:24 -08:00
|
|
|
Services.obs.addObserver(this, "browser-delayed-startup-finished", false);
|
2014-01-14 06:44:20 -08:00
|
|
|
CustomizableUI.addListener(this);
|
2013-12-10 11:49:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(aSubject, aTopic, aData) {
|
2014-01-02 16:02:46 -08:00
|
|
|
switch(aTopic) {
|
|
|
|
case "sessionstore-windows-restored":
|
|
|
|
this._gatherFirstWindowMeasurements();
|
|
|
|
break;
|
|
|
|
case "browser-delayed-startup-finished":
|
|
|
|
this._registerWindow(aSubject);
|
|
|
|
break;
|
2013-12-10 11:49:24 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the _countableEvents object, constructs a chain of
|
|
|
|
* Javascript Objects with the keys in aKeys, with the final
|
|
|
|
* key getting the value in aEndWith. If the final key already
|
|
|
|
* exists in the final object, its value is not set. In either
|
|
|
|
* case, a reference to the second last object in the chain is
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* Example - suppose I want to store:
|
|
|
|
* _countableEvents: {
|
|
|
|
* a: {
|
|
|
|
* b: {
|
|
|
|
* c: 0
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* And then increment the "c" value by 1, you could call this
|
|
|
|
* function like this:
|
|
|
|
*
|
|
|
|
* let example = this._ensureObjectChain([a, b, c], 0);
|
|
|
|
* example["c"]++;
|
|
|
|
*
|
|
|
|
* Subsequent repetitions of these last two lines would
|
|
|
|
* simply result in the c value being incremented again
|
|
|
|
* and again.
|
|
|
|
*
|
|
|
|
* @param aKeys the Array of keys to chain Objects together with.
|
|
|
|
* @param aEndWith the value to assign to the last key.
|
|
|
|
* @returns a reference to the second last object in the chain -
|
|
|
|
* so in our example, that'd be "b".
|
|
|
|
*/
|
|
|
|
_ensureObjectChain: function(aKeys, aEndWith) {
|
|
|
|
let current = this._countableEvents;
|
|
|
|
let parent = null;
|
|
|
|
for (let [i, key] of Iterator(aKeys)) {
|
|
|
|
if (!(key in current)) {
|
|
|
|
if (i == aKeys.length - 1) {
|
|
|
|
current[key] = aEndWith;
|
|
|
|
} else {
|
|
|
|
current[key] = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent = current;
|
|
|
|
current = current[key];
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
_countableEvents: {},
|
2014-01-14 06:44:20 -08:00
|
|
|
_countEvent: function(aKeyArray) {
|
|
|
|
let countObject = this._ensureObjectChain(aKeyArray, 0);
|
|
|
|
let lastItemKey = aKeyArray[aKeyArray.length - 1];
|
|
|
|
countObject[lastItemKey]++;
|
|
|
|
},
|
|
|
|
|
2013-12-10 15:26:37 -08:00
|
|
|
_countMouseUpEvent: function(aCategory, aAction, aButton) {
|
2013-12-10 11:49:24 -08:00
|
|
|
const BUTTONS = ["left", "middle", "right"];
|
2013-12-10 15:26:37 -08:00
|
|
|
let buttonKey = BUTTONS[aButton];
|
2013-12-10 11:49:24 -08:00
|
|
|
if (buttonKey) {
|
2014-01-14 06:44:20 -08:00
|
|
|
this._countEvent([aCategory, aAction, buttonKey]);
|
2013-12-10 11:49:24 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-12-19 13:46:39 -08:00
|
|
|
_firstWindowMeasurements: null,
|
2014-01-02 16:02:46 -08:00
|
|
|
_gatherFirstWindowMeasurements: function() {
|
|
|
|
// We'll gather measurements as soon as the session has restored.
|
|
|
|
// We do this here instead of waiting for UITelemetry to ask for
|
|
|
|
// our measurements because at that point all browser windows have
|
|
|
|
// probably been closed, since the vast majority of saved-session
|
|
|
|
// pings are gathered during shutdown.
|
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow({
|
|
|
|
private: false,
|
|
|
|
allowPopups: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
// If there are no such windows, we're out of luck. :(
|
|
|
|
this._firstWindowMeasurements = win ? this._getWindowMeasurements(win)
|
|
|
|
: {};
|
|
|
|
},
|
2013-12-19 13:46:39 -08:00
|
|
|
|
2014-01-02 16:02:46 -08:00
|
|
|
_registerWindow: function(aWindow) {
|
2013-12-10 11:49:24 -08:00
|
|
|
aWindow.addEventListener("unload", this);
|
|
|
|
let document = aWindow.document;
|
|
|
|
|
|
|
|
for (let areaID of CustomizableUI.areas) {
|
|
|
|
let areaNode = document.getElementById(areaID);
|
2013-12-16 03:28:38 -08:00
|
|
|
if (areaNode) {
|
|
|
|
(areaNode.customizationTarget || areaNode).addEventListener("mouseup", this);
|
|
|
|
}
|
2013-12-10 11:49:24 -08:00
|
|
|
}
|
2013-12-17 14:00:13 -08:00
|
|
|
|
|
|
|
for (let itemID of OTHER_MOUSEUP_MONITORED_ITEMS) {
|
|
|
|
let item = document.getElementById(itemID);
|
|
|
|
if (item) {
|
|
|
|
item.addEventListener("mouseup", this);
|
|
|
|
}
|
|
|
|
}
|
2014-01-14 06:44:20 -08:00
|
|
|
|
2014-01-20 13:33:21 -08:00
|
|
|
for (let itemID of MOUSEDOWN_MONITORED_ITEMS) {
|
|
|
|
let item = document.getElementById(itemID);
|
|
|
|
if (item) {
|
|
|
|
item.addEventListener("mousedown", this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-14 06:44:20 -08:00
|
|
|
WINDOW_DURATION_MAP.set(aWindow, {});
|
2013-12-10 11:49:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
_unregisterWindow: function(aWindow) {
|
|
|
|
aWindow.removeEventListener("unload", this);
|
|
|
|
let document = aWindow.document;
|
|
|
|
|
|
|
|
for (let areaID of CustomizableUI.areas) {
|
|
|
|
let areaNode = document.getElementById(areaID);
|
2013-12-16 03:28:38 -08:00
|
|
|
if (areaNode) {
|
|
|
|
(areaNode.customizationTarget || areaNode).removeEventListener("mouseup", this);
|
|
|
|
}
|
2013-12-10 11:49:24 -08:00
|
|
|
}
|
2013-12-17 14:00:13 -08:00
|
|
|
|
|
|
|
for (let itemID of OTHER_MOUSEUP_MONITORED_ITEMS) {
|
|
|
|
let item = document.getElementById(itemID);
|
|
|
|
if (item) {
|
|
|
|
item.removeEventListener("mouseup", this);
|
|
|
|
}
|
|
|
|
}
|
2014-01-20 13:33:21 -08:00
|
|
|
|
|
|
|
for (let itemID of MOUSEDOWN_MONITORED_ITEMS) {
|
|
|
|
let item = document.getElementById(itemID);
|
|
|
|
if (item) {
|
|
|
|
item.removeEventListener("mousedown", this);
|
|
|
|
}
|
|
|
|
}
|
2013-12-10 11:49:24 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
|
|
|
switch(aEvent.type) {
|
|
|
|
case "unload":
|
|
|
|
this._unregisterWindow(aEvent.currentTarget);
|
|
|
|
break;
|
|
|
|
case "mouseup":
|
|
|
|
this._handleMouseUp(aEvent);
|
|
|
|
break;
|
2014-01-20 13:33:21 -08:00
|
|
|
case "mousedown":
|
|
|
|
this._handleMouseDown(aEvent);
|
|
|
|
break;
|
2013-12-10 11:49:24 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_handleMouseUp: function(aEvent) {
|
2013-12-17 14:00:13 -08:00
|
|
|
let targetID = aEvent.currentTarget.id;
|
|
|
|
|
|
|
|
switch (targetID) {
|
|
|
|
case "PlacesToolbarItems":
|
|
|
|
this._PlacesToolbarItemsMouseUp(aEvent);
|
|
|
|
break;
|
|
|
|
case "PlacesChevron":
|
|
|
|
this._PlacesChevronMouseUp(aEvent);
|
|
|
|
break;
|
2014-01-20 08:51:32 -08:00
|
|
|
case "menubar-items":
|
|
|
|
this._menubarMouseUp(aEvent);
|
|
|
|
break;
|
2013-12-17 14:00:13 -08:00
|
|
|
default:
|
|
|
|
this._checkForBuiltinItem(aEvent);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-01-20 13:33:21 -08:00
|
|
|
_handleMouseDown: function(aEvent) {
|
|
|
|
if (aEvent.currentTarget.id == "PanelUI-menu-button") {
|
|
|
|
// _countMouseUpEvent expects a detail for the second argument,
|
|
|
|
// but we don't really have any details to give. Just passing in
|
|
|
|
// "button" is probably simpler than trying to modify
|
|
|
|
// _countMouseUpEvent for this particular case.
|
|
|
|
this._countMouseUpEvent("click-menu-button", "button", aEvent.button);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-12-17 14:00:13 -08:00
|
|
|
_PlacesChevronMouseUp: function(aEvent) {
|
|
|
|
let target = aEvent.originalTarget;
|
|
|
|
let result = target.id == "PlacesChevron" ? "chevron" : "overflowed-item";
|
|
|
|
this._countMouseUpEvent("click-bookmarks-bar", result, aEvent.button);
|
|
|
|
},
|
|
|
|
|
|
|
|
_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._countMouseUpEvent("click-bookmarks-bar", result, aEvent.button);
|
|
|
|
},
|
|
|
|
|
2014-01-20 08:51:32 -08:00
|
|
|
_menubarMouseUp: function(aEvent) {
|
|
|
|
let target = aEvent.originalTarget;
|
|
|
|
let tag = target.localName
|
|
|
|
let result = (tag == "menu" || tag == "menuitem") ? tag : "other";
|
|
|
|
this._countMouseUpEvent("click-menubar", result, aEvent.button);
|
|
|
|
},
|
|
|
|
|
2013-12-17 20:57:36 -08:00
|
|
|
_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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-12-17 14:00:13 -08:00
|
|
|
_checkForBuiltinItem: function(aEvent) {
|
2013-12-10 11:49:24 -08:00
|
|
|
let item = aEvent.originalTarget;
|
2013-12-17 20:57:36 -08:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2013-12-10 11:49:24 -08:00
|
|
|
// 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.
|
2013-12-10 15:26:37 -08:00
|
|
|
this._countMouseUpEvent("click-builtin-item", item.id, aEvent.button);
|
2013-12-20 11:15:50 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not, we need to check if one of the ancestors of the clicked
|
|
|
|
// item is in our list of built-in items to check.
|
|
|
|
let candidate = getIDBasedOnFirstIDedAncestor(item);
|
|
|
|
if (ALL_BUILTIN_ITEMS.indexOf(candidate) != -1) {
|
|
|
|
this._countMouseUpEvent("click-builtin-item", candidate, aEvent.button);
|
2013-12-10 11:49:24 -08:00
|
|
|
}
|
2013-12-10 11:49:02 -08:00
|
|
|
},
|
|
|
|
|
2013-12-19 13:46:39 -08:00
|
|
|
_getWindowMeasurements: function(aWindow) {
|
|
|
|
let document = aWindow.document;
|
2013-12-10 11:49:02 -08:00
|
|
|
let result = {};
|
|
|
|
|
2014-01-04 13:39:14 -08:00
|
|
|
// Determine if the window is in the maximized, normal or
|
|
|
|
// fullscreen state.
|
|
|
|
result.sizemode = document.documentElement.getAttribute("sizemode");
|
|
|
|
|
2013-12-17 14:00:13 -08:00
|
|
|
// Determine if the Bookmarks bar is currently visible
|
|
|
|
let bookmarksBar = document.getElementById("PersonalToolbar");
|
|
|
|
result.bookmarksBarEnabled = bookmarksBar && !bookmarksBar.collapsed;
|
|
|
|
|
2014-01-20 08:51:32 -08:00
|
|
|
// Determine if the menubar is currently visible. On OS X, the menubar
|
|
|
|
// is never shown, despite not having the collapsed attribute set.
|
|
|
|
let menuBar = document.getElementById("toolbar-menubar");
|
|
|
|
result.menuBarEnabled =
|
|
|
|
menuBar && Services.appinfo.OS != "Darwin"
|
|
|
|
&& menuBar.getAttribute("autohide") != "true";
|
|
|
|
|
2014-01-31 10:59:23 -08:00
|
|
|
// Determine if the titlebar is currently visible.
|
|
|
|
result.titleBarEnabled = !Services.prefs.getBoolPref("browser.tabs.drawInTitlebar");
|
|
|
|
|
2013-12-18 13:54:59 -08:00
|
|
|
// Examine all customizable areas and see what default items
|
|
|
|
// are present and missing.
|
|
|
|
let defaultKept = [];
|
|
|
|
let defaultMoved = [];
|
|
|
|
let nondefaultAdded = [];
|
|
|
|
|
|
|
|
for (let areaID of CustomizableUI.areas) {
|
|
|
|
let items = CustomizableUI.getWidgetIdsInArea(areaID);
|
|
|
|
for (let item of items) {
|
|
|
|
// 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
|
2014-01-15 00:40:12 -08:00
|
|
|
// toolbarID in DEFAULT_AREA_PLACEMENTS because an add-on might
|
2013-12-18 13:54:59 -08:00
|
|
|
// be clever and give itself the id of "toString" or something.
|
2014-01-15 00:40:12 -08:00
|
|
|
if (Array.isArray(DEFAULT_AREA_PLACEMENTS[areaID]) &&
|
|
|
|
DEFAULT_AREA_PLACEMENTS[areaID].indexOf(item) != -1) {
|
2013-12-18 13:54:59 -08:00
|
|
|
// 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 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 paletteItems =
|
2013-12-19 13:46:39 -08:00
|
|
|
CustomizableUI.getUnusedWidgets(aWindow.gNavToolbox.palette);
|
2013-12-18 13:54:59 -08:00
|
|
|
let defaultRemoved = [item.id for (item of paletteItems)
|
|
|
|
if (DEFAULT_ITEMS.indexOf(item.id) != -1)];
|
|
|
|
|
|
|
|
result.defaultKept = defaultKept;
|
|
|
|
result.defaultMoved = defaultMoved;
|
|
|
|
result.nondefaultAdded = nondefaultAdded;
|
|
|
|
result.defaultRemoved = defaultRemoved;
|
|
|
|
|
2014-01-15 00:40:12 -08:00
|
|
|
// Next, determine how many add-on provided toolbars exist.
|
|
|
|
let addonToolbars = 0;
|
|
|
|
let toolbars = document.querySelectorAll("toolbar[customizable=true]");
|
|
|
|
for (let toolbar of toolbars) {
|
|
|
|
if (DEFAULT_AREAS.indexOf(toolbar.id) == -1) {
|
|
|
|
addonToolbars++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.addonToolbars = addonToolbars;
|
|
|
|
|
2014-01-14 06:46:18 -08:00
|
|
|
// Find out how many open tabs we have in each window
|
|
|
|
let winEnumerator = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
let visibleTabs = [];
|
|
|
|
let hiddenTabs = [];
|
|
|
|
while (winEnumerator.hasMoreElements()) {
|
|
|
|
let someWin = winEnumerator.getNext();
|
|
|
|
if (someWin.gBrowser) {
|
|
|
|
let visibleTabsNum = someWin.gBrowser.visibleTabs.length;
|
|
|
|
visibleTabs.push(visibleTabsNum);
|
|
|
|
hiddenTabs.push(someWin.gBrowser.tabs.length - visibleTabsNum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.visibleTabs = visibleTabs;
|
|
|
|
result.hiddenTabs = hiddenTabs;
|
|
|
|
|
2013-12-19 13:46:39 -08:00
|
|
|
return result;
|
|
|
|
},
|
2013-12-10 11:49:24 -08:00
|
|
|
|
2013-12-19 13:46:39 -08:00
|
|
|
getToolbarMeasures: function() {
|
|
|
|
let result = this._firstWindowMeasurements || {};
|
|
|
|
result.countableEvents = this._countableEvents;
|
2014-01-14 06:44:20 -08:00
|
|
|
result.durations = this._durations;
|
2013-12-10 11:49:02 -08:00
|
|
|
return result;
|
|
|
|
},
|
2014-01-14 06:44:20 -08:00
|
|
|
|
|
|
|
countCustomizationEvent: function(aEventType) {
|
|
|
|
this._countEvent(["customize", aEventType]);
|
|
|
|
},
|
|
|
|
|
|
|
|
_durations: {
|
|
|
|
customization: [],
|
|
|
|
},
|
|
|
|
|
|
|
|
onCustomizeStart: function(aWindow) {
|
|
|
|
this._countEvent(["customize", "start"]);
|
|
|
|
let durationMap = WINDOW_DURATION_MAP.get(aWindow);
|
|
|
|
if (!durationMap) {
|
|
|
|
durationMap = {};
|
|
|
|
WINDOW_DURATION_MAP.set(aWindow, durationMap);
|
|
|
|
}
|
|
|
|
durationMap.customization = aWindow.performance.now();
|
|
|
|
},
|
|
|
|
|
|
|
|
onCustomizeEnd: function(aWindow) {
|
|
|
|
let durationMap = WINDOW_DURATION_MAP.get(aWindow);
|
|
|
|
if (durationMap && "customization" in durationMap) {
|
|
|
|
let duration = aWindow.performance.now() - durationMap.customization;
|
|
|
|
this._durations.customization.push(duration);
|
|
|
|
delete durationMap.customization;
|
|
|
|
}
|
|
|
|
},
|
2013-12-10 11:49:02 -08:00
|
|
|
};
|
2013-12-17 20:57:36 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2014-01-02 16:02:46 -08:00
|
|
|
}
|