|
1 /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 "use strict"; |
|
7 |
|
8 const { Cc, Ci, Cu, Cr } = require("chrome"); |
|
9 const EventEmitter = require("devtools/toolkit/event-emitter"); |
|
10 const { WebAudioFront } = require("devtools/server/actors/webaudio"); |
|
11 let Promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; |
|
12 |
|
13 function WebAudioEditorPanel (iframeWindow, toolbox) { |
|
14 this.panelWin = iframeWindow; |
|
15 this._toolbox = toolbox; |
|
16 this._destroyer = null; |
|
17 |
|
18 EventEmitter.decorate(this); |
|
19 } |
|
20 |
|
21 exports.WebAudioEditorPanel = WebAudioEditorPanel; |
|
22 |
|
23 WebAudioEditorPanel.prototype = { |
|
24 open: function() { |
|
25 let targetPromise; |
|
26 |
|
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 |
|
34 return targetPromise |
|
35 .then(() => { |
|
36 this.panelWin.gToolbox = this._toolbox; |
|
37 this.panelWin.gTarget = this.target; |
|
38 this.panelWin.gFront = new WebAudioFront(this.target.client, this.target.form); |
|
39 return this.panelWin.startupWebAudioEditor(); |
|
40 }) |
|
41 .then(() => { |
|
42 this.isReady = true; |
|
43 this.emit("ready"); |
|
44 return this; |
|
45 }) |
|
46 .then(null, function onError(aReason) { |
|
47 Cu.reportError("WebAudioEditorPanel open failed. " + |
|
48 aReason.error + ": " + aReason.message); |
|
49 }); |
|
50 }, |
|
51 |
|
52 // DevToolPanel API |
|
53 |
|
54 get target() this._toolbox.target, |
|
55 |
|
56 destroy: function() { |
|
57 // Make sure this panel is not already destroyed. |
|
58 if (this._destroyer) { |
|
59 return this._destroyer; |
|
60 } |
|
61 |
|
62 return this._destroyer = this.panelWin.shutdownWebAudioEditor().then(() => { |
|
63 this.emit("destroyed"); |
|
64 }); |
|
65 } |
|
66 }; |