diff --git a/xpfe/AppCores/src/makefile.win b/xpfe/AppCores/src/makefile.win index 1908c9ed01bb..5e7e26b5d7f4 100644 --- a/xpfe/AppCores/src/makefile.win +++ b/xpfe/AppCores/src/makefile.win @@ -84,10 +84,10 @@ install:: $(DLL) $(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin $(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib $(MAKE_INSTALL) $(DLL) $(DIST)\bin - $(MAKE_INSTALL) ..\xul\MailAppShell.html $(DIST)\bin\res\samples - $(MAKE_INSTALL) ..\xul\MailAppShellNoTB.html $(DIST)\bin\res\samples - $(MAKE_INSTALL) ..\xul\MailFrame.html $(DIST)\bin\res\samples - $(MAKE_INSTALL) ..\xul\MailToolbar.xml $(DIST)\bin\res\samples +# $(MAKE_INSTALL) ..\xul\MailAppShell.html $(DIST)\bin\res\samples +# $(MAKE_INSTALL) ..\xul\MailAppShellNoTB.html $(DIST)\bin\res\samples +# $(MAKE_INSTALL) ..\xul\MailFrame.html $(DIST)\bin\res\samples +# $(MAKE_INSTALL) ..\xul\MailToolbar.xml $(DIST)\bin\res\samples $(MAKE_INSTALL) ..\xul\resources\Mail_SendMsg.gif $(DIST)\bin\res\toolbar $(MAKE_INSTALL) ..\xul\resources\Mail_GetMsg.gif $(DIST)\bin\res\toolbar diff --git a/xpfe/AppCores/src/nsJSToolbarCore.cpp b/xpfe/AppCores/src/nsJSToolbarCore.cpp index a74058212d33..1a0c74de1f5e 100644 --- a/xpfe/AppCores/src/nsJSToolbarCore.cpp +++ b/xpfe/AppCores/src/nsJSToolbarCore.cpp @@ -172,6 +172,48 @@ ToolbarCoreSetWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva } +// +// Native method SetWebShellWindow +// +PR_STATIC_CALLBACK(JSBool) +ToolbarCoreSetWebShellWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMToolbarCore *nativeThis = (nsIDOMToolbarCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMWindowPtr b0; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 1) { + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kIWindowIID, + "Window", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->SetWebShellWindow(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function SetWebShellWindow requires 1 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + // // Native method SetStatus // @@ -241,6 +283,7 @@ static JSPropertySpec ToolbarCoreProperties[] = static JSFunctionSpec ToolbarCoreMethods[] = { {"SetWindow", ToolbarCoreSetWindow, 1}, + {"SetWebShellWindow", ToolbarCoreSetWebShellWindow, 1}, {"SetStatus", ToolbarCoreSetStatus, 1}, {0} }; diff --git a/xpfe/AppCores/src/nsMailCore.cpp b/xpfe/AppCores/src/nsMailCore.cpp index de9e400451c7..91803d53b0a6 100644 --- a/xpfe/AppCores/src/nsMailCore.cpp +++ b/xpfe/AppCores/src/nsMailCore.cpp @@ -157,7 +157,6 @@ nsMailCore::SendMail(const nsString& aAddrTo, const nsString& aSubject, const ns PRBool isUndefined = PR_FALSE; nsString rVal; mScriptContext->EvaluateString(mScript, url, 0, rVal, &isUndefined); - //printf("SendMail [%s] %d [%s]\n", mScript.ToNewCString(), isUndefined, rVal.ToNewCString()); } return NS_OK; } diff --git a/xpfe/AppCores/src/nsToolbarCore.cpp b/xpfe/AppCores/src/nsToolbarCore.cpp index 97b4b2931398..14baf33379f1 100644 --- a/xpfe/AppCores/src/nsToolbarCore.cpp +++ b/xpfe/AppCores/src/nsToolbarCore.cpp @@ -24,6 +24,8 @@ #include "nsAppCores.h" #include "nsAppCoresCIDs.h" #include "nsAppCoresManager.h" +#include "nsCOMPtr.h" +#include "nsIWebShell.h" #include "nsIScriptContext.h" #include "nsIDOMDocument.h" @@ -32,6 +34,9 @@ #include "nsIDOMNode.h" #include "nsIDOMElement.h" #include "nsIDOMCharacterData.h" +#include "nsIScriptGlobalObject.h" +#include "nsIWebShell.h" +#include "nsIWebShellWindow.h" // Globals @@ -44,6 +49,11 @@ static NS_DEFINE_IID(kIDOMCharacterDataIID, nsIDOMCharacterData::IID()); static NS_DEFINE_IID(kToolbarCoreCID, NS_TOOLBARCORE_CID); +static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID); +static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID); + +static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID); + ///////////////////////////////////////////////////////////////////////// // nsToolbarCore @@ -55,6 +65,7 @@ nsToolbarCore::nsToolbarCore() mWindow = nsnull; mStatusText = nsnull; + mWebShellWin = nsnull; IncInstanceCount(); NS_INIT_REFCNT(); @@ -63,6 +74,7 @@ nsToolbarCore::nsToolbarCore() nsToolbarCore::~nsToolbarCore() { NS_IF_RELEASE(mWindow); + NS_IF_RELEASE(mWebShellWin); NS_IF_RELEASE(mStatusText); DecInstanceCount(); } @@ -87,6 +99,16 @@ nsToolbarCore::QueryInterface(REFNSIID aIID,void** aInstancePtr) AddRef(); return NS_OK; } + if (aIID.Equals(kINetSupportIID)) { + *aInstancePtr = (void*) ((nsINetSupport*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIStreamObserverIID)) { + *aInstancePtr = (void*) ((nsIStreamObserver*)this); + NS_ADDREF_THIS(); + return NS_OK; + } return nsBaseAppCore::QueryInterface(aIID, aInstancePtr); } @@ -130,7 +152,7 @@ nsToolbarCore::Init(const nsString& aId) NS_IMETHODIMP nsToolbarCore::SetStatus(const nsString& aMsg) { - if (nsnull == mStatusText) { +/* if (nsnull == mStatusText) { nsIDOMDocument * domDoc; mWindow->GetDocument(&domDoc); if (!domDoc) @@ -154,20 +176,289 @@ nsToolbarCore::SetStatus(const nsString& aMsg) NS_RELEASE(domDoc); } - mStatusText->SetData(aMsg); + mStatusText->SetData(aMsg); */ + DoDialog(); return NS_OK; } +NS_IMETHODIMP +nsToolbarCore::SetWebShellWindow(nsIDOMWindow* aWin) +{ + mWindow = aWin; + NS_ADDREF(aWin); + + nsCOMPtr globalObj( mWindow ); + if (!globalObj) { + return NS_ERROR_FAILURE; + } + + nsIWebShell * webShell; + globalObj->GetWebShell(&webShell); + if (nsnull != webShell) { + webShell->SetObserver(this); + PRUnichar * name; + webShell->GetName( &name); + nsAutoString str(name); + + printf("attaching to [%s]\n", str.ToNewCString()); + + nsIWebShellContainer * webShellContainer; + webShell->GetContainer(webShellContainer); + if (nsnull != webShellContainer) { + if (NS_OK == webShellContainer->QueryInterface(kIWebShellWindowIID, (void**) &mWebShellWin)) { + } + NS_RELEASE(webShellContainer); + } + NS_RELEASE(webShell); + } + return NS_OK; +} + NS_IMETHODIMP nsToolbarCore::SetWindow(nsIDOMWindow* aWin) { mWindow = aWin; NS_ADDREF(aWin); + + + nsCOMPtr globalObj( mWindow ); + if (!globalObj) { + return NS_ERROR_FAILURE; + } + + nsIWebShell * webShell; + globalObj->GetWebShell(&webShell); + if (nsnull != webShell) { + webShell->SetObserver(this); + PRUnichar * name; + webShell->GetName( &name); + nsAutoString str(name); + + printf("attaching to [%s]\n", str.ToNewCString()); + NS_RELEASE(webShell); + } + + +/* nsCOMPtr oldNode( node ); + oldNode->GetNextSibling(getter_AddRefs(node)); + nsCOMPtr domDoc; // result == nsnull; + + // first get the toolbar child WebShell + nsCOMPtr childWebShell; + mWebShell->FindChildWithName(aWebShellName, *getter_AddRefs(childWebShell)); + if (!childWebShell) + return domDoc; + + nsCOMPtr cv; + childWebShell->GetContentViewer(getter_AddRefs(cv)); + if (!cv) + return domDoc; + + nsCOMPtr docv(cv); + if (!docv) + return domDoc; + + nsCOMPtr doc; + docv->GetDocument(*getter_AddRefs(doc)); + if (doc) + return nsCOMPtr(doc); + + return domDoc;*/ return NS_OK; } +#include "nsIServiceManager.h" +#include "nsIURL.h" +#include "nsIWidget.h" +#include "plevent.h" + +#include "nsIAppShell.h" +#include "nsIAppShellService.h" +#include "nsAppShellCIDs.h" + +/* Define Class IDs */ +static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); + +/* Define Interface IDs */ +static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID); + +NS_IMETHODIMP +nsToolbarCore::DoDialog() +{ + nsresult rv; + nsString controllerCID; + + char * urlstr=nsnull; + char * progname = nsnull; + char * width=nsnull, *height=nsnull; + char * iconic_state=nsnull; + + nsIAppShellService* appShell = nsnull; + + urlstr = "resource:/res/samples/Password.html"; + /* + * Create the Application Shell instance... + */ + rv = nsServiceManager::GetService(kAppShellServiceCID, + kIAppShellServiceIID, + (nsISupports**)&appShell); + if (!NS_SUCCEEDED(rv)) { + goto done; + } + + /* + * Initialize the Shell... + */ + rv = appShell->Initialize(); + if (!NS_SUCCEEDED(rv)) { + goto done; + } + + /* + * Post an event to the shell instance to load the AppShell + * initialization routines... + * + * This allows the application to enter its event loop before having to + * deal with GUI initialization... + */ + ///write me... + nsIURL* url; + nsIWidget* newWindow; + + rv = NS_NewURL(&url, urlstr); + if (NS_FAILED(rv)) { + goto done; + } + + nsIWidget * parent; + mWebShellWin->GetWidget(parent); + + /* + * XXX: Currently, the CID for the "controller" is passed in as an argument + * to CreateTopLevelWindow(...). Once XUL supports "controller" + * components this will be specified in the XUL description... + */ + controllerCID = "43147b80-8a39-11d2-9938-0080c7cb1081"; + appShell->CreateDialogWindow(parent, url, controllerCID, newWindow, (nsIStreamObserver *)this); + + NS_RELEASE(url); + NS_RELEASE(parent); + + /* + * Start up the main event loop... + */ + //rv = appShell->Run(); + rv = NS_OK; + while (rv == NS_OK) { + void * data; + PRBool inWin; + PRBool isMouseEvent; + rv = appShell->GetNativeEvent(data, newWindow, inWin, isMouseEvent); + if (rv == NS_OK) { + printf("In win %d is mouse %d\n", inWin, isMouseEvent); + } else { + rv = NS_OK; + } + if (rv == NS_OK && (inWin || (!inWin && !isMouseEvent))) { + appShell->DispatchNativeEvent(data); + } + } + + /* + * Shut down the Shell instance... This is done even if the Run(...) + * method returned an error. + */ + (void) appShell->Shutdown(); + +done: + + /* Release the shell... */ + if (nsnull != appShell) { + nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); + } + return NS_OK; +} +NS_IMETHODIMP +nsToolbarCore::OnStartBinding(nsIURL* aURL, const char *aContentType) +{ + nsresult rv = NS_OK; +printf("OnStartBinding\n"); + return rv; +} +NS_IMETHODIMP +nsToolbarCore::OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax) +{ + nsresult rv = NS_OK; +printf("OnStartBinding\n"); + return rv; +} + + +NS_IMETHODIMP +nsToolbarCore::OnStatus(nsIURL* aURL, const PRUnichar* aMsg) +{ + nsresult rv = NS_OK; +printf("OnStartBinding\n"); + return rv; +} + + +NS_IMETHODIMP +nsToolbarCore::OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg) +{ + nsresult rv = NS_OK; +printf("OnStartBinding\n"); + return rv; +} + +//---------------------------------------------------------------------- + +NS_IMETHODIMP_(void) +nsToolbarCore::Alert(const nsString &aText) +{ +printf("Alert\n"); +} + +NS_IMETHODIMP_(PRBool) +nsToolbarCore::Confirm(const nsString &aText) +{ + PRBool bResult = PR_FALSE; +printf("Confirm\n"); + return bResult; +} + +NS_IMETHODIMP_(PRBool) +nsToolbarCore::Prompt(const nsString &aText, + const nsString &aDefault, + nsString &aResult) +{ + PRBool bResult = PR_FALSE; +printf("Prompt\n"); + return bResult; +} + +NS_IMETHODIMP_(PRBool) +nsToolbarCore::PromptUserAndPassword(const nsString &aText, + nsString &aUser, + nsString &aPassword) +{ + PRBool bResult = PR_FALSE; +printf("PromptUserAndPassword\n"); +DoDialog(); + return bResult; +} + +NS_IMETHODIMP_(PRBool) +nsToolbarCore::PromptPassword(const nsString &aText, + nsString &aPassword) +{ + PRBool bResult = PR_FALSE; +printf("PromptPassword\n"); + return bResult; +} + diff --git a/xpfe/AppCores/src/nsToolbarCore.h b/xpfe/AppCores/src/nsToolbarCore.h index dc5ed04511b6..6c9f78f866fd 100644 --- a/xpfe/AppCores/src/nsToolbarCore.h +++ b/xpfe/AppCores/src/nsToolbarCore.h @@ -27,6 +27,8 @@ #include "nsIDOMToolbarCore.h" #include "nsBaseAppCore.h" +#include "nsINetSupport.h" +#include "nsIStreamObserver.h" class nsIBrowserWindow; class nsIWebShell; @@ -34,13 +36,16 @@ class nsIScriptContext; class nsIDOMWindow; class nsIDOMDocument; class nsIDOMCharacterData; +class nsIWebShellWindow; //////////////////////////////////////////////////////////////////////////////// // nsToolbarCore: //////////////////////////////////////////////////////////////////////////////// class nsToolbarCore : public nsBaseAppCore, - public nsIDOMToolbarCore + public nsIDOMToolbarCore, + public nsINetSupport, + public nsIStreamObserver { public: @@ -54,11 +59,36 @@ class nsToolbarCore : public nsBaseAppCore, NS_IMETHOD GetId(nsString& aId) { return nsBaseAppCore::GetId(aId); } NS_IMETHOD SetWindow(nsIDOMWindow* aWin); + NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin); NS_IMETHOD SetStatus(const nsString& aMsg); + // nsIStreamObserver + NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType); + NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax); + NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg); + NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg); + + // nsINetSupport + NS_IMETHOD_(void) Alert(const nsString &aText); + + NS_IMETHOD_(PRBool) Confirm(const nsString &aText); + + NS_IMETHOD_(PRBool) Prompt(const nsString &aText, + const nsString &aDefault, + nsString &aResult); + + NS_IMETHOD_(PRBool) PromptUserAndPassword(const nsString &aText, + nsString &aUser, + nsString &aPassword); + + NS_IMETHOD_(PRBool) PromptPassword(const nsString &aText, + nsString &aPassword); + private: + NS_IMETHOD DoDialog(); nsIDOMWindow *mWindow; + nsIWebShellWindow *mWebShellWin; nsIDOMCharacterData *mStatusText; };