Bug 1129957 - RemoteWebNavigation doesn't accept postdata or headers. r=Mossop

This commit is contained in:
Neil Rashbrook 2015-05-12 23:33:00 -03:00
parent f9a6bbeab5
commit 67ddd58239
5 changed files with 38 additions and 7 deletions

View File

@ -866,11 +866,14 @@ function _loadURIWithFlags(browser, uri, params) {
referrer, referrerPolicy,
postdata, null, null);
} else {
if (postData)
postData = NetUtil.readInputStreamToString(postData, postData.available());
LoadInOtherProcess(browser, {
uri: uri,
flags: flags,
referrer: referrer ? referrer.spec : null,
referrerPolicy: referrerPolicy,
postData: postData,
});
}
} catch (e) {

View File

@ -203,9 +203,11 @@ ContentRestoreInternal.prototype = {
let referrerPolicy = ('referrerPolicy' in loadArguments
? loadArguments.referrerPolicy
: Ci.nsIHttpChannel.REFERRER_POLICY_DEFAULT);
let postData = loadArguments.postData ?
Utils.makeInputStream(loadArguments.postData) : null;
webNavigation.loadURIWithOptions(loadArguments.uri, loadArguments.flags,
referrer, referrerPolicy, null, null,
null);
referrer, referrerPolicy, postData,
null, null);
} else if (tabData.userTypedValue && tabData.userTypedClear) {
// If the user typed a URL into the URL bar and hit enter right before
// we crashed, we want to start loading that page again. A non-zero

View File

@ -7,6 +7,8 @@
this.EXPORTED_SYMBOLS = ["Utils"];
const Cu = Components.utils;
const Cc = Components.classes;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm", this);
@ -15,6 +17,13 @@ this.Utils = Object.freeze({
return Services.io.newURI(url, null, null);
},
makeInputStream: function (aString) {
let stream = Cc["@mozilla.org/io/string-input-stream;1"].
createInstance(Ci.nsISupportsCString);
stream.data = aString;
return stream; // XPConnect will QI this to nsIInputStream for us.
},
/**
* Returns true if the |url| passed in is part of the given root |domain|.
* For example, if |url| is "www.mozilla.org", and we pass in |domain| as

View File

@ -21,6 +21,13 @@ if (AppConstants.MOZ_CRASHREPORTER) {
"nsICrashReporter");
}
function makeInputStream(aString) {
let stream = Cc["@mozilla.org/io/string-input-stream;1"].
createInstance(Ci.nsISupportsCString);
stream.data = aString;
return stream; // XPConnect will QI this to nsIInputStream for us.
}
let WebProgressListener = {
init: function() {
this._filter = Cc["@mozilla.org/appshell/component/browser-status-filter;1"]
@ -234,6 +241,7 @@ let WebNavigation = {
case "WebNavigation:LoadURI":
this.loadURI(message.data.uri, message.data.flags,
message.data.referrer, message.data.referrerPolicy,
message.data.postData, message.data.headers,
message.data.baseURI);
break;
case "WebNavigation:Reload":
@ -260,15 +268,19 @@ let WebNavigation = {
this.webNavigation.gotoIndex(index);
},
loadURI: function(uri, flags, referrer, referrerPolicy, baseURI) {
loadURI: function(uri, flags, referrer, referrerPolicy, postData, headers, baseURI) {
if (AppConstants.MOZ_CRASHREPORTER && CrashReporter.enabled)
CrashReporter.annotateCrashReport("URL", uri);
if (referrer)
referrer = Services.io.newURI(referrer, null, null);
if (postData)
postData = makeInputStream(postData);
if (headers)
headers = makeInputStream(headers);
if (baseURI)
baseURI = Services.io.newURI(baseURI, null, null);
this.webNavigation.loadURIWithOptions(uri, flags, referrer, referrerPolicy,
null, null, baseURI);
postData, headers, baseURI);
},
reload: function(flags) {

View File

@ -16,6 +16,12 @@ function makeURI(url)
newURI(url, null, null);
}
function readInputStreamToString(aStream)
{
Cu.import("resource://gre/modules/NetUtil.jsm");
return NetUtil.readInputStreamToString(aStream, aStream.available());
}
function RemoteWebNavigation(browser)
{
this.swapBrowser(browser);
@ -73,14 +79,13 @@ RemoteWebNavigation.prototype = {
},
loadURIWithOptions: function(aURI, aLoadFlags, aReferrer, aReferrerPolicy,
aPostData, aHeaders, aBaseURI) {
if (aPostData || aHeaders)
throw Components.Exception("RemoteWebNavigation doesn't accept postdata or headers.", Cr.NS_ERROR_INVALID_ARGS);
this._sendMessage("WebNavigation:LoadURI", {
uri: aURI,
flags: aLoadFlags,
referrer: aReferrer ? aReferrer.spec : null,
referrerPolicy: aReferrerPolicy,
postData: aPostData ? readInputStreamToString(aPostData) : null,
headers: aHeaders ? readInputStreamToString(aHeaders) : null,
baseURI: aBaseURI ? aBaseURI.spec : null,
});
},