Bug 813438 - Part 3: Rewrite the unknown decoder to use NS_SniffContent; r=bzbarsky

This commit is contained in:
Ehsan Akhgari 2012-11-20 19:37:40 -05:00
Родитель 6c1c6015f2
Коммит 81c52f1b45
2 изменённых файлов: 4 добавлений и 48 удалений

Просмотреть файл

@ -17,7 +17,6 @@
#include "nsIPrefBranch.h"
#include "nsICategoryManager.h"
#include "nsISupportsPrimitives.h"
#include "nsIContentSniffer.h"
#include "nsCRT.h"
@ -26,6 +25,7 @@
#include "nsIViewSourceChannel.h"
#include "nsIHttpChannel.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#define MAX_BUFFER_SIZE 512
@ -334,9 +334,9 @@ void nsUnknownDecoder::DetermineContentType(nsIRequest* aRequest)
}
}
if (TryContentSniffers(aRequest)) {
NS_ASSERTION(!mContentType.IsEmpty(),
"Content type should be known by now.");
NS_SniffContent(NS_DATA_SNIFFER_CATEGORY, aRequest,
(const uint8_t*)mBuffer, mBufferLen, mContentType);
if (!mContentType.IsEmpty()) {
return;
}
@ -359,49 +359,6 @@ void nsUnknownDecoder::DetermineContentType(nsIRequest* aRequest)
"Content type should be known by now.");
}
bool nsUnknownDecoder::TryContentSniffers(nsIRequest* aRequest)
{
// Enumerate content sniffers
nsCOMPtr<nsICategoryManager> catMan(do_GetService("@mozilla.org/categorymanager;1"));
if (!catMan) {
return false;
}
nsCOMPtr<nsISimpleEnumerator> sniffers;
catMan->EnumerateCategory("content-sniffing-services", getter_AddRefs(sniffers));
if (!sniffers) {
return false;
}
bool hasMore;
while (NS_SUCCEEDED(sniffers->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> elem;
sniffers->GetNext(getter_AddRefs(elem));
NS_ASSERTION(elem, "No element even though hasMore returned true!?");
nsCOMPtr<nsISupportsCString> sniffer_id(do_QueryInterface(elem));
NS_ASSERTION(sniffer_id, "element is no nsISupportsCString!?");
nsAutoCString contractid;
nsresult rv = sniffer_id->GetData(contractid);
if (NS_FAILED(rv)) {
continue;
}
nsCOMPtr<nsIContentSniffer> sniffer(do_GetService(contractid.get()));
if (!sniffer) {
continue;
}
rv = sniffer->GetMIMETypeFromContent(aRequest, (const uint8_t*)mBuffer,
mBufferLen, mContentType);
if (NS_SUCCEEDED(rv)) {
return true;
}
}
return false;
}
bool nsUnknownDecoder::SniffForHTML(nsIRequest* aRequest)
{
/*

Просмотреть файл

@ -60,7 +60,6 @@ protected:
// Various sniffer functions. Returning true means that a type
// was determined; false means no luck.
bool TryContentSniffers(nsIRequest* aRequest);
bool SniffForHTML(nsIRequest* aRequest);
bool SniffForXML(nsIRequest* aRequest);