michael@0: /* -*- js2-basic-offset: 2; indent-tabs-mode: nil; -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const {Cc, Ci, Cu} = require("chrome"); michael@0: michael@0: loader.lazyImporter(this, "LongStringClient", "resource://gre/modules/devtools/dbg-client.jsm"); michael@0: michael@0: /** michael@0: * A WebConsoleClient is used as a front end for the WebConsoleActor that is michael@0: * created on the server, hiding implementation details. michael@0: * michael@0: * @param object aDebuggerClient michael@0: * The DebuggerClient instance we live for. michael@0: * @param object aResponse michael@0: * The response packet received from the "startListeners" request sent to michael@0: * the WebConsoleActor. michael@0: */ michael@0: function WebConsoleClient(aDebuggerClient, aResponse) michael@0: { michael@0: this._actor = aResponse.from; michael@0: this._client = aDebuggerClient; michael@0: this._longStrings = {}; michael@0: this.traits = aResponse.traits || {}; michael@0: } michael@0: exports.WebConsoleClient = WebConsoleClient; michael@0: michael@0: WebConsoleClient.prototype = { michael@0: _longStrings: null, michael@0: traits: null, michael@0: michael@0: get actor() { return this._actor; }, michael@0: michael@0: /** michael@0: * Retrieve the cached messages from the server. michael@0: * michael@0: * @see this.CACHED_MESSAGES michael@0: * @param array aTypes michael@0: * The array of message types you want from the server. See michael@0: * this.CACHED_MESSAGES for known types. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: getCachedMessages: function WCC_getCachedMessages(aTypes, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "getCachedMessages", michael@0: messageTypes: aTypes, michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Inspect the properties of an object. michael@0: * michael@0: * @param string aActor michael@0: * The WebConsoleObjectActor ID to send the request to. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: inspectObjectProperties: michael@0: function WCC_inspectObjectProperties(aActor, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: aActor, michael@0: type: "inspectProperties", michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Evaluate a JavaScript expression. michael@0: * michael@0: * @param string aString michael@0: * The code you want to evaluate. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: * @param object [aOptions={}] michael@0: * Options for evaluation: michael@0: * michael@0: * - bindObjectActor: an ObjectActor ID. The OA holds a reference to michael@0: * a Debugger.Object that wraps a content object. This option allows michael@0: * you to bind |_self| to the D.O of the given OA, during string michael@0: * evaluation. michael@0: * michael@0: * See: Debugger.Object.evalInGlobalWithBindings() for information michael@0: * about bindings. michael@0: * michael@0: * Use case: the variable view needs to update objects and it does so michael@0: * by knowing the ObjectActor it inspects and binding |_self| to the michael@0: * D.O of the OA. As such, variable view sends strings like these for michael@0: * eval: michael@0: * _self["prop"] = value; michael@0: * michael@0: * - frameActor: a FrameActor ID. The FA holds a reference to michael@0: * a Debugger.Frame. This option allows you to evaluate the string in michael@0: * the frame of the given FA. michael@0: * michael@0: * - url: the url to evaluate the script as. Defaults to michael@0: * "debugger eval code". michael@0: */ michael@0: evaluateJS: function WCC_evaluateJS(aString, aOnResponse, aOptions = {}) michael@0: { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "evaluateJS", michael@0: text: aString, michael@0: bindObjectActor: aOptions.bindObjectActor, michael@0: frameActor: aOptions.frameActor, michael@0: url: aOptions.url, michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Autocomplete a JavaScript expression. michael@0: * michael@0: * @param string aString michael@0: * The code you want to autocomplete. michael@0: * @param number aCursor michael@0: * Cursor location inside the string. Index starts from 0. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: * @param string aFrameActor michael@0: * The id of the frame actor that made the call. michael@0: */ michael@0: autocomplete: function WCC_autocomplete(aString, aCursor, aOnResponse, aFrameActor) michael@0: { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "autocomplete", michael@0: text: aString, michael@0: cursor: aCursor, michael@0: frameActor: aFrameActor, michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Clear the cache of messages (page errors and console API calls). michael@0: */ michael@0: clearMessagesCache: function WCC_clearMessagesCache() michael@0: { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "clearMessagesCache", michael@0: }; michael@0: this._client.request(packet); michael@0: }, michael@0: michael@0: /** michael@0: * Get Web Console-related preferences on the server. michael@0: * michael@0: * @param array aPreferences michael@0: * An array with the preferences you want to retrieve. michael@0: * @param function [aOnResponse] michael@0: * Optional function to invoke when the response is received. michael@0: */ michael@0: getPreferences: function WCC_getPreferences(aPreferences, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "getPreferences", michael@0: preferences: aPreferences, michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Set Web Console-related preferences on the server. michael@0: * michael@0: * @param object aPreferences michael@0: * An object with the preferences you want to change. michael@0: * @param function [aOnResponse] michael@0: * Optional function to invoke when the response is received. michael@0: */ michael@0: setPreferences: function WCC_setPreferences(aPreferences, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "setPreferences", michael@0: preferences: aPreferences, michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Retrieve the request headers from the given NetworkEventActor. michael@0: * michael@0: * @param string aActor michael@0: * The NetworkEventActor ID. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: getRequestHeaders: function WCC_getRequestHeaders(aActor, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: aActor, michael@0: type: "getRequestHeaders", michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Retrieve the request cookies from the given NetworkEventActor. michael@0: * michael@0: * @param string aActor michael@0: * The NetworkEventActor ID. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: getRequestCookies: function WCC_getRequestCookies(aActor, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: aActor, michael@0: type: "getRequestCookies", michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Retrieve the request post data from the given NetworkEventActor. michael@0: * michael@0: * @param string aActor michael@0: * The NetworkEventActor ID. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: getRequestPostData: function WCC_getRequestPostData(aActor, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: aActor, michael@0: type: "getRequestPostData", michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Retrieve the response headers from the given NetworkEventActor. michael@0: * michael@0: * @param string aActor michael@0: * The NetworkEventActor ID. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: getResponseHeaders: function WCC_getResponseHeaders(aActor, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: aActor, michael@0: type: "getResponseHeaders", michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Retrieve the response cookies from the given NetworkEventActor. michael@0: * michael@0: * @param string aActor michael@0: * The NetworkEventActor ID. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: getResponseCookies: function WCC_getResponseCookies(aActor, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: aActor, michael@0: type: "getResponseCookies", michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Retrieve the response content from the given NetworkEventActor. michael@0: * michael@0: * @param string aActor michael@0: * The NetworkEventActor ID. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: getResponseContent: function WCC_getResponseContent(aActor, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: aActor, michael@0: type: "getResponseContent", michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Retrieve the timing information for the given NetworkEventActor. michael@0: * michael@0: * @param string aActor michael@0: * The NetworkEventActor ID. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: getEventTimings: function WCC_getEventTimings(aActor, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: aActor, michael@0: type: "getEventTimings", michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Send a HTTP request with the given data. michael@0: * michael@0: * @param string aData michael@0: * The details of the HTTP request. michael@0: * @param function aOnResponse michael@0: * The function invoked when the response is received. michael@0: */ michael@0: sendHTTPRequest: function WCC_sendHTTPRequest(aData, aOnResponse) { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "sendHTTPRequest", michael@0: request: aData michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Start the given Web Console listeners. michael@0: * michael@0: * @see this.LISTENERS michael@0: * @param array aListeners michael@0: * Array of listeners you want to start. See this.LISTENERS for michael@0: * known listeners. michael@0: * @param function aOnResponse michael@0: * Function to invoke when the server response is received. michael@0: */ michael@0: startListeners: function WCC_startListeners(aListeners, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "startListeners", michael@0: listeners: aListeners, michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Stop the given Web Console listeners. michael@0: * michael@0: * @see this.LISTENERS michael@0: * @param array aListeners michael@0: * Array of listeners you want to stop. See this.LISTENERS for michael@0: * known listeners. michael@0: * @param function aOnResponse michael@0: * Function to invoke when the server response is received. michael@0: */ michael@0: stopListeners: function WCC_stopListeners(aListeners, aOnResponse) michael@0: { michael@0: let packet = { michael@0: to: this._actor, michael@0: type: "stopListeners", michael@0: listeners: aListeners, michael@0: }; michael@0: this._client.request(packet, aOnResponse); michael@0: }, michael@0: michael@0: /** michael@0: * Return an instance of LongStringClient for the given long string grip. michael@0: * michael@0: * @param object aGrip michael@0: * The long string grip returned by the protocol. michael@0: * @return object michael@0: * The LongStringClient for the given long string grip. michael@0: */ michael@0: longString: function WCC_longString(aGrip) michael@0: { michael@0: if (aGrip.actor in this._longStrings) { michael@0: return this._longStrings[aGrip.actor]; michael@0: } michael@0: michael@0: let client = new LongStringClient(this._client, aGrip); michael@0: this._longStrings[aGrip.actor] = client; michael@0: return client; michael@0: }, michael@0: michael@0: /** michael@0: * Close the WebConsoleClient. This stops all the listeners on the server and michael@0: * detaches from the console actor. michael@0: * michael@0: * @param function aOnResponse michael@0: * Function to invoke when the server response is received. michael@0: */ michael@0: close: function WCC_close(aOnResponse) michael@0: { michael@0: this.stopListeners(null, aOnResponse); michael@0: this._longStrings = null; michael@0: this._client = null; michael@0: }, michael@0: };