Bug 1434855 - Refactor HAR builder options; r=ochameau
☠☠ backed out by 4d03290053fc ☠ ☠
authorJan Odvarko <odvarko@gmail.com>
Wed, 07 Mar 2018 13:33:19 +0100
changeset 406942 a87683b497417dc70f61389ef3280134d600af81
parent 406941 e1ae4f79fd6c2acf2c92233edb62fbfbf97ca30e
child 406943 ceea3f9776b1887dcfe3135778b8234b38f9f0d8
push id60748
push userjodvarko@mozilla.com
push dateWed, 07 Mar 2018 16:35:04 +0000
treeherderautoland@ceea3f9776b1 [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: A6wd5LvD19J
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;