зеркало из https://github.com/mozilla/gecko-dev.git
Bug 857082 - TabTarget.makeRemote doesn't need any arguments; r=jwalker
This commit is contained in:
Родитель
9fb1c3fe69
Коммит
d3fd6fde90
|
@ -19,6 +19,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "DebuggerClient",
|
|||
"resource://gre/modules/devtools/dbg-client.jsm");
|
||||
|
||||
const targets = new WeakMap();
|
||||
const promiseTargets = new WeakMap();
|
||||
|
||||
/**
|
||||
* Functions for creating Targets
|
||||
|
@ -26,9 +27,8 @@ const targets = new WeakMap();
|
|||
this.TargetFactory = {
|
||||
/**
|
||||
* Construct a Target
|
||||
* @param {XULTab} | {Object} tab
|
||||
* The tab to use in creating a new target, or an options object in
|
||||
* case of remote targets.
|
||||
* @param {XULTab} tab
|
||||
* The tab to use in creating a new target.
|
||||
*
|
||||
* @return A target object
|
||||
*/
|
||||
|
@ -41,6 +41,28 @@ this.TargetFactory = {
|
|||
return target;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return a promise of a Target for a remote tab.
|
||||
* @param {Object} options
|
||||
* The options object has the following properties:
|
||||
* {
|
||||
* form: the remote protocol form of a tab,
|
||||
* client: a DebuggerClient instance,
|
||||
* chrome: true if the remote target is the whole process
|
||||
* }
|
||||
*
|
||||
* @return A promise of a target object
|
||||
*/
|
||||
forRemoteTab: function TF_forRemoteTab(options) {
|
||||
let promise = promiseTargets.get(options);
|
||||
if (promise == null) {
|
||||
let target = new TabTarget(options);
|
||||
promise = target.makeRemote().then(() => target);
|
||||
promiseTargets.set(options, promise);
|
||||
}
|
||||
return promise;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creating a target for a tab that is being closed is a problem because it
|
||||
* allows a leak as a result of coming after the close event which normally
|
||||
|
@ -167,6 +189,10 @@ function TabTarget(tab) {
|
|||
if (tab && !["client", "form", "chrome"].every(tab.hasOwnProperty, tab)) {
|
||||
this._tab = tab;
|
||||
this._setupListeners();
|
||||
} else {
|
||||
this._form = tab.form;
|
||||
this._client = tab.client;
|
||||
this._chrome = tab.chrome;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,23 +252,15 @@ TabTarget.prototype = {
|
|||
* Adds remote protocol capabilities to the target, so that it can be used
|
||||
* for tools that support the Remote Debugging Protocol even for local
|
||||
* connections.
|
||||
*
|
||||
* @param object aOptions
|
||||
* An optional object containing remote connection options that is
|
||||
* supplied when connecting to another instance.
|
||||
*/
|
||||
makeRemote: function TabTarget_makeRemote(aOptions) {
|
||||
makeRemote: function TabTarget_makeRemote() {
|
||||
if (this._remote) {
|
||||
return this._remote.promise;
|
||||
}
|
||||
|
||||
this._remote = Promise.defer();
|
||||
|
||||
if (aOptions) {
|
||||
this._form = aOptions.form;
|
||||
this._client = aOptions.client;
|
||||
this._chrome = aOptions.chrome;
|
||||
} else {
|
||||
if (this.isLocalTab) {
|
||||
// Since a remote protocol connection will be made, let's start the
|
||||
// DebuggerServer here, once and for all tools.
|
||||
if (!DebuggerServer.initialized) {
|
||||
|
@ -257,7 +275,7 @@ TabTarget.prototype = {
|
|||
|
||||
this._setupRemoteListeners();
|
||||
|
||||
if (aOptions) {
|
||||
if (this.isRemote) {
|
||||
// In the remote debugging case, the protocol connection will have been
|
||||
// already initialized in the connection screen code.
|
||||
this._remote.resolve(null);
|
||||
|
@ -372,7 +390,6 @@ TabTarget.prototype = {
|
|||
|
||||
// If this target was not remoted, the promise will be resolved before the
|
||||
// function returns.
|
||||
// if (!this._remote) {
|
||||
if (this._tab && !this._client) {
|
||||
targets.delete(this._tab);
|
||||
this._tab = null;
|
||||
|
@ -388,8 +405,11 @@ TabTarget.prototype = {
|
|||
this.client.removeListener("tabDetached", this.destroy);
|
||||
|
||||
this._client.close(function onClosed() {
|
||||
let key = this._tab ? this._tab : this._form;
|
||||
targets.delete(key);
|
||||
if (this._tab) {
|
||||
targets.delete(this._tab);
|
||||
} else {
|
||||
promiseTargets.delete(this._form);
|
||||
}
|
||||
this._client = null;
|
||||
this._tab = null;
|
||||
this._form = null;
|
||||
|
|
|
@ -169,8 +169,7 @@ function openToolbox(form, chrome=false) {
|
|||
client: gClient,
|
||||
chrome: chrome
|
||||
};
|
||||
let target = TargetFactory.forTab(options);
|
||||
target.makeRemote(options).then(function() {
|
||||
TargetFactory.forRemoteTab(options).then((target) => {
|
||||
gDevTools.showToolbox(target, "webconsole", Toolbox.HostType.WINDOW);
|
||||
window.close();
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче