aPresContext->GetContainer(getter_AddRefs(parentAsSupports));
presContext->GetContainer(getter_AddRefs(parentAsSupports));
nsFrameLoader::EnsureDocShell(){  if (mDocShell) {    return NS_OK;  }#if 0  // Bug 8065: Don't exceed some maximum depth in content frames  // (MAX_DEPTH_CONTENT_FRAMES)  PRInt32 depth = 0;  nsCOMPtr<nsISupports> parentAsSupports;  aPresContext->GetContainer(getter_AddRefs(parentAsSupports));  if (parentAsSupports) {    nsCOMPtr<nsIDocShellTreeItem> parentAsItem =      do_QueryInterface(parentAsSupports);    while (parentAsItem) {      ++depth;      if (MAX_DEPTH_CONTENT_FRAMES < depth)        return NS_ERROR_UNEXPECTED; // Too deep, give up!  (silently?)      // Only count depth on content, not chrome.      // If we wanted to limit total depth, skip the following check:      PRInt32 parentType;      parentAsItem->GetItemType(&parentType);      if (nsIDocShellTreeItem::typeContent == parentType) {        nsIDocShellTreeItem* temp = parentAsItem;        temp->GetParent(getter_AddRefs(parentAsItem));      } else {        break; // we have exited content, stop counting, depth is OK!      }    }  }#endif  mDocShell = do_CreateInstance("@mozilla.org/webshell;1");  NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);#if 0  // 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(mDocShell));    NS_ENSURE_TRUE(subShellAsSupports, NS_ERROR_FAILURE);    presShell->SetSubShellFor(mContent, subShellAsSupports);    // We need to be able to get back to the presShell to unset the    // subshell at destruction    mPresShellWeak = getter_AddRefs(NS_GetWeakReference(presShell));  }#endif  nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));  NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);  nsAutoString frameName;  mOwnerElement->GetAttribute(NS_LITERAL_STRING("name"), frameName);  if (!frameName.IsEmpty()) {    docShellAsItem->SetName(frameName.get());  }  // 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<nsIPresContext> presContext;  GetPresContext(getter_AddRefs(presContext));  // what if !presContext ?  nsCOMPtr<nsISupports> container;  presContext->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);      nsAutoString value, valuePiece;      PRBool isContent;      isContent = PR_FALSE;      mOwnerElement->GetAttribute(NS_LITERAL_STRING("type"), value);      if (!value.IsEmpty()) {        // 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        // string iterators!        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) {          PRBool is_primary = value.EqualsIgnoreCase("content-primary");          parentTreeOwner->ContentShellAdded(docShellAsItem, is_primary,                                             value.get());        }      }      // connect the container...      nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mDocShell));      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<nsIChromeEventHandler> chromeEventHandler;      if (parentType == nsIDocShellTreeItem::typeChrome) {        // Our parent shell is a chrome shell. It is therefore our nearest        // enclosing chrome shell.        chromeEventHandler = do_QueryInterface(mOwnerElement);        NS_WARN_IF_FALSE(chromeEventHandler,                         "This mContent should implement this.");      } else {        nsCOMPtr<nsIDocShell> parentShell(do_QueryInterface(parentAsNode));        // 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));      }      // Should this be in the layout code?      mDocShell->SetChromeEventHandler(chromeEventHandler);    }  }  return NS_OK;}