panel.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 { Cc, Ci, Cu, Cr } = require("chrome");
  7. const EventEmitter = require("devtools/shared/event-emitter");
  8. const { WebAudioFront } = require("devtools/shared/fronts/webaudio");
  9. var Promise = require("promise");
  10. function WebAudioEditorPanel(iframeWindow, toolbox) {
  11. this.panelWin = iframeWindow;
  12. this._toolbox = toolbox;
  13. this._destroyer = null;
  14. EventEmitter.decorate(this);
  15. }
  16. exports.WebAudioEditorPanel = WebAudioEditorPanel;
  17. WebAudioEditorPanel.prototype = {
  18. open: function () {
  19. let targetPromise;
  20. // Local debugging needs to make the target remote.
  21. if (!this.target.isRemote) {
  22. targetPromise = this.target.makeRemote();
  23. } else {
  24. targetPromise = Promise.resolve(this.target);
  25. }
  26. return targetPromise
  27. .then(() => {
  28. this.panelWin.gToolbox = this._toolbox;
  29. this.panelWin.gTarget = this.target;
  30. this.panelWin.gFront = new WebAudioFront(this.target.client, this.target.form);
  31. return this.panelWin.startupWebAudioEditor();
  32. })
  33. .then(() => {
  34. this.isReady = true;
  35. this.emit("ready");
  36. return this;
  37. })
  38. .then(null, function onError(aReason) {
  39. console.error("WebAudioEditorPanel open failed. " +
  40. aReason.error + ": " + aReason.message);
  41. });
  42. },
  43. // DevToolPanel API
  44. get target() {
  45. return this._toolbox.target;
  46. },
  47. destroy: function () {
  48. // Make sure this panel is not already destroyed.
  49. if (this._destroyer) {
  50. return this._destroyer;
  51. }
  52. return this._destroyer = this.panelWin.shutdownWebAudioEditor().then(() => {
  53. // Destroy front to ensure packet handler is removed from client
  54. this.panelWin.gFront.destroy();
  55. this.emit("destroyed");
  56. });
  57. }
  58. };