DEBUG_PRINTF( PR_STDOUT, "nsSampleAppShellComponent::DoDialogTests called\n" );
PRINTF(("nsSampleAppShellComponent::DoDialogTests called\n" ));
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<nsIDOMWindowInternal> parentWindow = do_QueryInterface( parent, &rv );    if ( NS_SUCCEEDED( rv ) ) {        // Get JS context from parent window.        nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface( parentWindow, &rv );        if ( NS_SUCCEEDED( rv ) ) {            nsCOMPtr<nsIScriptContext> context;            sgo->GetContext( getter_AddRefs( context ) );            if ( context ) {                JSContext *jsContext = (JSContext*)context->GetNativeContext();                if ( jsContext ) {                    // XXX Since xpconnect now has a JS argument converter for                    // interfaces this explicit wrapping could be avoided.                    //                    // 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<nsIXPConnectJSObjectHolder> wrapper;                        rv = xpc->WrapNative( jsContext,                                              JS_GetGlobalObject(jsContext),                                              observer,                                              NS_GET_IID(nsIObserver),                                              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, "sssv",                                                            "resource:/res/samples/nsSampleAppShellComponent.xul",                                                            "foobar",                                                            "chrome",                                                            arg );                            if ( argv ) {                                nsIDOMWindowInternal *newWindow;                                rv = parentWindow->OpenDialog( jsContext, argv, 4, &newWindow );                                if ( NS_SUCCEEDED( rv ) ) {                                    newWindow->Release();                                } 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;}