mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 12:37:37 +00:00
98 lines
2.3 KiB
JavaScript
98 lines
2.3 KiB
JavaScript
/* 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";
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
|
Cu.import("resource://gre/modules/devtools/Loader.jsm");
|
|
Cu.import("resource:///modules/devtools/ViewHelpers.jsm");
|
|
|
|
devtools.lazyRequireGetter(this, "Services");
|
|
devtools.lazyRequireGetter(this, "promise");
|
|
devtools.lazyRequireGetter(this, "EventEmitter",
|
|
"devtools/toolkit/event-emitter");
|
|
devtools.lazyRequireGetter(this, "DevToolsUtils",
|
|
"devtools/toolkit/DevToolsUtils");
|
|
|
|
/**
|
|
* The current target and the profiler connection, set by this tool's host.
|
|
*/
|
|
let gToolbox, gTarget, gFront;
|
|
|
|
/**
|
|
* Initializes the profiler controller and views.
|
|
*/
|
|
let startupPerformance = Task.async(function*() {
|
|
yield promise.all([
|
|
PrefObserver.register(),
|
|
EventsHandler.initialize()
|
|
]);
|
|
});
|
|
|
|
/**
|
|
* Destroys the profiler controller and views.
|
|
*/
|
|
let shutdownPerformance = Task.async(function*() {
|
|
yield promise.all([
|
|
PrefObserver.unregister(),
|
|
EventsHandler.destroy()
|
|
]);
|
|
});
|
|
|
|
/**
|
|
* Observes pref changes on the devtools.profiler branch and triggers the
|
|
* required frontend modifications.
|
|
*/
|
|
let PrefObserver = {
|
|
register: function() {
|
|
this.branch = Services.prefs.getBranch("devtools.profiler.");
|
|
this.branch.addObserver("", this, false);
|
|
},
|
|
unregister: function() {
|
|
this.branch.removeObserver("", this);
|
|
},
|
|
observe: function(subject, topic, pref) {
|
|
Prefs.refresh();
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Functions handling target-related lifetime events.
|
|
*/
|
|
let EventsHandler = {
|
|
/**
|
|
* Listen for events emitted by the current tab target.
|
|
*/
|
|
initialize: function() {
|
|
},
|
|
|
|
/**
|
|
* Remove events emitted by the current tab target.
|
|
*/
|
|
destroy: function() {
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Shortcuts for accessing various profiler preferences.
|
|
*/
|
|
const Prefs = new ViewHelpers.Prefs("devtools.profiler", {
|
|
});
|
|
|
|
/**
|
|
* Convenient way of emitting events from the panel window.
|
|
*/
|
|
EventEmitter.decorate(this);
|
|
|
|
/**
|
|
* DOM query helpers.
|
|
*/
|
|
function $(selector, target = document) {
|
|
return target.querySelector(selector);
|
|
}
|
|
function $$(selector, target = document) {
|
|
return target.querySelectorAll(selector);
|
|
}
|