зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1337056 - Part 7: Refactor nsObjectLoadingContent::GetTypeOfContent logic out into nsContentUtils, r=qdot
MozReview-Commit-ID: IJQNhQZzx3y
This commit is contained in:
Родитель
5aa9ab1a69
Коммит
7a7e5daeef
|
@ -215,6 +215,8 @@
|
|||
#include "TabChild.h"
|
||||
#include "mozilla/dom/DocGroup.h"
|
||||
#include "mozilla/dom/TabGroup.h"
|
||||
#include "nsIWebNavigationInfo.h"
|
||||
#include "nsPluginHost.h"
|
||||
|
||||
#include "nsIBidiKeyboard.h"
|
||||
|
||||
|
@ -9961,3 +9963,93 @@ nsContentUtils::CreateJSValueFromSequenceOfObject(JSContext* aCx,
|
|||
aValue.setObject(*array);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given type is a supported document type for
|
||||
* loading within the nsObjectLoadingContent specified by aContent.
|
||||
*
|
||||
* NOTE Helper method for nsContentUtils::HtmlObjectContentTypeForMIMEType.
|
||||
* NOTE Does not take content policy or capabilities into account
|
||||
*/
|
||||
static bool
|
||||
HtmlObjectContentSupportsDocument(const nsCString& aMimeType,
|
||||
nsIContent* aContent)
|
||||
{
|
||||
nsCOMPtr<nsIWebNavigationInfo> info(
|
||||
do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID));
|
||||
if (!info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWebNavigation> webNav;
|
||||
if (aContent) {
|
||||
nsIDocument* currentDoc = aContent->GetComposedDoc();
|
||||
if (currentDoc) {
|
||||
webNav = do_GetInterface(currentDoc->GetWindow());
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t supported;
|
||||
nsresult rv = info->IsTypeSupported(aMimeType, webNav, &supported);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (supported != nsIWebNavigationInfo::UNSUPPORTED) {
|
||||
// Don't want to support plugins as documents
|
||||
return supported != nsIWebNavigationInfo::PLUGIN;
|
||||
}
|
||||
|
||||
// Try a stream converter
|
||||
// NOTE: We treat any type we can convert from as a supported type. If a
|
||||
// type is not actually supported, the URI loader will detect that and
|
||||
// return an error, and we'll fallback.
|
||||
nsCOMPtr<nsIStreamConverterService> convServ =
|
||||
do_GetService("@mozilla.org/streamConverters;1");
|
||||
bool canConvert = false;
|
||||
if (convServ) {
|
||||
rv = convServ->CanConvert(aMimeType.get(), "*/*", &canConvert);
|
||||
}
|
||||
return NS_SUCCEEDED(rv) && canConvert;
|
||||
}
|
||||
|
||||
/* static */ uint32_t
|
||||
nsContentUtils::HtmlObjectContentTypeForMIMEType(const nsCString& aMIMEType,
|
||||
nsIContent* aContent)
|
||||
{
|
||||
if (aMIMEType.IsEmpty()) {
|
||||
return nsIObjectLoadingContent::TYPE_NULL;
|
||||
}
|
||||
|
||||
if (imgLoader::SupportImageWithMimeType(aMIMEType.get())) {
|
||||
return nsIObjectLoadingContent::TYPE_IMAGE;
|
||||
}
|
||||
|
||||
// Faking support of the PDF content as a document for EMBED tags
|
||||
// when internal PDF viewer is enabled.
|
||||
if (aMIMEType.LowerCaseEqualsLiteral("application/pdf") &&
|
||||
IsPDFJSEnabled()) {
|
||||
return nsIObjectLoadingContent::TYPE_DOCUMENT;
|
||||
}
|
||||
|
||||
// Faking support of the SWF content as a document for EMBED tags
|
||||
// when internal SWF player is enabled.
|
||||
if (aMIMEType.LowerCaseEqualsLiteral("application/x-shockwave-flash") &&
|
||||
IsSWFPlayerEnabled()) {
|
||||
return nsIObjectLoadingContent::TYPE_DOCUMENT;
|
||||
}
|
||||
|
||||
if (HtmlObjectContentSupportsDocument(aMIMEType, aContent)) {
|
||||
return nsIObjectLoadingContent::TYPE_DOCUMENT;
|
||||
}
|
||||
|
||||
RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
||||
if (pluginHost &&
|
||||
pluginHost->HavePluginForType(aMIMEType, nsPluginHost::eExcludeNone)) {
|
||||
// ShouldPlay will handle checking for disabled plugins
|
||||
return nsIObjectLoadingContent::TYPE_PLUGIN;
|
||||
}
|
||||
|
||||
return nsIObjectLoadingContent::TYPE_NULL;
|
||||
}
|
||||
|
|
|
@ -2792,6 +2792,23 @@ public:
|
|||
static bool
|
||||
IsWebComponentsEnabled() { return sIsWebComponentsEnabled; }
|
||||
|
||||
/**
|
||||
* Returns one of the nsIObjectLoadingContent::TYPE_ values describing the
|
||||
* content type which will be used for the given MIME type when loaded within
|
||||
* an nsObjectLoadingContent.
|
||||
*
|
||||
* NOTE: This method doesn't take capabilities into account. The caller must
|
||||
* take that into account.
|
||||
*
|
||||
* @param aMIMEType The MIME type of the document being loaded.
|
||||
* @param aContent The nsIContent object which is performing the load. May be
|
||||
* nullptr in which case the docshell's plugin permissions
|
||||
* will not be checked.
|
||||
*/
|
||||
static uint32_t
|
||||
HtmlObjectContentTypeForMIMEType(const nsCString& aMIMEType,
|
||||
nsIContent* aContent);
|
||||
|
||||
private:
|
||||
static bool InitializeEventTable();
|
||||
|
||||
|
|
|
@ -452,12 +452,6 @@ URIEquals(nsIURI *a, nsIURI *b)
|
|||
return (!a && !b) || (a && b && NS_SUCCEEDED(a->Equals(b, &equal)) && equal);
|
||||
}
|
||||
|
||||
static bool
|
||||
IsSupportedImage(const nsCString& aMimeType)
|
||||
{
|
||||
return imgLoader::SupportImageWithMimeType(aMimeType.get());
|
||||
}
|
||||
|
||||
static void
|
||||
GetExtensionFromURI(nsIURI* uri, nsCString& ext)
|
||||
{
|
||||
|
@ -557,50 +551,6 @@ nsObjectLoadingContent::MakePluginListener()
|
|||
}
|
||||
|
||||
|
||||
bool
|
||||
nsObjectLoadingContent::IsSupportedDocument(const nsCString& aMimeType)
|
||||
{
|
||||
nsCOMPtr<nsIContent> thisContent =
|
||||
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
||||
NS_ASSERTION(thisContent, "must be a content");
|
||||
|
||||
nsCOMPtr<nsIWebNavigationInfo> info(
|
||||
do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID));
|
||||
if (!info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIWebNavigation> webNav;
|
||||
nsIDocument* currentDoc = thisContent->GetComposedDoc();
|
||||
if (currentDoc) {
|
||||
webNav = do_GetInterface(currentDoc->GetWindow());
|
||||
}
|
||||
|
||||
uint32_t supported;
|
||||
nsresult rv = info->IsTypeSupported(aMimeType, webNav, &supported);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (supported != nsIWebNavigationInfo::UNSUPPORTED) {
|
||||
// Don't want to support plugins as documents
|
||||
return supported != nsIWebNavigationInfo::PLUGIN;
|
||||
}
|
||||
|
||||
// Try a stream converter
|
||||
// NOTE: We treat any type we can convert from as a supported type. If a
|
||||
// type is not actually supported, the URI loader will detect that and
|
||||
// return an error, and we'll fallback.
|
||||
nsCOMPtr<nsIStreamConverterService> convServ =
|
||||
do_GetService("@mozilla.org/streamConverters;1");
|
||||
bool canConvert = false;
|
||||
if (convServ) {
|
||||
rv = convServ->CanConvert(aMimeType.get(), "*/*", &canConvert);
|
||||
}
|
||||
return NS_SUCCEEDED(rv) && canConvert;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsObjectLoadingContent::BindToTree(nsIDocument* aDocument,
|
||||
nsIContent* aParent,
|
||||
|
@ -2761,43 +2711,26 @@ nsObjectLoadingContent::NotifyStateChanged(ObjectType aOldType,
|
|||
nsObjectLoadingContent::ObjectType
|
||||
nsObjectLoadingContent::GetTypeOfContent(const nsCString& aMIMEType)
|
||||
{
|
||||
if (aMIMEType.IsEmpty()) {
|
||||
return eType_Null;
|
||||
}
|
||||
nsCOMPtr<nsIContent> thisContent =
|
||||
do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
|
||||
NS_ASSERTION(thisContent, "must be a content");
|
||||
|
||||
ObjectType type = static_cast<ObjectType>(
|
||||
nsContentUtils::HtmlObjectContentTypeForMIMEType(aMIMEType, thisContent));
|
||||
|
||||
// Switch the result type to eType_Null ic the capability is not present.
|
||||
uint32_t caps = GetCapabilities();
|
||||
|
||||
if ((caps & eSupportImages) && IsSupportedImage(aMIMEType)) {
|
||||
return eType_Image;
|
||||
if (!(caps & eSupportImages) && type == eType_Image) {
|
||||
type = eType_Null;
|
||||
}
|
||||
if (!(caps & eSupportDocuments) && type == eType_Document) {
|
||||
type = eType_Null;
|
||||
}
|
||||
if (!(caps & eSupportPlugins) && type == eType_Plugin) {
|
||||
type = eType_Null;
|
||||
}
|
||||
|
||||
// Faking support of the PDF content as a document for EMBED tags
|
||||
// when internal PDF viewer is enabled.
|
||||
if (aMIMEType.LowerCaseEqualsLiteral("application/pdf") &&
|
||||
nsContentUtils::IsPDFJSEnabled()) {
|
||||
return eType_Document;
|
||||
}
|
||||
|
||||
// Faking support of the SWF content as a document for EMBED tags
|
||||
// when internal SWF player is enabled.
|
||||
if (aMIMEType.LowerCaseEqualsLiteral("application/x-shockwave-flash") &&
|
||||
nsContentUtils::IsSWFPlayerEnabled()) {
|
||||
return eType_Document;
|
||||
}
|
||||
|
||||
if ((caps & eSupportDocuments) && IsSupportedDocument(aMIMEType)) {
|
||||
return eType_Document;
|
||||
}
|
||||
|
||||
RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
||||
if ((caps & eSupportPlugins) &&
|
||||
pluginHost &&
|
||||
pluginHost->HavePluginForType(aMIMEType, nsPluginHost::eExcludeNone)) {
|
||||
// ShouldPlay will handle checking for disabled plugins
|
||||
return eType_Plugin;
|
||||
}
|
||||
|
||||
return eType_Null;
|
||||
return type;
|
||||
}
|
||||
|
||||
nsPluginFrame*
|
||||
|
|
|
@ -515,13 +515,6 @@ class nsObjectLoadingContent : public nsImageLoadingContent
|
|||
*/
|
||||
bool CheckProcessPolicy(int16_t *aContentPolicy);
|
||||
|
||||
/**
|
||||
* Checks whether the given type is a supported document type
|
||||
*
|
||||
* NOTE Does not take content policy or capabilities into account
|
||||
*/
|
||||
bool IsSupportedDocument(const nsCString& aType);
|
||||
|
||||
/**
|
||||
* Gets the plugin instance and creates a plugin stream listener, assigning
|
||||
* it to mFinalListener
|
||||
|
|
Загрузка…
Ссылка в новой задаче