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: promise } = Cu.import("resource://gre/modules/Promise.jsm", {}); |
michael@0 | 10 | const EventEmitter = require("devtools/toolkit/event-emitter"); |
michael@0 | 11 | const { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {}); |
michael@0 | 12 | |
michael@0 | 13 | function DebuggerPanel(iframeWindow, toolbox) { |
michael@0 | 14 | this.panelWin = iframeWindow; |
michael@0 | 15 | this._toolbox = toolbox; |
michael@0 | 16 | this._destroyer = null; |
michael@0 | 17 | |
michael@0 | 18 | this._view = this.panelWin.DebuggerView; |
michael@0 | 19 | this._controller = this.panelWin.DebuggerController; |
michael@0 | 20 | this._view._hostType = this._toolbox.hostType; |
michael@0 | 21 | this._controller._target = this.target; |
michael@0 | 22 | this._controller._toolbox = this._toolbox; |
michael@0 | 23 | |
michael@0 | 24 | this.handleHostChanged = this.handleHostChanged.bind(this); |
michael@0 | 25 | this.highlightWhenPaused = this.highlightWhenPaused.bind(this); |
michael@0 | 26 | this.unhighlightWhenResumed = this.unhighlightWhenResumed.bind(this); |
michael@0 | 27 | |
michael@0 | 28 | EventEmitter.decorate(this); |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | exports.DebuggerPanel = DebuggerPanel; |
michael@0 | 32 | |
michael@0 | 33 | DebuggerPanel.prototype = { |
michael@0 | 34 | /** |
michael@0 | 35 | * Open is effectively an asynchronous constructor. |
michael@0 | 36 | * |
michael@0 | 37 | * @return object |
michael@0 | 38 | * A promise that is resolved when the Debugger completes opening. |
michael@0 | 39 | */ |
michael@0 | 40 | open: function() { |
michael@0 | 41 | let targetPromise; |
michael@0 | 42 | |
michael@0 | 43 | // Local debugging needs to make the target remote. |
michael@0 | 44 | if (!this.target.isRemote) { |
michael@0 | 45 | targetPromise = this.target.makeRemote(); |
michael@0 | 46 | } else { |
michael@0 | 47 | targetPromise = promise.resolve(this.target); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | return targetPromise |
michael@0 | 51 | .then(() => this._controller.startupDebugger()) |
michael@0 | 52 | .then(() => this._controller.connect()) |
michael@0 | 53 | .then(() => { |
michael@0 | 54 | this._toolbox.on("host-changed", this.handleHostChanged); |
michael@0 | 55 | this.target.on("thread-paused", this.highlightWhenPaused); |
michael@0 | 56 | this.target.on("thread-resumed", this.unhighlightWhenResumed); |
michael@0 | 57 | this.isReady = true; |
michael@0 | 58 | this.emit("ready"); |
michael@0 | 59 | return this; |
michael@0 | 60 | }) |
michael@0 | 61 | .then(null, function onError(aReason) { |
michael@0 | 62 | DevToolsUtils.reportException("DebuggerPanel.prototype.open", aReason); |
michael@0 | 63 | }); |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | // DevToolPanel API |
michael@0 | 67 | |
michael@0 | 68 | get target() this._toolbox.target, |
michael@0 | 69 | |
michael@0 | 70 | destroy: function() { |
michael@0 | 71 | // Make sure this panel is not already destroyed. |
michael@0 | 72 | if (this._destroyer) { |
michael@0 | 73 | return this._destroyer; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | this.target.off("thread-paused", this.highlightWhenPaused); |
michael@0 | 77 | this.target.off("thread-resumed", this.unhighlightWhenResumed); |
michael@0 | 78 | |
michael@0 | 79 | return this._destroyer = this._controller.shutdownDebugger().then(() => { |
michael@0 | 80 | this.emit("destroyed"); |
michael@0 | 81 | }); |
michael@0 | 82 | }, |
michael@0 | 83 | |
michael@0 | 84 | // DebuggerPanel API |
michael@0 | 85 | |
michael@0 | 86 | addBreakpoint: function(aLocation, aOptions) { |
michael@0 | 87 | return this._controller.Breakpoints.addBreakpoint(aLocation, aOptions); |
michael@0 | 88 | }, |
michael@0 | 89 | |
michael@0 | 90 | removeBreakpoint: function(aLocation) { |
michael@0 | 91 | return this._controller.Breakpoints.removeBreakpoint(aLocation); |
michael@0 | 92 | }, |
michael@0 | 93 | |
michael@0 | 94 | handleHostChanged: function() { |
michael@0 | 95 | this._view.handleHostChanged(this._toolbox.hostType); |
michael@0 | 96 | }, |
michael@0 | 97 | |
michael@0 | 98 | highlightWhenPaused: function() { |
michael@0 | 99 | this._toolbox.highlightTool("jsdebugger"); |
michael@0 | 100 | |
michael@0 | 101 | // Also raise the toolbox window if it is undocked or select the |
michael@0 | 102 | // corresponding tab when toolbox is docked. |
michael@0 | 103 | this._toolbox.raise(); |
michael@0 | 104 | }, |
michael@0 | 105 | |
michael@0 | 106 | unhighlightWhenResumed: function() { |
michael@0 | 107 | this._toolbox.unhighlightTool("jsdebugger"); |
michael@0 | 108 | } |
michael@0 | 109 | }; |