Bug 1434855 - Refactor HAR builder options; r=ochameau
authorJan Odvarko <odvarko@gmail.com>
Thu, 08 Mar 2018 10:07:45 +0100
changeset 407147 73628e4869b31f1d06ebda2c8ea46ae038705bb9
parent 407146 d15070cd21f43663e2a432839b76b316db79cbeb
child 407148 470c96bdde515239728d90e12c7bae067884f909
push id60820
push userjodvarko@mozilla.com
push dateThu, 08 Mar 2018 11:49:46 +0000
treeherderautoland@470c96bdde51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1434855
milestone60.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 1434855 - Refactor HAR builder options; r=ochameau MozReview-Commit-ID: FRcxp4XPFdf
devtools/client/netmonitor/initializer.js
devtools/client/netmonitor/src/har/har-exporter.js
devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
--- a/devtools/client/netmonitor/initializer.js
+++ b/devtools/client/netmonitor/initializer.js
@@ -100,54 +100,39 @@ window.Netmonitor = {
 
   // Support for WebExtensions API
 
   /**
    * Support for `devtools.network.getHAR` (get collected data as HAR)
    */
   getHar() {
     let { HarExporter } = require("devtools/client/netmonitor/src/har/har-exporter");
-    let {
-      getLongString,
-      getTabTarget,
-      getTimingMarker,
-      requestData,
-    } = connector;
-    let { form: { title, url } } = getTabTarget();
     let state = store.getState();
 
     let options = {
-      getString: getLongString,
+      connector,
       items: getSortedRequests(state),
-      requestData,
-      getTimingMarker,
-      title: title || url,
     };
 
     return HarExporter.getHar(options);
   },
 
   /**
    * Support for `devtools.network.onRequestFinished`. A hook for
    * every finished HTTP request used by WebExtensions API.
    */
   onRequestAdded(event, requestId) {
     let listeners = this.toolbox.getRequestFinishedListeners();
     if (!listeners.size) {
       return;
     }
 
     let { HarExporter } = require("devtools/client/netmonitor/src/har/har-exporter");
-    let { getLongString, getTabTarget, requestData } = connector;
-    let { form: { title, url } } = getTabTarget();
-
     let options = {
-      getString: getLongString,
-      requestData,
-      title: title || url,
+      connector,
       includeResponseBodies: false,
       items: [getDisplayedRequestById(store.getState(), requestId)],
     };
 
     // Build HAR for specified request only.
     HarExporter.getHar(options).then(har => {
       let harEntry = har.log.entries[0];
       delete harEntry.pageref;
--- a/devtools/client/netmonitor/src/har/har-exporter.js
+++ b/devtools/client/netmonitor/src/har/har-exporter.js
@@ -181,20 +181,38 @@ const HarExporter = {
   },
 
   /**
    * Build HAR data object. This object contains all HTTP data
    * collected by the Network panel. The process is asynchronous
    * since it can involve additional RDP communication (e.g. resolving
    * long strings).
    */
-  buildHarData: function (options) {
+  buildHarData: async function (options) {
+    let { connector } = options;
+    let {
+      getTabTarget,
+    } = connector;
+    let {
+      form: { title, url }
+    } = getTabTarget();
+
+    options = {
+      ...options,
+      title: title || url,
+      getString: connector.getLongString,
+      getTimingMarker: connector.getTimingMarker,
+      requestData: connector.requestData,
+    };
+
     // Build HAR object from collected data.
     let builder = new HarBuilder(options);
-    return builder.build();
+    let result = await builder.build();
+
+    return result;
   },
 
   /**
    * Build JSON string from the HAR data object.
    */
   stringify: function (har) {
     if (!har) {
       return null;
--- a/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
+++ b/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
@@ -404,27 +404,16 @@ class RequestListContextMenu {
     // This will not work in launchpad
     // document.execCommand(‘cut’/‘copy’) was denied because it was not called from
     // inside a short running user-generated event handler.
     // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Interact_with_the_clipboard
     return HarExporter.save(this.getDefaultHarOptions(sortedRequests));
   }
 
   getDefaultHarOptions(sortedRequests) {
-    let {
-      getLongString,
-      getTabTarget,
-      requestData,
-      getTimingMarker,
-    } = this.props.connector;
-    let { form: { title, url } } = getTabTarget();
-
     return {
-      getString: getLongString,
+      connector: this.props.connector,
       items: sortedRequests,
-      requestData,
-      getTimingMarker,
-      title: title || url,
     };
   }
 }
 
 module.exports = RequestListContextMenu;