panel.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 promise = require("promise");
  8. const EventEmitter = require("devtools/shared/event-emitter");
  9. const { WebGLFront } = require("devtools/shared/fronts/webgl");
  10. const DevToolsUtils = require("devtools/shared/DevToolsUtils");
  11. function ShaderEditorPanel(iframeWindow, toolbox) {
  12. this.panelWin = iframeWindow;
  13. this._toolbox = toolbox;
  14. this._destroyer = null;
  15. EventEmitter.decorate(this);
  16. }
  17. exports.ShaderEditorPanel = ShaderEditorPanel;
  18. ShaderEditorPanel.prototype = {
  19. /**
  20. * Open is effectively an asynchronous constructor.
  21. *
  22. * @return object
  23. * A promise that is resolved when the Shader Editor completes opening.
  24. */
  25. open: function () {
  26. let targetPromise;
  27. // Local debugging needs to make the target remote.
  28. if (!this.target.isRemote) {
  29. targetPromise = this.target.makeRemote();
  30. } else {
  31. targetPromise = promise.resolve(this.target);
  32. }
  33. return targetPromise
  34. .then(() => {
  35. this.panelWin.gToolbox = this._toolbox;
  36. this.panelWin.gTarget = this.target;
  37. this.panelWin.gFront = new WebGLFront(this.target.client, this.target.form);
  38. return this.panelWin.startupShaderEditor();
  39. })
  40. .then(() => {
  41. this.isReady = true;
  42. this.emit("ready");
  43. return this;
  44. })
  45. .then(null, function onError(aReason) {
  46. DevToolsUtils.reportException("ShaderEditorPanel.prototype.open", aReason);
  47. });
  48. },
  49. // DevToolPanel API
  50. get target() {
  51. return this._toolbox.target;
  52. },
  53. destroy: function () {
  54. // Make sure this panel is not already destroyed.
  55. if (this._destroyer) {
  56. return this._destroyer;
  57. }
  58. return this._destroyer = this.panelWin.shutdownShaderEditor().then(() => {
  59. // Destroy front to ensure packet handler is removed from client
  60. this.panelWin.gFront.destroy();
  61. this.emit("destroyed");
  62. });
  63. }
  64. };