From a018a396016d8dc64b77349a3e8ffa504a7352a8 Mon Sep 17 00:00:00 2001 From: "spider%netscape.com" Date: Fri, 11 Sep 1998 02:26:35 +0000 Subject: [PATCH] Implemented asynchronous stream manager for loading multiple XML UI definitions simultaneously --- calendar/modules/network/manifest.mn | 2 +- calendar/modules/shell/inc/nsCalendarWidget.h | 2 - .../modules/shell/public/nsICalendarWidget.h | 2 - .../modules/shell/src/nsCalendarShell.cpp | 9 +- .../modules/shell/src/nsCalendarWidget.cpp | 29 ---- calendar/modules/ui/core/inc/nscalstrings.h | 2 + xpfc/core/inc/nsxpfcCIID.h | 5 + xpfc/core/inc/nsxpfcFactory.h | 3 + xpfc/core/src/nsxpfcFactory.cpp | 2 + xpfc/shell/inc/manifest.mn | 1 + xpfc/shell/inc/nsStreamManager.h | 4 +- xpfc/shell/inc/nsStreamObject.h | 67 +++++++++ xpfc/shell/public/manifest.mn | 1 + xpfc/shell/public/nsIStreamManager.h | 1 - xpfc/shell/public/nsIStreamObject.h | 47 +++++++ xpfc/shell/src/manifest.mn | 1 + xpfc/shell/src/nsStreamManager.cpp | 94 +++++++++---- xpfc/shell/src/nsStreamObject.cpp | 128 ++++++++++++++++++ xpfc/shell/src/unix/main.cpp | 2 + xpfc/shell/src/windows/winmain.cpp | 2 + 20 files changed, 336 insertions(+), 68 deletions(-) create mode 100644 xpfc/shell/inc/nsStreamObject.h create mode 100644 xpfc/shell/public/nsIStreamObject.h create mode 100644 xpfc/shell/src/nsStreamObject.cpp diff --git a/calendar/modules/network/manifest.mn b/calendar/modules/network/manifest.mn index 045984263985..1541bb0d4c4e 100644 --- a/calendar/modules/network/manifest.mn +++ b/calendar/modules/network/manifest.mn @@ -10,7 +10,7 @@ GDEPTH = ../../.. DEPTH = ../../.. -DIRS = stream capi +DIRS = capi LIBRARY_NAME = calnetwork diff --git a/calendar/modules/shell/inc/nsCalendarWidget.h b/calendar/modules/shell/inc/nsCalendarWidget.h index 5daa017791bd..8ddc2a34e93d 100644 --- a/calendar/modules/shell/inc/nsCalendarWidget.h +++ b/calendar/modules/shell/inc/nsCalendarWidget.h @@ -74,8 +74,6 @@ public: NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent); - NS_IMETHOD_(nsIStreamListener *) GetParserStreamInterface(); - NS_IMETHOD GetRootCanvas(nsIXPFCCanvas ** aCanvas) ; private: diff --git a/calendar/modules/shell/public/nsICalendarWidget.h b/calendar/modules/shell/public/nsICalendarWidget.h index 30fd0699067a..8d07b1b24278 100644 --- a/calendar/modules/shell/public/nsICalendarWidget.h +++ b/calendar/modules/shell/public/nsICalendarWidget.h @@ -60,8 +60,6 @@ public: NS_IMETHOD BindToDocument(nsISupports *aDoc, const char *aCommand) = 0; - NS_IMETHOD_(nsIStreamListener *) GetParserStreamInterface() = 0; - NS_IMETHOD LoadURL(const nsString& aURLSpec, nsIStreamObserver* aListener, nsIPostData* aPostData = 0) = 0; diff --git a/calendar/modules/shell/src/nsCalendarShell.cpp b/calendar/modules/shell/src/nsCalendarShell.cpp index 5113ca62f99d..a111ffff1ce4 100644 --- a/calendar/modules/shell/src/nsCalendarShell.cpp +++ b/calendar/modules/shell/src/nsCalendarShell.cpp @@ -540,6 +540,7 @@ typedef struct static JULIAN_KEY_VAL KVPairs[] = { CAL_STRING_PREF_JULIAN_UI_XML_MENUBAR, CAL_STRING_RESOURCE_UI_MENUBAR, + CAL_STRING_PREF_JULIAN_UI_XML_TOOLBAR, CAL_STRING_RESOURCE_UI_TOOLBAR, CAL_STRING_PREF_JULIAN_UI_XML_CALENDAR, CAL_STRING_RESOURCE_UI_CALENDAR, CAL_STRING_PREF_LOCAL_ADDRESS, CAL_STRING_PREF_LOCAL_ADDRESS_DEFAULT, CAL_STRING_PREF_PREFERRED_ADDR, CAL_STRING_PREF_PREFERRED_ADDR_DEFAULT, @@ -790,11 +791,15 @@ nsresult nsCalendarShell::LoadUI() */ #ifdef XP_UNIX mShellInstance->GetPreferences()->GetCharPref(CAL_STRING_PREF_JULIAN_UI_XML_CALENDAR,pUI,&i); + res = mDocumentContainer->LoadURL(pUI,nsnull); #else mShellInstance->GetPreferences()->GetCharPref(CAL_STRING_PREF_JULIAN_UI_XML_MENUBAR,pUI,&i); -#endif - res = mDocumentContainer->LoadURL(pUI,nsnull); + mShellInstance->GetPreferences()->GetCharPref(CAL_STRING_PREF_JULIAN_UI_XML_CALENDAR,pUI,&i); + res = mDocumentContainer->LoadURL(pUI,nsnull); + mShellInstance->GetPreferences()->GetCharPref(CAL_STRING_PREF_JULIAN_UI_XML_TOOLBAR,pUI,&i); + res = mDocumentContainer->LoadURL(pUI,nsnull); +#endif mShellInstance->ShowApplicationWindow(PR_TRUE) ; diff --git a/calendar/modules/shell/src/nsCalendarWidget.cpp b/calendar/modules/shell/src/nsCalendarWidget.cpp index 161df869e0e5..22a31b306002 100644 --- a/calendar/modules/shell/src/nsCalendarWidget.cpp +++ b/calendar/modules/shell/src/nsCalendarWidget.cpp @@ -55,7 +55,6 @@ class nsICalendarShell; #include "nsCalXMLDTD.h" #include "nsXPFCXMLContentSink.h" #include "nsXPFCXMLDTD.h" -#include "nsCalStreamListener.h" #include "nsCurlParser.h" #include "nsCalToolkit.h" #include "nsBoxLayout.h" @@ -213,14 +212,6 @@ nsresult nsCalendarWidget::LoadURL(const nsString& aURLSpec, nsIStreamObserver* if (stream_manager == nsnull) return NS_OK; - static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); - - nsIStreamListener * stream_listener; - - NS_NewCalStreamListener(&stream_listener); - - ((nsCalStreamListener *)stream_listener)->SetWidget(this); - nsIID * iid_dtd = nsnull; nsIID * iid_sink = nsnull ; @@ -236,7 +227,6 @@ nsresult nsCalendarWidget::LoadURL(const nsString& aURLSpec, nsIStreamObserver* res = stream_manager->LoadURL(((nsCalendarShell*)mCalendarShell)->mDocumentContainer, aURLSpec, - stream_listener, aPostData,iid_dtd,iid_sink); return res; @@ -270,25 +260,6 @@ nsEventStatus nsCalendarWidget::HandleEvent(nsGUIEvent *aEvent) return (mRootCanvas->HandleEvent(aEvent)); } -nsIStreamListener * nsCalendarWidget::GetParserStreamInterface() -{ - NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); - - nsIStreamManager * stream_manager = ((nsCalendarShell *)mCalendarShell)->mShellInstance->GetStreamManager(); - - if (stream_manager == nsnull) - return nsnull; - - nsIStreamListener * aStreamListener ; - - nsresult res = ((nsStreamManager *)stream_manager)->mParser->QueryInterface(kIStreamListenerIID, (void **)&aStreamListener); - - if (NS_OK != res) - return (nsnull); - - return (aStreamListener); -} - nsresult nsCalendarWidget::GetRootCanvas(nsIXPFCCanvas ** aCanvas) { diff --git a/calendar/modules/ui/core/inc/nscalstrings.h b/calendar/modules/ui/core/inc/nscalstrings.h index 5416caa1ded3..6c622d96f7a9 100644 --- a/calendar/modules/ui/core/inc/nscalstrings.h +++ b/calendar/modules/ui/core/inc/nscalstrings.h @@ -34,6 +34,7 @@ #define CAL_STRING_HEIGHT "height" #define CAL_STRING_HOUR "hour" #define CAL_STRING_PREF_JULIAN_UI_XML_MENUBAR "julian.ui.xml.menubar" +#define CAL_STRING_PREF_JULIAN_UI_XML_TOOLBAR "julian.ui.xml.toolbar" #define CAL_STRING_PREF_JULIAN_UI_XML_CALENDAR "julian.ui.xml.calendar" #define CAL_STRING_ID "id" #define CAL_STRING_LABEL "label" @@ -48,6 +49,7 @@ #define CAL_STRING_ORIENTATION "orientation" #define CAL_STRING_PANEL "panel" #define CAL_STRING_RESOURCE_UI_MENUBAR "resource://res/ui/menubar.ui" +#define CAL_STRING_RESOURCE_UI_TOOLBAR "resource://res/ui/toolbar.ui" #define CAL_STRING_RESOURCE_UI_CALENDAR "resource://res/ui/julian.cal" #define CAL_STRING_RULE "rule" #define CAL_STRING_SECOND "second" diff --git a/xpfc/core/inc/nsxpfcCIID.h b/xpfc/core/inc/nsxpfcCIID.h index 916204876f76..73692ba49306 100644 --- a/xpfc/core/inc/nsxpfcCIID.h +++ b/xpfc/core/inc/nsxpfcCIID.h @@ -37,6 +37,11 @@ { 0x03dd8f40, 0x3610, 0x11d2, \ {0x92, 0x48, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6} } +// f7c349a0-4915-11d2-924a-00805f8a7ab6 +#define NS_STREAM_OBJECT_CID \ + { 0xf7c349a0, 0x4915, 0x11d2, \ + {0x92, 0x4a, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6} } + // cd5cd8b0-3b80-11d2-bee0-00805f8a8dbd #define NS_XPFC_DIALOG_CID \ { 0xcd5cd8b0, 0x3b80, 0x11d2, \ diff --git a/xpfc/core/inc/nsxpfcFactory.h b/xpfc/core/inc/nsxpfcFactory.h index 498140da58c9..4695158c5a0f 100644 --- a/xpfc/core/inc/nsxpfcFactory.h +++ b/xpfc/core/inc/nsxpfcFactory.h @@ -40,6 +40,7 @@ #include "nsMenuManager.h" #include "nsToolbarManager.h" #include "nsStreamManager.h" +#include "nsStreamObject.h" #include "nsVector.h" #include "nsVectorIterator.h" #include "nsStack.h" @@ -63,6 +64,8 @@ static NS_DEFINE_IID(kCMenuContainer, NS_MENUCONTAINER_CID); static NS_DEFINE_IID(kCMenuManager, NS_MENU_MANAGER_CID); static NS_DEFINE_IID(kCStreamManager, NS_STREAM_MANAGER_CID); static NS_DEFINE_IID(kIStreamManager, NS_ISTREAM_MANAGER_IID); +static NS_DEFINE_IID(kCStreamObject, NS_STREAM_OBJECT_CID); +static NS_DEFINE_IID(kIStreamObject, NS_ISTREAM_OBJECT_IID); static NS_DEFINE_IID(kCXPFCDTD, NS_IXPFCXML_DTD_IID); static NS_DEFINE_IID(kCXPFCContentSink, NS_XPFCXMLCONTENTSINK_IID); static NS_DEFINE_IID(kCXPFCToolbar, NS_XPFC_TOOLBAR_CID); diff --git a/xpfc/core/src/nsxpfcFactory.cpp b/xpfc/core/src/nsxpfcFactory.cpp index 49013d49c129..1a26848e4db2 100644 --- a/xpfc/core/src/nsxpfcFactory.cpp +++ b/xpfc/core/src/nsxpfcFactory.cpp @@ -110,6 +110,8 @@ nsresult nsxpfcFactory::CreateInstance(nsISupports *aOuter, inst = (nsISupports *)(nsIToolbarManager *)new nsToolbarManager(); } else if (mClassID.Equals(kCStreamManager)) { inst = (nsISupports *)(nsIStreamManager *)new nsStreamManager(); + } else if (mClassID.Equals(kCStreamObject)) { + inst = (nsISupports *)(nsIStreamObject *)new nsStreamObject(); } else if (mClassID.Equals(kCMenuItem)) { inst = (nsISupports *)(nsIMenuItem *)new nsMenuItem(); } else if (mClassID.Equals(kCXPFCDTD)) { diff --git a/xpfc/shell/inc/manifest.mn b/xpfc/shell/inc/manifest.mn index d6f1b028e1e1..31a448384c01 100644 --- a/xpfc/shell/inc/manifest.mn +++ b/xpfc/shell/inc/manifest.mn @@ -13,6 +13,7 @@ EXPORTS = \ nsShellInstance.h \ nsApplicationManager.h \ nsStreamManager.h \ + nsStreamObject.h \ $(NULL) MODULE = xpfc diff --git a/xpfc/shell/inc/nsStreamManager.h b/xpfc/shell/inc/nsStreamManager.h index 3b356765901d..de57369c3d5b 100644 --- a/xpfc/shell/inc/nsStreamManager.h +++ b/xpfc/shell/inc/nsStreamManager.h @@ -18,6 +18,8 @@ #include "nscore.h" #include "nsIFactory.h" +#include "nsIVector.h" +#include "nsIIterator.h" #include "nsIStreamManager.h" class nsStreamManager : public nsIStreamManager @@ -44,7 +46,6 @@ public: NS_IMETHOD LoadURL(nsIWebViewerContainer * aWebViewerContainer, const nsString& aURLSpec, - nsIStreamListener* aListener, nsIPostData * aPostData, nsIID *aDTDIID = nsnull, nsIID *aSinkIID = nsnull); @@ -53,6 +54,7 @@ private: nsIURL * mUrl; nsIDTD * mDTD; nsIContentSink * mSink; + nsIVector * mStreamObjects; public: nsIParser * mParser; diff --git a/xpfc/shell/inc/nsStreamObject.h b/xpfc/shell/inc/nsStreamObject.h new file mode 100644 index 000000000000..6c2a17cd9358 --- /dev/null +++ b/xpfc/shell/inc/nsStreamObject.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nscore.h" +#include "nsIFactory.h" +#include "nsIStreamObject.h" +#include "nsIStreamListener.h" + +class nsStreamObject : public nsIStreamObject, + public nsIStreamListener +{ +public: + + /** + * Constructor and Destructor + */ + + nsStreamObject(); + ~nsStreamObject(); + + /** + * ISupports Interface + */ + NS_DECL_ISUPPORTS + + /** + * Initialize Method + * @result The result of the initialization, NS_OK if no errors + */ + NS_IMETHOD Init(); + + NS_IMETHOD OnStartBinding(nsIURL * aURL, const char *aContentType); + NS_IMETHOD OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax); + NS_IMETHOD OnStatus(nsIURL* aURL, const nsString &aMsg) ; + NS_IMETHOD OnStopBinding(nsIURL * aURL, + PRInt32 aStatus, + const nsString &aMsg); + + NS_IMETHOD GetBindInfo(nsIURL * aURL); + NS_IMETHOD OnDataAvailable(nsIURL * aURL, + nsIInputStream *aIStream, + PRInt32 aLength); + +public: + nsIParser * mParser; + nsIURL * mUrl; + nsIDTD * mDTD; + nsIContentSink * mSink; + nsIStreamListener * mStreamListener; +}; + + diff --git a/xpfc/shell/public/manifest.mn b/xpfc/shell/public/manifest.mn index 038abf40d755..c6aeb0c00f83 100644 --- a/xpfc/shell/public/manifest.mn +++ b/xpfc/shell/public/manifest.mn @@ -15,6 +15,7 @@ EXPORTS = \ nsIShellInstance.h \ nsIWebViewerContainer.h\ nsIStreamManager.h \ + nsIStreamObject.h \ $(NULL) PRIVATE_EXPORTS = \ diff --git a/xpfc/shell/public/nsIStreamManager.h b/xpfc/shell/public/nsIStreamManager.h index d81ab26e6378..0c1943495017 100644 --- a/xpfc/shell/public/nsIStreamManager.h +++ b/xpfc/shell/public/nsIStreamManager.h @@ -44,7 +44,6 @@ public: NS_IMETHOD LoadURL(nsIWebViewerContainer * aWebViewerContainer, const nsString& aURLSpec, - nsIStreamListener* aListener, nsIPostData * aPostData, nsIID *aDTDIID = nsnull, nsIID *aSinkIID = nsnull) = 0; diff --git a/xpfc/shell/public/nsIStreamObject.h b/xpfc/shell/public/nsIStreamObject.h new file mode 100644 index 000000000000..2c26b6b383e8 --- /dev/null +++ b/xpfc/shell/public/nsIStreamObject.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsIStreamObject_h___ +#define nsIStreamObject_h___ + +#include "nscore.h" +#include "nsxpfc.h" +#include "nsISupports.h" +#include "nsIWebViewerContainer.h" +#include "nsIURL.h" +#include "nsIStreamListener.h" + +// 38acdab0-4914-11d2-924a-00805f8a7ab6 +#define NS_ISTREAM_OBJECT_IID \ + { 0x38acdab0, 0x4914, 0x11d2, \ + {0x92, 0x4a, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6} } + +// Application Shell Interface +class nsIStreamObject : public nsISupports +{ +public: + + /** + * Initialize the StreamObject + * @result The result of the initialization, NS_OK if no errors + */ + NS_IMETHOD Init() = 0; + +}; + +#endif /* nsIStreamObject_h___ */ diff --git a/xpfc/shell/src/manifest.mn b/xpfc/shell/src/manifest.mn index 21edb424843e..c51376a42729 100644 --- a/xpfc/shell/src/manifest.mn +++ b/xpfc/shell/src/manifest.mn @@ -23,6 +23,7 @@ CPPSRCS = \ nsApplicationManager.cpp \ nsShellInstance.cpp \ nsStreamManager.cpp \ + nsStreamObject.cpp \ $(NULL) REQUIRES = xpcom raptor pref js netlib diff --git a/xpfc/shell/src/nsStreamManager.cpp b/xpfc/shell/src/nsStreamManager.cpp index 3abe3fd0a4ca..3fdf56692550 100644 --- a/xpfc/shell/src/nsStreamManager.cpp +++ b/xpfc/shell/src/nsStreamManager.cpp @@ -27,11 +27,20 @@ #include "nspr.h" #include "nsParserCIID.h" #include "nsXPFCXMLContentSink.h" +#include "nsStreamObject.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); static NS_DEFINE_IID(kCStreamManager, NS_STREAM_MANAGER_CID); +static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); +static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID); +static NS_DEFINE_IID(kCCalXPFCXMLDTD, NS_IXPFCXML_DTD_IID); +static NS_DEFINE_IID(kCCalXPFCXMLContentSinkCID, NS_XPFCXMLCONTENTSINK_IID); + +static NS_DEFINE_IID(kIStreamObjectIID, NS_ISTREAM_OBJECT_IID); +static NS_DEFINE_IID(kCStreamObjectCID, NS_STREAM_OBJECT_CID); + nsStreamManager::nsStreamManager() { NS_INIT_REFCNT(); @@ -46,6 +55,12 @@ nsStreamManager::~nsStreamManager() NS_IF_RELEASE(mUrl); NS_IF_RELEASE(mParser); NS_IF_RELEASE(mSink); + + if (mStreamObjects != nsnull) { + mStreamObjects->RemoveAll(); + NS_RELEASE(mStreamObjects); + } + } NS_DEFINE_IID(kIStreamManagerIID, NS_ISTREAM_MANAGER_IID); @@ -53,28 +68,27 @@ NS_IMPL_ISUPPORTS(nsStreamManager,kIStreamManagerIID); nsresult nsStreamManager::Init() { + static NS_DEFINE_IID(kCVectorCID, NS_VECTOR_CID); + + nsresult res = nsRepository::CreateInstance(kCVectorCID, + nsnull, + kCVectorCID, + (void **)&mStreamObjects); + + if (NS_OK != res) + return res; + + mStreamObjects->Init(); + return NS_OK; } nsresult nsStreamManager::LoadURL(nsIWebViewerContainer * aWebViewerContainer, const nsString& aURLSpec, - nsIStreamListener* aListener, nsIPostData * aPostData, nsIID *aDTDIID, nsIID *aSinkIID) { -/* - * If we can find the file, then use it, else use the HARDCODE. - * We'll need to change the way we deal with this since the file - * could be gotten over the network. - */ - - static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); - static NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID); - - static NS_DEFINE_IID(kCCalXPFCXMLDTD, NS_IXPFCXML_DTD_IID); - static NS_DEFINE_IID(kCCalXPFCXMLContentSinkCID, NS_XPFCXMLCONTENTSINK_IID); - nsIID * iid_dtd = aDTDIID; nsIID * iid_sink = aSinkIID; @@ -83,22 +97,40 @@ nsresult nsStreamManager::LoadURL(nsIWebViewerContainer * aWebViewerContainer, if (iid_sink == nsnull) iid_sink = (nsIID*)&kCCalXPFCXMLContentSinkCID; - nsresult rv = NS_OK; - char * pUI = aURLSpec.ToNewCString(); + nsStreamObject * stream_object = nsnull; + nsresult res = NS_OK; + + res = nsRepository::CreateInstance(kCStreamObjectCID, + nsnull, + kIStreamObjectIID, + (void**) &stream_object); + + if (NS_OK != res) { + return res; + } + + stream_object->Init(); + + mStreamObjects->Append(stream_object); + /* * Create a nsIURL representing the interface ... */ - nsresult res = NS_OK; nsUrlParser urlParser(pUI); + + /* + * Create a StreamObject + */ + if (urlParser.IsLocalFile() == PR_TRUE) { char * pURL = urlParser.LocalFileToURL(); - res = NS_NewURL(&mUrl, pURL); + res = NS_NewURL(&(stream_object->mUrl), pURL); } else { - res = NS_NewURL(&mUrl, pUI); + res = NS_NewURL(&(stream_object->mUrl), pUI); } @@ -122,16 +154,18 @@ nsresult nsStreamManager::LoadURL(nsIWebViewerContainer * aWebViewerContainer, static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); - rv = nsRepository::CreateInstance(kCParserCID, + res = nsRepository::CreateInstance(kCParserCID, nsnull, kCParserIID, - (void **)&mParser); + (void **)&(stream_object->mParser)); if (NS_OK != res) { return res; } + res = stream_object->mParser->QueryInterface(kIStreamListenerIID, (void **)&(stream_object->mStreamListener)); + /* * Create the DTD and Sink */ @@ -139,7 +173,7 @@ nsresult nsStreamManager::LoadURL(nsIWebViewerContainer * aWebViewerContainer, res = nsRepository::CreateInstance(*iid_dtd, nsnull, kIDTDIID, - (void**) &mDTD); + (void**) &(stream_object->mDTD)); if (NS_OK != res) { return res; @@ -149,7 +183,7 @@ nsresult nsStreamManager::LoadURL(nsIWebViewerContainer * aWebViewerContainer, res = nsRepository::CreateInstance(*iid_sink, nsnull, kIContentSinkIID, - (void**) &mSink); + (void**) &(stream_object->mSink)); if (NS_OK != res) { return res; @@ -159,7 +193,7 @@ nsresult nsStreamManager::LoadURL(nsIWebViewerContainer * aWebViewerContainer, static NS_DEFINE_IID(kIXPFCXMLContentSinkIID, NS_IXPFC_XML_CONTENT_SINK_IID); - res = mSink->QueryInterface(kIXPFCXMLContentSinkIID,(void**)&sink); + res = stream_object->mSink->QueryInterface(kIXPFCXMLContentSinkIID,(void**)&sink); if (NS_OK == res) { @@ -171,35 +205,35 @@ nsresult nsStreamManager::LoadURL(nsIWebViewerContainer * aWebViewerContainer, * Register the DTD */ - mParser->RegisterDTD(mDTD); + stream_object->mParser->RegisterDTD(stream_object->mDTD); /* * Register the Context Sink, Parser, etc... */ - mParser->SetContentSink(mSink); + stream_object->mParser->SetContentSink(stream_object->mSink); - mDTD->SetContentSink(mSink); - mDTD->SetParser(mParser); + stream_object->mDTD->SetContentSink(stream_object->mSink); + stream_object->mDTD->SetParser(stream_object->mParser); /* * Open the URL */ - res = mUrl->Open(aListener); + res = stream_object->mUrl->Open(stream_object->mStreamListener); /* * We want to parse when the Stream has data? */ - mParser->Parse(mUrl); + stream_object->mParser->Parse(stream_object->mUrl); delete pUI; - return rv; + return res; } \ No newline at end of file diff --git a/xpfc/shell/src/nsStreamObject.cpp b/xpfc/shell/src/nsStreamObject.cpp new file mode 100644 index 000000000000..35a5bc9cf1ef --- /dev/null +++ b/xpfc/shell/src/nsStreamObject.cpp @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include +#include "nscore.h" + +#include "nsISupports.h" +#include "nsStreamObject.h" +#include "nsxpfcCIID.h" +#include "nsIContentSink.h" +#include "nsUrlParser.h" +#include "nspr.h" +#include "nsParserCIID.h" +#include "nsXPFCXMLContentSink.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kCStreamObject, NS_STREAM_OBJECT_CID); + +nsStreamObject::nsStreamObject() +{ + NS_INIT_REFCNT(); + mUrl = nsnull; + mParser = nsnull; + mDTD = nsnull; + mSink = nsnull; + mStreamListener = nsnull; +} + +nsStreamObject::~nsStreamObject() +{ + NS_IF_RELEASE(mUrl); + NS_IF_RELEASE(mParser); + NS_IF_RELEASE(mSink); + NS_IF_RELEASE(mDTD); + NS_IF_RELEASE(mStreamListener); +} + +NS_DEFINE_IID(kIStreamObjectIID, NS_ISTREAM_OBJECT_IID); + +NS_IMPL_ADDREF(nsStreamObject) +NS_IMPL_RELEASE(nsStreamObject) + +nsresult nsStreamObject::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + if(aIID.Equals(kISupportsIID)) { //do IUnknown... + *aInstancePtr = (nsISupports*)(nsIStreamObject*)(this); + } + else if(aIID.Equals(kIStreamObjectIID)) { //do this class... + *aInstancePtr = (nsStreamObject*)(this); + } + else if(aIID.Equals(kIStreamListenerIID)) { //do this class... + *aInstancePtr = (nsIStreamListener*)(this); + } + else { + *aInstancePtr=0; + return NS_NOINTERFACE; + } + ((nsISupports*) *aInstancePtr)->AddRef(); + return NS_OK; +} + +nsresult nsStreamObject::Init() +{ + if (mParser != nsnull) + { + nsresult res = mParser->QueryInterface(kIStreamListenerIID, (void **)&mStreamListener); + + if (NS_OK != res) + mStreamListener = nsnull; + } + return NS_OK; +} + + +nsresult nsStreamObject::GetBindInfo(nsIURL * aURL) +{ + return NS_OK; +} + +nsresult nsStreamObject::OnDataAvailable(nsIURL * aURL, + nsIInputStream *aIStream, + PRInt32 aLength) +{ + return (mStreamListener->OnDataAvailable(aURL, aIStream, aLength)); +} + +nsresult nsStreamObject::OnStartBinding(nsIURL * aURL, + const char *aContentType) +{ + return (mStreamListener->OnStartBinding(aURL,aContentType)); +} + +nsresult nsStreamObject::OnStopBinding(nsIURL * aURL, PRInt32 aStatus, const nsString &aMsg) +{ + return (mStreamListener->OnStopBinding(aURL, aStatus, aMsg)); +} + +nsresult nsStreamObject::OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax) +{ + return NS_OK; +} + +nsresult nsStreamObject::OnStatus(nsIURL* aURL, const nsString &aMsg) +{ + return NS_OK; +} + + diff --git a/xpfc/shell/src/unix/main.cpp b/xpfc/shell/src/unix/main.cpp index 86605abde0b5..616f8f000dfa 100644 --- a/xpfc/shell/src/unix/main.cpp +++ b/xpfc/shell/src/unix/main.cpp @@ -54,6 +54,7 @@ static NS_DEFINE_IID(kCVectorCID, NS_VECTOR_CID); static NS_DEFINE_IID(kCVectorIteratorCID, NS_VECTOR_ITERATOR_CID); static NS_DEFINE_IID(kCstackCID, NS_STACK_CID); static NS_DEFINE_IID(kCStreamManagerCID, NS_STREAM_MANAGER_CID); +static NS_DEFINE_IID(kCStreamObjectCID, NS_STREAM_OBJECT_CID); XtAppContext app_context ; Widget topLevel; @@ -88,6 +89,7 @@ void main(int argc, char **argv) nsRepository::RegisterFactory(kCXPFCTabWidgetCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCToolbarManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCStreamManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCStreamObjectCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCVectorCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCVectorIteratorCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCstackCID, XPFC_DLL, PR_FALSE, PR_FALSE); diff --git a/xpfc/shell/src/windows/winmain.cpp b/xpfc/shell/src/windows/winmain.cpp index d40f1aafa80e..5f3885a71c20 100644 --- a/xpfc/shell/src/windows/winmain.cpp +++ b/xpfc/shell/src/windows/winmain.cpp @@ -52,6 +52,7 @@ static NS_DEFINE_IID(kCXPFCTabWidgetCID, NS_XPFC_TABWIDGET_CID); static NS_DEFINE_IID(kCToolbarManagerCID, NS_TOOLBAR_MANAGER_CID); static NS_DEFINE_IID(kCStreamManagerCID, NS_STREAM_MANAGER_CID); +static NS_DEFINE_IID(kCStreamObjectCID, NS_STREAM_OBJECT_CID); static NS_DEFINE_IID(kCVectorCID, NS_VECTOR_CID); static NS_DEFINE_IID(kCVectorIteratorCID, NS_VECTOR_ITERATOR_CID); static NS_DEFINE_IID(kCstackCID, NS_STACK_CID); @@ -79,6 +80,7 @@ int PASCAL WinMain(HANDLE instance, HANDLE prevInstance, LPSTR cmdParam, int nCm nsRepository::RegisterFactory(kCXPFCTabWidgetCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCToolbarManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCStreamManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCStreamObjectCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCVectorCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCVectorIteratorCID, XPFC_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCstackCID, XPFC_DLL, PR_FALSE, PR_FALSE);