rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void **)&view);
rv = nsComponentManager::CreateInstance(kViewCID, nsnull, NS_GET_IID(nsIView), (void **)&view);
DocumentViewerImpl::PrintContent(nsIWebShell  *aParent,nsIDeviceContext *aDContext){  NS_ENSURE_ARG_POINTER(aParent);  NS_ENSURE_ARG_POINTER(aDContext);  nsCOMPtr<nsIStyleSet>       ss;  nsCOMPtr<nsIPref>           prefs;  nsCOMPtr<nsIViewManager>    vm;  PRInt32                     width, height;  nsIView                     *view;  nsresult                    rv;  PRInt32                     count,i;  nsCOMPtr<nsIContentViewer>  viewer;  nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(aParent));  parentAsNode->GetChildCount(&count);  if(count> 0) {     for(i=0;i<count;i++) {      nsCOMPtr<nsIDocShellTreeItem> child;      parentAsNode->GetChildAt(i, getter_AddRefs(child));      nsCOMPtr<nsIDocShell> childAsShell(do_QueryInterface(child));      childAsShell->GetContentViewer(getter_AddRefs(viewer));      nsCOMPtr<nsIContentViewerFile> viewerFile(do_QueryInterface(viewer));      if (viewerFile) {        nsCOMPtr<nsIWebShell> childWebShell(do_QueryInterface(child));        NS_ENSURE_SUCCESS(viewerFile->PrintContent(childWebShell,aDContext), NS_ERROR_FAILURE);      }    }  } else {    aDContext->BeginDocument();    aDContext->GetDeviceSurfaceDimensions(width, height);    nsCOMPtr<nsIPresContext> cx;    rv = NS_NewPrintContext(getter_AddRefs(cx));    if (NS_FAILED(rv)) {      return rv;    }    mPresContext->GetPrefs(getter_AddRefs(prefs));    cx->Init(aDContext, prefs);    nsCompatibility mode;    mPresContext->GetCompatibilityMode(&mode);    cx->SetCompatibilityMode(mode);    cx->SetContainer(aParent);    CreateStyleSet(mDocument, getter_AddRefs(ss));    nsCOMPtr<nsIPresShell> ps;    rv = NS_NewPresShell(getter_AddRefs(ps));    if (NS_FAILED(rv)) {      return rv;    }    rv = nsComponentManager::CreateInstance(kViewManagerCID,                                            nsnull,                                            kIViewManagerIID,                                            (void **)getter_AddRefs(vm));    if (NS_FAILED(rv)) {      return rv;    }    rv = vm->Init(aDContext);    if (NS_FAILED(rv)) {      return rv;    }    nsRect tbounds = nsRect(0, 0, width, height);    // Create a child window of the parent that is our "root view/window"    rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void **)&view);    if (NS_FAILED(rv)) {      return rv;    }    rv = view->Init(vm, tbounds, nsnull);    if (NS_FAILED(rv)) {      return rv;    }    // Setup hierarchical relationship in view manager    vm->SetRootView(view);    ps->Init(mDocument, cx, vm, ss);    //lay it out...    //aDContext->BeginDocument();    ps->InitialReflow(width, height);    // Ask the page sequence frame to print all the pages    nsIPageSequenceFrame* pageSequence;    nsPrintOptions        options;    ps->GetPageSequenceFrame(&pageSequence);    NS_ASSERTION(nsnull != pageSequence, "no page sequence frame");    pageSequence->Print(cx, options, nsnull);    aDContext->EndDocument();    ps->EndObservingDocument();  }  return NS_OK;}