forked from mirrors/gecko-dev
Bug 1574372 - Allow using nsWebNavigationInfo statically. r=bzbarsky
IsTypeSupported requires a docshell in order to determine if plugins are allowed. This adds a static version that lets the caller provide their own value for allowing plugins. Differential Revision: https://phabricator.services.mozilla.com/D56132 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
f2a23a9c75
commit
8fe54626de
7 changed files with 45 additions and 68 deletions
|
|
@ -61,6 +61,7 @@ EXPORTS += [
|
||||||
'nsDocShellLoadTypes.h',
|
'nsDocShellLoadTypes.h',
|
||||||
'nsDocShellTreeOwner.h',
|
'nsDocShellTreeOwner.h',
|
||||||
'nsIScrollObserver.h',
|
'nsIScrollObserver.h',
|
||||||
|
'nsWebNavigationInfo.h',
|
||||||
'SerializedLoadContext.h',
|
'SerializedLoadContext.h',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
#include "nsGlobalWindowOuter.h"
|
#include "nsGlobalWindowOuter.h"
|
||||||
#include "nsIInterfaceRequestor.h"
|
#include "nsIInterfaceRequestor.h"
|
||||||
#include "nsIMultiPartChannel.h"
|
#include "nsIMultiPartChannel.h"
|
||||||
|
#include "nsWebNavigationInfo.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
|
|
@ -77,13 +78,6 @@ nsDSURIContentListener::nsDSURIContentListener(nsDocShell* aDocShell)
|
||||||
|
|
||||||
nsDSURIContentListener::~nsDSURIContentListener() {}
|
nsDSURIContentListener::~nsDSURIContentListener() {}
|
||||||
|
|
||||||
nsresult nsDSURIContentListener::Init() {
|
|
||||||
nsresult rv;
|
|
||||||
mNavInfo = do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID, &rv);
|
|
||||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to get webnav info");
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsDSURIContentListener)
|
NS_IMPL_ADDREF(nsDSURIContentListener)
|
||||||
NS_IMPL_RELEASE(nsDSURIContentListener)
|
NS_IMPL_RELEASE(nsDSURIContentListener)
|
||||||
|
|
||||||
|
|
@ -242,15 +236,13 @@ nsDSURIContentListener::CanHandleContent(const char* aContentType,
|
||||||
*aCanHandleContent = false;
|
*aCanHandleContent = false;
|
||||||
*aDesiredContentType = nullptr;
|
*aDesiredContentType = nullptr;
|
||||||
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
if (aContentType) {
|
if (aContentType) {
|
||||||
uint32_t canHandle = nsIWebNavigationInfo::UNSUPPORTED;
|
uint32_t canHandle = nsWebNavigationInfo::IsTypeSupported(
|
||||||
rv = mNavInfo->IsTypeSupported(nsDependentCString(aContentType), mDocShell,
|
nsDependentCString(aContentType), mDocShell);
|
||||||
&canHandle);
|
|
||||||
*aCanHandleContent = (canHandle != nsIWebNavigationInfo::UNSUPPORTED);
|
*aCanHandleContent = (canHandle != nsIWebNavigationInfo::UNSUPPORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,6 @@ class nsDSURIContentListener final : public nsIURIContentListener,
|
||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
NS_DECL_NSIURICONTENTLISTENER
|
NS_DECL_NSIURICONTENTLISTENER
|
||||||
|
|
||||||
nsresult Init();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit nsDSURIContentListener(nsDocShell* aDocShell);
|
explicit nsDSURIContentListener(nsDocShell* aDocShell);
|
||||||
virtual ~nsDSURIContentListener();
|
virtual ~nsDSURIContentListener();
|
||||||
|
|
@ -90,8 +88,6 @@ class nsDSURIContentListener final : public nsIURIContentListener,
|
||||||
// preferred and encouraged!
|
// preferred and encouraged!
|
||||||
nsWeakPtr mWeakParentContentListener;
|
nsWeakPtr mWeakParentContentListener;
|
||||||
nsIURIContentListener* mParentContentListener;
|
nsIURIContentListener* mParentContentListener;
|
||||||
|
|
||||||
nsCOMPtr<nsIWebNavigationInfo> mNavInfo;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* nsDSURIContentListener_h__ */
|
#endif /* nsDSURIContentListener_h__ */
|
||||||
|
|
|
||||||
|
|
@ -466,10 +466,6 @@ already_AddRefed<nsDocShell> nsDocShell::Create(
|
||||||
|
|
||||||
// Create our ContentListener
|
// Create our ContentListener
|
||||||
ds->mContentListener = new nsDSURIContentListener(ds);
|
ds->mContentListener = new nsDSURIContentListener(ds);
|
||||||
rv = ds->mContentListener->Init();
|
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If parent intercept is not enabled then we must forward to
|
// If parent intercept is not enabled then we must forward to
|
||||||
// the network controller from docshell. We also enable if we're
|
// the network controller from docshell. We also enable if we're
|
||||||
|
|
|
||||||
|
|
@ -16,56 +16,56 @@
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(nsWebNavigationInfo, nsIWebNavigationInfo)
|
NS_IMPL_ISUPPORTS(nsWebNavigationInfo, nsIWebNavigationInfo)
|
||||||
|
|
||||||
nsresult nsWebNavigationInfo::Init() {
|
|
||||||
nsresult rv;
|
|
||||||
mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
|
nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
|
||||||
nsIWebNavigation* aWebNav,
|
nsIWebNavigation* aWebNav,
|
||||||
uint32_t* aIsTypeSupported) {
|
uint32_t* aIsTypeSupported) {
|
||||||
MOZ_ASSERT(aIsTypeSupported, "null out param?");
|
MOZ_ASSERT(aIsTypeSupported, "null out param?");
|
||||||
|
|
||||||
|
*aIsTypeSupported = IsTypeSupported(aType, aWebNav);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
|
||||||
|
nsIWebNavigation* aWebNav) {
|
||||||
// Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or
|
// Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or
|
||||||
// an nsSHistory, but not much we can do with that). So if we start using
|
// an nsSHistory, but not much we can do with that). So if we start using
|
||||||
// it here, we need to be careful to get to the docshell correctly.
|
// it here, we need to be careful to get to the docshell correctly.
|
||||||
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebNav));
|
||||||
|
bool pluginsAllowed = true;
|
||||||
|
if (docShell) {
|
||||||
|
docShell->GetAllowPlugins(&pluginsAllowed);
|
||||||
|
}
|
||||||
|
|
||||||
// For now just report what the Gecko-Content-Viewers category has
|
return IsTypeSupported(aType, pluginsAllowed);
|
||||||
// to say for itself.
|
}
|
||||||
*aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED;
|
|
||||||
|
|
||||||
|
uint32_t nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
|
||||||
|
bool aPluginsAllowed) {
|
||||||
// We want to claim that the type for PDF documents is unsupported,
|
// We want to claim that the type for PDF documents is unsupported,
|
||||||
// so that the internal PDF viewer's stream converted will get used.
|
// so that the internal PDF viewer's stream converted will get used.
|
||||||
if (aType.LowerCaseEqualsLiteral("application/pdf") &&
|
if (aType.LowerCaseEqualsLiteral("application/pdf") &&
|
||||||
nsContentUtils::IsPDFJSEnabled()) {
|
nsContentUtils::IsPDFJSEnabled()) {
|
||||||
return NS_OK;
|
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nsCString& flatType = PromiseFlatCString(aType);
|
const nsCString& flatType = PromiseFlatCString(aType);
|
||||||
nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported);
|
uint32_t result = IsTypeSupportedInternal(flatType);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
if (result != nsIWebNavigationInfo::UNSUPPORTED) {
|
||||||
|
return result;
|
||||||
if (*aIsTypeSupported) {
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// As of FF 52, we only support flash and test plugins, so if the mime types
|
// As of FF 52, we only support flash and test plugins, so if the mime types
|
||||||
// don't match for that, exit before we start loading plugins.
|
// don't match for that, exit before we start loading plugins.
|
||||||
if (!nsPluginHost::CanUsePluginForMIMEType(aType)) {
|
if (!nsPluginHost::CanUsePluginForMIMEType(aType)) {
|
||||||
return NS_OK;
|
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this request is for a docShell that isn't going to allow plugins,
|
// If this request is for a docShell that isn't going to allow plugins,
|
||||||
// there's no need to try and find a plugin to handle it.
|
// there's no need to try and find a plugin to handle it.
|
||||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebNav));
|
if (!aPluginsAllowed) {
|
||||||
bool allowed;
|
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||||
if (docShell && NS_SUCCEEDED(docShell->GetAllowPlugins(&allowed)) &&
|
|
||||||
!allowed) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try reloading plugins in case they've changed.
|
// Try reloading plugins in case they've changed.
|
||||||
|
|
@ -74,23 +74,20 @@ nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
|
||||||
if (pluginHost) {
|
if (pluginHost) {
|
||||||
// false will ensure that currently running plugins will not
|
// false will ensure that currently running plugins will not
|
||||||
// be shut down
|
// be shut down
|
||||||
rv = pluginHost->ReloadPlugins();
|
nsresult rv = pluginHost->ReloadPlugins();
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
// OK, we reloaded plugins and there were new ones
|
// OK, we reloaded plugins and there were new ones
|
||||||
// (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have
|
// (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have
|
||||||
// been returned). Try checking whether we can handle the
|
// been returned). Try checking whether we can handle the
|
||||||
// content now.
|
// content now.
|
||||||
return IsTypeSupportedInternal(flatType, aIsTypeSupported);
|
return IsTypeSupportedInternal(flatType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType,
|
uint32_t nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType) {
|
||||||
uint32_t* aIsSupported) {
|
|
||||||
MOZ_ASSERT(aIsSupported, "Null out param?");
|
|
||||||
|
|
||||||
nsContentUtils::ContentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
|
nsContentUtils::ContentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
|
||||||
|
|
||||||
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
|
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
|
||||||
|
|
@ -98,28 +95,24 @@ nsresult nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType,
|
||||||
|
|
||||||
switch (vtype) {
|
switch (vtype) {
|
||||||
case nsContentUtils::TYPE_UNSUPPORTED:
|
case nsContentUtils::TYPE_UNSUPPORTED:
|
||||||
*aIsSupported = nsIWebNavigationInfo::UNSUPPORTED;
|
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||||
break;
|
|
||||||
|
|
||||||
case nsContentUtils::TYPE_PLUGIN:
|
case nsContentUtils::TYPE_PLUGIN:
|
||||||
*aIsSupported = nsIWebNavigationInfo::PLUGIN;
|
return nsIWebNavigationInfo::PLUGIN;
|
||||||
break;
|
|
||||||
|
|
||||||
case nsContentUtils::TYPE_UNKNOWN:
|
case nsContentUtils::TYPE_UNKNOWN:
|
||||||
*aIsSupported = nsIWebNavigationInfo::OTHER;
|
return nsIWebNavigationInfo::OTHER;
|
||||||
break;
|
|
||||||
|
|
||||||
case nsContentUtils::TYPE_CONTENT:
|
case nsContentUtils::TYPE_CONTENT:
|
||||||
// XXXbz we only need this because images register for the same
|
// XXXbz we only need this because images register for the same
|
||||||
// contractid as documents, so we can't tell them apart based on
|
// contractid as documents, so we can't tell them apart based on
|
||||||
// contractid.
|
// contractid.
|
||||||
if (imgLoader::SupportImageWithMimeType(aType.get())) {
|
if (imgLoader::SupportImageWithMimeType(aType.get())) {
|
||||||
*aIsSupported = nsIWebNavigationInfo::IMAGE;
|
return nsIWebNavigationInfo::IMAGE;
|
||||||
} else {
|
} else {
|
||||||
*aIsSupported = nsIWebNavigationInfo::OTHER;
|
return nsIWebNavigationInfo::OTHER;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,17 +21,17 @@ class nsWebNavigationInfo final : public nsIWebNavigationInfo {
|
||||||
|
|
||||||
NS_DECL_NSIWEBNAVIGATIONINFO
|
NS_DECL_NSIWEBNAVIGATIONINFO
|
||||||
|
|
||||||
nsresult Init();
|
static uint32_t IsTypeSupported(const nsACString& aType,
|
||||||
|
nsIWebNavigation* aWebNav);
|
||||||
|
static uint32_t IsTypeSupported(const nsACString& aType,
|
||||||
|
bool aPluginsAllowed);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~nsWebNavigationInfo() {}
|
~nsWebNavigationInfo() {}
|
||||||
|
|
||||||
// Check whether aType is supported. If this method throws, the
|
// Check whether aType is supported, and returns an nsIWebNavigationInfo
|
||||||
// value of aIsSupported is not changed.
|
// constant.
|
||||||
nsresult IsTypeSupportedInternal(const nsCString& aType,
|
static uint32_t IsTypeSupportedInternal(const nsCString& aType);
|
||||||
uint32_t* aIsSupported);
|
|
||||||
|
|
||||||
nsCOMPtr<nsICategoryManager> mCategoryManager;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsWebNavigationInfo_h__
|
#endif // nsWebNavigationInfo_h__
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,6 @@ Classes = [
|
||||||
'contract_ids': ['@mozilla.org/webnavigation-info;1'],
|
'contract_ids': ['@mozilla.org/webnavigation-info;1'],
|
||||||
'type': 'nsWebNavigationInfo',
|
'type': 'nsWebNavigationInfo',
|
||||||
'headers': ['/docshell/base/nsWebNavigationInfo.h'],
|
'headers': ['/docshell/base/nsWebNavigationInfo.h'],
|
||||||
'init_method': 'Init',
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue