diff --git a/mozilla/xpfe/components/sample/public/nsISampleAppShellComponent.idl b/mozilla/xpfe/components/sample/public/nsISampleAppShellComponent.idl index 69fee90fd10..1ad747e5008 100644 --- a/mozilla/xpfe/components/sample/public/nsISampleAppShellComponent.idl +++ b/mozilla/xpfe/components/sample/public/nsISampleAppShellComponent.idl @@ -18,6 +18,8 @@ #include "nsIAppShellComponent.idl" +interface nsIObserver; + /*------------------------ nsISampleAppShellComponent -------------------------- | This file describes the interface for a sample "application shell | | component." | @@ -39,12 +41,12 @@ interface nsISampleAppShellComponent : nsIAppShellComponent { | o Modal dialog from C++ | | o Modal dialog from JavaScript | --------------------------------------------------------------------------*/ - void DoDialogTests(); + void DoDialogTests( in nsISupports parent, in nsIObserver observer ); }; %{C++ #define NS_ISAMPLEAPPSHELLCOMPONENT_PROGID NS_IAPPSHELLCOMPONENT_PROGID "/sample" #define NS_ISAMPLEAPPSHELLCOMPONENT_CLASSNAME "Mozilla Sample App Shell Component" #define NS_DECL_ISAMPLEAPPSHELLCOMPONENT \ - NS_IMETHOD DoDialogTests(); + NS_IMETHOD DoDialogTests( nsISupports *, nsIObserver * ); %} diff --git a/mozilla/xpfe/components/sample/resources/nsSampleAppShellComponent.xul b/mozilla/xpfe/components/sample/resources/nsSampleAppShellComponent.xul index 35316b08bd8..665d9e87100 100644 --- a/mozilla/xpfe/components/sample/resources/nsSampleAppShellComponent.xul +++ b/mozilla/xpfe/components/sample/resources/nsSampleAppShellComponent.xul @@ -22,23 +22,6 @@ --> - - @@ -63,7 +46,6 @@ data = new Object; data.input = document.getElementById( "data.input" ); data.output = document.getElementById( "data.output" ); - data.execute = document.getElementById( "data.execute" ); } /* @@ -89,6 +71,10 @@ the dialog, then loads the initial dialog contents. */ function onLoad() { + + + window.arguments[0].Observe( window, "sample", "onLoad called" ); + // Init data. initData(); diff --git a/mozilla/xpfe/components/sample/src/makefile.win b/mozilla/xpfe/components/sample/src/makefile.win index 4078d9f3677..781251e86da 100644 --- a/mozilla/xpfe/components/sample/src/makefile.win +++ b/mozilla/xpfe/components/sample/src/makefile.win @@ -48,6 +48,7 @@ LLIBS = \ $(LIBNSPR) \ $(DIST)\lib\xpcom.lib \ $(DIST)\lib\netlib.lib \ + $(DIST)\lib\js3250.lib \ $(NULL) #//------------------------------------------------------------------------ diff --git a/mozilla/xpfe/components/sample/src/nsSampleAppShellComponent.cpp b/mozilla/xpfe/components/sample/src/nsSampleAppShellComponent.cpp index 949267544f8..97dd0db5530 100644 --- a/mozilla/xpfe/components/sample/src/nsSampleAppShellComponent.cpp +++ b/mozilla/xpfe/components/sample/src/nsSampleAppShellComponent.cpp @@ -19,6 +19,11 @@ #include "nsIAppShellComponentImpl.h" +#include "nsIDOMWindow.h" +#include "nsIScriptGlobalObject.h" +#include "nsIXPConnect.h" +#include "nsIObserver.h" + #if 0 #include "nsCOMPtr.h" #include "pratom.h" @@ -79,9 +84,75 @@ private: NS_IMETHODIMP -nsSampleAppShellComponent::DoDialogTests() { +nsSampleAppShellComponent::DoDialogTests( nsISupports *parent, nsIObserver *observer ) { nsresult rv = NS_OK; DEBUG_PRINTF( PR_STDOUT, "nsSampleAppShellComponent::DoDialogTests called\n" ); + + if ( parent && observer ) { + // Open the dialog from C++. + nsCOMPtr parentWindow = do_QueryInterface( parent, &rv ); + + if ( NS_SUCCEEDED( rv ) ) { + // Get JS context from parent window. + nsCOMPtr sgo = do_QueryInterface( parentWindow, &rv ); + if ( NS_SUCCEEDED( rv ) ) { + nsCOMPtr context; + sgo->GetContext( getter_AddRefs( context ) ); + if ( context ) { + JSContext *jsContext = (JSContext*)context->GetNativeContext(); + if ( jsContext ) { + // Convert observer to jsval so we can pass it as argument. + static NS_DEFINE_CID( kXPConnectCID, NS_XPCONNECT_CID ); + NS_WITH_SERVICE( nsIXPConnect, xpc, kXPConnectCID, &rv ); + + if ( NS_SUCCEEDED( rv ) ) { + nsCOMPtr wrapper; + rv = xpc->WrapNative( jsContext, + observer, + nsIObserver::GetIID(), + getter_AddRefs( wrapper ) ); + if ( NS_SUCCEEDED( rv ) ) { + JSObject* obj; + rv = wrapper->GetJSObject( &obj ); + if ( NS_SUCCEEDED( rv ) ) { + // Get a jsval corresponding to the wrapped object. + jsval arg = OBJECT_TO_JSVAL( obj ); + void *stackPtr; + jsval *argv = JS_PushArguments( jsContext, &stackPtr, "ssso", + "resource:/res/samples/nsSampleAppShellComponent.xul", + "", + "chrome", + arg ); + if ( argv ) { + nsIDOMWindow *newWindow; + rv = parentWindow->OpenDialog( jsContext, argv, 4, &newWindow ); + if ( NS_SUCCEEDED( rv ) ) { + } else { + } + JS_PopArguments( jsContext, stackPtr ); + } else { + } + } + } + //? NS_RELEASE(aSupports); + } else { + } + } else { + } + } else { + } + } else { + } + } else { + DEBUG_PRINTF( PR_STDOUT, "%s %d: QueryInterface failed, rv=0x%08X\n", + __FILE__, (int)__LINE__, (int)rv ); + } + } else { + DEBUG_PRINTF( PR_STDOUT, "%s %d: DoDialogTests was passed a null pointer!\n", + __FILE__, (int)__LINE__ ); + rv = NS_ERROR_NULL_POINTER; + } + return rv; }