mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-07 00:08:39 +09:00
Issue #2258 - Part 1: Support XCTO:nosniff when navigating.
This commit is contained in:
parent
723180132d
commit
e56e5d6cb1
10 changed files with 103 additions and 5 deletions
|
|
@ -315,6 +315,12 @@ nsUnknownDecoder::GetMIMETypeFromContent(nsIRequest* aRequest,
|
|||
uint32_t aLength,
|
||||
nsACString& type)
|
||||
{
|
||||
// Note: This is only used by sniffer, therefore we do not need to lock anything here.
|
||||
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
||||
if (loadInfo->GetSkipContentSniffing()) {
|
||||
return NS_OK;
|
||||
}
|
||||
mBuffer = const_cast<char*>(reinterpret_cast<const char*>(aData));
|
||||
mBufferLen = aLength;
|
||||
DetermineContentType(aRequest);
|
||||
|
|
@ -345,6 +351,11 @@ bool nsUnknownDecoder::AllowSniffing(nsIRequest* aRequest)
|
|||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
||||
if (loadInfo->GetSkipContentSniffing()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isLocalFile = false;
|
||||
if (NS_FAILED(uri->SchemeIs("file", &isLocalFile)) || isLocalFile) {
|
||||
return false;
|
||||
|
|
@ -391,10 +402,17 @@ void nsUnknownDecoder::DetermineContentType(nsIRequest* aRequest)
|
|||
NS_ASSERTION(mContentType.IsEmpty(), "Content type is already known.");
|
||||
if (!mContentType.IsEmpty()) return;
|
||||
|
||||
nsCOMPtr<nsIHttpChannel> channel(do_QueryInterface(aRequest));
|
||||
if (channel) {
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
||||
if (loadInfo->GetSkipContentSniffing()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const char* testData = mBuffer;
|
||||
uint32_t testDataLen = mBufferLen;
|
||||
// Check if data are compressed.
|
||||
nsCOMPtr<nsIHttpChannel> channel(do_QueryInterface(aRequest));
|
||||
if (channel) {
|
||||
nsresult rv = ConvertEncodedData(aRequest, mBuffer, mBufferLen);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
|
@ -561,6 +579,11 @@ bool nsUnknownDecoder::SniffForXML(nsIRequest* aRequest)
|
|||
|
||||
bool nsUnknownDecoder::SniffURI(nsIRequest* aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
||||
if (loadInfo->GetSkipContentSniffing()) {
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1"));
|
||||
if (mimeService) {
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
||||
|
|
@ -592,6 +615,12 @@ bool nsUnknownDecoder::LastDitchSniff(nsIRequest* aRequest)
|
|||
// All we can do now is try to guess whether this is text/plain or
|
||||
// application/octet-stream
|
||||
|
||||
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo();
|
||||
if (loadInfo->GetSkipContentSniffing()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* testData;
|
||||
uint32_t testDataLen;
|
||||
if (mDecodedData.IsEmpty()) {
|
||||
|
|
@ -791,6 +820,11 @@ nsBinaryDetector::DetermineContentType(nsIRequest* aRequest)
|
|||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsILoadInfo> loadInfo = httpChannel->GetLoadInfo();
|
||||
if (loadInfo->GetSkipContentSniffing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// It's an HTTP channel. Check for the text/plain mess
|
||||
nsAutoCString contentTypeHdr;
|
||||
httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Type"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue