Bug 1171408 - Move NetworkEventsHandler.getString into WebConsoleClient. r=past
authorJan Odvarko <odvarko@gmail.com>
Wed, 17 Jun 2015 16:27:20 +0200
changeset 280166 0859b5b72ea52d66ed4d46911647c59533e1fd6d
parent 280165 040a407b070561ecda0b0b80968117a843bf7ea6
child 280167 7a7b4d0dc56544248a30ec2429c08c05d16c89b7
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs1171408
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1171408 - Move NetworkEventsHandler.getString into WebConsoleClient. r=past
browser/devtools/netmonitor/netmonitor-controller.js
toolkit/devtools/webconsole/client.js
--- a/browser/devtools/netmonitor/netmonitor-controller.js
+++ b/browser/devtools/netmonitor/netmonitor-controller.js
@@ -708,39 +708,17 @@ NetworkEventsHandler.prototype = {
    *        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.
    */
   getString: function(aStringGrip) {
-    // Make sure this is a long string.
-    if (typeof aStringGrip != "object" || aStringGrip.type != "longString") {
-      return promise.resolve(aStringGrip); // Go home string, you're drunk.
-    }
-    // Fetch the long string only once.
-    if (aStringGrip._fullText) {
-      return aStringGrip._fullText.promise;
-    }
-
-    let deferred = aStringGrip._fullText = promise.defer();
-    let { actor, initial, length } = aStringGrip;
-    let longStringClient = this.webConsoleClient.longString(aStringGrip);
-
-    longStringClient.substring(initial.length, length, aResponse => {
-      if (aResponse.error) {
-        Cu.reportError(aResponse.error + ": " + aResponse.message);
-        deferred.reject(aResponse);
-        return;
-      }
-      deferred.resolve(initial + aResponse.substring);
-    });
-
-    return deferred.promise;
+    return this.webConsoleClient.getString(aStringGrip);
   }
 };
 
 /**
  * Localization convenience methods.
  */
 let L10N = new ViewHelpers.L10N(NET_STRINGS_URI);
 let PKI_L10N = new ViewHelpers.L10N(PKI_STRINGS_URI);
--- a/toolkit/devtools/webconsole/client.js
+++ b/toolkit/devtools/webconsole/client.js
@@ -4,16 +4,17 @@
  * 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";
 
 const {Cc, Ci, Cu} = require("chrome");
 const DevToolsUtils = require("devtools/toolkit/DevToolsUtils");
 const EventEmitter = require("devtools/toolkit/event-emitter");
+const promise = require("promise");
 
 loader.lazyImporter(this, "LongStringClient", "resource://gre/modules/devtools/dbg-client.jsm");
 
 /**
  * A WebConsoleClient is used as a front end for the WebConsoleActor that is
  * created on the server, hiding implementation details.
  *
  * @param object aDebuggerClient
@@ -609,10 +610,50 @@ WebConsoleClient.prototype = {
     this.pendingEvaluationResults.clear();
     this.pendingEvaluationResults = null;
     this.clearNetworkRequests();
     this._networkRequests = null;
   },
 
   clearNetworkRequests: function () {
     this._networkRequests.clear();
+  },
+
+  /**
+   * 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.
+   */
+  getString: function(stringGrip) {
+    // Make sure this is a long string.
+    if (typeof stringGrip != "object" || stringGrip.type != "longString") {
+      return promise.resolve(stringGrip); // Go home string, you're drunk.
+    }
+
+    // Fetch the long string only once.
+    if (stringGrip._fullText) {
+      return stringGrip._fullText.promise;
+    }
+
+    let deferred = stringGrip._fullText = promise.defer();
+    let { actor, initial, length } = stringGrip;
+    let longStringClient = this.longString(stringGrip);
+
+    longStringClient.substring(initial.length, length, aResponse => {
+      if (aResponse.error) {
+        DevToolsUtils.reportException("getString",
+            aResponse.error + ": " + aResponse.message);
+
+        deferred.reject(aResponse);
+        return;
+      }
+      deferred.resolve(initial + aResponse.substring);
+    });
+
+    return deferred.promise;
   }
 };