1 /* -*- js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
2 /* vim: set 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/. */
9 const {Cc, Ci, Cu} = require("chrome");
11 loader.lazyImporter(this, "LongStringClient", "resource://gre/modules/devtools/dbg-client.jsm");
14 * A WebConsoleClient is used as a front end for the WebConsoleActor that is
15 * created on the server, hiding implementation details.
17 * @param object aDebuggerClient
18 * The DebuggerClient instance we live for.
19 * @param string aActor
20 * The WebConsoleActor ID.
22 function WebConsoleClient(aDebuggerClient, aActor)
25 this._client = aDebuggerClient;
26 this._longStrings = {};
28 exports.WebConsoleClient = WebConsoleClient;
30 WebConsoleClient.prototype = {
34 * Retrieve the cached messages from the server.
36 * @see this.CACHED_MESSAGES
38 * The array of message types you want from the server. See
39 * this.CACHED_MESSAGES for known types.
40 * @param function aOnResponse
41 * The function invoked when the response is received.
43 getCachedMessages: function WCC_getCachedMessages(aTypes, aOnResponse)
47 type: "getCachedMessages",
50 this._client.request(packet, aOnResponse);
54 * Inspect the properties of an object.
56 * @param string aActor
57 * The WebConsoleObjectActor ID to send the request to.
58 * @param function aOnResponse
59 * The function invoked when the response is received.
61 inspectObjectProperties:
62 function WCC_inspectObjectProperties(aActor, aOnResponse)
66 type: "inspectProperties",
68 this._client.request(packet, aOnResponse);
72 * Evaluate a JavaScript expression.
74 * @param string aString
75 * The code you want to evaluate.
76 * @param function aOnResponse
77 * The function invoked when the response is received.
78 * @param object [aOptions={}]
79 * Options for evaluation:
81 * - bindObjectActor: an ObjectActor ID. The OA holds a reference to
82 * a Debugger.Object that wraps a content object. This option allows
83 * you to bind |_self| to the D.O of the given OA, during string
86 * See: Debugger.Object.evalInGlobalWithBindings() for information
89 * Use case: the variable view needs to update objects and it does so
90 * by knowing the ObjectActor it inspects and binding |_self| to the
91 * D.O of the OA. As such, variable view sends strings like these for
93 * _self["prop"] = value;
95 * - frameActor: a FrameActor ID. The FA holds a reference to
96 * a Debugger.Frame. This option allows you to evaluate the string in
97 * the frame of the given FA.
99 * - url: the url to evaluate the script as. Defaults to
100 * "debugger eval code".
102 evaluateJS: function WCC_evaluateJS(aString, aOnResponse, aOptions = {})
108 bindObjectActor: aOptions.bindObjectActor,
109 frameActor: aOptions.frameActor,
112 this._client.request(packet, aOnResponse);
116 * Autocomplete a JavaScript expression.
118 * @param string aString
119 * The code you want to autocomplete.
120 * @param number aCursor
121 * Cursor location inside the string. Index starts from 0.
122 * @param function aOnResponse
123 * The function invoked when the response is received.
124 * @param string aFrameActor
125 * The id of the frame actor that made the call.
127 autocomplete: function WCC_autocomplete(aString, aCursor, aOnResponse, aFrameActor)
131 type: "autocomplete",
134 frameActor: aFrameActor,
136 this._client.request(packet, aOnResponse);
140 * Clear the cache of messages (page errors and console API calls).
142 clearMessagesCache: function WCC_clearMessagesCache()
146 type: "clearMessagesCache",
148 this._client.request(packet);
152 * Get Web Console-related preferences on the server.
154 * @param array aPreferences
155 * An array with the preferences you want to retrieve.
156 * @param function [aOnResponse]
157 * Optional function to invoke when the response is received.
159 getPreferences: function WCC_getPreferences(aPreferences, aOnResponse)
163 type: "getPreferences",
164 preferences: aPreferences,
166 this._client.request(packet, aOnResponse);
170 * Set Web Console-related preferences on the server.
172 * @param object aPreferences
173 * An object with the preferences you want to change.
174 * @param function [aOnResponse]
175 * Optional function to invoke when the response is received.
177 setPreferences: function WCC_setPreferences(aPreferences, aOnResponse)
181 type: "setPreferences",
182 preferences: aPreferences,
184 this._client.request(packet, aOnResponse);
188 * Retrieve the request headers from the given NetworkEventActor.
190 * @param string aActor
191 * The NetworkEventActor ID.
192 * @param function aOnResponse
193 * The function invoked when the response is received.
195 getRequestHeaders: function WCC_getRequestHeaders(aActor, aOnResponse)
199 type: "getRequestHeaders",
201 this._client.request(packet, aOnResponse);
205 * Retrieve the request cookies from the given NetworkEventActor.
207 * @param string aActor
208 * The NetworkEventActor ID.
209 * @param function aOnResponse
210 * The function invoked when the response is received.
212 getRequestCookies: function WCC_getRequestCookies(aActor, aOnResponse)
216 type: "getRequestCookies",
218 this._client.request(packet, aOnResponse);
222 * Retrieve the request post data from the given NetworkEventActor.
224 * @param string aActor
225 * The NetworkEventActor ID.
226 * @param function aOnResponse
227 * The function invoked when the response is received.
229 getRequestPostData: function WCC_getRequestPostData(aActor, aOnResponse)
233 type: "getRequestPostData",
235 this._client.request(packet, aOnResponse);
239 * Retrieve the response headers from the given NetworkEventActor.
241 * @param string aActor
242 * The NetworkEventActor ID.
243 * @param function aOnResponse
244 * The function invoked when the response is received.
246 getResponseHeaders: function WCC_getResponseHeaders(aActor, aOnResponse)
250 type: "getResponseHeaders",
252 this._client.request(packet, aOnResponse);
256 * Retrieve the response cookies from the given NetworkEventActor.
258 * @param string aActor
259 * The NetworkEventActor ID.
260 * @param function aOnResponse
261 * The function invoked when the response is received.
263 getResponseCookies: function WCC_getResponseCookies(aActor, aOnResponse)
267 type: "getResponseCookies",
269 this._client.request(packet, aOnResponse);
273 * Retrieve the response content from the given NetworkEventActor.
275 * @param string aActor
276 * The NetworkEventActor ID.
277 * @param function aOnResponse
278 * The function invoked when the response is received.
280 getResponseContent: function WCC_getResponseContent(aActor, aOnResponse)
284 type: "getResponseContent",
286 this._client.request(packet, aOnResponse);
290 * Retrieve the timing information for the given NetworkEventActor.
292 * @param string aActor
293 * The NetworkEventActor ID.
294 * @param function aOnResponse
295 * The function invoked when the response is received.
297 getEventTimings: function WCC_getEventTimings(aActor, aOnResponse)
301 type: "getEventTimings",
303 this._client.request(packet, aOnResponse);
307 * Send a HTTP request with the given data.
309 * @param string aData
310 * The details of the HTTP request.
311 * @param function aOnResponse
312 * The function invoked when the response is received.
314 sendHTTPRequest: function WCC_sendHTTPRequest(aData, aOnResponse) {
317 type: "sendHTTPRequest",
320 this._client.request(packet, aOnResponse);
324 * Start the given Web Console listeners.
326 * @see this.LISTENERS
327 * @param array aListeners
328 * Array of listeners you want to start. See this.LISTENERS for
330 * @param function aOnResponse
331 * Function to invoke when the server response is received.
333 startListeners: function WCC_startListeners(aListeners, aOnResponse)
337 type: "startListeners",
338 listeners: aListeners,
340 this._client.request(packet, aOnResponse);
344 * Stop the given Web Console listeners.
346 * @see this.LISTENERS
347 * @param array aListeners
348 * Array of listeners you want to stop. See this.LISTENERS for
350 * @param function aOnResponse
351 * Function to invoke when the server response is received.
353 stopListeners: function WCC_stopListeners(aListeners, aOnResponse)
357 type: "stopListeners",
358 listeners: aListeners,
360 this._client.request(packet, aOnResponse);
364 * Return an instance of LongStringClient for the given long string grip.
366 * @param object aGrip
367 * The long string grip returned by the protocol.
369 * The LongStringClient for the given long string grip.
371 longString: function WCC_longString(aGrip)
373 if (aGrip.actor in this._longStrings) {
374 return this._longStrings[aGrip.actor];
377 let client = new LongStringClient(this._client, aGrip);
378 this._longStrings[aGrip.actor] = client;
383 * Close the WebConsoleClient. This stops all the listeners on the server and
384 * detaches from the console actor.
386 * @param function aOnResponse
387 * Function to invoke when the server response is received.
389 close: function WCC_close(aOnResponse)
391 this.stopListeners(null, aOnResponse);
392 this._longStrings = null;