зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1220758 - Properly pass postData into new tab; r=rickychien
MozReview-Commit-ID: HB5Sl8gvPGp --HG-- extra : rebase_source : 7a3f63af12f9da54acf15325f53de97e5b45ebd1
This commit is contained in:
Родитель
4577fc1a90
Коммит
a11d1e703d
|
@ -11,6 +11,7 @@ const { saveAs } = require("devtools/client/shared/file-saver");
|
|||
const { copyString } = require("devtools/shared/platform/clipboard");
|
||||
const { showMenu } = require("devtools/client/netmonitor/src/utils/menu");
|
||||
const { HarExporter } = require("./har/har-exporter");
|
||||
const { openRequestInTab } = require("devtools/client/netmonitor/src/utils/firefox/open-request-in-tab");
|
||||
const {
|
||||
getSelectedRequest,
|
||||
getSortedRequests,
|
||||
|
@ -182,7 +183,7 @@ class RequestListContextMenu {
|
|||
label: L10N.getStr("netmonitor.context.newTab"),
|
||||
accesskey: L10N.getStr("netmonitor.context.newTab.accesskey"),
|
||||
visible: !!selectedRequest,
|
||||
click: () => this.openRequestInTab(url),
|
||||
click: () => this.openRequestInTab(selectedRequest),
|
||||
});
|
||||
|
||||
menu.push({
|
||||
|
@ -217,9 +218,8 @@ class RequestListContextMenu {
|
|||
/**
|
||||
* Opens selected item in a new tab.
|
||||
*/
|
||||
openRequestInTab(url) {
|
||||
let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
|
||||
win.openUILinkIn(url, "tab", { relatedToCurrent: true });
|
||||
openRequestInTab(selectedRequest) {
|
||||
openRequestInTab(selectedRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
DevToolsModules(
|
||||
'open-request-in-tab.js',
|
||||
)
|
|
@ -0,0 +1,40 @@
|
|||
/* 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/. */
|
||||
/* eslint-disable mozilla/reject-some-requires */
|
||||
|
||||
"use strict";
|
||||
|
||||
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) {
|
||||
let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
|
||||
let rawData = request.requestPostData ? request.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);
|
||||
}
|
||||
|
||||
function getInputStreamFromString(data) {
|
||||
let stringStream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
stringStream.data = data;
|
||||
return stringStream;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
openRequestInTab,
|
||||
};
|
|
@ -3,6 +3,10 @@
|
|||
# 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/.
|
||||
|
||||
DIRS += [
|
||||
'firefox',
|
||||
]
|
||||
|
||||
DevToolsModules(
|
||||
'create-store.js',
|
||||
'filter-autocomplete-provider.js',
|
||||
|
@ -12,6 +16,7 @@ DevToolsModules(
|
|||
'l10n.js',
|
||||
'mdn-utils.js',
|
||||
'menu.js',
|
||||
'open-request-in-tab.js',
|
||||
'prefs.js',
|
||||
'request-utils.js',
|
||||
'sort-predicates.js',
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/* 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");
|
||||
const { gDevTools } = require("devtools/client/framework/devtools");
|
||||
|
||||
/**
|
||||
* Opens given request in a new tab.
|
||||
*/
|
||||
function openRequestInTab(request) {
|
||||
let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
|
||||
if (request.method.toLowerCase() !== "get") {
|
||||
win.openUILinkIn(this.selectedRequest.url, "tab", {
|
||||
relatedToCurrent: true
|
||||
});
|
||||
} else {
|
||||
openRequestInTabHelper({
|
||||
url: request.url,
|
||||
method: request.method,
|
||||
data: request.requestPostData ? request.requestPostData.postData : null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function openRequestInTabHelper({url, method, data}) {
|
||||
let form = document.createElement("form");
|
||||
form.target = "_blank";
|
||||
form.action = url;
|
||||
form.method = method;
|
||||
|
||||
if (data) {
|
||||
for (let key in data) {
|
||||
let input = document.createElement("input");
|
||||
input.name = key;
|
||||
input.value = data[key];
|
||||
form.appendChild(input);
|
||||
}
|
||||
}
|
||||
|
||||
form.hidden = true;
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
form.remove();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
openRequestInTab,
|
||||
};
|
|
@ -86,6 +86,7 @@ let webpackConfig = {
|
|||
"devtools/shared/old-event-emitter": "devtools-modules/src/utils/event-emitter",
|
||||
"devtools/shared/fronts/timeline": path.join(__dirname, "../../client/shared/webpack/shims/fronts-timeline-shim"),
|
||||
"devtools/shared/platform/clipboard": path.join(__dirname, "../../client/shared/webpack/shims/platform-clipboard-stub"),
|
||||
"devtools/client/netmonitor/src/utils/firefox/open-request-in-tab": path.join(__dirname, "src/utils/open-request-in-tab"),
|
||||
|
||||
// Locales need to be explicitly mapped to the en-US subfolder
|
||||
"devtools/client/locales": path.join(__dirname, "../../client/locales/en-US"),
|
||||
|
|
Загрузка…
Ссылка в новой задаче