browser/devtools/netmonitor/panel.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 "use strict";
     8 const { Cc, Ci, Cu, Cr } = require("chrome");
     9 const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
    10 const EventEmitter = require("devtools/toolkit/event-emitter");
    11 const { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {});
    13 function NetMonitorPanel(iframeWindow, toolbox) {
    14   this.panelWin = iframeWindow;
    15   this._toolbox = toolbox;
    16   this._destroyer = null;
    18   this._view = this.panelWin.NetMonitorView;
    19   this._controller = this.panelWin.NetMonitorController;
    20   this._controller._target = this.target;
    22   EventEmitter.decorate(this);
    23 };
    25 exports.NetMonitorPanel = NetMonitorPanel;
    27 NetMonitorPanel.prototype = {
    28   /**
    29    * Open is effectively an asynchronous constructor.
    30    *
    31    * @return object
    32    *         A promise that is resolved when the NetMonitor completes opening.
    33    */
    34   open: function() {
    35     let targetPromise;
    37     // Local monitoring needs to make the target remote.
    38     if (!this.target.isRemote) {
    39       targetPromise = this.target.makeRemote();
    40     } else {
    41       targetPromise = promise.resolve(this.target);
    42     }
    44     return targetPromise
    45       .then(() => this._controller.startupNetMonitor())
    46       .then(() => this._controller.connect())
    47       .then(() => {
    48         this.isReady = true;
    49         this.emit("ready");
    50         return this;
    51       })
    52       .then(null, function onError(aReason) {
    53         DevToolsUtils.reportException("NetMonitorPanel.prototype.open", aReason);
    54       });
    55   },
    57   // DevToolPanel API
    59   get target() this._toolbox.target,
    61   destroy: function() {
    62     // Make sure this panel is not already destroyed.
    63     if (this._destroyer) {
    64       return this._destroyer;
    65     }
    67     return this._destroyer = this._controller.shutdownNetMonitor().then(() => {
    68       this.emit("destroyed");
    69     });
    70   }
    71 };

mercurial