toolkit/devtools/webconsole/client.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial