2014-06-18 17:56:02 -07: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";
|
|
|
|
|
2014-11-20 12:21:29 -08:00
|
|
|
this.EXPORTED_SYMBOLS = ["UITour", "UITourMetricsProvider"];
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Promise.jsm");
|
2014-10-14 17:48:49 -07:00
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
|
|
|
|
"resource://gre/modules/LightweightThemeManager.jsm");
|
2014-09-17 05:58:00 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "ResetProfile",
|
|
|
|
"resource://gre/modules/ResetProfile.jsm");
|
2014-06-18 17:56:02 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
|
|
|
|
"resource:///modules/CustomizableUI.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry",
|
|
|
|
"resource://gre/modules/UITelemetry.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "BrowserUITelemetry",
|
|
|
|
"resource:///modules/BrowserUITelemetry.jsm");
|
2014-11-20 12:21:29 -08:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Metrics",
|
|
|
|
"resource://gre/modules/Metrics.jsm");
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2014-11-13 10:22:53 -08:00
|
|
|
// See LOG_LEVELS in Console.jsm. Common examples: "All", "Info", "Warn", & "Error".
|
|
|
|
const PREF_LOG_LEVEL = "browser.uitour.loglevel";
|
2014-06-18 17:56:02 -07:00
|
|
|
const PREF_SEENPAGEIDS = "browser.uitour.seenPageIDs";
|
|
|
|
const MAX_BUTTONS = 4;
|
|
|
|
|
|
|
|
const BUCKET_NAME = "UITour";
|
|
|
|
const BUCKET_TIMESTEPS = [
|
|
|
|
1 * 60 * 1000, // Until 1 minute after tab is closed/inactive.
|
|
|
|
3 * 60 * 1000, // Until 3 minutes after tab is closed/inactive.
|
|
|
|
10 * 60 * 1000, // Until 10 minutes after tab is closed/inactive.
|
|
|
|
60 * 60 * 1000, // Until 1 hour after tab is closed/inactive.
|
|
|
|
];
|
|
|
|
|
|
|
|
// Time after which seen Page IDs expire.
|
|
|
|
const SEENPAGEID_EXPIRY = 8 * 7 * 24 * 60 * 60 * 1000; // 8 weeks.
|
|
|
|
|
2014-10-14 17:48:49 -07:00
|
|
|
// Prefix for any target matching a search engine.
|
|
|
|
const TARGET_SEARCHENGINE_PREFIX = "searchEngine-";
|
|
|
|
|
2014-11-13 10:22:53 -08:00
|
|
|
// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "log", () => {
|
|
|
|
let ConsoleAPI = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).ConsoleAPI;
|
|
|
|
let consoleOptions = {
|
|
|
|
// toLowerCase is because the loglevel values use title case to be compatible with Log.jsm.
|
|
|
|
maxLogLevel: Services.prefs.getCharPref(PREF_LOG_LEVEL).toLowerCase(),
|
|
|
|
prefix: "UITour",
|
|
|
|
};
|
|
|
|
return new ConsoleAPI(consoleOptions);
|
|
|
|
});
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
this.UITour = {
|
|
|
|
url: null,
|
|
|
|
seenPageIDs: null,
|
2015-01-21 13:21:41 -08:00
|
|
|
pageIDSourceBrowsers: new WeakMap(),
|
|
|
|
/* Map from browser chrome windows to a Set of <browser>s in which a tour is open (both visible and hidden) */
|
|
|
|
tourBrowsersByWindow: new WeakMap(),
|
2014-06-18 17:56:02 -07:00
|
|
|
urlbarCapture: new WeakMap(),
|
|
|
|
appMenuOpenForAnnotation: new Set(),
|
|
|
|
availableTargetsCache: new WeakMap(),
|
|
|
|
|
|
|
|
_detachingTab: false,
|
|
|
|
_annotationPanelMutationObservers: new WeakMap(),
|
|
|
|
_queuedEvents: [],
|
|
|
|
_pendingDoc: null,
|
|
|
|
|
|
|
|
highlightEffects: ["random", "wobble", "zoom", "color"],
|
|
|
|
targets: new Map([
|
|
|
|
["accountStatus", {
|
|
|
|
query: (aDocument) => {
|
|
|
|
let statusButton = aDocument.getElementById("PanelUI-fxa-status");
|
|
|
|
return aDocument.getAnonymousElementByAttribute(statusButton,
|
|
|
|
"class",
|
|
|
|
"toolbarbutton-icon");
|
|
|
|
},
|
|
|
|
widgetName: "PanelUI-fxa-status",
|
|
|
|
}],
|
|
|
|
["addons", {query: "#add-ons-button"}],
|
|
|
|
["appMenu", {
|
|
|
|
addTargetListener: (aDocument, aCallback) => {
|
|
|
|
let panelPopup = aDocument.getElementById("PanelUI-popup");
|
|
|
|
panelPopup.addEventListener("popupshown", aCallback);
|
|
|
|
},
|
|
|
|
query: "#PanelUI-button",
|
|
|
|
removeTargetListener: (aDocument, aCallback) => {
|
|
|
|
let panelPopup = aDocument.getElementById("PanelUI-popup");
|
|
|
|
panelPopup.removeEventListener("popupshown", aCallback);
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
["backForward", {
|
|
|
|
query: "#back-button",
|
|
|
|
widgetName: "urlbar-container",
|
|
|
|
}],
|
|
|
|
["bookmarks", {query: "#bookmarks-menu-button"}],
|
|
|
|
["customize", {
|
|
|
|
query: (aDocument) => {
|
|
|
|
let customizeButton = aDocument.getElementById("PanelUI-customize");
|
|
|
|
return aDocument.getAnonymousElementByAttribute(customizeButton,
|
|
|
|
"class",
|
|
|
|
"toolbarbutton-icon");
|
|
|
|
},
|
|
|
|
widgetName: "PanelUI-customize",
|
|
|
|
}],
|
2014-11-30 21:46:23 -08:00
|
|
|
["devtools", {query: "#developer-button"}],
|
2014-06-18 17:56:02 -07:00
|
|
|
["help", {query: "#PanelUI-help"}],
|
|
|
|
["home", {query: "#home-button"}],
|
2014-10-06 15:49:30 -07:00
|
|
|
["forget", {
|
|
|
|
query: "#panic-button",
|
|
|
|
widgetName: "panic-button",
|
2014-11-30 21:46:23 -08:00
|
|
|
allowAdd: true,
|
|
|
|
}],
|
|
|
|
["loop", {query: "#loop-button"}],
|
2014-12-04 14:40:03 -08:00
|
|
|
["loop-newRoom", {
|
2014-12-09 16:08:08 -08:00
|
|
|
infoPanelPosition: "leftcenter topright",
|
2014-12-04 14:40:03 -08:00
|
|
|
query: (aDocument) => {
|
2015-01-14 13:04:01 -08:00
|
|
|
let loopBrowser = aDocument.querySelector("#loop-notification-panel > #loop-panel-iframe");
|
2014-12-04 14:40:03 -08:00
|
|
|
if (!loopBrowser) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-12-09 16:08:08 -08:00
|
|
|
// Use the parentElement full-width container of the button so our arrow
|
|
|
|
// doesn't overlap the panel contents much.
|
|
|
|
return loopBrowser.contentDocument.querySelector(".new-room-button").parentElement;
|
2014-12-04 14:40:03 -08:00
|
|
|
},
|
|
|
|
}],
|
|
|
|
["loop-roomList", {
|
2014-12-09 16:08:08 -08:00
|
|
|
infoPanelPosition: "leftcenter topright",
|
2014-12-04 14:40:03 -08:00
|
|
|
query: (aDocument) => {
|
2015-01-14 13:04:01 -08:00
|
|
|
let loopBrowser = aDocument.querySelector("#loop-notification-panel > #loop-panel-iframe");
|
2014-12-04 14:40:03 -08:00
|
|
|
if (!loopBrowser) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return loopBrowser.contentDocument.querySelector(".room-list");
|
|
|
|
},
|
|
|
|
}],
|
2014-12-11 21:05:54 -08:00
|
|
|
["loop-selectedRoomButtons", {
|
2014-12-22 11:24:35 -08:00
|
|
|
infoPanelOffsetY: -20,
|
|
|
|
infoPanelPosition: "start_after",
|
2014-12-11 21:05:54 -08:00
|
|
|
query: (aDocument) => {
|
|
|
|
let chatbox = aDocument.querySelector("chatbox[src^='about\:loopconversation'][selected]");
|
2014-12-22 11:24:35 -08:00
|
|
|
|
|
|
|
// Check that the real target actually exists
|
|
|
|
if (!chatbox || !chatbox.contentDocument ||
|
|
|
|
!chatbox.contentDocument.querySelector(".call-action-group")) {
|
2014-12-11 21:05:54 -08:00
|
|
|
return null;
|
|
|
|
}
|
2014-12-22 11:24:35 -08:00
|
|
|
|
|
|
|
// But anchor on the <browser> in the chatbox so the panel doesn't jump to undefined
|
|
|
|
// positions when the copy/email buttons disappear e.g. when the feedback form opens or
|
|
|
|
// somebody else joins the room.
|
|
|
|
return chatbox.content;
|
2014-12-11 21:05:54 -08:00
|
|
|
},
|
|
|
|
}],
|
2014-12-04 14:40:03 -08:00
|
|
|
["loop-signInUpLink", {
|
|
|
|
query: (aDocument) => {
|
2015-01-14 13:04:01 -08:00
|
|
|
let loopBrowser = aDocument.querySelector("#loop-notification-panel > #loop-panel-iframe");
|
2014-12-04 14:40:03 -08:00
|
|
|
if (!loopBrowser) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return loopBrowser.contentDocument.querySelector(".signin-link");
|
|
|
|
},
|
|
|
|
}],
|
2014-09-23 07:36:00 -07:00
|
|
|
["privateWindow", {query: "#privatebrowsing-button"}],
|
2014-06-18 17:56:02 -07:00
|
|
|
["quit", {query: "#PanelUI-quit"}],
|
|
|
|
["search", {
|
2014-12-22 11:24:35 -08:00
|
|
|
infoPanelOffsetX: 18,
|
2014-12-09 16:08:08 -08:00
|
|
|
infoPanelPosition: "after_start",
|
2014-06-18 17:56:02 -07:00
|
|
|
query: "#searchbar",
|
|
|
|
widgetName: "search-container",
|
|
|
|
}],
|
|
|
|
["searchProvider", {
|
|
|
|
query: (aDocument) => {
|
|
|
|
let searchbar = aDocument.getElementById("searchbar");
|
2014-11-20 12:13:21 -08:00
|
|
|
if (searchbar.hasAttribute("oneoffui")) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
return aDocument.getAnonymousElementByAttribute(searchbar,
|
|
|
|
"anonid",
|
|
|
|
"searchbar-engine-button");
|
|
|
|
},
|
|
|
|
widgetName: "search-container",
|
|
|
|
}],
|
2014-11-20 12:13:21 -08:00
|
|
|
["searchIcon", {
|
|
|
|
query: (aDocument) => {
|
|
|
|
let searchbar = aDocument.getElementById("searchbar");
|
|
|
|
if (!searchbar.hasAttribute("oneoffui")) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return aDocument.getAnonymousElementByAttribute(searchbar,
|
|
|
|
"anonid",
|
|
|
|
"searchbar-search-button");
|
|
|
|
},
|
|
|
|
widgetName: "search-container",
|
|
|
|
}],
|
|
|
|
["searchPrefsLink", {
|
|
|
|
query: (aDocument) => {
|
|
|
|
let element = null;
|
|
|
|
let searchbar = aDocument.getElementById("searchbar");
|
|
|
|
if (searchbar.hasAttribute("oneoffui")) {
|
|
|
|
let popup = aDocument.getElementById("PopupSearchAutoComplete");
|
|
|
|
if (popup.state != "open")
|
|
|
|
return null;
|
|
|
|
element = aDocument.getAnonymousElementByAttribute(popup,
|
|
|
|
"anonid",
|
|
|
|
"search-settings");
|
|
|
|
} else {
|
|
|
|
element = aDocument.getAnonymousElementByAttribute(searchbar,
|
|
|
|
"anonid",
|
|
|
|
"open-engine-manager");
|
|
|
|
}
|
|
|
|
if (!element || !UITour.isElementVisible(element)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
}],
|
2014-06-18 17:56:02 -07:00
|
|
|
["selectedTabIcon", {
|
|
|
|
query: (aDocument) => {
|
|
|
|
let selectedtab = aDocument.defaultView.gBrowser.selectedTab;
|
|
|
|
let element = aDocument.getAnonymousElementByAttribute(selectedtab,
|
|
|
|
"anonid",
|
|
|
|
"tab-icon-image");
|
|
|
|
if (!element || !UITour.isElementVisible(element)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
["urlbar", {
|
|
|
|
query: "#urlbar",
|
|
|
|
widgetName: "urlbar-container",
|
|
|
|
}],
|
2014-11-30 21:46:23 -08:00
|
|
|
["webide", {query: "#webide-button"}],
|
2014-06-18 17:56:02 -07:00
|
|
|
]),
|
|
|
|
|
|
|
|
init: function() {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("Initializing UITour");
|
2014-06-18 17:56:02 -07:00
|
|
|
// Lazy getter is initialized here so it can be replicated any time
|
|
|
|
// in a test.
|
|
|
|
delete this.seenPageIDs;
|
|
|
|
Object.defineProperty(this, "seenPageIDs", {
|
|
|
|
get: this.restoreSeenPageIDs.bind(this),
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
delete this.url;
|
|
|
|
XPCOMUtils.defineLazyGetter(this, "url", function () {
|
|
|
|
return Services.urlFormatter.formatURLPref("browser.uitour.url");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Clear the availableTargetsCache on widget changes.
|
|
|
|
let listenerMethods = [
|
|
|
|
"onWidgetAdded",
|
|
|
|
"onWidgetMoved",
|
|
|
|
"onWidgetRemoved",
|
|
|
|
"onWidgetReset",
|
|
|
|
"onAreaReset",
|
|
|
|
];
|
|
|
|
CustomizableUI.addListener(listenerMethods.reduce((listener, method) => {
|
|
|
|
listener[method] = () => this.availableTargetsCache.clear();
|
|
|
|
return listener;
|
|
|
|
}, {}));
|
|
|
|
},
|
|
|
|
|
|
|
|
restoreSeenPageIDs: function() {
|
|
|
|
delete this.seenPageIDs;
|
|
|
|
|
|
|
|
if (UITelemetry.enabled) {
|
|
|
|
let dateThreshold = Date.now() - SEENPAGEID_EXPIRY;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let data = Services.prefs.getCharPref(PREF_SEENPAGEIDS);
|
|
|
|
data = new Map(JSON.parse(data));
|
|
|
|
|
|
|
|
for (let [pageID, details] of data) {
|
|
|
|
|
|
|
|
if (typeof pageID != "string" ||
|
|
|
|
typeof details != "object" ||
|
|
|
|
typeof details.lastSeen != "number" ||
|
|
|
|
details.lastSeen < dateThreshold) {
|
|
|
|
|
|
|
|
data.delete(pageID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.seenPageIDs = data;
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.seenPageIDs)
|
|
|
|
this.seenPageIDs = new Map();
|
|
|
|
|
|
|
|
this.persistSeenIDs();
|
|
|
|
|
|
|
|
return this.seenPageIDs;
|
|
|
|
},
|
|
|
|
|
|
|
|
addSeenPageID: function(aPageID) {
|
|
|
|
if (!UITelemetry.enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.seenPageIDs.set(aPageID, {
|
|
|
|
lastSeen: Date.now(),
|
|
|
|
});
|
|
|
|
|
|
|
|
this.persistSeenIDs();
|
|
|
|
},
|
|
|
|
|
|
|
|
persistSeenIDs: function() {
|
|
|
|
if (this.seenPageIDs.size === 0) {
|
|
|
|
Services.prefs.clearUserPref(PREF_SEENPAGEIDS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.prefs.setCharPref(PREF_SEENPAGEIDS,
|
|
|
|
JSON.stringify([...this.seenPageIDs]));
|
|
|
|
},
|
|
|
|
|
2014-10-24 08:19:00 -07:00
|
|
|
onPageEvent: function(aMessage, aEvent) {
|
2014-06-18 17:56:02 -07:00
|
|
|
let contentDocument = null;
|
2014-10-24 08:19:00 -07:00
|
|
|
let browser = aMessage.target;
|
|
|
|
let window = browser.ownerDocument.defaultView;
|
|
|
|
let tab = window.gBrowser.getTabForBrowser(browser);
|
|
|
|
let messageManager = browser.messageManager;
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("onPageEvent:", aEvent.detail);
|
|
|
|
|
|
|
|
if (typeof aEvent.detail != "object") {
|
|
|
|
log.warn("Malformed event - detail not an object");
|
2014-06-18 17:56:02 -07:00
|
|
|
return false;
|
2014-11-13 10:22:53 -08:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
let action = aEvent.detail.action;
|
2014-11-13 10:22:53 -08:00
|
|
|
if (typeof action != "string" || !action) {
|
|
|
|
log.warn("Action not defined");
|
2014-06-18 17:56:02 -07:00
|
|
|
return false;
|
2014-11-13 10:22:53 -08:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
let data = aEvent.detail.data;
|
2014-11-13 10:22:53 -08:00
|
|
|
if (typeof data != "object") {
|
|
|
|
log.warn("Malformed event - data not an object");
|
2014-06-18 17:56:02 -07:00
|
|
|
return false;
|
2014-11-13 10:22:53 -08:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
// Do this before bailing if there's no tab, so later we can pick up the pieces:
|
|
|
|
window.gBrowser.tabContainer.addEventListener("TabSelect", this);
|
2014-10-24 08:19:00 -07:00
|
|
|
|
|
|
|
if (!window.gMultiProcessBrowser) { // Non-e10s. See bug 1089000.
|
|
|
|
contentDocument = browser.contentWindow.document;
|
|
|
|
if (!tab) {
|
|
|
|
// This should only happen while detaching a tab:
|
|
|
|
if (this._detachingTab) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("Got event while detatching a tab");
|
2014-10-24 08:19:00 -07:00
|
|
|
this._queuedEvents.push(aEvent);
|
|
|
|
this._pendingDoc = Cu.getWeakReference(contentDocument);
|
|
|
|
return;
|
|
|
|
}
|
2014-11-13 10:22:53 -08:00
|
|
|
log.error("Discarding tabless UITour event (" + action + ") while not detaching a tab." +
|
2014-10-24 08:19:00 -07:00
|
|
|
"This shouldn't happen!");
|
2014-06-18 17:56:02 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case "registerPageID": {
|
|
|
|
// This is only relevant if Telemtry is enabled.
|
2014-11-13 10:22:53 -08:00
|
|
|
if (!UITelemetry.enabled) {
|
|
|
|
log.debug("registerPageID: Telemery disabled, not doing anything");
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
2014-11-13 10:22:53 -08:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
// We don't want to allow BrowserUITelemetry.BUCKET_SEPARATOR in the
|
|
|
|
// pageID, as it could make parsing the telemetry bucket name difficult.
|
2014-11-13 10:22:53 -08:00
|
|
|
if (typeof data.pageID != "string" ||
|
|
|
|
data.pageID.contains(BrowserUITelemetry.BUCKET_SEPARATOR)) {
|
|
|
|
log.warn("registerPageID: Invalid page ID specified");
|
|
|
|
break;
|
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2014-11-13 10:22:53 -08:00
|
|
|
this.addSeenPageID(data.pageID);
|
2015-01-21 13:21:41 -08:00
|
|
|
this.pageIDSourceBrowsers.set(browser, data.pageID);
|
2014-11-13 10:22:53 -08:00
|
|
|
this.setTelemetryBucket(data.pageID);
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "showHighlight": {
|
|
|
|
let targetPromise = this.getTarget(window, data.target);
|
|
|
|
targetPromise.then(target => {
|
|
|
|
if (!target.node) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.error("UITour: Target could not be resolved: " + data.target);
|
2014-06-18 17:56:02 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let effect = undefined;
|
|
|
|
if (this.highlightEffects.indexOf(data.effect) !== -1) {
|
|
|
|
effect = data.effect;
|
|
|
|
}
|
2014-12-04 14:40:03 -08:00
|
|
|
this.showHighlight(window, target, effect);
|
2014-11-13 10:22:53 -08:00
|
|
|
}).catch(log.error);
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "hideHighlight": {
|
|
|
|
this.hideHighlight(window);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "showInfo": {
|
|
|
|
let targetPromise = this.getTarget(window, data.target, true);
|
|
|
|
targetPromise.then(target => {
|
|
|
|
if (!target.node) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.error("UITour: Target could not be resolved: " + data.target);
|
2014-06-18 17:56:02 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let iconURL = null;
|
|
|
|
if (typeof data.icon == "string")
|
2014-10-24 08:19:00 -07:00
|
|
|
iconURL = this.resolveURL(browser, data.icon);
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
let buttons = [];
|
|
|
|
if (Array.isArray(data.buttons) && data.buttons.length > 0) {
|
|
|
|
for (let buttonData of data.buttons) {
|
|
|
|
if (typeof buttonData == "object" &&
|
|
|
|
typeof buttonData.label == "string" &&
|
|
|
|
typeof buttonData.callbackID == "string") {
|
|
|
|
let button = {
|
|
|
|
label: buttonData.label,
|
|
|
|
callbackID: buttonData.callbackID,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof buttonData.icon == "string")
|
2014-10-24 08:19:00 -07:00
|
|
|
button.iconURL = this.resolveURL(browser, buttonData.icon);
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
if (typeof buttonData.style == "string")
|
|
|
|
button.style = buttonData.style;
|
|
|
|
|
|
|
|
buttons.push(button);
|
|
|
|
|
2014-11-13 10:22:53 -08:00
|
|
|
if (buttons.length == MAX_BUTTONS) {
|
|
|
|
log.warn("showInfo: Reached limit of allowed number of buttons");
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
2014-11-13 10:22:53 -08:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let infoOptions = {};
|
|
|
|
|
|
|
|
if (typeof data.closeButtonCallbackID == "string")
|
|
|
|
infoOptions.closeButtonCallbackID = data.closeButtonCallbackID;
|
|
|
|
if (typeof data.targetCallbackID == "string")
|
|
|
|
infoOptions.targetCallbackID = data.targetCallbackID;
|
|
|
|
|
2014-12-04 14:40:03 -08:00
|
|
|
this.showInfo(window, messageManager, target, data.title, data.text, iconURL, buttons, infoOptions);
|
2014-11-13 10:22:53 -08:00
|
|
|
}).catch(log.error);
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "hideInfo": {
|
|
|
|
this.hideInfo(window);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "previewTheme": {
|
|
|
|
this.previewTheme(data.theme);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "resetTheme": {
|
|
|
|
this.resetTheme();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "showMenu": {
|
2014-10-14 17:48:49 -07:00
|
|
|
this.showMenu(window, data.name, () => {
|
|
|
|
if (typeof data.showCallbackID == "string")
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(messageManager, data.showCallbackID);
|
2014-10-14 17:48:49 -07:00
|
|
|
});
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "hideMenu": {
|
|
|
|
this.hideMenu(window, data.name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "startUrlbarCapture": {
|
|
|
|
if (typeof data.text != "string" || !data.text ||
|
|
|
|
typeof data.url != "string" || !data.url) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.warn("startUrlbarCapture: Text or URL not specified");
|
2014-06-18 17:56:02 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let uri = null;
|
|
|
|
try {
|
|
|
|
uri = Services.io.newURI(data.url, null, null);
|
|
|
|
} catch (e) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.warn("startUrlbarCapture: Malformed URL specified");
|
2014-06-18 17:56:02 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let secman = Services.scriptSecurityManager;
|
|
|
|
let principal = contentDocument.nodePrincipal;
|
|
|
|
let flags = secman.DISALLOW_INHERIT_PRINCIPAL;
|
|
|
|
try {
|
|
|
|
secman.checkLoadURIWithPrincipal(principal, uri, flags);
|
|
|
|
} catch (e) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.warn("startUrlbarCapture: Orginating page doesn't have permission to open specified URL");
|
2014-06-18 17:56:02 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.startUrlbarCapture(window, data.text, data.url);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "endUrlbarCapture": {
|
|
|
|
this.endUrlbarCapture(window);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "getConfiguration": {
|
|
|
|
if (typeof data.configuration != "string") {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.warn("getConfiguration: No configuration option specified");
|
2014-06-18 17:56:02 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-24 08:19:00 -07:00
|
|
|
this.getConfiguration(messageManager, window, data.configuration, data.callbackID);
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-17 19:37:19 -08:00
|
|
|
case "setConfiguration": {
|
|
|
|
if (typeof data.configuration != "string") {
|
|
|
|
log.warn("setConfiguration: No configuration option specified");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setConfiguration(data.configuration, data.value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
case "showFirefoxAccounts": {
|
|
|
|
// 'signup' is the only action that makes sense currently, so we don't
|
|
|
|
// accept arbitrary actions just to be safe...
|
|
|
|
// We want to replace the current tab.
|
2014-09-10 04:39:00 -07:00
|
|
|
contentDocument.location.href = "about:accounts?action=signup&entrypoint=uitour";
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-09-17 05:58:00 -07:00
|
|
|
|
|
|
|
case "resetFirefox": {
|
|
|
|
// Open a reset profile dialog window.
|
|
|
|
ResetProfile.openConfirmationDialog(window);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-06 15:49:30 -07:00
|
|
|
|
|
|
|
case "addNavBarWidget": {
|
|
|
|
// Add a widget to the toolbar
|
|
|
|
let targetPromise = this.getTarget(window, data.name);
|
|
|
|
targetPromise.then(target => {
|
2014-10-24 08:19:00 -07:00
|
|
|
this.addNavBarWidget(target, messageManager, data.callbackID);
|
2014-11-13 10:22:53 -08:00
|
|
|
}).catch(log.error);
|
2014-10-06 15:49:30 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-11-12 12:53:15 -08:00
|
|
|
|
|
|
|
case "setDefaultSearchEngine": {
|
|
|
|
let enginePromise = this.selectSearchEngine(data.identifier);
|
|
|
|
enginePromise.catch(Cu.reportError);
|
|
|
|
break;
|
|
|
|
}
|
2014-11-21 13:19:31 -08:00
|
|
|
|
2014-11-19 14:52:23 -08:00
|
|
|
case "setTreatmentTag": {
|
|
|
|
let name = data.name;
|
|
|
|
let value = data.value;
|
|
|
|
let string = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
|
|
|
string.data = value;
|
|
|
|
Services.prefs.setComplexValue("browser.uitour.treatment." + name,
|
|
|
|
Ci.nsISupportsString, string);
|
|
|
|
UITourHealthReport.recordTreatmentTag(name, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "getTreatmentTag": {
|
|
|
|
let name = data.name;
|
|
|
|
let value;
|
|
|
|
try {
|
|
|
|
value = Services.prefs.getComplexValue("browser.uitour.treatment." + name,
|
|
|
|
Ci.nsISupportsString).data;
|
|
|
|
} catch (ex) {}
|
|
|
|
this.sendPageCallback(messageManager, data.callbackID, { value: value });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-21 13:19:31 -08:00
|
|
|
case "setSearchTerm": {
|
|
|
|
let targetPromise = this.getTarget(window, "search");
|
|
|
|
targetPromise.then(target => {
|
|
|
|
let searchbar = target.node;
|
|
|
|
searchbar.value = data.term;
|
|
|
|
searchbar.inputChanged();
|
|
|
|
}).then(null, Cu.reportError);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "openSearchPanel": {
|
|
|
|
let targetPromise = this.getTarget(window, "search");
|
|
|
|
targetPromise.then(target => {
|
|
|
|
let searchbar = target.node;
|
|
|
|
|
|
|
|
if (searchbar.textbox.open) {
|
|
|
|
this.sendPageCallback(messageManager, data.callbackID);
|
|
|
|
} else {
|
|
|
|
let onPopupShown = () => {
|
|
|
|
searchbar.textbox.popup.removeEventListener("popupshown", onPopupShown);
|
|
|
|
this.sendPageCallback(messageManager, data.callbackID);
|
|
|
|
};
|
|
|
|
|
|
|
|
searchbar.textbox.popup.addEventListener("popupshown", onPopupShown);
|
|
|
|
searchbar.openSuggestionsPanel();
|
|
|
|
}
|
|
|
|
}).then(null, Cu.reportError);
|
|
|
|
break;
|
|
|
|
}
|
2014-12-04 17:50:45 -08:00
|
|
|
|
|
|
|
case "ping": {
|
|
|
|
if (typeof data.callbackID == "string")
|
|
|
|
this.sendPageCallback(messageManager, data.callbackID);
|
|
|
|
break;
|
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
if (!this.tourBrowsersByWindow.has(window)) {
|
|
|
|
this.tourBrowsersByWindow.set(window, new Set());
|
|
|
|
}
|
|
|
|
this.tourBrowsersByWindow.get(window).add(browser);
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
// We don't have a tab if it's being detached or we're in a <browser> without a tab.
|
|
|
|
if (tab) {
|
2014-10-24 08:19:00 -07:00
|
|
|
tab.addEventListener("TabClose", this);
|
2015-01-21 13:21:41 -08:00
|
|
|
if (!window.gMultiProcessBrowser) {
|
|
|
|
tab.addEventListener("TabBecomingWindow", this);
|
|
|
|
}
|
2014-10-24 08:19:00 -07:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
window.addEventListener("SSWindowClosing", this);
|
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function(aEvent) {
|
2015-01-21 13:21:41 -08:00
|
|
|
log.debug("handleEvent: type =", aEvent.type, "event =", aEvent);
|
2014-06-18 17:56:02 -07:00
|
|
|
switch (aEvent.type) {
|
|
|
|
case "pagehide": {
|
|
|
|
let window = this.getChromeWindow(aEvent.target);
|
2015-01-21 13:21:41 -08:00
|
|
|
this.teardownTourForWindow(window);
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "TabBecomingWindow":
|
|
|
|
this._detachingTab = true;
|
|
|
|
// Fall through
|
|
|
|
case "TabClose": {
|
|
|
|
let tab = aEvent.target;
|
|
|
|
let window = tab.ownerDocument.defaultView;
|
2015-01-21 13:21:41 -08:00
|
|
|
this.teardownTourForBrowser(window, tab.linkedBrowser, true);
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "TabSelect": {
|
2015-01-21 13:21:41 -08:00
|
|
|
let window = aEvent.target.ownerDocument.defaultView;
|
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
if (aEvent.detail && aEvent.detail.previousTab) {
|
|
|
|
let previousTab = aEvent.detail.previousTab;
|
2015-01-21 13:21:41 -08:00
|
|
|
let openTourWindows = this.tourBrowsersByWindow.get(window);
|
|
|
|
if (openTourWindows.has(previousTab.linkedBrowser)) {
|
|
|
|
this.teardownTourForBrowser(window, previousTab.linkedBrowser, false);
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let pendingDoc;
|
|
|
|
if (this._detachingTab && this._pendingDoc && (pendingDoc = this._pendingDoc.get())) {
|
2015-01-21 10:33:25 -08:00
|
|
|
let selectedTab = window.gBrowser.selectedTab;
|
2014-06-18 17:56:02 -07:00
|
|
|
if (selectedTab.linkedBrowser.contentDocument == pendingDoc) {
|
2015-01-21 13:21:41 -08:00
|
|
|
if (!this.tourBrowsersByWindow.get(window)) {
|
|
|
|
this.tourBrowsersByWindow.set(window, new Set());
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
2015-01-21 13:21:41 -08:00
|
|
|
this.tourBrowsersByWindow.get(window).add(selectedTab.linkedBrowser);
|
2014-06-18 17:56:02 -07:00
|
|
|
this.pendingDoc = null;
|
|
|
|
this._detachingTab = false;
|
|
|
|
while (this._queuedEvents.length) {
|
|
|
|
try {
|
|
|
|
this.onPageEvent(this._queuedEvents.shift());
|
|
|
|
} catch (ex) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.error(ex);
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "SSWindowClosing": {
|
|
|
|
let window = aEvent.target;
|
2015-01-21 13:21:41 -08:00
|
|
|
this.teardownTourForWindow(window);
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case "input": {
|
|
|
|
if (aEvent.target.id == "urlbar") {
|
|
|
|
let window = aEvent.target.ownerDocument.defaultView;
|
|
|
|
this.handleUrlbarInput(window);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setTelemetryBucket: function(aPageID) {
|
|
|
|
let bucket = BUCKET_NAME + BrowserUITelemetry.BUCKET_SEPARATOR + aPageID;
|
|
|
|
BrowserUITelemetry.setBucket(bucket);
|
|
|
|
},
|
|
|
|
|
|
|
|
setExpiringTelemetryBucket: function(aPageID, aType) {
|
|
|
|
let bucket = BUCKET_NAME + BrowserUITelemetry.BUCKET_SEPARATOR + aPageID +
|
|
|
|
BrowserUITelemetry.BUCKET_SEPARATOR + aType;
|
|
|
|
|
|
|
|
BrowserUITelemetry.setExpiringBucket(bucket,
|
|
|
|
BUCKET_TIMESTEPS);
|
|
|
|
},
|
|
|
|
|
|
|
|
// This is registered with UITelemetry by BrowserUITelemetry, so that UITour
|
|
|
|
// can remain lazy-loaded on-demand.
|
|
|
|
getTelemetry: function() {
|
|
|
|
return {
|
|
|
|
seenPageIDs: [...this.seenPageIDs.keys()],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
/**
|
|
|
|
* Tear down a tour from a tab e.g. upon switching/closing tabs.
|
|
|
|
*/
|
|
|
|
teardownTourForBrowser: function(aWindow, aBrowser, aTourPageClosing = false) {
|
|
|
|
log.debug("teardownTourForBrowser: aBrowser = ", aBrowser, aTourPageClosing);
|
2015-01-21 10:33:28 -08:00
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
if (this.pageIDSourceBrowsers.has(aBrowser)) {
|
|
|
|
let pageID = this.pageIDSourceBrowsers.get(aBrowser);
|
|
|
|
this.setExpiringTelemetryBucket(pageID, aTourPageClosing ? "closed" : "inactive");
|
|
|
|
}
|
|
|
|
|
|
|
|
let openTourBrowsers = this.tourBrowsersByWindow.get(aWindow);
|
|
|
|
if (aTourPageClosing) {
|
|
|
|
let tab = aWindow.gBrowser.getTabForBrowser(aBrowser);
|
|
|
|
if (tab) { // Handle standalone <browser>
|
2014-06-18 17:56:02 -07:00
|
|
|
tab.removeEventListener("TabClose", this);
|
|
|
|
tab.removeEventListener("TabBecomingWindow", this);
|
2015-01-21 13:21:41 -08:00
|
|
|
if (openTourBrowsers) {
|
|
|
|
openTourBrowsers.delete(aBrowser);
|
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
this.hideHighlight(aWindow);
|
|
|
|
this.hideInfo(aWindow);
|
|
|
|
// Ensure the menu panel is hidden before calling recreatePopup so popup events occur.
|
|
|
|
this.hideMenu(aWindow, "appMenu");
|
|
|
|
this.hideMenu(aWindow, "loop");
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
// Clean up panel listeners after calling hideMenu above.
|
2014-12-04 14:40:03 -08:00
|
|
|
aWindow.PanelUI.panel.removeEventListener("popuphiding", this.hideAppMenuAnnotations);
|
|
|
|
aWindow.PanelUI.panel.removeEventListener("ViewShowing", this.hideAppMenuAnnotations);
|
|
|
|
aWindow.PanelUI.panel.removeEventListener("popuphidden", this.onPanelHidden);
|
2014-11-30 21:46:23 -08:00
|
|
|
let loopPanel = aWindow.document.getElementById("loop-notification-panel");
|
2014-12-04 14:40:03 -08:00
|
|
|
loopPanel.removeEventListener("popuphidden", this.onPanelHidden);
|
|
|
|
loopPanel.removeEventListener("popuphiding", this.hideLoopPanelAnnotations);
|
2014-11-30 21:46:23 -08:00
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
this.endUrlbarCapture(aWindow);
|
|
|
|
this.resetTheme();
|
2015-01-21 13:21:41 -08:00
|
|
|
|
|
|
|
// If there are no more tour tabs left in the window, teardown the tour for the whole window.
|
|
|
|
if (!openTourBrowsers || openTourBrowsers.size == 0) {
|
|
|
|
this.teardownTourForWindow(aWindow);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tear down all tours for a ChromeWindow.
|
|
|
|
*/
|
|
|
|
teardownTourForWindow: function(aWindow) {
|
|
|
|
log.debug("teardownTourForWindow");
|
|
|
|
aWindow.gBrowser.tabContainer.removeEventListener("TabSelect", this);
|
|
|
|
aWindow.removeEventListener("SSWindowClosing", this);
|
|
|
|
|
|
|
|
let openTourBrowsers = this.tourBrowsersByWindow.get(aWindow);
|
|
|
|
if (openTourBrowsers) {
|
|
|
|
for (let browser of openTourBrowsers) {
|
|
|
|
if (this.pageIDSourceBrowsers.has(browser)) {
|
|
|
|
let pageID = this.pageIDSourceBrowsers.get(browser);
|
|
|
|
this.setExpiringTelemetryBucket(pageID, "closed");
|
|
|
|
}
|
|
|
|
|
|
|
|
let tab = aWindow.gBrowser.getTabForBrowser(browser);
|
|
|
|
tab.removeEventListener("TabClose", this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.tourBrowsersByWindow.delete(aWindow);
|
2014-06-18 17:56:02 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getChromeWindow: function(aContentDocument) {
|
|
|
|
return aContentDocument.defaultView
|
|
|
|
.window
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
|
|
|
.rootTreeItem
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow)
|
|
|
|
.wrappedJSObject;
|
|
|
|
},
|
|
|
|
|
2014-10-24 08:19:00 -07:00
|
|
|
// This function is copied to UITourListener.
|
2014-06-18 17:56:02 -07:00
|
|
|
isSafeScheme: function(aURI) {
|
2014-07-29 07:26:37 -07:00
|
|
|
let allowedSchemes = new Set(["https", "about"]);
|
2014-06-18 17:56:02 -07:00
|
|
|
if (!Services.prefs.getBoolPref("browser.uitour.requireSecure"))
|
|
|
|
allowedSchemes.add("http");
|
|
|
|
|
2014-11-13 10:22:53 -08:00
|
|
|
if (!allowedSchemes.has(aURI.scheme)) {
|
|
|
|
log.error("Unsafe scheme:", aURI.scheme);
|
2014-06-18 17:56:02 -07:00
|
|
|
return false;
|
2014-11-13 10:22:53 -08:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2014-10-24 08:19:00 -07:00
|
|
|
resolveURL: function(aBrowser, aURL) {
|
2014-06-18 17:56:02 -07:00
|
|
|
try {
|
2014-10-24 08:19:00 -07:00
|
|
|
let uri = Services.io.newURI(aURL, null, aBrowser.currentURI);
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
if (!this.isSafeScheme(uri))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return uri.spec;
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2014-10-24 08:19:00 -07:00
|
|
|
sendPageCallback: function(aMessageManager, aCallbackID, aData = {}) {
|
2014-06-18 17:56:02 -07:00
|
|
|
let detail = {data: aData, callbackID: aCallbackID};
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("sendPageCallback", detail);
|
2014-10-24 08:19:00 -07:00
|
|
|
aMessageManager.sendAsyncMessage("UITour:SendPageCallback", detail);
|
2014-06-18 17:56:02 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
isElementVisible: function(aElement) {
|
|
|
|
let targetStyle = aElement.ownerDocument.defaultView.getComputedStyle(aElement);
|
2014-12-04 14:40:03 -08:00
|
|
|
return !aElement.ownerDocument.hidden &&
|
|
|
|
targetStyle.display != "none" &&
|
|
|
|
targetStyle.visibility == "visible";
|
2014-06-18 17:56:02 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getTarget: function(aWindow, aTargetName, aSticky = false) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("getTarget:", aTargetName);
|
2014-06-18 17:56:02 -07:00
|
|
|
let deferred = Promise.defer();
|
|
|
|
if (typeof aTargetName != "string" || !aTargetName) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.warn("getTarget: Invalid target name specified");
|
2014-06-18 17:56:02 -07:00
|
|
|
deferred.reject("Invalid target name specified");
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
2014-10-14 17:48:49 -07:00
|
|
|
if (aTargetName.startsWith(TARGET_SEARCHENGINE_PREFIX)) {
|
|
|
|
let engineID = aTargetName.slice(TARGET_SEARCHENGINE_PREFIX.length);
|
|
|
|
return this.getSearchEngineTarget(aWindow, engineID);
|
|
|
|
}
|
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
let targetObject = this.targets.get(aTargetName);
|
|
|
|
if (!targetObject) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.warn("getTarget: The specified target name is not in the allowed set");
|
2014-06-18 17:56:02 -07:00
|
|
|
deferred.reject("The specified target name is not in the allowed set");
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
let targetQuery = targetObject.query;
|
|
|
|
aWindow.PanelUI.ensureReady().then(() => {
|
|
|
|
let node;
|
|
|
|
if (typeof targetQuery == "function") {
|
|
|
|
try {
|
|
|
|
node = targetQuery(aWindow.document);
|
|
|
|
} catch (ex) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.warn("getTarget: Error running target query:", ex);
|
2014-06-18 17:56:02 -07:00
|
|
|
node = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
node = aWindow.document.querySelector(targetQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
deferred.resolve({
|
|
|
|
addTargetListener: targetObject.addTargetListener,
|
2014-12-22 11:24:35 -08:00
|
|
|
infoPanelOffsetX: targetObject.infoPanelOffsetX,
|
|
|
|
infoPanelOffsetY: targetObject.infoPanelOffsetY,
|
2014-12-09 16:08:08 -08:00
|
|
|
infoPanelPosition: targetObject.infoPanelPosition,
|
2014-06-18 17:56:02 -07:00
|
|
|
node: node,
|
|
|
|
removeTargetListener: targetObject.removeTargetListener,
|
|
|
|
targetName: aTargetName,
|
|
|
|
widgetName: targetObject.widgetName,
|
2014-10-06 15:49:30 -07:00
|
|
|
allowAdd: targetObject.allowAdd,
|
2014-06-18 17:56:02 -07:00
|
|
|
});
|
2014-11-13 10:22:53 -08:00
|
|
|
}).catch(log.error);
|
2014-06-18 17:56:02 -07:00
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
targetIsInAppMenu: function(aTarget) {
|
|
|
|
let placement = CustomizableUI.getPlacementOfWidget(aTarget.widgetName || aTarget.node.id);
|
|
|
|
if (placement && placement.area == CustomizableUI.AREA_PANEL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let targetElement = aTarget.node;
|
|
|
|
// Use the widget for filtering if it exists since the target may be the icon inside.
|
|
|
|
if (aTarget.widgetName) {
|
|
|
|
targetElement = aTarget.node.ownerDocument.getElementById(aTarget.widgetName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle the non-customizable buttons at the bottom of the menu which aren't proper widgets.
|
|
|
|
return targetElement.id.startsWith("PanelUI-")
|
|
|
|
&& targetElement.id != "PanelUI-button";
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called before opening or after closing a highlight or info panel to see if
|
|
|
|
* we need to open or close the appMenu to see the annotation's anchor.
|
|
|
|
*/
|
|
|
|
_setAppMenuStateForAnnotation: function(aWindow, aAnnotationType, aShouldOpenForHighlight, aCallback = null) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("_setAppMenuStateForAnnotation:", aAnnotationType);
|
2014-11-30 21:46:23 -08:00
|
|
|
log.debug("_setAppMenuStateForAnnotation: Menu is expected to be:", aShouldOpenForHighlight ? "open" : "closed");
|
2014-11-13 10:22:53 -08:00
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
// If the panel is in the desired state, we're done.
|
|
|
|
let panelIsOpen = aWindow.PanelUI.panel.state != "closed";
|
|
|
|
if (aShouldOpenForHighlight == panelIsOpen) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("_setAppMenuStateForAnnotation: Panel already in expected state");
|
2014-06-18 17:56:02 -07:00
|
|
|
if (aCallback)
|
|
|
|
aCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't close the menu if it wasn't opened by us (e.g. via showmenu instead).
|
|
|
|
if (!aShouldOpenForHighlight && !this.appMenuOpenForAnnotation.has(aAnnotationType)) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("_setAppMenuStateForAnnotation: Menu not opened by us, not closing");
|
2014-06-18 17:56:02 -07:00
|
|
|
if (aCallback)
|
|
|
|
aCallback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aShouldOpenForHighlight) {
|
|
|
|
this.appMenuOpenForAnnotation.add(aAnnotationType);
|
|
|
|
} else {
|
|
|
|
this.appMenuOpenForAnnotation.delete(aAnnotationType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually show or hide the menu
|
|
|
|
if (this.appMenuOpenForAnnotation.size) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("_setAppMenuStateForAnnotation: Opening the menu");
|
2014-06-18 17:56:02 -07:00
|
|
|
this.showMenu(aWindow, "appMenu", aCallback);
|
|
|
|
} else {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("_setAppMenuStateForAnnotation: Closing the menu");
|
2014-06-18 17:56:02 -07:00
|
|
|
this.hideMenu(aWindow, "appMenu");
|
|
|
|
if (aCallback)
|
|
|
|
aCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
previewTheme: function(aTheme) {
|
|
|
|
let origin = Services.prefs.getCharPref("browser.uitour.themeOrigin");
|
|
|
|
let data = LightweightThemeManager.parseTheme(aTheme, origin);
|
|
|
|
if (data)
|
|
|
|
LightweightThemeManager.previewTheme(data);
|
|
|
|
},
|
|
|
|
|
|
|
|
resetTheme: function() {
|
|
|
|
LightweightThemeManager.resetPreview();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-12-04 14:40:03 -08:00
|
|
|
* @param aChromeWindow The chrome window that the highlight is in. Necessary since some targets
|
|
|
|
* are in a sub-frame so the defaultView is not the same as the chrome
|
|
|
|
* window.
|
2014-06-18 17:56:02 -07:00
|
|
|
* @param aTarget The element to highlight.
|
|
|
|
* @param aEffect (optional) The effect to use from UITour.highlightEffects or "none".
|
|
|
|
* @see UITour.highlightEffects
|
|
|
|
*/
|
2014-12-04 14:40:03 -08:00
|
|
|
showHighlight: function(aChromeWindow, aTarget, aEffect = "none") {
|
2014-10-14 17:48:49 -07:00
|
|
|
function showHighlightPanel() {
|
|
|
|
if (aTarget.targetName.startsWith(TARGET_SEARCHENGINE_PREFIX)) {
|
|
|
|
// This won't affect normal higlights done via the panel, so we need to
|
|
|
|
// manually hide those.
|
2014-12-04 14:40:03 -08:00
|
|
|
this.hideHighlight(aChromeWindow);
|
2014-10-14 17:48:49 -07:00
|
|
|
aTarget.node.setAttribute("_moz-menuactive", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conversely, highlights for search engines are highlighted via CSS
|
|
|
|
// rather than a panel, so need to be manually removed.
|
2014-12-04 14:40:03 -08:00
|
|
|
this._hideSearchEngineHighlight(aChromeWindow);
|
2014-10-14 17:48:49 -07:00
|
|
|
|
2014-12-04 14:40:03 -08:00
|
|
|
let highlighter = aChromeWindow.document.getElementById("UITourHighlight");
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
let effect = aEffect;
|
|
|
|
if (effect == "random") {
|
|
|
|
// Exclude "random" from the randomly selected effects.
|
|
|
|
let randomEffect = 1 + Math.floor(Math.random() * (this.highlightEffects.length - 1));
|
|
|
|
if (randomEffect == this.highlightEffects.length)
|
|
|
|
randomEffect--; // On the order of 1 in 2^62 chance of this happening.
|
|
|
|
effect = this.highlightEffects[randomEffect];
|
|
|
|
}
|
|
|
|
// Toggle the effect attribute to "none" and flush layout before setting it so the effect plays.
|
|
|
|
highlighter.setAttribute("active", "none");
|
2014-12-04 14:40:03 -08:00
|
|
|
aChromeWindow.getComputedStyle(highlighter).animationName;
|
2014-06-18 17:56:02 -07:00
|
|
|
highlighter.setAttribute("active", effect);
|
|
|
|
highlighter.parentElement.setAttribute("targetName", aTarget.targetName);
|
|
|
|
highlighter.parentElement.hidden = false;
|
|
|
|
|
2014-10-28 14:37:46 -07:00
|
|
|
let highlightAnchor;
|
|
|
|
// If the target is in the overflow panel, just highlight the overflow button.
|
|
|
|
if (aTarget.node.getAttribute("overflowedItem")) {
|
|
|
|
let doc = aTarget.node.ownerDocument;
|
|
|
|
let placement = CustomizableUI.getPlacementOfWidget(aTarget.widgetName || aTarget.node.id);
|
|
|
|
let areaNode = doc.getElementById(placement.area);
|
|
|
|
highlightAnchor = areaNode.overflowable._chevron;
|
|
|
|
} else {
|
|
|
|
highlightAnchor = aTarget.node;
|
|
|
|
}
|
|
|
|
let targetRect = highlightAnchor.getBoundingClientRect();
|
2014-06-18 17:56:02 -07:00
|
|
|
let highlightHeight = targetRect.height;
|
|
|
|
let highlightWidth = targetRect.width;
|
|
|
|
let minDimension = Math.min(highlightHeight, highlightWidth);
|
|
|
|
let maxDimension = Math.max(highlightHeight, highlightWidth);
|
|
|
|
|
|
|
|
// If the dimensions are within 200% of each other (to include the bookmarks button),
|
|
|
|
// make the highlight a circle with the largest dimension as the diameter.
|
|
|
|
if (maxDimension / minDimension <= 3.0) {
|
|
|
|
highlightHeight = highlightWidth = maxDimension;
|
|
|
|
highlighter.style.borderRadius = "100%";
|
|
|
|
} else {
|
|
|
|
highlighter.style.borderRadius = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
highlighter.style.height = highlightHeight + "px";
|
|
|
|
highlighter.style.width = highlightWidth + "px";
|
|
|
|
|
|
|
|
// Close a previous highlight so we can relocate the panel.
|
2014-07-14 10:39:04 -07:00
|
|
|
if (highlighter.parentElement.state == "showing" || highlighter.parentElement.state == "open") {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("showHighlight: Closing previous highlight first");
|
2014-06-18 17:56:02 -07:00
|
|
|
highlighter.parentElement.hidePopup();
|
|
|
|
}
|
|
|
|
/* The "overlap" position anchors from the top-left but we want to centre highlights at their
|
|
|
|
minimum size. */
|
2014-12-04 14:40:03 -08:00
|
|
|
let highlightWindow = aChromeWindow;
|
2014-06-18 17:56:02 -07:00
|
|
|
let containerStyle = highlightWindow.getComputedStyle(highlighter.parentElement);
|
|
|
|
let paddingTopPx = 0 - parseFloat(containerStyle.paddingTop);
|
|
|
|
let paddingLeftPx = 0 - parseFloat(containerStyle.paddingLeft);
|
|
|
|
let highlightStyle = highlightWindow.getComputedStyle(highlighter);
|
|
|
|
let highlightHeightWithMin = Math.max(highlightHeight, parseFloat(highlightStyle.minHeight));
|
|
|
|
let highlightWidthWithMin = Math.max(highlightWidth, parseFloat(highlightStyle.minWidth));
|
|
|
|
let offsetX = paddingTopPx
|
|
|
|
- (Math.max(0, highlightWidthWithMin - targetRect.width) / 2);
|
|
|
|
let offsetY = paddingLeftPx
|
|
|
|
- (Math.max(0, highlightHeightWithMin - targetRect.height) / 2);
|
|
|
|
this._addAnnotationPanelMutationObserver(highlighter.parentElement);
|
2014-10-28 14:37:46 -07:00
|
|
|
highlighter.parentElement.openPopup(highlightAnchor, "overlap", offsetX, offsetY);
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent showing a panel at an undefined position.
|
2014-11-13 10:22:53 -08:00
|
|
|
if (!this.isElementVisible(aTarget.node)) {
|
|
|
|
log.warn("showHighlight: Not showing a highlight since the target isn't visible", aTarget);
|
2014-06-18 17:56:02 -07:00
|
|
|
return;
|
2014-11-13 10:22:53 -08:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2014-12-04 14:40:03 -08:00
|
|
|
this._setAppMenuStateForAnnotation(aChromeWindow, "highlight",
|
2014-06-18 17:56:02 -07:00
|
|
|
this.targetIsInAppMenu(aTarget),
|
2014-10-14 17:48:49 -07:00
|
|
|
showHighlightPanel.bind(this));
|
2014-06-18 17:56:02 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
hideHighlight: function(aWindow) {
|
|
|
|
let highlighter = aWindow.document.getElementById("UITourHighlight");
|
|
|
|
this._removeAnnotationPanelMutationObserver(highlighter.parentElement);
|
|
|
|
highlighter.parentElement.hidePopup();
|
|
|
|
highlighter.removeAttribute("active");
|
|
|
|
|
|
|
|
this._setAppMenuStateForAnnotation(aWindow, "highlight", false);
|
2014-10-14 17:48:49 -07:00
|
|
|
this._hideSearchEngineHighlight(aWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
_hideSearchEngineHighlight: function(aWindow) {
|
|
|
|
// We special case highlighting items in the search engines dropdown,
|
|
|
|
// so just blindly remove any highlight there.
|
|
|
|
let searchMenuBtn = null;
|
|
|
|
try {
|
|
|
|
searchMenuBtn = this.targets.get("searchProvider").query(aWindow.document);
|
|
|
|
} catch (e) { /* This is ok to fail. */ }
|
|
|
|
if (searchMenuBtn) {
|
|
|
|
let searchPopup = aWindow.document
|
|
|
|
.getAnonymousElementByAttribute(searchMenuBtn,
|
|
|
|
"anonid",
|
|
|
|
"searchbar-popup");
|
|
|
|
for (let menuItem of searchPopup.children)
|
|
|
|
menuItem.removeAttribute("_moz-menuactive");
|
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show an info panel.
|
|
|
|
*
|
2014-12-04 14:40:03 -08:00
|
|
|
* @param {ChromeWindow} aChromeWindow
|
2014-10-24 08:19:00 -07:00
|
|
|
* @param {nsIMessageSender} aMessageManager
|
2014-06-18 17:56:02 -07:00
|
|
|
* @param {Node} aAnchor
|
|
|
|
* @param {String} [aTitle=""]
|
|
|
|
* @param {String} [aDescription=""]
|
|
|
|
* @param {String} [aIconURL=""]
|
|
|
|
* @param {Object[]} [aButtons=[]]
|
|
|
|
* @param {Object} [aOptions={}]
|
|
|
|
* @param {String} [aOptions.closeButtonCallbackID]
|
|
|
|
*/
|
2014-12-04 14:40:03 -08:00
|
|
|
showInfo: function(aChromeWindow, aMessageManager, aAnchor, aTitle = "", aDescription = "", aIconURL = "",
|
2014-06-18 17:56:02 -07:00
|
|
|
aButtons = [], aOptions = {}) {
|
|
|
|
function showInfoPanel(aAnchorEl) {
|
|
|
|
aAnchorEl.focus();
|
|
|
|
|
2014-12-04 14:40:03 -08:00
|
|
|
let document = aChromeWindow.document;
|
2014-06-18 17:56:02 -07:00
|
|
|
let tooltip = document.getElementById("UITourTooltip");
|
|
|
|
let tooltipTitle = document.getElementById("UITourTooltipTitle");
|
|
|
|
let tooltipDesc = document.getElementById("UITourTooltipDescription");
|
|
|
|
let tooltipIcon = document.getElementById("UITourTooltipIcon");
|
2014-12-16 18:30:34 -08:00
|
|
|
let tooltipIconContainer = document.getElementById("UITourTooltipIconContainer");
|
2014-06-18 17:56:02 -07:00
|
|
|
let tooltipButtons = document.getElementById("UITourTooltipButtons");
|
|
|
|
|
2014-07-14 10:39:04 -07:00
|
|
|
if (tooltip.state == "showing" || tooltip.state == "open") {
|
2014-06-18 17:56:02 -07:00
|
|
|
tooltip.hidePopup();
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltipTitle.textContent = aTitle || "";
|
|
|
|
tooltipDesc.textContent = aDescription || "";
|
|
|
|
tooltipIcon.src = aIconURL || "";
|
2014-12-16 18:30:34 -08:00
|
|
|
tooltipIconContainer.hidden = !aIconURL;
|
2014-06-18 17:56:02 -07:00
|
|
|
|
|
|
|
while (tooltipButtons.firstChild)
|
|
|
|
tooltipButtons.firstChild.remove();
|
|
|
|
|
|
|
|
for (let button of aButtons) {
|
|
|
|
let el = document.createElement("button");
|
|
|
|
el.setAttribute("label", button.label);
|
|
|
|
if (button.iconURL)
|
|
|
|
el.setAttribute("image", button.iconURL);
|
|
|
|
|
|
|
|
if (button.style == "link")
|
|
|
|
el.setAttribute("class", "button-link");
|
|
|
|
|
|
|
|
if (button.style == "primary")
|
|
|
|
el.setAttribute("class", "button-primary");
|
|
|
|
|
|
|
|
let callbackID = button.callbackID;
|
|
|
|
el.addEventListener("command", event => {
|
|
|
|
tooltip.hidePopup();
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, callbackID);
|
2014-06-18 17:56:02 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
tooltipButtons.appendChild(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltipButtons.hidden = !aButtons.length;
|
|
|
|
|
|
|
|
let tooltipClose = document.getElementById("UITourTooltipClose");
|
|
|
|
let closeButtonCallback = (event) => {
|
|
|
|
this.hideInfo(document.defaultView);
|
|
|
|
if (aOptions && aOptions.closeButtonCallbackID)
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, aOptions.closeButtonCallbackID);
|
2014-06-18 17:56:02 -07:00
|
|
|
};
|
|
|
|
tooltipClose.addEventListener("command", closeButtonCallback);
|
|
|
|
|
|
|
|
let targetCallback = (event) => {
|
|
|
|
let details = {
|
|
|
|
target: aAnchor.targetName,
|
|
|
|
type: event.type,
|
|
|
|
};
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, aOptions.targetCallbackID, details);
|
2014-06-18 17:56:02 -07:00
|
|
|
};
|
|
|
|
if (aOptions.targetCallbackID && aAnchor.addTargetListener) {
|
|
|
|
aAnchor.addTargetListener(document, targetCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltip.addEventListener("popuphiding", function tooltipHiding(event) {
|
|
|
|
tooltip.removeEventListener("popuphiding", tooltipHiding);
|
|
|
|
tooltipClose.removeEventListener("command", closeButtonCallback);
|
|
|
|
if (aOptions.targetCallbackID && aAnchor.removeTargetListener) {
|
|
|
|
aAnchor.removeTargetListener(document, targetCallback);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
tooltip.setAttribute("targetName", aAnchor.targetName);
|
|
|
|
tooltip.hidden = false;
|
|
|
|
let alignment = "bottomcenter topright";
|
2014-12-09 16:08:08 -08:00
|
|
|
if (aAnchor.infoPanelPosition) {
|
|
|
|
alignment = aAnchor.infoPanelPosition;
|
|
|
|
}
|
|
|
|
|
2014-12-22 11:24:35 -08:00
|
|
|
let { infoPanelOffsetX: xOffset, infoPanelOffsetY: yOffset } = aAnchor;
|
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
this._addAnnotationPanelMutationObserver(tooltip);
|
2014-12-22 11:24:35 -08:00
|
|
|
tooltip.openPopup(aAnchorEl, alignment, xOffset || 0, yOffset || 0);
|
2014-11-12 14:10:08 -08:00
|
|
|
if (tooltip.state == "closed") {
|
|
|
|
document.defaultView.addEventListener("endmodalstate", function endModalStateHandler() {
|
|
|
|
document.defaultView.removeEventListener("endmodalstate", endModalStateHandler);
|
|
|
|
tooltip.openPopup(aAnchorEl, alignment);
|
|
|
|
}, false);
|
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent showing a panel at an undefined position.
|
2014-12-04 14:40:03 -08:00
|
|
|
if (!this.isElementVisible(aAnchor.node)) {
|
|
|
|
log.warn("showInfo: Not showing since the target isn't visible", aAnchor);
|
2014-06-18 17:56:02 -07:00
|
|
|
return;
|
2014-12-04 14:40:03 -08:00
|
|
|
}
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2014-10-14 17:48:49 -07:00
|
|
|
// Due to a platform limitation, we can't anchor a panel to an element in a
|
|
|
|
// <menupopup>. So we can't support showing info panels for search engines.
|
|
|
|
if (aAnchor.targetName.startsWith(TARGET_SEARCHENGINE_PREFIX))
|
|
|
|
return;
|
|
|
|
|
2014-12-04 14:40:03 -08:00
|
|
|
this._setAppMenuStateForAnnotation(aChromeWindow, "info",
|
2014-06-18 17:56:02 -07:00
|
|
|
this.targetIsInAppMenu(aAnchor),
|
|
|
|
showInfoPanel.bind(this, aAnchor.node));
|
|
|
|
},
|
|
|
|
|
|
|
|
hideInfo: function(aWindow) {
|
|
|
|
let document = aWindow.document;
|
|
|
|
|
|
|
|
let tooltip = document.getElementById("UITourTooltip");
|
|
|
|
this._removeAnnotationPanelMutationObserver(tooltip);
|
|
|
|
tooltip.hidePopup();
|
|
|
|
this._setAppMenuStateForAnnotation(aWindow, "info", false);
|
|
|
|
|
|
|
|
let tooltipButtons = document.getElementById("UITourTooltipButtons");
|
|
|
|
while (tooltipButtons.firstChild)
|
|
|
|
tooltipButtons.firstChild.remove();
|
|
|
|
},
|
|
|
|
|
|
|
|
showMenu: function(aWindow, aMenuName, aOpenCallback = null) {
|
2015-01-21 13:21:41 -08:00
|
|
|
log.debug("showMenu:", aMenuName);
|
2014-10-14 17:48:49 -07:00
|
|
|
function openMenuButton(aMenuBtn) {
|
|
|
|
if (!aMenuBtn || !aMenuBtn.boxObject || aMenuBtn.open) {
|
|
|
|
if (aOpenCallback)
|
|
|
|
aOpenCallback();
|
2014-06-18 17:56:02 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aOpenCallback)
|
2014-10-14 17:48:49 -07:00
|
|
|
aMenuBtn.addEventListener("popupshown", onPopupShown);
|
2014-10-15 11:31:16 -07:00
|
|
|
aMenuBtn.boxObject.openMenu(true);
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
function onPopupShown(event) {
|
|
|
|
this.removeEventListener("popupshown", onPopupShown);
|
|
|
|
aOpenCallback(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMenuName == "appMenu") {
|
|
|
|
aWindow.PanelUI.panel.setAttribute("noautohide", "true");
|
|
|
|
// If the popup is already opened, don't recreate the widget as it may cause a flicker.
|
|
|
|
if (aWindow.PanelUI.panel.state != "open") {
|
|
|
|
this.recreatePopup(aWindow.PanelUI.panel);
|
|
|
|
}
|
2014-12-04 14:40:03 -08:00
|
|
|
aWindow.PanelUI.panel.addEventListener("popuphiding", this.hideAppMenuAnnotations);
|
|
|
|
aWindow.PanelUI.panel.addEventListener("ViewShowing", this.hideAppMenuAnnotations);
|
|
|
|
aWindow.PanelUI.panel.addEventListener("popuphidden", this.onPanelHidden);
|
2014-06-18 17:56:02 -07:00
|
|
|
if (aOpenCallback) {
|
|
|
|
aWindow.PanelUI.panel.addEventListener("popupshown", onPopupShown);
|
|
|
|
}
|
|
|
|
aWindow.PanelUI.show();
|
|
|
|
} else if (aMenuName == "bookmarks") {
|
2014-10-14 17:48:49 -07:00
|
|
|
let menuBtn = aWindow.document.getElementById("bookmarks-menu-button");
|
|
|
|
openMenuButton(menuBtn);
|
2014-11-30 21:46:23 -08:00
|
|
|
} else if (aMenuName == "loop") {
|
|
|
|
let toolbarButton = aWindow.LoopUI.toolbarButton;
|
2014-12-19 10:01:43 -08:00
|
|
|
// It's possible to have a node that isn't placed anywhere
|
|
|
|
if (!toolbarButton || !toolbarButton.node ||
|
|
|
|
!CustomizableUI.getPlacementOfWidget(toolbarButton.node.id)) {
|
|
|
|
log.debug("Can't show the Loop menu since the toolbarButton isn't placed");
|
2014-11-30 21:46:23 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let panel = aWindow.document.getElementById("loop-notification-panel");
|
|
|
|
panel.setAttribute("noautohide", true);
|
|
|
|
if (panel.state != "open") {
|
|
|
|
this.recreatePopup(panel);
|
2014-12-04 14:40:03 -08:00
|
|
|
this.availableTargetsCache.clear();
|
2014-11-30 21:46:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// An event object is expected but we don't want to toggle the panel with a click if the panel
|
|
|
|
// is already open.
|
2014-12-17 19:37:19 -08:00
|
|
|
aWindow.LoopUI.openCallPanel({ target: toolbarButton.node, }, "rooms").then(() => {
|
2014-11-30 21:46:23 -08:00
|
|
|
if (aOpenCallback) {
|
|
|
|
aOpenCallback();
|
|
|
|
}
|
|
|
|
});
|
2014-12-04 14:40:03 -08:00
|
|
|
panel.addEventListener("popuphidden", this.onPanelHidden);
|
|
|
|
panel.addEventListener("popuphiding", this.hideLoopPanelAnnotations);
|
2014-10-14 17:48:49 -07:00
|
|
|
} else if (aMenuName == "searchEngines") {
|
|
|
|
this.getTarget(aWindow, "searchProvider").then(target => {
|
|
|
|
openMenuButton(target.node);
|
2014-11-13 10:22:53 -08:00
|
|
|
}).catch(log.error);
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
hideMenu: function(aWindow, aMenuName) {
|
2015-01-21 13:21:41 -08:00
|
|
|
log.debug("hideMenu:", aMenuName);
|
2014-10-14 17:48:49 -07:00
|
|
|
function closeMenuButton(aMenuBtn) {
|
|
|
|
if (aMenuBtn && aMenuBtn.boxObject)
|
2014-10-15 11:31:16 -07:00
|
|
|
aMenuBtn.boxObject.openMenu(false);
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aMenuName == "appMenu") {
|
|
|
|
aWindow.PanelUI.hide();
|
|
|
|
} else if (aMenuName == "bookmarks") {
|
2014-10-14 17:48:49 -07:00
|
|
|
let menuBtn = aWindow.document.getElementById("bookmarks-menu-button");
|
|
|
|
closeMenuButton(menuBtn);
|
2014-11-30 21:46:23 -08:00
|
|
|
} else if (aMenuName == "loop") {
|
|
|
|
let panel = aWindow.document.getElementById("loop-notification-panel");
|
|
|
|
panel.hidePopup();
|
2014-10-14 17:48:49 -07:00
|
|
|
} else if (aMenuName == "searchEngines") {
|
|
|
|
let menuBtn = this.targets.get("searchProvider").query(aWindow.document);
|
|
|
|
closeMenuButton(menuBtn);
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-12-04 14:40:03 -08:00
|
|
|
hideAnnotationsForPanel: function(aEvent, aTargetPositionCallback) {
|
2014-06-18 17:56:02 -07:00
|
|
|
let win = aEvent.target.ownerDocument.defaultView;
|
|
|
|
let annotationElements = new Map([
|
|
|
|
// [annotationElement (panel), method to hide the annotation]
|
|
|
|
[win.document.getElementById("UITourHighlightContainer"), UITour.hideHighlight.bind(UITour)],
|
|
|
|
[win.document.getElementById("UITourTooltip"), UITour.hideInfo.bind(UITour)],
|
|
|
|
]);
|
|
|
|
annotationElements.forEach((hideMethod, annotationElement) => {
|
|
|
|
if (annotationElement.state != "closed") {
|
|
|
|
let targetName = annotationElement.getAttribute("targetName");
|
|
|
|
UITour.getTarget(win, targetName).then((aTarget) => {
|
|
|
|
// Since getTarget is async, we need to make sure that the target hasn't
|
|
|
|
// changed since it may have just moved to somewhere outside of the app menu.
|
|
|
|
if (annotationElement.getAttribute("targetName") != aTarget.targetName ||
|
|
|
|
annotationElement.state == "closed" ||
|
2014-12-04 14:40:03 -08:00
|
|
|
!aTargetPositionCallback(aTarget)) {
|
2014-06-18 17:56:02 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
hideMethod(win);
|
2014-11-13 10:22:53 -08:00
|
|
|
}).catch(log.error);
|
2014-06-18 17:56:02 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
UITour.appMenuOpenForAnnotation.clear();
|
|
|
|
},
|
|
|
|
|
2014-12-04 14:40:03 -08:00
|
|
|
hideAppMenuAnnotations: function(aEvent) {
|
|
|
|
UITour.hideAnnotationsForPanel(aEvent, UITour.targetIsInAppMenu);
|
|
|
|
},
|
|
|
|
|
|
|
|
hideLoopPanelAnnotations: function(aEvent) {
|
|
|
|
UITour.hideAnnotationsForPanel(aEvent, (aTarget) => {
|
2014-12-11 21:05:54 -08:00
|
|
|
return aTarget.targetName.startsWith("loop-") && aTarget.targetName != "loop-selectedRoomButtons";
|
2014-12-04 14:40:03 -08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onPanelHidden: function(aEvent) {
|
2014-11-30 21:46:23 -08:00
|
|
|
aEvent.target.removeAttribute("noautohide");
|
|
|
|
UITour.recreatePopup(aEvent.target);
|
|
|
|
},
|
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
recreatePopup: function(aPanel) {
|
|
|
|
// After changing popup attributes that relate to how the native widget is created
|
|
|
|
// (e.g. @noautohide) we need to re-create the frame/widget for it to take effect.
|
|
|
|
if (aPanel.hidden) {
|
|
|
|
// If the panel is already hidden, we don't need to recreate it but flush
|
|
|
|
// in case someone just hid it.
|
|
|
|
aPanel.clientWidth; // flush
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aPanel.hidden = true;
|
|
|
|
aPanel.clientWidth; // flush
|
|
|
|
aPanel.hidden = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
startUrlbarCapture: function(aWindow, aExpectedText, aUrl) {
|
|
|
|
let urlbar = aWindow.document.getElementById("urlbar");
|
|
|
|
this.urlbarCapture.set(aWindow, {
|
|
|
|
expected: aExpectedText.toLocaleLowerCase(),
|
|
|
|
url: aUrl
|
|
|
|
});
|
|
|
|
urlbar.addEventListener("input", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
endUrlbarCapture: function(aWindow) {
|
|
|
|
let urlbar = aWindow.document.getElementById("urlbar");
|
|
|
|
urlbar.removeEventListener("input", this);
|
|
|
|
this.urlbarCapture.delete(aWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleUrlbarInput: function(aWindow) {
|
|
|
|
if (!this.urlbarCapture.has(aWindow))
|
|
|
|
return;
|
|
|
|
|
|
|
|
let urlbar = aWindow.document.getElementById("urlbar");
|
|
|
|
|
|
|
|
let {expected, url} = this.urlbarCapture.get(aWindow);
|
|
|
|
|
|
|
|
if (urlbar.value.toLocaleLowerCase().localeCompare(expected) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
urlbar.handleRevert();
|
|
|
|
|
|
|
|
let tab = aWindow.gBrowser.addTab(url, {
|
|
|
|
owner: aWindow.gBrowser.selectedTab,
|
|
|
|
relatedToCurrent: true
|
|
|
|
});
|
|
|
|
aWindow.gBrowser.selectedTab = tab;
|
|
|
|
},
|
|
|
|
|
2014-10-24 08:19:00 -07:00
|
|
|
getConfiguration: function(aMessageManager, aWindow, aConfiguration, aCallbackID) {
|
2014-06-18 17:56:02 -07:00
|
|
|
switch (aConfiguration) {
|
|
|
|
case "availableTargets":
|
2014-10-24 08:19:00 -07:00
|
|
|
this.getAvailableTargets(aMessageManager, aWindow, aCallbackID);
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
case "sync":
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, aCallbackID, {
|
2014-06-18 17:56:02 -07:00
|
|
|
setup: Services.prefs.prefHasUserValue("services.sync.username"),
|
|
|
|
});
|
|
|
|
break;
|
2014-09-17 14:05:00 -07:00
|
|
|
case "appinfo":
|
2014-09-22 03:04:00 -07:00
|
|
|
let props = ["defaultUpdateChannel", "version"];
|
2014-09-17 14:05:00 -07:00
|
|
|
let appinfo = {};
|
|
|
|
props.forEach(property => appinfo[property] = Services.appinfo[property]);
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, aCallbackID, appinfo);
|
2014-09-17 14:05:00 -07:00
|
|
|
break;
|
2014-11-20 12:21:29 -08:00
|
|
|
case "selectedSearchEngine":
|
|
|
|
Services.search.init(rv => {
|
|
|
|
let engine;
|
|
|
|
if (Components.isSuccessCode(rv)) {
|
|
|
|
engine = Services.search.defaultEngine;
|
|
|
|
} else {
|
|
|
|
engine = { identifier: "" };
|
|
|
|
}
|
|
|
|
this.sendPageCallback(aMessageManager, aCallbackID, {
|
|
|
|
searchEngineIdentifier: engine.identifier
|
|
|
|
});
|
|
|
|
});
|
|
|
|
break;
|
2014-06-18 17:56:02 -07:00
|
|
|
default:
|
2014-11-13 10:22:53 -08:00
|
|
|
log.error("getConfiguration: Unknown configuration requested: " + aConfiguration);
|
2014-06-18 17:56:02 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-12-17 19:37:19 -08:00
|
|
|
setConfiguration: function(aConfiguration, aValue) {
|
|
|
|
switch (aConfiguration) {
|
|
|
|
case "Loop:ResumeTourOnFirstJoin":
|
|
|
|
// Ignore aValue in this case to avoid accidentally setting it to false.
|
|
|
|
Services.prefs.setBoolPref("loop.gettingStarted.resumeOnFirstJoin", true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log.error("setConfiguration: Unknown configuration requested: " + aConfiguration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-10-24 08:19:00 -07:00
|
|
|
getAvailableTargets: function(aMessageManager, aChromeWindow, aCallbackID) {
|
2014-10-14 17:48:49 -07:00
|
|
|
Task.spawn(function*() {
|
2014-10-24 08:19:00 -07:00
|
|
|
let window = aChromeWindow;
|
2014-10-14 17:48:49 -07:00
|
|
|
let data = this.availableTargetsCache.get(window);
|
|
|
|
if (data) {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.debug("getAvailableTargets: Using cached targets list", data.targets.join(","));
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, aCallbackID, data);
|
2014-10-14 17:48:49 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let promises = [];
|
|
|
|
for (let targetName of this.targets.keys()) {
|
|
|
|
promises.push(this.getTarget(window, targetName));
|
|
|
|
}
|
|
|
|
let targetObjects = yield Promise.all(promises);
|
2014-06-18 17:56:02 -07:00
|
|
|
|
2015-01-21 10:33:25 -08:00
|
|
|
let targetNames = [];
|
2014-06-18 17:56:02 -07:00
|
|
|
for (let targetObject of targetObjects) {
|
|
|
|
if (targetObject.node)
|
|
|
|
targetNames.push(targetObject.targetName);
|
|
|
|
}
|
2014-10-14 17:48:49 -07:00
|
|
|
|
|
|
|
targetNames = targetNames.concat(
|
|
|
|
yield this.getAvailableSearchEngineTargets(window)
|
|
|
|
);
|
|
|
|
|
|
|
|
data = {
|
2014-06-18 17:56:02 -07:00
|
|
|
targets: targetNames,
|
|
|
|
};
|
|
|
|
this.availableTargetsCache.set(window, data);
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, aCallbackID, data);
|
2014-10-14 17:48:49 -07:00
|
|
|
}.bind(this)).catch(err => {
|
2014-11-13 10:22:53 -08:00
|
|
|
log.error(err);
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, aCallbackID, {
|
2014-06-18 17:56:02 -07:00
|
|
|
targets: [],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-10-24 08:19:00 -07:00
|
|
|
addNavBarWidget: function (aTarget, aMessageManager, aCallbackID) {
|
2014-10-06 15:49:30 -07:00
|
|
|
if (aTarget.node) {
|
2014-11-13 11:25:45 -08:00
|
|
|
log.error("addNavBarWidget: can't add a widget already present:", aTarget);
|
2014-10-06 15:49:30 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!aTarget.allowAdd) {
|
2014-11-13 11:25:45 -08:00
|
|
|
log.error("addNavBarWidget: not allowed to add this widget:", aTarget);
|
2014-10-06 15:49:30 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!aTarget.widgetName) {
|
2014-11-13 11:25:45 -08:00
|
|
|
log.error("addNavBarWidget: can't add a widget without a widgetName property:", aTarget);
|
2014-10-06 15:49:30 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomizableUI.addWidgetToArea(aTarget.widgetName, CustomizableUI.AREA_NAVBAR);
|
2014-10-24 08:19:00 -07:00
|
|
|
this.sendPageCallback(aMessageManager, aCallbackID);
|
2014-10-06 15:49:30 -07:00
|
|
|
},
|
|
|
|
|
2014-06-18 17:56:02 -07:00
|
|
|
_addAnnotationPanelMutationObserver: function(aPanelEl) {
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
let observer = this._annotationPanelMutationObservers.get(aPanelEl);
|
|
|
|
if (observer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let win = aPanelEl.ownerDocument.defaultView;
|
|
|
|
observer = new win.MutationObserver(this._annotationMutationCallback);
|
|
|
|
this._annotationPanelMutationObservers.set(aPanelEl, observer);
|
|
|
|
let observerOptions = {
|
|
|
|
attributeFilter: ["height", "width"],
|
|
|
|
attributes: true,
|
|
|
|
};
|
|
|
|
observer.observe(aPanelEl, observerOptions);
|
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeAnnotationPanelMutationObserver: function(aPanelEl) {
|
|
|
|
#ifdef XP_LINUX
|
|
|
|
let observer = this._annotationPanelMutationObservers.get(aPanelEl);
|
|
|
|
if (observer) {
|
|
|
|
observer.disconnect();
|
|
|
|
this._annotationPanelMutationObservers.delete(aPanelEl);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Workaround for Ubuntu panel craziness in bug 970788 where incorrect sizes get passed to
|
|
|
|
* nsXULPopupManager::PopupResized and lead to incorrect width and height attributes getting
|
|
|
|
* set on the panel.
|
|
|
|
*/
|
|
|
|
_annotationMutationCallback: function(aMutations) {
|
|
|
|
for (let mutation of aMutations) {
|
|
|
|
// Remove both attributes at once and ignore remaining mutations to be proccessed.
|
|
|
|
mutation.target.removeAttribute("width");
|
|
|
|
mutation.target.removeAttribute("height");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
2014-10-14 17:48:49 -07:00
|
|
|
|
2014-11-12 12:53:15 -08:00
|
|
|
selectSearchEngine(aID) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Services.search.init((rv) => {
|
|
|
|
if (!Components.isSuccessCode(rv)) {
|
|
|
|
reject("selectSearchEngine: search service init failed: " + rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let engines = Services.search.getVisibleEngines();
|
|
|
|
for (let engine of engines) {
|
|
|
|
if (engine.identifier == aID) {
|
|
|
|
Services.search.defaultEngine = engine;
|
|
|
|
return resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reject("selectSearchEngine could not find engine with given ID");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-10-14 17:48:49 -07:00
|
|
|
getAvailableSearchEngineTargets(aWindow) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this.getTarget(aWindow, "search").then(searchTarget => {
|
|
|
|
if (!searchTarget.node || this.targetIsInAppMenu(searchTarget))
|
|
|
|
return resolve([]);
|
|
|
|
|
|
|
|
Services.search.init(() => {
|
|
|
|
let engines = Services.search.getVisibleEngines();
|
|
|
|
resolve([TARGET_SEARCHENGINE_PREFIX + engine.identifier
|
|
|
|
for (engine of engines)
|
|
|
|
if (engine.identifier)]);
|
|
|
|
});
|
|
|
|
}).catch(() => resolve([]));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// We only allow matching based on a search engine's identifier - this gives
|
|
|
|
// us a non-changing ID and guarentees we only match against app-provided
|
|
|
|
// engines.
|
|
|
|
getSearchEngineTarget(aWindow, aIdentifier) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
Task.spawn(function*() {
|
|
|
|
let searchTarget = yield this.getTarget(aWindow, "search");
|
|
|
|
// We're not supporting having the searchbar in the app-menu, because
|
|
|
|
// popups within popups gets crazy. This restriction should be lifted
|
|
|
|
// once bug 988151 is implemented, as the page can then be responsible
|
|
|
|
// for opening each menu when appropriate.
|
|
|
|
if (!searchTarget.node || this.targetIsInAppMenu(searchTarget))
|
|
|
|
return reject("Search engine not available");
|
|
|
|
|
|
|
|
yield Services.search.init();
|
|
|
|
|
|
|
|
let searchPopup = searchTarget.node._popup;
|
|
|
|
for (let engineNode of searchPopup.children) {
|
|
|
|
let engine = engineNode.engine;
|
|
|
|
if (engine && engine.identifier == aIdentifier) {
|
|
|
|
return resolve({
|
|
|
|
targetName: TARGET_SEARCHENGINE_PREFIX + engine.identifier,
|
|
|
|
node: engineNode,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reject("Search engine not available");
|
|
|
|
}.bind(this)).catch(() => {
|
|
|
|
reject("Search engine not available");
|
|
|
|
});
|
|
|
|
});
|
2014-12-04 17:50:45 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
notify(eventName, params) {
|
|
|
|
let winEnum = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (winEnum.hasMoreElements()) {
|
|
|
|
let window = winEnum.getNext();
|
|
|
|
if (window.closed)
|
|
|
|
continue;
|
2014-12-10 16:33:33 -08:00
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
let openTourBrowsers = this.tourBrowsersByWindow.get(window);
|
|
|
|
if (!openTourBrowsers)
|
2014-12-04 17:50:45 -08:00
|
|
|
continue;
|
|
|
|
|
2015-01-21 13:21:41 -08:00
|
|
|
for (let browser of openTourBrowsers) {
|
|
|
|
let messageManager = browser.messageManager;
|
|
|
|
if (!messageManager) {
|
|
|
|
log.error("notify: Trying to notify a browser without a messageManager", browser);
|
|
|
|
continue;
|
|
|
|
}
|
2014-12-04 17:50:45 -08:00
|
|
|
let detail = {
|
|
|
|
event: eventName,
|
|
|
|
params: params,
|
|
|
|
};
|
|
|
|
messageManager.sendAsyncMessage("UITour:SendPageNotification", detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-06-18 17:56:02 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
this.UITour.init();
|
2014-11-20 12:21:29 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UITour Health Report
|
|
|
|
*/
|
|
|
|
const DAILY_DISCRETE_TEXT_FIELD = Metrics.Storage.FIELD_DAILY_DISCRETE_TEXT;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public API to be called by the UITour code
|
|
|
|
*/
|
|
|
|
const UITourHealthReport = {
|
|
|
|
recordTreatmentTag: function(tag, value) {
|
|
|
|
#ifdef MOZ_SERVICES_HEALTHREPORT
|
|
|
|
Task.spawn(function*() {
|
|
|
|
let reporter = Cc["@mozilla.org/datareporting/service;1"]
|
|
|
|
.getService()
|
|
|
|
.wrappedJSObject
|
|
|
|
.healthReporter;
|
|
|
|
|
|
|
|
// This can happen if the FHR component of the data reporting service is
|
|
|
|
// disabled. This is controlled by a pref that most will never use.
|
|
|
|
if (!reporter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield reporter.onInit();
|
|
|
|
|
|
|
|
// Get the UITourMetricsProvider instance from the Health Reporter
|
|
|
|
reporter.getProvider("org.mozilla.uitour").recordTreatmentTag(tag, value);
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.UITourMetricsProvider = function() {
|
|
|
|
Metrics.Provider.call(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
UITourMetricsProvider.prototype = Object.freeze({
|
|
|
|
__proto__: Metrics.Provider.prototype,
|
|
|
|
|
|
|
|
name: "org.mozilla.uitour",
|
|
|
|
|
|
|
|
measurementTypes: [
|
|
|
|
UITourTreatmentMeasurement1,
|
|
|
|
],
|
|
|
|
|
|
|
|
recordTreatmentTag: function(tag, value) {
|
|
|
|
let m = this.getMeasurement(UITourTreatmentMeasurement1.prototype.name,
|
|
|
|
UITourTreatmentMeasurement1.prototype.version);
|
|
|
|
let field = tag;
|
|
|
|
|
|
|
|
if (this.storage.hasFieldFromMeasurement(m.id, field,
|
|
|
|
DAILY_DISCRETE_TEXT_FIELD)) {
|
|
|
|
let fieldID = this.storage.fieldIDFromMeasurement(m.id, field);
|
|
|
|
return this.enqueueStorageOperation(function recordKnownField() {
|
|
|
|
return this.storage.addDailyDiscreteTextFromFieldID(fieldID, value);
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we first need to create the field.
|
|
|
|
return this.enqueueStorageOperation(function recordField() {
|
|
|
|
// This function has to return a promise.
|
|
|
|
return Task.spawn(function () {
|
|
|
|
let fieldID = yield this.storage.registerField(m.id, field,
|
|
|
|
DAILY_DISCRETE_TEXT_FIELD);
|
|
|
|
yield this.storage.addDailyDiscreteTextFromFieldID(fieldID, value);
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function UITourTreatmentMeasurement1() {
|
|
|
|
Metrics.Measurement.call(this);
|
|
|
|
|
|
|
|
this._serializers = {};
|
|
|
|
this._serializers[this.SERIALIZE_JSON] = {
|
|
|
|
//singular: We don't need a singular serializer because we have none of this data
|
|
|
|
daily: this._serializeJSONDaily.bind(this)
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UITourTreatmentMeasurement1.prototype = Object.freeze({
|
|
|
|
__proto__: Metrics.Measurement.prototype,
|
|
|
|
|
|
|
|
name: "treatment",
|
|
|
|
version: 1,
|
|
|
|
|
|
|
|
// our fields are dynamic
|
|
|
|
fields: { },
|
|
|
|
|
|
|
|
// We need a custom serializer because the default one doesn't accept unknown fields
|
|
|
|
_serializeJSONDaily: function(data) {
|
|
|
|
let result = {_v: this.version };
|
|
|
|
|
|
|
|
for (let [field, data] of data) {
|
|
|
|
result[field] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
});
|