mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 16:28:38 +09:00
Merge remote-tracking branch 'origin/tracking' into custom
This commit is contained in:
commit
60e7987621
15 changed files with 79 additions and 47 deletions
|
|
@ -596,48 +596,47 @@ 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 &result)
|
||||
nsJARChannel::GetContentType(nsACString &aResult)
|
||||
{
|
||||
// If the Jar file has not been open yet,
|
||||
// We return application/x-unknown-content-type
|
||||
if (!mOpened) {
|
||||
result.Assign(UNKNOWN_CONTENT_TYPE);
|
||||
aResult.Assign(UNKNOWN_CONTENT_TYPE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
aResult = mContentType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -655,8 +654,8 @@ nsJARChannel::SetContentType(const nsACString &aContentType)
|
|||
NS_IMETHODIMP
|
||||
nsJARChannel::GetContentCharset(nsACString &aContentCharset)
|
||||
{
|
||||
// If someone gives us a charset hint we should just use that charset.
|
||||
// So we don't care when this is being called.
|
||||
// We behave like HTTP channels (treat this as a hint if called before open,
|
||||
// and override the charset if called after open).
|
||||
aContentCharset = mContentCharset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -749,6 +748,10 @@ 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;
|
||||
|
|
@ -846,6 +849,10 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
|
|||
mLoadGroup->AddRequest(this, nullptr);
|
||||
|
||||
mOpened = true;
|
||||
// Compute the content type now.
|
||||
if (!GetContentTypeGuess(mContentType)) {
|
||||
mContentType.Assign(UNKNOWN_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue