summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/panel.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/performance/panel.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/performance/panel.js')
-rw-r--r--devtools/client/performance/panel.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/devtools/client/performance/panel.js b/devtools/client/performance/panel.js
new file mode 100644
index 000000000..6fa9f37cf
--- /dev/null
+++ b/devtools/client/performance/panel.js
@@ -0,0 +1,100 @@
+/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* 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 { Task } = require("devtools/shared/task");
+
+loader.lazyRequireGetter(this, "promise");
+loader.lazyRequireGetter(this, "EventEmitter",
+ "devtools/shared/event-emitter");
+
+function PerformancePanel(iframeWindow, toolbox) {
+ this.panelWin = iframeWindow;
+ this.toolbox = toolbox;
+
+ EventEmitter.decorate(this);
+}
+
+exports.PerformancePanel = PerformancePanel;
+
+PerformancePanel.prototype = {
+ /**
+ * Open is effectively an asynchronous constructor.
+ *
+ * @return object
+ * A promise that is resolved when the Performance tool
+ * completes opening.
+ */
+ open: Task.async(function* () {
+ if (this._opening) {
+ return this._opening;
+ }
+ let deferred = promise.defer();
+ this._opening = deferred.promise;
+
+ this.panelWin.gToolbox = this.toolbox;
+ this.panelWin.gTarget = this.target;
+ this._checkRecordingStatus = this._checkRecordingStatus.bind(this);
+
+ // Actor is already created in the toolbox; reuse
+ // the same front, and the toolbox will also initialize the front,
+ // but redo it here so we can hook into the same event to prevent race conditions
+ // in the case of the front still being in the process of opening.
+ let front = yield this.panelWin.gToolbox.initPerformance();
+
+ // This should only happen if this is completely unsupported (when profiler
+ // does not exist), and in that case, the tool shouldn't be available,
+ // so let's ensure this assertion.
+ if (!front) {
+ console.error("No PerformanceFront found in toolbox.");
+ }
+
+ this.panelWin.gFront = front;
+ let { PerformanceController, EVENTS } = this.panelWin;
+ PerformanceController.on(EVENTS.RECORDING_ADDED, this._checkRecordingStatus);
+ PerformanceController.on(EVENTS.RECORDING_STATE_CHANGE, this._checkRecordingStatus);
+ yield this.panelWin.startupPerformance();
+
+ // Fire this once incase we have an in-progress recording (console profile)
+ // that caused this start up, and no state change yet, so we can highlight the
+ // tab if we need.
+ this._checkRecordingStatus();
+
+ this.isReady = true;
+ this.emit("ready");
+
+ deferred.resolve(this);
+ return this._opening;
+ }),
+
+ // DevToolPanel API
+
+ get target() {
+ return this.toolbox.target;
+ },
+
+ destroy: Task.async(function* () {
+ // Make sure this panel is not already destroyed.
+ if (this._destroyed) {
+ return;
+ }
+
+ let { PerformanceController, EVENTS } = this.panelWin;
+ PerformanceController.off(EVENTS.RECORDING_ADDED, this._checkRecordingStatus);
+ PerformanceController.off(EVENTS.RECORDING_STATE_CHANGE, this._checkRecordingStatus);
+ yield this.panelWin.shutdownPerformance();
+ this.emit("destroyed");
+ this._destroyed = true;
+ }),
+
+ _checkRecordingStatus: function () {
+ if (this.panelWin.PerformanceController.isRecording()) {
+ this.toolbox.highlightTool("performance");
+ } else {
+ this.toolbox.unhighlightTool("performance");
+ }
+ }
+};