1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/webapprt/content/dbg-webapp-actors.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,126 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +'use strict'; 1.9 + 1.10 +const { Promise } = Cu.import("resource://gre/modules/Promise.jsm", {}); 1.11 + 1.12 +/** 1.13 + * WebappRT-specific actors. 1.14 + */ 1.15 + 1.16 +/** 1.17 + * Construct a root actor appropriate for use in a server running in the webapp 1.18 + * runtime. The returned root actor: 1.19 + * - respects the factories registered with DebuggerServer.addGlobalActor, 1.20 + * - uses a WebappTabList to supply tab actors, 1.21 + * - sends all webapprt:webapp window documents a Debugger:Shutdown event 1.22 + * when it exits. 1.23 + * 1.24 + * * @param connection DebuggerServerConnection 1.25 + * The conection to the client. 1.26 + */ 1.27 +function createRootActor(connection) 1.28 +{ 1.29 + let parameters = { 1.30 + tabList: new WebappTabList(connection), 1.31 + globalActorFactories: DebuggerServer.globalActorFactories, 1.32 + onShutdown: sendShutdownEvent 1.33 + }; 1.34 + return new RootActor(connection, parameters); 1.35 +} 1.36 + 1.37 +/** 1.38 + * A live list of BrowserTabActors representing the current webapp windows, 1.39 + * to be provided to the root actor to answer 'listTabs' requests. In the 1.40 + * webapp runtime, only a single tab per window is ever present. 1.41 + * 1.42 + * @param connection DebuggerServerConnection 1.43 + * The connection in which this list's tab actors may participate. 1.44 + * 1.45 + * @see BrowserTabList for more a extensive description of how tab list objects 1.46 + * work. 1.47 + */ 1.48 +function WebappTabList(connection) 1.49 +{ 1.50 + BrowserTabList.call(this, connection); 1.51 +} 1.52 + 1.53 +WebappTabList.prototype = Object.create(BrowserTabList.prototype); 1.54 + 1.55 +WebappTabList.prototype.constructor = WebappTabList; 1.56 + 1.57 +WebappTabList.prototype.getList = function() { 1.58 + let topXULWindow = Services.wm.getMostRecentWindow(this._windowType); 1.59 + 1.60 + // As a sanity check, make sure all the actors presently in our map get 1.61 + // picked up when we iterate over all windows. 1.62 + let initialMapSize = this._actorByBrowser.size; 1.63 + let foundCount = 0; 1.64 + 1.65 + // To avoid mysterious behavior if windows are closed or opened mid-iteration, 1.66 + // we update the map first, and then make a second pass over it to yield 1.67 + // the actors. Thus, the sequence yielded is always a snapshot of the 1.68 + // actors that were live when we began the iteration. 1.69 + 1.70 + // Iterate over all webapprt:webapp XUL windows. 1.71 + for (let win of allAppShellDOMWindows(this._windowType)) { 1.72 + let browser = win.document.getElementById("content"); 1.73 + if (!browser) { 1.74 + continue; 1.75 + } 1.76 + 1.77 + // Do we have an existing actor for this browser? If not, create one. 1.78 + let actor = this._actorByBrowser.get(browser); 1.79 + if (actor) { 1.80 + foundCount++; 1.81 + } else { 1.82 + actor = new WebappTabActor(this._connection, browser); 1.83 + this._actorByBrowser.set(browser, actor); 1.84 + } 1.85 + 1.86 + actor.selected = (win == topXULWindow); 1.87 + } 1.88 + 1.89 + if (this._testing && initialMapSize !== foundCount) { 1.90 + throw Error("_actorByBrowser map contained actors for dead tabs"); 1.91 + } 1.92 + 1.93 + this._mustNotify = true; 1.94 + this._checkListening(); 1.95 + 1.96 + return Promise.resolve([actor for ([_, actor] of this._actorByBrowser)]); 1.97 +}; 1.98 + 1.99 +/** 1.100 + * Creates a tab actor for handling requests to the single tab, like 1.101 + * attaching and detaching. WebappTabActor respects the actor factories 1.102 + * registered with DebuggerServer.addTabActor. 1.103 + * 1.104 + * We override the title of the XUL window in content/webapp.js so here 1.105 + * we need to override the title property to avoid confusion to the user. 1.106 + * We won't return the title of the contained browser, but the title of 1.107 + * the webapp window. 1.108 + * 1.109 + * @param connection DebuggerServerConnection 1.110 + * The conection to the client. 1.111 + * @param browser browser 1.112 + * The browser instance that contains this tab. 1.113 + */ 1.114 +function WebappTabActor(connection, browser) 1.115 +{ 1.116 + BrowserTabActor.call(this, connection, browser); 1.117 +} 1.118 + 1.119 +WebappTabActor.prototype.constructor = WebappTabActor; 1.120 + 1.121 +WebappTabActor.prototype = Object.create(BrowserTabActor.prototype); 1.122 + 1.123 +Object.defineProperty(WebappTabActor.prototype, "title", { 1.124 + get: function() { 1.125 + return this.browser.ownerDocument.defaultView.document.title; 1.126 + }, 1.127 + enumerable: true, 1.128 + configurable: false 1.129 +});