From 18fa617572e19a52d497fe9cbd2a03948ed7e792 Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Mon, 2 Aug 2004 04:52:55 +0000 Subject: [PATCH] Remove non-inlined version of nsIPresShell::GetDocument(). Bug 253889, r+sr=roc. --- accessible/src/base/nsAccessNode.cpp | 4 +- accessible/src/base/nsAccessible.cpp | 4 +- .../src/base/nsAccessibleTreeWalker.cpp | 7 +- accessible/src/base/nsCaretAccessible.cpp | 3 +- accessible/src/base/nsDocAccessible.cpp | 2 +- accessible/src/html/nsHTMLImageAccessible.cpp | 3 +- content/base/src/nsPrintEngine.cpp | 3 +- content/base/src/nsPrintObject.cpp | 114 ------------------ content/base/src/nsSelection.cpp | 16 +-- content/events/src/nsDOMEvent.cpp | 4 +- content/events/src/nsEventListenerManager.cpp | 3 +- content/events/src/nsEventStateManager.cpp | 16 +-- .../html/content/src/nsHTMLBodyElement.cpp | 3 +- content/html/style/src/nsHTMLStyleSheet.cpp | 4 +- docshell/base/nsDocShell.cpp | 18 +-- docshell/base/nsWebShell.cpp | 5 +- editor/libeditor/base/nsEditor.cpp | 6 +- editor/libeditor/html/nsHTMLEditor.cpp | 11 +- editor/libeditor/text/nsPlaintextEditor.cpp | 5 +- .../typeaheadfind/src/nsTypeAheadFind.cpp | 8 +- layout/base/nsCSSRendering.cpp | 5 +- layout/base/nsFrameManager.cpp | 6 +- layout/base/nsIPresShell.h | 5 +- layout/base/nsPresContext.cpp | 48 ++++---- layout/base/nsPresShell.cpp | 33 ++--- layout/base/public/nsIPresShell.h | 5 +- layout/base/src/nsPresContext.cpp | 48 ++++---- layout/forms/nsListControlFrame.cpp | 5 +- layout/forms/nsTextControlFrame.cpp | 6 +- layout/generic/nsBulletFrame.cpp | 3 +- layout/generic/nsContainerFrame.cpp | 3 +- layout/generic/nsGfxScrollFrame.cpp | 4 +- layout/generic/nsImageFrame.cpp | 7 +- layout/generic/nsObjectFrame.cpp | 35 +++--- layout/generic/nsSelection.cpp | 16 +-- layout/generic/nsTextFrame.cpp | 24 ++-- layout/html/base/src/nsBulletFrame.cpp | 3 +- layout/html/base/src/nsContainerFrame.cpp | 3 +- layout/html/base/src/nsFrameManager.cpp | 6 +- layout/html/base/src/nsGfxScrollFrame.cpp | 4 +- layout/html/base/src/nsImageFrame.cpp | 7 +- layout/html/base/src/nsObjectFrame.cpp | 35 +++--- layout/html/base/src/nsPresShell.cpp | 33 ++--- layout/html/base/src/nsTextFrame.cpp | 24 ++-- layout/html/forms/src/nsListControlFrame.cpp | 5 +- layout/html/forms/src/nsTextControlFrame.cpp | 6 +- layout/html/style/src/nsCSSRendering.cpp | 5 +- layout/printing/nsPrintEngine.cpp | 3 +- layout/printing/nsPrintObject.cpp | 2 +- layout/style/nsHTMLStyleSheet.cpp | 4 +- layout/xul/base/src/nsBoxFrame.cpp | 3 +- layout/xul/base/src/nsBoxObject.cpp | 6 +- layout/xul/base/src/nsImageBoxFrame.cpp | 3 +- layout/xul/base/src/nsMenuBarFrame.cpp | 10 +- layout/xul/base/src/nsMenuPopupFrame.cpp | 3 +- layout/xul/base/src/nsResizerFrame.cpp | 5 +- layout/xul/base/src/nsTitleBarFrame.cpp | 5 +- webshell/tests/viewer/nsBrowserWindow.cpp | 9 +- webshell/tests/viewer/nsViewerApp.cpp | 3 +- webshell/tests/viewer/nsXPBaseWindow.cpp | 6 +- 60 files changed, 200 insertions(+), 485 deletions(-) diff --git a/accessible/src/base/nsAccessNode.cpp b/accessible/src/base/nsAccessNode.cpp index bda4d9977cb..6247d0126c8 100755 --- a/accessible/src/base/nsAccessNode.cpp +++ b/accessible/src/base/nsAccessNode.cpp @@ -112,9 +112,7 @@ NS_IMETHODIMP nsAccessNode::Init() // Create a doc accessible so we can cache this node nsCOMPtr presShell(do_QueryReferent(mWeakShell)); if (presShell) { - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - nsCOMPtr docNode(do_QueryInterface(doc)); + nsCOMPtr docNode(do_QueryInterface(presShell->GetDocument())); if (docNode) { nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 6fed3334187..8c559b62fb3 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -683,9 +683,7 @@ void nsAccessible::GetScrollOffset(nsRect *aRect) { nsCOMPtr shell(do_QueryReferent(mWeakShell)); if (shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); - nsCOMPtr docView(do_QueryInterface(doc)); + nsCOMPtr docView(do_QueryInterface(shell->GetDocument())); if (!docView) return; diff --git a/accessible/src/base/nsAccessibleTreeWalker.cpp b/accessible/src/base/nsAccessibleTreeWalker.cpp index 3f7a89a3710..48a2a4f3750 100755 --- a/accessible/src/base/nsAccessibleTreeWalker.cpp +++ b/accessible/src/base/nsAccessibleTreeWalker.cpp @@ -59,11 +59,8 @@ nsAccessibleTreeWalker::nsAccessibleTreeWalker(nsIWeakReference* aPresShell, nsI if (aWalkAnonContent) { nsCOMPtr presShell(do_QueryReferent(mWeakShell)); - if (presShell) { - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - mBindingManager = doc->GetBindingManager(); - } + if (presShell) + mBindingManager = presShell->GetDocument()->GetBindingManager(); } MOZ_COUNT_CTOR(nsAccessibleTreeWalker); } diff --git a/accessible/src/base/nsCaretAccessible.cpp b/accessible/src/base/nsCaretAccessible.cpp index 1ed58a8e420..0c7733cb643 100644 --- a/accessible/src/base/nsCaretAccessible.cpp +++ b/accessible/src/base/nsCaretAccessible.cpp @@ -95,8 +95,7 @@ NS_IMETHODIMP nsCaretAccessible::AttachNewSelectionListener(nsIDOMNode *aCurrent if (!presShell) return NS_ERROR_FAILURE; - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc = presShell->GetDocument(); if (!doc) // we also should try to QI to document instead (necessary to do when node is a document) doc = do_QueryInterface(aCurrentNode); nsCOMPtr content(do_QueryInterface(aCurrentNode)); diff --git a/accessible/src/base/nsDocAccessible.cpp b/accessible/src/base/nsDocAccessible.cpp index 401546a3259..3bce7378088 100644 --- a/accessible/src/base/nsDocAccessible.cpp +++ b/accessible/src/base/nsDocAccessible.cpp @@ -90,7 +90,7 @@ nsDocAccessible::nsDocAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell) nsCOMPtr shell(do_QueryReferent(mWeakShell)); if (shell) { - shell->GetDocument(getter_AddRefs(mDocument)); + mDocument = shell->GetDocument(); nsIViewManager* vm = shell->GetViewManager(); if (vm) { nsCOMPtr widget; diff --git a/accessible/src/html/nsHTMLImageAccessible.cpp b/accessible/src/html/nsHTMLImageAccessible.cpp index c99cc5fe689..41d73e72aff 100644 --- a/accessible/src/html/nsHTMLImageAccessible.cpp +++ b/accessible/src/html/nsHTMLImageAccessible.cpp @@ -53,12 +53,11 @@ nsHTMLImageAccessible::nsHTMLImageAccessible(nsIDOMNode* aDOMNode, nsIWeakRefere nsLinkableAccessible(aDOMNode, aShell) { nsCOMPtr element(do_QueryInterface(aDOMNode)); - nsCOMPtr doc; nsCOMPtr shell(do_QueryReferent(mWeakShell)); if (!shell) return; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); nsAutoString mapElementName; if (doc && element) { diff --git a/content/base/src/nsPrintEngine.cpp b/content/base/src/nsPrintEngine.cpp index 868cfad576a..4adefb3df91 100644 --- a/content/base/src/nsPrintEngine.cpp +++ b/content/base/src/nsPrintEngine.cpp @@ -1744,8 +1744,7 @@ nsPrintEngine::IsParentAFrameSet(nsIWebShell * aParent) // only check to see if there is a frameset if there is // NO parent doc for this doc. meaning this parent is the root doc if (shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { nsIContent *rootContent = doc->GetRootContent(); if (rootContent) { diff --git a/content/base/src/nsPrintObject.cpp b/content/base/src/nsPrintObject.cpp index f60cbb2edd6..e69de29bb2d 100644 --- a/content/base/src/nsPrintObject.cpp +++ b/content/base/src/nsPrintObject.cpp @@ -1,114 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsPrintObject.h" -#include "imgIContainer.h" - -//--------------------------------------------------- -//-- nsPrintObject Class Impl -//--------------------------------------------------- -nsPrintObject::nsPrintObject() : - mFrameType(eFrame), mStyleSet(nsnull), - mRootView(nsnull), mContent(nsnull), - mSeqFrame(nsnull), mPageFrame(nsnull), mPageNum(-1), - mRect(0,0,0,0), mReflowRect(0,0,0,0), - mParent(nsnull), mHasBeenPrinted(PR_FALSE), mDontPrint(PR_TRUE), - mPrintAsIs(PR_FALSE), mSkippedPageEject(PR_FALSE), mSharedPresShell(PR_FALSE), mIsHidden(PR_FALSE), - mClipRect(-1,-1, -1, -1), - mImgAnimationMode(imgIContainer::kNormalAnimMode), - mDocTitle(nsnull), mDocURL(nsnull), mShrinkRatio(1.0), mXMost(0) -{ -} - - -nsPrintObject::~nsPrintObject() -{ - if (mPresContext) { - mPresContext->SetImageAnimationMode(mImgAnimationMode); - } - - for (PRInt32 i=0;iEndObservingDocument(); - mPresShell->Destroy(); - } - - if (mDocTitle) nsMemory::Free(mDocTitle); - if (mDocURL) nsMemory::Free(mDocURL); - -} - -//------------------------------------------------------------------ -// Resets PO by destroying the presentation -nsresult -nsPrintObject::Init(nsIWebShell* aWebShell) -{ - mWebShell = aWebShell; - - mDocShell = do_QueryInterface(mWebShell); - NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE); - - mDocShell->GetPresShell(getter_AddRefs(mDisplayPresShell)); - NS_ENSURE_TRUE(mDisplayPresShell, NS_ERROR_FAILURE); - - mDocShell->GetPresContext(getter_AddRefs(mDisplayPresContext)); - NS_ENSURE_TRUE(mDisplayPresContext, NS_ERROR_FAILURE); - - mDisplayPresShell->GetDocument(getter_AddRefs(mDocument)); - NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE); - - return NS_OK; -} - -//------------------------------------------------------------------ -// Resets PO by destroying the presentation -void -nsPrintObject::DestroyPresentation() -{ - mWindow = nsnull; - mPresContext = nsnull; - if (mPresShell) mPresShell->Destroy(); - mPresShell = nsnull; - mViewManager = nsnull; - mStyleSet = nsnull; -} - diff --git a/content/base/src/nsSelection.cpp b/content/base/src/nsSelection.cpp index e7164e86ff9..c845275de56 100644 --- a/content/base/src/nsSelection.cpp +++ b/content/base/src/nsSelection.cpp @@ -1635,8 +1635,7 @@ nsTypedSelection::ToStringWithFormat(const char * aFormatType, PRUint32 aFlags, return NS_ERROR_FAILURE; } - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); NS_ENSURE_SUCCESS(rv, rv); // Flags should always include OutputSelectionOnly if we're coming from here: @@ -3092,10 +3091,7 @@ NS_IMETHODIMP nsSelection::SelectAll() return NS_ERROR_FAILURE; } - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) - return rv; + nsIDocument *doc = shell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; rootContent = doc->GetRootContent(); @@ -7479,16 +7475,10 @@ nsTypedSelection::NotifySelectionListeners() PRInt32 cnt = mSelectionListeners.Count(); nsCOMPtr domdoc; - nsCOMPtr doc; nsCOMPtr shell; nsresult rv = GetPresShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) - { - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) - doc = 0; - domdoc = do_QueryInterface(doc); - } + domdoc = do_QueryInterface(shell->GetDocument()); short reason = mFrameSelection->PopReason(); for (PRInt32 i = 0; i < cnt; i++) { diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 4713ea95b44..b9203ce325c 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -314,8 +314,8 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget) //Always want a target. Use document if nothing else. nsIPresShell *presShell; if (mPresContext && (presShell = mPresContext->GetPresShell())) { - nsCOMPtr doc; - if (NS_SUCCEEDED(presShell->GetDocument(getter_AddRefs(doc))) && doc) { + nsIDocument *doc = presShell->GetDocument(); + if (doc) { mTarget = do_QueryInterface(doc); if (mTarget) { *aTarget = mTarget; diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 7c524843373..fd7956398a3 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -1975,11 +1975,10 @@ nsEventListenerManager::FixContextMenuEvent(nsPresContext* aPresContext, // from the focus controller. nsCOMPtr currentTarget(aCurrentTarget); nsCOMPtr currentFocus; - nsCOMPtr doc; nsIPresShell* shell = aPresContext->PresShell(); if (aEvent->message == NS_CONTEXTMENU_KEY) { - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { nsCOMPtr privWindow = do_QueryInterface(doc->GetScriptGlobalObject()); if (privWindow) { diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index dd3665fa1d5..a2c9038f88f 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -1811,9 +1811,7 @@ nsEventStateManager::GetParentScrollingView(nsInputEvent *aEvent, if (!aEvent) return NS_ERROR_FAILURE; if (!aPresContext) return NS_ERROR_FAILURE; - nsCOMPtr doc; - aPresContext->PresShell()->GetDocument(getter_AddRefs(doc)); - + nsIDocument *doc = aPresContext->PresShell()->GetDocument(); NS_ASSERTION(doc, "No document in prescontext!"); nsIDocument *parentDoc = doc->GetParentDocument(); @@ -3039,8 +3037,7 @@ PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel) parentAsDocShell->GetPresShell(getter_AddRefs(presShell)); nsCOMPtr presContext; parentAsDocShell->GetPresContext(getter_AddRefs(presContext)); - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); nsCOMPtr domwin(do_QueryInterface(doc->GetScriptGlobalObject())); @@ -3327,9 +3324,7 @@ nsEventStateManager::ShiftFocusInternal(PRBool aForward, nsIContent* aStart) nsCOMPtr parentShell; parentDS->GetPresShell(getter_AddRefs(parentShell)); - nsCOMPtr parent_doc; - parentShell->GetDocument(getter_AddRefs(parent_doc)); - + nsIDocument *parent_doc = parentShell->GetDocument(); nsIContent *docContent = parent_doc->FindContentForSubDocument(mDocument); nsCOMPtr parentPC; @@ -4431,7 +4426,7 @@ void nsEventStateManager::EnsureDocument(nsIPresShell* aPresShell) { if (!mDocument && aPresShell) - aPresShell->GetDocument(getter_AddRefs(mDocument)); + mDocument = aPresShell->GetDocument(); } void @@ -4963,8 +4958,7 @@ nsEventStateManager::IsFrameSetDoc(nsIDocShell* aDocShell) nsCOMPtr presShell; aDocShell->GetPresShell(getter_AddRefs(presShell)); if (presShell) { - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); nsCOMPtr htmlDoc = do_QueryInterface(doc); if (htmlDoc) { nsIContent *rootContent = doc->GetRootContent(); diff --git a/content/html/content/src/nsHTMLBodyElement.cpp b/content/html/content/src/nsHTMLBodyElement.cpp index 352cafe93ce..0add2e30ea7 100644 --- a/content/html/content/src/nsHTMLBodyElement.cpp +++ b/content/html/content/src/nsHTMLBodyElement.cpp @@ -450,8 +450,7 @@ void MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aD // When display if first asked for, go ahead and get our colors set up. nsIPresShell *presShell = aData->mPresContext->GetPresShell(); if (presShell) { - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); if (doc) { nsHTMLStyleSheet* styleSheet = doc->GetAttributeStyleSheet(); if (styleSheet) { diff --git a/content/html/style/src/nsHTMLStyleSheet.cpp b/content/html/style/src/nsHTMLStyleSheet.cpp index 4ee656544e3..51d4e329922 100644 --- a/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/content/html/style/src/nsHTMLStyleSheet.cpp @@ -500,10 +500,8 @@ NS_IMPL_ISUPPORTS2(nsHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor) static nsresult GetBodyColor(nsPresContext* aPresContext, nscolor* aColor) { - nsCOMPtr doc; nsIPresShell *shell = aPresContext->PresShell(); - shell->GetDocument(getter_AddRefs(doc)); - nsCOMPtr domdoc = do_QueryInterface(doc); + nsCOMPtr domdoc = do_QueryInterface(shell->GetDocument()); if (!domdoc) return NS_ERROR_FAILURE; nsCOMPtr body; diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 7888015707d..4309688d828 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1383,10 +1383,9 @@ nsDocShell::GetCharset(char** aCharset) *aCharset = nsnull; nsCOMPtr presShell; - nsCOMPtr doc; GetPresShell(getter_AddRefs(presShell)); NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); *aCharset = ToNewCString(doc->GetDocumentCharacterSet()); if (!*aCharset) { @@ -1956,8 +1955,7 @@ PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel) parentAsDocShell->GetPresShell(getter_AddRefs(presShell)); nsCOMPtr presContext; parentAsDocShell->GetPresContext(getter_AddRefs(presContext)); - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); nsCOMPtr sgo; doc->GetScriptGlobalObject(getter_AddRefs(sgo)); @@ -3364,17 +3362,12 @@ nsDocShell::GetVisibility(PRBool * aVisibility) nsCOMPtr docShell(do_QueryInterface(treeItem)); docShell->GetPresShell(getter_AddRefs(presShell)); - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - nsCOMPtr parentDS = do_QueryInterface(parentItem); nsCOMPtr pPresShell; parentDS->GetPresShell(getter_AddRefs(pPresShell)); - nsCOMPtr pDoc; - pPresShell->GetDocument(getter_AddRefs(pDoc)); - - nsIContent *shellContent = pDoc->FindContentForSubDocument(doc); + nsIContent *shellContent = + pPresShell->GetDocument()->FindContentForSubDocument(presShell->GetDocument()); NS_ASSERTION(shellContent, "subshell not in the map"); nsIFrame* frame; @@ -7017,8 +7010,7 @@ nsDocShell::SetCanvasHasFocus(PRBool aCanvasHasFocus) GetPresShell(getter_AddRefs(presShell)); if (!presShell) return NS_ERROR_FAILURE; - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; nsIContent *rootContent = doc->GetRootContent(); diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index 65662653c01..906ae43857a 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -577,10 +577,7 @@ nsWebShell::OnLinkClickSync(nsIContent *aContent, GetPresShell(getter_AddRefs(presShell)); NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - nsCOMPtr currentDoc; - presShell->GetDocument(getter_AddRefs(currentDoc)); - - if (currentDoc != sourceDoc) { + if (presShell->GetDocument() != sourceDoc) { // The source is not in the current document, don't let it // execute any javascript in the current document. diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 1ad151078be..8b7d254a8b9 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -960,8 +960,7 @@ nsEditor::GetDocumentCharacterSet(nsACString &characterSet) nsresult rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv)) { - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); if (doc) { characterSet = doc->GetDocumentCharacterSet(); return NS_OK; @@ -980,8 +979,7 @@ nsEditor::SetDocumentCharacterSet(const nsACString& characterSet) nsresult rv = GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv)) { - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); if (doc) { doc->SetDocumentCharacterSet(characterSet); return NS_OK; diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index ec9742e2537..e2f03fa5b60 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -3623,12 +3623,10 @@ nsHTMLEditor::ReplaceStyleSheet(const nsAString& aURL) nsresult rv = GetCSSLoader(aURL, getter_AddRefs(cssLoader)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr document; if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - rv = ps->GetDocument(getter_AddRefs(document)); - NS_ENSURE_SUCCESS(rv, rv);; + nsIDocument *document = ps->GetDocument(); if (!document) return NS_ERROR_NULL_POINTER; nsCOMPtr uaURI; @@ -3871,15 +3869,10 @@ nsHTMLEditor::GetCSSLoader(const nsAString& aURL, nsICSSLoader** aCSSLoader) return NS_ERROR_NULL_POINTER; *aCSSLoader = 0; - nsresult rv; - - nsCOMPtr document; - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - rv = ps->GetDocument(getter_AddRefs(document)); - NS_ENSURE_SUCCESS(rv, rv);; + nsIDocument *document = ps->GetDocument(); if (!document) return NS_ERROR_NULL_POINTER; NS_IF_ADDREF(*aCSSLoader = document->GetCSSLoader()); diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index 2571589017d..096a6f09aa2 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -1329,10 +1329,7 @@ nsPlaintextEditor::GetAndInitDocEncoder(const nsAString& aFormatType, nsCOMPtr docEncoder (do_CreateInstance(formatType.get(), &rv)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr doc; - rv = presShell->GetDocument(getter_AddRefs(doc)); - NS_ENSURE_SUCCESS(rv, rv); - + nsIDocument *doc = presShell->GetDocument(); rv = docEncoder->Init(doc, aFormatType, aFlags); NS_ENSURE_SUCCESS(rv, rv); diff --git a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp index 31875f2d3b7..6b3aab2fa9e 100644 --- a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp +++ b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp @@ -1329,9 +1329,7 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, mFocusedDocSelection->CollapseToStart(); // Hide old doc's selection SetSelectionLook(startingPresShell, PR_FALSE, PR_FALSE); // hide caret - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - + nsIDocument *doc = presShell->GetDocument(); if (!doc) { return NS_ERROR_FAILURE; } @@ -1472,9 +1470,7 @@ nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer, return NS_ERROR_FAILURE; } - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - + nsIDocument *doc = presShell->GetDocument(); if (!doc) { return NS_ERROR_FAILURE; } diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index a4141127d36..774776473a7 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -1546,8 +1546,8 @@ PRBool GetBGColorForHTMLElement( nsPresContext *aPresContext, nsIPresShell* shell = aPresContext->GetPresShell(); if (shell) { - nsIDocument *doc = nsnull; - if (NS_SUCCEEDED(shell->GetDocument(&doc)) && doc) { + nsIDocument *doc = shell->GetDocument(); + if (doc) { nsIContent *pContent; if ((pContent = doc->GetRootContent())) { // make sure that this is the HTML element @@ -1576,7 +1576,6 @@ PRBool GetBGColorForHTMLElement( nsPresContext *aPresContext, } #endif }// if content - NS_RELEASE(doc); }// if doc } // if shell diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index 9fb4b14900e..e285bf91de0 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -954,8 +954,7 @@ CantRenderReplacedElementEvent::~CantRenderReplacedElementEvent() nsresult CantRenderReplacedElementEvent::AddLoadGroupRequest(nsIPresShell* aPresShell) { - nsCOMPtr doc; - aPresShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = aPresShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; nsresult rv = nsDummyLayoutRequest::Create(getter_AddRefs(mDummyLayoutRequest), aPresShell); @@ -986,8 +985,7 @@ CantRenderReplacedElementEvent::RemoveLoadGroupRequest() nsCOMPtr presShell = do_QueryReferent(mPresShell); if (!presShell) return NS_ERROR_FAILURE; - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE;; nsCOMPtr loadGroup = doc->GetDocumentLoadGroup(); diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 90bb62925d8..eabd1385027 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -90,8 +90,8 @@ class nsIStyleSheet; class nsCSSFrameConstructor; #define NS_IPRESSHELL_IID \ -{ 0x76e79c60, 0x944e, 0x11d1, \ - {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } +{ 0xde106833, 0xf56c, 0x4062, \ + {0x9c, 0x7c, 0x60, 0x67, 0x40, 0x7e, 0x88, 0x4a} } // Constants uses for ScrollFrameIntoView() function #define NS_PRESSHELL_SCROLL_TOP 0 @@ -163,7 +163,6 @@ public: NS_IMETHOD PopStackMemory() = 0; NS_IMETHOD AllocateStackMemory(size_t aSize, void** aResult) = 0; - NS_IMETHOD GetDocument(nsIDocument** aResult) = 0; nsIDocument* GetDocument() { return mDocument; } NS_IMETHOD GetPresContext(nsPresContext** aResult) = 0; diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index f3618530b75..c2681cdc50c 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -702,8 +702,7 @@ nsPresContext::SetShell(nsIPresShell* aShell) if (mShell) { // Remove ourselves as the charset observer from the shell's doc, because // this shell may be going away for good. - nsCOMPtr doc; - mShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = mShell->GetDocument(); if (doc) { doc->RemoveCharSetObserver(this); } @@ -712,28 +711,26 @@ nsPresContext::SetShell(nsIPresShell* aShell) mShell = aShell; if (mShell) { - nsCOMPtr doc; - if (NS_SUCCEEDED(mShell->GetDocument(getter_AddRefs(doc)))) { - NS_ASSERTION(doc, "expect document here"); - if (doc) { - nsIURI *baseURI = doc->GetBaseURI(); + nsIDocument *doc = mShell->GetDocument(); + NS_ASSERTION(doc, "expect document here"); + if (doc) { + nsIURI *baseURI = doc->GetBaseURI(); - if (mMedium != nsLayoutAtoms::print && baseURI) { - PRBool isChrome = PR_FALSE; - PRBool isRes = PR_FALSE; - baseURI->SchemeIs("chrome", &isChrome); - baseURI->SchemeIs("resource", &isRes); + if (mMedium != nsLayoutAtoms::print && baseURI) { + PRBool isChrome = PR_FALSE; + PRBool isRes = PR_FALSE; + baseURI->SchemeIs("chrome", &isChrome); + baseURI->SchemeIs("resource", &isRes); - if (!isChrome && !isRes) - mImageAnimationMode = mImageAnimationModePref; - else - mImageAnimationMode = imgIContainer::kNormalAnimMode; - } + if (!isChrome && !isRes) + mImageAnimationMode = mImageAnimationModePref; + else + mImageAnimationMode = imgIContainer::kNormalAnimMode; + } - if (mLangService) { - doc->AddCharSetObserver(this); - UpdateCharSet(doc->GetDocumentCharacterSet().get()); - } + if (mLangService) { + doc->AddCharSetObserver(this); + UpdateCharSet(doc->GetDocumentCharacterSet().get()); } } } @@ -861,9 +858,8 @@ nsPresContext::SetImageAnimationModeInternal(PRUint16 aMode) // Now walk the content tree and set the animation mode // on all the images - nsCOMPtr doc; if (mShell != nsnull) { - mShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = mShell->GetDocument(); if (doc) { nsIContent *rootContent = doc->GetRootContent(); if (rootContent) { @@ -1055,8 +1051,7 @@ nsPresContext::BidiEnabledInternal() const PRBool bidiEnabled = PR_FALSE; NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsPresContext::GetBidiEnabled"); if (mShell) { - nsCOMPtr doc; - mShell->GetDocument(getter_AddRefs(doc) ); + nsIDocument *doc = mShell->GetDocument(); NS_ASSERTION(doc, "PresShell has no document in nsPresContext::GetBidiEnabled"); if (doc) { bidiEnabled = doc->GetBidiEnabled(); @@ -1075,8 +1070,7 @@ void nsPresContext::SetBidiEnabled(PRBool aBidiEnabled) const { if (mShell) { - nsCOMPtr doc; - mShell->GetDocument(getter_AddRefs(doc) ); + nsIDocument *doc = mShell->GetDocument(); if (doc) { doc->SetBidiEnabled(aBidiEnabled); } diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index be37acea56c..e9972f48bc7 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1084,7 +1084,6 @@ public: NS_IMETHOD PopStackMemory(); NS_IMETHOD AllocateStackMemory(size_t aSize, void** aResult); - NS_IMETHOD GetDocument(nsIDocument** aResult); NS_IMETHOD GetPresContext(nsPresContext** aResult); NS_IMETHOD GetViewManager(nsIViewManager** aResult); nsIViewManager* GetViewManager() { return mViewManager; } @@ -2007,18 +2006,6 @@ PresShell::AllocateFrame(size_t aSize) return mFrameArena.AllocateFrame(aSize); } -NS_IMETHODIMP -PresShell::GetDocument(nsIDocument** aResult) -{ - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } - *aResult = mDocument; - NS_IF_ADDREF(*aResult); - return NS_OK; -} - NS_IMETHODIMP PresShell::GetPresContext(nsPresContext** aResult) { @@ -4436,9 +4423,7 @@ PresShell::GetSelectionForCopy(nsISelection** outSelection) *outSelection = nsnull; - nsCOMPtr doc; - GetDocument(getter_AddRefs(doc)); - if (!doc) return NS_ERROR_FAILURE; + if (!mDocument) return NS_ERROR_FAILURE; nsCOMPtr content; nsCOMPtr ourWindow = do_QueryInterface(mDocument->GetScriptGlobalObject()); @@ -4487,9 +4472,7 @@ PresShell::DoGetContents(const nsACString& aMimeType, PRUint32 aFlags, PRBool aS { aOutValue.Truncate(); - nsCOMPtr doc; - GetDocument(getter_AddRefs(doc)); - if (!doc) return NS_ERROR_FAILURE; + if (!mDocument) return NS_ERROR_FAILURE; nsresult rv; nsCOMPtr sel; @@ -4508,15 +4491,14 @@ PresShell::DoGetContents(const nsACString& aMimeType, PRUint32 aFlags, PRBool aS } // call the copy code - return nsCopySupport::GetContents(aMimeType, aFlags, sel, doc, aOutValue); + return nsCopySupport::GetContents(aMimeType, aFlags, sel, + mDocument, aOutValue); } NS_IMETHODIMP PresShell::DoCopy() { - nsCOMPtr doc; - GetDocument(getter_AddRefs(doc)); - if (!doc) return NS_ERROR_FAILURE; + if (!mDocument) return NS_ERROR_FAILURE; nsCOMPtr sel; nsresult rv = GetSelectionForCopy(getter_AddRefs(sel)); @@ -4532,12 +4514,13 @@ PresShell::DoCopy() return NS_OK; // call the copy code - rv = nsCopySupport::HTMLCopy(sel, doc, nsIClipboard::kGlobalClipboard); + rv = nsCopySupport::HTMLCopy(sel, mDocument, nsIClipboard::kGlobalClipboard); if (NS_FAILED(rv)) return rv; // Now that we have copied, update the Paste menu item - nsCOMPtr domWindow = do_QueryInterface(doc->GetScriptGlobalObject()); + nsCOMPtr domWindow = + do_QueryInterface(mDocument->GetScriptGlobalObject()); if (domWindow) { domWindow->UpdateCommands(NS_LITERAL_STRING("clipboard")); diff --git a/layout/base/public/nsIPresShell.h b/layout/base/public/nsIPresShell.h index 90bb62925d8..eabd1385027 100644 --- a/layout/base/public/nsIPresShell.h +++ b/layout/base/public/nsIPresShell.h @@ -90,8 +90,8 @@ class nsIStyleSheet; class nsCSSFrameConstructor; #define NS_IPRESSHELL_IID \ -{ 0x76e79c60, 0x944e, 0x11d1, \ - {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } +{ 0xde106833, 0xf56c, 0x4062, \ + {0x9c, 0x7c, 0x60, 0x67, 0x40, 0x7e, 0x88, 0x4a} } // Constants uses for ScrollFrameIntoView() function #define NS_PRESSHELL_SCROLL_TOP 0 @@ -163,7 +163,6 @@ public: NS_IMETHOD PopStackMemory() = 0; NS_IMETHOD AllocateStackMemory(size_t aSize, void** aResult) = 0; - NS_IMETHOD GetDocument(nsIDocument** aResult) = 0; nsIDocument* GetDocument() { return mDocument; } NS_IMETHOD GetPresContext(nsPresContext** aResult) = 0; diff --git a/layout/base/src/nsPresContext.cpp b/layout/base/src/nsPresContext.cpp index f3618530b75..c2681cdc50c 100644 --- a/layout/base/src/nsPresContext.cpp +++ b/layout/base/src/nsPresContext.cpp @@ -702,8 +702,7 @@ nsPresContext::SetShell(nsIPresShell* aShell) if (mShell) { // Remove ourselves as the charset observer from the shell's doc, because // this shell may be going away for good. - nsCOMPtr doc; - mShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = mShell->GetDocument(); if (doc) { doc->RemoveCharSetObserver(this); } @@ -712,28 +711,26 @@ nsPresContext::SetShell(nsIPresShell* aShell) mShell = aShell; if (mShell) { - nsCOMPtr doc; - if (NS_SUCCEEDED(mShell->GetDocument(getter_AddRefs(doc)))) { - NS_ASSERTION(doc, "expect document here"); - if (doc) { - nsIURI *baseURI = doc->GetBaseURI(); + nsIDocument *doc = mShell->GetDocument(); + NS_ASSERTION(doc, "expect document here"); + if (doc) { + nsIURI *baseURI = doc->GetBaseURI(); - if (mMedium != nsLayoutAtoms::print && baseURI) { - PRBool isChrome = PR_FALSE; - PRBool isRes = PR_FALSE; - baseURI->SchemeIs("chrome", &isChrome); - baseURI->SchemeIs("resource", &isRes); + if (mMedium != nsLayoutAtoms::print && baseURI) { + PRBool isChrome = PR_FALSE; + PRBool isRes = PR_FALSE; + baseURI->SchemeIs("chrome", &isChrome); + baseURI->SchemeIs("resource", &isRes); - if (!isChrome && !isRes) - mImageAnimationMode = mImageAnimationModePref; - else - mImageAnimationMode = imgIContainer::kNormalAnimMode; - } + if (!isChrome && !isRes) + mImageAnimationMode = mImageAnimationModePref; + else + mImageAnimationMode = imgIContainer::kNormalAnimMode; + } - if (mLangService) { - doc->AddCharSetObserver(this); - UpdateCharSet(doc->GetDocumentCharacterSet().get()); - } + if (mLangService) { + doc->AddCharSetObserver(this); + UpdateCharSet(doc->GetDocumentCharacterSet().get()); } } } @@ -861,9 +858,8 @@ nsPresContext::SetImageAnimationModeInternal(PRUint16 aMode) // Now walk the content tree and set the animation mode // on all the images - nsCOMPtr doc; if (mShell != nsnull) { - mShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = mShell->GetDocument(); if (doc) { nsIContent *rootContent = doc->GetRootContent(); if (rootContent) { @@ -1055,8 +1051,7 @@ nsPresContext::BidiEnabledInternal() const PRBool bidiEnabled = PR_FALSE; NS_ASSERTION(mShell, "PresShell must be set on PresContext before calling nsPresContext::GetBidiEnabled"); if (mShell) { - nsCOMPtr doc; - mShell->GetDocument(getter_AddRefs(doc) ); + nsIDocument *doc = mShell->GetDocument(); NS_ASSERTION(doc, "PresShell has no document in nsPresContext::GetBidiEnabled"); if (doc) { bidiEnabled = doc->GetBidiEnabled(); @@ -1075,8 +1070,7 @@ void nsPresContext::SetBidiEnabled(PRBool aBidiEnabled) const { if (mShell) { - nsCOMPtr doc; - mShell->GetDocument(getter_AddRefs(doc) ); + nsIDocument *doc = mShell->GetDocument(); if (doc) { doc->SetBidiEnabled(aBidiEnabled); } diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 2e00985d494..92d03c55b84 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -162,9 +162,8 @@ NS_NewListControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) if (nsnull == aNewFrame) { return NS_ERROR_NULL_POINTER; } - nsCOMPtr doc; - aPresShell->GetDocument(getter_AddRefs(doc)); - nsListControlFrame* it = new (aPresShell) nsListControlFrame(aPresShell, doc); + nsListControlFrame* it = + new (aPresShell) nsListControlFrame(aPresShell, aPresShell->GetDocument()); if (!it) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index d414ee43c54..990af34c9bd 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -1578,13 +1578,11 @@ nsTextControlFrame::CreateAnonymousContent(nsPresContext* aPresContext, // Get the DOM document - nsCOMPtr doc; - nsresult rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) - return rv; + nsIDocument *doc = shell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; + nsresult rv; nsCOMPtr domdoc = do_QueryInterface(doc, &rv); if (NS_FAILED(rv)) return rv; diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp index f7f3961d537..d4fef58581b 100644 --- a/layout/generic/nsBulletFrame.cpp +++ b/layout/generic/nsBulletFrame.cpp @@ -1768,8 +1768,7 @@ nsBulletFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGro if (!shell) return; - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (!doc) return; diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp index 0f1066cc830..bfbc5b4632e 100644 --- a/layout/generic/nsContainerFrame.cpp +++ b/layout/generic/nsContainerFrame.cpp @@ -610,8 +610,7 @@ SyncFrameViewGeometryDependentProperties(nsPresContext* aPresContext, viewHasTransparentContent = PR_FALSE; } - nsCOMPtr doc; - aPresContext->PresShell()->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = aPresContext->PresShell()->GetDocument(); if (doc) { nsIContent *rootElem = doc->GetRootContent(); if (!doc->GetParentDocument() && diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 361395b7829..a2d5f946d78 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1318,9 +1318,9 @@ nsGfxScrollFrameInner::CreateAnonymousContent(nsISupportsArray& aAnonymousChildr } nsIPresShell *shell = presContext->GetPresShell(); - nsCOMPtr document; + nsIDocument *document = nsnull; if (shell) - shell->GetDocument(getter_AddRefs(document)); + document = shell->GetDocument(); // The anonymous
used by never gets scrollbars. nsCOMPtr textFrame(do_QueryInterface(parent)); diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index a01e00c9d2b..ceeaa268e42 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1522,9 +1522,7 @@ nsImageFrame::TriggerLink(nsPresContext* aPresContext, if (!ps) return; - nsCOMPtr doc; - rv = ps->GetDocument(getter_AddRefs(doc)); - + nsIDocument *doc = ps->GetDocument(); if (doc) { rv = securityManager-> CheckLoadURIWithPrincipal(doc->GetPrincipal(), aURI, @@ -1899,8 +1897,7 @@ nsImageFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGrou if (!shell) return; - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (!doc) return; diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index 33da4ba65d6..638f1ebf9aa 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -1247,12 +1247,7 @@ nsObjectFrame::InstantiatePlugin(nsPresContext* aPresContext, // Check to see if content-policy wants to veto this if(aURI) { - nsresult rv; - - nsCOMPtr document; - rv = aPresContext->PresShell()->GetDocument(getter_AddRefs(document)); - if (NS_FAILED(rv)) return rv; - + nsIDocument *document = aPresContext->PresShell()->GetDocument(); if (! document) return NS_ERROR_FAILURE; @@ -1260,13 +1255,13 @@ nsObjectFrame::InstantiatePlugin(nsPresContext* aPresContext, //don't care if we can't get the originating URL PRInt16 shouldLoad = nsIContentPolicy::ACCEPT; // default permit - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OBJECT, - aURI, - docURI, - mContent, - nsDependentCString(aMimetype ? aMimetype : ""), - nsnull, //extra - &shouldLoad); + nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OBJECT, + aURI, + docURI, + mContent, + nsDependentCString(aMimetype ? aMimetype : ""), + nsnull, //extra + &shouldLoad); if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) { return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT; } @@ -2344,13 +2339,16 @@ NS_IMETHODIMP nsPluginInstanceOwner::ShowStatus(const PRUnichar *aStatusMsg) NS_IMETHODIMP nsPluginInstanceOwner::GetDocument(nsIDocument* *aDocument) { - nsresult rv = NS_ERROR_FAILURE; + if (!aDocument) + return NS_ERROR_NULL_POINTER; + + *aDocument = nsnull; if (nsnull != mContext) { nsIPresShell *shell = mContext->GetPresShell(); if (shell) - rv = shell->GetDocument(aDocument); + NS_IF_ADDREF(*aDocument = shell->GetDocument()); } - return rv; + return NS_OK; } NS_IMETHODIMP nsPluginInstanceOwner::InvalidateRect(nsPluginRect *invalidRect) @@ -2544,10 +2542,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetDocumentBase(const char* *result) return NS_ERROR_FAILURE; } - nsCOMPtr doc; - mContext->PresShell()->GetDocument(getter_AddRefs(doc)); - - rv = doc->GetBaseURI()->GetSpec(mDocumentBase); + rv = mContext->PresShell()->GetDocument()->GetBaseURI()->GetSpec(mDocumentBase); } if (rv == NS_OK) *result = ToNewCString(mDocumentBase); diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index e7164e86ff9..c845275de56 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -1635,8 +1635,7 @@ nsTypedSelection::ToStringWithFormat(const char * aFormatType, PRUint32 aFlags, return NS_ERROR_FAILURE; } - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); NS_ENSURE_SUCCESS(rv, rv); // Flags should always include OutputSelectionOnly if we're coming from here: @@ -3092,10 +3091,7 @@ NS_IMETHODIMP nsSelection::SelectAll() return NS_ERROR_FAILURE; } - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) - return rv; + nsIDocument *doc = shell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; rootContent = doc->GetRootContent(); @@ -7479,16 +7475,10 @@ nsTypedSelection::NotifySelectionListeners() PRInt32 cnt = mSelectionListeners.Count(); nsCOMPtr domdoc; - nsCOMPtr doc; nsCOMPtr shell; nsresult rv = GetPresShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) - { - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) - doc = 0; - domdoc = do_QueryInterface(doc); - } + domdoc = do_QueryInterface(shell->GetDocument()); short reason = mFrameSelection->PopReason(); for (PRInt32 i = 0; i < cnt; i++) { diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 79ff0d15e4b..dc924a05a33 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -655,7 +655,7 @@ public: {} }; - already_AddRefed GetDocument(nsPresContext* aPresContext); + nsIDocument* GetDocument(nsPresContext* aPresContext); PRIntn PrepareUnicodeText(nsTextTransformer& aTransformer, nsAutoIndexBuffer* aIndexBuffer, @@ -1325,15 +1325,15 @@ nsTextFrame::~nsTextFrame() } } -already_AddRefed +nsIDocument* nsTextFrame::GetDocument(nsPresContext* aPresContext) { - nsIDocument* result = nsnull; + nsIDocument *result = nsnull; if (mContent) { - NS_IF_ADDREF(result = mContent->GetDocument()); + result = mContent->GetDocument(); } if (!result && aPresContext) { - aPresContext->PresShell()->GetDocument(&result); + result = aPresContext->PresShell()->GetDocument(); } return result; } @@ -2046,8 +2046,7 @@ nsresult nsTextFrame::GetTextInfoForPainting(nsPresContext* aPresContex // transformed when we formatted it, then there's no need to do all // this and we should just render the text fragment directly. See // PaintAsciiText()... - nsCOMPtr doc; - (*aPresShell)->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = (*aPresShell)->GetDocument(); if (!doc) return NS_ERROR_FAILURE; @@ -2488,7 +2487,7 @@ nsTextFrame::GetPositionSlowly(nsPresContext* aPresContext, *aNewContent = mContent; aOffset =0; } - nsCOMPtr doc(GetDocument(aPresContext)); + nsIDocument *doc = GetDocument(aPresContext); // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -3391,7 +3390,7 @@ nsTextFrame::GetPosition(nsPresContext* aCX, SetFontFromStyle(acx, mStyleContext); // Get the renderable form of the text - nsCOMPtr doc(GetDocument(aCX)); + nsIDocument *doc = GetDocument(aCX); nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aCX); PRInt32 textLength; // no need to worry about justification, that's always on the slow path @@ -3722,7 +3721,7 @@ nsTextFrame::GetPointFromOffset(nsPresContext* aPresContext, } // Transform text from content into renderable form - nsCOMPtr doc(GetDocument(aPresContext)); + nsIDocument *doc = GetDocument(aPresContext); nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aPresContext); PRInt32 textLength; PRInt32 numSpaces; @@ -4336,10 +4335,7 @@ nsTextFrame::CheckVisibility(nsPresContext* aContext, PRInt32 aStartIndex, PRInt return NS_ERROR_FAILURE; //get the document - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) - return rv; + nsIDocument *doc = shell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; //create texttransformer diff --git a/layout/html/base/src/nsBulletFrame.cpp b/layout/html/base/src/nsBulletFrame.cpp index f7f3961d537..d4fef58581b 100644 --- a/layout/html/base/src/nsBulletFrame.cpp +++ b/layout/html/base/src/nsBulletFrame.cpp @@ -1768,8 +1768,7 @@ nsBulletFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGro if (!shell) return; - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (!doc) return; diff --git a/layout/html/base/src/nsContainerFrame.cpp b/layout/html/base/src/nsContainerFrame.cpp index 0f1066cc830..bfbc5b4632e 100644 --- a/layout/html/base/src/nsContainerFrame.cpp +++ b/layout/html/base/src/nsContainerFrame.cpp @@ -610,8 +610,7 @@ SyncFrameViewGeometryDependentProperties(nsPresContext* aPresContext, viewHasTransparentContent = PR_FALSE; } - nsCOMPtr doc; - aPresContext->PresShell()->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = aPresContext->PresShell()->GetDocument(); if (doc) { nsIContent *rootElem = doc->GetRootContent(); if (!doc->GetParentDocument() && diff --git a/layout/html/base/src/nsFrameManager.cpp b/layout/html/base/src/nsFrameManager.cpp index 9fb4b14900e..e285bf91de0 100644 --- a/layout/html/base/src/nsFrameManager.cpp +++ b/layout/html/base/src/nsFrameManager.cpp @@ -954,8 +954,7 @@ CantRenderReplacedElementEvent::~CantRenderReplacedElementEvent() nsresult CantRenderReplacedElementEvent::AddLoadGroupRequest(nsIPresShell* aPresShell) { - nsCOMPtr doc; - aPresShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = aPresShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; nsresult rv = nsDummyLayoutRequest::Create(getter_AddRefs(mDummyLayoutRequest), aPresShell); @@ -986,8 +985,7 @@ CantRenderReplacedElementEvent::RemoveLoadGroupRequest() nsCOMPtr presShell = do_QueryReferent(mPresShell); if (!presShell) return NS_ERROR_FAILURE; - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); if (!doc) return NS_ERROR_FAILURE;; nsCOMPtr loadGroup = doc->GetDocumentLoadGroup(); diff --git a/layout/html/base/src/nsGfxScrollFrame.cpp b/layout/html/base/src/nsGfxScrollFrame.cpp index 361395b7829..a2d5f946d78 100644 --- a/layout/html/base/src/nsGfxScrollFrame.cpp +++ b/layout/html/base/src/nsGfxScrollFrame.cpp @@ -1318,9 +1318,9 @@ nsGfxScrollFrameInner::CreateAnonymousContent(nsISupportsArray& aAnonymousChildr } nsIPresShell *shell = presContext->GetPresShell(); - nsCOMPtr document; + nsIDocument *document = nsnull; if (shell) - shell->GetDocument(getter_AddRefs(document)); + document = shell->GetDocument(); // The anonymous
used by never gets scrollbars. nsCOMPtr textFrame(do_QueryInterface(parent)); diff --git a/layout/html/base/src/nsImageFrame.cpp b/layout/html/base/src/nsImageFrame.cpp index a01e00c9d2b..ceeaa268e42 100644 --- a/layout/html/base/src/nsImageFrame.cpp +++ b/layout/html/base/src/nsImageFrame.cpp @@ -1522,9 +1522,7 @@ nsImageFrame::TriggerLink(nsPresContext* aPresContext, if (!ps) return; - nsCOMPtr doc; - rv = ps->GetDocument(getter_AddRefs(doc)); - + nsIDocument *doc = ps->GetDocument(); if (doc) { rv = securityManager-> CheckLoadURIWithPrincipal(doc->GetPrincipal(), aURI, @@ -1899,8 +1897,7 @@ nsImageFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGrou if (!shell) return; - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (!doc) return; diff --git a/layout/html/base/src/nsObjectFrame.cpp b/layout/html/base/src/nsObjectFrame.cpp index 33da4ba65d6..638f1ebf9aa 100644 --- a/layout/html/base/src/nsObjectFrame.cpp +++ b/layout/html/base/src/nsObjectFrame.cpp @@ -1247,12 +1247,7 @@ nsObjectFrame::InstantiatePlugin(nsPresContext* aPresContext, // Check to see if content-policy wants to veto this if(aURI) { - nsresult rv; - - nsCOMPtr document; - rv = aPresContext->PresShell()->GetDocument(getter_AddRefs(document)); - if (NS_FAILED(rv)) return rv; - + nsIDocument *document = aPresContext->PresShell()->GetDocument(); if (! document) return NS_ERROR_FAILURE; @@ -1260,13 +1255,13 @@ nsObjectFrame::InstantiatePlugin(nsPresContext* aPresContext, //don't care if we can't get the originating URL PRInt16 shouldLoad = nsIContentPolicy::ACCEPT; // default permit - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OBJECT, - aURI, - docURI, - mContent, - nsDependentCString(aMimetype ? aMimetype : ""), - nsnull, //extra - &shouldLoad); + nsresult rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_OBJECT, + aURI, + docURI, + mContent, + nsDependentCString(aMimetype ? aMimetype : ""), + nsnull, //extra + &shouldLoad); if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) { return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT; } @@ -2344,13 +2339,16 @@ NS_IMETHODIMP nsPluginInstanceOwner::ShowStatus(const PRUnichar *aStatusMsg) NS_IMETHODIMP nsPluginInstanceOwner::GetDocument(nsIDocument* *aDocument) { - nsresult rv = NS_ERROR_FAILURE; + if (!aDocument) + return NS_ERROR_NULL_POINTER; + + *aDocument = nsnull; if (nsnull != mContext) { nsIPresShell *shell = mContext->GetPresShell(); if (shell) - rv = shell->GetDocument(aDocument); + NS_IF_ADDREF(*aDocument = shell->GetDocument()); } - return rv; + return NS_OK; } NS_IMETHODIMP nsPluginInstanceOwner::InvalidateRect(nsPluginRect *invalidRect) @@ -2544,10 +2542,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetDocumentBase(const char* *result) return NS_ERROR_FAILURE; } - nsCOMPtr doc; - mContext->PresShell()->GetDocument(getter_AddRefs(doc)); - - rv = doc->GetBaseURI()->GetSpec(mDocumentBase); + rv = mContext->PresShell()->GetDocument()->GetBaseURI()->GetSpec(mDocumentBase); } if (rv == NS_OK) *result = ToNewCString(mDocumentBase); diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index be37acea56c..e9972f48bc7 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -1084,7 +1084,6 @@ public: NS_IMETHOD PopStackMemory(); NS_IMETHOD AllocateStackMemory(size_t aSize, void** aResult); - NS_IMETHOD GetDocument(nsIDocument** aResult); NS_IMETHOD GetPresContext(nsPresContext** aResult); NS_IMETHOD GetViewManager(nsIViewManager** aResult); nsIViewManager* GetViewManager() { return mViewManager; } @@ -2007,18 +2006,6 @@ PresShell::AllocateFrame(size_t aSize) return mFrameArena.AllocateFrame(aSize); } -NS_IMETHODIMP -PresShell::GetDocument(nsIDocument** aResult) -{ - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } - *aResult = mDocument; - NS_IF_ADDREF(*aResult); - return NS_OK; -} - NS_IMETHODIMP PresShell::GetPresContext(nsPresContext** aResult) { @@ -4436,9 +4423,7 @@ PresShell::GetSelectionForCopy(nsISelection** outSelection) *outSelection = nsnull; - nsCOMPtr doc; - GetDocument(getter_AddRefs(doc)); - if (!doc) return NS_ERROR_FAILURE; + if (!mDocument) return NS_ERROR_FAILURE; nsCOMPtr content; nsCOMPtr ourWindow = do_QueryInterface(mDocument->GetScriptGlobalObject()); @@ -4487,9 +4472,7 @@ PresShell::DoGetContents(const nsACString& aMimeType, PRUint32 aFlags, PRBool aS { aOutValue.Truncate(); - nsCOMPtr doc; - GetDocument(getter_AddRefs(doc)); - if (!doc) return NS_ERROR_FAILURE; + if (!mDocument) return NS_ERROR_FAILURE; nsresult rv; nsCOMPtr sel; @@ -4508,15 +4491,14 @@ PresShell::DoGetContents(const nsACString& aMimeType, PRUint32 aFlags, PRBool aS } // call the copy code - return nsCopySupport::GetContents(aMimeType, aFlags, sel, doc, aOutValue); + return nsCopySupport::GetContents(aMimeType, aFlags, sel, + mDocument, aOutValue); } NS_IMETHODIMP PresShell::DoCopy() { - nsCOMPtr doc; - GetDocument(getter_AddRefs(doc)); - if (!doc) return NS_ERROR_FAILURE; + if (!mDocument) return NS_ERROR_FAILURE; nsCOMPtr sel; nsresult rv = GetSelectionForCopy(getter_AddRefs(sel)); @@ -4532,12 +4514,13 @@ PresShell::DoCopy() return NS_OK; // call the copy code - rv = nsCopySupport::HTMLCopy(sel, doc, nsIClipboard::kGlobalClipboard); + rv = nsCopySupport::HTMLCopy(sel, mDocument, nsIClipboard::kGlobalClipboard); if (NS_FAILED(rv)) return rv; // Now that we have copied, update the Paste menu item - nsCOMPtr domWindow = do_QueryInterface(doc->GetScriptGlobalObject()); + nsCOMPtr domWindow = + do_QueryInterface(mDocument->GetScriptGlobalObject()); if (domWindow) { domWindow->UpdateCommands(NS_LITERAL_STRING("clipboard")); diff --git a/layout/html/base/src/nsTextFrame.cpp b/layout/html/base/src/nsTextFrame.cpp index 79ff0d15e4b..dc924a05a33 100644 --- a/layout/html/base/src/nsTextFrame.cpp +++ b/layout/html/base/src/nsTextFrame.cpp @@ -655,7 +655,7 @@ public: {} }; - already_AddRefed GetDocument(nsPresContext* aPresContext); + nsIDocument* GetDocument(nsPresContext* aPresContext); PRIntn PrepareUnicodeText(nsTextTransformer& aTransformer, nsAutoIndexBuffer* aIndexBuffer, @@ -1325,15 +1325,15 @@ nsTextFrame::~nsTextFrame() } } -already_AddRefed +nsIDocument* nsTextFrame::GetDocument(nsPresContext* aPresContext) { - nsIDocument* result = nsnull; + nsIDocument *result = nsnull; if (mContent) { - NS_IF_ADDREF(result = mContent->GetDocument()); + result = mContent->GetDocument(); } if (!result && aPresContext) { - aPresContext->PresShell()->GetDocument(&result); + result = aPresContext->PresShell()->GetDocument(); } return result; } @@ -2046,8 +2046,7 @@ nsresult nsTextFrame::GetTextInfoForPainting(nsPresContext* aPresContex // transformed when we formatted it, then there's no need to do all // this and we should just render the text fragment directly. See // PaintAsciiText()... - nsCOMPtr doc; - (*aPresShell)->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = (*aPresShell)->GetDocument(); if (!doc) return NS_ERROR_FAILURE; @@ -2488,7 +2487,7 @@ nsTextFrame::GetPositionSlowly(nsPresContext* aPresContext, *aNewContent = mContent; aOffset =0; } - nsCOMPtr doc(GetDocument(aPresContext)); + nsIDocument *doc = GetDocument(aPresContext); // Make enough space to transform nsAutoTextBuffer paintBuffer; @@ -3391,7 +3390,7 @@ nsTextFrame::GetPosition(nsPresContext* aCX, SetFontFromStyle(acx, mStyleContext); // Get the renderable form of the text - nsCOMPtr doc(GetDocument(aCX)); + nsIDocument *doc = GetDocument(aCX); nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aCX); PRInt32 textLength; // no need to worry about justification, that's always on the slow path @@ -3722,7 +3721,7 @@ nsTextFrame::GetPointFromOffset(nsPresContext* aPresContext, } // Transform text from content into renderable form - nsCOMPtr doc(GetDocument(aPresContext)); + nsIDocument *doc = GetDocument(aPresContext); nsTextTransformer tx(doc->GetLineBreaker(), nsnull, aPresContext); PRInt32 textLength; PRInt32 numSpaces; @@ -4336,10 +4335,7 @@ nsTextFrame::CheckVisibility(nsPresContext* aContext, PRInt32 aStartIndex, PRInt return NS_ERROR_FAILURE; //get the document - nsCOMPtr doc; - rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) - return rv; + nsIDocument *doc = shell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; //create texttransformer diff --git a/layout/html/forms/src/nsListControlFrame.cpp b/layout/html/forms/src/nsListControlFrame.cpp index 2e00985d494..92d03c55b84 100644 --- a/layout/html/forms/src/nsListControlFrame.cpp +++ b/layout/html/forms/src/nsListControlFrame.cpp @@ -162,9 +162,8 @@ NS_NewListControlFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) if (nsnull == aNewFrame) { return NS_ERROR_NULL_POINTER; } - nsCOMPtr doc; - aPresShell->GetDocument(getter_AddRefs(doc)); - nsListControlFrame* it = new (aPresShell) nsListControlFrame(aPresShell, doc); + nsListControlFrame* it = + new (aPresShell) nsListControlFrame(aPresShell, aPresShell->GetDocument()); if (!it) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/layout/html/forms/src/nsTextControlFrame.cpp b/layout/html/forms/src/nsTextControlFrame.cpp index d414ee43c54..990af34c9bd 100644 --- a/layout/html/forms/src/nsTextControlFrame.cpp +++ b/layout/html/forms/src/nsTextControlFrame.cpp @@ -1578,13 +1578,11 @@ nsTextControlFrame::CreateAnonymousContent(nsPresContext* aPresContext, // Get the DOM document - nsCOMPtr doc; - nsresult rv = shell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) - return rv; + nsIDocument *doc = shell->GetDocument(); if (!doc) return NS_ERROR_FAILURE; + nsresult rv; nsCOMPtr domdoc = do_QueryInterface(doc, &rv); if (NS_FAILED(rv)) return rv; diff --git a/layout/html/style/src/nsCSSRendering.cpp b/layout/html/style/src/nsCSSRendering.cpp index a4141127d36..774776473a7 100644 --- a/layout/html/style/src/nsCSSRendering.cpp +++ b/layout/html/style/src/nsCSSRendering.cpp @@ -1546,8 +1546,8 @@ PRBool GetBGColorForHTMLElement( nsPresContext *aPresContext, nsIPresShell* shell = aPresContext->GetPresShell(); if (shell) { - nsIDocument *doc = nsnull; - if (NS_SUCCEEDED(shell->GetDocument(&doc)) && doc) { + nsIDocument *doc = shell->GetDocument(); + if (doc) { nsIContent *pContent; if ((pContent = doc->GetRootContent())) { // make sure that this is the HTML element @@ -1576,7 +1576,6 @@ PRBool GetBGColorForHTMLElement( nsPresContext *aPresContext, } #endif }// if content - NS_RELEASE(doc); }// if doc } // if shell diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 868cfad576a..4adefb3df91 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -1744,8 +1744,7 @@ nsPrintEngine::IsParentAFrameSet(nsIWebShell * aParent) // only check to see if there is a frameset if there is // NO parent doc for this doc. meaning this parent is the root doc if (shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { nsIContent *rootContent = doc->GetRootContent(); if (rootContent) { diff --git a/layout/printing/nsPrintObject.cpp b/layout/printing/nsPrintObject.cpp index f60cbb2edd6..c165c055857 100644 --- a/layout/printing/nsPrintObject.cpp +++ b/layout/printing/nsPrintObject.cpp @@ -93,7 +93,7 @@ nsPrintObject::Init(nsIWebShell* aWebShell) mDocShell->GetPresContext(getter_AddRefs(mDisplayPresContext)); NS_ENSURE_TRUE(mDisplayPresContext, NS_ERROR_FAILURE); - mDisplayPresShell->GetDocument(getter_AddRefs(mDocument)); + mDocument = mDisplayPresShell->GetDocument(); NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE); return NS_OK; diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index 4ee656544e3..51d4e329922 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -500,10 +500,8 @@ NS_IMPL_ISUPPORTS2(nsHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor) static nsresult GetBodyColor(nsPresContext* aPresContext, nscolor* aColor) { - nsCOMPtr doc; nsIPresShell *shell = aPresContext->PresShell(); - shell->GetDocument(getter_AddRefs(doc)); - nsCOMPtr domdoc = do_QueryInterface(doc); + nsCOMPtr domdoc = do_QueryInterface(shell->GetDocument()); if (!domdoc) return NS_ERROR_FAILURE; nsCOMPtr body; diff --git a/layout/xul/base/src/nsBoxFrame.cpp b/layout/xul/base/src/nsBoxFrame.cpp index 443cfa8d65f..2995412631e 100644 --- a/layout/xul/base/src/nsBoxFrame.cpp +++ b/layout/xul/base/src/nsBoxFrame.cpp @@ -755,8 +755,7 @@ nsBoxFrame::IsInitialReflowForPrintPreview(nsBoxLayoutState& aState, // Now, get the current URI to see if we doing chrome nsIPresShell *presShell = aState.PresShell(); if (!presShell) return PR_FALSE; - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = presShell->GetDocument(); if (!doc) return PR_FALSE; nsIURI *uri = doc->GetDocumentURI(); if (!uri) return PR_FALSE; diff --git a/layout/xul/base/src/nsBoxObject.cpp b/layout/xul/base/src/nsBoxObject.cpp index e10951b0224..bcaa9007473 100644 --- a/layout/xul/base/src/nsBoxObject.cpp +++ b/layout/xul/base/src/nsBoxObject.cpp @@ -627,10 +627,8 @@ nsBoxObject::GetDocShell(nsIDocShell** aResult) // No nsIFrameFrame available for mContent, try if there's a mapping // between mContent's document to mContent's subdocument. - nsCOMPtr doc; - mPresShell->GetDocument(getter_AddRefs(doc)); - - nsIDocument *sub_doc = doc->GetSubDocumentFor(mContent); + nsIDocument *sub_doc = + mPresShell->GetDocument()->GetSubDocumentFor(mContent); if (!sub_doc) { return NS_OK; diff --git a/layout/xul/base/src/nsImageBoxFrame.cpp b/layout/xul/base/src/nsImageBoxFrame.cpp index b99f9d2d9e5..541318df930 100644 --- a/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/layout/xul/base/src/nsImageBoxFrame.cpp @@ -666,8 +666,7 @@ nsImageBoxFrame::GetLoadGroup() if (!shell) return nsnull; - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (!doc) return nsnull; diff --git a/layout/xul/base/src/nsMenuBarFrame.cpp b/layout/xul/base/src/nsMenuBarFrame.cpp index 784dc53e5d6..eae7fb0924a 100644 --- a/layout/xul/base/src/nsMenuBarFrame.cpp +++ b/layout/xul/base/src/nsMenuBarFrame.cpp @@ -205,8 +205,7 @@ nsMenuBarFrame::SetActive(PRBool aActiveFlag) if (!presShell) break; - nsCOMPtr document; - presShell->GetDocument(getter_AddRefs(document)); + nsIDocument *document = presShell->GetDocument(); if (!document) break; @@ -226,12 +225,13 @@ nsMenuBarFrame::SetActive(PRBool aActiveFlag) break; nsCOMPtr domDoc; + nsCOMPtr focusedDoc; windowInternal->GetDocument(getter_AddRefs(domDoc)); - document = do_QueryInterface(domDoc); - if (!document) + focusedDoc = do_QueryInterface(domDoc); + if (!focusedDoc) break; - presShell = document->GetShellAt(0); + presShell = focusedDoc->GetShellAt(0); nsCOMPtr selCon(do_QueryInterface(presShell)); // there is no selection controller for full page plugins if (!selCon) diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index be45c5ff965..49733d52f89 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -894,8 +894,7 @@ nsMenuPopupFrame::SyncViewWithFrame(nsPresContext* aPresContext, // get the document and the global script object nsIPresShell *presShell = aPresContext->PresShell(); - nsCOMPtr document; - presShell->GetDocument(getter_AddRefs(document)); + nsIDocument *document = presShell->GetDocument(); PRBool sizedToPopup = (mContent->Tag() != nsXULAtoms::tooltip) && (nsMenuFrame::IsSizedToPopup(aFrame->GetContent(), PR_FALSE)); diff --git a/layout/xul/base/src/nsResizerFrame.cpp b/layout/xul/base/src/nsResizerFrame.cpp index 8774c077ff5..db21a99aff0 100644 --- a/layout/xul/base/src/nsResizerFrame.cpp +++ b/layout/xul/base/src/nsResizerFrame.cpp @@ -152,9 +152,8 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, if(mTrackingMouseMove) { // get the document and the global script object - should this be cached? - nsCOMPtr document; - aPresContext->PresShell()->GetDocument(getter_AddRefs(document)); - nsIScriptGlobalObject *scriptGlobalObject = document->GetScriptGlobalObject(); + nsIScriptGlobalObject *scriptGlobalObject = + aPresContext->PresShell()->GetDocument()->GetScriptGlobalObject(); NS_ENSURE_TRUE(scriptGlobalObject, NS_ERROR_FAILURE); nsCOMPtr docShellAsItem = diff --git a/layout/xul/base/src/nsTitleBarFrame.cpp b/layout/xul/base/src/nsTitleBarFrame.cpp index 2a39e8e1cd1..6ab81f1cf54 100644 --- a/layout/xul/base/src/nsTitleBarFrame.cpp +++ b/layout/xul/base/src/nsTitleBarFrame.cpp @@ -167,9 +167,8 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, if(mTrackingMouseMove) { // get the document and the global script object - should this be cached? - nsCOMPtr document; - aPresContext->PresShell()->GetDocument(getter_AddRefs(document)); - nsCOMPtr window(do_QueryInterface(document->GetScriptGlobalObject())); + nsCOMPtr + window(do_QueryInterface(aPresContext->PresShell()->GetDocument()->GetScriptGlobalObject())); diff --git a/webshell/tests/viewer/nsBrowserWindow.cpp b/webshell/tests/viewer/nsBrowserWindow.cpp index c1e204944b8..af8a3e0c86c 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -2392,8 +2392,7 @@ DumpContentRecurse(nsIDocShell* aDocShell, FILE* out) fprintf(out, "docshell=%p \n", aDocShell); nsIPresShell* shell = GetPresShellFor(aDocShell); if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { nsIContent *root = doc->GetRootContent(); if (nsnull != root) { @@ -2855,8 +2854,7 @@ nsBrowserWindow::DispatchStyleMenu(PRInt32 aID) nsIPresShell* shell = GetPresShell(); if (nsnull != shell) { nsAutoString defaultStyle; - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { nsIAtom* defStyleAtom = NS_NewAtom("default-style"); doc->GetHeaderData(defStyleAtom, defaultStyle); @@ -2893,8 +2891,7 @@ nsBrowserWindow::DispatchStyleMenu(PRInt32 aID) { nsIPresShell* shell = GetPresShell(); if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { nsAutoString defaultStyle; nsIAtom* defStyleAtom = NS_NewAtom("default-style"); diff --git a/webshell/tests/viewer/nsViewerApp.cpp b/webshell/tests/viewer/nsViewerApp.cpp index f7c0fb2a2fc..7a94b7f7f93 100644 --- a/webshell/tests/viewer/nsViewerApp.cpp +++ b/webshell/tests/viewer/nsViewerApp.cpp @@ -1084,8 +1084,7 @@ nsViewerApp::CreateRobot(nsBrowserWindow* aWindow) { nsIPresShell* shell = aWindow->GetPresShell(); if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { nsCAutoString str; nsresult rv = doc->GetDocumentURI()->GetSpec(str); diff --git a/webshell/tests/viewer/nsXPBaseWindow.cpp b/webshell/tests/viewer/nsXPBaseWindow.cpp index 5a01a5f4ea3..55b39b0f850 100644 --- a/webshell/tests/viewer/nsXPBaseWindow.cpp +++ b/webshell/tests/viewer/nsXPBaseWindow.cpp @@ -404,8 +404,7 @@ NS_IMETHODIMP nsXPBaseWindow::EndLoadURL(nsIWebShell* aShell, const PRUnichar* a nsIPresShell* shell; GetPresShell(shell); if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { NS_IF_ADDREF(mContentRoot = doc->GetRootContent()); mDocIsLoaded = PR_TRUE; @@ -513,8 +512,7 @@ NS_IMETHODIMP nsXPBaseWindow::GetDocument(nsIDOMHTMLDocument *& aDocument) nsIPresShell *shell = nsnull; GetPresShell(shell); if (nsnull != shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); + nsIDocument *doc = shell->GetDocument(); if (doc) { doc->QueryInterface(kIDOMHTMLDocumentIID,(void **)&htmlDoc); }