NS_IF_RELEASE(typeAtom);
nsHTMLFrameInnerFrame::CreateDocShell(nsIPresContext* aPresContext,                                      const nsSize& aSize){  nsresult rv;  nsCOMPtr<nsIContent> parentContent;  GetParentContent(*getter_AddRefs(parentContent));  mSubShell = do_CreateInstance(kWebShellCID);  NS_ENSURE_TRUE(mSubShell, NS_ERROR_FAILURE);  // notify the pres shell that a docshell has been created  nsCOMPtr<nsIPresShell> presShell;  aPresContext->GetShell(getter_AddRefs(presShell));  if (presShell)  {    nsCOMPtr<nsISupports> subShellAsSupports(do_QueryInterface(mSubShell));    NS_ENSURE_TRUE(subShellAsSupports, NS_ERROR_FAILURE);    presShell->SetSubShellFor(mContent, subShellAsSupports);  }    nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mSubShell));  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);  // pass along marginwidth, marginheight, scrolling so sub document can use it  docShell->SetMarginWidth(GetMarginWidth(aPresContext, parentContent));  docShell->SetMarginHeight(GetMarginHeight(aPresContext, parentContent));  nsCompatibility mode;  aPresContext->GetCompatibilityMode(&mode);  // Current and initial scrolling is set so that all succeeding docs  // will use the scrolling value set here, regardless if scrolling is  // set by viewing a particular document (e.g. XUL turns off scrolling)  nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryInterface(mSubShell));  if (scrollableContainer) {    scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,      GetScrolling(parentContent, mode));    scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_X,      GetScrolling(parentContent, mode));  }  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mSubShell));  NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);  nsString frameName;  if (GetName(parentContent, frameName)) {    docShellAsItem->SetName(frameName.GetUnicode());  }  // If our container is a web-shell, inform it that it has a new  // child. If it's not a web-shell then some things will not operate  // properly.  nsCOMPtr<nsISupports> container;  aPresContext->GetContainer(getter_AddRefs(container));  if (container) {    nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(container));    if (parentAsNode) {      nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(parentAsNode));      PRInt32 parentType;      parentAsItem->GetItemType(&parentType);      nsIAtom* typeAtom = NS_NewAtom("type");      nsAutoString value, valuePiece;      PRBool isContent;      isContent = PR_FALSE;      if (NS_SUCCEEDED(parentContent->GetAttribute(kNameSpaceID_None,         typeAtom, value))) {        // we accept "content" and "content-xxx" values.        // at time of writing, we expect "xxx" to be "primary", but        // someday it might be an integer expressing priority        value.Left(valuePiece, 7);        if (valuePiece.EqualsIgnoreCase("content") &&           (value.Length() == 7 ||              value.Mid(valuePiece, 7, 1) == 1 && valuePiece.EqualsWithConversion("-")))            isContent = PR_TRUE;      }      if (isContent) {        // The web shell's type is content.        docShellAsItem->SetItemType(nsIDocShellTreeItem::typeContent);      } else {        // Inherit our type from our parent webshell.  If it is        // chrome, we'll be chrome.  If it is content, we'll be        // content.        docShellAsItem->SetItemType(parentType);      }            parentAsNode->AddChild(docShellAsItem);      if (isContent) {        nsCOMPtr<nsIDocShellTreeOwner> parentTreeOwner;        parentAsItem->GetTreeOwner(getter_AddRefs(parentTreeOwner));        if(parentTreeOwner)          parentTreeOwner->ContentShellAdded(docShellAsItem,             value.EqualsIgnoreCase("content-primary") ? PR_TRUE : PR_FALSE,             value.GetUnicode());      }      // connect the container...      nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mSubShell));      nsCOMPtr<nsIWebShellContainer> outerContainer(do_QueryInterface(container));      if (outerContainer)        webShell->SetContainer(outerContainer);      // Make sure all shells have links back to the content element in the      // nearest enclosing chrome shell.      nsCOMPtr<nsIDocShell> parentShell(do_QueryInterface(parentAsNode));      nsCOMPtr<nsIChromeEventHandler> chromeEventHandler;      if (parentType == nsIDocShellTreeItem::typeChrome) {        // Our parent shell is a chrome shell. It is therefore our nearest        // enclosing chrome shell.        chromeEventHandler = do_QueryInterface(mContent);        NS_WARN_IF_FALSE(chromeEventHandler, "This mContent should implement this.");      }      else {        // Our parent shell is a content shell. Get the chrome info from        // it and use that for our shell as well.        parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler));      }      docShell->SetChromeEventHandler(chromeEventHandler);    }  }  float t2p;  aPresContext->GetTwipsToPixels(&t2p);  // create, init, set the parent of the view  nsIView* view;  rv = nsComponentManager::CreateInstance(kCViewCID, nsnull, kIViewIID,                                        (void **)&view);  if (NS_OK != rv) {    NS_ASSERTION(0, "Could not create view for nsHTMLFrame");    return rv;  }  nsIView* parView;  nsPoint origin;  GetOffsetFromView(aPresContext, origin, &parView);    nsRect viewBounds(origin.x, origin.y, aSize.width, aSize.height);  nsCOMPtr<nsIViewManager> viewMan;  presShell->GetViewManager(getter_AddRefs(viewMan));    rv = view->Init(viewMan, viewBounds, parView);  viewMan->InsertChild(parView, view, 0);  rv = view->CreateWidget(kCChildCID);  SetView(aPresContext, view);  // if the visibility is hidden, reflect that in the view  const nsStyleDisplay* display;  GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)display));  if (!display->IsVisible()) {    view->SetVisibility(nsViewVisibility_kHide);  }  nsCOMPtr<nsIWidget> widget;  view->GetWidget(*getter_AddRefs(widget));  mSubShell->InitWindow(nsnull, widget, 0, 0, NSToCoordRound(aSize.width * t2p),    NSToCoordRound(aSize.height * t2p));  mSubShell->Create();  mSubShell->SetVisibility(PR_TRUE);  return NS_OK;}