From b99eb21d102dfbab40a6795e12d4fabeeef04f7c Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Thu, 18 Nov 1999 07:19:39 +0000 Subject: [PATCH] Bug #14928 --> inital uri dispatching landing. the app instance is a uri content listener. implement that interface. Register the content listener with the uri loader when we are created and again when we go away. Forward doContent calls on nsIURIContentListener to the webshell where we want content displayed. r=travis --- xpfe/browser/src/nsBrowserInstance.cpp | 124 ++++++++++++++++--------- xpfe/browser/src/nsBrowserInstance.h | 11 ++- 2 files changed, 87 insertions(+), 48 deletions(-) diff --git a/xpfe/browser/src/nsBrowserInstance.cpp b/xpfe/browser/src/nsBrowserInstance.cpp index 2ed3f1783ab..cd3cd860613 100644 --- a/xpfe/browser/src/nsBrowserInstance.cpp +++ b/xpfe/browser/src/nsBrowserInstance.cpp @@ -81,6 +81,9 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsIFileLocator.h" #include "nsIFileSpec.h" #include "nsIWalletService.h" + +#include "nsCURILoader.h" + static NS_DEFINE_IID(kIWalletServiceIID, NS_IWALLETSERVICE_IID); static NS_DEFINE_IID(kWalletServiceCID, NS_WALLETSERVICE_CID); @@ -161,50 +164,15 @@ nsBrowserAppCore::~nsBrowserAppCore() NS_IF_RELEASE(mSHistory); } +NS_IMPL_ADDREF(nsBrowserAppCore) +NS_IMPL_RELEASE(nsBrowserAppCore) -NS_IMPL_ADDREF(nsBrowserInstance) -NS_IMPL_RELEASE(nsBrowserInstance) - - -NS_IMETHODIMP -nsBrowserAppCore::QueryInterface(REFNSIID aIID,void** aInstancePtr) -{ - if (aInstancePtr == NULL) { - return NS_ERROR_NULL_POINTER; - } - - // Always NULL result, in case of failure - *aInstancePtr = NULL; - - if ( aIID.Equals( nsIBrowserInstance::GetIID() ) ) { - *aInstancePtr = this; - this->AddRef(); - return NS_OK; - } - - if (aIID.Equals(nsIDocumentLoaderObserver::GetIID())) { - nsIDocumentLoaderObserver *self = this; - *aInstancePtr = self; - self->AddRef(); - return NS_OK; - } - - if (aIID.Equals( nsIObserver::GetIID())) { - nsIObserver *self = this; - *aInstancePtr = self; - self->AddRef(); - return NS_OK; - } - - if ( aIID.Equals( nsCOMTypeInfo::GetIID() ) ) { - nsISupports *self = (nsIBrowserInstance*)this; - *aInstancePtr = self; - self->AddRef(); - return NS_OK; - } - - return NS_ERROR_NO_INTERFACE; -} +NS_IMPL_QUERY_HEAD(nsBrowserAppCore) + NS_IMPL_QUERY_BODY(nsIBrowserInstance) + NS_IMPL_QUERY_BODY(nsIDocumentLoaderObserver) + NS_IMPL_QUERY_BODY(nsIObserver) + NS_IMPL_QUERY_BODY(nsIURIContentListener) +NS_IMPL_QUERY_TAIL(nsIBrowserInstance) static nsIPresShell* @@ -245,12 +213,19 @@ nsBrowserAppCore::Init() (void **)&mSHistory ); if ( NS_SUCCEEDED( rv ) ) { +#ifdef DEBUG_radha printf("Successfully created instance of session history\n"); +#endif // Add this object of observer of various events. BeginObserving(); } - - + + // register ourselves as a content listener with the uri dispatcher service + rv = NS_OK; + NS_WITH_SERVICE(nsIURILoader, dispatcher, NS_URI_LOADER_PROGID, &rv); + if (NS_SUCCEEDED(rv)) + rv = dispatcher->RegisterContentListener(this); + return rv; } @@ -1273,6 +1248,9 @@ nsBrowserAppCore::SetWebShellWindow(nsIDOMWindow* aWin) if (nsnull != webShell) { mWebShell = webShell; //NS_ADDREF(mWebShell); WE DO NOT OWN THIS + // inform our top level webshell that we are its parent URI content listener... + mWebShell->SetParentURIContentListener(this); + const PRUnichar * name; webShell->GetName( &name); nsAutoString str(name); @@ -1956,6 +1934,13 @@ nsBrowserAppCore::Close() // Release search context. mSearchContext = 0; + // unregister ourselves with the uri loader because + // we can no longer accept new content! + nsresult rv = NS_OK; + NS_WITH_SERVICE(nsIURILoader, dispatcher, NS_URI_LOADER_PROGID, &rv); + if (NS_SUCCEEDED(rv)) + rv = dispatcher->UnRegisterContentListener(this); + return NS_OK; } @@ -2222,6 +2207,55 @@ nsBrowserInstance::SetIsViewSource(PRBool aBool) { return rv; } +// nsIURIContentListener support + +NS_IMETHODIMP +nsBrowserInstance::GetProtocolHandler(nsIURI * /* aURI */, nsIProtocolHandler **aProtocolHandler) +{ + // we don't have any app specific protocol handlers we want to use so + // just use the system default by returning null. + *aProtocolHandler = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserInstance::DoContent(const char *aContentType, const char *aCommand, const char *aWindowTarget, + nsIChannel *aChannel, nsIStreamListener **aContentHandler, PRBool *aAbortProcess) +{ + // forward the DoContent call to our content area webshell + nsCOMPtr ctnListener = do_QueryInterface(mContentAreaWebShell); + if (ctnListener) + return ctnListener->DoContent(aContentType, aCommand, aWindowTarget, aChannel, aContentHandler, aAbortProcess); + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserInstance::CanHandleContent(const char * aContentType, + const char * aCommand, + const char * aWindowTarget, + char ** aDesiredContentType, + PRBool * aCanHandleContent) + +{ + // need to list all the content types the browser window knows how to handle here: + if (aContentType) + { + if (nsCRT::strcasecmp(aContentType, "multipart/x-mixed-replace") == 0) + { + *aDesiredContentType = nsCRT::strdup("text/html"); + *aCanHandleContent = PR_TRUE; + } + if (nsCRT::strcasecmp(aContentType, "text/html") == 0) + *aCanHandleContent = PR_TRUE; + + } + else + *aCanHandleContent = PR_FALSE; + + return NS_OK; +} + + NS_DEFINE_MODULE_INSTANCE_COUNTER() NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsBrowserInstance, Init) diff --git a/xpfe/browser/src/nsBrowserInstance.h b/xpfe/browser/src/nsBrowserInstance.h index c5394bba9dd..f38c4927346 100644 --- a/xpfe/browser/src/nsBrowserInstance.h +++ b/xpfe/browser/src/nsBrowserInstance.h @@ -35,6 +35,7 @@ #include "nsIDocumentLoaderObserver.h" #include "nsIObserver.h" #include "nsISessionHistory.h" +#include "nsIURIContentListener.h" class nsIBrowserWindow; class nsIWebShell; @@ -45,6 +46,7 @@ class nsIURI; class nsIWebShellWindow; class nsIFindComponent; + #define SHISTORY_POPUP_LIST 10 // {5551A1E0-5A66-11d3-806A-00600811A9C3} @@ -57,7 +59,8 @@ class nsIFindComponent; class nsBrowserInstance : public nsIBrowserInstance, public nsIDocumentLoaderObserver, public nsIObserver, - public nsISessionHistory { + public nsISessionHistory, + public nsIURIContentListener { public: nsBrowserInstance(); @@ -82,6 +85,8 @@ class nsBrowserInstance : public nsIBrowserInstance, NS_DECL_NSIOBSERVER // nsISessionHistory NS_DECL_NSISESSIONHISTORY + // URI Content listener + NS_DECL_NSIURICONTENTLISTENER protected: NS_IMETHOD ExecuteScript(nsIScriptContext * aContext, const nsString& aScript); @@ -89,8 +94,8 @@ class nsBrowserInstance : public nsIBrowserInstance, void BeginObserving(); void EndObserving(); NS_IMETHOD CreateMenuItem(nsIDOMNode * , PRInt32,const PRUnichar * ); - NS_IMETHOD UpdateGoMenu(); - NS_IMETHOD ClearHistoryPopup(nsIDOMNode * ); + NS_IMETHOD UpdateGoMenu(); + NS_IMETHOD ClearHistoryPopup(nsIDOMNode * ); PRBool mIsViewSource;