Introduce a GetPrimaryShell() API on nsIDocument. Convert existing callers ofGetShellAt(0) to using this API. Bug 378780. API introduction part by me,r+sr=jst. Mass-changes done by taras using squash, r+sr=me
authorbzbarsky@mit.edu
Tue, 01 May 2007 15:24:20 -0700
changeset 981 037001687c8fbc60e127ca7f535dcb7342dabdc5
parent 980 3eb42f5df8becd4102c9f38092e612ecf63889d1
child 982 030ef6c40d2e21d8799cbd54f6f7f66a8c53cde2
push idunknown
push userunknown
push dateunknown
bugs378780
milestone1.9a5pre
Introduce a GetPrimaryShell() API on nsIDocument. Convert existing callers ofGetShellAt(0) to using this API. Bug 378780. API introduction part by me,r+sr=jst. Mass-changes done by taras using squash, r+sr=me
accessible/src/base/nsAccessNode.cpp
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessible.cpp
accessible/src/base/nsDocAccessible.cpp
accessible/src/html/nsHTMLSelectAccessible.cpp
accessible/src/html/nsHTMLTableAccessible.cpp
accessible/src/msaa/nsDocAccessibleWrap.cpp
content/base/public/nsIDocument.h
content/base/src/nsContentAreaDragDrop.cpp
content/base/src/nsContentSink.cpp
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/base/src/nsGenericElement.cpp
content/base/src/nsImageLoadingContent.cpp
content/base/src/nsObjectLoadingContent.cpp
content/base/src/nsScriptElement.cpp
content/events/src/nsEventListenerManager.cpp
content/events/src/nsEventStateManager.cpp
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsHTMLButtonElement.cpp
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsHTMLTableRowElement.cpp
content/html/document/src/nsHTMLDocument.cpp
content/html/document/src/nsImageDocument.cpp
content/html/document/src/nsPluginDocument.cpp
content/svg/content/src/nsSVGSVGElement.cpp
content/svg/content/src/nsSVGUseElement.cpp
content/xbl/src/nsBindingManager.cpp
content/xbl/src/nsXBLPrototypeHandler.cpp
content/xbl/src/nsXBLResourceLoader.cpp
content/xbl/src/nsXBLService.cpp
content/xml/document/src/nsXMLContentSink.cpp
content/xtf/src/nsXTFElementWrapper.cpp
content/xul/content/src/nsXULElement.cpp
content/xul/content/src/nsXULPopupListener.cpp
content/xul/document/src/nsXULDocument.cpp
dom/src/base/nsDOMClassInfo.cpp
dom/src/base/nsFocusController.cpp
dom/src/base/nsGlobalWindow.cpp
dom/src/base/nsHistory.cpp
dom/src/base/nsLocation.cpp
editor/libeditor/text/nsEditorEventListeners.cpp
embedding/browser/gtk/src/EmbedContextMenuInfo.cpp
embedding/browser/gtk/src/EmbedEventListener.cpp
embedding/components/find/src/nsFind.cpp
embedding/components/find/src/nsWebBrowserFind.cpp
extensions/access-builtin/accessproxy/nsAccessProxy.cpp
layout/base/nsPresShell.cpp
layout/forms/nsTextControlFrame.cpp
layout/generic/nsImageMap.cpp
layout/generic/nsObjectFrame.cpp
layout/inspector/src/inLayoutUtils.cpp
layout/printing/nsPrintPreviewListener.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsInspectorCSSUtils.cpp
layout/xul/base/src/nsBoxObject.cpp
layout/xul/base/src/nsImageBoxFrame.cpp
layout/xul/base/src/nsMenuBarFrame.cpp
layout/xul/base/src/nsMenuPopupFrame.cpp
layout/xul/base/src/nsXULTooltipListener.cpp
layout/xul/base/src/tree/src/nsTreeColumns.cpp
layout/xul/base/src/tree/src/nsTreeSelection.cpp
modules/plugin/base/src/nsPluginHostImpl.cpp
toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
toolkit/components/satchel/src/nsFormFillController.cpp
widget/src/beos/nsDragService.cpp
widget/src/mac/nsDragService.cpp
widget/src/xpwidgets/nsBaseDragService.cpp
--- a/accessible/src/base/nsAccessNode.cpp
+++ b/accessible/src/base/nsAccessNode.cpp
@@ -624,17 +624,17 @@ nsAccessNode::GetPresShellFor(nsIDOMNode
   nsCOMPtr<nsIDOMDocument> domDocument;
   aNode->GetOwnerDocument(getter_AddRefs(domDocument));
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDocument));
   if (!doc) {   // This is necessary when the node is the document node
     doc = do_QueryInterface(aNode);
   }
   nsIPresShell *presShell = nsnull;
   if (doc) {
-    presShell = doc->GetShellAt(0);
+    presShell = doc->GetPrimaryShell();
     NS_IF_ADDREF(presShell);
   }
   return presShell;
 }
 
 
 already_AddRefed<nsIDocShellTreeItem>
 nsAccessNode::GetDocShellTreeItemFor(nsIDOMNode *aStartNode)
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -290,33 +290,33 @@ nsAccessibilityService::GetInfo(nsISuppo
 
 #ifdef DEBUG_A11Y
   PRInt32 shells = document->GetNumberOfShells();
   NS_ASSERTION(shells > 0,"Error no shells!");
 #endif
 
   // do_GetWR only works into a |nsCOMPtr| :-(
   nsCOMPtr<nsIWeakReference> weakShell =
-    do_GetWeakReference(document->GetShellAt(0));
+    do_GetWeakReference(document->GetPrimaryShell());
   NS_IF_ADDREF(*aShell = weakShell);
 
   return NS_OK;
 }
 
 nsresult
 nsAccessibilityService::GetShellFromNode(nsIDOMNode *aNode, nsIWeakReference **aWeakShell)
 {
   nsCOMPtr<nsIDOMDocument> domDoc;
   aNode->GetOwnerDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
   if (!doc)
     return NS_ERROR_INVALID_ARG;
 
   // ---- Get the pres shell ----
-  nsIPresShell *shell = doc->GetShellAt(0);
+  nsIPresShell *shell = doc->GetPrimaryShell();
   if (!shell)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIWeakReference> weakRef(do_GetWeakReference(shell));
   
   *aWeakShell = weakRef;
   NS_IF_ADDREF(*aWeakShell);
 
@@ -355,17 +355,17 @@ nsAccessibilityService::CreateRootAccess
 {
   *aRootAcc = nsnull;
 
   nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(aDocument));
   NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);
 
   nsIPresShell *presShell = aShell;
   if (!presShell) {
-    presShell = aDocument->GetShellAt(0);
+    presShell = aDocument->GetPrimaryShell();
   }
   nsCOMPtr<nsIWeakReference> weakShell(do_GetWeakReference(presShell));
 
   nsCOMPtr<nsISupports> container = aDocument->GetContainer();
   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
     do_QueryInterface(container);
   NS_ENSURE_TRUE(docShellTreeItem, NS_ERROR_FAILURE);
   
@@ -934,17 +934,17 @@ nsAccessibilityService::GetAccessibleFor
     doc = content->GetDocument();
   }
   else {// Could be document node
     doc = do_QueryInterface(aNode);
   }
   if (!doc)
     return NS_ERROR_FAILURE;
 
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   return GetAccessibleInShell(aNode, presShell, aAccessible);
 }
 
 NS_IMETHODIMP
 nsAccessibilityService::GetAttachedAccessibleFor(nsIDOMNode *aNode,
                                                  nsIAccessible **aAccessible)
 {
   NS_ENSURE_ARG(aNode);
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -2857,17 +2857,17 @@ void nsAccessible::DoCommandCallback(nsI
   if (xulElement) {
     xulElement->Click();
   }
   else {
     nsIDocument *doc = content->GetDocument();
     if (!doc) {
       return;
     }
-    nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
+    nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
     nsPIDOMWindow *outerWindow = doc->GetWindow();
     if (presShell && outerWindow) {
       nsAutoPopupStatePusher popupStatePusher(outerWindow, openAllowed);
 
       nsMouseEvent downEvent(PR_TRUE, NS_MOUSE_BUTTON_DOWN, nsnull,
                              nsMouseEvent::eSynthesized);
       nsMouseEvent upEvent(PR_TRUE, NS_MOUSE_BUTTON_UP, nsnull,
                            nsMouseEvent::eSynthesized);
@@ -3236,17 +3236,17 @@ PRBool nsAccessible::CheckVisibilityInPa
       }
       view = view->GetParent();
     }
 
     nsIDocument* parentDoc = document->GetParentDocument();
     if (parentDoc != nsnull) {
       nsIContent* content = parentDoc->FindContentForSubDocument(document);
       if (content != nsnull) {
-        nsIPresShell* shell = parentDoc->GetShellAt(0);
+        nsIPresShell* shell = parentDoc->GetPrimaryShell();
         nsIFrame* frame = shell->GetPrimaryFrameFor(content);
         while (frame != nsnull && !frame->HasView()) {
           frame = frame->GetParent();
         }
 
         if (frame != nsnull) {
           view = frame->GetViewExternal();
         }
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -588,17 +588,17 @@ nsIFrame* nsDocAccessible::GetFrame()
 void nsDocAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aRelativeFrame)
 {
   *aRelativeFrame = GetFrame();
 
   nsIDocument *document = mDocument;
   nsIDocument *parentDoc = nsnull;
 
   while (document) {
-    nsIPresShell *presShell = document->GetShellAt(0);
+    nsIPresShell *presShell = document->GetPrimaryShell();
     if (!presShell) {
       return;
     }
     nsIViewManager* vm = presShell->GetViewManager();
     if (!vm) {
       return;
     }
 
--- a/accessible/src/html/nsHTMLSelectAccessible.cpp
+++ b/accessible/src/html/nsHTMLSelectAccessible.cpp
@@ -722,17 +722,17 @@ nsresult nsHTMLSelectOptionAccessible::G
 {
   *aFocusedOptionNode = nsnull;
   NS_ASSERTION(aListNode, "Called GetFocusedOptionNode without a valid list node");
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(aListNode));
   nsCOMPtr<nsIDocument> document = content->GetDocument();
   nsIPresShell *shell = nsnull;
   if (document)
-    shell = document->GetShellAt(0);
+    shell = document->GetPrimaryShell();
   if (!shell)
     return NS_ERROR_FAILURE;
 
   nsIFrame *frame = shell->GetPrimaryFrameFor(content);
   if (!frame)
     return NS_ERROR_FAILURE;
 
   PRInt32 focusedOptionIndex = 0;
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ b/accessible/src/html/nsHTMLTableAccessible.cpp
@@ -661,17 +661,17 @@ nsHTMLTableAccessible::GetTableLayout(ns
 
   nsCOMPtr<nsIDOMNode> tableNode;
   rv = GetTableNode(getter_AddRefs(tableNode));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIContent> content(do_QueryInterface(tableNode));
   NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
 
-  nsIPresShell *presShell = content->GetDocument()->GetShellAt(0);
+  nsIPresShell *presShell = content->GetDocument()->GetPrimaryShell();
 
   nsCOMPtr<nsISupports> layoutObject;
   rv = presShell->GetLayoutObjectFor(content, getter_AddRefs(layoutObject));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return CallQueryInterface(layoutObject, aLayoutObject);
 }
 
--- a/accessible/src/msaa/nsDocAccessibleWrap.cpp
+++ b/accessible/src/msaa/nsDocAccessibleWrap.cpp
@@ -131,17 +131,17 @@ STDMETHODIMP nsDocAccessibleWrap::get_ac
       return S_OK;
     }
     else if (mDocument) {
       // If child ID from event can't be found in this window, ask parent.
       // This is especially relevant for times when a xul menu item
       // has focus, but the system thinks the content window has focus.
       nsIDocument* parentDoc = mDocument->GetParentDocument();
       if (parentDoc) {
-        nsIPresShell *parentShell = parentDoc->GetShellAt(0);
+        nsIPresShell *parentShell = parentDoc->GetPrimaryShell();
         nsCOMPtr<nsIWeakReference> weakParentShell(do_GetWeakReference(parentShell));
         if (weakParentShell) {
           nsCOMPtr<nsIAccessibleDocument> parentDocAccessible = 
             nsAccessNode::GetDocAccessibleFor(weakParentShell);
           nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(parentDocAccessible));
           IAccessible *msaaParentDoc;
           if (accessible) {
             accessible->GetNativeInterface((void**)&msaaParentDoc);
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -89,18 +89,18 @@ class nsIDOMUserDataHandler;
 template<class E> class nsCOMArray;
 class nsIDocumentObserver;
 class nsBindingManager;
 class nsIDOMNodeList;
 class mozAutoSubtreeModified;
 
 // IID for the nsIDocument interface
 #define NS_IDOCUMENT_IID      \
-{ 0x1b8ed19c, 0xb87d, 0x4058, \
-  { 0x92, 0x2a, 0xff, 0xbc, 0x36, 0x29, 0x3b, 0xd7 } }
+{ 0xb7f930df, 0x1c61, 0x410f, \
+ { 0xab, 0x3c, 0xe2, 0x53, 0xca, 0x8d, 0x85, 0x49 } }
 
 // Flag for AddStyleSheet().
 #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
 
 //----------------------------------------------------------------------
 
 // Document interface.  This is implemented by all document objects in
 // Gecko.
@@ -344,16 +344,17 @@ public:
    */
   virtual nsresult CreateShell(nsPresContext* aContext,
                                nsIViewManager* aViewManager,
                                nsStyleSet* aStyleSet,
                                nsIPresShell** aInstancePtrResult) = 0;
   virtual PRBool DeleteShell(nsIPresShell* aShell) = 0;
   virtual PRUint32 GetNumberOfShells() const = 0;
   virtual nsIPresShell *GetShellAt(PRUint32 aIndex) const = 0;
+  virtual nsIPresShell *GetPrimaryShell() const = 0;
   virtual void SetShellsHidden(PRBool aHide) = 0;
 
   /**
    * Return the parent document of this document. Will return null
    * unless this document is within a compound document and has a
    * parent. Note that this parent chain may cross chrome boundaries.
    */
   nsIDocument *GetParentDocument() const
--- a/content/base/src/nsContentAreaDragDrop.cpp
+++ b/content/base/src/nsContentAreaDragDrop.cpp
@@ -800,17 +800,17 @@ nsContentAreaDragDrop::DragGesture(nsIDO
                       nsIDragService::DRAGDROP_ACTION_LINK;
 
     nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(inMouseEvent));
 
     if (isSelection) {
       nsCOMPtr<nsIContent> targetContent(do_QueryInterface(target));
       nsIDocument* doc = targetContent->GetCurrentDoc();
       if (doc) {
-        nsIPresShell* presShell = doc->GetShellAt(0);
+        nsIPresShell* presShell = doc->GetPrimaryShell();
         if (presShell) {
           nsISelection* selection =
             presShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
           return dragService->InvokeDragSessionWithSelection(selection,
                                                              transArray,
                                                              action,
                                                              mouseEvent);
         }
--- a/content/base/src/nsContentSink.cpp
+++ b/content/base/src/nsContentSink.cpp
@@ -443,17 +443,17 @@ nsContentSink::ProcessHeaderData(nsIAtom
   else if (aHeader == nsGkAtoms::link) {
     rv = ProcessLinkHeader(aContent, aValue);
   }
   else if (aHeader == nsGkAtoms::msthemecompatible) {
     // Disable theming for the presshell if the value is no.
     // XXXbz don't we want to support this as an HTTP header too?
     nsAutoString value(aValue);
     if (value.LowerCaseEqualsLiteral("no")) {
-      nsIPresShell* shell = mDocument->GetShellAt(0);
+      nsIPresShell* shell = mDocument->GetPrimaryShell();
       if (shell) {
         shell->DisableThemeSupport();
       }
     }
   }
   // Don't report "refresh" headers back to necko, since our document handles
   // them
   else if (aHeader != nsGkAtoms::refresh && mParser) {
@@ -1169,17 +1169,17 @@ nsContentSink::DidProcessATokenImpl()
   // interrupts the parser and samples the system clock infrequently
   // to provide fast page load time. When the user moves the mouse,
   // clicks or types the mode switches to the high frequency
   // interrupt mode. If the user stops moving the mouse or typing
   // for a duration of time (mDynamicIntervalSwitchThreshold) it
   // switches to low frequency interrupt mode.
 
   // Get the current user event time
-  nsIPresShell *shell = mDocument->GetShellAt(0);
+  nsIPresShell *shell = mDocument->GetPrimaryShell();
 
   if (!shell) {
     // If there's no pres shell in the document, return early since
     // we're not laying anything out here.
     return NS_OK;
   }
 
   nsIViewManager* vm = shell->GetViewManager();
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1979,16 +1979,23 @@ nsDocument::GetNumberOfShells() const
 
 nsIPresShell *
 nsDocument::GetShellAt(PRUint32 aIndex) const
 {
   return mShellsAreHidden ? nsnull :
          NS_STATIC_CAST(nsIPresShell*, mPresShells.SafeElementAt(aIndex));
 }
 
+nsIPresShell *
+nsDocument::GetPrimaryShell() const
+{
+  return mShellsAreHidden ? nsnull :
+         NS_STATIC_CAST(nsIPresShell*, mPresShells.SafeElementAt(0));
+}
+
 void
 nsDocument::SetShellsHidden(PRBool aHide)
 {
   mShellsAreHidden = aHide;
 }
 
 PR_STATIC_CALLBACK(void)
 SubDocClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
@@ -2764,17 +2771,17 @@ nsDocument::DispatchContentLoadedEvents(
         // the ancestor document if we used the normal event
         // dispatching code.
 
         nsEvent* innerEvent;
         privateEvent->GetInternalNSEvent(&innerEvent);
         if (innerEvent) {
           nsEventStatus status = nsEventStatus_eIgnore;
 
-          nsIPresShell *shell = ancestor_doc->GetShellAt(0);
+          nsIPresShell *shell = ancestor_doc->GetPrimaryShell();
           if (shell) {
             nsCOMPtr<nsPresContext> context = shell->GetPresContext();
 
             if (context) {
               nsEventDispatcher::Dispatch(ancestor_doc, context, innerEvent,
                                           event, &status);
             }
           }
@@ -3793,17 +3800,17 @@ NS_IMETHODIMP
 nsDocument::SetDir(const nsAString& aDirection)
 {
   PRUint32 options = GetBidiOptions();
 
   for (const DirTable* elt = dirAttributes; elt->mName; elt++) {
     if (aDirection == NS_ConvertASCIItoUTF16(elt->mName)) {
       if (GET_BIDI_OPTION_DIRECTION(options) != elt->mValue) {
         SET_BIDI_OPTION_DIRECTION(options, elt->mValue);
-        nsIPresShell *shell = GetShellAt(0);
+        nsIPresShell *shell = GetPrimaryShell();
         if (shell) {
           nsPresContext *context = shell->GetPresContext();
           NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
           context->SetBidi(options, PR_TRUE);
         } else {
           // No presentation; just set it on ourselves
           SetBidiOptions(options);
         }
@@ -4646,17 +4653,17 @@ nsDocument::RemoveEventListener(const ns
 {
   return RemoveGroupedEventListener(aType, aListener, aUseCapture, nsnull);
 }
 
 NS_IMETHODIMP
 nsDocument::DispatchEvent(nsIDOMEvent* aEvent, PRBool *_retval)
 {
   // Obtain a presentation context
-  nsIPresShell *shell = GetShellAt(0);
+  nsIPresShell *shell = GetPrimaryShell();
   nsCOMPtr<nsPresContext> context;
   if (shell) {
      context = shell->GetPresContext();
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =
     nsEventDispatcher::DispatchDOMEvent(NS_STATIC_CAST(nsINode*, this),
@@ -4735,17 +4742,17 @@ nsDocument::AddEventListener(const nsASt
 NS_IMETHODIMP
 nsDocument::CreateEvent(const nsAString& aEventType, nsIDOMEvent** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   *aReturn = nsnull;
 
   // Obtain a presentation shell
 
-  nsIPresShell *shell = GetShellAt(0);
+  nsIPresShell *shell = GetPrimaryShell();
 
   nsPresContext *presContext = nsnull;
 
   if (shell) {
     // Retrieve the context
     presContext = shell->GetPresContext();
   }
 
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -372,16 +372,17 @@ public:
    */
   virtual nsresult CreateShell(nsPresContext* aContext,
                                nsIViewManager* aViewManager,
                                nsStyleSet* aStyleSet,
                                nsIPresShell** aInstancePtrResult);
   virtual PRBool DeleteShell(nsIPresShell* aShell);
   virtual PRUint32 GetNumberOfShells() const;
   virtual nsIPresShell *GetShellAt(PRUint32 aIndex) const;
+  virtual nsIPresShell *GetPrimaryShell() const;
   virtual void SetShellsHidden(PRBool aHide);
 
   virtual nsresult SetSubDocumentFor(nsIContent *aContent,
                                      nsIDocument* aSubDoc);
   virtual nsIDocument* GetSubDocumentFor(nsIContent *aContent) const;
   virtual nsIContent* FindContentForSubDocument(nsIDocument *aDocument) const;
 
   /**
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -2494,17 +2494,17 @@ nsGenericElement::GetPrimaryFrame(mozFlu
 }
 
 /* static */
 nsIFrame*
 nsGenericElement::GetPrimaryFrameFor(nsIContent* aContent,
                                      nsIDocument* aDocument)
 {
   // Get presentation shell 0
-  nsIPresShell *presShell = aDocument->GetShellAt(0);
+  nsIPresShell *presShell = aDocument->GetPrimaryShell();
   if (!presShell) {
     return nsnull;
   }
 
   return presShell->GetPrimaryFrameFor(aContent);
 }
 
 //----------------------------------------------------------------------
--- a/content/base/src/nsImageLoadingContent.cpp
+++ b/content/base/src/nsImageLoadingContent.cpp
@@ -817,17 +817,17 @@ nsImageLoadingContent::FireEvent(const n
   if (!document) {
     // no use to fire events if there is no document....
     return NS_OK;
   }                                                                             
 
   // We should not be getting called from off the UI thread...
   NS_ASSERTION(NS_IsMainThread(), "should be on the main thread");
 
-  nsIPresShell *shell = document->GetShellAt(0);
+  nsIPresShell *shell = document->GetPrimaryShell();
   nsPresContext *presContext = shell ? shell->GetPresContext() : nsnull;
 
   nsCOMPtr<nsIRunnable> evt =
       new nsImageLoadingContent::Event(presContext, this, aEventType, document);
   NS_ENSURE_TRUE(evt, NS_ERROR_OUT_OF_MEMORY);
 
   // Block onload for our event.  Since we unblock in the event destructor, we
   // want to block now, even if posting will fail.
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -1293,17 +1293,17 @@ nsObjectLoadingContent::GetFrame()
     do_QueryInterface(NS_STATIC_CAST(nsIImageLoadingContent*, this));
   NS_ASSERTION(thisContent, "must be a content");
 
   nsIDocument* doc = thisContent->GetCurrentDoc();
   if (!doc) {
     return nsnull; // No current doc -> no frame
   }
 
-  nsIPresShell* shell = doc->GetShellAt(0);
+  nsIPresShell* shell = doc->GetPrimaryShell();
   if (!shell) {
     return nsnull; // No presentation -> no frame
   }
 
   nsIFrame* frame = shell->GetPrimaryFrameFor(thisContent);
   if (!frame) {
     return nsnull;
   }
--- a/content/base/src/nsScriptElement.cpp
+++ b/content/base/src/nsScriptElement.cpp
@@ -48,17 +48,17 @@
 #include "nsAutoPtr.h"
 #include "nsGkAtoms.h"
 
 static nsPresContext*
 GetContextForContent(nsIContent* aContent)
 {
   nsIDocument* doc = aContent->GetCurrentDoc();
   if (doc) {
-    nsIPresShell *presShell = doc->GetShellAt(0);
+    nsIPresShell *presShell = doc->GetPrimaryShell();
     if (presShell) {
       return presShell->GetPresContext();
     }
   }
   
   return nsnull;
 }
 
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -1316,17 +1316,17 @@ nsEventListenerManager::DispatchEvent(ns
   nsCOMPtr<nsIDocument> document = targetContent->GetOwnerDoc();
 
   // Do nothing if the element does not belong to a document
   if (!document) {
     return NS_OK;
   }
 
   // Obtain a presentation shell
-  nsIPresShell *shell = document->GetShellAt(0);
+  nsIPresShell *shell = document->GetPrimaryShell();
   nsCOMPtr<nsPresContext> context;
   if (shell) {
     context = shell->GetPresContext();
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =
     nsEventDispatcher::DispatchDOMEvent(targetContent, nsnull, aEvent,
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -791,17 +791,17 @@ nsEventStateManager::PreHandleEvent(nsPr
 
               // XXX bryner this isn't quite right -- it can result in
               // firing two blur events on the content.
 
               nsCOMPtr<nsIDocument> doc;
               if (gLastFocusedContent) // could have changed in Dispatch
                 doc = gLastFocusedContent->GetDocument();
               if (doc) {
-                nsIPresShell *shell = doc->GetShellAt(0);
+                nsIPresShell *shell = doc->GetPrimaryShell();
                 if (shell) {
                   nsCOMPtr<nsPresContext> oldPresContext =
                     shell->GetPresContext();
 
                   nsCOMPtr<nsIEventStateManager> esm;
                   esm = oldPresContext->EventStateManager();
                   esm->SetFocusedContent(gLastFocusedContent);
                   nsEventDispatcher::Dispatch(gLastFocusedContent,
@@ -1012,17 +1012,17 @@ nsEventStateManager::PreHandleEvent(nsPr
       if (focusedWindow) {
         focusedWindow->Focus();
 
         nsCOMPtr<nsIDocument> document = GetDocumentFromWindow(focusedWindow);
 
         if (document) {
           // Use a strong ref to make sure that the shell is alive still
           // when calling FrameSelection().
-          nsCOMPtr<nsIPresShell> shell = document->GetShellAt(0);
+          nsCOMPtr<nsIPresShell> shell = document->GetPrimaryShell();
           NS_ASSERTION(shell, "Focus events should not be getting thru when this is null!");
           if (shell) {
             nsPresContext* context = shell->GetPresContext();
             nsIMEStateManager::OnActivate(context);
             if (focusedElement) {
               nsCOMPtr<nsIContent> focusContent = do_QueryInterface(focusedElement);
               focusContent->SetFocus(context);
             } else {
@@ -1080,17 +1080,17 @@ nsEventStateManager::PreHandleEvent(nsPr
       // Now fire blurs.  Blur the content, then the document, then the window.
 
       if (gLastFocusedDocument && gLastFocusedDocument == mDocument) {
 
         nsEventStatus status = nsEventStatus_eIgnore;
         nsEvent event(PR_TRUE, NS_BLUR_CONTENT);
 
         if (gLastFocusedContent) {
-          nsIPresShell *shell = gLastFocusedDocument->GetShellAt(0);
+          nsIPresShell *shell = gLastFocusedDocument->GetPrimaryShell();
           if (shell) {
             nsCOMPtr<nsPresContext> oldPresContext = shell->GetPresContext();
 
             nsCOMPtr<nsIDOMElement> focusedElement;
             if (focusController)
               focusController->GetFocusedElement(getter_AddRefs(focusedElement));
 
             nsCOMPtr<nsIEventStateManager> esm;
@@ -1780,17 +1780,17 @@ nsEventStateManager::ChangeTextSize(PRIn
 
   nsCOMPtr<nsIDOMWindow> contentWindow;
   rootWindow->GetContent(getter_AddRefs(contentWindow));
   if(!contentWindow) return NS_ERROR_FAILURE;
 
   nsIDocument *doc = GetDocumentFromWindow(contentWindow);
   if(!doc) return NS_ERROR_FAILURE;
 
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   if(!presShell) return NS_ERROR_FAILURE;
   nsPresContext *presContext = presShell->GetPresContext();
   if(!presContext) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsISupports> pcContainer = presContext->GetContainer();
   if(!pcContainer) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDocShell> docshell(do_QueryInterface(pcContainer));
@@ -2786,17 +2786,17 @@ nsEventStateManager::NotifyMouseOver(nsG
   // Check to see if we're a subdocument and if so update the parent
   // document's ESM state to indicate that the mouse is over the
   // content associated with our subdocument.
   EnsureDocument(mPresContext);
   nsIDocument *parentDoc = mDocument->GetParentDocument();
   if (parentDoc) {
     nsIContent *docContent = parentDoc->FindContentForSubDocument(mDocument);
     if (docContent) {
-      nsIPresShell *parentShell = parentDoc->GetShellAt(0);
+      nsIPresShell *parentShell = parentDoc->GetPrimaryShell();
       if (parentShell) {
         nsEventStateManager* parentESM =
           NS_STATIC_CAST(nsEventStateManager*,
                          parentShell->GetPresContext()->EventStateManager());
         parentESM->NotifyMouseOver(aEvent, docContent);
       }
     }
   }
@@ -4173,17 +4173,17 @@ nsEventStateManager::SendFocusBlur(nsPre
       // the Ender widget case.
       nsCOMPtr<nsIDocument> doc = gLastFocusedContent->GetDocument();
       if (doc) {
         // The order of the nsIViewManager and nsIPresShell COM pointers is
         // important below.  We want the pres shell to get released before the
         // associated view manager on exit from this function.
         // See bug 53763.
         nsCOMPtr<nsIViewManager> kungFuDeathGrip;
-        nsIPresShell *shell = doc->GetShellAt(0);
+        nsIPresShell *shell = doc->GetPrimaryShell();
         if (shell) {
           kungFuDeathGrip = shell->GetViewManager();
 
           nsCOMPtr<nsPresContext> oldPresContext = shell->GetPresContext();
 
           //fire blur
           nsEventStatus status = nsEventStatus_eIgnore;
           nsEvent event(PR_TRUE, NS_BLUR_CONTENT);
@@ -4450,17 +4450,17 @@ nsEventStateManager::GetLastFocusedConte
 }
 
 NS_IMETHODIMP
 nsEventStateManager::GetFocusedFrame(nsIFrame** aFrame)
 {
   if (!mCurrentFocusFrame && mCurrentFocus) {
     nsIDocument* doc = mCurrentFocus->GetDocument();
     if (doc) {
-      nsIPresShell *shell = doc->GetShellAt(0);
+      nsIPresShell *shell = doc->GetPrimaryShell();
       if (shell) {
         mCurrentFocusFrame = shell->GetPrimaryFrameFor(mCurrentFocus);
       }
     }
   }
 
   *aFrame = mCurrentFocusFrame;
   return NS_OK;
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -1055,17 +1055,17 @@ nsGenericHTMLElement::ScrollIntoView(PRB
 {
   nsIDocument *document = GetCurrentDoc();
 
   if (!document) {
     return NS_OK;
   }
 
   // Get the presentation shell
-  nsCOMPtr<nsIPresShell> presShell = document->GetShellAt(0);
+  nsCOMPtr<nsIPresShell> presShell = document->GetPrimaryShell();
   if (!presShell) {
     return NS_OK;
   }
 
   PRIntn vpercent = aTop ? NS_PRESSHELL_SCROLL_TOP :
     NS_PRESSHELL_SCROLL_ANYWHERE;
 
   presShell->ScrollContentIntoView(this, vpercent,
@@ -1752,17 +1752,17 @@ nsGenericHTMLElement::RestoreFormControl
 // XXX This creates a dependency between content and frames
 nsPresContext*
 nsGenericHTMLElement::GetPresContext()
 {
   // Get the document
   nsIDocument* doc = GetDocument();
   if (doc) {
     // Get presentation shell 0
-    nsIPresShell *presShell = doc->GetShellAt(0);
+    nsIPresShell *presShell = doc->GetPrimaryShell();
     if (presShell) {
       return presShell->GetPresContext();
     }
   }
 
   return nsnull;
 }
 
--- a/content/html/content/src/nsHTMLButtonElement.cpp
+++ b/content/html/content/src/nsHTMLButtonElement.cpp
@@ -213,17 +213,17 @@ nsHTMLButtonElement::Click()
     return NS_OK;
 
   mHandlingClick = PR_TRUE;
   // Hold on to the document in case one of the events makes it die or
   // something...
   nsCOMPtr<nsIDocument> doc = GetCurrentDoc();
 
   if (doc) {
-    nsIPresShell *shell = doc->GetShellAt(0);
+    nsIPresShell *shell = doc->GetPrimaryShell();
     if (shell) {
       nsCOMPtr<nsPresContext> context = shell->GetPresContext();
       if (context) {
         // Click() is never called from native code, but it may be
         // called from chrome JS. Mark this event trusted if Click()
         // is called from chrome code.
         nsMouseEvent event(nsContentUtils::IsCallerChrome(),
                            NS_MOUSE_CLICK, nsnull,
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -1305,17 +1305,17 @@ nsHTMLInputElement::Click()
       mType == NS_FORM_INPUT_IMAGE) {
 
     // Strong in case the event kills it
     nsCOMPtr<nsIDocument> doc = GetCurrentDoc();
     if (!doc) {
       return rv;
     }
     
-    nsIPresShell *shell = doc->GetShellAt(0);
+    nsIPresShell *shell = doc->GetPrimaryShell();
 
     if (shell) {
       nsCOMPtr<nsPresContext> context = shell->GetPresContext();
 
       if (context) {
         // Click() is never called from native code, but it may be
         // called from chrome JS. Mark this event trusted if Click()
         // is called from chrome code.
--- a/content/html/content/src/nsHTMLTableRowElement.cpp
+++ b/content/html/content/src/nsHTMLTableRowElement.cpp
@@ -101,17 +101,17 @@ void DebugList(nsIDOMHTMLTableElement* a
     nsCOMPtr<nsIDocument> doc;
     result = content->GetDocument(getter_AddRefs(doc));
     if (doc) {
       nsCOMPtr<nsIContent> root;
       doc->GetRootContent(getter_AddRefs(root));
       if (root) {
         root->List();
       }
-      nsIPresShell *shell = doc->GetShellAt(0);
+      nsIPresShell *shell = doc->GetPrimaryShell();
       if (shell) {
         nsIFrame* rootFrame = shell->FrameManager()->GetRootFrame();
         if (rootFrame) {
           rootFrame->List(stdout, 0);
         }
       }
     }
   }
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -1234,17 +1234,17 @@ nsHTMLDocument::GetImageMap(const nsAStr
 void
 nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode)
 {
   NS_ASSERTION(!IsXHTML() || aMode == eCompatibility_FullStandards,
                "Bad compat mode for XHTML document!");
 
   mCompatMode = aMode;
   CSSLoader()->SetCompatibilityMode(mCompatMode);
-  nsCOMPtr<nsIPresShell> shell = GetShellAt(0);
+  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
   if (shell) {
     nsPresContext *pc = shell->GetPresContext();
     if (pc) {
       pc->CompatibilityModeChanged();
     }
   }
 }
 
@@ -2727,17 +2727,17 @@ nsHTMLDocument::GetWidth(PRInt32* aWidth
 {
   NS_ENSURE_ARG_POINTER(aWidth);
   *aWidth = 0;
 
   // We make the assumption that the first presentation shell
   // is the one for which we need information.
   // Since GetPixelDimensions flushes and flushing can destroy
   // our shell, hold a strong ref to it.
-  nsCOMPtr<nsIPresShell> shell = GetShellAt(0);
+  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
   if (!shell) {
     return NS_OK;
   }
 
   PRInt32 dummy;
 
   // GetPixelDimensions() does the flushing for us, no need to flush
   // here too
@@ -2749,17 +2749,17 @@ nsHTMLDocument::GetHeight(PRInt32* aHeig
 {
   NS_ENSURE_ARG_POINTER(aHeight);
   *aHeight = 0;
 
   // We make the assumption that the first presentation shell
   // is the one for which we need information.
   // Since GetPixelDimensions flushes and flushing can destroy
   // our shell, hold a strong ref to it.
-  nsCOMPtr<nsIPresShell> shell = GetShellAt(0);
+  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
   if (!shell) {
     return NS_OK;
   }
 
   PRInt32 dummy;
 
   // GetPixelDimensions() does the flushing for us, no need to flush
   // here too
--- a/content/html/document/src/nsImageDocument.cpp
+++ b/content/html/document/src/nsImageDocument.cpp
@@ -423,17 +423,17 @@ nsImageDocument::ShrinkToFit()
 NS_IMETHODIMP
 nsImageDocument::RestoreImageTo(PRInt32 aX, PRInt32 aY)
 {
   float ratio = GetRatio();
 
   RestoreImage();
   FlushPendingNotifications(Flush_Layout);
 
-  nsIPresShell *shell = GetShellAt(0);
+  nsIPresShell *shell = GetPrimaryShell();
   if (!shell)
     return NS_OK;
 
   nsPresContext* context = shell->GetPresContext();
   if (!context)
     return NS_OK;
 
   nsIViewManager* vm = context->GetViewManager();
@@ -595,17 +595,17 @@ nsImageDocument::CreateSyntheticDocument
   imageLoader->SetLoadingEnabled(PR_TRUE);
 
   return NS_OK;
 }
 
 nsresult
 nsImageDocument::CheckOverflowing(PRBool changeState)
 {
-  nsIPresShell *shell = GetShellAt(0);
+  nsIPresShell *shell = GetPrimaryShell();
   if (!shell) {
     return NS_OK;
   }
 
   nsPresContext *context = shell->GetPresContext();
   nsRect visibleArea = context->GetVisibleArea();
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(mBodyContent);
--- a/content/html/document/src/nsPluginDocument.cpp
+++ b/content/html/document/src/nsPluginDocument.cpp
@@ -94,17 +94,17 @@ nsPluginStreamListener::OnStartRequest(n
   nsresult rv = nsMediaDocumentStreamListener::OnStartRequest(request, ctxt);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsIContent* embed = mPluginDoc->GetPluginContent();
 
   // Now we have a frame for our <embed>, start the load
-  nsIPresShell* shell = mDocument->GetShellAt(0);
+  nsIPresShell* shell = mDocument->GetPrimaryShell();
   if (!shell) {
     // Can't instantiate w/o a shell
     return NS_BINDING_ABORTED;
   }
 
   nsIFrame* frame = shell->GetPrimaryFrameFor(embed);
   if (!frame) {
     return rv;
@@ -286,17 +286,17 @@ nsPluginDocument::SetStreamListener(nsIS
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPluginDocument::Print()
 {
   NS_ENSURE_TRUE(mPluginContent, NS_ERROR_FAILURE);
 
-  nsIPresShell *shell = GetShellAt(0);
+  nsIPresShell *shell = GetPrimaryShell();
   if (!shell) {
     return NS_OK;
   }
 
   nsIFrame* frame = shell->GetPrimaryFrameFor(mPluginContent);
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
   nsIObjectFrame* objectFrame = nsnull;
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -267,17 +267,17 @@ nsSVGSVGElement::GetPixelUnitToMillimete
   // to correctly determine this, the caller would need to pass in the
   // right PresContext...
 
   *aPixelUnitToMillimeterX = 0.28f; // 90dpi
 
   nsIDocument* doc = GetCurrentDoc();
   if (!doc) return NS_OK;
   // Get Presentation shell 0
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   if (!presShell) return NS_OK;
   
   // Get the Presentation Context from the Shell
   nsPresContext *context = presShell->GetPresContext();
   if (!context) return NS_OK;
 
   *aPixelUnitToMillimeterX = 25.4f / nsPresContext::AppUnitsToIntCSSPixels(context->AppUnitsPerInch());
   return NS_OK;
@@ -297,17 +297,17 @@ nsSVGSVGElement::GetScreenPixelToMillime
   // to correctly determine this, the caller would need to pass in the
   // right PresContext...
 
   *aScreenPixelToMillimeterX = 0.28f; // 90dpi
 
   nsIDocument* doc = GetCurrentDoc();
   if (!doc) return NS_OK;
     // Get Presentation shell 0
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   if (!presShell) return NS_OK;
   
   // Get the Presentation Context from the Shell
   nsPresContext *context = presShell->GetPresContext();
   if (!context) return NS_OK;
 
   *aScreenPixelToMillimeterX = 25.4f / context->AppUnitsToDevPixels(context->AppUnitsPerInch());
   return NS_OK;
@@ -1006,17 +1006,17 @@ nsSVGSVGElement::SetCurrentScaleTranslat
   SetCurrentScale(s);  // clamps! don't call mCurrentScale->SetValue() directly
   mCurrentTranslate->SetX(x);
   mCurrentTranslate->SetY(y);
   mDispatchEvent = PR_TRUE;
 
   // now dispatch an SVGZoom event if we are the root element
   nsIDocument* doc = GetCurrentDoc();
   if (doc) {
-    nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
+    nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
     NS_ASSERTION(presShell, "no presShell");
     if (presShell &&
         doc->GetRootContent() == NS_STATIC_CAST(nsIContent*, this)) {
       nsEventStatus status = nsEventStatus_eIgnore;
       nsGUIEvent event(PR_TRUE, NS_SVG_ZOOM, 0);
       event.eventStructType = NS_SVGZOOM_EVENT;
       presShell->HandleDOMEventWithTarget(this, &event, &status);
     }
@@ -1031,17 +1031,17 @@ nsSVGSVGElement::SetCurrentTranslate(flo
   mDispatchEvent = PR_FALSE;
   mCurrentTranslate->SetX(x);
   mCurrentTranslate->SetY(y);
   mDispatchEvent = PR_TRUE;
 
   // now dispatch an SVGScroll event if we are the root element
   nsIDocument* doc = GetCurrentDoc();
   if (doc) {
-    nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
+    nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
     NS_ASSERTION(presShell, "no presShell");
     if (presShell &&
         doc->GetRootContent() == NS_STATIC_CAST(nsIContent*, this)) {
       nsEventStatus status = nsEventStatus_eIgnore;
       nsEvent event(PR_TRUE, NS_SVG_SCROLL);
       event.eventStructType = NS_SVG_EVENT;
       presShell->HandleDOMEventWithTarget(this, &event, &status);
     }
@@ -1162,17 +1162,17 @@ nsSVGSVGElement::WillModifySVGObservable
 }
 
 NS_IMETHODIMP
 nsSVGSVGElement::DidModifySVGObservable (nsISVGValue* observable,
                                          nsISVGValue::modificationType aModType)
 {
   nsIDocument* doc = GetCurrentDoc();
   if (!doc) return NS_ERROR_FAILURE;
-  nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
+  nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
   NS_ASSERTION(presShell, "no presShell");
   if (!presShell) return NS_ERROR_FAILURE;
 
   // If currentScale or currentTranslate has changed, we are the root element,
   // and the changes wasn't caused by SetCurrent[Scale]Translate then we must
   // dispatch an SVGZoom or SVGScroll DOM event before repainting
   nsCOMPtr<nsIDOMSVGNumber> n = do_QueryInterface(observable);
   if (n && n==mCurrentScale) {
@@ -1291,17 +1291,17 @@ void nsSVGSVGElement::GetOffsetToAncesto
   nsIDocument *document = GetCurrentDoc();
   if (!document) return;
 
   // Flush all pending notifications so that our frames are uptodate
   // Make sure to do this before we start grabbing layout objects like
   // presshells.
   document->FlushPendingNotifications(Flush_Layout);
   
-  nsIPresShell *presShell = document->GetShellAt(0);
+  nsIPresShell *presShell = document->GetPrimaryShell();
   if (!presShell) {
     return;
   }
 
   nsPresContext *context = presShell->GetPresContext();
   if (!context) {
     return;
   }
@@ -1318,17 +1318,17 @@ void nsSVGSVGElement::GetOffsetToAncesto
   }
 }
 
 void
 nsSVGSVGElement::InvalidateTransformNotifyFrame()
 {
   nsIDocument* doc = GetCurrentDoc();
   if (!doc) return;
-  nsIPresShell* presShell = doc->GetShellAt(0);
+  nsIPresShell* presShell = doc->GetPrimaryShell();
   if (!presShell) return;
 
   nsIFrame* frame = presShell->GetPrimaryFrameFor(this);
   if (frame) {
     nsISVGSVGFrame* svgframe;
     CallQueryInterface(frame, &svgframe);
     if (svgframe) {
       svgframe->NotifyViewportChange();
--- a/content/svg/content/src/nsSVGUseElement.cpp
+++ b/content/svg/content/src/nsSVGUseElement.cpp
@@ -441,17 +441,17 @@ nsSVGUseElement::LookupHref()
   return nsContentUtils::GetReferencedElement(targetURI, this);
 }
 
 void
 nsSVGUseElement::TriggerReclone()
 {
   nsIDocument *doc = GetCurrentDoc();
   if (!doc) return;
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   if (!presShell) return;
   presShell->RecreateFramesFor(this);
 }
 
 void
 nsSVGUseElement::RemoveListener()
 {
   if (mSourceContent) {
--- a/content/xbl/src/nsBindingManager.cpp
+++ b/content/xbl/src/nsBindingManager.cpp
@@ -721,17 +721,17 @@ nsBindingManager::RemoveLayeredBinding(n
   binding->ChangeDocument(doc, nsnull);
   SetBinding(aContent, nsnull);
   binding->MarkForDeath();
   
   // ...and recreate it's frames. We need to do this since the frames may have
   // been removed and style may have changed due to the removal of the
   // anonymous children.
   // XXXbz this should be using the current doc (if any), not the owner doc.
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   return presShell->RecreateFramesFor(aContent);;
 }
 
 nsresult
 nsBindingManager::LoadBindingDocument(nsIDocument* aBoundDoc,
                                       nsIURI* aURL,
--- a/content/xbl/src/nsXBLPrototypeHandler.cpp
+++ b/content/xbl/src/nsXBLPrototypeHandler.cpp
@@ -390,17 +390,17 @@ nsXBLPrototypeHandler::ExecuteHandler(ns
     keyEvent->GetAltKey(&event.isAlt);
     keyEvent->GetCtrlKey(&event.isControl);
     keyEvent->GetShiftKey(&event.isShift);
     keyEvent->GetMetaKey(&event.isMeta);
     
     nsPresContext *pc = nsnull;
     nsIDocument *doc = handlerElement->GetCurrentDoc();
     if (doc) {
-      nsIPresShell *shell = doc->GetShellAt(0);
+      nsIPresShell *shell = doc->GetPrimaryShell();
       if (shell) {
         pc = shell->GetPresContext();
       }
     }
 
     nsEventDispatcher::Dispatch(handlerElement, pc, &event, nsnull, &status);
     return NS_OK;
   }
--- a/content/xbl/src/nsXBLResourceLoader.cpp
+++ b/content/xbl/src/nsXBLResourceLoader.cpp
@@ -246,17 +246,17 @@ nsXBLResourceLoader::NotifyBoundElements
         // also a descendant of another element with binding |mBinding|,
         // then we might have just constructed it due to the
         // notification of its parent.  (We can know about both if the
         // binding loads were triggered from the DOM rather than frame
         // construction.)  So we have to check both whether the element
         // has a primary frame and whether it's in the undisplayed map
         // before sending a ContentInserted notification, or bad things
         // will happen.
-        nsIPresShell *shell = doc->GetShellAt(0);
+        nsIPresShell *shell = doc->GetPrimaryShell();
         if (shell) {
           nsIFrame* childFrame = shell->GetPrimaryFrameFor(content);
           if (!childFrame) {
             // Check to see if it's in the undisplayed content map.
             nsStyleContext* sc =
               shell->FrameManager()->GetUndisplayedContent(content);
 
             if (!sc) {
--- a/content/xbl/src/nsXBLService.cpp
+++ b/content/xbl/src/nsXBLService.cpp
@@ -185,17 +185,17 @@ public:
     // also a descendant of another element with binding |mBinding|,
     // then we might have just constructed it due to the
     // notification of its parent.  (We can know about both if the
     // binding loads were triggered from the DOM rather than frame
     // construction.)  So we have to check both whether the element
     // has a primary frame and whether it's in the undisplayed map
     // before sending a ContentInserted notification, or bad things
     // will happen.
-    nsIPresShell *shell = doc->GetShellAt(0);
+    nsIPresShell *shell = doc->GetPrimaryShell();
     if (shell) {
       nsIFrame* childFrame = shell->GetPrimaryFrameFor(mBoundElement);
       if (!childFrame) {
         // Check to see if it's in the undisplayed content map.
         nsStyleContext* sc =
           shell->FrameManager()->GetUndisplayedContent(mBoundElement);
 
         if (!sc) {
--- a/content/xml/document/src/nsXMLContentSink.cpp
+++ b/content/xml/document/src/nsXMLContentSink.cpp
@@ -1091,17 +1091,17 @@ nsXMLContentSink::HandleEndElement(const
   DidAddContent();
 
 #ifdef MOZ_SVG
   if (content->GetNameSpaceID() == kNameSpaceID_SVG &&
       content->HasAttr(kNameSpaceID_None, nsGkAtoms::onload)) {
     nsEventStatus status = nsEventStatus_eIgnore;
     nsEvent event(PR_TRUE, NS_SVG_LOAD);
     event.eventStructType = NS_SVG_EVENT;
-    nsCOMPtr<nsIPresShell> presShell = mDocument->GetShellAt(0);
+    nsCOMPtr<nsIPresShell> presShell = mDocument->GetPrimaryShell();
     if (presShell) {
       FlushTags();
       presShell->HandleDOMEventWithTarget(content, &event, &status);
     }
   }
 #endif
 
   return NS_SUCCEEDED(result) ? DidProcessATokenImpl() : result;
--- a/content/xtf/src/nsXTFElementWrapper.cpp
+++ b/content/xtf/src/nsXTFElementWrapper.cpp
@@ -925,17 +925,17 @@ nsXTFElementWrapper::SetClassAttributeNa
 void
 nsXTFElementWrapper::RegUnregAccessKey(PRBool aDoReg)
 {
   nsIDocument* doc = GetCurrentDoc();
   if (!doc)
     return;
 
   // Get presentation shell 0
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   if (!presShell)
     return;
 
   nsPresContext *presContext = presShell->GetPresContext();
   if (!presContext)
     return;
 
   nsIEventStateManager *esm = presContext->EventStateManager();
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -600,17 +600,17 @@ nsXULElement::PerformAccesskey(PRBool aK
         if (!content)
             return;
     }
 
     nsIDocument* doc = GetCurrentDoc();
     if (!doc)
         return;
 
-    nsIPresShell *shell = doc->GetShellAt(0);
+    nsIPresShell *shell = doc->GetPrimaryShell();
     if (!shell)
         return;
 
     nsIFrame* frame = shell->GetPrimaryFrameFor(content);
     if (!frame)
         return;
 
     const nsStyleVisibility* vis = frame->GetStyleVisibility();
@@ -1100,17 +1100,17 @@ nsXULElement::RemoveChildAt(PRUint32 aIn
 
 void
 nsXULElement::UnregisterAccessKey(const nsAString& aOldValue)
 {
     // If someone changes the accesskey, unregister the old one
     //
     nsIDocument* doc = GetCurrentDoc();
     if (doc && !aOldValue.IsEmpty()) {
-        nsIPresShell *shell = doc->GetShellAt(0);
+        nsIPresShell *shell = doc->GetPrimaryShell();
 
         if (shell) {
             nsIContent *content = this;
 
             // find out what type of content node this is
             if (mNodeInfo->Equals(nsGkAtoms::label)) {
                 // For anonymous labels the unregistering must
                 // occur on the binding parent control.
@@ -2029,17 +2029,17 @@ nsXULElement::Focus()
     // What kind of crazy tries to focus an element without a doc?
     if (!doc)
         return NS_OK;
 
     // Obtain a presentation context and then call SetFocus.
     if (doc->GetNumberOfShells() == 0)
         return NS_OK;
 
-    nsIPresShell *shell = doc->GetShellAt(0);
+    nsIPresShell *shell = doc->GetPrimaryShell();
 
     // Set focus
     nsCOMPtr<nsPresContext> context = shell->GetPresContext();
     SetFocus(context);
 
     return NS_OK;
 }
 
@@ -2050,17 +2050,17 @@ nsXULElement::Blur()
     // What kind of crazy tries to blur an element without a doc?
     if (!doc)
         return NS_OK;
 
     // Obtain a presentation context and then call SetFocus.
     if (doc->GetNumberOfShells() == 0)
         return NS_OK;
 
-    nsIPresShell *shell = doc->GetShellAt(0);
+    nsIPresShell *shell = doc->GetPrimaryShell();
 
     // Set focus
     nsCOMPtr<nsPresContext> context = shell->GetPresContext();
     if (ShouldBlur(this))
       RemoveFocus(context);
 
     return NS_OK;
 }
@@ -2331,17 +2331,17 @@ nsresult nsXULElement::MakeHeavyweight()
 
 nsresult
 nsXULElement::HideWindowChrome(PRBool aShouldHide)
 {
     nsIDocument* doc = GetCurrentDoc();
     if (!doc || doc->GetRootContent() != this)
       return NS_ERROR_UNEXPECTED;
 
-    nsIPresShell *shell = doc->GetShellAt(0);
+    nsIPresShell *shell = doc->GetPrimaryShell();
 
     if (shell) {
         nsIContent* content = NS_STATIC_CAST(nsIContent*, this);
         nsIFrame* frame = shell->GetPrimaryFrameFor(content);
 
         nsPresContext *presContext = shell->GetPresContext();
 
         if (frame && presContext) {
--- a/content/xul/content/src/nsXULPopupListener.cpp
+++ b/content/xul/content/src/nsXULPopupListener.cpp
@@ -322,17 +322,17 @@ XULPopupListenerImpl::FireFocusOnTargetC
   nsresult rv;
   nsCOMPtr<nsIDOMDocument> domDoc;
   rv = aTargetNode->GetOwnerDocument(getter_AddRefs(domDoc));
   if(NS_SUCCEEDED(rv) && domDoc)
   {
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
 
     // Get nsIDOMElement for targetNode
-    nsIPresShell *shell = doc->GetShellAt(0);
+    nsIPresShell *shell = doc->GetPrimaryShell();
     if (!shell)
       return NS_ERROR_FAILURE;
 
     // strong reference to keep this from going away between events
     nsCOMPtr<nsPresContext> context = shell->GetPresContext();
  
     nsCOMPtr<nsIContent> content = do_QueryInterface(aTargetNode);
     nsIFrame* targetFrame = shell->GetPrimaryFrameFor(content);
@@ -565,17 +565,17 @@ XULPopupListenerImpl::LaunchPopup(PRInt3
     return NS_OK;
 
   // Submenus can't be used as context menus or popups, bug 288763.
   // Similar code also in nsXULTooltipListener::GetTooltipFor.
   nsCOMPtr<nsIContent> popup = do_QueryInterface(popupContent);
   nsIContent* parent = popup->GetParent();
   if (parent) {
     nsIDocument* doc = parent->GetCurrentDoc();
-    nsIPresShell* presShell = doc ? doc->GetShellAt(0) : nsnull;
+    nsIPresShell* presShell = doc ? doc->GetPrimaryShell() : nsnull;
     nsIFrame* frame = presShell ? presShell->GetPrimaryFrameFor(parent) : nsnull;
     if (frame) {
       nsIMenuFrame* menu = nsnull;
       CallQueryInterface(frame, &menu);
       NS_ENSURE_FALSE(menu, NS_OK);
     }
   }
 
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -1417,17 +1417,17 @@ NS_IMETHODIMP
 nsXULDocument::GetWidth(PRInt32* aWidth)
 {
     NS_ENSURE_ARG_POINTER(aWidth);
 
     nsresult rv = NS_OK;
 
     // We make the assumption that the first presentation shell
     // is the one for which we need information.
-    nsIPresShell *shell = GetShellAt(0);
+    nsIPresShell *shell = GetPrimaryShell();
     if (shell) {
         PRInt32 width, height;
 
         rv = GetPixelDimensions(shell, &width, &height);
         *aWidth = width;
     } else
         *aWidth = 0;
 
@@ -1438,17 +1438,17 @@ NS_IMETHODIMP
 nsXULDocument::GetHeight(PRInt32* aHeight)
 {
     NS_ENSURE_ARG_POINTER(aHeight);
 
     nsresult rv = NS_OK;
 
     // We make the assumption that the first presentation shell
     // is the one for which we need information.
-    nsIPresShell *shell = GetShellAt(0);
+    nsIPresShell *shell = GetPrimaryShell();
     if (shell) {
         PRInt32 width, height;
 
         rv = GetPixelDimensions(shell, &width, &height);
         *aHeight = height;
     } else
         *aHeight = 0;
 
@@ -3793,17 +3793,17 @@ nsForwardReference::Result
 nsXULDocument::OverlayForwardReference::Resolve()
 {
     // Resolve a forward reference from an overlay element; attempt to
     // hook it up into the main document.
     nsresult rv;
     nsCOMPtr<nsIContent> target;
 
     PRBool notify = PR_FALSE;
-    nsIPresShell *shell = mDocument->GetShellAt(0);
+    nsIPresShell *shell = mDocument->GetPrimaryShell();
     if (shell)
         shell->GetDidInitialReflow(&notify);
 
     nsAutoString id;
     mOverlay->GetAttr(kNameSpaceID_None, nsGkAtoms::id, id);
     if (id.IsEmpty()) {
         // mOverlay is a direct child of <overlay> and has no id.
         // Insert it under the root element in the base document.
--- a/dom/src/base/nsDOMClassInfo.cpp
+++ b/dom/src/base/nsDOMClassInfo.cpp
@@ -6812,17 +6812,17 @@ nsElementSH::PostCreate(nsIXPConnectWrap
   if (!doc) {
     // There's no baseclass that cares about this call so we just
     // return here.
 
     return NS_OK;
   }
 
   // See if we have a frame.
-  nsIPresShell *shell = doc->GetShellAt(0);
+  nsIPresShell *shell = doc->GetPrimaryShell();
 
   if (!shell) {
     return NS_OK;
   }
 
   nsIFrame* frame = shell->GetPrimaryFrameFor(content);
 
   if (frame) {
--- a/dom/src/base/nsFocusController.cpp
+++ b/dom/src/base/nsFocusController.cpp
@@ -282,17 +282,17 @@ nsFocusController::MoveFocus(PRBool aFor
     return NS_OK;
 
 
   // Obtain a presentation context
   PRInt32 count = doc->GetNumberOfShells();
   if (count == 0)
     return NS_OK;
 
-  nsIPresShell *shell = doc->GetShellAt(0);
+  nsIPresShell *shell = doc->GetPrimaryShell();
   if (!shell)
     return NS_OK;
 
   // Make sure frames have been constructed before shifting focus, bug 273092.
   shell->FlushPendingNotifications(Flush_Frames);
 
   // Retrieve the context
   nsCOMPtr<nsPresContext> presContext = shell->GetPresContext();
--- a/dom/src/base/nsGlobalWindow.cpp
+++ b/dom/src/base/nsGlobalWindow.cpp
@@ -5466,17 +5466,17 @@ nsGlobalWindow::DispatchEvent(nsIDOMEven
 {
   FORWARD_TO_INNER(DispatchEvent, (aEvent, _retval), NS_OK);
 
   if (!mDoc) {
     return NS_ERROR_FAILURE;
   }
 
   // Obtain a presentation shell
-  nsIPresShell *shell = mDoc->GetShellAt(0);
+  nsIPresShell *shell = mDoc->GetPrimaryShell();
   nsCOMPtr<nsPresContext> presContext;
   if (shell) {
     // Retrieve the context
     presContext = shell->GetPresContext();
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =
@@ -7440,17 +7440,17 @@ nsGlobalWindow::RestoreWindowState(nsISu
     nsCOMPtr<nsIContent> focusedContent = do_QueryInterface(focusedElement);
 
     if (focusedContent) {
       // We don't bother checking whether the element or frame is focusable.
       // If it was focusable when we stored the presentation, it must be
       // focusable now.
       nsIDocument *doc = focusedContent->GetCurrentDoc();
       if (doc) {
-        nsIPresShell *shell = doc->GetShellAt(0);
+        nsIPresShell *shell = doc->GetPrimaryShell();
         if (shell) {
           nsPresContext *pc = shell->GetPresContext();
           if (pc) {
             pc->EventStateManager()->SetContentState(focusedContent,
                                                      NS_EVENT_STATE_FOCUS);
             didFocusContent = PR_TRUE;
           }
         }
--- a/dom/src/base/nsHistory.cpp
+++ b/dom/src/base/nsHistory.cpp
@@ -288,17 +288,17 @@ nsHistory::Go()
       // trick to work around gecko reflow bugs, and this should have
       // the same effect.
 
       nsCOMPtr<nsIDocument> doc =
         do_QueryInterface(window->GetExtantDocument());
 
       nsIPresShell *shell;
       nsPresContext *pcx;
-      if (doc && (shell = doc->GetShellAt(0)) &&
+      if (doc && (shell = doc->GetPrimaryShell()) &&
           (pcx = shell->GetPresContext())) {
         pcx->ClearStyleDataAndReflow();
       }
 
       return NS_OK;
     }
   }
 
--- a/dom/src/base/nsLocation.cpp
+++ b/dom/src/base/nsLocation.cpp
@@ -888,17 +888,17 @@ nsLocation::Reload()
     // of reloading the page, just clear style data and reflow the
     // page since some sites may use this trick to work around gecko
     // reflow bugs, and this should have the same effect.
 
     nsCOMPtr<nsIDocument> doc(do_QueryInterface(window->GetExtantDocument()));
 
     nsIPresShell *shell;
     nsPresContext *pcx;
-    if (doc && (shell = doc->GetShellAt(0)) &&
+    if (doc && (shell = doc->GetPrimaryShell()) &&
         (pcx = shell->GetPresContext())) {
       pcx->ClearStyleDataAndReflow();
     }
 
     return NS_OK;
   }
 
   PRBool force_get = PR_FALSE;
--- a/editor/libeditor/text/nsEditorEventListeners.cpp
+++ b/editor/libeditor/text/nsEditorEventListeners.cpp
@@ -1009,17 +1009,17 @@ IsTargetFocused(nsIDOMEventTarget* aTarg
   if (content)
     doc = content->GetDocument();
   else
     doc = do_QueryInterface(aTarget);
 
   if (!doc)
     return PR_FALSE;
 
-  nsIPresShell *shell = doc->GetShellAt(0);
+  nsIPresShell *shell = doc->GetPrimaryShell();
   if (!shell)
     return PR_FALSE;
 
   nsPresContext *presContext = shell->GetPresContext();
   if (!presContext)
     return PR_FALSE;
 
   nsCOMPtr<nsIContent> focusedContent;
--- a/embedding/browser/gtk/src/EmbedContextMenuInfo.cpp
+++ b/embedding/browser/gtk/src/EmbedContextMenuInfo.cpp
@@ -156,17 +156,17 @@ EmbedContextMenuInfo::GetFormControlType
     if (!NS_SUCCEEDED(rv) || !domDoc) {
       return NS_OK;
     }
     mEventNode = eventNode;
     mCtxDocument = domDoc;
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(mCtxDocument);
     if (!doc)
       return NS_OK;
-    nsIPresShell *presShell = doc->GetShellAt(0);
+    nsIPresShell *presShell = doc->GetPrimaryShell();
     if (!presShell)
       return NS_OK;
     nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
 	nsIFrame* frame = nsnull;
 #if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
 #ifdef MOZILLA_1_8_BRANCH
     presShell->GetPrimaryFrameFor(tgContent, &frame);
 #else
@@ -590,17 +590,17 @@ EmbedContextMenuInfo::UpdateContextData(
     if (DMode.EqualsLiteral("on")) {
       mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
       mEmbedCtxType |= GTK_MOZ_EMBED_CTX_RICHEDIT;
     }
   }
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(mCtxDocument);
   if (!doc)
     return NS_OK;
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   if (!presShell)
     return NS_OK;
   nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
   nsIFrame* frame = nsnull;
 #if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
   if (mEmbedCtxType & GTK_MOZ_EMBED_CTX_RICHEDIT)
     frame = presShell->GetRootFrame();
   else {
--- a/embedding/browser/gtk/src/EmbedEventListener.cpp
+++ b/embedding/browser/gtk/src/EmbedEventListener.cpp
@@ -651,17 +651,17 @@ EmbedEventListener::HandleSelection(nsID
   rv = eventNode->GetOwnerDocument(getter_AddRefs(domDoc));
   if (NS_FAILED(rv))
     return rv;
 
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &rv);
   if (NS_FAILED(rv) || !doc)
     return NS_ERROR_FAILURE;
 
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
 
   /* Gets nsISelectionController interface for the current context */
   mCurSelCon = do_QueryInterface(presShell);
   if (!mCurSelCon)
     return NS_ERROR_FAILURE;
 
   /* Gets event type */
   nsString eventType;
--- a/embedding/components/find/src/nsFind.cpp
+++ b/embedding/components/find/src/nsFind.cpp
@@ -367,17 +367,17 @@ nsFindContentIterator::MaybeSetupInnerIt
 }
 
 void
 nsFindContentIterator::SetupInnerIterator(nsIContent* aContent)
 {
   NS_ASSERTION(aContent && !aContent->IsNativeAnonymous(), "invalid call");
 
   nsIDocument* doc = aContent->GetDocument();
-  nsIPresShell* shell = doc ? doc->GetShellAt(0) : nsnull;
+  nsIPresShell* shell = doc ? doc->GetPrimaryShell() : nsnull;
   if (!shell)
     return;
 
   nsIFrame* frame = shell->GetPrimaryFrameFor(aContent);
   if (!frame)
     return;
 
   nsITextControlFrame* tcFrame = nsnull;
@@ -825,17 +825,17 @@ PRBool nsFind::IsVisibleNode(nsIDOMNode 
   nsCOMPtr<nsIContent> content(do_QueryInterface(aDOMNode));
   if (!content)
     return PR_FALSE;
 
   nsCOMPtr<nsIDocument> doc = content->GetDocument();
   if (!doc)
     return PR_FALSE;
 
-  nsIPresShell *presShell = doc->GetShellAt(0);
+  nsIPresShell *presShell = doc->GetPrimaryShell();
   if (!presShell)
     return PR_FALSE;
 
   nsIFrame *frame = presShell->GetPrimaryFrameFor(content);
   if (!frame) {
     // No frame! Not visible then.
     return PR_FALSE;
   }
--- a/embedding/components/find/src/nsWebBrowserFind.cpp
+++ b/embedding/components/find/src/nsWebBrowserFind.cpp
@@ -380,17 +380,17 @@ FocusElementButNotDocument(nsIDocument* 
   focusController->GetFocusedElement(getter_AddRefs(oldFocusedElement));
   nsCOMPtr<nsIContent> oldFocusedContent =
     do_QueryInterface(oldFocusedElement);
 
   // Notify focus controller of new focus for this document
   nsCOMPtr<nsIDOMElement> newFocusedElement(do_QueryInterface(aContent));
   focusController->SetFocusedElement(newFocusedElement);
 
-  nsIPresShell* presShell = aDocument->GetShellAt(0);
+  nsIPresShell* presShell = aDocument->GetPrimaryShell();
   nsIEventStateManager* esm = presShell->GetPresContext()->EventStateManager();
 
   // Temporarily set esm::mCurrentFocus so that esm::GetContentState() tells 
   // layout system to show focus on this element. 
   esm->SetFocusedContent(aContent);  // Reset back to null at the end.
   aDocument->BeginUpdate(UPDATE_CONTENT_STATE);
   aDocument->ContentStatesChanged(oldFocusedContent, aContent, 
                                   NS_EVENT_STATE_FOCUS);
@@ -405,17 +405,17 @@ FocusElementButNotDocument(nsIDocument* 
 void nsWebBrowserFind::SetSelectionAndScroll(nsIDOMWindow* aWindow,
                                              nsIDOMRange*  aRange)
 {
   nsCOMPtr<nsIDOMDocument> domDoc;    
   aWindow->GetDocument(getter_AddRefs(domDoc));
   if (!domDoc) return;
 
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
-  nsIPresShell* presShell = doc->GetShellAt(0);
+  nsIPresShell* presShell = doc->GetPrimaryShell();
   if (!presShell) return;
 
   // since the match could be an anonymous textnode inside a
   // <textarea> or text <input>, we need to get the outer frame
   nsIFrame *frame = nsnull;
   nsITextControlFrame *tcFrame = nsnull;
   nsCOMPtr<nsIDOMNode> node;
   aRange->GetStartContainer(getter_AddRefs(node));
@@ -829,17 +829,17 @@ nsWebBrowserFind::GetFrameSelection(nsID
 {
     *aSel = nsnull;
 
     nsCOMPtr<nsIDOMDocument> domDoc;    
     aWindow->GetDocument(getter_AddRefs(domDoc));
     if (!domDoc) return;
 
     nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
-    nsIPresShell* presShell = doc->GetShellAt(0);
+    nsIPresShell* presShell = doc->GetPrimaryShell();
     if (!presShell) return;
 
     // text input controls have their independent selection controllers
     // that we must use when they have focus.
     nsPresContext *presContext = presShell->GetPresContext();
 
     nsIFrame *frame = nsnull;
     presContext->EventStateManager()->GetFocusedFrame(&frame);
--- a/extensions/access-builtin/accessproxy/nsAccessProxy.cpp
+++ b/extensions/access-builtin/accessproxy/nsAccessProxy.cpp
@@ -136,17 +136,17 @@ NS_IMETHODIMP nsAccessProxy::HandleEvent
   // get the Document and PresShell
   nsCOMPtr<nsIDOMDocument> domDoc;
   nsIPresShell *presShell = nsnull;
   nsCOMPtr<nsIDocument> doc;
   domNode->GetOwnerDocument(getter_AddRefs(domDoc));
   if (domDoc) {
     doc = do_QueryInterface(domDoc);
     if (doc && doc->GetNumberOfShells()>0) {
-      presShell = doc->GetShellAt(0);
+      presShell = doc->GetPrimaryShell();
     }
   }
   //return  NS_OK;
   /*
   if (presShell && eventNameStr.EqualsLiteral("click")) {
     nsCOMPtr<nsISelection> domSelection;
     presShell->FrameSelection()->GetSelection(nsISelectionController::SELECTION_NORMAL,
                             getter_AddRefs(domSelection));
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -5871,17 +5871,17 @@ StopPluginInstance(PresShell *aShell, ns
     return;
 
   objectFrame->StopPlugin();
 }
 
 PR_STATIC_CALLBACK(PRBool)
 FreezeSubDocument(nsIDocument *aDocument, void *aData)
 {
-  nsIPresShell *shell = aDocument->GetShellAt(0);
+  nsIPresShell *shell = aDocument->GetPrimaryShell();
   if (shell)
     shell->Freeze();
 
   return PR_TRUE;
 }
 
 void
 PresShell::Freeze()
@@ -5911,17 +5911,17 @@ StartPluginInstance(PresShell *aShell, n
 
   nsCOMPtr<nsIPluginInstance> inst;
   objlc->EnsureInstantiation(getter_AddRefs(inst));
 }
 
 PR_STATIC_CALLBACK(PRBool)
 ThawSubDocument(nsIDocument *aDocument, void *aData)
 {
-  nsIPresShell *shell = aDocument->GetShellAt(0);
+  nsIPresShell *shell = aDocument->GetPrimaryShell();
   if (shell)
     shell->Thaw();
 
   return PR_TRUE;
 }
 
 void
 PresShell::Thaw()
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -300,17 +300,17 @@ nsTextInputListener::NotifySelectionChan
                                 nsISelectionListener::SELECTALL_REASON)))
   {
     nsIContent* content = mFrame->GetContent();
     if (content) 
     {
       nsCOMPtr<nsIDocument> doc = content->GetDocument();
       if (doc) 
       {
-        nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
+        nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
         if (presShell) 
         {
           nsEventStatus status = nsEventStatus_eIgnore;
           nsEvent event(PR_TRUE, NS_FORM_SELECTED);
 
           presShell->HandleEventWithTarget(&event, mFrame, content, &status);
         }
       }
--- a/layout/generic/nsImageMap.cpp
+++ b/layout/generic/nsImageMap.cpp
@@ -1002,17 +1002,17 @@ nsImageMap::ChangeFocus(nsIDOMEvent* aEv
         if (areaContent) {
           if (areaContent.get() == targetContent.get()) {
             //Set or Remove internal focus
             area->HasFocus(aFocus);
             //Now invalidate the rect
             nsCOMPtr<nsIDocument> doc = targetContent->GetDocument();
             //This check is necessary to see if we're still attached to the doc
             if (doc) {
-              nsIPresShell *presShell = doc->GetShellAt(0);
+              nsIPresShell *presShell = doc->GetPrimaryShell();
               if (presShell) {
                 nsIFrame* imgFrame = presShell->GetPrimaryFrameFor(targetContent);
                 if (imgFrame) {
                   nsPresContext *presContext = presShell->GetPresContext();
                   if (presContext) {
                     nsRect dmgRect;
                     area->GetRect(presContext, dmgRect);
                     imgFrame->Invalidate(dmgRect, PR_TRUE);
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -976,17 +976,17 @@ nsObjectFrame::PrintPlugin(nsIRenderingC
 
   // first, we need to get the document
   nsIDocument* doc = mContent->GetCurrentDoc();
   if (!doc)
     return;
 
   // now we need to get the shell for the screen
   // XXX assuming that the shell at zero will always be the screen one
-  nsIPresShell *shell = doc->GetShellAt(0);
+  nsIPresShell *shell = doc->GetPrimaryShell();
   if (!shell)
     return;
 
   // then the shell can give us the screen frame for this content node
   nsIFrame* frame = shell->GetPrimaryFrameFor(mContent);
   if (!frame)
     return;
 
--- a/layout/inspector/src/inLayoutUtils.cpp
+++ b/layout/inspector/src/inLayoutUtils.cpp
@@ -103,17 +103,17 @@ inLayoutUtils::GetEventStateManagerFor(n
   aElement->GetOwnerDocument(getter_AddRefs(domDoc));
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
 
   if (!doc) {
     NS_WARNING("Could not get an nsIDocument!");
     return nsnull;
   }
 
-  nsIPresShell *shell = doc->GetShellAt(0);
+  nsIPresShell *shell = doc->GetPrimaryShell();
   NS_ASSERTION(shell, "No pres shell");
 
   return shell->GetPresContext()->EventStateManager();
 }
 
 nsBindingManager* 
 inLayoutUtils::GetBindingManagerFor(nsIDOMNode* aNode)
 {
--- a/layout/printing/nsPrintPreviewListener.cpp
+++ b/layout/printing/nsPrintPreviewListener.cpp
@@ -183,17 +183,17 @@ nsPrintPreviewListener::HandleEvent(nsID
           // Handle tabbing explicitly here since we don't want focus ending up
           // inside the content document, bug 244128.
           nsIDocument* doc = content->GetCurrentDoc();
           NS_ASSERTION(doc, "no document");
 
           nsIDocument* parentDoc = doc->GetParentDocument();
           NS_ASSERTION(parentDoc, "no parent document");
           nsIEventStateManager* esm =
-            parentDoc->GetShellAt(0)->GetPresContext()->EventStateManager();
+            parentDoc->GetPrimaryShell()->GetPresContext()->EventStateManager();
           if (esm) {
             esm->SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
             PRBool forward = (action == eEventAction_Tab);
             esm->ShiftFocus(forward,
                             forward ? nsnull : parentDoc->FindContentForSubDocument(doc));
           }
         }
       }
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -303,17 +303,17 @@ nsComputedDOMStyle::GetPropertyCSSValue(
   NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE);
 
   // Flush _before_ getting the presshell, since that could create a new
   // presshell.  Also note that we want to flush the style on the document
   // we're computing style in, not on the document mContent is in -- the two
   // may be different.
   document->FlushPendingNotifications(Flush_Style);
 
-  nsIPresShell* presShell = document->GetShellAt(0);
+  nsIPresShell* presShell = document->GetPrimaryShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_NOT_AVAILABLE);
 
   mFrame = presShell->GetPrimaryFrameFor(mContent);
   if (!mFrame || mPseudo) {
     // Need to resolve a style context
     mStyleContextHolder =
       nsInspectorCSSUtils::GetStyleContextForContent(mContent,
                                                      mPseudo,
@@ -675,17 +675,17 @@ nsComputedDOMStyle::GetFontFamily(nsIDOM
 {
   nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
   NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
 
   const nsStyleFont* font = GetStyleFont();
 
   nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocumentWeak);
   NS_ASSERTION(doc, "document is required");
-  nsIPresShell* presShell = doc->GetShellAt(0);
+  nsIPresShell* presShell = doc->GetPrimaryShell();
   NS_ASSERTION(presShell, "pres shell is required");
   nsPresContext *presContext = presShell->GetPresContext();
   NS_ASSERTION(presContext, "pres context is required");
 
   const nsString& fontName = font->mFont.name;
   PRUint8 generic = font->mFlags & NS_STYLE_FONT_FACE_MASK;
   if (generic == kGenericFont_NONE && !font->mFont.systemFont) { 
     const nsFont* defaultFont =
--- a/layout/style/nsInspectorCSSUtils.cpp
+++ b/layout/style/nsInspectorCSSUtils.cpp
@@ -162,17 +162,17 @@ NS_IMETHODIMP
 nsInspectorCSSUtils::GetRuleNodeForContent(nsIContent* aContent,
                                            nsRuleNode** aRuleNode)
 {
     *aRuleNode = nsnull;
 
     nsIDocument* doc = aContent->GetDocument();
     NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
 
-    nsIPresShell *presShell = doc->GetShellAt(0);
+    nsIPresShell *presShell = doc->GetPrimaryShell();
     NS_ENSURE_TRUE(presShell, NS_ERROR_UNEXPECTED);
 
     nsRefPtr<nsStyleContext> sContext =
         GetStyleContextForContent(aContent, nsnull, presShell);
     *aRuleNode = sContext->GetRuleNode();
     return NS_OK;
 }
 
--- a/layout/xul/base/src/nsBoxObject.cpp
+++ b/layout/xul/base/src/nsBoxObject.cpp
@@ -152,17 +152,17 @@ nsBoxObject::GetPresShell(PRBool aFlushL
   if (!doc) {
     return nsnull;
   }
 
   if (aFlushLayout) {
     doc->FlushPendingNotifications(Flush_Layout);
   }
 
-  return doc->GetShellAt(0);
+  return doc->GetPrimaryShell();
 }
 
 nsresult 
 nsBoxObject::GetOffsetRect(nsRect& aRect)
 {
   aRect.x = aRect.y = 0;
   aRect.Empty();
  
--- a/layout/xul/base/src/nsImageBoxFrame.cpp
+++ b/layout/xul/base/src/nsImageBoxFrame.cpp
@@ -109,17 +109,17 @@ private:
 NS_IMETHODIMP
 nsImageBoxFrameEvent::Run()
 {
   nsIDocument* doc = mContent->GetOwnerDoc();
   if (!doc) {
     return NS_OK;
   }
 
-  nsIPresShell *pres_shell = doc->GetShellAt(0);
+  nsIPresShell *pres_shell = doc->GetPrimaryShell();
   if (!pres_shell) {
     return NS_OK;
   }
 
   nsCOMPtr<nsPresContext> pres_context = pres_shell->GetPresContext();
   if (!pres_context) {
     return NS_OK;
   }
--- a/layout/xul/base/src/nsMenuBarFrame.cpp
+++ b/layout/xul/base/src/nsMenuBarFrame.cpp
@@ -213,17 +213,17 @@ nsMenuBarFrame::SetActive(PRBool aActive
 
     nsCOMPtr<nsIDOMDocument> domDoc;
     nsCOMPtr<nsIDocument> focusedDoc;
     windowInternal->GetDocument(getter_AddRefs(domDoc));
     focusedDoc = do_QueryInterface(domDoc);
     if (!focusedDoc)
       break;
 
-    presShell = focusedDoc->GetShellAt(0);
+    presShell = focusedDoc->GetPrimaryShell();
     nsCOMPtr<nsISelectionController> selCon(do_QueryInterface(presShell));
     // there is no selection controller for full page plugins
     if (!selCon)
       break;
 
     if (mIsActive) {// store whether caret was visible so that we can restore that state when menu is closed
       PRBool isCaretVisible;
       selCon->GetCaretEnabled(&isCaretVisible);
--- a/layout/xul/base/src/nsMenuPopupFrame.cpp
+++ b/layout/xul/base/src/nsMenuPopupFrame.cpp
@@ -373,17 +373,17 @@ nsMenuPopupFrame::AdjustClientXYForNeste
     inPopupDoc->TrustedGetPopupNode(getter_AddRefs(targetNode));
 
   //NS_ASSERTION(targetNode, "no popup/tooltip node on document!");
   nsCOMPtr<nsIContent> targetAsContent ( do_QueryInterface(targetNode) );
   nsIWidget* targetDocumentWidget = nsnull;
   if ( targetAsContent ) {
     nsCOMPtr<nsIDocument> targetDocument = targetAsContent->GetDocument();
     if (targetDocument) {
-      nsIPresShell *shell = targetDocument->GetShellAt(0);
+      nsIPresShell *shell = targetDocument->GetPrimaryShell();
       if ( shell ) {
         // We might be inside a popup widget. If so, we need to use that widget and
         // not the root view's widget.
         nsIFrame* targetFrame = shell->GetPrimaryFrameFor(targetAsContent);
         nsIView* parentView = nsnull;
         if (targetFrame) {
           GetRootViewForPopup(targetFrame, PR_TRUE, &parentView);
           if (parentView) {
--- a/layout/xul/base/src/nsXULTooltipListener.cpp
+++ b/layout/xul/base/src/nsXULTooltipListener.cpp
@@ -584,17 +584,17 @@ nsXULTooltipListener::FindTooltip(nsICon
   if (closed) {
     return NS_OK;
   }
 
   nsAutoString tooltipText;
   aTarget->GetAttr(kNameSpaceID_None, nsGkAtoms::tooltiptext, tooltipText);
   if (!tooltipText.IsEmpty()) {
     // specifying tooltiptext means we will always use the default tooltip
-    nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetShellAt(0));
+    nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetPrimaryShell());
     NS_ENSURE_STATE(rootBox);
     *aTooltip = rootBox->GetDefaultTooltip();
     if (*aTooltip) {
       NS_ADDREF(*aTooltip);
       (*aTooltip)->SetAttr(kNameSpaceID_None, nsGkAtoms::label, tooltipText, PR_TRUE);
     }
     return NS_OK;
   }
@@ -626,17 +626,17 @@ nsXULTooltipListener::FindTooltip(nsICon
       CallQueryInterface(tooltipEl, aTooltip);
       return NS_OK;
     }
   }
 
 #ifdef MOZ_XUL
   // titletips should just use the default tooltip
   if (mIsSourceTree && mNeedTitletip) {
-    nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetShellAt(0));
+    nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetPrimaryShell());
     NS_ENSURE_STATE(rootBox);
     NS_IF_ADDREF(*aTooltip = rootBox->GetDefaultTooltip());
   }
 #endif
 
   return NS_OK;
 }
 
@@ -650,17 +650,17 @@ nsXULTooltipListener::GetTooltipFor(nsIC
   if (NS_FAILED(rv) || !tooltip) {
     return rv;
   }
 
   // Submenus can't be used as tooltips, see bug 288763.
   nsIContent* parent = tooltip->GetParent();
   if (parent) {
     nsIDocument* doc = parent->GetCurrentDoc();
-    nsIPresShell* presShell = doc ? doc->GetShellAt(0) : nsnull;
+    nsIPresShell* presShell = doc ? doc->GetPrimaryShell() : nsnull;
     nsIFrame* frame = presShell ? presShell->GetPrimaryFrameFor(parent) : nsnull;
     if (frame) {
       nsIMenuFrame* menu = nsnull;
       CallQueryInterface(frame, &menu);
       NS_ENSURE_FALSE(menu, NS_ERROR_FAILURE);
     }
   }
 
--- a/layout/xul/base/src/tree/src/nsTreeColumns.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeColumns.cpp
@@ -101,17 +101,17 @@ nsTreeColumn::GetFrame(nsIFrame* aBodyFr
 
 nsIFrame*
 nsTreeColumn::GetFrame()
 {
   nsCOMPtr<nsIDocument> document = mContent->GetDocument();
   if (!document)
     return nsnull;
 
-  nsIPresShell *shell = document->GetShellAt(0);
+  nsIPresShell *shell = document->GetPrimaryShell();
   if (!shell)
     return nsnull;
 
   return shell->GetPrimaryFrameFor(mContent);
 }
 
 nsresult
 nsTreeColumn::GetRect(nsIFrame* aBodyFrame, nscoord aY, nscoord aHeight, nsRect* aResult)
@@ -584,17 +584,17 @@ nsTreeColumns::EnsureColumns()
     nsCOMPtr<nsIContent> treeContent = do_QueryInterface(treeElement);
 
     nsCOMPtr<nsIContent> colsContent;
     nsTreeUtils::GetDescendantChild(treeContent, nsGkAtoms::treecols, getter_AddRefs(colsContent));
     if (!colsContent)
       return;
 
     nsCOMPtr<nsIDocument> document = treeContent->GetDocument();
-    nsIPresShell *shell = document->GetShellAt(0);
+    nsIPresShell *shell = document->GetPrimaryShell();
     if (!shell)
       return;
 
     nsCOMPtr<nsIContent> colContent;
     nsTreeUtils::GetDescendantChild(colsContent, nsGkAtoms::treecol, getter_AddRefs(colContent));
     if (!colContent)
       return;
 
--- a/layout/xul/base/src/tree/src/nsTreeSelection.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeSelection.cpp
@@ -823,17 +823,17 @@ nsTreeSelection::FireOnSelectHandler()
   nsCOMPtr<nsIContent> content(do_QueryInterface(elt));
   nsCOMPtr<nsIDocument> document = content->GetDocument();
   
   // we might be firing on a delay, so it's possible in rare cases that
   // the document may have been destroyed by the time it fires
   if (!document)
     return NS_OK;
 
-  nsIPresShell *shell = document->GetShellAt(0);
+  nsIPresShell *shell = document->GetPrimaryShell();
   if (shell) {
     // Retrieve the context in which our DOM event will fire.
     nsCOMPtr<nsPresContext> aPresContext = shell->GetPresContext();
 
     nsEventStatus status = nsEventStatus_eIgnore;
     nsEvent event(PR_TRUE, NS_FORM_SELECTED);
 
     nsEventDispatcher::Dispatch(content, aPresContext, &event, nsnull, &status);
--- a/modules/plugin/base/src/nsPluginHostImpl.cpp
+++ b/modules/plugin/base/src/nsPluginHostImpl.cpp
@@ -310,17 +310,17 @@ NS_IMETHODIMP nsPluginDocReframeEvent::R
   PRUint32 c;
   mDocs->Count(&c);
 
   // for each document (which previously had a running instance), tell
   // the frame constructor to rebuild
   for (PRUint32 i = 0; i < c; i++) {
     nsCOMPtr<nsIDocument> doc (do_QueryElementAt(mDocs, i));
     if (doc) {
-      nsIPresShell *shell = doc->GetShellAt(0);
+      nsIPresShell *shell = doc->GetPrimaryShell();
 
       // if this document has a presentation shell, then it has frames and can be reframed
       if (shell) {
         /**
          * A reframe will cause a fresh object frame, instance owner, and instance
          * to be created. Reframing of the entire document is necessary as we may have
          * recently found new plugins and we want a shot at trying to use them instead
          * of leaving alternate renderings.
--- a/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
@@ -1418,17 +1418,17 @@ nsAutoCompleteController::GetPopupWidget
 
   nsCOMPtr<nsIDOMDocument> domDoc;
   popup->GetOwnerDocument(getter_AddRefs(domDoc));
   NS_ENSURE_TRUE(domDoc, nsnull);
 
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
   NS_ENSURE_TRUE(doc, nsnull);
 
-  nsIPresShell* presShell = doc->GetShellAt(0);
+  nsIPresShell* presShell = doc->GetPrimaryShell();
   NS_ENSURE_TRUE(presShell, nsnull);
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(popup);
   nsIFrame* frame = presShell->GetPrimaryFrameFor(content);
   NS_ENSURE_TRUE(frame, nsnull);
 
   return frame->GetWindow();
 }
--- a/toolkit/components/satchel/src/nsFormFillController.cpp
+++ b/toolkit/components/satchel/src/nsFormFillController.cpp
@@ -130,17 +130,17 @@ GetScreenOrigin(nsIDOMElement* aElement)
 {
   nsRect rect(0,0,0,0);
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
   nsCOMPtr<nsIDocument> doc = content->GetDocument();
 
   if (doc) {
     // Get Presentation shell 0
-    nsIPresShell* presShell = doc->GetShellAt(0);
+    nsIPresShell* presShell = doc->GetPrimaryShell();
 
     if (presShell) {
       nsIFrame* frame = presShell->GetPrimaryFrameFor(content);
       if (!frame)
         return rect;
       rect = frame->GetScreenRectExternal();
     }
   }
--- a/widget/src/beos/nsDragService.cpp
+++ b/widget/src/beos/nsDragService.cpp
@@ -86,17 +86,17 @@ GetPrimaryFrameFor(nsIDOMNode *aDOMNode)
 {
     nsCOMPtr<nsIContent> aContent = do_QueryInterface(aDOMNode);
     if (nsnull == aContent)
         return nsnull;
 
     nsIDocument* doc = aContent->GetCurrentDoc();
     if (nsnull == doc)
         return nsnull;
-    nsIPresShell* presShell = doc->GetShellAt(0);
+    nsIPresShell* presShell = doc->GetPrimaryShell();
     if ( nsnull == presShell) 
         return nsnull;
     return presShell->GetPrimaryFrameFor(aContent);
 }
 
 static bool 
 IsInternalDrag(BMessage * aMsg)
 {
--- a/widget/src/mac/nsDragService.cpp
+++ b/widget/src/mac/nsDragService.cpp
@@ -92,17 +92,17 @@
 // Get the primary frame for a content node in the current document.
 //
 static nsIFrame*
 GetPrimaryFrameFor(nsIContent* aContent)
 {
   nsIFrame* result = nsnull;
   nsIDocument* doc = aContent->GetCurrentDoc();
   if (doc) {
-    nsIPresShell* presShell = doc->GetShellAt(0);
+    nsIPresShell* presShell = doc->GetPrimaryShell();
     if (presShell) {
       result = presShell->GetPrimaryFrameFor(aContent);
     }
   }
   return result;
 }
 
 static const PRUint32 kPrivateFlavorMask = 0xffff0000;
--- a/widget/src/xpwidgets/nsBaseDragService.cpp
+++ b/widget/src/xpwidgets/nsBaseDragService.cpp
@@ -226,17 +226,17 @@ nsBaseDragService::InvokeDragSession(nsI
   // capture. However, this gets in the way of determining drag
   // feedback for things like trees because the event coordinates
   // are in the wrong coord system. Turn off mouse capture in
   // the associated view manager.
   nsCOMPtr<nsIContent> contentNode = do_QueryInterface(aDOMNode);
   if (contentNode) {
     nsIDocument* doc = contentNode->GetCurrentDoc();
     if (doc) {
-      nsIPresShell* presShell = doc->GetShellAt(0);
+      nsIPresShell* presShell = doc->GetPrimaryShell();
       if (presShell) {
         nsIViewManager* vm = presShell->GetViewManager();
         if (vm) {
           PRBool notUsed;
           vm->GrabMouseEvents(nsnull, notUsed);
         }
       }
     }
@@ -351,17 +351,17 @@ nsBaseDragService::EndDragSession(PRBool
 }
 
 NS_IMETHODIMP
 nsBaseDragService::FireDragEventAtSource(PRUint32 aMsg)
 {
   if (mSourceNode) {
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(mSourceDocument);
     if (doc) {
-      nsCOMPtr<nsIPresShell> presShell = doc->GetShellAt(0);
+      nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
       if (presShell) {
         nsEventStatus status = nsEventStatus_eIgnore;
         nsMouseEvent event(PR_TRUE, aMsg, nsnull, nsMouseEvent::eReal);
 
         nsCOMPtr<nsIContent> content = do_QueryInterface(mSourceNode);
         return presShell->HandleDOMEventWithTarget(content, &event, &status);
       }
     }
@@ -375,17 +375,17 @@ nsBaseDragService::FireDragEventAtSource
 static nsIPresShell*
 GetPresShellForContent(nsIDOMNode* aDOMNode)
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(aDOMNode);
   nsCOMPtr<nsIDocument> document = content->GetCurrentDoc();
   if (document) {
     document->FlushPendingNotifications(Flush_Display);
 
-    return document->GetShellAt(0);
+    return document->GetPrimaryShell();
   }
 
   return nsnull;
 }
 
 nsresult
 nsBaseDragService::DrawDrag(nsIDOMNode* aDOMNode,
                             nsIScriptableRegion* aRegion,