summaryrefslogtreecommitdiff
path: root/components/jar/src/nsJARChannel.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2022-05-03 11:44:57 -0500
committerMatt A. Tobin <email@mattatobin.com>2022-05-03 11:44:57 -0500
commit203a7d03ee41db505c9213ef3ec14ff95ac0a277 (patch)
tree8060080a462cfb10df2c224d5e9bca4abae0c7e7 /components/jar/src/nsJARChannel.cpp
parent07fe90dc5d569917ca13cf6f4aa53c79ed8e8cca (diff)
downloadaura-central-203a7d03ee41db505c9213ef3ec14ff95ac0a277.tar.gz
Revert "[Components:Jar] [MozSec] Make content-type on JAR channels behave the same as HTTP channels."
This reverts commit b17c689b521e44fcf6cbc0ffaa5b635466c95671.
Diffstat (limited to 'components/jar/src/nsJARChannel.cpp')
-rw-r--r--components/jar/src/nsJARChannel.cpp75
1 files changed, 36 insertions, 39 deletions
diff --git a/components/jar/src/nsJARChannel.cpp b/components/jar/src/nsJARChannel.cpp
index 0bbfa31eb..65c034779 100644
--- a/components/jar/src/nsJARChannel.cpp
+++ b/components/jar/src/nsJARChannel.cpp
@@ -577,47 +577,48 @@ nsJARChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
return NS_OK;
}
-bool nsJARChannel::GetContentTypeGuess(nsACString& aResult) const {
- 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)) {
- aResult.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT);
- return true;
- }
-
- // 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) {
- return false;
- }
- nsIMIMEService* mimeServ = gJarHandler->MimeService();
- if (!mimeServ) {
- return false;
- }
- mimeServ->GetTypeFromExtension(nsDependentCString(ext), aResult);
- return !aResult.IsEmpty();
-}
-
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) {
- aResult.Assign(UNKNOWN_CONTENT_TYPE);
+ 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;
}
@@ -635,8 +636,8 @@ nsJARChannel::SetContentType(const nsACString &aContentType)
NS_IMETHODIMP
nsJARChannel::GetContentCharset(nsACString &aContentCharset)
{
- // We behave like HTTP channels (treat this as a hint if called before open,
- // and override the charset if called after open).
+ // If someone gives us a charset hint we should just use that charset.
+ // So we don't care when this is being called.
aContentCharset = mContentCharset;
return NS_OK;
}
@@ -729,10 +730,6 @@ nsJARChannel::Open(nsIInputStream **stream)
input.forget(stream);
mOpened = true;
- // Compute the content type now.
- if (!GetContentTypeGuess(mContentType)) {
- mContentType.Assign(UNKNOWN_CONTENT_TYPE);
- }
// local files are always considered safe
mIsUnsafe = false;
return NS_OK;