1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/panel.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 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 { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {}); 1.13 +const EventEmitter = require("devtools/toolkit/event-emitter"); 1.14 +const { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {}); 1.15 + 1.16 +function DebuggerPanel(iframeWindow, toolbox) { 1.17 + this.panelWin = iframeWindow; 1.18 + this._toolbox = toolbox; 1.19 + this._destroyer = null; 1.20 + 1.21 + this._view = this.panelWin.DebuggerView; 1.22 + this._controller = this.panelWin.DebuggerController; 1.23 + this._view._hostType = this._toolbox.hostType; 1.24 + this._controller._target = this.target; 1.25 + this._controller._toolbox = this._toolbox; 1.26 + 1.27 + this.handleHostChanged = this.handleHostChanged.bind(this); 1.28 + this.highlightWhenPaused = this.highlightWhenPaused.bind(this); 1.29 + this.unhighlightWhenResumed = this.unhighlightWhenResumed.bind(this); 1.30 + 1.31 + EventEmitter.decorate(this); 1.32 +}; 1.33 + 1.34 +exports.DebuggerPanel = DebuggerPanel; 1.35 + 1.36 +DebuggerPanel.prototype = { 1.37 + /** 1.38 + * Open is effectively an asynchronous constructor. 1.39 + * 1.40 + * @return object 1.41 + * A promise that is resolved when the Debugger completes opening. 1.42 + */ 1.43 + open: function() { 1.44 + let targetPromise; 1.45 + 1.46 + // Local debugging needs to make the target remote. 1.47 + if (!this.target.isRemote) { 1.48 + targetPromise = this.target.makeRemote(); 1.49 + } else { 1.50 + targetPromise = promise.resolve(this.target); 1.51 + } 1.52 + 1.53 + return targetPromise 1.54 + .then(() => this._controller.startupDebugger()) 1.55 + .then(() => this._controller.connect()) 1.56 + .then(() => { 1.57 + this._toolbox.on("host-changed", this.handleHostChanged); 1.58 + this.target.on("thread-paused", this.highlightWhenPaused); 1.59 + this.target.on("thread-resumed", this.unhighlightWhenResumed); 1.60 + this.isReady = true; 1.61 + this.emit("ready"); 1.62 + return this; 1.63 + }) 1.64 + .then(null, function onError(aReason) { 1.65 + DevToolsUtils.reportException("DebuggerPanel.prototype.open", aReason); 1.66 + }); 1.67 + }, 1.68 + 1.69 + // DevToolPanel API 1.70 + 1.71 + get target() this._toolbox.target, 1.72 + 1.73 + destroy: function() { 1.74 + // Make sure this panel is not already destroyed. 1.75 + if (this._destroyer) { 1.76 + return this._destroyer; 1.77 + } 1.78 + 1.79 + this.target.off("thread-paused", this.highlightWhenPaused); 1.80 + this.target.off("thread-resumed", this.unhighlightWhenResumed); 1.81 + 1.82 + return this._destroyer = this._controller.shutdownDebugger().then(() => { 1.83 + this.emit("destroyed"); 1.84 + }); 1.85 + }, 1.86 + 1.87 + // DebuggerPanel API 1.88 + 1.89 + addBreakpoint: function(aLocation, aOptions) { 1.90 + return this._controller.Breakpoints.addBreakpoint(aLocation, aOptions); 1.91 + }, 1.92 + 1.93 + removeBreakpoint: function(aLocation) { 1.94 + return this._controller.Breakpoints.removeBreakpoint(aLocation); 1.95 + }, 1.96 + 1.97 + handleHostChanged: function() { 1.98 + this._view.handleHostChanged(this._toolbox.hostType); 1.99 + }, 1.100 + 1.101 + highlightWhenPaused: function() { 1.102 + this._toolbox.highlightTool("jsdebugger"); 1.103 + 1.104 + // Also raise the toolbox window if it is undocked or select the 1.105 + // corresponding tab when toolbox is docked. 1.106 + this._toolbox.raise(); 1.107 + }, 1.108 + 1.109 + unhighlightWhenResumed: function() { 1.110 + this._toolbox.unhighlightTool("jsdebugger"); 1.111 + } 1.112 +};