Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | "use strict"; |
michael@0 | 7 | |
michael@0 | 8 | const { Cc, Ci, Cu, Cr } = require("chrome"); |
michael@0 | 9 | const promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; |
michael@0 | 10 | const EventEmitter = require("devtools/toolkit/event-emitter"); |
michael@0 | 11 | const { CanvasFront } = require("devtools/server/actors/canvas"); |
michael@0 | 12 | const { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {}); |
michael@0 | 13 | |
michael@0 | 14 | function CanvasDebuggerPanel(iframeWindow, toolbox) { |
michael@0 | 15 | this.panelWin = iframeWindow; |
michael@0 | 16 | this._toolbox = toolbox; |
michael@0 | 17 | this._destroyer = null; |
michael@0 | 18 | |
michael@0 | 19 | EventEmitter.decorate(this); |
michael@0 | 20 | }; |
michael@0 | 21 | |
michael@0 | 22 | exports.CanvasDebuggerPanel = CanvasDebuggerPanel; |
michael@0 | 23 | |
michael@0 | 24 | CanvasDebuggerPanel.prototype = { |
michael@0 | 25 | /** |
michael@0 | 26 | * Open is effectively an asynchronous constructor. |
michael@0 | 27 | * |
michael@0 | 28 | * @return object |
michael@0 | 29 | * A promise that is resolved when the Canvas Debugger completes opening. |
michael@0 | 30 | */ |
michael@0 | 31 | open: function() { |
michael@0 | 32 | let targetPromise; |
michael@0 | 33 | |
michael@0 | 34 | // Local debugging needs to make the target remote. |
michael@0 | 35 | if (!this.target.isRemote) { |
michael@0 | 36 | targetPromise = this.target.makeRemote(); |
michael@0 | 37 | } else { |
michael@0 | 38 | targetPromise = promise.resolve(this.target); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | return targetPromise |
michael@0 | 42 | .then(() => { |
michael@0 | 43 | this.panelWin.gToolbox = this._toolbox; |
michael@0 | 44 | this.panelWin.gTarget = this.target; |
michael@0 | 45 | this.panelWin.gFront = new CanvasFront(this.target.client, this.target.form); |
michael@0 | 46 | return this.panelWin.startupCanvasDebugger(); |
michael@0 | 47 | }) |
michael@0 | 48 | .then(() => { |
michael@0 | 49 | this.isReady = true; |
michael@0 | 50 | this.emit("ready"); |
michael@0 | 51 | return this; |
michael@0 | 52 | }) |
michael@0 | 53 | .then(null, function onError(aReason) { |
michael@0 | 54 | DevToolsUtils.reportException("CanvasDebuggerPanel.prototype.open", aReason); |
michael@0 | 55 | }); |
michael@0 | 56 | }, |
michael@0 | 57 | |
michael@0 | 58 | // DevToolPanel API |
michael@0 | 59 | |
michael@0 | 60 | get target() this._toolbox.target, |
michael@0 | 61 | |
michael@0 | 62 | destroy: function() { |
michael@0 | 63 | // Make sure this panel is not already destroyed. |
michael@0 | 64 | if (this._destroyer) { |
michael@0 | 65 | return this._destroyer; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | return this._destroyer = this.panelWin.shutdownCanvasDebugger().then(() => { |
michael@0 | 69 | this.emit("destroyed"); |
michael@0 | 70 | }); |
michael@0 | 71 | } |
michael@0 | 72 | }; |