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