toolkit/devtools/webconsole/client.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 "use strict";
michael@0 8
michael@0 9 const {Cc, Ci, Cu} = require("chrome");
michael@0 10
michael@0 11 loader.lazyImporter(this, "LongStringClient", "resource://gre/modules/devtools/dbg-client.jsm");
michael@0 12
michael@0 13 /**
michael@0 14 * A WebConsoleClient is used as a front end for the WebConsoleActor that is
michael@0 15 * created on the server, hiding implementation details.
michael@0 16 *
michael@0 17 * @param object aDebuggerClient
michael@0 18 * The DebuggerClient instance we live for.
michael@0 19 * @param object aResponse
michael@0 20 * The response packet received from the "startListeners" request sent to
michael@0 21 * the WebConsoleActor.
michael@0 22 */
michael@0 23 function WebConsoleClient(aDebuggerClient, aResponse)
michael@0 24 {
michael@0 25 this._actor = aResponse.from;
michael@0 26 this._client = aDebuggerClient;
michael@0 27 this._longStrings = {};
michael@0 28 this.traits = aResponse.traits || {};
michael@0 29 }
michael@0 30 exports.WebConsoleClient = WebConsoleClient;
michael@0 31
michael@0 32 WebConsoleClient.prototype = {
michael@0 33 _longStrings: null,
michael@0 34 traits: null,
michael@0 35
michael@0 36 get actor() { return this._actor; },
michael@0 37
michael@0 38 /**
michael@0 39 * Retrieve the cached messages from the server.
michael@0 40 *
michael@0 41 * @see this.CACHED_MESSAGES
michael@0 42 * @param array aTypes
michael@0 43 * The array of message types you want from the server. See
michael@0 44 * this.CACHED_MESSAGES for known types.
michael@0 45 * @param function aOnResponse
michael@0 46 * The function invoked when the response is received.
michael@0 47 */
michael@0 48 getCachedMessages: function WCC_getCachedMessages(aTypes, aOnResponse)
michael@0 49 {
michael@0 50 let packet = {
michael@0 51 to: this._actor,
michael@0 52 type: "getCachedMessages",
michael@0 53 messageTypes: aTypes,
michael@0 54 };
michael@0 55 this._client.request(packet, aOnResponse);
michael@0 56 },
michael@0 57
michael@0 58 /**
michael@0 59 * Inspect the properties of an object.
michael@0 60 *
michael@0 61 * @param string aActor
michael@0 62 * The WebConsoleObjectActor ID to send the request to.
michael@0 63 * @param function aOnResponse
michael@0 64 * The function invoked when the response is received.
michael@0 65 */
michael@0 66 inspectObjectProperties:
michael@0 67 function WCC_inspectObjectProperties(aActor, aOnResponse)
michael@0 68 {
michael@0 69 let packet = {
michael@0 70 to: aActor,
michael@0 71 type: "inspectProperties",
michael@0 72 };
michael@0 73 this._client.request(packet, aOnResponse);
michael@0 74 },
michael@0 75
michael@0 76 /**
michael@0 77 * Evaluate a JavaScript expression.
michael@0 78 *
michael@0 79 * @param string aString
michael@0 80 * The code you want to evaluate.
michael@0 81 * @param function aOnResponse
michael@0 82 * The function invoked when the response is received.
michael@0 83 * @param object [aOptions={}]
michael@0 84 * Options for evaluation:
michael@0 85 *
michael@0 86 * - bindObjectActor: an ObjectActor ID. The OA holds a reference to
michael@0 87 * a Debugger.Object that wraps a content object. This option allows
michael@0 88 * you to bind |_self| to the D.O of the given OA, during string
michael@0 89 * evaluation.
michael@0 90 *
michael@0 91 * See: Debugger.Object.evalInGlobalWithBindings() for information
michael@0 92 * about bindings.
michael@0 93 *
michael@0 94 * Use case: the variable view needs to update objects and it does so
michael@0 95 * by knowing the ObjectActor it inspects and binding |_self| to the
michael@0 96 * D.O of the OA. As such, variable view sends strings like these for
michael@0 97 * eval:
michael@0 98 * _self["prop"] = value;
michael@0 99 *
michael@0 100 * - frameActor: a FrameActor ID. The FA holds a reference to
michael@0 101 * a Debugger.Frame. This option allows you to evaluate the string in
michael@0 102 * the frame of the given FA.
michael@0 103 *
michael@0 104 * - url: the url to evaluate the script as. Defaults to
michael@0 105 * "debugger eval code".
michael@0 106 */
michael@0 107 evaluateJS: function WCC_evaluateJS(aString, aOnResponse, aOptions = {})
michael@0 108 {
michael@0 109 let packet = {
michael@0 110 to: this._actor,
michael@0 111 type: "evaluateJS",
michael@0 112 text: aString,
michael@0 113 bindObjectActor: aOptions.bindObjectActor,
michael@0 114 frameActor: aOptions.frameActor,
michael@0 115 url: aOptions.url,
michael@0 116 };
michael@0 117 this._client.request(packet, aOnResponse);
michael@0 118 },
michael@0 119
michael@0 120 /**
michael@0 121 * Autocomplete a JavaScript expression.
michael@0 122 *
michael@0 123 * @param string aString
michael@0 124 * The code you want to autocomplete.
michael@0 125 * @param number aCursor
michael@0 126 * Cursor location inside the string. Index starts from 0.
michael@0 127 * @param function aOnResponse
michael@0 128 * The function invoked when the response is received.
michael@0 129 * @param string aFrameActor
michael@0 130 * The id of the frame actor that made the call.
michael@0 131 */
michael@0 132 autocomplete: function WCC_autocomplete(aString, aCursor, aOnResponse, aFrameActor)
michael@0 133 {
michael@0 134 let packet = {
michael@0 135 to: this._actor,
michael@0 136 type: "autocomplete",
michael@0 137 text: aString,
michael@0 138 cursor: aCursor,
michael@0 139 frameActor: aFrameActor,
michael@0 140 };
michael@0 141 this._client.request(packet, aOnResponse);
michael@0 142 },
michael@0 143
michael@0 144 /**
michael@0 145 * Clear the cache of messages (page errors and console API calls).
michael@0 146 */
michael@0 147 clearMessagesCache: function WCC_clearMessagesCache()
michael@0 148 {
michael@0 149 let packet = {
michael@0 150 to: this._actor,
michael@0 151 type: "clearMessagesCache",
michael@0 152 };
michael@0 153 this._client.request(packet);
michael@0 154 },
michael@0 155
michael@0 156 /**
michael@0 157 * Get Web Console-related preferences on the server.
michael@0 158 *
michael@0 159 * @param array aPreferences
michael@0 160 * An array with the preferences you want to retrieve.
michael@0 161 * @param function [aOnResponse]
michael@0 162 * Optional function to invoke when the response is received.
michael@0 163 */
michael@0 164 getPreferences: function WCC_getPreferences(aPreferences, aOnResponse)
michael@0 165 {
michael@0 166 let packet = {
michael@0 167 to: this._actor,
michael@0 168 type: "getPreferences",
michael@0 169 preferences: aPreferences,
michael@0 170 };
michael@0 171 this._client.request(packet, aOnResponse);
michael@0 172 },
michael@0 173
michael@0 174 /**
michael@0 175 * Set Web Console-related preferences on the server.
michael@0 176 *
michael@0 177 * @param object aPreferences
michael@0 178 * An object with the preferences you want to change.
michael@0 179 * @param function [aOnResponse]
michael@0 180 * Optional function to invoke when the response is received.
michael@0 181 */
michael@0 182 setPreferences: function WCC_setPreferences(aPreferences, aOnResponse)
michael@0 183 {
michael@0 184 let packet = {
michael@0 185 to: this._actor,
michael@0 186 type: "setPreferences",
michael@0 187 preferences: aPreferences,
michael@0 188 };
michael@0 189 this._client.request(packet, aOnResponse);
michael@0 190 },
michael@0 191
michael@0 192 /**
michael@0 193 * Retrieve the request headers from the given NetworkEventActor.
michael@0 194 *
michael@0 195 * @param string aActor
michael@0 196 * The NetworkEventActor ID.
michael@0 197 * @param function aOnResponse
michael@0 198 * The function invoked when the response is received.
michael@0 199 */
michael@0 200 getRequestHeaders: function WCC_getRequestHeaders(aActor, aOnResponse)
michael@0 201 {
michael@0 202 let packet = {
michael@0 203 to: aActor,
michael@0 204 type: "getRequestHeaders",
michael@0 205 };
michael@0 206 this._client.request(packet, aOnResponse);
michael@0 207 },
michael@0 208
michael@0 209 /**
michael@0 210 * Retrieve the request cookies from the given NetworkEventActor.
michael@0 211 *
michael@0 212 * @param string aActor
michael@0 213 * The NetworkEventActor ID.
michael@0 214 * @param function aOnResponse
michael@0 215 * The function invoked when the response is received.
michael@0 216 */
michael@0 217 getRequestCookies: function WCC_getRequestCookies(aActor, aOnResponse)
michael@0 218 {
michael@0 219 let packet = {
michael@0 220 to: aActor,
michael@0 221 type: "getRequestCookies",
michael@0 222 };
michael@0 223 this._client.request(packet, aOnResponse);
michael@0 224 },
michael@0 225
michael@0 226 /**
michael@0 227 * Retrieve the request post data from the given NetworkEventActor.
michael@0 228 *
michael@0 229 * @param string aActor
michael@0 230 * The NetworkEventActor ID.
michael@0 231 * @param function aOnResponse
michael@0 232 * The function invoked when the response is received.
michael@0 233 */
michael@0 234 getRequestPostData: function WCC_getRequestPostData(aActor, aOnResponse)
michael@0 235 {
michael@0 236 let packet = {
michael@0 237 to: aActor,
michael@0 238 type: "getRequestPostData",
michael@0 239 };
michael@0 240 this._client.request(packet, aOnResponse);
michael@0 241 },
michael@0 242
michael@0 243 /**
michael@0 244 * Retrieve the response headers from the given NetworkEventActor.
michael@0 245 *
michael@0 246 * @param string aActor
michael@0 247 * The NetworkEventActor ID.
michael@0 248 * @param function aOnResponse
michael@0 249 * The function invoked when the response is received.
michael@0 250 */
michael@0 251 getResponseHeaders: function WCC_getResponseHeaders(aActor, aOnResponse)
michael@0 252 {
michael@0 253 let packet = {
michael@0 254 to: aActor,
michael@0 255 type: "getResponseHeaders",
michael@0 256 };
michael@0 257 this._client.request(packet, aOnResponse);
michael@0 258 },
michael@0 259
michael@0 260 /**
michael@0 261 * Retrieve the response cookies from the given NetworkEventActor.
michael@0 262 *
michael@0 263 * @param string aActor
michael@0 264 * The NetworkEventActor ID.
michael@0 265 * @param function aOnResponse
michael@0 266 * The function invoked when the response is received.
michael@0 267 */
michael@0 268 getResponseCookies: function WCC_getResponseCookies(aActor, aOnResponse)
michael@0 269 {
michael@0 270 let packet = {
michael@0 271 to: aActor,
michael@0 272 type: "getResponseCookies",
michael@0 273 };
michael@0 274 this._client.request(packet, aOnResponse);
michael@0 275 },
michael@0 276
michael@0 277 /**
michael@0 278 * Retrieve the response content from the given NetworkEventActor.
michael@0 279 *
michael@0 280 * @param string aActor
michael@0 281 * The NetworkEventActor ID.
michael@0 282 * @param function aOnResponse
michael@0 283 * The function invoked when the response is received.
michael@0 284 */
michael@0 285 getResponseContent: function WCC_getResponseContent(aActor, aOnResponse)
michael@0 286 {
michael@0 287 let packet = {
michael@0 288 to: aActor,
michael@0 289 type: "getResponseContent",
michael@0 290 };
michael@0 291 this._client.request(packet, aOnResponse);
michael@0 292 },
michael@0 293
michael@0 294 /**
michael@0 295 * Retrieve the timing information for the given NetworkEventActor.
michael@0 296 *
michael@0 297 * @param string aActor
michael@0 298 * The NetworkEventActor ID.
michael@0 299 * @param function aOnResponse
michael@0 300 * The function invoked when the response is received.
michael@0 301 */
michael@0 302 getEventTimings: function WCC_getEventTimings(aActor, aOnResponse)
michael@0 303 {
michael@0 304 let packet = {
michael@0 305 to: aActor,
michael@0 306 type: "getEventTimings",
michael@0 307 };
michael@0 308 this._client.request(packet, aOnResponse);
michael@0 309 },
michael@0 310
michael@0 311 /**
michael@0 312 * Send a HTTP request with the given data.
michael@0 313 *
michael@0 314 * @param string aData
michael@0 315 * The details of the HTTP request.
michael@0 316 * @param function aOnResponse
michael@0 317 * The function invoked when the response is received.
michael@0 318 */
michael@0 319 sendHTTPRequest: function WCC_sendHTTPRequest(aData, aOnResponse) {
michael@0 320 let packet = {
michael@0 321 to: this._actor,
michael@0 322 type: "sendHTTPRequest",
michael@0 323 request: aData
michael@0 324 };
michael@0 325 this._client.request(packet, aOnResponse);
michael@0 326 },
michael@0 327
michael@0 328 /**
michael@0 329 * Start the given Web Console listeners.
michael@0 330 *
michael@0 331 * @see this.LISTENERS
michael@0 332 * @param array aListeners
michael@0 333 * Array of listeners you want to start. See this.LISTENERS for
michael@0 334 * known listeners.
michael@0 335 * @param function aOnResponse
michael@0 336 * Function to invoke when the server response is received.
michael@0 337 */
michael@0 338 startListeners: function WCC_startListeners(aListeners, aOnResponse)
michael@0 339 {
michael@0 340 let packet = {
michael@0 341 to: this._actor,
michael@0 342 type: "startListeners",
michael@0 343 listeners: aListeners,
michael@0 344 };
michael@0 345 this._client.request(packet, aOnResponse);
michael@0 346 },
michael@0 347
michael@0 348 /**
michael@0 349 * Stop the given Web Console listeners.
michael@0 350 *
michael@0 351 * @see this.LISTENERS
michael@0 352 * @param array aListeners
michael@0 353 * Array of listeners you want to stop. See this.LISTENERS for
michael@0 354 * known listeners.
michael@0 355 * @param function aOnResponse
michael@0 356 * Function to invoke when the server response is received.
michael@0 357 */
michael@0 358 stopListeners: function WCC_stopListeners(aListeners, aOnResponse)
michael@0 359 {
michael@0 360 let packet = {
michael@0 361 to: this._actor,
michael@0 362 type: "stopListeners",
michael@0 363 listeners: aListeners,
michael@0 364 };
michael@0 365 this._client.request(packet, aOnResponse);
michael@0 366 },
michael@0 367
michael@0 368 /**
michael@0 369 * Return an instance of LongStringClient for the given long string grip.
michael@0 370 *
michael@0 371 * @param object aGrip
michael@0 372 * The long string grip returned by the protocol.
michael@0 373 * @return object
michael@0 374 * The LongStringClient for the given long string grip.
michael@0 375 */
michael@0 376 longString: function WCC_longString(aGrip)
michael@0 377 {
michael@0 378 if (aGrip.actor in this._longStrings) {
michael@0 379 return this._longStrings[aGrip.actor];
michael@0 380 }
michael@0 381
michael@0 382 let client = new LongStringClient(this._client, aGrip);
michael@0 383 this._longStrings[aGrip.actor] = client;
michael@0 384 return client;
michael@0 385 },
michael@0 386
michael@0 387 /**
michael@0 388 * Close the WebConsoleClient. This stops all the listeners on the server and
michael@0 389 * detaches from the console actor.
michael@0 390 *
michael@0 391 * @param function aOnResponse
michael@0 392 * Function to invoke when the server response is received.
michael@0 393 */
michael@0 394 close: function WCC_close(aOnResponse)
michael@0 395 {
michael@0 396 this.stopListeners(null, aOnResponse);
michael@0 397 this._longStrings = null;
michael@0 398 this._client = null;
michael@0 399 },
michael@0 400 };

mercurial