diff --git a/mozilla/browser/components/nsBrowserContentHandler.js b/mozilla/browser/components/nsBrowserContentHandler.js index a00e514c77c..26de5c2aaf0 100644 --- a/mozilla/browser/components/nsBrowserContentHandler.js +++ b/mozilla/browser/components/nsBrowserContentHandler.js @@ -57,6 +57,7 @@ const nsIWebNavigation = Components.interfaces.nsIWebNavigation; const nsIWindowMediator = Components.interfaces.nsIWindowMediator; const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; const nsICategoryManager = Components.interfaces.nsICategoryManager; +const nsIWebNavigationInfo = Components.interfaces.nsIWebNavigationInfo; const NS_BINDING_ABORTED = 0x80020006; const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001; @@ -248,10 +249,11 @@ var nsBrowserContentHandler = { handleContent : function bch_handleContent(contentType, context, request) { try { - var catMan = Components.classes["@mozilla.org/categorymanager;1"] - .getService(nsICategoryManager); - var entry = catMan.getCategoryEntry("Gecko-Content-Viewers", - contentType); + var webNavInfo = Components.classes["@mozilla.org/webnavigation-info;1"] + .getService(nsIWebNavigationInfo); + if (!webNavInfo.isTypeSupported(contentType, null)) { + throw NS_ERROR_WONT_HANDLE_CONTENT; + } } catch (e) { throw NS_ERROR_WONT_HANDLE_CONTENT; } diff --git a/mozilla/docshell/base/Makefile.in b/mozilla/docshell/base/Makefile.in index 647d4845fbc..da57a598082 100644 --- a/mozilla/docshell/base/Makefile.in +++ b/mozilla/docshell/base/Makefile.in @@ -82,6 +82,7 @@ REQUIRES = xpcom \ commandhandler \ editor \ windowwatcher \ + imglib2 \ $(NULL) SDK_XPIDLSRCS = \ @@ -106,6 +107,7 @@ XPIDLSRCS = \ nsIScrollable.idl \ nsITextScroll.idl \ nsIWebNavigation.idl \ + nsIWebNavigationInfo.idl \ nsIContentViewer.idl \ nsIContentViewerEdit.idl \ nsIContentViewerFile.idl \ @@ -125,6 +127,7 @@ CPPSRCS = \ nsDefaultURIFixup.cpp \ nsGlobalHistoryAdapter.cpp \ nsGlobalHistory2Adapter.cpp \ + nsWebNavigationInfo.cpp \ $(NULL) # we don't want the shared lib, but we want to force the creation of a diff --git a/mozilla/docshell/base/nsDSURIContentListener.cpp b/mozilla/docshell/base/nsDSURIContentListener.cpp index 11de7bedeae..cd9fa4bbc79 100644 --- a/mozilla/docshell/base/nsDSURIContentListener.cpp +++ b/mozilla/docshell/base/nsDSURIContentListener.cpp @@ -40,9 +40,10 @@ #include "nsDocShell.h" #include "nsDSURIContentListener.h" #include "nsIChannel.h" +#include "nsServiceManagerUtils.h" #include "nsXPIDLString.h" -#include "nsIServiceManager.h" -#include "nsIPluginManager.h" +#include "nsDocShellCID.h" +#include "nsIWebNavigationInfo.h" #include "nsIDOMWindowInternal.h" #include "nsAutoPtr.h" @@ -63,9 +64,9 @@ nsDSURIContentListener::~nsDSURIContentListener() nsresult nsDSURIContentListener::Init() { - nsresult rv = NS_OK; - mCatMgr = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsresult rv; + mNavInfo = do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID, &rv); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to get webnav info"); return rv; } @@ -182,38 +183,22 @@ nsDSURIContentListener::CanHandleContent(const char* aContentType, char ** aDesiredContentType, PRBool* aCanHandleContent) { - nsresult rv; - NS_ENSURE_ARG_POINTER(aCanHandleContent); + NS_PRECONDITION(aCanHandleContent, "Null out param?"); NS_ENSURE_ARG_POINTER(aDesiredContentType); *aCanHandleContent = PR_FALSE; + *aDesiredContentType = nsnull; - if (aContentType && mCatMgr) - { - rv = IsTypeSupported(aContentType, aCanHandleContent); - if (NS_FAILED(rv)) - return rv; - - if (!*aCanHandleContent) { - // Try loading plugins to see whether someone neglected to do so - nsCOMPtr pluginManager = - do_GetService("@mozilla.org/plugin/manager;1"); - if (pluginManager) { - // PR_FALSE will ensure that currently running plugins will not - // be shut down - rv = pluginManager->ReloadPlugins(PR_FALSE); - 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 IsTypeSupported(aContentType, aCanHandleContent); - } - } - } + nsresult rv = NS_OK; + if (aContentType) { + PRUint32 canHandle = nsIWebNavigationInfo::UNSUPPORTED; + rv = mNavInfo->IsTypeSupported(nsDependentCString(aContentType), + mDocShell, + &canHandle); + *aCanHandleContent = (canHandle != nsIWebNavigationInfo::UNSUPPORTED); } - return NS_OK; + return rv; } NS_IMETHODIMP @@ -275,30 +260,3 @@ nsDSURIContentListener::SetParentContentListener(nsIURIContentListener* } return NS_OK; } - -nsresult -nsDSURIContentListener::IsTypeSupported(const char* aContentType, - PRBool* aIsSupported) -{ - NS_PRECONDITION(aContentType, "Must have content type"); - NS_PRECONDITION(mCatMgr, "Must have category manager"); - NS_PRECONDITION(aIsSupported, "Null out param?"); - - nsXPIDLCString value; - nsresult rv = mCatMgr->GetCategoryEntry("Gecko-Content-Viewers", - aContentType, - getter_Copies(value)); - - // If the category manager can't find what we're looking for - // it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate - // that to the caller since it's really not a failure - - if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) - return rv; - - // XXXbz should we check that this service actually exists? May be a - // good idea... - - *aIsSupported = !value.IsEmpty(); - return NS_OK; -} diff --git a/mozilla/docshell/base/nsDSURIContentListener.h b/mozilla/docshell/base/nsDSURIContentListener.h index 9307c7e81e6..8996d6c6334 100644 --- a/mozilla/docshell/base/nsDSURIContentListener.h +++ b/mozilla/docshell/base/nsDSURIContentListener.h @@ -43,10 +43,10 @@ #include "nsCOMPtr.h" #include "nsString.h" #include "nsIURIContentListener.h" -#include "nsICategoryManager.h" #include "nsWeakReference.h" class nsDocShell; +class nsIWebNavigationInfo; class nsDSURIContentListener : public nsIURIContentListener, @@ -68,12 +68,6 @@ protected: mDocShell = nsnull; } - // Check whether aContentType is supported. If this method throws, the - // value of aIsSupported is undefined and should not be looked at. - // aContentType must not be null before this is called, and we must have an - // mCatMgr. - nsresult IsTypeSupported(const char* aContentType, PRBool* aIsSupported); - protected: nsDocShell* mDocShell; @@ -83,7 +77,7 @@ protected: nsWeakPtr mWeakParentContentListener; nsIURIContentListener* mParentContentListener; - nsCOMPtr mCatMgr; + nsCOMPtr mNavInfo; }; #endif /* nsDSURIContentListener_h__ */ diff --git a/mozilla/docshell/base/nsIWebNavigationInfo.idl b/mozilla/docshell/base/nsIWebNavigationInfo.idl new file mode 100644 index 00000000000..e59d6838e88 --- /dev/null +++ b/mozilla/docshell/base/nsIWebNavigationInfo.idl @@ -0,0 +1,97 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla.org code. + * + * The Initial Developer of the Original Code is + * Boris Zbarsky . + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsIWebNavigation; + +/** + * The nsIWebNavigationInfo interface exposes a way to get information + * on the capabilities of Gecko webnavigation objects. + * + * @status UNDER_REVIEW + */ +[scriptable, uuid(62a93afb-93a1-465c-84c8-0432264229de)] +interface nsIWebNavigationInfo : nsISupports +{ + /** + * Returned by isTypeSupported to indicate lack of support for a type. + * @note this is guaranteed not to change, so that boolean tests can be done + * on the return value if isTypeSupported to detect whether a type is + * supported at all. + */ + const unsigned long UNSUPPORTED = 0; + + /** + * Returned by isTypeSupported to indicate that a type is supported as an + * image. + */ + const unsigned long IMAGE = 1; + + /** + * Returned by isTypeSupported to indicate that a type is supported via an + * NPAPI ("Netscape 4 API") plug-in. This is not the value returned for + * "XPCOM plug-ins". + */ + const unsigned long PLUGIN = 2; + + /** + * @note Other return types may be added here in the future as they become + * relevant. + */ + + /** + * Returned by isTypeSupported to indicate that a type is supported via some + * other means. + */ + const unsigned long OTHER = 1 << 15; + + /** + * Query whether aType is supported. + * @param aType the MIME type in question. + * @param aWebNav the nsIWebNavigation object for which the request + * is being made. This is allowed to be null. If it is non-null, + * the return value of this method may depend on the exact state of + * aWebNav and the values set through nsIWebBrowserSetup; otherwise + * the method will assume that the caller is interested in information + * about nsIWebNavigation objects in their default state. + * @return an enum value indicating whether and how aType is supported. + * @note This method may rescan plugins to ensure that they're properly + * registered for the types they support. + */ + unsigned long isTypeSupported(in ACString aType, in nsIWebNavigation aWebNav); +}; diff --git a/mozilla/docshell/base/nsWebNavigationInfo.cpp b/mozilla/docshell/base/nsWebNavigationInfo.cpp new file mode 100644 index 00000000000..f52ef53841a --- /dev/null +++ b/mozilla/docshell/base/nsWebNavigationInfo.cpp @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla.org code. + * + * The Initial Developer of the Original Code is + * Boris Zbarsky . + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsWebNavigationInfo.h" +#include "nsIWebNavigation.h" +#include "nsString.h" +#include "nsServiceManagerUtils.h" +#include "nsIDocumentLoaderFactory.h" +#include "nsIPluginManager.h" + +NS_IMPL_ISUPPORTS1(nsWebNavigationInfo, nsIWebNavigationInfo) + +#define CONTENT_DLF_CONTRACT "@mozilla.org/content/document-loader-factory;1" +#define PLUGIN_DLF_CONTRACT \ + "@mozilla.org/content/plugin/document-loader-factory;1" + +nsresult +nsWebNavigationInfo::Init() +{ + nsresult rv; + mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + mImgLoader = do_GetService("@mozilla.org/image/loader;1", &rv); + + return rv; +} + +NS_IMETHODIMP +nsWebNavigationInfo::IsTypeSupported(const nsACString& aType, + nsIWebNavigation* aWebNav, + PRUint32* aIsTypeSupported) +{ + NS_PRECONDITION(aIsTypeSupported, "null out param?"); + + // 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. + + // For now just report what the Gecko-Content-Viewers category has + // to say for itself. + *aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED; + + const nsCString& flatType = PromiseFlatCString(aType); + nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported); + NS_ENSURE_SUCCESS(rv, rv); + + if (*aIsTypeSupported) { + return rv; + } + + // Try reloading plugins in case they've changed. + nsCOMPtr pluginManager = + do_GetService("@mozilla.org/plugin/manager;1"); + if (pluginManager) { + // PR_FALSE will ensure that currently running plugins will not + // be shut down + rv = pluginManager->ReloadPlugins(PR_FALSE); + 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 NS_OK; +} + +nsresult +nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType, + PRUint32* aIsSupported) +{ + NS_PRECONDITION(mCategoryManager, "Must have category manager"); + NS_PRECONDITION(aIsSupported, "Null out param?"); + + nsXPIDLCString value; + nsresult rv = mCategoryManager->GetCategoryEntry("Gecko-Content-Viewers", + aType.get(), + getter_Copies(value)); + + // If the category manager can't find what we're looking for + // it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate + // that to the caller since it's really not a failure + + if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) + return rv; + + // Now try to get an actual document loader factory for this contractid. If + // there is no contractid, don't try and just return false for *aIsSupported. + nsCOMPtr docLoaderFactory; + if (!value.IsEmpty()) { + docLoaderFactory = do_GetService(value.get()); + } + + // If we got a factory, we should be able to handle this type + if (!docLoaderFactory) { + *aIsSupported = nsIWebNavigationInfo::UNSUPPORTED; + } + else if (value.EqualsLiteral(CONTENT_DLF_CONTRACT)) { + PRBool isImage = PR_FALSE; + mImgLoader->SupportImageWithMimeType(aType.get(), &isImage); + if (isImage) { + *aIsSupported = nsIWebNavigationInfo::IMAGE; + } + else { + *aIsSupported = nsIWebNavigationInfo::OTHER; + } + } + else if (value.EqualsLiteral(PLUGIN_DLF_CONTRACT)) { + *aIsSupported = nsIWebNavigationInfo::PLUGIN; + } + else { + *aIsSupported = nsIWebNavigationInfo::OTHER; + } + + return NS_OK; +} diff --git a/mozilla/docshell/base/nsWebNavigationInfo.h b/mozilla/docshell/base/nsWebNavigationInfo.h new file mode 100644 index 00000000000..5a476cbac37 --- /dev/null +++ b/mozilla/docshell/base/nsWebNavigationInfo.h @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla.org code. + * + * The Initial Developer of the Original Code is + * Boris Zbarsky . + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsWebNavigationInfo_h__ +#define nsWebNavigationInfo_h__ + +#include "nsIWebNavigationInfo.h" +#include "nsCOMPtr.h" +#include "nsICategoryManager.h" +#include "imgILoader.h" +#include "nsStringFwd.h" + +// Class ID for webnavigationinfo +#define NS_WEBNAVIGATION_INFO_CID \ + { 0xf30bc0a2, 0x958b, 0x4287,{0xbf, 0x62, 0xce, 0x38, 0xba, 0x0c, 0x81, 0x1e}} + +class nsWebNavigationInfo : public nsIWebNavigationInfo +{ +public: + nsWebNavigationInfo() {} + + NS_DECL_ISUPPORTS + + NS_DECL_NSIWEBNAVIGATIONINFO + + nsresult Init(); + +private: + ~nsWebNavigationInfo() {} + + // Check whether aType is supported. If this method throws, the + // value of aIsSupported is not changed. + nsresult IsTypeSupportedInternal(const nsCString& aType, + PRUint32* aIsSupported); + + nsCOMPtr mCategoryManager; + // XXXbz we only need this because images register for the same + // contractid as documents, so we can't tell them apart based on + // contractid. + nsCOMPtr mImgLoader; +}; + +#endif // nsWebNavigationInfo_h__ diff --git a/mozilla/docshell/build/Makefile.in b/mozilla/docshell/build/Makefile.in index dad9826055b..e1f122e77bf 100644 --- a/mozilla/docshell/build/Makefile.in +++ b/mozilla/docshell/build/Makefile.in @@ -79,6 +79,7 @@ REQUIRES = xpcom \ mimetype \ rdf \ prefetch \ + imglib2 \ $(NULL) EXPORTS = \ diff --git a/mozilla/docshell/build/nsDocShellCID.h b/mozilla/docshell/build/nsDocShellCID.h index fa7cffeefe3..10524e898ff 100644 --- a/mozilla/docshell/build/nsDocShellCID.h +++ b/mozilla/docshell/build/nsDocShellCID.h @@ -41,4 +41,12 @@ #define NS_GLOBALHISTORY2_CONTRACTID \ "@mozilla.org/browser/global-history;2" +/** + * A contract that can be used to get a service that provides + * meta-information about nsIWebNavigation objects' capabilities. + * @implements nsIWebNavigationInfo + */ +#define NS_WEBNAVIGATION_INFO_CONTRACTID \ + "@mozilla.org/webnavigation-info;1" + #endif // nsDocShellCID_h__ diff --git a/mozilla/docshell/build/nsDocShellModule.cpp b/mozilla/docshell/build/nsDocShellModule.cpp index 78324dfaca1..b5ef6dc5c3f 100644 --- a/mozilla/docshell/build/nsDocShellModule.cpp +++ b/mozilla/docshell/build/nsDocShellModule.cpp @@ -39,8 +39,12 @@ #include "nsIModule.h" #include "nsIGenericFactory.h" + +#include "nsDocShellCID.h" + #include "nsWebShell.h" #include "nsDefaultURIFixup.h" +#include "nsWebNavigationInfo.h" // uriloader #include "nsURILoader.h" @@ -61,6 +65,7 @@ // docshell NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWebShell, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDefaultURIFixup) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWebNavigationInfo, Init) // uriloader NS_GENERIC_FACTORY_CONSTRUCTOR(nsURILoader) @@ -99,6 +104,11 @@ static const nsModuleComponentInfo gDocShellModuleInfo[] = { NS_URIFIXUP_CONTRACTID, nsDefaultURIFixupConstructor }, + { "Webnavigation info service", + NS_WEBNAVIGATION_INFO_CID, + NS_WEBNAVIGATION_INFO_CONTRACTID, + nsWebNavigationInfoConstructor + }, // uriloader { "Netscape URI Loader Service", NS_URI_LOADER_CID, NS_URI_LOADER_CONTRACTID, nsURILoaderConstructor, }, diff --git a/mozilla/embedding/browser/activex/src/control/WebBrowserContainer.cpp b/mozilla/embedding/browser/activex/src/control/WebBrowserContainer.cpp index 301215dad9a..06b6a9b3210 100644 --- a/mozilla/embedding/browser/activex/src/control/WebBrowserContainer.cpp +++ b/mozilla/embedding/browser/activex/src/control/WebBrowserContainer.cpp @@ -43,9 +43,11 @@ #include "WebBrowserContainer.h" -#include "nsICategoryManager.h" #include "nsReadableUtils.h" +#include "nsServiceManagerUtils.h" +#include "nsIWebNavigationInfo.h" + CWebBrowserContainer::CWebBrowserContainer(CMozillaBrowser *pOwner) : mOwner(pOwner), mEvents1(mOwner), @@ -405,28 +407,25 @@ NS_IMETHODIMP CWebBrowserContainer::IsPreferred(const char *aContentType, char * NS_IMETHODIMP CWebBrowserContainer::CanHandleContent(const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType, PRBool *_retval) { *_retval = PR_FALSE; + *aDesiredContentType = nsnull; if (aContentType) { - nsCOMPtr catMgr; - nsresult rv; - catMgr = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - nsXPIDLCString value; - rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers", - aContentType, - getter_Copies(value)); - - // If the category manager can't find what we're looking for - // it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate - // that to the caller since it's really not a failure - - if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) - return rv; - - if (value && *value) - *_retval = PR_TRUE; + nsCOMPtr webNav(do_QueryInterface(mOwner->mWebBrowser)); + nsCOMPtr webNavInfo( + do_GetService("@mozilla.org/webnavigation-info;1")); + if (webNavInfo) + { + PRUint32 canHandle; + nsresult rv = + webNavInfo->IsTypeSupported(nsDependentCString(aContentType), + webNav, + &canHandle); + NS_ENSURE_SUCCESS(rv, rv); + *_retval = (canHandle != nsIWebNavigationInfo::UNSUPPORTED); + } } + return NS_OK; } diff --git a/mozilla/embedding/browser/gtk/src/EmbedContentListener.cpp b/mozilla/embedding/browser/gtk/src/EmbedContentListener.cpp index e8129f31d3f..eab8902fdee 100644 --- a/mozilla/embedding/browser/gtk/src/EmbedContentListener.cpp +++ b/mozilla/embedding/browser/gtk/src/EmbedContentListener.cpp @@ -43,8 +43,9 @@ #include "EmbedContentListener.h" #include "EmbedPrivate.h" -#include "nsICategoryManager.h" #include "nsServiceManagerUtils.h" +#include "nsIWebNavigationInfo.h" +#include "nsDocShellCID.h" EmbedContentListener::EmbedContentListener(void) { @@ -114,26 +115,20 @@ EmbedContentListener::CanHandleContent(const char *aContentType, PRBool *_retval) { *_retval = PR_FALSE; + *aDesiredContentType = nsnull; if (aContentType) { - nsCOMPtr catMgr; - nsresult rv; - catMgr = do_GetService("@mozilla.org/categorymanager;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - nsXPIDLCString value; - rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers", - aContentType, - getter_Copies(value)); - - // If the category manager can't find what we're looking for - // it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate - // that to the caller since it's really not a failure - - if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) - return rv; - - if (value && *value) - *_retval = PR_TRUE; + nsCOMPtr webNavInfo( + do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID)); + if (webNavInfo) { + PRUint32 canHandle; + nsresult rv = + webNavInfo->IsTypeSupported(nsDependentCString(aContentType), + mOwner ? mOwner->mNavigation : nsnull, + &canHandle); + NS_ENSURE_SUCCESS(rv, rv); + *_retval = (canHandle != nsIWebNavigationInfo::UNSUPPORTED); + } } return NS_OK; } diff --git a/mozilla/embedding/browser/photon/src/EmbedContentListener.cpp b/mozilla/embedding/browser/photon/src/EmbedContentListener.cpp index f246f3a1a79..c8224904b35 100644 --- a/mozilla/embedding/browser/photon/src/EmbedContentListener.cpp +++ b/mozilla/embedding/browser/photon/src/EmbedContentListener.cpp @@ -46,8 +46,9 @@ #include "PtMozilla.h" -#include "nsICategoryManager.h" #include "nsServiceManagerUtils.h" +#include "nsIWebNavigationInfo.h" +#include "nsDocShellCID.h" EmbedContentListener::EmbedContentListener(void) { @@ -126,26 +127,20 @@ EmbedContentListener::CanHandleContent(const char *aContentType, PRBool *_retval) { *_retval = PR_FALSE; + *aDesiredContentType = nsnull; if (aContentType) { - nsCOMPtr catMgr; - nsresult rv; - catMgr = do_GetService("@mozilla.org/categorymanager;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - nsXPIDLCString value; - rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers", - aContentType, - getter_Copies(value)); - - // If the category manager can't find what we're looking for - // it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate - // that to the caller since it's really not a failure - - if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) - return rv; - - if (value && *value) - *_retval = PR_TRUE; + nsCOMPtr webNavInfo( + do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID)); + if (webNavInfo) { + PRUint32 canHandle; + nsresult rv = + webNavInfo->IsTypeSupported(nsDependentCString(aContentType), + mOwner ? mOwner->mNavigation : nsnull, + &canHandle); + NS_ENSURE_SUCCESS(rv, rv); + *_retval = (canHandle != nsIWebNavigationInfo::UNSUPPORTED); + } } return NS_OK; } diff --git a/mozilla/embedding/browser/qt/src/EmbedContentListener.cpp b/mozilla/embedding/browser/qt/src/EmbedContentListener.cpp index 8e0dae101bc..7654141b687 100644 --- a/mozilla/embedding/browser/qt/src/EmbedContentListener.cpp +++ b/mozilla/embedding/browser/qt/src/EmbedContentListener.cpp @@ -44,8 +44,9 @@ #include "EmbedContentListener.h" #include "qgeckoembed.h" -#include "nsICategoryManager.h" #include "nsServiceManagerUtils.h" +#include "nsIWebNavigationInfo.h" +#include "nsDocShellCID.h" EmbedContentListener::EmbedContentListener(QGeckoEmbed *aOwner) { @@ -107,27 +108,21 @@ EmbedContentListener::CanHandleContent(const char *aContentType, PRBool *_retval) { *_retval = PR_FALSE; + *aDesiredContentType = nsnull; qDebug("HANDLING:"); if (aContentType) { - nsCOMPtr catMgr; - nsresult rv; - catMgr = do_GetService("@mozilla.org/categorymanager;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - nsXPIDLCString value; - rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers", - aContentType, - getter_Copies(value)); - - // If the category manager can't find what we're looking for - // it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate - // that to the caller since it's really not a failure - - if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) - return rv; - - if (value && *value) - *_retval = PR_TRUE; + nsCOMPtr webNavInfo( + do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID)); + if (webNavInfo) { + PRUint32 canHandle; + nsresult rv = + webNavInfo->IsTypeSupported(nsDependentCString(aContentType), + mOwner ? mOwner->d->navigation : nsnull, + &canHandle); + NS_ENSURE_SUCCESS(rv, rv); + *_retval = (canHandle != nsIWebNavigationInfo::UNSUPPORTED); + } } qDebug("\tCan handle content %s: %d", aContentType, *_retval); diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index fb83a1a12cf..2d5a0f06543 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -77,6 +77,9 @@ #include "nsLayoutAtoms.h" #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeOwner.h" +#include "nsIWebNavigation.h" +#include "nsIWebNavigationInfo.h" +#include "nsDocShellCID.h" #include "nsIWebBrowserChrome.h" #include "nsIDOMElement.h" #include "nsIDOMNodeList.h" @@ -500,25 +503,22 @@ IsSupportedImageMimeType(const char *aMimeType) } static PRBool -IsSupportedDocumentMimeType(const char *aMimeType) +IsSupportedDocumentMimeType(nsIContent* aOurContent, + const nsCString& aMimeType) { - nsCOMPtr catman = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID); - if (!catman) - return PR_FALSE; - - nsXPIDLCString value; - nsresult rv = catman->GetCategoryEntry("Gecko-Content-Viewers", aMimeType, - getter_Copies(value)); - - // If we have a content viewer entry in the catagory manager for - // this mime type and it's not the full-page plugin one, return - // PR_TRUE to act like an IFRAME. - return - NS_SUCCEEDED(rv) && - !value.IsEmpty() && - !value.Equals("@mozilla.org/content/plugin/document-loader-factory;1"); + nsresult rv; + nsCOMPtr info( + do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID, &rv)); + PRUint32 supported; + if (info) { + nsCOMPtr webNav = + do_GetInterface(aOurContent->GetCurrentDoc()->GetScriptGlobalObject()); + rv = info->IsTypeSupported(aMimeType, webNav, &supported); + } + return NS_SUCCEEDED(rv) && + supported != nsIWebNavigationInfo::UNSUPPORTED && + supported != nsIWebNavigationInfo::PLUGIN; } // static @@ -621,7 +621,7 @@ nsObjectFrame::IsSupportedDocument(nsIContent* aContent) #endif return PR_FALSE; - return IsSupportedDocumentMimeType(typeStr.get()); + return IsSupportedDocumentMimeType(aContent, typeStr); } NS_IMETHODIMP @@ -3072,6 +3072,11 @@ void nsObjectFrame::FixUpURLS(const nsString &name, nsAString &value) void nsObjectFrame::PluginNotAvailable(const char *aMimeType) { + if (!aMimeType) { + NS_ERROR("bogus type... behavior will be broken"); + return; + } + // Tell mContent about the mime type nsCOMPtr object(do_QueryInterface(mContent)); @@ -3094,7 +3099,7 @@ nsObjectFrame::PluginNotAvailable(const char *aMimeType) // For non-image and non-document mime types, fire the plugin not // found event and mark this plugin as broken. if (!IsSupportedImageMimeType(aMimeType) && - !IsSupportedDocumentMimeType(aMimeType)) { + !IsSupportedDocumentMimeType(mContent, nsDependentCString(aMimeType))) { FirePluginNotFoundEvent(mContent); mIsBrokenPlugin = PR_TRUE; diff --git a/mozilla/xpfe/browser/resources/content/nsBrowserContentListener.js b/mozilla/xpfe/browser/resources/content/nsBrowserContentListener.js index 645ec5bbfb4..c0df6dcdf9b 100644 --- a/mozilla/xpfe/browser/resources/content/nsBrowserContentListener.js +++ b/mozilla/xpfe/browser/resources/content/nsBrowserContentListener.js @@ -136,15 +136,10 @@ nsBrowserContentListener.prototype = isPreferred: function(contentType, desiredContentType) { try { - var catMgr = Components.classes["@mozilla.org/categorymanager;1"] - .getService(Components.interfaces.nsICategoryManager); - var entry = catMgr.getCategoryEntry("Gecko-Content-Viewers", - contentType); - if (entry) { - return true; - } - - return false; + var webNavInfo = + Components.classes["@mozilla.org/webnavigation-info;1"] + .getService(Components.interfaces.nsIWebNavigationInfo); + return webNavInfo.isTypeSupported(contentType, null); } catch (e) { // XXX propagate failures other than "NS_ERROR_NOT_AVAILABLE"? // This seems to never get called, so not like it matters.... diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index d9b57bb8232..3d9ee983225 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -45,7 +45,8 @@ // Interfaces Needed #include "nsIBaseWindow.h" -#include "nsICategoryManager.h" +#include "nsIWebNavigationInfo.h" +#include "nsDocShellCID.h" #include "nsIDocShell.h" #include "nsIDocShellTreeItem.h" #include "nsIHttpProtocolHandler.h" @@ -791,21 +792,21 @@ NS_IMETHODIMP nsBrowserContentHandler::HandleContent(const char * aContentType, nsIInterfaceRequestor * aWindowContext, nsIRequest * aRequest) { + NS_PRECONDITION(aContentType, "Must have a content type"); + // Verify that we can handle this content, to avoid infinite window opening // loops nsresult rv; - nsCOMPtr catMan = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + nsCOMPtr webNavInfo = + do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsXPIDLCString value; - rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", - aContentType, - getter_Copies(value)); + PRUint32 typeSupported; + rv = webNavInfo->IsTypeSupported(nsDependentCString(aContentType), nsnull, + &typeSupported); + NS_ENSURE_SUCCESS(rv, rv); - // If there is no value (i.e. rv is NS_ERROR_NOT_AVAILABLE), we can't handle - // the content. - if (rv == NS_ERROR_NOT_AVAILABLE) + if (!typeSupported) return NS_ERROR_WONT_HANDLE_CONTENT; // create a new browser window to handle the content diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul b/mozilla/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul index 0c37c0413c7..08ace96581f 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-applications-edit.xul @@ -315,9 +315,10 @@ // Check if Mozilla can handle this type internally, in which case // an entry would have no effect try { - var categoryManager = Components.classes["@mozilla.org/categorymanager;1"] - .getService(Components.interfaces.nsICategoryManager); - if (categoryManager.getCategoryEntry("Gecko-Content-Viewers", gMIMEField.value)) { + var webNavigationInfo = + Components.classes["@mozilla.org/webnavigation-info;1"] + .getService(Components.interfaces.nsIWebNavigationInfo); + if (webNavigationInfo.isTypeSupported(gMIMEField.value, null)) { var brandBundle = document.getElementById("bundle_Brand"); var text = gPrefApplicationsBundle.getString("canHandleInternally"); text = text.replace(/%brand%/g, brandBundle.getString("brandShortName"));