browser/devtools/netmonitor/panel.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/netmonitor/panel.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +"use strict";
    1.10 +
    1.11 +const { Cc, Ci, Cu, Cr } = require("chrome");
    1.12 +const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
    1.13 +const EventEmitter = require("devtools/toolkit/event-emitter");
    1.14 +const { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {});
    1.15 +
    1.16 +function NetMonitorPanel(iframeWindow, toolbox) {
    1.17 +  this.panelWin = iframeWindow;
    1.18 +  this._toolbox = toolbox;
    1.19 +  this._destroyer = null;
    1.20 +
    1.21 +  this._view = this.panelWin.NetMonitorView;
    1.22 +  this._controller = this.panelWin.NetMonitorController;
    1.23 +  this._controller._target = this.target;
    1.24 +
    1.25 +  EventEmitter.decorate(this);
    1.26 +};
    1.27 +
    1.28 +exports.NetMonitorPanel = NetMonitorPanel;
    1.29 +
    1.30 +NetMonitorPanel.prototype = {
    1.31 +  /**
    1.32 +   * Open is effectively an asynchronous constructor.
    1.33 +   *
    1.34 +   * @return object
    1.35 +   *         A promise that is resolved when the NetMonitor completes opening.
    1.36 +   */
    1.37 +  open: function() {
    1.38 +    let targetPromise;
    1.39 +
    1.40 +    // Local monitoring needs to make the target remote.
    1.41 +    if (!this.target.isRemote) {
    1.42 +      targetPromise = this.target.makeRemote();
    1.43 +    } else {
    1.44 +      targetPromise = promise.resolve(this.target);
    1.45 +    }
    1.46 +
    1.47 +    return targetPromise
    1.48 +      .then(() => this._controller.startupNetMonitor())
    1.49 +      .then(() => this._controller.connect())
    1.50 +      .then(() => {
    1.51 +        this.isReady = true;
    1.52 +        this.emit("ready");
    1.53 +        return this;
    1.54 +      })
    1.55 +      .then(null, function onError(aReason) {
    1.56 +        DevToolsUtils.reportException("NetMonitorPanel.prototype.open", aReason);
    1.57 +      });
    1.58 +  },
    1.59 +
    1.60 +  // DevToolPanel API
    1.61 +
    1.62 +  get target() this._toolbox.target,
    1.63 +
    1.64 +  destroy: function() {
    1.65 +    // Make sure this panel is not already destroyed.
    1.66 +    if (this._destroyer) {
    1.67 +      return this._destroyer;
    1.68 +    }
    1.69 +
    1.70 +    return this._destroyer = this._controller.shutdownNetMonitor().then(() => {
    1.71 +      this.emit("destroyed");
    1.72 +    });
    1.73 +  }
    1.74 +};

mercurial