зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 2 changesets (bug 1771423) for causing webcompat regressions CLOSED TREE
Backed out changeset c1d1be434427 (bug 1771423) Backed out changeset 2b7d886f374f (bug 1771423)
This commit is contained in:
Родитель
cd79769a82
Коммит
dff4f6d15e
|
@ -1027,13 +1027,13 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest) {
|
|||
if (NS_SUCCEEDED(rv) && !contentCharset.IsEmpty()) {
|
||||
contentType += ";charset="_ns + contentCharset;
|
||||
}
|
||||
|
||||
IgnoredErrorResult result;
|
||||
response->Headers()->Append("Content-Type"_ns, contentType, result);
|
||||
MOZ_ASSERT(!result.Failed());
|
||||
}
|
||||
|
||||
IgnoredErrorResult result;
|
||||
response->Headers()->Append("Content-Type"_ns, contentType, result);
|
||||
MOZ_ASSERT(!result.Failed());
|
||||
|
||||
if (contentLength >= 0) {
|
||||
if (contentLength > 0) {
|
||||
nsAutoCString contentLenStr;
|
||||
contentLenStr.AppendInt(contentLength);
|
||||
|
||||
|
|
|
@ -26,18 +26,6 @@ BlobURLChannel::BlobURLChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo)
|
|||
|
||||
BlobURLChannel::~BlobURLChannel() = default;
|
||||
|
||||
NS_IMETHODIMP
|
||||
BlobURLChannel::SetContentType(const nsACString& aContentType) {
|
||||
// If the blob type is empty, set the content type of the channel to the
|
||||
// empty string.
|
||||
if (aContentType.IsEmpty()) {
|
||||
mContentType.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsBaseChannel::SetContentType(aContentType);
|
||||
}
|
||||
|
||||
nsresult BlobURLChannel::OpenContentStream(bool aAsync,
|
||||
nsIInputStream** aResult,
|
||||
nsIChannel** aChannel) {
|
||||
|
|
|
@ -21,8 +21,6 @@ class BlobURLChannel final : public nsBaseChannel {
|
|||
public:
|
||||
BlobURLChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo);
|
||||
|
||||
NS_IMETHOD SetContentType(const nsACString& aContentType) override;
|
||||
|
||||
private:
|
||||
~BlobURLChannel() override;
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/IPCBlobUtils.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "nsMimeTypes.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
|
||||
|
@ -462,21 +461,9 @@ nsresult BlobURLInputStream::StoreBlobImplStream(
|
|||
already_AddRefed<BlobImpl> aBlobImpl, const MutexAutoLock& aProofOfLock) {
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread");
|
||||
const RefPtr<BlobImpl> blobImpl = aBlobImpl;
|
||||
nsAutoString blobContentType;
|
||||
nsAutoCString channelContentType;
|
||||
|
||||
blobImpl->GetType(blobContentType);
|
||||
mChannel->GetContentType(channelContentType);
|
||||
// A empty content type is the correct channel content type in the case of a
|
||||
// fetch of a blob where the type was not set. It is invalid in others cases
|
||||
// such as a XHR (See https://xhr.spec.whatwg.org/#response-mime-type). The
|
||||
// XMLHttpRequestMainThread will set the channel content type to the correct
|
||||
// fallback value before this point, so we need to be careful to only override
|
||||
// it when the blob type is valid.
|
||||
if (!blobContentType.IsEmpty() ||
|
||||
channelContentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE)) {
|
||||
mChannel->SetContentType(NS_ConvertUTF16toUTF8(blobContentType));
|
||||
}
|
||||
nsAutoString contentType;
|
||||
blobImpl->GetType(contentType);
|
||||
mChannel->SetContentType(NS_ConvertUTF16toUTF8(contentType));
|
||||
|
||||
auto cleanupOnExit = MakeScopeExit([&] { mChannel = nullptr; });
|
||||
|
||||
|
|
|
@ -1889,7 +1889,7 @@ XMLHttpRequestMainThread::OnStartRequest(nsIRequest* request) {
|
|||
// Fallback to 'application/octet-stream'
|
||||
nsAutoCString type;
|
||||
channel->GetContentType(type);
|
||||
if (type.IsEmpty() || type.EqualsLiteral(UNKNOWN_CONTENT_TYPE)) {
|
||||
if (type.EqualsLiteral(UNKNOWN_CONTENT_TYPE)) {
|
||||
channel->SetContentType(nsLiteralCString(APPLICATION_OCTET_STREAM));
|
||||
}
|
||||
|
||||
|
|
|
@ -292,6 +292,8 @@ class nsBaseChannel
|
|||
nsCOMPtr<nsISupports> mOwner;
|
||||
nsCOMPtr<nsISupports> mSecurityInfo;
|
||||
nsCOMPtr<nsIChannel> mRedirectChannel;
|
||||
nsCString mContentType;
|
||||
nsCString mContentCharset;
|
||||
uint32_t mLoadFlags{LOAD_NORMAL};
|
||||
bool mQueriedProgressSink{true};
|
||||
bool mSynthProgressEvents{false};
|
||||
|
@ -301,8 +303,6 @@ class nsBaseChannel
|
|||
uint32_t mRedirectFlags{0};
|
||||
|
||||
protected:
|
||||
nsCString mContentType;
|
||||
nsCString mContentCharset;
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
nsCOMPtr<nsILoadInfo> mLoadInfo;
|
||||
|
|
|
@ -246,8 +246,7 @@ class ParentProcessDocumentOpenInfo final : public nsDocumentOpenInfo,
|
|||
// The one exception is nsUnknownDecoder, which works in the parent
|
||||
// (and we need to know what the content type is before we can
|
||||
// decide if it will be handled in the parent), so we run that here.
|
||||
if (mContentType.LowerCaseEqualsASCII(UNKNOWN_CONTENT_TYPE) ||
|
||||
mContentType.IsEmpty()) {
|
||||
if (mContentType.LowerCaseEqualsASCII(UNKNOWN_CONTENT_TYPE)) {
|
||||
return nsDocumentOpenInfo::TryStreamConversion(aChannel);
|
||||
}
|
||||
|
||||
|
|
|
@ -471,8 +471,7 @@ nsViewSourceChannel::GetContentType(nsACString& aContentType) {
|
|||
// content decoder will then kick in automatically, and it
|
||||
// will call our SetOriginalContentType method instead of our
|
||||
// SetContentType method to set the type it determines.
|
||||
if (!contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE) &&
|
||||
!contentType.IsEmpty()) {
|
||||
if (!contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE)) {
|
||||
contentType = VIEWSOURCE_CONTENT_TYPE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title></title>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<script>
|
||||
|
||||
function parseBlob(blob) {
|
||||
return new Promise(resolve => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", URL.createObjectURL(blob));
|
||||
xhr.onload = () => {
|
||||
resolve(xhr.getResponseHeader("Content-Type"));
|
||||
}
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
|
||||
promise_test(async (t) => {
|
||||
// Create a new blob with a valid content type
|
||||
let blob = new Blob(["<x></x>"], { type: "application/xml" });
|
||||
|
||||
// The blob content type should survive
|
||||
let blobContentType = await parseBlob(blob);
|
||||
assert_equals(blobContentType, "application/xml");
|
||||
}, "blob object with content type is passed through");
|
||||
|
||||
promise_test(async (t) => {
|
||||
// Create a new blob with a invalid content type
|
||||
let blob = new Blob(["<x></x>"], { type: "\0" });
|
||||
|
||||
// The blob content type should be overridden to text/xml
|
||||
let blobContentType = await parseBlob(blob);
|
||||
assert_equals(blobContentType, "text/xml");
|
||||
}, "blob object with invalid content type is given text/xml");
|
||||
|
||||
promise_test(async (t) => {
|
||||
// Create a new blob without a content type
|
||||
let blob = new Blob(["<x></x>"]);
|
||||
|
||||
// The blob content type should be overridden to text/xml
|
||||
let blobContentType = await parseBlob(blob);
|
||||
assert_equals(blobContentType, "text/xml");
|
||||
}, "blob object with empty content type is given text/xml");
|
||||
|
||||
promise_test(async (t) => {
|
||||
let blob = new Blob(["<x></x>"], { type: "application/xml" });
|
||||
|
||||
// Create a slice of a blob without a content type
|
||||
let slice = blob.slice(0, 6);
|
||||
|
||||
// The slice content type should be overridden to text/xml
|
||||
let sliceContentType = await parseBlob(slice);
|
||||
assert_equals(sliceContentType, "text/xml");
|
||||
}, "blob slice with empty content type is given text/xml");
|
||||
|
||||
</script>
|
|
@ -42,47 +42,7 @@ invalidRequestMethods.forEach(function(method) {
|
|||
checkKoUrl(URL.createObjectURL(blob2), method, "Fetching [" + method + "] URL.createObjectURL(blob) is KO");
|
||||
});
|
||||
|
||||
var empty_blob = new Blob([]);
|
||||
checkFetchResponse(URL.createObjectURL(empty_blob), "", "", 0,
|
||||
"Fetching URL.createObjectURL(empty_blob) is OK");
|
||||
|
||||
var empty_type_blob = new Blob([], {type: ""});
|
||||
checkFetchResponse(URL.createObjectURL(empty_type_blob), "", "", 0,
|
||||
"Fetching URL.createObjectURL(empty_type_blob) is OK");
|
||||
|
||||
var empty_data_blob = new Blob([], {type: "text/plain"});
|
||||
checkFetchResponse(URL.createObjectURL(empty_data_blob), "", "text/plain", 0,
|
||||
"Fetching URL.createObjectURL(empty_data_blob) is OK");
|
||||
|
||||
checkKoUrl("blob:not-backed-by-a-blob/", "GET",
|
||||
"Fetching [GET] blob:not-backed-by-a-blob/ is KO");
|
||||
|
||||
promise_test(function(test) {
|
||||
var blob = new Blob(["content type with invalid character"], {"type": "text/plain"});
|
||||
let slice = blob.slice(8, 25, "\0");
|
||||
return fetch(URL.createObjectURL(slice)).then(function (resp) {
|
||||
assert_equals(resp.status, 200, "HTTP status is 200");
|
||||
assert_equals(resp.type, "basic", "response type is basic");
|
||||
assert_equals(resp.headers.get("Content-Type"), "");
|
||||
assert_equals(resp.headers.get("Content-Length"), "17");
|
||||
return resp.text();
|
||||
}).then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, "type with invalid");
|
||||
});
|
||||
}, "Set content type to the empty string for slice with invalid content type");
|
||||
|
||||
promise_test(function(test) {
|
||||
var blob = new Blob(["content type that is empty"], {"type": "text/plain"});
|
||||
let slice = blob.slice(8, 20);
|
||||
return fetch(URL.createObjectURL(slice)).then(function (resp) {
|
||||
assert_equals(resp.status, 200, "HTTP status is 200");
|
||||
assert_equals(resp.type, "basic", "response type is basic");
|
||||
assert_equals(resp.headers.get("Content-Type"), "");
|
||||
assert_equals(resp.headers.get("Content-Length"), "12");
|
||||
return resp.text();
|
||||
}).then(function(bodyAsText) {
|
||||
assert_equals(bodyAsText, "type that is");
|
||||
});
|
||||
}, "Set content type to the empty string for slice with no content type ");
|
||||
|
||||
done();
|
||||
|
|
|
@ -568,15 +568,7 @@ nsresult nsDocumentOpenInfo::ConvertData(nsIRequest* request,
|
|||
|
||||
nsresult nsDocumentOpenInfo::TryStreamConversion(nsIChannel* aChannel) {
|
||||
constexpr auto anyType = "*/*"_ns;
|
||||
|
||||
// A empty content type should be treated like the unknown content type.
|
||||
nsCString srcContentType(mContentType);
|
||||
if (srcContentType.IsEmpty()) {
|
||||
srcContentType.AssignLiteral(UNKNOWN_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
nsresult rv =
|
||||
ConvertData(aChannel, m_contentListener, srcContentType, anyType);
|
||||
nsresult rv = ConvertData(aChannel, m_contentListener, mContentType, anyType);
|
||||
if (NS_FAILED(rv)) {
|
||||
m_targetStreamListener = nullptr;
|
||||
} else if (m_targetStreamListener) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче