::util_ThrowExceptionToJava(initContext->env, "Exception: Can't get DocShell from nsIWebShell");
nsresult InitMozillaStuff (WebShellInitContext * initContext) {    nsIEventQueueService * aEventQService = nsnull;    nsresult rv = NS_ERROR_FAILURE;    PRBool allowPlugins = PR_FALSE;    //TODO Add tracing from nspr.    #if DEBUG_RAPTOR_CANVAS    printf("InitMozillaStuff(%lx): Create the Event Queue for the UI thread...\n", initContext);#endif        // Create the Event Queue for the UI thread...    rv = nsServiceManager::GetService(kEventQueueServiceCID,                                      kIEventQueueServiceIID,                                      (nsISupports **) &aEventQService);        if (NS_FAILED(rv)) {        initContext->initFailCode = kEventQueueError;        return rv;    }        // Create the event queue.    rv = aEventQService->CreateThreadEventQueue();    initContext->embeddedThread = PR_GetCurrentThread();    // Create the action queue    if (initContext->embeddedThread) {#if DEBUG_RAPTOR_CANVAS		printf("InitMozillaStuff(%lx): embeddedThread != nsnull\n", initContext);#endif		if (initContext->actionQueue == nsnull) {#if DEBUG_RAPTOR_CANVAS			printf("InitMozillaStuff(%lx): Create the action queue\n", initContext);#endif            // We need to do something different for Unix            nsIEventQueue * EQueue = nsnull;                        rv = aEventQService->GetThreadEventQueue(initContext->embeddedThread,                                                      &EQueue);            if (NS_FAILED(rv)) {                initContext->initFailCode = kCreateWebShellError;                return rv;            }#ifdef XP_UNIX            gdk_input_add(EQueue->GetEventQueueSelectFD(),                          GDK_INPUT_READ,                          event_processor_callback,                          EQueue);#endif            PLEventQueue * plEventQueue = nsnull;            EQueue->GetPLEventQueue(&plEventQueue);            initContext->actionQueue = plEventQueue;		}	}    else {        initContext->initFailCode = kCreateWebShellError;        return NS_ERROR_UNEXPECTED;    }#if DEBUG_RAPTOR_CANVAS	printf("InitMozillaStuff(%lx): Create the WebShell...\n", initContext);#endif    // Create the WebShell.    rv = nsRepository::CreateInstance(kWebShellCID, nsnull, kIWebShellIID, getter_AddRefs(initContext->webShell));    if (NS_FAILED(rv)) {        initContext->initFailCode = kCreateWebShellError;        return rv;    }    #if DEBUG_RAPTOR_CANVAS	printf("InitMozillaStuff(%lx): Init the WebShell...\n", initContext);#endif   #ifdef XP_UNIX    GdkSuperWin * superwin;    GtkMozArea * mozarea;    mozarea = (GtkMozArea *) initContext->gtkWinPtr;    superwin = mozarea->superwin;    rv = initContext->webShell->Init((nsNativeWidget *)superwin, initContext->x, initContext->y, initContext->w, initContext->h);#else        rv = initContext->webShell->Init((nsNativeWidget *)initContext->parentHWnd,                                     initContext->x, initContext->y, initContext->w, initContext->h);#endif    if (NS_FAILED(rv)) {        initContext->initFailCode = kInitWebShellError;        return rv;    }#if DEBUG_RAPTOR_CANVAS	printf("InitMozillaStuff(%lx): Install Prefs in the Webshell...\n", initContext);#endif    nsIPref *prefs;        rv = nsServiceManager::GetService(kPrefCID,                                       nsIPref::GetIID(),                                       (nsISupports **)&prefs);    if (NS_SUCCEEDED(rv)) {        // Set the prefs in the outermost webshell.        initContext->webShell->SetPrefs(prefs);        nsServiceManager::ReleaseService(kPrefCID, prefs);    }    if (nsnull == gHistory) {        rv = nsComponentManager::CreateInstance(kSessionHistoryCID, nsnull, kISessionHistoryIID,                                                 (void**)&gHistory);        if (NS_FAILED(rv)) {            initContext->initFailCode = kHistoryWebShellError;            return rv;        }    }    initContext->webShell->SetSessionHistory(gHistory);    // set the sessionHistory in the initContexn    initContext->sessionHistory = gHistory;    #if DEBUG_RAPTOR_CANVAS	printf("InitMozillaStuff(%lx): Show the WebShell...\n", initContext);#endif    nsCOMPtr<nsIBaseWindow> baseWindow;        rv = initContext->webShell->QueryInterface(NS_GET_IID(nsIBaseWindow),                                               getter_AddRefs(baseWindow));        if (NS_FAILED(rv)) {        initContext->initFailCode = kShowWebShellError;        return rv;    }    rv = baseWindow->SetVisibility(PR_TRUE);    if (NS_FAILED(rv)) {        initContext->initFailCode = kShowWebShellError;        return rv;    }    // set the docShell    rv = initContext->webShell->QueryInterface(NS_GET_IID(nsIDocShell),                                               getter_AddRefs(initContext->docShell));        if (NS_FAILED(rv)) {        initContext->initFailCode = kHistoryWebShellError;        ::util_ThrowExceptionToJava(initContext->env,                                     "Exception: Can't get DocShell from nsIWebShell");        return rv;    }            initContext->initComplete = TRUE;    #if DEBUG_RAPTOR_CANVAS    printf("InitMozillaStuff(%lx): enter event loop\n", initContext);#endif    // Just need to loop once to clear out events before returning    processEventLoop(initContext);    return rv;}