2016-01-25 22:19:58 +03:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2016-02-24 21:16:16 +03:00
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
2012-09-26 21:07:57 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2015-09-21 20:04:18 +03:00
|
|
|
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
|
|
|
const EventEmitter = require("devtools/shared/event-emitter");
|
2015-06-17 17:27:20 +03:00
|
|
|
const promise = require("promise");
|
2016-06-09 18:03:47 +03:00
|
|
|
const defer = require("devtools/shared/defer");
|
2015-09-21 20:04:18 +03:00
|
|
|
const {LongStringClient} = require("devtools/shared/client/main");
|
2012-09-26 21:07:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A WebConsoleClient is used as a front end for the WebConsoleActor that is
|
|
|
|
* created on the server, hiding implementation details.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param object debuggerClient
|
2012-09-26 21:07:57 +04:00
|
|
|
* The DebuggerClient instance we live for.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param object response
|
2014-03-10 22:57:27 +04:00
|
|
|
* The response packet received from the "startListeners" request sent to
|
|
|
|
* the WebConsoleActor.
|
2012-09-26 21:07:57 +04:00
|
|
|
*/
|
2016-03-16 10:16:00 +03:00
|
|
|
function WebConsoleClient(debuggerClient, response) {
|
|
|
|
this._actor = response.from;
|
|
|
|
this._client = debuggerClient;
|
2012-11-05 20:41:59 +04:00
|
|
|
this._longStrings = {};
|
2016-03-16 10:16:00 +03:00
|
|
|
this.traits = response.traits || {};
|
2014-07-07 17:40:00 +04:00
|
|
|
this.events = [];
|
2015-04-24 21:38:09 +03:00
|
|
|
this._networkRequests = new Map();
|
2014-12-17 04:18:26 +03:00
|
|
|
|
|
|
|
this.pendingEvaluationResults = new Map();
|
|
|
|
this.onEvaluationResult = this.onEvaluationResult.bind(this);
|
2015-04-24 21:38:09 +03:00
|
|
|
this.onNetworkEvent = this._onNetworkEvent.bind(this);
|
|
|
|
this.onNetworkEventUpdate = this._onNetworkEventUpdate.bind(this);
|
2014-12-17 04:18:26 +03:00
|
|
|
|
|
|
|
this._client.addListener("evaluationResult", this.onEvaluationResult);
|
2015-04-24 21:38:09 +03:00
|
|
|
this._client.addListener("networkEvent", this.onNetworkEvent);
|
|
|
|
this._client.addListener("networkEventUpdate", this.onNetworkEventUpdate);
|
|
|
|
EventEmitter.decorate(this);
|
2012-09-26 21:07:57 +04:00
|
|
|
}
|
2014-12-17 04:18:26 +03:00
|
|
|
|
2013-08-03 14:29:48 +04:00
|
|
|
exports.WebConsoleClient = WebConsoleClient;
|
2012-09-26 21:07:57 +04:00
|
|
|
|
|
|
|
WebConsoleClient.prototype = {
|
2012-11-05 20:41:59 +04:00
|
|
|
_longStrings: null,
|
2014-03-10 22:57:27 +04:00
|
|
|
traits: null,
|
2012-11-05 20:41:59 +04:00
|
|
|
|
2015-04-24 21:38:09 +03:00
|
|
|
/**
|
|
|
|
* Holds the network requests currently displayed by the Web Console. Each key
|
|
|
|
* represents the connection ID and the value is network request information.
|
|
|
|
* @private
|
|
|
|
* @type object
|
|
|
|
*/
|
|
|
|
_networkRequests: null,
|
|
|
|
|
|
|
|
getNetworkRequest(actorId) {
|
|
|
|
return this._networkRequests.get(actorId);
|
|
|
|
},
|
|
|
|
|
|
|
|
hasNetworkRequest(actorId) {
|
|
|
|
return this._networkRequests.has(actorId);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeNetworkRequest(actorId) {
|
|
|
|
this._networkRequests.delete(actorId);
|
|
|
|
},
|
|
|
|
|
2015-04-27 19:59:35 +03:00
|
|
|
getNetworkEvents() {
|
|
|
|
return this._networkRequests.values();
|
|
|
|
},
|
|
|
|
|
2016-03-16 10:16:00 +03:00
|
|
|
get actor() {
|
|
|
|
return this._actor;
|
|
|
|
},
|
2014-03-07 16:14:53 +04:00
|
|
|
|
2015-04-24 21:38:09 +03:00
|
|
|
/**
|
|
|
|
* The "networkEvent" message type handler. We redirect any message to
|
|
|
|
* the UI for displaying.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param string type
|
|
|
|
* Message type.
|
|
|
|
* @param object packet
|
|
|
|
* The message received from the server.
|
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
_onNetworkEvent(type, packet) {
|
2015-04-24 21:38:09 +03:00
|
|
|
if (packet.from == this._actor) {
|
|
|
|
let actor = packet.eventActor;
|
|
|
|
let networkInfo = {
|
2015-04-27 19:59:35 +03:00
|
|
|
_type: "NetworkEvent",
|
|
|
|
timeStamp: actor.timeStamp,
|
2015-04-24 21:38:09 +03:00
|
|
|
node: null,
|
|
|
|
actor: actor.actor,
|
|
|
|
discardRequestBody: true,
|
|
|
|
discardResponseBody: true,
|
|
|
|
startedDateTime: actor.startedDateTime,
|
|
|
|
request: {
|
|
|
|
url: actor.url,
|
|
|
|
method: actor.method,
|
|
|
|
},
|
|
|
|
isXHR: actor.isXHR,
|
2016-06-01 02:03:00 +03:00
|
|
|
cause: actor.cause,
|
2015-04-24 21:38:09 +03:00
|
|
|
response: {},
|
|
|
|
timings: {},
|
2016-03-16 10:16:00 +03:00
|
|
|
// track the list of network event updates
|
|
|
|
updates: [],
|
2015-04-24 21:38:09 +03:00
|
|
|
private: actor.private,
|
2016-01-14 16:53:00 +03:00
|
|
|
fromCache: actor.fromCache,
|
|
|
|
fromServiceWorker: actor.fromServiceWorker
|
2015-04-24 21:38:09 +03:00
|
|
|
};
|
|
|
|
this._networkRequests.set(actor.actor, networkInfo);
|
|
|
|
|
|
|
|
this.emit("networkEvent", networkInfo);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The "networkEventUpdate" message type handler. We redirect any message to
|
|
|
|
* the UI for displaying.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param string type
|
|
|
|
* Message type.
|
|
|
|
* @param object packet
|
|
|
|
* The message received from the server.
|
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
_onNetworkEventUpdate(type, packet) {
|
2015-04-24 21:38:09 +03:00
|
|
|
let networkInfo = this.getNetworkRequest(packet.from);
|
|
|
|
if (!networkInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
networkInfo.updates.push(packet.updateType);
|
|
|
|
|
|
|
|
switch (packet.updateType) {
|
|
|
|
case "requestHeaders":
|
|
|
|
networkInfo.request.headersSize = packet.headersSize;
|
|
|
|
break;
|
|
|
|
case "requestPostData":
|
|
|
|
networkInfo.discardRequestBody = packet.discardRequestBody;
|
|
|
|
networkInfo.request.bodySize = packet.dataSize;
|
|
|
|
break;
|
|
|
|
case "responseStart":
|
|
|
|
networkInfo.response.httpVersion = packet.response.httpVersion;
|
|
|
|
networkInfo.response.status = packet.response.status;
|
|
|
|
networkInfo.response.statusText = packet.response.statusText;
|
|
|
|
networkInfo.response.headersSize = packet.response.headersSize;
|
2015-04-28 20:20:20 +03:00
|
|
|
networkInfo.response.remoteAddress = packet.response.remoteAddress;
|
|
|
|
networkInfo.response.remotePort = packet.response.remotePort;
|
2015-04-24 21:38:09 +03:00
|
|
|
networkInfo.discardResponseBody = packet.response.discardResponseBody;
|
|
|
|
break;
|
|
|
|
case "responseContent":
|
|
|
|
networkInfo.response.content = {
|
|
|
|
mimeType: packet.mimeType,
|
|
|
|
};
|
|
|
|
networkInfo.response.bodySize = packet.contentSize;
|
2015-04-28 20:20:20 +03:00
|
|
|
networkInfo.response.transferredSize = packet.transferredSize;
|
2015-04-24 21:38:09 +03:00
|
|
|
networkInfo.discardResponseBody = packet.discardResponseBody;
|
|
|
|
break;
|
|
|
|
case "eventTimings":
|
|
|
|
networkInfo.totalTime = packet.totalTime;
|
|
|
|
break;
|
2015-04-28 20:20:20 +03:00
|
|
|
case "securityInfo":
|
|
|
|
networkInfo.securityInfo = packet.state;
|
|
|
|
break;
|
2015-04-24 21:38:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.emit("networkEventUpdate", {
|
2017-01-12 00:22:15 +03:00
|
|
|
packet,
|
2015-04-24 21:38:09 +03:00
|
|
|
networkInfo
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-09-26 21:07:57 +04:00
|
|
|
/**
|
|
|
|
* Retrieve the cached messages from the server.
|
|
|
|
*
|
|
|
|
* @see this.CACHED_MESSAGES
|
2015-04-24 21:38:09 +03:00
|
|
|
* @param array types
|
2012-09-26 21:07:57 +04:00
|
|
|
* The array of message types you want from the server. See
|
|
|
|
* this.CACHED_MESSAGES for known types.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-09-26 21:07:57 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-09-26 21:07:57 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getCachedMessages(types, onResponse) {
|
2012-09-26 21:07:57 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "getCachedMessages",
|
2015-04-24 21:38:09 +03:00
|
|
|
messageTypes: types,
|
2012-09-26 21:07:57 +04:00
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-09-26 21:07:57 +04:00
|
|
|
},
|
|
|
|
|
2012-09-26 21:02:04 +04:00
|
|
|
/**
|
|
|
|
* Inspect the properties of an object.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2012-09-26 21:02:04 +04:00
|
|
|
* The WebConsoleObjectActor ID to send the request to.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-09-26 21:02:04 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-09-26 21:02:04 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
inspectObjectProperties(actor, onResponse) {
|
2012-09-26 21:02:04 +04:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2012-09-26 21:02:04 +04:00
|
|
|
type: "inspectProperties",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-09-26 21:02:04 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluate a JavaScript expression.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string string
|
2012-09-26 21:02:04 +04:00
|
|
|
* The code you want to evaluate.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-09-26 21:02:04 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param object [options={}]
|
2013-03-30 15:31:10 +04:00
|
|
|
* Options for evaluation:
|
|
|
|
*
|
|
|
|
* - bindObjectActor: an ObjectActor ID. The OA holds a reference to
|
|
|
|
* a Debugger.Object that wraps a content object. This option allows
|
|
|
|
* you to bind |_self| to the D.O of the given OA, during string
|
|
|
|
* evaluation.
|
|
|
|
*
|
2015-08-31 01:08:19 +03:00
|
|
|
* See: Debugger.Object.executeInGlobalWithBindings() for information
|
2013-03-30 15:31:10 +04:00
|
|
|
* about bindings.
|
|
|
|
*
|
|
|
|
* Use case: the variable view needs to update objects and it does so
|
|
|
|
* by knowing the ObjectActor it inspects and binding |_self| to the
|
|
|
|
* D.O of the OA. As such, variable view sends strings like these for
|
|
|
|
* eval:
|
|
|
|
* _self["prop"] = value;
|
|
|
|
*
|
|
|
|
* - frameActor: a FrameActor ID. The FA holds a reference to
|
|
|
|
* a Debugger.Frame. This option allows you to evaluate the string in
|
|
|
|
* the frame of the given FA.
|
2013-07-23 20:58:27 +04:00
|
|
|
*
|
|
|
|
* - url: the url to evaluate the script as. Defaults to
|
|
|
|
* "debugger eval code".
|
2014-07-31 21:07:27 +04:00
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* - selectedNodeActor: the NodeActor ID of the current
|
|
|
|
* selection in the Inspector, if such a selection
|
|
|
|
* exists. This is used by helper functions that can
|
|
|
|
* reference the currently selected node in the Inspector,
|
|
|
|
* like $0.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-09-26 21:02:04 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
evaluateJS(string, onResponse, options = {}) {
|
2012-09-26 21:02:04 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "evaluateJS",
|
2016-03-16 10:16:00 +03:00
|
|
|
text: string,
|
|
|
|
bindObjectActor: options.bindObjectActor,
|
|
|
|
frameActor: options.frameActor,
|
|
|
|
url: options.url,
|
|
|
|
selectedNodeActor: options.selectedNodeActor,
|
|
|
|
selectedObjectActor: options.selectedObjectActor,
|
2012-09-26 21:02:04 +04:00
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-09-26 21:02:04 +04:00
|
|
|
},
|
|
|
|
|
2014-12-17 04:18:26 +03:00
|
|
|
/**
|
|
|
|
* Evaluate a JavaScript expression asynchronously.
|
|
|
|
* See evaluateJS for parameter and response information.
|
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
evaluateJSAsync(string, onResponse, options = {}) {
|
2015-01-06 00:15:04 +03:00
|
|
|
// Pre-37 servers don't support async evaluation.
|
|
|
|
if (!this.traits.evaluateJSAsync) {
|
2016-11-24 18:12:25 +03:00
|
|
|
return this.evaluateJS(string, onResponse, options);
|
2015-01-06 00:15:04 +03:00
|
|
|
}
|
|
|
|
|
2014-12-17 04:18:26 +03:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "evaluateJSAsync",
|
2016-03-16 10:16:00 +03:00
|
|
|
text: string,
|
|
|
|
bindObjectActor: options.bindObjectActor,
|
|
|
|
frameActor: options.frameActor,
|
|
|
|
url: options.url,
|
|
|
|
selectedNodeActor: options.selectedNodeActor,
|
|
|
|
selectedObjectActor: options.selectedObjectActor,
|
2014-12-17 04:18:26 +03:00
|
|
|
};
|
|
|
|
|
2016-11-24 18:12:25 +03:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
this._client.request(packet, response => {
|
|
|
|
// Null check this in case the client has been detached while waiting
|
|
|
|
// for a response.
|
|
|
|
if (this.pendingEvaluationResults) {
|
|
|
|
this.pendingEvaluationResults.set(response.resultID, resp => {
|
|
|
|
if (onResponse) {
|
|
|
|
onResponse(resp);
|
|
|
|
}
|
|
|
|
if (resp.error) {
|
|
|
|
reject(resp);
|
|
|
|
} else {
|
|
|
|
resolve(resp);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-12-17 04:18:26 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the actors's unsolicited evaluationResult packet.
|
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
onEvaluationResult(notification, packet) {
|
2015-10-26 19:13:11 +03:00
|
|
|
// The client on the main thread can receive notification packets from
|
|
|
|
// multiple webconsole actors: the one on the main thread and the ones
|
|
|
|
// on worker threads. So make sure we should be handling this request.
|
2016-03-16 10:16:00 +03:00
|
|
|
if (packet.from !== this._actor) {
|
2015-10-26 19:13:11 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-17 04:18:26 +03:00
|
|
|
// Find the associated callback based on this ID, and fire it.
|
|
|
|
// In a sync evaluation, this would have already been called in
|
|
|
|
// direct response to the client.request function.
|
2016-03-16 10:16:00 +03:00
|
|
|
let onResponse = this.pendingEvaluationResults.get(packet.resultID);
|
2014-12-17 04:18:26 +03:00
|
|
|
if (onResponse) {
|
2016-03-16 10:16:00 +03:00
|
|
|
onResponse(packet);
|
|
|
|
this.pendingEvaluationResults.delete(packet.resultID);
|
2014-12-17 04:18:26 +03:00
|
|
|
} else {
|
|
|
|
DevToolsUtils.reportException("onEvaluationResult",
|
2016-03-16 10:16:00 +03:00
|
|
|
"No response handler for an evaluateJSAsync result (resultID: " +
|
|
|
|
packet.resultID + ")");
|
2014-12-17 04:18:26 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-26 21:02:04 +04:00
|
|
|
/**
|
|
|
|
* Autocomplete a JavaScript expression.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string string
|
2012-09-26 21:02:04 +04:00
|
|
|
* The code you want to autocomplete.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param number cursor
|
2012-09-26 21:02:04 +04:00
|
|
|
* Cursor location inside the string. Index starts from 0.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-09-26 21:02:04 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string frameActor
|
2013-11-26 22:42:02 +04:00
|
|
|
* The id of the frame actor that made the call.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-09-26 21:02:04 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
autocomplete(string, cursor, onResponse, frameActor) {
|
2012-09-26 21:02:04 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "autocomplete",
|
2016-03-16 10:16:00 +03:00
|
|
|
text: string,
|
2017-01-12 00:22:15 +03:00
|
|
|
cursor,
|
|
|
|
frameActor,
|
2012-09-26 21:02:04 +04:00
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-09-26 21:02:04 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the cache of messages (page errors and console API calls).
|
2016-11-24 18:12:25 +03:00
|
|
|
*
|
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-09-26 21:02:04 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
clearMessagesCache() {
|
2012-09-26 21:02:04 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "clearMessagesCache",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet);
|
2012-09-26 21:02:04 +04:00
|
|
|
},
|
|
|
|
|
2013-06-27 00:35:39 +04:00
|
|
|
/**
|
|
|
|
* Get Web Console-related preferences on the server.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param array preferences
|
2013-09-13 16:06:46 +04:00
|
|
|
* An array with the preferences you want to retrieve.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function [onResponse]
|
2013-06-27 00:35:39 +04:00
|
|
|
* Optional function to invoke when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2013-06-27 00:35:39 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getPreferences(preferences, onResponse) {
|
2013-06-27 00:35:39 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "getPreferences",
|
2017-01-12 00:22:15 +03:00
|
|
|
preferences,
|
2013-06-27 00:35:39 +04:00
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2013-06-27 00:35:39 +04:00
|
|
|
},
|
|
|
|
|
2012-10-05 15:54:43 +04:00
|
|
|
/**
|
|
|
|
* Set Web Console-related preferences on the server.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param object preferences
|
2012-10-05 15:54:43 +04:00
|
|
|
* An object with the preferences you want to change.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function [onResponse]
|
2012-10-05 15:54:43 +04:00
|
|
|
* Optional function to invoke when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-10-05 15:54:43 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
setPreferences(preferences, onResponse) {
|
2012-10-05 15:54:43 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "setPreferences",
|
2017-01-12 00:22:15 +03:00
|
|
|
preferences,
|
2012-10-05 15:54:43 +04:00
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-10-05 15:54:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the request headers from the given NetworkEventActor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2012-10-05 15:54:43 +04:00
|
|
|
* The NetworkEventActor ID.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-10-05 15:54:43 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-10-05 15:54:43 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getRequestHeaders(actor, onResponse) {
|
2012-10-05 15:54:43 +04:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2012-10-05 15:54:43 +04:00
|
|
|
type: "getRequestHeaders",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-10-05 15:54:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the request cookies from the given NetworkEventActor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2012-10-05 15:54:43 +04:00
|
|
|
* The NetworkEventActor ID.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-10-05 15:54:43 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-10-05 15:54:43 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getRequestCookies(actor, onResponse) {
|
2012-10-05 15:54:43 +04:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2012-10-05 15:54:43 +04:00
|
|
|
type: "getRequestCookies",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-10-05 15:54:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the request post data from the given NetworkEventActor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2012-10-05 15:54:43 +04:00
|
|
|
* The NetworkEventActor ID.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-10-05 15:54:43 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-10-05 15:54:43 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getRequestPostData(actor, onResponse) {
|
2012-10-05 15:54:43 +04:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2012-10-05 15:54:43 +04:00
|
|
|
type: "getRequestPostData",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-10-05 15:54:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the response headers from the given NetworkEventActor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2012-10-05 15:54:43 +04:00
|
|
|
* The NetworkEventActor ID.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-10-05 15:54:43 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-10-05 15:54:43 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getResponseHeaders(actor, onResponse) {
|
2012-10-05 15:54:43 +04:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2012-10-05 15:54:43 +04:00
|
|
|
type: "getResponseHeaders",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-10-05 15:54:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the response cookies from the given NetworkEventActor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2012-10-05 15:54:43 +04:00
|
|
|
* The NetworkEventActor ID.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-10-05 15:54:43 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-10-05 15:54:43 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getResponseCookies(actor, onResponse) {
|
2012-10-05 15:54:43 +04:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2012-10-05 15:54:43 +04:00
|
|
|
type: "getResponseCookies",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-10-05 15:54:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the response content from the given NetworkEventActor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2012-10-05 15:54:43 +04:00
|
|
|
* The NetworkEventActor ID.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-10-05 15:54:43 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-10-05 15:54:43 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getResponseContent(actor, onResponse) {
|
2012-10-05 15:54:43 +04:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2012-10-05 15:54:43 +04:00
|
|
|
type: "getResponseContent",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-10-05 15:54:43 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the timing information for the given NetworkEventActor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2012-10-05 15:54:43 +04:00
|
|
|
* The NetworkEventActor ID.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-10-05 15:54:43 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-10-05 15:54:43 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getEventTimings(actor, onResponse) {
|
2012-10-05 15:54:43 +04:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2012-10-05 15:54:43 +04:00
|
|
|
type: "getEventTimings",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2013-06-26 13:09:59 +04:00
|
|
|
},
|
|
|
|
|
2015-01-06 03:58:00 +03:00
|
|
|
/**
|
|
|
|
* Retrieve the security information for the given NetworkEventActor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string actor
|
2015-01-06 03:58:00 +03:00
|
|
|
* The NetworkEventActor ID.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2015-01-06 03:58:00 +03:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2015-01-06 03:58:00 +03:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getSecurityInfo(actor, onResponse) {
|
2015-01-06 03:58:00 +03:00
|
|
|
let packet = {
|
2016-03-16 10:16:00 +03:00
|
|
|
to: actor,
|
2015-01-06 03:58:00 +03:00
|
|
|
type: "getSecurityInfo",
|
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2015-01-06 03:58:00 +03:00
|
|
|
},
|
|
|
|
|
2013-06-26 13:09:59 +04:00
|
|
|
/**
|
|
|
|
* Send a HTTP request with the given data.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param string data
|
2013-06-26 13:09:59 +04:00
|
|
|
* The details of the HTTP request.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2013-06-26 13:09:59 +04:00
|
|
|
* The function invoked when the response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2013-06-26 13:09:59 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
sendHTTPRequest(data, onResponse) {
|
2013-06-26 13:09:59 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "sendHTTPRequest",
|
2016-03-16 10:16:00 +03:00
|
|
|
request: data
|
2013-06-26 13:09:59 +04:00
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-10-05 15:54:43 +04:00
|
|
|
},
|
|
|
|
|
2012-09-26 21:07:57 +04:00
|
|
|
/**
|
|
|
|
* Start the given Web Console listeners.
|
|
|
|
*
|
|
|
|
* @see this.LISTENERS
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param array listeners
|
2012-09-26 21:07:57 +04:00
|
|
|
* Array of listeners you want to start. See this.LISTENERS for
|
|
|
|
* known listeners.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-09-26 21:07:57 +04:00
|
|
|
* Function to invoke when the server response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-09-26 21:07:57 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
startListeners(listeners, onResponse) {
|
2012-09-26 21:07:57 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "startListeners",
|
2017-01-12 00:22:15 +03:00
|
|
|
listeners,
|
2012-09-26 21:07:57 +04:00
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-09-26 21:07:57 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the given Web Console listeners.
|
|
|
|
*
|
|
|
|
* @see this.LISTENERS
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param array listeners
|
2012-09-26 21:07:57 +04:00
|
|
|
* Array of listeners you want to stop. See this.LISTENERS for
|
|
|
|
* known listeners.
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-09-26 21:07:57 +04:00
|
|
|
* Function to invoke when the server response is received.
|
2016-11-24 18:12:25 +03:00
|
|
|
* @return request
|
|
|
|
* Request object that implements both Promise and EventEmitter interfaces
|
2012-09-26 21:07:57 +04:00
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
stopListeners(listeners, onResponse) {
|
2012-09-26 21:07:57 +04:00
|
|
|
let packet = {
|
|
|
|
to: this._actor,
|
|
|
|
type: "stopListeners",
|
2017-01-12 00:22:15 +03:00
|
|
|
listeners,
|
2012-09-26 21:07:57 +04:00
|
|
|
};
|
2016-11-24 18:12:25 +03:00
|
|
|
return this._client.request(packet, onResponse);
|
2012-09-26 21:07:57 +04:00
|
|
|
},
|
|
|
|
|
2012-11-05 20:41:59 +04:00
|
|
|
/**
|
|
|
|
* Return an instance of LongStringClient for the given long string grip.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param object grip
|
2012-11-05 20:41:59 +04:00
|
|
|
* The long string grip returned by the protocol.
|
|
|
|
* @return object
|
|
|
|
* The LongStringClient for the given long string grip.
|
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
longString(grip) {
|
2016-03-16 10:16:00 +03:00
|
|
|
if (grip.actor in this._longStrings) {
|
|
|
|
return this._longStrings[grip.actor];
|
2012-11-05 20:41:59 +04:00
|
|
|
}
|
|
|
|
|
2016-03-16 10:16:00 +03:00
|
|
|
let client = new LongStringClient(this._client, grip);
|
|
|
|
this._longStrings[grip.actor] = client;
|
2012-11-05 20:41:59 +04:00
|
|
|
return client;
|
|
|
|
},
|
|
|
|
|
2012-09-26 21:07:57 +04:00
|
|
|
/**
|
|
|
|
* Close the WebConsoleClient. This stops all the listeners on the server and
|
|
|
|
* detaches from the console actor.
|
|
|
|
*
|
2016-03-16 10:16:00 +03:00
|
|
|
* @param function onResponse
|
2012-09-26 21:07:57 +04:00
|
|
|
* Function to invoke when the server response is received.
|
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
detach(onResponse) {
|
2014-12-17 04:18:26 +03:00
|
|
|
this._client.removeListener("evaluationResult", this.onEvaluationResult);
|
2015-04-24 21:38:09 +03:00
|
|
|
this._client.removeListener("networkEvent", this.onNetworkEvent);
|
2016-03-16 10:16:00 +03:00
|
|
|
this._client.removeListener("networkEventUpdate",
|
|
|
|
this.onNetworkEventUpdate);
|
|
|
|
this.stopListeners(null, onResponse);
|
2012-11-05 20:41:59 +04:00
|
|
|
this._longStrings = null;
|
2012-09-26 21:07:57 +04:00
|
|
|
this._client = null;
|
2014-12-17 04:18:26 +03:00
|
|
|
this.pendingEvaluationResults.clear();
|
|
|
|
this.pendingEvaluationResults = null;
|
2015-04-24 21:38:09 +03:00
|
|
|
this.clearNetworkRequests();
|
|
|
|
this._networkRequests = null;
|
2012-09-26 21:07:57 +04:00
|
|
|
},
|
2015-04-24 21:38:09 +03:00
|
|
|
|
2017-01-12 00:22:15 +03:00
|
|
|
clearNetworkRequests() {
|
2015-04-24 21:38:09 +03:00
|
|
|
this._networkRequests.clear();
|
2015-06-17 17:27:20 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the full text of a LongString.
|
|
|
|
*
|
|
|
|
* @param object | string stringGrip
|
|
|
|
* The long string grip containing the corresponding actor.
|
|
|
|
* If you pass in a plain string (by accident or because you're lazy),
|
|
|
|
* then a promise of the same string is simply returned.
|
|
|
|
* @return object Promise
|
|
|
|
* A promise that is resolved when the full string contents
|
|
|
|
* are available, or rejected if something goes wrong.
|
|
|
|
*/
|
2017-01-12 00:22:15 +03:00
|
|
|
getString(stringGrip) {
|
2015-06-17 17:27:20 +03:00
|
|
|
// Make sure this is a long string.
|
|
|
|
if (typeof stringGrip != "object" || stringGrip.type != "longString") {
|
2016-03-16 10:16:00 +03:00
|
|
|
// Go home string, you're drunk.
|
|
|
|
return promise.resolve(stringGrip);
|
2015-06-17 17:27:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch the long string only once.
|
|
|
|
if (stringGrip._fullText) {
|
|
|
|
return stringGrip._fullText.promise;
|
|
|
|
}
|
|
|
|
|
2016-06-09 18:03:47 +03:00
|
|
|
let deferred = stringGrip._fullText = defer();
|
2016-03-16 10:16:00 +03:00
|
|
|
let { initial, length } = stringGrip;
|
2015-06-17 17:27:20 +03:00
|
|
|
let longStringClient = this.longString(stringGrip);
|
|
|
|
|
2016-03-16 10:16:00 +03:00
|
|
|
longStringClient.substring(initial.length, length, response => {
|
|
|
|
if (response.error) {
|
2015-06-17 17:27:20 +03:00
|
|
|
DevToolsUtils.reportException("getString",
|
2016-03-16 10:16:00 +03:00
|
|
|
response.error + ": " + response.message);
|
2015-06-17 17:27:20 +03:00
|
|
|
|
2016-03-16 10:16:00 +03:00
|
|
|
deferred.reject(response);
|
2015-06-17 17:27:20 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-03-16 10:16:00 +03:00
|
|
|
deferred.resolve(initial + response.substring);
|
2015-06-17 17:27:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
2015-04-24 21:38:09 +03:00
|
|
|
}
|
2012-09-26 21:07:57 +04:00
|
|
|
};
|