Bug 538362 - rename nsIDocument::GetPrimaryShell to nsIDocument::GetShell. r=smaug
authorMs2ger@gmail.com
Fri, 25 Jun 2010 15:59:57 +0200
changeset 46225 0dd4e086cea5368862bf2a337d518114944e905f
parent 46224 2f3c4cbb8c4f65e0ee029352e29e0803c7c0678c
child 46226 5719e5214cc66702cba25290b31f5194bc785048
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs538362
milestone1.9.3a6pre
Bug 538362 - rename nsIDocument::GetPrimaryShell to nsIDocument::GetShell. r=smaug
accessible/src/base/nsAccDocManager.cpp
accessible/src/base/nsAccDocManager.h
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessible.cpp
accessible/src/base/nsCaretAccessible.cpp
accessible/src/base/nsCoreUtils.cpp
accessible/src/base/nsCoreUtils.h
accessible/src/base/nsDocAccessible.cpp
chrome/src/nsChromeRegistry.cpp
content/base/public/nsIDocument.h
content/base/src/nsContentSink.cpp
content/base/src/nsContentUtils.cpp
content/base/src/nsCopySupport.cpp
content/base/src/nsDocument.cpp
content/base/src/nsFrameLoader.cpp
content/base/src/nsGenericElement.cpp
content/base/src/nsImageLoadingContent.cpp
content/base/src/nsObjectLoadingContent.cpp
content/canvas/src/nsCanvasRenderingContext2D.cpp
content/events/src/nsEventListenerManager.cpp
content/events/src/nsEventStateManager.cpp
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsHTMLAnchorElement.cpp
content/html/content/src/nsHTMLButtonElement.cpp
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsTextEditorState.cpp
content/html/document/src/nsHTMLDocument.cpp
content/html/document/src/nsImageDocument.cpp
content/html/document/src/nsMediaDocument.cpp
content/html/document/src/nsPluginDocument.cpp
content/mathml/content/src/nsMathMLElement.cpp
content/smil/nsSMILAnimationController.cpp
content/smil/nsSMILCSSProperty.cpp
content/smil/nsSMILCSSValueType.cpp
content/smil/nsSMILMappedAttribute.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGSVGElement.cpp
content/svg/content/src/nsSVGUseElement.cpp
content/xbl/src/nsBindingManager.cpp
content/xbl/src/nsXBLResourceLoader.cpp
content/xbl/src/nsXBLService.cpp
content/xml/document/src/nsXMLContentSink.cpp
content/xml/document/src/nsXMLPrettyPrinter.cpp
content/xtf/src/nsXTFElementWrapper.cpp
content/xul/content/src/nsXULElement.cpp
content/xul/content/src/nsXULPopupListener.cpp
content/xul/document/src/nsXULCommandDispatcher.cpp
content/xul/document/src/nsXULDocument.cpp
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMWindowUtils.cpp
dom/base/nsFocusManager.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsHistory.cpp
dom/base/nsLocation.cpp
embedding/browser/gtk/src/EmbedContextMenuInfo.cpp
embedding/components/find/src/nsWebBrowserFind.cpp
extensions/access-builtin/accessproxy/nsAccessProxy.cpp
extensions/widgetutils/src/nsWidgetUtils.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsPresShell.cpp
layout/inspector/src/inDOMUtils.cpp
layout/inspector/src/inLayoutUtils.cpp
layout/printing/nsPrintEngine.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsHTMLStyleSheet.cpp
layout/style/nsStyleAnimation.cpp
layout/svg/base/src/nsSVGEffects.cpp
layout/svg/base/src/nsSVGUtils.cpp
layout/xul/base/src/nsBoxObject.cpp
layout/xul/base/src/nsImageBoxFrame.cpp
layout/xul/base/src/nsMenuPopupFrame.cpp
layout/xul/base/src/nsXULPopupManager.cpp
layout/xul/base/src/nsXULTooltipListener.cpp
modules/plugin/base/src/nsPluginHost.cpp
parser/html/nsHtml5TreeBuilderCppSupplement.h
widget/src/xpwidgets/nsBaseDragService.cpp
--- a/accessible/src/base/nsAccDocManager.cpp
+++ b/accessible/src/base/nsAccDocManager.cpp
@@ -434,17 +434,17 @@ nsDocAccessible*
 nsAccDocManager::CreateDocOrRootAccessible(nsIDocument *aDocument)
 {
   // Ignore temporary, hiding and svg resource documents.
   if (aDocument->IsInitialDocument() || !aDocument->IsVisible() ||
       aDocument->GetDisplayDocument())
     return nsnull;
 
   // Ignore documents without presshell.
-  nsIPresShell *presShell = aDocument->GetPrimaryShell();
+  nsIPresShell *presShell = aDocument->GetShell();
   if (!presShell)
     return nsnull;
 
   // Do not create document accessible until role content is loaded, otherwise
   // we get accessible document with wrong role.
   nsIContent *rootElm = nsCoreUtils::GetRoleContent(aDocument);
   if (!rootElm)
     return nsnull;
--- a/accessible/src/base/nsAccDocManager.h
+++ b/accessible/src/base/nsAccDocManager.h
@@ -254,17 +254,17 @@ private:
   }                                                                            \
   printf("doc state: %s", docState);                                           \
   printf(", %sinitial", aDocument->IsInitialDocument() ? "" : "not ");         \
   printf(", %sshowing", aDocument->IsShowing() ? "" : "not ");                 \
   printf(", %svisible", aDocument->IsVisible() ? "" : "not ");                 \
   printf(", %sactive", aDocument->IsActive() ? "" : "not ");
 
 #define NS_LOG_ACCDOC_DOCPRESSHELL(aDocument)                                  \
-  nsIPresShell *ps = aDocument->GetPrimaryShell();                             \
+  nsIPresShell *ps = aDocument->GetShell();                                    \
   printf("presshell: %p", ps);                                                 \
   nsIScrollableFrame *sf = ps ?                                                \
     ps->GetRootScrollFrameAsScrollableExternal() : nsnull;                     \
   printf(", root scroll frame: %p", sf);
 
 #define NS_LOG_ACCDOC_DOCLOADGROUP(aDocument)                                  \
   nsCOMPtr<nsILoadGroup> loadGroup = aDocument->GetDocumentLoadGroup();        \
   printf("load group: %p", loadGroup);
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -198,21 +198,22 @@ nsAccessibilityService::GetInfo(nsIFrame
   nsIContent* content = aFrame->GetContent();
   if (!content)
     return NS_ERROR_FAILURE;
 
   nsIDocument* document = content->GetOwnerDoc();
   if (!document)
     return NS_ERROR_FAILURE;
 
-  NS_ASSERTION(document->GetPrimaryShell(),"Error no shells!");
+  NS_ASSERTION(document->GetShell(),
+               "Error: aFrame's document doesn't have a PresShell!");
 
   // do_GetWR only works into a |nsCOMPtr| :-(
   nsCOMPtr<nsIWeakReference> weakShell =
-    do_GetWeakReference(document->GetPrimaryShell());
+    do_GetWeakReference(document->GetShell());
 
   weakShell.forget(aShell);
   NS_IF_ADDREF(*aContent = content);
 
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1093,17 +1094,17 @@ nsAccessibilityService::GetContainerAcce
 {
   if (!aNode)
     return nsnull;
 
   nsIDocument *document = aNode->GetCurrentDoc();
   if (!document)
     return nsnull;
 
-  nsIPresShell *presShell = document->GetPrimaryShell();
+  nsIPresShell *presShell = document->GetShell();
   if (!presShell)
     return nsnull;
 
   nsINode *currNode = aNode;
   nsCOMPtr<nsIWeakReference> weakShell(do_GetWeakReference(presShell));
 
   nsAccessible *accessible = nsnull;
   while (!accessible && (currNode = currNode->GetNodeParent())) {
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -3003,17 +3003,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->GetPrimaryShell();
+        nsIPresShell* shell = parentDoc->GetShell();
         if (!shell) {
           return PR_FALSE;
         }
         nsIFrame* frame = content->GetPrimaryFrame();
         while (frame != nsnull && !frame->HasView()) {
           frame = frame->GetParent();
         }
 
--- a/accessible/src/base/nsCaretAccessible.cpp
+++ b/accessible/src/base/nsCaretAccessible.cpp
@@ -356,17 +356,17 @@ nsCaretAccessible::GetSelectionControlle
 {
   if (!aContent)
     return nsnull;
 
   nsIDocument *document = aContent->GetOwnerDoc();
   if (!document)
     return nsnull;
 
-  nsIPresShell *presShell = document->GetPrimaryShell();
+  nsIPresShell *presShell = document->GetShell();
   if (!presShell)
     return nsnull;
 
   nsIFrame *frame = aContent->GetPrimaryFrame();
   if (!frame)
     return nsnull;
 
   nsPresContext *presContext = presShell->GetPresContext();
--- a/accessible/src/base/nsCoreUtils.cpp
+++ b/accessible/src/base/nsCoreUtils.cpp
@@ -102,17 +102,17 @@ nsCoreUtils::DispatchClickEvent(nsITreeB
     return;
 
   nsCOMPtr<nsIContent> tcContent(do_QueryInterface(tcElm));
   nsIDocument *document = tcContent->GetCurrentDoc();
   if (!document)
     return;
 
   nsIPresShell *presShell = nsnull;
-  presShell = document->GetPrimaryShell();
+  presShell = document->GetShell();
   if (!presShell)
     return;
 
   // Ensure row is visible.
   aTreeBoxObj->EnsureRowIsVisible(aRowIndex);
 
   // Calculate x and y coordinates.
   PRInt32 x = 0, y = 0, width = 0, height = 0;
@@ -214,17 +214,17 @@ nsCoreUtils::GetAccessKeyFor(nsIContent 
   // nsIEventStateManager::GetRegisteredAccessKey() method.
   if (!aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::accesskey))
     return 0;
 
   nsCOMPtr<nsIDocument> doc = aContent->GetOwnerDoc();
   if (!doc)
     return 0;
 
-  nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
   if (!presShell)
     return 0;
 
   nsPresContext *presContext = presShell->GetPresContext();
   if (!presContext)
     return 0;
 
   nsIEventStateManager *esm = presContext->EventStateManager();
--- a/accessible/src/base/nsCoreUtils.h
+++ b/accessible/src/base/nsCoreUtils.h
@@ -251,17 +251,17 @@ public:
   static PRBool IsCorrectFrameType(nsIFrame* aFrame, nsIAtom* aAtom);
 
   /**
    * Return presShell for the document containing the given DOM node.
    */
   static nsIPresShell *GetPresShellFor(nsINode *aNode)
   {
     nsIDocument *document = aNode->GetOwnerDoc();
-    return document ? document->GetPrimaryShell() : nsnull;
+    return document ? document->GetShell() : nsnull;
   }
   static already_AddRefed<nsIWeakReference> GetWeakShellFor(nsINode *aNode)
   {
     nsCOMPtr<nsIWeakReference> weakShell =
       do_GetWeakReference(GetPresShellFor(aNode));
     return weakShell.forget();
   }
 
--- a/accessible/src/base/nsDocAccessible.cpp
+++ b/accessible/src/base/nsDocAccessible.cpp
@@ -668,17 +668,17 @@ nsDocAccessible::IsDefunct()
 void nsDocAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aRelativeFrame)
 {
   *aRelativeFrame = GetFrame();
 
   nsIDocument *document = mDocument;
   nsIDocument *parentDoc = nsnull;
 
   while (document) {
-    nsIPresShell *presShell = document->GetPrimaryShell();
+    nsIPresShell *presShell = document->GetShell();
     if (!presShell) {
       return;
     }
 
     nsRect scrollPort;
     nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollableExternal();
     if (sf) {
       scrollPort = sf->GetScrollPortRect();
--- a/chrome/src/nsChromeRegistry.cpp
+++ b/chrome/src/nsChromeRegistry.cpp
@@ -946,17 +946,17 @@ nsresult nsChromeRegistry::RefreshWindow
   if (!domDocument)
     return NS_OK;
 
   nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
   if (!document)
     return NS_OK;
 
   // Deal with the agent sheets first.  Have to do all the style sets by hand.
-  nsCOMPtr<nsIPresShell> shell = document->GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = document->GetShell();
   if (shell) {
     // Reload only the chrome URL agent style sheets.
     nsCOMArray<nsIStyleSheet> agentSheets;
     rv = shell->GetAgentStyleSheets(agentSheets);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMArray<nsIStyleSheet> newAgentSheets;
     for (PRInt32 l = 0; l < agentSheets.Count(); ++l) {
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -110,19 +110,21 @@ class Loader;
 } // namespace css
 
 namespace dom {
 class Link;
 class Element;
 } // namespace dom
 } // namespace mozilla
 
+
+// fbcd570b-dbfa-479b-9bd0-02312129c044
 #define NS_IDOCUMENT_IID      \
-{ 0x3ee6a14b, 0x83b5, 0x4629, \
-  { 0x96, 0x9b, 0xe9, 0x84, 0x7c, 0x57, 0x24, 0x3c } }
+{ 0xfbcd570b, 0xdbfa, 0x479b, \
+  { 0x9b, 0xd0, 0x02, 0x31, 0x21, 0x29, 0xc0, 0x44 } }
 
 // Flag for AddStyleSheet().
 #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
 
 // Document states
 
 // RTL locale: specific to the XUL localedir attribute
 #define NS_DOCUMENT_STATE_RTL_LOCALE              (1 << 0)
@@ -432,17 +434,17 @@ public:
    * presshell if the presshell should observe document mutations.
    */
   virtual nsresult CreateShell(nsPresContext* aContext,
                                nsIViewManager* aViewManager,
                                nsStyleSet* aStyleSet,
                                nsIPresShell** aInstancePtrResult) = 0;
   void DeleteShell() { mPresShell = nsnull; }
 
-  nsIPresShell* GetPrimaryShell() const
+  nsIPresShell* GetShell() const
   {
     return mShellIsHidden ? nsnull : mPresShell;
   }
 
   void SetShellHidden(PRBool aHide) { mShellIsHidden = aHide; }
   PRBool ShellIsHidden() const { return mShellIsHidden; }
 
   /**
@@ -1144,17 +1146,17 @@ public:
   }
   
   /**
    * Set the display document for this document.  aDisplayDocument must not be
    * null.
    */
   void SetDisplayDocument(nsIDocument* aDisplayDocument)
   {
-    NS_PRECONDITION(!GetPrimaryShell() &&
+    NS_PRECONDITION(!GetShell() &&
                     !nsCOMPtr<nsISupports>(GetContainer()) &&
                     !GetWindow() &&
                     !GetScriptGlobalObject(),
                     "Shouldn't set mDisplayDocument on documents that already "
                     "have a presentation or a docshell or a window");
     NS_PRECONDITION(aDisplayDocument != this, "Should be different document");
     NS_PRECONDITION(!aDisplayDocument->GetDisplayDocument(),
                     "Display documents should not nest");
--- a/content/base/src/nsContentSink.cpp
+++ b/content/base/src/nsContentSink.cpp
@@ -528,17 +528,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->GetPrimaryShell();
+      nsIPresShell* shell = mDocument->GetShell();
       if (shell) {
         shell->DisableThemeSupport();
       }
     }
   }
   // Don't report "refresh" headers back to necko, since our document handles
   // them
   else if (aHeader != nsGkAtoms::refresh && mParser) {
@@ -1262,17 +1262,17 @@ nsContentSink::StartLayout(PRBool aIgnor
   // sure to flush tags instead of just calling UpdateChildCounts() after we
   // loop over the shells.
   FlushTags();
 
   mLayoutStarted = PR_TRUE;
   mLastNotificationTime = PR_Now();
 
   mDocument->SetMayStartLayout(PR_TRUE);
-  nsCOMPtr<nsIPresShell> shell = mDocument->GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = mDocument->GetShell();
   // Make sure we don't call InitialReflow() for a shell that has
   // already called it. This can happen when the layout frame for
   // an iframe is constructed *between* the Embed() call for the
   // docshell in the iframe, and the content sink's call to OpenBody().
   // (Bug 153815)
   if (shell && !shell->DidInitialReflow()) {
     nsRect r = shell->GetPresContext()->GetVisibleArea();
     nsCOMPtr<nsIPresShell> shellGrip = shell;
@@ -1458,17 +1458,17 @@ nsContentSink::WillResumeImpl()
 nsresult
 nsContentSink::DidProcessATokenImpl()
 {
   if (!mCanInterruptParser || !mParser || !mParser->CanInterrupt()) {
     return NS_OK;
   }
 
   // Get the current user event time
-  nsIPresShell *shell = mDocument->GetPrimaryShell();
+  nsIPresShell *shell = mDocument->GetShell();
   if (!shell) {
     // If there's no pres shell in the document, return early since
     // we're not laying anything out here.
     return NS_OK;
   }
 
   // Increase before comparing to gEventProbeRate
   ++mDeflectedCount;
@@ -1626,17 +1626,17 @@ nsContentSink::IsScriptExecutingImpl()
 
 nsresult
 nsContentSink::WillParseImpl(void)
 {
   if (!mCanInterruptParser) {
     return NS_OK;
   }
 
-  nsIPresShell *shell = mDocument->GetPrimaryShell();
+  nsIPresShell *shell = mDocument->GetShell();
   if (!shell) {
     return NS_OK;
   }
 
   PRUint32 currentTime = PR_IntervalToMicroseconds(PR_IntervalNow());
 
   if (sEnablePerfMode == 0) {
     nsIViewManager* vm = shell->GetViewManager();
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -2295,17 +2295,17 @@ nsContentUtils::SplitExpatName(const PRU
 }
 
 // static
 nsPresContext*
 nsContentUtils::GetContextForContent(nsIContent* aContent)
 {
   nsIDocument* doc = aContent->GetCurrentDoc();
   if (doc) {
-    nsIPresShell *presShell = doc->GetPrimaryShell();
+    nsIPresShell *presShell = doc->GetShell();
     if (presShell) {
       return presShell->GetPresContext();
     }
   }
   return nsnull;
 }
 
 // static
@@ -6111,17 +6111,17 @@ already_AddRefed<mozilla::layers::LayerM
 nsContentUtils::LayerManagerForDocument(nsIDocument *aDoc)
 {
   nsIDocument* doc = aDoc;
   nsIDocument* displayDoc = doc->GetDisplayDocument();
   if (displayDoc) {
     doc = displayDoc;
   }
 
-  nsIPresShell* shell = doc->GetPrimaryShell();
+  nsIPresShell* shell = doc->GetShell();
   nsCOMPtr<nsISupports> container = doc->GetContainer();
   nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = do_QueryInterface(container);
   while (!shell && docShellTreeItem) {
     // We may be in a display:none subdocument, or we may not have a presshell
     // created yet.
     // Walk the docshell tree to find the nearest container that has a presshell,
     // and find the root widget from that.
     nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(docShellTreeItem);
--- a/content/base/src/nsCopySupport.cpp
+++ b/content/base/src/nsCopySupport.cpp
@@ -593,17 +593,17 @@ static nsresult AppendDOMNode(nsITransfe
   return AppendString(aTransferable, context, kHTMLContext);
 }
 
 nsIContent*
 nsCopySupport::GetSelectionForCopy(nsIDocument* aDocument, nsISelection** aSelection)
 {
   *aSelection = nsnull;
 
-  nsIPresShell* presShell = aDocument->GetPrimaryShell();
+  nsIPresShell* presShell = aDocument->GetShell();
   if (!presShell)
     return nsnull;
 
   // check if the focused node in the window has a selection
   nsCOMPtr<nsPIDOMWindow> focusedWindow;
   nsIContent* content =
     nsFocusManager::GetFocusedDescendant(aDocument->GetWindow(), PR_FALSE,
                                          getter_AddRefs(focusedWindow));
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -1992,17 +1992,17 @@ nsDocument::ResetStylesheetsToURI(nsIURI
   }
 
   indx = mCatalogSheets.Count();
   while (--indx >= 0) {
     nsIStyleSheet* sheet = mCatalogSheets[indx];
     sheet->SetOwningDocument(nsnull);
 
     if (sheet->IsApplicable()) {
-      nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+      nsCOMPtr<nsIPresShell> shell = GetShell();
       if (shell) {
         shell->StyleSet()->RemoveStyleSheet(nsStyleSet::eAgentSheet, sheet);
       }
     }
 
     // XXX Tell observers?
   }
 
@@ -2013,33 +2013,33 @@ nsDocument::ResetStylesheetsToURI(nsIURI
   // now, but it could in the future -- in which case not releasing them
   // is probably the right thing to do.
 
   // Now reset our inline style and attribute sheets.
   nsresult rv = NS_OK;
   nsStyleSet::sheetType attrSheetType = GetAttrSheetType();
   if (mAttrStyleSheet) {
     // Remove this sheet from all style sets
-    nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = GetShell();
     if (shell) {
       shell->StyleSet()->RemoveStyleSheet(attrSheetType, mAttrStyleSheet);
     }
     mAttrStyleSheet->Reset(aURI);
   } else {
     rv = NS_NewHTMLStyleSheet(getter_AddRefs(mAttrStyleSheet), aURI, this);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Don't use AddStyleSheet, since it'll put the sheet into style
   // sets in the document level, which is not desirable here.
   mAttrStyleSheet->SetOwningDocument(this);
   
   if (mStyleAttrStyleSheet) {
     // Remove this sheet from all style sets
-    nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = GetShell();
     if (shell) {
       shell->StyleSet()->
         RemoveStyleSheet(nsStyleSet::eStyleAttrSheet, mStyleAttrStyleSheet);
     }
     mStyleAttrStyleSheet->Reset(aURI);
   } else {
     mStyleAttrStyleSheet = new nsHTMLCSSStyleSheet();
     NS_ENSURE_TRUE(mStyleAttrStyleSheet, NS_ERROR_OUT_OF_MEMORY);
@@ -2047,17 +2047,17 @@ nsDocument::ResetStylesheetsToURI(nsIURI
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // The loop over style sets below will handle putting this sheet
   // into style sets as needed.
   mStyleAttrStyleSheet->SetOwningDocument(this);
 
   // Now set up our style sets
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     FillStyleSet(shell->StyleSet());
   }
 
   return rv;
 }
 
 nsStyleSet::sheetType
@@ -2563,17 +2563,17 @@ nsDocument::ElementFromPointHelper(float
   nscoord y = nsPresContext::CSSPixelsToAppUnits(aY);
   nsPoint pt(x, y);
 
   // Make sure the layout information we get is up-to-date, and
   // ensure we get a root frame (for everything but XUL)
   if (aFlushLayout)
     FlushPendingNotifications(Flush_Layout);
 
-  nsIPresShell *ps = GetPrimaryShell();
+  nsIPresShell *ps = GetShell();
   NS_ENSURE_STATE(ps);
   nsIFrame *rootFrame = ps->GetRootFrame();
 
   // XUL docs, unlike HTML, have no frame tree until everything's done loading
   if (!rootFrame)
     return NS_OK; // return null to premature XUL callers as a reminder to wait
 
   nsIFrame *ptFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, pt, PR_TRUE,
@@ -2633,17 +2633,17 @@ nsDocument::NodesFromRectHelper(float aX
   nsRect rect(x, y, w, h);
 
   // Make sure the layout information we get is up-to-date, and
   // ensure we get a root frame (for everything but XUL)
   if (aFlushLayout) {
     FlushPendingNotifications(Flush_Layout);
   }
 
-  nsIPresShell *ps = GetPrimaryShell();
+  nsIPresShell *ps = GetShell();
   NS_ENSURE_STATE(ps);
   nsIFrame *rootFrame = ps->GetRootFrame();
 
   // XUL docs, unlike HTML, have no frame tree until everything's done loading
   if (!rootFrame)
     return NS_OK; // return nothing to premature XUL callers as a reminder to wait
 
   nsTArray<nsIFrame*> outFrames;
@@ -3234,17 +3234,17 @@ PRInt32
 nsDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const
 {
   return mStyleSheets.IndexOf(aSheet);
 }
 
 void
 nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet)
 {
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     shell->StyleSet()->AddDocStyleSheet(aSheet, this);
   }
 }
 
 void
 nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
 {
@@ -3257,17 +3257,17 @@ nsDocument::AddStyleSheet(nsIStyleSheet*
   }
 
   NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (this, aSheet, PR_TRUE));
 }
 
 void
 nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet)
 {
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     shell->StyleSet()->RemoveStyleSheet(nsStyleSet::eDocSheet, aSheet);
   }
 }
 
 void
 nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet)
 {
@@ -3385,17 +3385,17 @@ nsDocument::GetCatalogStyleSheetAt(PRInt
 void
 nsDocument::AddCatalogStyleSheet(nsIStyleSheet* aSheet)
 {
   mCatalogSheets.AppendObject(aSheet);
   aSheet->SetOwningDocument(this);
 
   if (aSheet->IsApplicable()) {
     // This is like |AddStyleSheetToStyleSets|, but for an agent sheet.
-    nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = GetShell();
     if (shell) {
       shell->StyleSet()->AppendStyleSheet(nsStyleSet::eAgentSheet, aSheet);
     }
   }
                                                                                 
   NS_DOCUMENT_NOTIFY_OBSERVERS(StyleSheetAdded, (this, aSheet, PR_FALSE));
 }
 
@@ -3854,17 +3854,17 @@ nsDocument::DispatchContentLoadedEvents(
         // target is not in the same document, so the event would never reach
         // the ancestor document if we used the normal event
         // dispatching code.
 
         nsEvent* innerEvent = privateEvent->GetInternalNSEvent();
         if (innerEvent) {
           nsEventStatus status = nsEventStatus_eIgnore;
 
-          nsIPresShell *shell = parent->GetPrimaryShell();
+          nsIPresShell *shell = parent->GetShell();
           if (shell) {
             nsRefPtr<nsPresContext> context = shell->GetPresContext();
 
             if (context) {
               nsEventDispatcher::Dispatch(parent, context, innerEvent, event,
                                           &status);
             }
           }
@@ -4942,17 +4942,17 @@ void
 nsDocument::DoNotifyPossibleTitleChange()
 {
   mPendingTitleChangeEvent.Forget();
   mHaveFiredTitleChange = PR_TRUE;
 
   nsAutoString title;
   GetTitle(title);
 
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     nsCOMPtr<nsISupports> container = shell->GetPresContext()->GetContainer();
     if (container) {
       nsCOMPtr<nsIBaseWindow> docShellWin = do_QueryInterface(container);
       if (docShellWin) {
         docShellWin->SetTitle(PromiseFlatString(title).get());
       }
     }
@@ -5216,17 +5216,17 @@ nsDocument::GetAnimationController()
   // for data documents.
   if (!NS_SMILEnabled() || mLoadedAsData || mLoadedAsInteractiveData)
     return nsnull;
 
   mAnimationController = NS_NewSMILAnimationController(this);
   
   // If there's a presContext then check the animation mode and pause if
   // necessary.
-  nsIPresShell *shell = GetPrimaryShell();
+  nsIPresShell *shell = GetShell();
   if (mAnimationController && shell) {
     nsPresContext *context = shell->GetPresContext();
     if (context &&
         context->ImageAnimationMode() == imgIContainer::kDontAnimMode) {
       mAnimationController->Pause(nsSMILTimeContainer::PAUSE_USERPREF);
     }
   }
 
@@ -5273,17 +5273,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 = GetPrimaryShell();
+        nsIPresShell *shell = GetShell();
         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);
         }
@@ -5954,17 +5954,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 = GetPrimaryShell();
+  nsIPresShell *shell = GetShell();
   nsRefPtr<nsPresContext> context;
   if (shell) {
      context = shell->GetPresContext();
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =
     nsEventDispatcher::DispatchDOMEvent(static_cast<nsINode*>(this),
@@ -6039,17 +6039,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 = GetPrimaryShell();
+  nsIPresShell *shell = GetShell();
 
   nsPresContext *presContext = nsnull;
 
   if (shell) {
     // Retrieve the context
     presContext = shell->GetPresContext();
   }
 
@@ -6109,17 +6109,17 @@ nsDocument::FlushPendingNotifications(mo
   // correct size to determine the correct style.
   if (mParentDocument && IsSafeToFlush()) {
     mozFlushType parentType = aType;
     if (aType >= Flush_Style)
       parentType = NS_MAX(Flush_Layout, aType);
     mParentDocument->FlushPendingNotifications(parentType);
   }
 
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     shell->FlushPendingNotifications(aType);
   }
 }
 
 static PRBool
 Flush(nsIDocument* aDocument, void* aData)
 {
@@ -6539,17 +6539,17 @@ nsDocument::CreateElem(nsIAtom *aName, n
   NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
 
   return NS_NewElement(aResult, elementType, nodeInfo, PR_FALSE);
 }
 
 PRBool
 nsDocument::IsSafeToFlush() const
 {
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   if (!shell)
     return PR_TRUE;
 
   return shell->IsSafeToFlush();
 }
 
 nsresult
 nsDocument::Sanitize()
@@ -7366,17 +7366,17 @@ FireOrClearDelayedEvents(nsTArray<nsCOMP
 {
   nsIFocusManager* fm = nsFocusManager::GetFocusManager();
   if (!fm)
     return;
 
   for (PRUint32 i = 0; i < aDocuments.Length(); ++i) {
     if (!aDocuments[i]->EventHandlingSuppressed()) {
       fm->FireDelayedEvents(aDocuments[i]);
-      nsCOMPtr<nsIPresShell> shell = aDocuments[i]->GetPrimaryShell();
+      nsCOMPtr<nsIPresShell> shell = aDocuments[i]->GetShell();
       if (shell) {
         shell->FireOrClearDelayedEvents(aFireEvents);
       }
     }
   }
 }
 
 void
@@ -7416,17 +7416,17 @@ nsDocument::GetDocumentState()
 {
   if (!(mGotDocumentState & NS_DOCUMENT_STATE_RTL_LOCALE)) {
     if (IsDocumentRightToLeft()) {
       mDocumentState |= NS_DOCUMENT_STATE_RTL_LOCALE;
     }
     mGotDocumentState |= NS_DOCUMENT_STATE_RTL_LOCALE;
   }
   if (!(mGotDocumentState & NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
-    nsIPresShell* shell = GetPrimaryShell();
+    nsIPresShell* shell = GetShell();
     if (shell && shell->GetPresContext() &&
         shell->GetPresContext()->IsTopLevelWindowInactive()) {
       mDocumentState |= NS_DOCUMENT_STATE_WINDOW_INACTIVE;
     }
     mGotDocumentState |= NS_DOCUMENT_STATE_WINDOW_INACTIVE;
   }
   return mDocumentState;
 }
@@ -7581,17 +7581,17 @@ nsDocument::ScrollToRef()
   unescapedRef.Assign(tmpstr);
   nsMemory::Free(tmpstr);
 
   nsresult rv = NS_ERROR_FAILURE;
   // We assume that the bytes are in UTF-8, as it says in the spec:
   // http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1
   NS_ConvertUTF8toUTF16 ref(unescapedRef);
 
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     // Check an empty string which might be caused by the UTF-8 conversion
     if (!ref.IsEmpty()) {
       // Note that GoToAnchor will handle flushing layout as needed.
       rv = shell->GoToAnchor(ref, mChangeScrollPosWhenScrollingToRef);
     } else {
       rv = NS_ERROR_FAILURE;
     }
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -799,18 +799,18 @@ nsFrameLoader::SwapWithOtherLoader(nsFra
   if (!ourDoc || !otherDoc) {
     // Again, how odd, given that we had docshells
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   NS_ASSERTION(ourDoc == ourParentDocument, "Unexpected parent document");
   NS_ASSERTION(otherDoc == otherParentDocument, "Unexpected parent document");
 
-  nsIPresShell* ourShell = ourDoc->GetPrimaryShell();
-  nsIPresShell* otherShell = otherDoc->GetPrimaryShell();
+  nsIPresShell* ourShell = ourDoc->GetShell();
+  nsIPresShell* otherShell = otherDoc->GetShell();
   if (!ourShell || !otherShell) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   if (mInSwap || aOther->mInSwap) {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
   mInSwap = aOther->mInSwap = PR_TRUE;
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -842,17 +842,17 @@ nsIContent::GetDesiredIMEState()
   // This is in another editable content, use the result of it.
   if (editableAncestor) {
     return editableAncestor->GetDesiredIMEState();
   }
   nsIDocument* doc = GetCurrentDoc();
   if (!doc) {
     return IME_STATUS_DISABLE;
   }
-  nsIPresShell* ps = doc->GetPrimaryShell();
+  nsIPresShell* ps = doc->GetShell();
   if (!ps) {
     return IME_STATUS_DISABLE;
   }
   nsPresContext* pc = ps->GetPresContext();
   if (!pc) {
     return IME_STATUS_DISABLE;
   }
   nsIEditor* editor = GetHTMLEditor(pc);
@@ -3296,17 +3296,17 @@ nsGenericElement::SetSMILOverrideStyleRu
   slots->mSMILOverrideStyleRule = aStyleRule;
 
   if (aNotify) {
     nsIDocument* doc = GetCurrentDoc();
     // Only need to request a restyle if we're in a document.  (We might not
     // be in a document, if we're clearing animation effects on a target node
     // that's been detached since the previous animation sample.)
     if (doc) {
-      nsCOMPtr<nsIPresShell> shell = doc->GetPrimaryShell();
+      nsCOMPtr<nsIPresShell> shell = doc->GetShell();
       if (shell) {
         shell->RestyleForAnimation(this);
       }
     }
   }
 
   return NS_OK;
 }
@@ -3616,17 +3616,17 @@ nsINode::doRemoveChildAt(PRUint32 aIndex
                          nsIContent* aKid, nsAttrAndChildArray& aChildArray,
                          PRBool aMutationEvent)
 {
   nsIDocument* doc = GetCurrentDoc();
 #ifdef ACCESSIBILITY
   // A11y needs to be notified of content removals first, so accessibility
   // events can be fired before any changes occur
   if (aNotify && doc) {
-    nsIPresShell *presShell = doc->GetPrimaryShell();
+    nsIPresShell *presShell = doc->GetShell();
     if (presShell && presShell->IsAccessibilityActive()) {
       nsCOMPtr<nsIAccessibilityService> accService = 
         do_GetService("@mozilla.org/accessibilityService;1");
       if (accService) {
         accService->InvalidateSubtreeFor(presShell, aKid,
                                          nsIAccessibilityService::NODE_REMOVE);
       }
     }
@@ -5373,17 +5373,17 @@ ParseSelectorList(nsINode* aNode,
       slot = &cur->mNext;
     }
   } while (*slot);
   *aSelectorList = selectorList;
 
   // It's not strictly necessary to have a prescontext here, but it's
   // a bit of an optimization for various stuff.
   *aPresContext = nsnull;
-  nsIPresShell* shell = doc->GetPrimaryShell();
+  nsIPresShell* shell = doc->GetShell();
   if (shell) {
     *aPresContext = shell->GetPresContext();
   }
 
   return NS_OK;
 }
 
 /*
--- a/content/base/src/nsImageLoadingContent.cpp
+++ b/content/base/src/nsImageLoadingContent.cpp
@@ -286,17 +286,17 @@ nsImageLoadingContent::OnStopDecode(imgI
   // by blocking onload until all in progress decodes get at least one frame
   // decoded. However, if all the data comes in while painting is suppressed
   // (ie, before the initial paint delay is finished), we fire onload without
   // doing a paint first. This means that decode-on-draw images don't start
   // decoding, so we can't wait for them to finish. See bug 512435.
 
   // We can only do this if we have a presshell
   nsIDocument* doc = GetOurDocument();
-  nsIPresShell* shell = doc ? doc->GetPrimaryShell() : nsnull;
+  nsIPresShell* shell = doc ? doc->GetShell() : nsnull;
   if (shell) {
 
     // We need to figure out whether to kick off decoding
     PRBool doRequestDecode = PR_FALSE;
 
     // If we haven't got the initial reflow yet, IsPaintingSuppressed actually
     // returns false
     if (!shell->DidInitialReflow())
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -871,17 +871,17 @@ nsObjectLoadingContent::EnsureInstantiat
 
     nsIDocument* doc = thisContent->GetCurrentDoc();
     if (!doc) {
       // Nothing we can do while plugin loading is done in layout...
       mInstantiating = PR_FALSE;
       return NS_OK;
     }
 
-    nsCOMPtr<nsIPresShell> shell = doc->GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = doc->GetShell();
     if (shell) {
       shell->RecreateFramesFor(thisContent);
     }
 
     mInstantiating = PR_FALSE;
 
     frame = GetExistingFrame(eFlushContent);
     if (!frame) {
@@ -1651,17 +1651,17 @@ nsObjectLoadingContent::NotifyStateChang
     if (aSync) {
       // Make sure that frames are actually constructed, and do it after
       // EndUpdate was called.
       doc->FlushPendingNotifications(Flush_Frames);
     }
   } else if (aOldType != mType) {
     // If our state changed, then we already recreated frames
     // Otherwise, need to do that here
-    nsCOMPtr<nsIPresShell> shell = doc->GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = doc->GetShell();
     if (shell) {
       shell->RecreateFramesFor(thisContent);
     }
   }
 }
 
 /* static */ void
 nsObjectLoadingContent::FirePluginError(nsIContent* thisContent,
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -532,17 +532,17 @@ protected:
     /**
      * Gets the pres shell from either the canvas element or the doc shell
      */
     nsIPresShell *GetPresShell() {
       nsCOMPtr<nsIContent> content =
         do_QueryInterface(static_cast<nsIDOMHTMLCanvasElement*>(mCanvasElement));
       if (content) {
         nsIDocument* ownerDoc = content->GetOwnerDoc();
-        return ownerDoc ? ownerDoc->GetPrimaryShell() : nsnull;
+        return ownerDoc ? ownerDoc->GetShell() : nsnull;
       }
       if (mDocShell) {
         nsCOMPtr<nsIPresShell> shell;
         mDocShell->GetPresShell(getter_AddRefs(shell));
         return shell.get();
       }
       return nsnull;
     }
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -1291,17 +1291,17 @@ nsEventListenerManager::DispatchEvent(ns
   nsCOMPtr<nsIDocument> document = targetNode->GetOwnerDoc();
 
   // Do nothing if the element does not belong to a document
   if (!document) {
     return NS_OK;
   }
 
   // Obtain a presentation shell
-  nsIPresShell *shell = document->GetPrimaryShell();
+  nsIPresShell *shell = document->GetShell();
   nsRefPtr<nsPresContext> context;
   if (shell) {
     context = shell->GetPresContext();
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =
     nsEventDispatcher::DispatchDOMEvent(targetNode, nsnull, aEvent,
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -2198,17 +2198,17 @@ nsEventStateManager::DoDefaultDragStart(
   // If a selection is being dragged, and no custom drag image was
   // set, get the selection so that the drag region can be created
   // from the selection area. If a custom image was set, it doesn't
   // matter what the selection is since the image will be used instead.
   nsISelection* selection = nsnull;
   if (aIsSelection && !dragImage) {
     nsIDocument* doc = aDragTarget->GetCurrentDoc();
     if (doc) {
-      nsIPresShell* presShell = doc->GetPrimaryShell();
+      nsIPresShell* presShell = doc->GetShell();
       if (presShell) {
         selection = presShell->GetCurrentSelection(
                       nsISelectionController::SELECTION_NORMAL);
       }
     }
   }
 
   nsCOMPtr<nsISupportsArray> transArray;
@@ -2278,17 +2278,17 @@ nsEventStateManager::GetMarkupDocumentVi
 
   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->GetPrimaryShell();
+  nsIPresShell *presShell = doc->GetShell();
   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));
@@ -3565,17 +3565,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->GetPrimaryShell();
+      nsIPresShell *parentShell = parentDoc->GetShell();
       if (parentShell) {
         nsEventStateManager* parentESM =
           static_cast<nsEventStateManager*>
                      (parentShell->GetPresContext()->EventStateManager());
         parentESM->NotifyMouseOver(aEvent, docContent);
       }
     }
   }
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -779,17 +779,17 @@ nsGenericHTMLElement::ScrollIntoView(PRB
 {
   nsIDocument *document = GetCurrentDoc();
 
   if (!document) {
     return NS_OK;
   }
 
   // Get the presentation shell
-  nsCOMPtr<nsIPresShell> presShell = document->GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> presShell = document->GetShell();
   if (!presShell) {
     return NS_OK;
   }
 
   if (!optional_argc) {
     aTop = PR_TRUE;
   }
 
@@ -1439,17 +1439,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->GetPrimaryShell();
+    nsIPresShell *presShell = doc->GetShell();
     if (presShell) {
       return presShell->GetPresContext();
     }
   }
 
   return nsnull;
 }
 
--- a/content/html/content/src/nsHTMLAnchorElement.cpp
+++ b/content/html/content/src/nsHTMLAnchorElement.cpp
@@ -250,17 +250,17 @@ nsHTMLAnchorElement::IsHTMLFocusable(PRB
 {
   if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
     return PR_TRUE;
   }
 
   // cannot focus links if there is no link handler
   nsIDocument* doc = GetCurrentDoc();
   if (doc) {
-    nsIPresShell* presShell = doc->GetPrimaryShell();
+    nsIPresShell* presShell = doc->GetShell();
     if (presShell) {
       nsPresContext* presContext = presShell->GetPresContext();
       if (presContext && !presContext->GetLinkHandler()) {
         *aIsFocusable = PR_FALSE;
         return PR_FALSE;
       }
     }
   }
--- a/content/html/content/src/nsHTMLButtonElement.cpp
+++ b/content/html/content/src/nsHTMLButtonElement.cpp
@@ -236,17 +236,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->GetPrimaryShell();
+    nsIPresShell *shell = doc->GetShell();
     if (shell) {
       nsRefPtr<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
@@ -1705,25 +1705,25 @@ nsHTMLInputElement::Click()
       mType == NS_FORM_INPUT_IMAGE) {
 
     // Strong in case the event kills it
     nsCOMPtr<nsIDocument> doc = GetCurrentDoc();
     if (!doc) {
       return rv;
     }
 
-    nsCOMPtr<nsIPresShell> shell = doc->GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = doc->GetShell();
     nsRefPtr<nsPresContext> context = nsnull;
     if (shell) {
       context = shell->GetPresContext();
     }
 
     if (!context) {
       doc->FlushPendingNotifications(Flush_Frames);
-      shell = doc->GetPrimaryShell();
+      shell = doc->GetShell();
       if (shell) {
         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()
--- a/content/html/content/src/nsTextEditorState.cpp
+++ b/content/html/content/src/nsTextEditorState.cpp
@@ -680,17 +680,17 @@ nsTextInputListener::NotifySelectionChan
                                 nsISelectionListener::SELECTALL_REASON)))
   {
     nsIContent* content = mFrame->GetContent();
     if (content) 
     {
       nsCOMPtr<nsIDocument> doc = content->GetDocument();
       if (doc) 
       {
-        nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
+        nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
         if (presShell) 
         {
           nsEventStatus status = nsEventStatus_eIgnore;
           nsEvent event(PR_TRUE, NS_FORM_SELECTED);
 
           presShell->HandleEventWithTarget(&event, mFrame, content, &status);
         }
       }
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -1242,17 +1242,17 @@ nsHTMLDocument::GetImageMap(const nsAStr
 void
 nsHTMLDocument::SetCompatibilityMode(nsCompatibility aMode)
 {
   NS_ASSERTION(IsHTML() || aMode == eCompatibility_FullStandards,
                "Bad compat mode for XHTML document!");
 
   mCompatMode = aMode;
   CSSLoader()->SetCompatibilityMode(mCompatMode);
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   if (shell) {
     nsPresContext *pc = shell->GetPresContext();
     if (pc) {
       pc->CompatibilityModeChanged();
     }
   }
 }
 
@@ -2153,17 +2153,17 @@ nsHTMLDocument::Close()
     // handler of the frameset fires before the frames get reflowed
     // and loaded.  That is the long explanation for why we need this
     // one line of code here!
     // XXXbz as far as I can tell this may not be needed anymore; all
     // the testcases in bug 57636 pass without this line...  Leaving
     // it be for now, though.  In any case, there's no reason to do
     // this if we have no presshell, since in that case none of the
     // above about reusing frames applies.
-    if (GetPrimaryShell()) {
+    if (GetShell()) {
       FlushPendingNotifications(Flush_Layout);
     }
 
     // Remove the wyciwyg channel request from the document load group
     // that we added in OpenCommon().  If all other requests between
     // document.open() and document.close() have completed, then this
     // method should cause the firing of an onload event.
     NS_ASSERTION(mWyciwygChannel, "nsHTMLDocument::Close(): Trying to remove "
--- a/content/html/document/src/nsImageDocument.cpp
+++ b/content/html/document/src/nsImageDocument.cpp
@@ -506,17 +506,17 @@ nsImageDocument::ScrollImageTo(PRInt32 a
 {
   float ratio = GetRatio();
 
   if (restoreImage) {
     RestoreImage();
     FlushPendingNotifications(Flush_Layout);
   }
 
-  nsIPresShell *shell = GetPrimaryShell();
+  nsIPresShell *shell = GetShell();
   if (!shell)
     return NS_OK;
 
   nsIScrollableFrame* sf = shell->GetRootScrollFrameAsScrollable();
   if (!sf)
     return NS_OK;
 
   nsRect portRect = sf->GetScrollPortRect();
@@ -682,17 +682,17 @@ nsImageDocument::CreateSyntheticDocument
 nsresult
 nsImageDocument::CheckOverflowing(PRBool changeState)
 {
   /* Create a scope so that the style context gets destroyed before we might
    * call RebuildStyleData.  Also, holding onto pointers to the
    * presentatation through style resolution is potentially dangerous.
    */
   {
-    nsIPresShell *shell = GetPrimaryShell();
+    nsIPresShell *shell = GetShell();
     if (!shell) {
       return NS_OK;
     }
 
     nsPresContext *context = shell->GetPresContext();
     nsRect visibleArea = context->GetVisibleArea();
 
     Element* body = GetBodyElement();
--- a/content/html/document/src/nsMediaDocument.cpp
+++ b/content/html/document/src/nsMediaDocument.cpp
@@ -271,17 +271,17 @@ nsMediaDocument::CreateSyntheticDocument
 
   return NS_OK;
 }
 
 nsresult
 nsMediaDocument::StartLayout()
 {
   mMayStartLayout = PR_TRUE;
-  nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = GetShell();
   // Don't mess with the presshell if someone has already handled
   // its initial reflow.
   if (shell && !shell->DidInitialReflow()) {
     nsRect visibleArea = shell->GetPresContext()->GetVisibleArea();
     nsresult rv = shell->InitialReflow(visibleArea.width, visibleArea.height);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
--- a/content/html/document/src/nsPluginDocument.cpp
+++ b/content/html/document/src/nsPluginDocument.cpp
@@ -124,17 +124,17 @@ nsresult
 nsPluginStreamListener::SetupPlugin()
 {
   NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
   mPluginDoc->StartLayout();
 
   nsCOMPtr<nsIContent> embed = mPluginDoc->GetPluginContent();
 
   // Now we have a frame for our <embed>, start the load
-  nsCOMPtr<nsIPresShell> shell = mDocument->GetPrimaryShell();
+  nsCOMPtr<nsIPresShell> shell = mDocument->GetShell();
   if (!shell) {
     // Can't instantiate w/o a shell
     mPluginDoc->AllowNormalInstantiation();
     return NS_BINDING_ABORTED;
   }
 
   // Flush out layout before we go to instantiate, because some
   // plug-ins depend on NPP_SetWindow() being called early enough and
@@ -264,17 +264,17 @@ nsPluginDocument::StartDocumentLoad(cons
   NS_ADDREF(*aDocListener = mStreamListener);
 
   return rv;
 }
 
 nsresult
 nsPluginDocument::CreateSyntheticPluginDocument()
 {
-  NS_ASSERTION(!GetPrimaryShell() || !GetPrimaryShell()->DidInitialReflow(),
+  NS_ASSERTION(!GetShell() || !GetShell()->DidInitialReflow(),
                "Creating synthetic plugin document content too late");
 
   // make our generic document
   nsresult rv = nsMediaDocument::CreateSyntheticDocument();
   NS_ENSURE_SUCCESS(rv, rv);
   // then attach our plugin
 
   Element* body = GetBodyElement();
--- a/content/mathml/content/src/nsMathMLElement.cpp
+++ b/content/mathml/content/src/nsMathMLElement.cpp
@@ -87,17 +87,17 @@ nsMathMLElement::BindToTree(nsIDocument*
     // construction, because we could move a MathML element from the document
     // that created it to another document.
     aDocument->SetMathMLEnabled();
     aDocument->EnsureCatalogStyleSheet(kMathMLStyleSheetURI);
 
     // Rebuild style data for the presshell, because style system
     // optimizations may have taken place assuming MathML was disabled.
     // (See nsRuleNode::CheckSpecifiedProperties.)
-    nsCOMPtr<nsIPresShell> shell = aDocument->GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = aDocument->GetShell();
     if (shell) {
       shell->GetPresContext()->PostRebuildAllStyleDataEvent(nsChangeHint(0));
     }
   }
 
   return rv;
 }
 
--- a/content/smil/nsSMILAnimationController.cpp
+++ b/content/smil/nsSMILAnimationController.cpp
@@ -53,17 +53,17 @@ using namespace mozilla::dom;
 
 //----------------------------------------------------------------------
 // nsSMILAnimationController implementation
 
 // Helper method
 static nsRefreshDriver*
 GetRefreshDriverForDoc(nsIDocument* aDoc)
 {
-  nsIPresShell* shell = aDoc->GetPrimaryShell();
+  nsIPresShell* shell = aDoc->GetShell();
   if (!shell) {
     return nsnull;
   }
 
   nsPresContext* context = shell->GetPresContext();
   return context ? context->RefreshDriver() : nsnull;
 }
 
--- a/content/smil/nsSMILCSSProperty.cpp
+++ b/content/smil/nsSMILCSSProperty.cpp
@@ -62,17 +62,17 @@ GetCSSComputedValue(nsIContent* aElem,
   nsIDocument* doc = aElem->GetCurrentDoc();
   if (!doc) {
     // This can happen if we process certain types of restyles mid-sample
     // and remove anonymous animated content from the document as a result.
     // See bug 534975.
     return PR_FALSE;
   }
 
-  nsIPresShell* shell = doc->GetPrimaryShell();
+  nsIPresShell* shell = doc->GetShell();
   if (!shell) {
     NS_WARNING("Unable to look up computed style -- no pres shell");
     return PR_FALSE;
   }
 
   nsRefPtr<nsComputedDOMStyle> computedStyle;
   nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(aElem));
   nsresult rv = NS_NewComputedDOMStyle(domElement, EmptyString(), shell,
--- a/content/smil/nsSMILCSSValueType.cpp
+++ b/content/smil/nsSMILCSSValueType.cpp
@@ -322,17 +322,17 @@ GetPresContextForElement(nsIContent* aEl
 {
   nsIDocument* doc = aElem->GetCurrentDoc();
   if (!doc) {
     // This can happen if we process certain types of restyles mid-sample
     // and remove anonymous animated content from the document as a result.
     // See bug 534975.
     return nsnull;
   }
-  nsIPresShell* shell = doc->GetPrimaryShell();
+  nsIPresShell* shell = doc->GetShell();
   return shell ? shell->GetPresContext() : nsnull;
 }
 
 // Helper function to parse a string into a nsStyleAnimation::Value
 static PRBool
 ValueFromStringHelper(nsCSSProperty aPropID,
                       nsIContent* aTargetElement,
                       nsPresContext* aPresContext,
--- a/content/smil/nsSMILMappedAttribute.cpp
+++ b/content/smil/nsSMILMappedAttribute.cpp
@@ -152,17 +152,17 @@ nsSMILMappedAttribute::FlushChangesToTar
 {
   // Clear animated content-style-rule
   mElement->DeleteProperty(SMIL_MAPPED_ATTR_ANIMVAL,
                            SMIL_MAPPED_ATTR_STYLERULE_ATOM);
   nsIDocument* doc = mElement->GetCurrentDoc();
 
   // Request animation restyle
   if (doc) {
-    nsIPresShell* shell = doc->GetPrimaryShell();
+    nsIPresShell* shell = doc->GetShell();
     if (shell) {
       shell->RestyleForAnimation(mElement);
     }
   }
 }
 
 already_AddRefed<nsIAtom>
 nsSMILMappedAttribute::GetAttrNameAtom() const
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -753,25 +753,25 @@ nsSVGElement::WalkContentStyleRules(nsRu
   // Update & walk the animated content style rule, to include style from
   // animated mapped attributes.  But first, get nsPresContext to check
   // whether this is a "no-animation restyle". (This should match the check
   // in nsHTMLCSSStyleSheet::RulesMatching(), where we determine whether to
   // apply the SMILOverrideStyle.)
   nsIDocument* doc = GetOwnerDoc();
   NS_ASSERTION(doc, "SVG element without doc");
   if (doc) {
-    nsIPresShell* shell = doc->GetPrimaryShell();
+    nsIPresShell* shell = doc->GetShell();
     nsPresContext* context = shell ? shell->GetPresContext() : nsnull;
     if (context && context->IsProcessingRestyles() &&
         !context->IsProcessingAnimationStyleChange()) {
       // Any style changes right now could trigger CSS Transitions. We don't
       // want that to happen from SMIL-animated value of mapped attrs, so
       // ignore animated value for now, and request an animation restyle to
       // get our animated value noticed.
-      context->PresShell()->RestyleForAnimation(this);
+      shell->RestyleForAnimation(this);
     } else {
       // Ok, this is an animation restyle -- go ahead and update/walk the
       // animated content style rule.
       nsICSSStyleRule* animContentStyleRule = GetAnimatedContentStyleRule();
       if (!animContentStyleRule) {
         UpdateAnimatedContentStyleRule();
         animContentStyleRule = GetAnimatedContentStyleRule();
       }
--- a/content/svg/content/src/nsSVGSVGElement.cpp
+++ b/content/svg/content/src/nsSVGSVGElement.cpp
@@ -868,17 +868,17 @@ nsSVGSVGElement::SetCurrentScaleTranslat
   mPreviousTranslate = mCurrentTranslate;
   
   mCurrentScale = s;
   mCurrentTranslate = nsSVGTranslatePoint(x, y);
 
   // now dispatch the appropriate event if we are the root element
   nsIDocument* doc = GetCurrentDoc();
   if (doc) {
-    nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
     if (presShell && IsRoot()) {
       PRBool scaling = (mPreviousScale != mCurrentScale);
       nsEventStatus status = nsEventStatus_eIgnore;
       nsGUIEvent event(PR_TRUE, scaling ? NS_SVG_ZOOM : NS_SVG_SCROLL, 0);
       event.eventStructType = scaling ? NS_SVGZOOM_EVENT : NS_SVG_EVENT;
       presShell->HandleDOMEventWithTarget(this, &event, &status);
       InvalidateTransformNotifyFrame();
     }
--- a/content/svg/content/src/nsSVGUseElement.cpp
+++ b/content/svg/content/src/nsSVGUseElement.cpp
@@ -446,19 +446,21 @@ nsSVGUseElement::LookupHref()
 
   mSource.Reset(this, targetURI);
 }
 
 void
 nsSVGUseElement::TriggerReclone()
 {
   nsIDocument *doc = GetCurrentDoc();
-  if (!doc) return;
-  nsIPresShell *presShell = doc->GetPrimaryShell();
-  if (!presShell) return;
+  if (!doc)
+    return;
+  nsIPresShell *presShell = doc->GetShell();
+  if (!presShell)
+    return;
   presShell->PostRecreateFramesFor(this);
 }
 
 void
 nsSVGUseElement::UnlinkSource()
 {
   if (mSource.get()) {
     mSource.get()->RemoveMutationObserver(this);
--- a/content/xbl/src/nsBindingManager.cpp
+++ b/content/xbl/src/nsBindingManager.cpp
@@ -906,17 +906,17 @@ nsBindingManager::RemoveLayeredBinding(n
   binding->ChangeDocument(doc, nsnull);
   SetBinding(aContent, nsnull);
   binding->MarkForDeath();
   
   // ...and recreate its 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->GetPrimaryShell();
+  nsIPresShell *presShell = doc->GetShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
 
   return presShell->RecreateFramesFor(aContent);;
 }
 
 nsresult
 nsBindingManager::LoadBindingDocument(nsIDocument* aBoundDoc,
                                       nsIURI* aURL,
--- a/content/xbl/src/nsXBLResourceLoader.cpp
+++ b/content/xbl/src/nsXBLResourceLoader.cpp
@@ -258,17 +258,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->GetPrimaryShell();
+        nsIPresShell *shell = doc->GetShell();
         if (shell) {
           nsIFrame* childFrame = content->GetPrimaryFrame();
           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
@@ -209,17 +209,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->GetPrimaryShell();
+    nsIPresShell *shell = doc->GetShell();
     if (shell) {
       nsIFrame* childFrame = mBoundElement->GetPrimaryFrame();
       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
@@ -1171,17 +1171,17 @@ nsXMLContentSink::HandleEndElement(const
     event.eventStructType = NS_SVG_EVENT;
     event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
 
     // Do we care about forcing presshell creation if it hasn't happened yet?
     // That is, should this code flush or something?  Does it really matter?
     // For that matter, do we really want to try getting the prescontext?  Does
     // this event ever want one?
     nsRefPtr<nsPresContext> ctx;
-    nsCOMPtr<nsIPresShell> shell = mDocument->GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = mDocument->GetShell();
     if (shell) {
       ctx = shell->GetPresContext();
     }
     nsEventDispatcher::Dispatch(content, ctx, &event);
   }
 #endif
 
   return aInterruptable && NS_SUCCEEDED(result) ? DidProcessATokenImpl() :
--- a/content/xml/document/src/nsXMLPrettyPrinter.cpp
+++ b/content/xml/document/src/nsXMLPrettyPrinter.cpp
@@ -72,17 +72,17 @@ nsXMLPrettyPrinter::~nsXMLPrettyPrinter(
 
 nsresult
 nsXMLPrettyPrinter::PrettyPrint(nsIDocument* aDocument,
                                 PRBool* aDidPrettyPrint)
 {
     *aDidPrettyPrint = PR_FALSE;
     
     // Check for iframe with display:none. Such iframes don't have presshells
-    if (!aDocument->GetPrimaryShell()) {
+    if (!aDocument->GetShell()) {
         return NS_OK;
     }
 
     // check if we're in an invisible iframe
     nsPIDOMWindow *internalWin = aDocument->GetWindow();
     nsCOMPtr<nsIDOMElement> frameElem;
     if (internalWin) {
         internalWin->GetFrameElement(getter_AddRefs(frameElem));
--- a/content/xtf/src/nsXTFElementWrapper.cpp
+++ b/content/xtf/src/nsXTFElementWrapper.cpp
@@ -956,17 +956,17 @@ nsXTFElementWrapper::SetClassAttributeNa
 void
 nsXTFElementWrapper::RegUnregAccessKey(PRBool aDoReg)
 {
   nsIDocument* doc = GetCurrentDoc();
   if (!doc)
     return;
 
   // Get presentation shell 0
-  nsIPresShell *presShell = doc->GetPrimaryShell();
+  nsIPresShell *presShell = doc->GetShell();
   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
@@ -1024,17 +1024,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->GetPrimaryShell();
+        nsIPresShell *shell = doc->GetShell();
 
         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.
@@ -2095,17 +2095,17 @@ nsXULElement::Click()
 nsresult
 nsXULElement::ClickWithInputSource(PRUint16 aInputSource)
 {
     if (BoolAttrIsTrue(nsGkAtoms::disabled))
         return NS_OK;
 
     nsCOMPtr<nsIDocument> doc = GetCurrentDoc(); // Strong just in case
     if (doc) {
-        nsCOMPtr<nsIPresShell> shell = doc->GetPrimaryShell();
+        nsCOMPtr<nsIPresShell> shell = doc->GetShell();
         if (shell) {
             // strong ref to PresContext so events don't destroy it
             nsRefPtr<nsPresContext> context = shell->GetPresContext();
 
             PRBool isCallerChrome = nsContentUtils::IsCallerChrome();
 
             nsMouseEvent eventDown(isCallerChrome, NS_MOUSE_BUTTON_DOWN,
                                    nsnull, nsMouseEvent::eReal);
@@ -2351,17 +2351,17 @@ nsXULElement::HideWindowChrome(PRBool aS
     nsIDocument* doc = GetCurrentDoc();
     if (!doc || doc->GetRootElement() != this)
       return NS_ERROR_UNEXPECTED;
 
     // only top level chrome documents can hide the window chrome
     if (!doc->IsRootDisplayDocument())
       return NS_OK;
 
-    nsIPresShell *shell = doc->GetPrimaryShell();
+    nsIPresShell *shell = doc->GetShell();
 
     if (shell) {
         nsIFrame* frame = GetPrimaryFrame();
 
         nsPresContext *presContext = shell->GetPresContext();
 
         if (frame && presContext && presContext->IsChrome()) {
             nsIView* view = frame->GetClosestView();
--- a/content/xul/content/src/nsXULPopupListener.cpp
+++ b/content/xul/content/src/nsXULPopupListener.cpp
@@ -264,17 +264,17 @@ nsXULPopupListener::FireFocusOnTargetCon
   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->GetPrimaryShell();
+    nsIPresShell *shell = doc->GetShell();
     if (!shell)
       return NS_ERROR_FAILURE;
 
     // strong reference to keep this from going away between events
     // XXXbz between what events?  We don't use this local at all!
     nsRefPtr<nsPresContext> context = shell->GetPresContext();
  
     nsCOMPtr<nsIContent> content = do_QueryInterface(aTargetNode);
--- a/content/xul/document/src/nsXULCommandDispatcher.cpp
+++ b/content/xul/document/src/nsXULCommandDispatcher.cpp
@@ -431,19 +431,18 @@ nsXULCommandDispatcher::UpdateCommands(c
       CopyUTF16toUTF8(aEventName, aeventnameC);
       PR_LOG(gLog, PR_LOG_NOTICE,
              ("xulcmd[%p] update %p event=%s",
               this, updater->mElement.get(),
               aeventnameC.get()));
     }
 #endif
 
-    nsCOMPtr<nsIPresShell> shell = document->GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = document->GetShell();
     if (shell) {
-
       // Retrieve the context in which our DOM event will fire.
       nsRefPtr<nsPresContext> context = shell->GetPresContext();
 
       // Handle the DOM event
       nsEventStatus status = nsEventStatus_eIgnore;
 
       nsEvent event(PR_TRUE, NS_XUL_COMMAND_UPDATE);
 
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -957,19 +957,18 @@ nsXULDocument::ExecuteOnBroadcastHandler
             !listeningToAttribute.EqualsLiteral("*")) {
             continue;
         }
 
         // This is the right <observes> element. Execute the
         // |onbroadcast| event handler
         nsEvent event(PR_TRUE, NS_XUL_BROADCAST);
 
-        nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+        nsCOMPtr<nsIPresShell> shell = GetShell();
         if (shell) {
-
             nsRefPtr<nsPresContext> aPresContext = shell->GetPresContext();
 
             // Handle the DOM event
             nsEventStatus status = nsEventStatus_eIgnore;
             nsEventDispatcher::Dispatch(child, aPresContext, &event, nsnull,
                                         &status);
         }
     }
@@ -1469,17 +1468,17 @@ nsXULDocument::Persist(nsIContent* aElem
 nsresult
 nsXULDocument::GetViewportSize(PRInt32* aWidth,
                                PRInt32* aHeight)
 {
     *aWidth = *aHeight = 0;
 
     FlushPendingNotifications(Flush_Layout);
 
-    nsIPresShell *shell = GetPrimaryShell();
+    nsIPresShell *shell = GetShell();
     NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
 
     nsIFrame* frame = shell->GetRootFrame();
     NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
     nsSize size = frame->GetSize();
 
     *aWidth = nsPresContext::AppUnitsToIntCSSPixels(size.width);
@@ -1983,19 +1982,18 @@ nsXULDocument::Init()
     return NS_OK;
 }
 
 
 nsresult
 nsXULDocument::StartLayout(void)
 {
     mMayStartLayout = PR_TRUE;
-    nsCOMPtr<nsIPresShell> shell = GetPrimaryShell();
+    nsCOMPtr<nsIPresShell> shell = GetShell();
     if (shell) {
-
         // Resize-reflow this time
         nsPresContext *cx = shell->GetPresContext();
         NS_ASSERTION(cx != nsnull, "no pres context");
         if (! cx)
             return NS_ERROR_UNEXPECTED;
 
         nsCOMPtr<nsISupports> container = cx->GetContainer();
         NS_ASSERTION(container != nsnull, "pres context has no container");
@@ -3891,17 +3889,17 @@ nsXULDocument::AddPrototypeSheets()
 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;
 
-    nsIPresShell *shell = mDocument->GetPrimaryShell();
+    nsIPresShell *shell = mDocument->GetShell();
     PRBool notify = shell && shell->DidInitialReflow();
 
     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.
         Element* root = mDocument->GetRootElement();
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -7840,17 +7840,17 @@ nsEventTargetSH::PreserveWrapper(nsISupp
 
 static PRBool
 GetBindingURL(Element *aElement, nsIDocument *aDocument,
               nsCSSValue::URL **aResult)
 {
   // If we have a frame the frame has already loaded the binding.  And
   // otherwise, don't do anything else here unless we're dealing with
   // XUL.
-  nsIPresShell *shell = aDocument->GetPrimaryShell();
+  nsIPresShell *shell = aDocument->GetShell();
   if (!shell || aElement->GetPrimaryFrame() || !aElement->IsXUL()) {
     *aResult = nsnull;
 
     return PR_TRUE;
   }
 
   // Get the computed -moz-binding directly from the style context
   nsPresContext *pctx = shell->GetPresContext();
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -473,17 +473,17 @@ nsDOMWindowUtils::GetWidget(nsPoint* aOf
 nsIWidget*
 nsDOMWindowUtils::GetWidgetForElement(nsIDOMElement* aElement)
 {
   if (!aElement)
     return GetWidget();
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
   nsIDocument* doc = content->GetCurrentDoc();
-  nsIPresShell* presShell = doc ? doc->GetPrimaryShell() : nsnull;
+  nsIPresShell* presShell = doc ? doc->GetShell() : nsnull;
 
   if (presShell) {
     nsIFrame* frame = content->GetPrimaryFrame();
     if (!frame) {
       frame = presShell->GetRootFrame();
     }
     if (frame)
       return frame->GetWindow();
@@ -779,17 +779,17 @@ nsDOMWindowUtils::GetScrollXY(PRBool aFl
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(mWindow->GetExtantDocument()));
   NS_ENSURE_STATE(doc);
 
   if (aFlushLayout) {
     doc->FlushPendingNotifications(Flush_Layout);
   }
 
   nsPoint scrollPos(0,0);
-  nsIPresShell *presShell = doc->GetPrimaryShell();
+  nsIPresShell *presShell = doc->GetShell();
   if (presShell) {
     nsIScrollableFrame* sf = presShell->GetRootScrollFrameAsScrollable();
     if (sf) {
       scrollPos = sf->GetScrollPosition();
     }
   }
 
   *aScrollX = nsPresContext::AppUnitsToIntCSSPixels(scrollPos.x);
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -1330,17 +1330,17 @@ nsFocusManager::CheckIfFocusable(nsICont
   // can't focus elements that are not in documents
   if (!doc)
     return nsnull;
 
   // Make sure that our frames are up to date
   if (doc)
     doc->FlushPendingNotifications(Flush_Frames);
 
-  nsIPresShell *shell = doc->GetPrimaryShell();
+  nsIPresShell *shell = doc->GetShell();
   if (!shell)
     return nsnull;
 
   // the root content can always be focused
   if (aContent == doc->GetRootElement())
     return aContent;
 
   // cannot focus content in print preview mode. Only the root can be focused.
@@ -2174,17 +2174,17 @@ nsFocusManager::DetermineElementToMoveFo
   if (aType == MOVEFOCUS_BACKWARDDOC) {
     NS_IF_ADDREF(*aNextContent = GetNextTabbableDocument(PR_FALSE));
     return NS_OK;
   }
   
   nsIContent* rootContent = doc->GetRootElement();
   NS_ENSURE_TRUE(rootContent, NS_OK);
 
-  nsIPresShell *presShell = doc->GetPrimaryShell();
+  nsIPresShell *presShell = doc->GetShell();
   NS_ENSURE_TRUE(presShell, NS_OK);
 
   if (aType == MOVEFOCUS_FIRST) {
     if (!aStartContent)
       startContent = rootContent;
     return GetNextTabbableContent(presShell, startContent,
                                   nsnull, startContent,
                                   PR_TRUE, 1, PR_FALSE, aNextContent);
@@ -2394,17 +2394,17 @@ nsFocusManager::DetermineElementToMoveFo
       docShell = do_QueryInterface(docShellParent);
       NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
       nsCOMPtr<nsPIDOMWindow> piParentWindow = do_GetInterface(docShellParent);
       NS_ENSURE_TRUE(piParentWindow, NS_ERROR_FAILURE);
       doc = do_QueryInterface(piParentWindow->GetExtantDocument());
       NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
-      presShell = doc->GetPrimaryShell();
+      presShell = doc->GetShell();
 
       rootContent = doc->GetRootElement();
       startContent = do_QueryInterface(piWindow->GetFrameElementInternal());
       if (startContent) {
         nsIFrame* frame = startContent->GetPrimaryFrame();
         if (!frame)
           return NS_OK;
 
@@ -2608,17 +2608,17 @@ nsFocusManager::GetNextTabbableContent(n
                   }
                   if (*aResultContent) {
                     NS_ADDREF(*aResultContent);
                     return NS_OK;
                   }
                 }
               }
               Element* rootElement = subdoc->GetRootElement();
-              nsIPresShell* subShell = subdoc->GetPrimaryShell();
+              nsIPresShell* subShell = subdoc->GetShell();
               if (rootElement && subShell) {
                 rv = GetNextTabbableContent(subShell, rootElement,
                                             aOriginalStartContent, rootElement,
                                             aForward, (aForward ? 1 : 0),
                                             PR_FALSE, aResultContent);
                 NS_ENSURE_SUCCESS(rv, rv);
                 if (*aResultContent)
                   return NS_OK;
@@ -2972,17 +2972,17 @@ nsFocusManager::GetNextTabbableDocument(
     if (doc && !doc->EventHandlingSuppressed()) {
       content = GetRootForFocus(nextFrame, doc, PR_TRUE, PR_TRUE);
       if (content && !GetRootForFocus(nextFrame, doc, PR_FALSE, PR_FALSE)) {
         // if the found content is in a chrome shell or a frameset, navigate
         // forward one tabbable item so that the first item is focused. Note
         // that we always go forward and not back here.
         nsCOMPtr<nsIContent> nextFocus;
         Element* rootElement = doc->GetRootElement();
-        nsIPresShell* presShell = doc->GetPrimaryShell();
+        nsIPresShell* presShell = doc->GetShell();
         if (presShell) {
           nsresult rv = GetNextTabbableContent(presShell, rootElement,
                                                nsnull, rootElement,
                                                PR_TRUE, 1, PR_FALSE,
                                                getter_AddRefs(nextFocus));
           return NS_SUCCEEDED(rv) ? nextFocus.get() : nsnull;
         }
       }
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -5514,17 +5514,17 @@ PostMessageEvent::Run()
     return NS_OK;
 
 
   // We can't simply call dispatchEvent on the window because doing so ends
   // up flipping the trusted bit on the event, and we don't want that to
   // happen because then untrusted content can call postMessage on a chrome
   // window if it can get a reference to it.
 
-  nsIPresShell *shell = targetWindow->mDoc->GetPrimaryShell();
+  nsIPresShell *shell = targetWindow->mDoc->GetShell();
   nsRefPtr<nsPresContext> presContext;
   if (shell)
     presContext = shell->GetPresContext();
 
   nsCOMPtr<nsIPrivateDOMEvent> privEvent = do_QueryInterface(message);
   privEvent->SetTrusted(mTrustedCaller);
   nsEvent *internalEvent = privEvent->GetInternalNSEvent();
 
@@ -6698,17 +6698,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->GetPrimaryShell();
+  nsIPresShell *shell = mDoc->GetShell();
   nsRefPtr<nsPresContext> presContext;
   if (shell) {
     // Retrieve the context
     presContext = shell->GetPresContext();
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   nsresult rv =
@@ -7294,17 +7294,17 @@ nsGlobalWindow::DispatchSyncPopState()
 
     nsCOMPtr<nsIXPConnect> xpconnect = do_GetService(nsIXPConnect::GetCID());
     NS_ENSURE_TRUE(xpconnect, NS_ERROR_FAILURE);
     rv = xpconnect->JSValToVariant(cx, &jsStateObj, getter_AddRefs(stateObj));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Obtain a presentation shell for use in creating a popstate event.
-  nsIPresShell *shell = mDoc->GetPrimaryShell();
+  nsIPresShell *shell = mDoc->GetShell();
   nsRefPtr<nsPresContext> presContext;
   if (shell) {
     presContext = shell->GetPresContext();
   }
 
   // Create a new popstate event
   nsCOMPtr<nsIDOMEvent> domEvent;
   rv = nsEventDispatcher::CreateEvent(presContext, nsnull,
--- a/dom/base/nsHistory.cpp
+++ b/dom/base/nsHistory.cpp
@@ -242,18 +242,17 @@ nsHistory::Go(PRInt32 aDelta)
       // 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->GetPrimaryShell()) &&
-          (pcx = shell->GetPresContext())) {
+      if (doc && (shell = doc->GetShell()) && (pcx = shell->GetPresContext())) {
         pcx->RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
       }
 
       return NS_OK;
     }
   }
 
   nsCOMPtr<nsISHistory> session_history;
--- a/dom/base/nsLocation.cpp
+++ b/dom/base/nsLocation.cpp
@@ -789,18 +789,17 @@ nsLocation::Reload(PRBool aForceget)
     // 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->GetPrimaryShell()) &&
-        (pcx = shell->GetPresContext())) {
+    if (doc && (shell = doc->GetShell()) && (pcx = shell->GetPresContext())) {
       pcx->RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
     }
 
     return NS_OK;
   }
 
   if (webNav) {
     PRUint32 reloadFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
--- 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->GetPrimaryShell();
+    nsIPresShell *presShell = doc->GetShell();
     if (!presShell)
       return NS_OK;
     nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
     nsIFrame* frame = nsnull;
 #if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
     frame = tgContent->GetDocument() == presShell->GetDocument() ?
       tgContent->GetPrimaryFrame() : nsnull;
     if (frame)
@@ -581,17 +581,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->GetPrimaryShell();
+  nsIPresShell *presShell = doc->GetShell();
   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 if (tgContent->GetDocument() == presShell->GetDocument()) {
--- a/embedding/components/find/src/nsWebBrowserFind.cpp
+++ b/embedding/components/find/src/nsWebBrowserFind.cpp
@@ -390,17 +390,17 @@ IsInNativeAnonymousSubtree(nsIContent* a
 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->GetPrimaryShell();
+  nsIPresShell* presShell = doc->GetShell();
   if (!presShell) return;
 
   nsCOMPtr<nsIDOMNode> node;
   aRange->GetStartContainer(getter_AddRefs(node));
   nsCOMPtr<nsIContent> content(do_QueryInterface(node));
   nsIFrame* frame = content->GetPrimaryFrame();
   if (!frame)
       return;
@@ -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->GetPrimaryShell();
+    nsIPresShell* presShell = doc->GetShell();
     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;
     nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
--- 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) {
-      presShell = doc->GetPrimaryShell();
+      presShell = doc->GetShell();
     }
   }
   //return  NS_OK;
   /*
   if (presShell && eventNameStr.EqualsLiteral("click")) {
     nsCOMPtr<nsISelection> domSelection;
     presShell->FrameSelection()->GetSelection(nsISelectionController::SELECTION_NORMAL,
                             getter_AddRefs(domSelection));
--- a/extensions/widgetutils/src/nsWidgetUtils.cpp
+++ b/extensions/widgetutils/src/nsWidgetUtils.cpp
@@ -206,17 +206,17 @@ nsWidgetUtils::UpdateFromEvent(nsIDOMEve
   if (!mWindow)
     return NS_OK;
   nsCOMPtr<nsIDocument> doc;
   nsCOMPtr<nsIDOMDocument> domDoc;
   mWindow->GetDocument(getter_AddRefs(domDoc));
   doc = do_QueryInterface(domDoc);
   if (!doc) return NS_OK;
   // the only case where there could be more shells in printpreview
-  nsIPresShell *shell = doc->GetPrimaryShell();
+  nsIPresShell *shell = doc->GetShell();
   NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
   mViewManager = shell->GetViewManager();
   NS_ENSURE_TRUE(mViewManager, NS_ERROR_FAILURE);
   mViewManager->GetRootWidget(getter_AddRefs(mWidget));
   NS_ENSURE_TRUE(mWidget, NS_ERROR_FAILURE);
   return NS_OK;
 }
 
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2434,17 +2434,17 @@ DocumentViewerImpl::CreateDeviceContext(
   NS_PRECONDITION(!mPresShell && !mWindow,
                   "This will screw up our existing presentation");
   NS_PRECONDITION(mDocument, "Gotta have a document here");
   
   nsIDocument* doc = mDocument->GetDisplayDocument();
   if (doc) {
     NS_ASSERTION(!aContainerView, "External resource document embedded somewhere?");
     // We want to use our display document's device context if possible
-    nsIPresShell* shell = doc->GetPrimaryShell();
+    nsIPresShell* shell = doc->GetShell();
     if (shell) {
       nsPresContext* ctx = shell->GetPresContext();
       if (ctx) {
         mDeviceContext = ctx->DeviceContext();
         return NS_OK;
       }
     }
   }
@@ -2758,33 +2758,33 @@ SetChildFullZoom(nsIMarkupDocumentViewer
   struct ZoomInfo* ZoomInfo = (struct ZoomInfo*) aClosure;
   aChild->SetFullZoom(ZoomInfo->mZoom);
 }
 
 static PRBool
 SetExtResourceTextZoom(nsIDocument* aDocument, void* aClosure)
 {
   // Would it be better to enumerate external resource viewers instead?
-  nsIPresShell* shell = aDocument->GetPrimaryShell();
+  nsIPresShell* shell = aDocument->GetShell();
   if (shell) {
     nsPresContext* ctxt = shell->GetPresContext();
     if (ctxt) {
       struct ZoomInfo* ZoomInfo = static_cast<struct ZoomInfo*>(aClosure);
       ctxt->SetTextZoom(ZoomInfo->mZoom);
     }
   }
 
   return PR_TRUE;
 }
 
 static PRBool
 SetExtResourceFullZoom(nsIDocument* aDocument, void* aClosure)
 {
   // Would it be better to enumerate external resource viewers instead?
-  nsIPresShell* shell = aDocument->GetPrimaryShell();
+  nsIPresShell* shell = aDocument->GetShell();
   if (shell) {
     nsPresContext* ctxt = shell->GetPresContext();
     if (ctxt) {
       struct ZoomInfo* ZoomInfo = static_cast<struct ZoomInfo*>(aClosure);
       ctxt->SetFullZoom(ZoomInfo->mZoom);
     }
   }
 
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1907,17 +1907,17 @@ PresShell::Destroy()
   }
 
   mStyleSet->BeginShutdown(mPresContext);
 
   // This shell must be removed from the document before the frame
   // hierarchy is torn down to avoid finding deleted frames through
   // this presshell while the frames are being torn down
   if (mDocument) {
-    NS_ASSERTION(mDocument->GetPrimaryShell() == this, "Wrong shell?");
+    NS_ASSERTION(mDocument->GetShell() == this, "Wrong shell?");
     mDocument->DeleteShell();
   }
 
   nsRefreshDriver* rd = GetPresContext()->RefreshDriver();
 #ifdef MOZ_SMIL
   if (mDocument->HasAnimationController()) {
     mDocument->GetAnimationController()->StopSampling(rd);
   }
@@ -6132,17 +6132,17 @@ PresShell::HandleEvent(nsIView         *
         return NS_OK;
     } else if (capturingContent) {
       // if the mouse is being captured then retarget the mouse event at the
       // document that is being captured.
       retargetEventDoc = capturingContent->GetCurrentDoc();
     }
 
     if (retargetEventDoc) {
-      nsIPresShell* presShell = retargetEventDoc->GetPrimaryShell();
+      nsIPresShell* presShell = retargetEventDoc->GetShell();
       if (!presShell)
         return NS_OK;
 
       if (presShell != this) {
         nsCOMPtr<nsIViewObserver> viewObserver = do_QueryInterface(presShell);
         if (!viewObserver)
           return NS_ERROR_FAILURE;
 
@@ -7129,17 +7129,17 @@ FreezeElement(nsIContent *aContent, void
   if (objectFrame) {
     objectFrame->StopPlugin();
   }
 }
 
 static PRBool
 FreezeSubDocument(nsIDocument *aDocument, void *aData)
 {
-  nsIPresShell *shell = aDocument->GetPrimaryShell();
+  nsIPresShell *shell = aDocument->GetShell();
   if (shell)
     shell->Freeze();
 
   return PR_TRUE;
 }
 
 void
 PresShell::Freeze()
@@ -7194,17 +7194,17 @@ ThawElement(nsIContent *aContent, void *
     nsCOMPtr<nsIPluginInstance> inst;
     objlc->EnsureInstantiation(getter_AddRefs(inst));
   }
 }
 
 static PRBool
 ThawSubDocument(nsIDocument *aDocument, void *aData)
 {
-  nsIPresShell *shell = aDocument->GetPrimaryShell();
+  nsIPresShell *shell = aDocument->GetShell();
   if (shell)
     shell->Thaw();
 
   return PR_TRUE;
 }
 
 void
 PresShell::Thaw()
--- a/layout/inspector/src/inDOMUtils.cpp
+++ b/layout/inspector/src/inDOMUtils.cpp
@@ -275,17 +275,17 @@ inDOMUtils::GetRuleNodeForContent(nsICon
 
   if (!aContent->IsElement()) {
     return NS_ERROR_UNEXPECTED;
   }
 
   nsIDocument* doc = aContent->GetDocument();
   NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
 
-  nsIPresShell *presShell = doc->GetPrimaryShell();
+  nsIPresShell *presShell = doc->GetShell();
   NS_ENSURE_TRUE(presShell, NS_ERROR_UNEXPECTED);
 
   nsPresContext *presContext = presShell->GetPresContext();
   NS_ENSURE_TRUE(presContext, NS_ERROR_UNEXPECTED);
 
   PRBool safe = presContext->EnsureSafeToHandOutCSSRules();
   NS_ENSURE_TRUE(safe, NS_ERROR_OUT_OF_MEMORY);
 
--- a/layout/inspector/src/inLayoutUtils.cpp
+++ b/layout/inspector/src/inLayoutUtils.cpp
@@ -99,17 +99,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->GetPrimaryShell();
+  nsIPresShell *shell = doc->GetShell();
   if (!shell)
     return nsnull;
 
   return shell->GetPresContext()->EventStateManager();
 }
 
 nsBindingManager* 
 inLayoutUtils::GetBindingManagerFor(nsIDOMNode* aNode)
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -2236,18 +2236,18 @@ static nsresult CloneRangeToSelection(ns
   rv = range->SetEnd(newEnd, endOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return aSelection->AddRange(range);
 }
 
 static nsresult CloneSelection(nsIDocument* aOrigDoc, nsIDocument* aDoc)
 {
-  nsIPresShell* origShell = aOrigDoc->GetPrimaryShell();
-  nsIPresShell* shell = aDoc->GetPrimaryShell();
+  nsIPresShell* origShell = aOrigDoc->GetShell();
+  nsIPresShell* shell = aDoc->GetShell();
   NS_ENSURE_STATE(origShell && shell);
 
   nsCOMPtr<nsISelection> origSelection =
     origShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
   nsCOMPtr<nsISelection> selection =
     shell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
   NS_ENSURE_STATE(origSelection && selection);
 
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -403,17 +403,17 @@ nsComputedDOMStyle::GetStyleContextForEl
 /* static */
 nsIPresShell*
 nsComputedDOMStyle::GetPresShellForContent(nsIContent* aContent)
 {
   nsIDocument* currentDoc = aContent->GetCurrentDoc();
   if (!currentDoc)
     return nsnull;
 
-  return currentDoc->GetPrimaryShell();
+  return currentDoc->GetShell();
 }
 
 NS_IMETHODIMP
 nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName,
                                         nsIDOMCSSValue** aReturn)
 {
   NS_ASSERTION(!mStyleContextHolder, "bad state");
 
@@ -450,17 +450,17 @@ nsComputedDOMStyle::GetPropertyCSSValue(
   // we're computing style in, not on the document mContent is in -- the two
   // may be different.
   document->FlushPendingNotifications(
     propEntry->mNeedsLayoutFlush ? Flush_Layout : Flush_Style);
 #ifdef DEBUG
   mFlushedPendingReflows = propEntry->mNeedsLayoutFlush;
 #endif
 
-  mPresShell = document->GetPrimaryShell();
+  mPresShell = document->GetShell();
   NS_ENSURE_TRUE(mPresShell && mPresShell->GetPresContext(),
                  NS_ERROR_NOT_AVAILABLE);
 
   mOuterFrame = mContent->GetPrimaryFrame();
   mInnerFrame = mOuterFrame;
   if (mOuterFrame && !mPseudo) {
     nsIAtom* type = mOuterFrame->GetType();
     if (type == nsGkAtoms::tableOuterFrame) {
@@ -1174,17 +1174,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->GetPrimaryShell();
+  nsIPresShell* presShell = doc->GetShell();
   NS_ASSERTION(presShell, "pres shell is required");
   nsPresContext *presContext = presShell->GetPresContext();
   NS_ASSERTION(presContext, "pres context is required");
 
   const nsString& fontName = font->mFont.name;
   if (font->mGenericID == kGenericFont_NONE && !font->mFont.systemFont) {
     const nsFont* defaultFont =
       presContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID);
--- a/layout/style/nsHTMLStyleSheet.cpp
+++ b/layout/style/nsHTMLStyleSheet.cpp
@@ -454,30 +454,30 @@ nsHTMLStyleSheet::Reset(nsIURI* aURL)
     mMappedAttrTable.ops = nsnull;
   }
 }
 
 nsresult
 nsHTMLStyleSheet::ImplLinkColorSetter(nsRefPtr<HTMLColorRule>& aRule, nscolor aColor)
 {
   if (aRule && aRule->mColor == aColor) {
-      return NS_OK;
+    return NS_OK;
   }
 
   aRule = new HTMLColorRule();
   if (!aRule)
     return NS_ERROR_OUT_OF_MEMORY;
 
   aRule->mColor = aColor;
   // Now make sure we restyle any links that might need it.  This
   // shouldn't happen often, so just rebuilding everything is ok.
-  if (mDocument && mDocument->GetPrimaryShell()) {
+  if (mDocument && mDocument->GetShell()) {
     Element* root = mDocument->GetRootElement();
     if (root) {
-      mDocument->GetPrimaryShell()->FrameConstructor()->
+      mDocument->GetShell()->FrameConstructor()->
         PostRestyleEvent(root, eRestyle_Subtree, NS_STYLE_HINT_NONE);
     }
   }
   return NS_OK;
 }
 
 nsresult
 nsHTMLStyleSheet::SetLinkColor(nscolor aColor)
--- a/layout/style/nsStyleAnimation.cpp
+++ b/layout/style/nsStyleAnimation.cpp
@@ -976,17 +976,17 @@ BuildStyleRule(nsCSSProperty aProperty,
   return styleRule.forget();
 }
 
 inline
 already_AddRefed<nsStyleContext>
 LookupStyleContext(nsIContent* aElement)
 {
   nsIDocument* doc = aElement->GetCurrentDoc();
-  nsIPresShell* shell = doc->GetPrimaryShell();
+  nsIPresShell* shell = doc->GetShell();
   if (!shell) {
     return nsnull;
   }
   return nsComputedDOMStyle::GetStyleContextForElement(aElement->AsElement(),
                                                        nsnull, shell);
 }
 
 
--- a/layout/svg/base/src/nsSVGEffects.cpp
+++ b/layout/svg/base/src/nsSVGEffects.cpp
@@ -110,17 +110,17 @@ nsSVGRenderingObserver::GetReferencedFra
                    static_cast<nsGenericElement*>(mElement.get())->GetPrimaryFrame() == mReferencedFrame,
                    "Cached frame is incorrect!");
     }
     return mReferencedFrame;
   }
 
   if (mElement.get()) {
     nsIDocument* doc = mElement.get()->GetCurrentDoc();
-    nsIPresShell* shell = doc ? doc->GetPrimaryShell() : nsnull;
+    nsIPresShell* shell = doc ? doc->GetShell() : nsnull;
     if (shell && !shell->FrameManager()->IsDestroyingFrames()) {
       nsIFrame* frame = mElement.get()->GetPrimaryFrame();
       if (frame) {
         mReferencedFrame = frame;
         mReferencedFramePresShell = shell;
         nsSVGEffects::AddRenderingObserver(mReferencedFrame, this);
         return frame;
       }
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -555,17 +555,17 @@ nsSVGUtils::GetCTM(nsSVGElement *aElemen
       return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
     }
     return matrix * GetCTM(static_cast<nsSVGElement*>(ancestor), PR_TRUE);
   }
   // XXX this does not take into account CSS transform, or that the non-SVG
   // content that we've hit may itself be inside an SVG foreignObject higher up
   float x = 0.0f, y = 0.0f;
   if (currentDoc && element->NodeInfo()->Equals(nsGkAtoms::svg, kNameSpaceID_SVG)) {
-    nsIPresShell *presShell = currentDoc->GetPrimaryShell();
+    nsIPresShell *presShell = currentDoc->GetShell();
     if (presShell) {
       nsIFrame* frame = element->GetPrimaryFrame();
       nsIFrame* ancestorFrame = presShell->GetRootFrame();
       if (frame && ancestorFrame) {
         nsPoint point = frame->GetOffsetTo(ancestorFrame);
         x = nsPresContext::AppUnitsToFloatCSSPixels(point.x);
         y = nsPresContext::AppUnitsToFloatCSSPixels(point.y);
       }
--- a/layout/xul/base/src/nsBoxObject.cpp
+++ b/layout/xul/base/src/nsBoxObject.cpp
@@ -177,17 +177,17 @@ nsBoxObject::GetPresShell(PRBool aFlushL
   if (!doc) {
     return nsnull;
   }
 
   if (aFlushLayout) {
     doc->FlushPendingNotifications(Flush_Layout);
   }
 
-  return doc->GetPrimaryShell();
+  return doc->GetShell();
 }
 
 nsresult 
 nsBoxObject::GetOffsetRect(nsIntRect& aRect)
 {
   aRect.SetRect(0, 0, 0, 0);
  
   if (!mContent)
--- a/layout/xul/base/src/nsImageBoxFrame.cpp
+++ b/layout/xul/base/src/nsImageBoxFrame.cpp
@@ -106,17 +106,17 @@ private:
 NS_IMETHODIMP
 nsImageBoxFrameEvent::Run()
 {
   nsIDocument* doc = mContent->GetOwnerDoc();
   if (!doc) {
     return NS_OK;
   }
 
-  nsIPresShell *pres_shell = doc->GetPrimaryShell();
+  nsIPresShell *pres_shell = doc->GetShell();
   if (!pres_shell) {
     return NS_OK;
   }
 
   nsRefPtr<nsPresContext> pres_context = pres_shell->GetPresContext();
   if (!pres_context) {
     return NS_OK;
   }
--- a/layout/xul/base/src/nsMenuPopupFrame.cpp
+++ b/layout/xul/base/src/nsMenuPopupFrame.cpp
@@ -965,17 +965,17 @@ nsMenuPopupFrame::SetPopupPosition(nsIFr
 
   // if the frame is not specified, use the anchor node passed to OpenPopup. If
   // that wasn't specified either, use the root frame. Note that mAnchorContent
   // might be a different document so its presshell must be used.
   if (!aAnchorFrame) {
     if (mAnchorContent) {
       nsCOMPtr<nsIDocument> document = mAnchorContent->GetDocument();
       if (document) {
-        nsIPresShell *shell = document->GetPrimaryShell();
+        nsIPresShell *shell = document->GetShell();
         if (!shell)
           return NS_ERROR_FAILURE;
 
         aAnchorFrame = mAnchorContent->GetPrimaryFrame();
       }
     }
 
     if (!aAnchorFrame) {
--- a/layout/xul/base/src/nsXULPopupManager.cpp
+++ b/layout/xul/base/src/nsXULPopupManager.cpp
@@ -277,17 +277,17 @@ nsXULPopupManager::AdjustPopupsOnWindowC
 nsIFrame*
 nsXULPopupManager::GetFrameOfTypeForContent(nsIContent* aContent,
                                             nsIAtom* aFrameType,
                                             PRBool aShouldFlush)
 {
   if (aShouldFlush) {
     nsIDocument *document = aContent->GetCurrentDoc();
     if (document) {
-      nsCOMPtr<nsIPresShell> presShell = document->GetPrimaryShell();
+      nsCOMPtr<nsIPresShell> presShell = document->GetShell();
       if (presShell)
         presShell->FlushPendingNotifications(Flush_Frames);
     }
   }
 
   nsIFrame* frame = aContent->GetPrimaryFrame();
   return (frame && frame->GetType() == aFrameType) ? frame : nsnull;
 }
@@ -339,17 +339,17 @@ nsXULPopupManager::SetTriggerEvent(nsIDO
     nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aEvent));
     if (privateEvent) {
       NS_ASSERTION(aPopup, "Expected a popup node");
       nsEvent* event;
       event = privateEvent->GetInternalNSEvent();
       if (event) {
         nsIDocument* doc = aPopup->GetCurrentDoc();
         if (doc) {
-          nsIPresShell* presShell = doc->GetPrimaryShell();
+          nsIPresShell* presShell = doc->GetShell();
           if (presShell && presShell->GetPresContext()) {
             nsPresContext* rootDocPresContext =
               presShell->GetPresContext()->GetRootPresContext();
             if (!rootDocPresContext)
               return;
             nsIFrame* rootDocumentRootFrame = rootDocPresContext->
                 PresShell()->FrameManager()->GetRootFrame();
             if ((event->eventStructType == NS_MOUSE_EVENT || 
@@ -540,17 +540,17 @@ CheckCaretDrawingState() {
 
     nsCOMPtr<nsIDOMDocument> domDoc;
     nsCOMPtr<nsIDocument> focusedDoc;
     windowInternal->GetDocument(getter_AddRefs(domDoc));
     focusedDoc = do_QueryInterface(domDoc);
     if (!focusedDoc)
       return;
 
-    nsIPresShell* presShell = focusedDoc->GetPrimaryShell();
+    nsIPresShell* presShell = focusedDoc->GetShell();
     if (!presShell)
       return;
 
     nsRefPtr<nsCaret> caret = presShell->GetCaret();
     if (!caret)
       return;
     caret->CheckCaretDrawingState();
   }
@@ -2019,17 +2019,17 @@ nsXULPopupManager::KeyPress(nsIDOMEvent*
   return NS_OK; // I am consuming event
 }
 
 static nsPresContext*
 GetPresContextFor(nsIContent* aContent)
 {
   nsIDocument *document = aContent->GetCurrentDoc();
   if (document) {
-    nsIPresShell* presShell = document->GetPrimaryShell();
+    nsIPresShell* presShell = document->GetShell();
     if (presShell)
       return presShell->GetPresContext();
   }
 
   return nsnull;
 }
 
 NS_IMETHODIMP
--- a/layout/xul/base/src/nsXULTooltipListener.cpp
+++ b/layout/xul/base/src/nsXULTooltipListener.cpp
@@ -624,17 +624,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->GetPrimaryShell());
+    nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetShell());
     NS_ENSURE_STATE(rootBox);
     *aTooltip = rootBox->GetDefaultTooltip();
     if (*aTooltip) {
       NS_ADDREF(*aTooltip);
       (*aTooltip)->SetAttr(kNameSpaceID_None, nsGkAtoms::label, tooltipText, PR_TRUE);
     }
     return NS_OK;
   }
@@ -659,17 +659,17 @@ nsXULTooltipListener::FindTooltip(nsICon
       *aTooltip = tooltipEl.forget().get();
       return NS_OK;
     }
   }
 
 #ifdef MOZ_XUL
   // titletips should just use the default tooltip
   if (mIsSourceTree && mNeedTitletip) {
-    nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetPrimaryShell());
+    nsIRootBox* rootBox = nsIRootBox::GetRootBox(document->GetShell());
     NS_ENSURE_STATE(rootBox);
     NS_IF_ADDREF(*aTooltip = rootBox->GetDefaultTooltip());
   }
 #endif
 
   return NS_OK;
 }
 
--- a/modules/plugin/base/src/nsPluginHost.cpp
+++ b/modules/plugin/base/src/nsPluginHost.cpp
@@ -273,17 +273,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->GetPrimaryShell();
+      nsIPresShell *shell = doc->GetShell();
 
       // 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.
          * We do not want to completely reload all the documents that had running plugins
--- a/parser/html/nsHtml5TreeBuilderCppSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h
@@ -499,17 +499,17 @@ nsHtml5TreeBuilder::elementPopped(PRInt3
       nsEvent event(PR_TRUE, NS_SVG_LOAD);
       event.eventStructType = NS_SVG_EVENT;
       event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
       // Do we care about forcing presshell creation if it hasn't happened yet?
       // That is, should this code flush or something?  Does it really matter?
       // For that matter, do we really want to try getting the prescontext?  Does
       // this event ever want one?
       nsRefPtr<nsPresContext> ctx;
-      nsCOMPtr<nsIPresShell> shell = parser->GetDocument()->GetPrimaryShell();
+      nsCOMPtr<nsIPresShell> shell = parser->GetDocument()->GetShell();
       if (shell) {
         ctx = shell->GetPresContext();
       }
       nsEventDispatcher::Dispatch(aElement, ctx, &event);
     }
 #endif
     // TODO soft flush the op queue every now and then
     return;
--- a/widget/src/xpwidgets/nsBaseDragService.cpp
+++ b/widget/src/xpwidgets/nsBaseDragService.cpp
@@ -241,17 +241,17 @@ nsBaseDragService::InvokeDragSession(nsI
   mEndDragPoint = nsIntPoint(0, 0);
 
   // When the mouse goes down, the selection code starts a mouse
   // 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, so turn off mouse capture.
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(mSourceDocument);
   if (doc) {
-    nsCOMPtr<nsIViewObserver> viewObserver = do_QueryInterface(doc->GetPrimaryShell());
+    nsCOMPtr<nsIViewObserver> viewObserver = do_QueryInterface(doc->GetShell());
     if (viewObserver) {
       viewObserver->ClearMouseCapture(nsnull);
     }
   }
 
   return NS_OK;
 }
 
@@ -381,17 +381,17 @@ nsBaseDragService::EndDragSession(PRBool
 }
 
 NS_IMETHODIMP
 nsBaseDragService::FireDragEventAtSource(PRUint32 aMsg)
 {
   if (mSourceNode && !mSuppressLevel) {
     nsCOMPtr<nsIDocument> doc = do_QueryInterface(mSourceDocument);
     if (doc) {
-      nsCOMPtr<nsIPresShell> presShell = doc->GetPrimaryShell();
+      nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
       if (presShell) {
         nsEventStatus status = nsEventStatus_eIgnore;
         nsDragEvent event(PR_TRUE, aMsg, nsnull);
         event.inputSource = mInputSource;
         if (aMsg == NS_DRAGDROP_END) {
           event.refPoint.x = mEndDragPoint.x;
           event.refPoint.y = mEndDragPoint.y;
           event.userCancelled = mUserCancelled;
@@ -412,17 +412,17 @@ GetPresShellForContent(nsIDOMNode* aDOMN
   nsCOMPtr<nsIContent> content = do_QueryInterface(aDOMNode);
   if (!content)
     return nsnull;
 
   nsCOMPtr<nsIDocument> document = content->GetCurrentDoc();
   if (document) {
     document->FlushPendingNotifications(Flush_Display);
 
-    return document->GetPrimaryShell();
+    return document->GetShell();
   }
 
   return nsnull;
 }
 
 nsresult
 nsBaseDragService::DrawDrag(nsIDOMNode* aDOMNode,
                             nsIScriptableRegion* aRegion,