2014-08-29 20:32:49 +04:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2015-08-18 13:48:22 +03:00
|
|
|
"use strict";
|
|
|
|
|
2018-03-21 17:46:00 +03:00
|
|
|
const EventEmitter = require("devtools/shared/event-emitter");
|
2014-08-29 20:32:49 +04:00
|
|
|
|
2015-09-02 18:51:02 +03:00
|
|
|
loader.lazyRequireGetter(this, "StorageFront",
|
2016-05-17 15:59:21 +03:00
|
|
|
"devtools/shared/fronts/storage", true);
|
2015-09-02 18:51:02 +03:00
|
|
|
loader.lazyRequireGetter(this, "StorageUI",
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/client/storage/ui", true);
|
2014-08-29 20:32:49 +04:00
|
|
|
|
2018-03-06 19:06:04 +03:00
|
|
|
class StoragePanel {
|
|
|
|
constructor(panelWin, toolbox) {
|
|
|
|
EventEmitter.decorate(this);
|
2014-08-29 20:32:49 +04:00
|
|
|
|
2018-03-06 19:06:04 +03:00
|
|
|
this._toolbox = toolbox;
|
|
|
|
this._target = toolbox.target;
|
|
|
|
this._panelWin = panelWin;
|
2014-08-29 20:32:49 +04:00
|
|
|
|
2018-03-06 19:06:04 +03:00
|
|
|
this.destroy = this.destroy.bind(this);
|
|
|
|
}
|
2014-08-29 20:32:49 +04:00
|
|
|
|
2015-05-25 15:42:51 +03:00
|
|
|
get target() {
|
|
|
|
return this._toolbox.target;
|
2018-03-06 19:06:04 +03:00
|
|
|
}
|
2014-08-29 20:32:49 +04:00
|
|
|
|
2015-05-25 15:42:51 +03:00
|
|
|
get panelWindow() {
|
|
|
|
return this._panelWin;
|
2018-03-06 19:06:04 +03:00
|
|
|
}
|
2014-08-29 20:32:49 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* open is effectively an asynchronous constructor
|
|
|
|
*/
|
2018-03-06 19:06:04 +03:00
|
|
|
open() {
|
2014-08-29 20:32:49 +04:00
|
|
|
let targetPromise;
|
|
|
|
// We always interact with the target as if it were remote
|
|
|
|
if (!this.target.isRemote) {
|
|
|
|
targetPromise = this.target.makeRemote();
|
|
|
|
} else {
|
|
|
|
targetPromise = Promise.resolve(this.target);
|
|
|
|
}
|
|
|
|
|
|
|
|
return targetPromise.then(() => {
|
|
|
|
this.target.on("close", this.destroy);
|
|
|
|
this._front = new StorageFront(this.target.client, this.target.form);
|
|
|
|
|
2016-05-17 21:57:21 +03:00
|
|
|
this.UI = new StorageUI(this._front, this._target,
|
|
|
|
this._panelWin, this._toolbox);
|
2014-08-29 20:32:49 +04:00
|
|
|
this.isReady = true;
|
|
|
|
this.emit("ready");
|
2015-08-20 13:52:04 +03:00
|
|
|
|
2014-08-29 20:32:49 +04:00
|
|
|
return this;
|
2016-02-02 12:31:34 +03:00
|
|
|
}).catch(e => {
|
|
|
|
console.log("error while opening storage panel", e);
|
|
|
|
this.destroy();
|
|
|
|
});
|
2018-03-06 19:06:04 +03:00
|
|
|
}
|
2014-08-29 20:32:49 +04:00
|
|
|
|
|
|
|
/**
|
2014-11-08 02:06:00 +03:00
|
|
|
* Destroy the storage inspector.
|
2014-08-29 20:32:49 +04:00
|
|
|
*/
|
2018-03-06 19:06:04 +03:00
|
|
|
destroy() {
|
2014-08-29 20:32:49 +04:00
|
|
|
if (!this._destroyed) {
|
|
|
|
this.UI.destroy();
|
2015-08-20 13:52:04 +03:00
|
|
|
this.UI = null;
|
|
|
|
|
2014-09-24 10:48:00 +04:00
|
|
|
// Destroy front to ensure packet handler is removed from client
|
|
|
|
this._front.destroy();
|
2015-08-20 13:52:04 +03:00
|
|
|
this._front = null;
|
2014-08-29 20:32:49 +04:00
|
|
|
this._destroyed = true;
|
|
|
|
|
|
|
|
this._target.off("close", this.destroy);
|
|
|
|
this._target = null;
|
|
|
|
this._toolbox = null;
|
2015-08-20 13:52:04 +03:00
|
|
|
this._panelWin = null;
|
2014-08-29 20:32:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve(null);
|
2018-03-06 19:06:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.StoragePanel = StoragePanel;
|