browser/devtools/canvasdebugger/panel.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:2563af8a6b9d
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 promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
10 const EventEmitter = require("devtools/toolkit/event-emitter");
11 const { CanvasFront } = require("devtools/server/actors/canvas");
12 const { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {});
13
14 function CanvasDebuggerPanel(iframeWindow, toolbox) {
15 this.panelWin = iframeWindow;
16 this._toolbox = toolbox;
17 this._destroyer = null;
18
19 EventEmitter.decorate(this);
20 };
21
22 exports.CanvasDebuggerPanel = CanvasDebuggerPanel;
23
24 CanvasDebuggerPanel.prototype = {
25 /**
26 * Open is effectively an asynchronous constructor.
27 *
28 * @return object
29 * A promise that is resolved when the Canvas Debugger completes opening.
30 */
31 open: function() {
32 let targetPromise;
33
34 // Local debugging needs to make the target remote.
35 if (!this.target.isRemote) {
36 targetPromise = this.target.makeRemote();
37 } else {
38 targetPromise = promise.resolve(this.target);
39 }
40
41 return targetPromise
42 .then(() => {
43 this.panelWin.gToolbox = this._toolbox;
44 this.panelWin.gTarget = this.target;
45 this.panelWin.gFront = new CanvasFront(this.target.client, this.target.form);
46 return this.panelWin.startupCanvasDebugger();
47 })
48 .then(() => {
49 this.isReady = true;
50 this.emit("ready");
51 return this;
52 })
53 .then(null, function onError(aReason) {
54 DevToolsUtils.reportException("CanvasDebuggerPanel.prototype.open", aReason);
55 });
56 },
57
58 // DevToolPanel API
59
60 get target() this._toolbox.target,
61
62 destroy: function() {
63 // Make sure this panel is not already destroyed.
64 if (this._destroyer) {
65 return this._destroyer;
66 }
67
68 return this._destroyer = this.panelWin.shutdownCanvasDebugger().then(() => {
69 this.emit("destroyed");
70 });
71 }
72 };

mercurial