1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/shadereditor/panel.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 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 = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; 1.13 +const EventEmitter = require("devtools/toolkit/event-emitter"); 1.14 +const { WebGLFront } = require("devtools/server/actors/webgl"); 1.15 +const { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {}); 1.16 + 1.17 +function ShaderEditorPanel(iframeWindow, toolbox) { 1.18 + this.panelWin = iframeWindow; 1.19 + this._toolbox = toolbox; 1.20 + this._destroyer = null; 1.21 + 1.22 + EventEmitter.decorate(this); 1.23 +}; 1.24 + 1.25 +exports.ShaderEditorPanel = ShaderEditorPanel; 1.26 + 1.27 +ShaderEditorPanel.prototype = { 1.28 + /** 1.29 + * Open is effectively an asynchronous constructor. 1.30 + * 1.31 + * @return object 1.32 + * A promise that is resolved when the Shader Editor completes opening. 1.33 + */ 1.34 + open: function() { 1.35 + let targetPromise; 1.36 + 1.37 + // Local debugging needs to make the target remote. 1.38 + if (!this.target.isRemote) { 1.39 + targetPromise = this.target.makeRemote(); 1.40 + } else { 1.41 + targetPromise = promise.resolve(this.target); 1.42 + } 1.43 + 1.44 + return targetPromise 1.45 + .then(() => { 1.46 + this.panelWin.gToolbox = this._toolbox; 1.47 + this.panelWin.gTarget = this.target; 1.48 + this.panelWin.gFront = new WebGLFront(this.target.client, this.target.form); 1.49 + return this.panelWin.startupShaderEditor(); 1.50 + }) 1.51 + .then(() => { 1.52 + this.isReady = true; 1.53 + this.emit("ready"); 1.54 + return this; 1.55 + }) 1.56 + .then(null, function onError(aReason) { 1.57 + DevToolsUtils.reportException("ShaderEditorPanel.prototype.open", aReason); 1.58 + }); 1.59 + }, 1.60 + 1.61 + // DevToolPanel API 1.62 + 1.63 + get target() this._toolbox.target, 1.64 + 1.65 + destroy: function() { 1.66 + // Make sure this panel is not already destroyed. 1.67 + if (this._destroyer) { 1.68 + return this._destroyer; 1.69 + } 1.70 + 1.71 + return this._destroyer = this.panelWin.shutdownShaderEditor().then(() => { 1.72 + this.emit("destroyed"); 1.73 + }); 1.74 + } 1.75 +};