зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
f2a23a9c75
Коммит
8fe54626de
|
@ -61,6 +61,7 @@ EXPORTS += [
|
|||
'nsDocShellLoadTypes.h',
|
||||
'nsDocShellTreeOwner.h',
|
||||
'nsIScrollObserver.h',
|
||||
'nsWebNavigationInfo.h',
|
||||
'SerializedLoadContext.h',
|
||||
]
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "nsGlobalWindowOuter.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIMultiPartChannel.h"
|
||||
#include "nsWebNavigationInfo.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
@ -77,13 +78,6 @@ nsDSURIContentListener::nsDSURIContentListener(nsDocShell* aDocShell)
|
|||
|
||||
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_RELEASE(nsDSURIContentListener)
|
||||
|
||||
|
@ -242,15 +236,13 @@ nsDSURIContentListener::CanHandleContent(const char* aContentType,
|
|||
*aCanHandleContent = false;
|
||||
*aDesiredContentType = nullptr;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (aContentType) {
|
||||
uint32_t canHandle = nsIWebNavigationInfo::UNSUPPORTED;
|
||||
rv = mNavInfo->IsTypeSupported(nsDependentCString(aContentType), mDocShell,
|
||||
&canHandle);
|
||||
uint32_t canHandle = nsWebNavigationInfo::IsTypeSupported(
|
||||
nsDependentCString(aContentType), mDocShell);
|
||||
*aCanHandleContent = (canHandle != nsIWebNavigationInfo::UNSUPPORTED);
|
||||
}
|
||||
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -67,8 +67,6 @@ class nsDSURIContentListener final : public nsIURIContentListener,
|
|||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIURICONTENTLISTENER
|
||||
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
explicit nsDSURIContentListener(nsDocShell* aDocShell);
|
||||
virtual ~nsDSURIContentListener();
|
||||
|
@ -90,8 +88,6 @@ class nsDSURIContentListener final : public nsIURIContentListener,
|
|||
// preferred and encouraged!
|
||||
nsWeakPtr mWeakParentContentListener;
|
||||
nsIURIContentListener* mParentContentListener;
|
||||
|
||||
nsCOMPtr<nsIWebNavigationInfo> mNavInfo;
|
||||
};
|
||||
|
||||
#endif /* nsDSURIContentListener_h__ */
|
||||
|
|
|
@ -466,10 +466,6 @@ already_AddRefed<nsDocShell> nsDocShell::Create(
|
|||
|
||||
// Create our ContentListener
|
||||
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
|
||||
// the network controller from docshell. We also enable if we're
|
||||
|
|
|
@ -16,56 +16,56 @@
|
|||
|
||||
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
|
||||
nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
|
||||
nsIWebNavigation* aWebNav,
|
||||
uint32_t* aIsTypeSupported) {
|
||||
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
|
||||
// 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.
|
||||
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
|
||||
// to say for itself.
|
||||
*aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED;
|
||||
return IsTypeSupported(aType, pluginsAllowed);
|
||||
}
|
||||
|
||||
uint32_t nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
|
||||
bool aPluginsAllowed) {
|
||||
// We want to claim that the type for PDF documents is unsupported,
|
||||
// so that the internal PDF viewer's stream converted will get used.
|
||||
if (aType.LowerCaseEqualsLiteral("application/pdf") &&
|
||||
nsContentUtils::IsPDFJSEnabled()) {
|
||||
return NS_OK;
|
||||
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||
;
|
||||
}
|
||||
|
||||
const nsCString& flatType = PromiseFlatCString(aType);
|
||||
nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (*aIsTypeSupported) {
|
||||
return rv;
|
||||
uint32_t result = IsTypeSupportedInternal(flatType);
|
||||
if (result != nsIWebNavigationInfo::UNSUPPORTED) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 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.
|
||||
if (!nsPluginHost::CanUsePluginForMIMEType(aType)) {
|
||||
return NS_OK;
|
||||
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||
}
|
||||
|
||||
// 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.
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebNav));
|
||||
bool allowed;
|
||||
if (docShell && NS_SUCCEEDED(docShell->GetAllowPlugins(&allowed)) &&
|
||||
!allowed) {
|
||||
return NS_OK;
|
||||
if (!aPluginsAllowed) {
|
||||
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||
}
|
||||
|
||||
// Try reloading plugins in case they've changed.
|
||||
|
@ -74,23 +74,20 @@ nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
|
|||
if (pluginHost) {
|
||||
// false will ensure that currently running plugins will not
|
||||
// be shut down
|
||||
rv = pluginHost->ReloadPlugins();
|
||||
nsresult rv = pluginHost->ReloadPlugins();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// OK, we reloaded plugins and there were new ones
|
||||
// (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have
|
||||
// been returned). Try checking whether we can handle the
|
||||
// content now.
|
||||
return IsTypeSupportedInternal(flatType, aIsTypeSupported);
|
||||
return IsTypeSupportedInternal(flatType);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||
}
|
||||
|
||||
nsresult nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType,
|
||||
uint32_t* aIsSupported) {
|
||||
MOZ_ASSERT(aIsSupported, "Null out param?");
|
||||
|
||||
uint32_t nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType) {
|
||||
nsContentUtils::ContentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
|
||||
|
||||
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
|
||||
|
@ -98,28 +95,24 @@ nsresult nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType,
|
|||
|
||||
switch (vtype) {
|
||||
case nsContentUtils::TYPE_UNSUPPORTED:
|
||||
*aIsSupported = nsIWebNavigationInfo::UNSUPPORTED;
|
||||
break;
|
||||
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||
|
||||
case nsContentUtils::TYPE_PLUGIN:
|
||||
*aIsSupported = nsIWebNavigationInfo::PLUGIN;
|
||||
break;
|
||||
return nsIWebNavigationInfo::PLUGIN;
|
||||
|
||||
case nsContentUtils::TYPE_UNKNOWN:
|
||||
*aIsSupported = nsIWebNavigationInfo::OTHER;
|
||||
break;
|
||||
return nsIWebNavigationInfo::OTHER;
|
||||
|
||||
case nsContentUtils::TYPE_CONTENT:
|
||||
// XXXbz we only need this because images register for the same
|
||||
// contractid as documents, so we can't tell them apart based on
|
||||
// contractid.
|
||||
if (imgLoader::SupportImageWithMimeType(aType.get())) {
|
||||
*aIsSupported = nsIWebNavigationInfo::IMAGE;
|
||||
return nsIWebNavigationInfo::IMAGE;
|
||||
} 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
|
||||
|
||||
nsresult Init();
|
||||
static uint32_t IsTypeSupported(const nsACString& aType,
|
||||
nsIWebNavigation* aWebNav);
|
||||
static uint32_t IsTypeSupported(const nsACString& aType,
|
||||
bool aPluginsAllowed);
|
||||
|
||||
private:
|
||||
~nsWebNavigationInfo() {}
|
||||
|
||||
// Check whether aType is supported. If this method throws, the
|
||||
// value of aIsSupported is not changed.
|
||||
nsresult IsTypeSupportedInternal(const nsCString& aType,
|
||||
uint32_t* aIsSupported);
|
||||
|
||||
nsCOMPtr<nsICategoryManager> mCategoryManager;
|
||||
// Check whether aType is supported, and returns an nsIWebNavigationInfo
|
||||
// constant.
|
||||
static uint32_t IsTypeSupportedInternal(const nsCString& aType);
|
||||
};
|
||||
|
||||
#endif // nsWebNavigationInfo_h__
|
||||
|
|
|
@ -137,7 +137,6 @@ Classes = [
|
|||
'contract_ids': ['@mozilla.org/webnavigation-info;1'],
|
||||
'type': 'nsWebNavigationInfo',
|
||||
'headers': ['/docshell/base/nsWebNavigationInfo.h'],
|
||||
'init_method': 'Init',
|
||||
},
|
||||
]
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче