Bug 1407515 - make sure post data is suplied to Open in New Tab draft
authorTom Glowka <glowka.tom@gmail.com>
Thu, 29 Mar 2018 11:40:11 +0200
changeset 775111 8adf587744cc
parent 774444 6aa3b57955fe
child 775112 9ba01ea8f145
push id104611
push userbmo:glowka.tom@gmail.com
push dateFri, 30 Mar 2018 03:02:03 +0000
bugs1407515
milestone61.0a1
Bug 1407515 - make sure post data is suplied to Open in New Tab MozReview-Commit-ID: JqqS7ZhLrr7
devtools/client/netmonitor/src/utils/firefox/open-request-in-tab.js
devtools/client/netmonitor/src/utils/open-request-in-tab.js
devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
--- a/devtools/client/netmonitor/src/utils/firefox/open-request-in-tab.js
+++ b/devtools/client/netmonitor/src/utils/firefox/open-request-in-tab.js
@@ -7,30 +7,30 @@
 
 let { Cc, Ci } = require("chrome");
 const Services = require("Services");
 const { gDevTools } = require("devtools/client/framework/devtools");
 
 /**
  * Opens given request in a new tab.
  */
-function openRequestInTab(request) {
+function openRequestInTab(url, method, requestPostData) {
   let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
-  let rawData = request.requestPostData ? request.requestPostData.postData : null;
+  let rawData = requestPostData ? requestPostData.postData : null;
   let postData;
 
   if (rawData && rawData.text) {
     let stringStream = getInputStreamFromString(rawData.text);
     postData = Cc["@mozilla.org/network/mime-input-stream;1"]
       .createInstance(Ci.nsIMIMEInputStream);
     postData.addHeader("Content-Type", "application/x-www-form-urlencoded");
     postData.setData(stringStream);
   }
 
-  win.gBrowser.selectedTab = win.gBrowser.addTab(request.url, null, null, postData);
+  win.gBrowser.selectedTab = win.gBrowser.addTab(url, null, null, postData);
 }
 
 function getInputStreamFromString(data) {
   let stringStream = Cc["@mozilla.org/io/string-input-stream;1"]
     .createInstance(Ci.nsIStringInputStream);
   stringStream.data = data;
   return stringStream;
 }
--- a/devtools/client/netmonitor/src/utils/open-request-in-tab.js
+++ b/devtools/client/netmonitor/src/utils/open-request-in-tab.js
@@ -5,27 +5,25 @@
 "use strict";
 
 const Services = require("Services");
 const { gDevTools } = require("devtools/client/framework/devtools");
 
 /**
  * Opens given request in a new tab.
  */
-function openRequestInTab(request) {
+function openRequestInTab(url, method, requestPostData) {
   let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
-  if (request.method.toLowerCase() !== "get") {
-    win.openUILinkIn(this.selectedRequest.url, "tab", {
-      relatedToCurrent: true
-    });
+  if (method.toLowerCase() !== "get") {
+    win.openUILinkIn(url, "tab", {relatedToCurrent: true});
   } else {
     openRequestInTabHelper({
-      url: request.url,
-      method: request.method,
-      data: request.requestPostData ? request.requestPostData.postData : null,
+      url,
+      method,
+      data: requestPostData ? requestPostData.postData : null,
     });
   }
 }
 
 function openRequestInTabHelper({url, method, data}) {
   let form = document.createElement("form");
   form.target = "_blank";
   form.action = url;
--- a/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
+++ b/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
@@ -189,17 +189,17 @@ class RequestListContextMenu {
       visible: copySubmenu.slice(15, 16).some((subMenu) => subMenu.visible),
     });
 
     menu.push({
       id: "request-list-context-newtab",
       label: L10N.getStr("netmonitor.context.newTab"),
       accesskey: L10N.getStr("netmonitor.context.newTab.accesskey"),
       visible: !!selectedRequest,
-      click: () => this.openRequestInTab(selectedRequest),
+      click: () => this.openRequestInTab(id, url, method, requestPostData),
     });
 
     menu.push({
       id: "request-list-context-open-in-debugger",
       label: L10N.getStr("netmonitor.context.openInDebugger"),
       accesskey: L10N.getStr("netmonitor.context.openInDebugger.accesskey"),
       visible: !!(selectedRequest && mimeType && mimeType.includes("javascript")),
       click: () => this.openInDebugger(url),
@@ -224,18 +224,20 @@ class RequestListContextMenu {
     });
 
     showMenu(event, menu);
   }
 
   /**
    * Opens selected item in a new tab.
    */
-  openRequestInTab(selectedRequest) {
-    openRequestInTab(selectedRequest);
+  async openRequestInTab(id, url, method, requestPostData) {
+    requestPostData = requestPostData ||
+      await this.props.connector.requestData(id, "requestPostData");
+    openRequestInTab(url, method, requestPostData);
   }
 
   /**
    * Opens selected item in the debugger
    */
   openInDebugger(url) {
     let toolbox = gDevTools.getToolbox(this.props.connector.getTabTarget());
     toolbox.viewSourceInDebugger(url, 0);