Bug 1373594 - Fix broken automatic HAR logs exported r?honza draft
authorRicky Chien <ricky060709@gmail.com>
Tue, 20 Jun 2017 17:58:09 +0800
changeset 597274 455c118b05f3aa0b2588606dd1f4ea1de4d5365b
parent 597026 416c3c8c4b3db9ba96a103ce7820c9a140a3051d
child 634185 6af994d76821aff02382dfe0823b82ea8156133a
push id64883
push userbmo:rchien@mozilla.com
push dateTue, 20 Jun 2017 09:59:08 +0000
reviewershonza
bugs1373594
milestone56.0a1
Bug 1373594 - Fix broken automatic HAR logs exported r?honza MozReview-Commit-ID: LEWZsBYk9vT
devtools/client/netmonitor/src/har/har-automation.js
devtools/client/netmonitor/src/har/har-builder.js
devtools/client/netmonitor/src/har/har-collector.js
devtools/client/netmonitor/src/har/toolbox-overlay.js
devtools/shared/webconsole/client.js
--- a/devtools/client/netmonitor/src/har/har-automation.js
+++ b/devtools/client/netmonitor/src/har/har-automation.js
@@ -3,20 +3,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* eslint-disable mozilla/reject-some-requires */
 
 "use strict";
 
 const { Ci } = require("chrome");
 const Services = require("Services");
-
-loader.lazyRequireGetter(this, "HarCollector", "devtools/client/netmonitor/har/har-collector", true);
-loader.lazyRequireGetter(this, "HarExporter", "devtools/client/netmonitor/har/har-exporter", true);
-loader.lazyRequireGetter(this, "HarUtils", "devtools/client/netmonitor/har/har-utils", true);
+const { HarCollector } = require("./har-collector");
+const { HarExporter } = require("./har-exporter");
+const { HarUtils } = require("./har-utils");
 
 const prefDomain = "devtools.netmonitor.har.";
 
 // Helper tracer. Should be generic sharable by other modules (bug 1171927)
 const trace = {
   log: function (...args) {
   }
 };
--- a/devtools/client/netmonitor/src/har/har-builder.js
+++ b/devtools/client/netmonitor/src/har/har-builder.js
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const Services = require("Services");
 const appInfo = Services.appinfo;
 const { LocalizationHelper } = require("devtools/shared/l10n");
 const { CurlUtils } = require("devtools/client/shared/curl");
-const { getLongString } = require("../connector/index");
 const {
   getFormDataSections,
   getUrlQuery,
   parseQueryString,
 } = require("../utils/request-utils");
 
 const L10N = new LocalizationHelper("devtools/client/locales/har.properties");
 const HAR_VERSION = "1.1";
@@ -265,17 +264,17 @@ HarBuilder.prototype = {
       if (CurlUtils.isUrlEncodedRequest({ headers, postDataText })) {
         postData.mimeType = "application/x-www-form-urlencoded";
 
         // Extract form parameters and produce nice HAR array.
         getFormDataSections(
           file.requestHeaders,
           file.requestHeadersFromUploadStream,
           file.requestPostData,
-          getLongString,
+          this._options.getString,
         ).then(formDataSections => {
           formDataSections.forEach(section => {
             let paramsArray = parseQueryString(section);
             if (paramsArray) {
               postData.params = [...postData.params, ...paramsArray];
             }
           });
         });
--- a/devtools/client/netmonitor/src/har/har-collector.js
+++ b/devtools/client/netmonitor/src/har/har-collector.js
@@ -79,25 +79,26 @@ HarCollector.prototype = {
     // process of HTTP data collection.
     return waitForAll(this.requests).then(() => {
       // All responses are received from the backend now. We yet need to
       // wait for a little while to see if a new request appears. If yes,
       // lets's start gathering HTTP data again. If no, we can declare
       // the page loaded.
       // If some new requests appears in the meantime the promise will
       // be rejected and we need to wait for responses all over again.
-      return this.waitForTimeout().then(() => {
+
+      this.pageLoadDeferred = this.waitForTimeout().then(() => {
         // Page loaded!
       }, () => {
         trace.log("HarCollector.waitForResponses; NEW requests " +
           "appeared during page timeout!");
-
         // New requests executed, let's wait again.
         return this.waitForResponses();
       });
+      return this.pageLoadDeferred;
     });
   },
 
   // Page Loaded Timeout
 
   /**
    * The page is loaded when there are no new requests within given period
    * of time. The time is set in preferences:
@@ -107,20 +108,21 @@ HarCollector.prototype = {
     // The auto-export is not done if the timeout is set to zero (or less).
     // This is useful in cases where the export is done manually through
     // API exposed to the content.
     let timeout = Services.prefs.getIntPref(
       "devtools.netmonitor.har.pageLoadedTimeout");
 
     trace.log("HarCollector.waitForTimeout; " + timeout);
 
-    return new Promise((resolve) => {
+    return new Promise((resolve, reject) => {
       if (timeout <= 0) {
         resolve();
       }
+      this.pageLoadReject = reject;
       this.pageLoadTimeout = setTimeout(() => {
         trace.log("HarCollector.onPageLoadTimeout;");
         resolve();
       }, timeout);
     });
   },
 
   resetPageLoadTimeout: function () {
@@ -128,19 +130,19 @@ HarCollector.prototype = {
     if (this.pageLoadTimeout) {
       trace.log("HarCollector.resetPageLoadTimeout;");
 
       clearTimeout(this.pageLoadTimeout);
       this.pageLoadTimeout = null;
     }
 
     // Reject the current page load promise
-    if (this.pageLoadDeferred) {
-      this.pageLoadDeferred.reject();
-      this.pageLoadDeferred = null;
+    if (this.pageLoadReject) {
+      this.pageLoadReject();
+      this.pageLoadReject = null;
     }
   },
 
   // Collected Data
 
   getFile: function (actorId) {
     return this.files.get(actorId);
   },
@@ -435,14 +437,15 @@ function waitForAll(promises) {
 
   // Wait for all promises in the given array.
   return Promise.all(clone).then(() => {
     // If there are new promises (in the original array)
     // to wait for - chain them!
     if (promises.length) {
       return waitForAll(promises);
     }
+
     return undefined;
   });
 }
 
 // Exports from this module
 exports.HarCollector = HarCollector;
--- a/devtools/client/netmonitor/src/har/toolbox-overlay.js
+++ b/devtools/client/netmonitor/src/har/toolbox-overlay.js
@@ -1,17 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 Services = require("Services");
 
-loader.lazyRequireGetter(this, "HarAutomation", "devtools/client/netmonitor/har/har-automation", true);
+loader.lazyRequireGetter(this, "HarAutomation", "devtools/client/netmonitor/src/har/har-automation", true);
 
 // Map of all created overlays. There is always one instance of
 // an overlay per Toolbox instance (i.e. one per browser tab).
 const overlays = new WeakMap();
 
 /**
  * This object is responsible for initialization and cleanup for HAR
  * export feature. It represents an overlay for the Toolbox
--- a/devtools/shared/webconsole/client.js
+++ b/devtools/shared/webconsole/client.js
@@ -3,18 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 DevToolsUtils = require("devtools/shared/DevToolsUtils");
 const EventEmitter = require("devtools/shared/event-emitter");
-const promise = require("promise");
-const defer = require("devtools/shared/defer");
 const {LongStringClient} = require("devtools/shared/client/main");
 
 /**
  * A WebConsoleClient is used as a front end for the WebConsoleActor that is
  * created on the server, hiding implementation details.
  *
  * @param object debuggerClient
  *        The DebuggerClient instance we live for.
@@ -681,36 +679,33 @@ WebConsoleClient.prototype = {
    *        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") {
+    if (typeof stringGrip !== "object" || stringGrip.type !== "longString") {
       // Go home string, you're drunk.
-      return promise.resolve(stringGrip);
+      return Promise.resolve(stringGrip);
     }
 
     // Fetch the long string only once.
     if (stringGrip._fullText) {
-      return stringGrip._fullText.promise;
+      return stringGrip._fullText;
     }
 
-    let deferred = stringGrip._fullText = defer();
-    let { initial, length } = stringGrip;
-    let longStringClient = this.longString(stringGrip);
+    return new Promise((resolve, reject) => {
+      let { initial, length } = stringGrip;
+      let longStringClient = this.longString(stringGrip);
 
-    longStringClient.substring(initial.length, length, response => {
-      if (response.error) {
-        DevToolsUtils.reportException("getString",
-            response.error + ": " + response.message);
-
-        deferred.reject(response);
-        return;
-      }
-      deferred.resolve(initial + response.substring);
+      longStringClient.substring(initial.length, length, response => {
+        if (response.error) {
+          DevToolsUtils.reportException("getString",
+              response.error + ": " + response.message);
+          reject(response);
+        }
+        resolve(initial + response.substring);
+      });
     });
-
-    return deferred.promise;
   }
 };