backout bug1757604 part from rev c28b308e as it cause display issues

This commit is contained in:
2022-09-21 22:38:00 +08:00
parent 54d374ceb2
commit cf157e5f85
2 changed files with 37 additions and 50 deletions
+37 -47
View File
@@ -714,50 +714,48 @@ nsJARChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
return NS_OK;
}
nsresult
nsJARChannel::SetContentTypeGuess() {
//
// generate content type and set it
//
const char *ext = nullptr, *fileName = mJarEntry.get();
int32_t len = mJarEntry.Length();
// check if we're displaying a directory
// mJarEntry will be empty if we're trying to display
// the topmost directory in a zip, e.g. jar:foo.zip!/
if (ENTRY_IS_DIRECTORY(mJarEntry)) {
mContentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT);
} else {
// not a directory, take a guess by its extension
for (int32_t i = len-1; i >= 0; i--) {
if (fileName[i] == '.') {
ext = &fileName[i + 1];
break;
}
}
if (ext) {
nsIMIMEService *mimeServ = gJarHandler->MimeService();
if (mimeServ)
mimeServ->GetTypeFromExtension(nsDependentCString(ext), mContentType);
}
if (mContentType.IsEmpty())
mContentType.AssignLiteral(UNKNOWN_CONTENT_TYPE);
}
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetContentType(nsACString &aResult)
nsJARChannel::GetContentType(nsACString &result)
{
// If the Jar file has not been open yet,
// We return application/x-unknown-content-type
if (!mOpened || mContentType.IsEmpty()) {
aResult.Assign(UNKNOWN_CONTENT_TYPE);
if (!mOpened) {
result.Assign(UNKNOWN_CONTENT_TYPE);
return NS_OK;
}
aResult = mContentType;
if (mContentType.IsEmpty()) {
//
// generate content type and set it
//
const char *ext = nullptr, *fileName = mJarEntry.get();
int32_t len = mJarEntry.Length();
// check if we're displaying a directory
// mJarEntry will be empty if we're trying to display
// the topmost directory in a zip, e.g. jar:foo.zip!/
if (ENTRY_IS_DIRECTORY(mJarEntry)) {
mContentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT);
}
else {
// not a directory, take a guess by its extension
for (int32_t i = len-1; i >= 0; i--) {
if (fileName[i] == '.') {
ext = &fileName[i + 1];
break;
}
}
if (ext) {
nsIMIMEService *mimeServ = gJarHandler->MimeService();
if (mimeServ)
mimeServ->GetTypeFromExtension(nsDependentCString(ext), mContentType);
}
if (mContentType.IsEmpty())
mContentType.AssignLiteral(UNKNOWN_CONTENT_TYPE);
}
}
result = mContentType;
return NS_OK;
}
@@ -868,7 +866,7 @@ nsJARChannel::Open(nsIInputStream **stream)
return rv;
input.forget(stream);
SetOpened();
mOpened = true;
// local files are always considered safe
mIsUnsafe = false;
return NS_OK;
@@ -955,14 +953,6 @@ nsJARChannel::OverrideWithSynthesizedResponse(nsIInputStream* aSynthesizedInput,
NS_ENSURE_SUCCESS_VOID(rv);
}
void
nsJARChannel::SetOpened() {
MOZ_ASSERT(!mOpened, "Opening channel twice?");
mOpened = true;
// Compute the content type now.
NS_ASSERTION(NS_SUCCEEDED(SetContentTypeGuess()), "content type guess failure");
}
NS_IMETHODIMP
nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
{
@@ -1097,7 +1087,7 @@ nsJARChannel::FinishAsyncOpen()
if (mLoadGroup)
mLoadGroup->AddRequest(this, nullptr);
SetOpened();
mOpened = true;
}
//-----------------------------------------------------------------------------
-3
View File
@@ -82,9 +82,6 @@ private:
bool BypassServiceWorker() const;
nsresult SetContentTypeGuess();
void SetOpened();
// Returns true if this channel should intercept the network request and
// prepare for a possible synthesized response instead.
bool ShouldIntercept();