browser/devtools/debugger/panel.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial