mDocLoader->SetContainer(NS_STATIC_CAST(nsIContentViewerContainer*, this));
mDocLoader->SetContainer(NS_STATIC_CAST(nsIContentViewerContainer*, (nsIWebShell*)this));
nsWebShell::Init(nsNativeWidget aNativeParent,                 PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h,                 nsScrollPreference aScrolling,                 PRBool aAllowPlugins,                 PRBool aIsSunkenBorder){  nsresult rv = NS_OK;  // Cache the PL_EventQueue of the current UI thread...  //  // Since this call must be made on the UI thread, we know the Event Queue  // will be associated with the current thread...  //  NS_WITH_SERVICE(nsIEventQueueService, eventService, kEventQueueServiceCID, &rv);  if (NS_FAILED(rv)) return rv;  rv = eventService->GetThreadEventQueue(NS_CURRENT_THREAD, &mThreadEventQueue);  if (NS_FAILED(rv)) return rv;  //XXX make sure plugins have started up. this really needs to  //be associated with the nsIContentViewerContainer interfaces,  //not the nsIWebShell interfaces. this is a hack. MMP  nsRect aBounds(x,y,w,h);  mBounds.SetRect(x,y,w,h);     // initialize the webshells bounds --dwc0001  nsWidgetInitData  widgetInit;  CreatePluginHost(aAllowPlugins);  //mScrollPref = aScrolling;  WEB_TRACE(WEB_TRACE_CALLS,            ("nsWebShell::Init: this=%p", this));/*  it is ok to have a webshell without an aNativeParent (used later to create the mWindow --dwc0001  // Initial error checking...  NS_PRECONDITION(nsnull != aNativeParent, "null Parent Window");  if (nsnull == aNativeParent) {    rv = NS_ERROR_NULL_POINTER;    goto done;  }*/  // Create a document loader...  nsCOMPtr<nsIWebShell> webShellParent(do_QueryInterface(mParent));  if (webShellParent) {    nsIDocumentLoader* parentLoader;    // Create a child document loader...    rv = webShellParent->GetDocumentLoader(parentLoader);    if (NS_SUCCEEDED(rv)) {      rv = parentLoader->CreateDocumentLoader(&mDocLoader);      NS_RELEASE(parentLoader);    }  } else {    NS_WITH_SERVICE(nsIDocumentLoader, docLoaderService, kDocLoaderServiceCID, &rv);    if (NS_FAILED(rv)) return rv;    rv = docLoaderService->CreateDocumentLoader(&mDocLoader);    if (NS_FAILED(rv)) return rv;  }  // Set the webshell as the default IContentViewerContainer for the loader...  mDocLoader->SetContainer(NS_STATIC_CAST(nsIContentViewerContainer*, this));  //Register ourselves as an observer for the new doc loader  mDocLoader->AddObserver((nsIDocumentLoaderObserver*)this);  /* this is the old code, commented out for the new code below while I figure this out -- dwc0001  // Create device context  rv = nsComponentManager::CreateInstance(kDeviceContextCID, nsnull,                                    kIDeviceContextIID,                                    (void **)&mDeviceContext);  if (NS_FAILED(rv)) {    goto done;  }  mDeviceContext->Init(aNativeParent);  float dev2twip;  mDeviceContext->GetDevUnitsToTwips(dev2twip);  mDeviceContext->SetDevUnitsToAppUnits(dev2twip);  float twip2dev;  mDeviceContext->GetTwipsToDevUnits(twip2dev);  mDeviceContext->SetAppUnitsToDevUnits(twip2dev);//  mDeviceContext->SetGamma(1.7f);  mDeviceContext->SetGamma(1.0f);  // Create a Native window for the shell container...  rv = nsComponentManager::CreateInstance(kChildCID, nsnull, kIWidgetIID, (void**)&mWindow);  if (NS_FAILED(rv)) return rv;  widgetInit.clipChildren = PR_FALSE;  widgetInit.mWindowType = eWindowType_child;  //widgetInit.mBorderStyle = aIsSunkenBorder ? eBorderStyle_3DChildWindow : eBorderStyle_none;  mWindow->Create(aNativeParent, aBounds, nsWebShell::HandleEvent,                  mDeviceContext, nsnull, nsnull, &widgetInit);*/  // Create device context  if (nsnull != aNativeParent) {    rv = nsComponentManager::CreateInstance(kDeviceContextCID, nsnull,                                            kIDeviceContextIID,                                            (void **)&mDeviceContext);    if (NS_FAILED(rv)) return rv;    mDeviceContext->Init(aNativeParent);    float dev2twip;    mDeviceContext->GetDevUnitsToTwips(dev2twip);    mDeviceContext->SetDevUnitsToAppUnits(dev2twip);    float twip2dev;    mDeviceContext->GetTwipsToDevUnits(twip2dev);    mDeviceContext->SetAppUnitsToDevUnits(twip2dev);    //  mDeviceContext->SetGamma(1.7f);    mDeviceContext->SetGamma(1.0f);    // Create a Native window for the shell container...    rv = nsComponentManager::CreateInstance(kChildCID, nsnull, kIWidgetIID, (void**)&mWindow);    if (NS_FAILED(rv)) return rv;    widgetInit.clipChildren = PR_FALSE;    widgetInit.mWindowType = eWindowType_child;    //widgetInit.mBorderStyle = aIsSunkenBorder ? eBorderStyle_3DChildWindow : eBorderStyle_none;    mWindow->Create(aNativeParent, aBounds, nsWebShell::HandleEvent,                    mDeviceContext, nsnull, nsnull, &widgetInit);  } else {    // we need a deviceContext    rv = nsComponentManager::CreateInstance(kDeviceContextCID, nsnull,kIDeviceContextIID,(void **)&mDeviceContext);    if (NS_FAILED(rv)) return rv;    mDeviceContext->Init(aNativeParent);    float dev2twip;    mDeviceContext->GetDevUnitsToTwips(dev2twip);    mDeviceContext->SetDevUnitsToAppUnits(dev2twip);    float twip2dev;    mDeviceContext->GetTwipsToDevUnits(twip2dev);    mDeviceContext->SetAppUnitsToDevUnits(twip2dev);    mDeviceContext->SetGamma(1.0f);    widgetInit.clipChildren = PR_FALSE;    widgetInit.mWindowType = eWindowType_child;  }  // Set the language portion of the user agent. :)  NS_WITH_SERVICE(nsILocaleService, localeServ, kLocaleServiceCID, &rv);  if (NS_FAILED(rv)) return rv;  PRUnichar *UALang;  rv = localeServ->GetLocaleComponentForUserAgent(&UALang);  if (NS_FAILED(rv)) return rv;  NS_WITH_SERVICE(nsIIOService, ioServ, kIOServiceCID, &rv);  if (NS_FAILED(rv)) return rv;  rv = ioServ->SetLanguage(UALang);  nsAllocator::Free(UALang);  return rv;}