panel.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. const promise = require("promise");
  7. const EventEmitter = require("devtools/shared/event-emitter");
  8. const { Task } = require("devtools/shared/task");
  9. const { localizeMarkup } = require("devtools/shared/l10n");
  10. function NetMonitorPanel(iframeWindow, toolbox) {
  11. this.panelWin = iframeWindow;
  12. this.panelDoc = iframeWindow.document;
  13. this._toolbox = toolbox;
  14. this._view = this.panelWin.NetMonitorView;
  15. this._controller = this.panelWin.NetMonitorController;
  16. this._controller._target = this.target;
  17. this._controller._toolbox = this._toolbox;
  18. EventEmitter.decorate(this);
  19. }
  20. exports.NetMonitorPanel = NetMonitorPanel;
  21. NetMonitorPanel.prototype = {
  22. /**
  23. * Open is effectively an asynchronous constructor.
  24. *
  25. * @return object
  26. * A promise that is resolved when the NetMonitor completes opening.
  27. */
  28. open: Task.async(function* () {
  29. if (this._opening) {
  30. return this._opening;
  31. }
  32. // Localize all the nodes containing a data-localization attribute.
  33. localizeMarkup(this.panelDoc);
  34. let deferred = promise.defer();
  35. this._opening = deferred.promise;
  36. // Local monitoring needs to make the target remote.
  37. if (!this.target.isRemote) {
  38. yield this.target.makeRemote();
  39. }
  40. yield this._controller.startupNetMonitor();
  41. this.isReady = true;
  42. this.emit("ready");
  43. deferred.resolve(this);
  44. return this._opening;
  45. }),
  46. // DevToolPanel API
  47. get target() {
  48. return this._toolbox.target;
  49. },
  50. destroy: Task.async(function* () {
  51. if (this._destroying) {
  52. return this._destroying;
  53. }
  54. let deferred = promise.defer();
  55. this._destroying = deferred.promise;
  56. yield this._controller.shutdownNetMonitor();
  57. this.emit("destroyed");
  58. deferred.resolve();
  59. return this._destroying;
  60. })
  61. };