diff --git a/docshell/base/nsDownloadHistory.cpp b/docshell/base/nsDownloadHistory.cpp index a6b26b431fa..d62788985a9 100644 --- a/docshell/base/nsDownloadHistory.cpp +++ b/docshell/base/nsDownloadHistory.cpp @@ -44,12 +44,43 @@ #include "nsIGlobalHistory2.h" #include "nsIObserverService.h" #include "nsIURI.h" +#include "nsIComponentRegistrar.h" +#include "nsDocShellCID.h" //////////////////////////////////////////////////////////////////////////////// //// nsDownloadHistory NS_IMPL_ISUPPORTS1(nsDownloadHistory, nsIDownloadHistory) +nsresult +nsDownloadHistory::RegisterSelf(nsIComponentManager *aCompMgr, + nsIFile *aPath, + const char *aLoaderStr, + const char *aType, + const nsModuleComponentInfo *aInfo) +{ + nsCOMPtr compReg(do_QueryInterface(aCompMgr)); + if (!compReg) + return NS_ERROR_UNEXPECTED; + + PRBool registered; + nsresult rv = compReg->IsContractIDRegistered(NS_DOWNLOADHISTORY_CONTRACTID, + ®istered); + NS_ENSURE_SUCCESS(rv, rv); + + // If someone has already registered the contractID, we don't want to register + // it ourself. We do want to register though in case someone wants to access + // this implementation (by CID). + if (registered) { + return compReg->RegisterFactoryLocation(GetCID(), "nsDownloadHistory", + nsnull, aPath, aLoaderStr, aType); + } + + return compReg->RegisterFactoryLocation(GetCID(), "nsDownloadHistory", + NS_DOWNLOADHISTORY_CONTRACTID, + aPath, aLoaderStr, aType); +} + //////////////////////////////////////////////////////////////////////////////// //// nsIDownloadHistory diff --git a/docshell/base/nsDownloadHistory.h b/docshell/base/nsDownloadHistory.h index 05d28bbf9e8..86bc0778450 100644 --- a/docshell/base/nsDownloadHistory.h +++ b/docshell/base/nsDownloadHistory.h @@ -41,6 +41,7 @@ #define __nsDownloadHistory_h__ #include "nsIDownloadHistory.h" +#include "nsIGenericFactory.h" #define NS_DOWNLOADHISTORY_CID \ {0x2ee83680, 0x2af0, 0x4bcb, {0xbf, 0xa0, 0xc9, 0x70, 0x5f, 0x65, 0x54, 0xf1}} @@ -50,6 +51,14 @@ class nsDownloadHistory : public nsIDownloadHistory public: NS_DECL_ISUPPORTS NS_DECL_NSIDOWNLOADHISTORY + + static NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, + nsIFile *aPath, + const char *aLoaderStr, + const char *aType, + const nsModuleComponentInfo *aInfo); + + NS_DEFINE_STATIC_CID_ACCESSOR(NS_DOWNLOADHISTORY_CID) }; #endif // __nsDownloadHistory_h__ diff --git a/docshell/build/nsDocShellModule.cpp b/docshell/build/nsDocShellModule.cpp index d38b31642cb..6138db08eda 100644 --- a/docshell/build/nsDocShellModule.cpp +++ b/docshell/build/nsDocShellModule.cpp @@ -250,7 +250,8 @@ static const nsModuleComponentInfo gDocShellModuleInfo[] = { // download history { "nsDownloadHistory", NS_DOWNLOADHISTORY_CID, - NS_DOWNLOADHISTORY_CONTRACTID, nsDownloadHistoryConstructor } + nsnull, nsDownloadHistoryConstructor, + nsDownloadHistory::RegisterSelf } }; // "docshell provider" to illustrate that this thing really *should*