Bug 682420 - Rename nsINode::GetOwnerDoc to nsINode::OwnerDoc, part 2, r=jst
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 18 Oct 2011 14:19:44 +0300
changeset 79523 9e6aa5ee6425233b428323bb9c9fef2c1c625982
parent 79522 41a01f78db7a85912c92fadd49298601a84ddc41
child 79528 7ed661aa832d8e0ffd0789f00de602956de3bb21
push id506
push userclegnitto@mozilla.com
push dateWed, 09 Nov 2011 02:03:18 +0000
treeherdermozilla-aurora@63587fc7bb93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs682420
milestone10.0a1
Bug 682420 - Rename nsINode::GetOwnerDoc to nsINode::OwnerDoc, part 2, r=jst
accessible/src/base/nsAccessNode.cpp
accessible/src/base/nsCaretAccessible.cpp
accessible/src/base/nsCoreUtils.cpp
accessible/src/base/nsCoreUtils.h
accessible/src/xul/nsXULMenuAccessible.cpp
accessible/src/xul/nsXULSliderAccessible.cpp
accessible/src/xul/nsXULTextAccessible.cpp
browser/components/shell/src/nsMacShellService.cpp
content/base/public/nsIContent.h
content/base/src/nsContentList.cpp
content/base/src/nsContentUtils.cpp
content/base/src/nsDOMAttribute.cpp
content/base/src/nsDocument.cpp
content/base/src/nsFrameLoader.cpp
content/base/src/nsGenericDOMDataNode.cpp
content/base/src/nsGenericElement.cpp
content/base/src/nsGenericElement.h
content/base/src/nsNodeUtils.cpp
content/base/src/nsObjectLoadingContent.cpp
content/base/src/nsRange.cpp
content/base/src/nsStyledElement.cpp
content/canvas/src/nsCanvasRenderingContext2D.cpp
content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
content/events/src/nsEventListenerManager.cpp
content/events/src/nsPLDOMEvent.cpp
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsHTMLDNSPrefetch.cpp
content/html/content/src/nsHTMLImageElement.cpp
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsHTMLMediaElement.cpp
content/html/content/src/nsHTMLMenuElement.cpp
content/html/content/src/nsHTMLSharedElement.cpp
content/mathml/content/src/nsMathMLElement.cpp
content/svg/content/src/nsSVGAnimationElement.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGFilters.cpp
content/svg/content/src/nsSVGStylableElement.cpp
content/xbl/src/nsBindingManager.cpp
content/xbl/src/nsXBLBinding.cpp
content/xbl/src/nsXBLProtoImpl.cpp
content/xbl/src/nsXBLProtoImplMethod.cpp
content/xbl/src/nsXBLProtoImplProperty.cpp
content/xbl/src/nsXBLPrototypeHandler.cpp
content/xbl/src/nsXBLService.cpp
content/xml/content/src/nsXMLStylesheetPI.cpp
content/xslt/src/base/txURIUtils.cpp
content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp
content/xslt/src/xslt/txMozillaXMLOutput.cpp
content/xul/content/src/nsXULElement.cpp
content/xul/document/src/nsXULDocument.cpp
docshell/base/nsDocShell.cpp
dom/base/nsDOMClassInfo.cpp
dom/ipc/TabParent.cpp
dom/plugins/base/nsJSNPRuntime.cpp
layout/base/nsCSSRendering.cpp
layout/base/nsChildIterator.cpp
layout/inspector/src/inDOMUtils.cpp
layout/style/nsCSSStyleSheet.cpp
layout/style/nsDOMCSSAttrDeclaration.cpp
layout/xul/base/src/nsImageBoxFrame.cpp
layout/xul/base/src/nsMenuPopupFrame.cpp
layout/xul/base/src/nsSplitterFrame.cpp
parser/html/nsHtml5Parser.cpp
widget/src/cocoa/nsMenuItemIconX.mm
widget/src/cocoa/nsMenuItemX.mm
widget/src/xpwidgets/nsNativeTheme.cpp
--- a/accessible/src/base/nsAccessNode.cpp
+++ b/accessible/src/base/nsAccessNode.cpp
@@ -460,16 +460,14 @@ nsAccessNode::GetLanguage(nsAString& aLa
   aLanguage.Truncate();
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
   nsCoreUtils::GetLanguageFor(mContent, nsnull, aLanguage);
 
   if (aLanguage.IsEmpty()) { // Nothing found, so use document's language
-    nsIDocument *doc = mContent->OwnerDoc();
-    if (doc) {
-      doc->GetHeaderData(nsGkAtoms::headerContentLanguage, aLanguage);
-    }
+    mContent->OwnerDoc()->GetHeaderData(nsGkAtoms::headerContentLanguage,
+                                        aLanguage);
   }
  
   return NS_OK;
 }
--- a/accessible/src/base/nsCaretAccessible.cpp
+++ b/accessible/src/base/nsCaretAccessible.cpp
@@ -381,21 +381,17 @@ nsCaretAccessible::GetCaretRect(nsIWidge
 }
 
 already_AddRefed<nsISelectionController>
 nsCaretAccessible::GetSelectionControllerForNode(nsIContent *aContent)
 {
   if (!aContent)
     return nsnull;
 
-  nsIDocument *document = aContent->OwnerDoc();
-  if (!document)
-    return nsnull;
-
-  nsIPresShell *presShell = document->GetShell();
+  nsIPresShell *presShell = aContent->OwnerDoc()->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
@@ -202,21 +202,17 @@ nsCoreUtils::GetAccessKeyFor(nsIContent 
     return 0;
 
   // Accesskeys are registered by @accesskey attribute only. At first check
   // whether it is presented on the given element to avoid the slow
   // nsEventStateManager::GetRegisteredAccessKey() method.
   if (!aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::accesskey))
     return 0;
 
-  nsCOMPtr<nsIDocument> doc = aContent->OwnerDoc();
-  if (!doc)
-    return 0;
-
-  nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
+  nsCOMPtr<nsIPresShell> presShell = aContent->OwnerDoc()->GetShell();
   if (!presShell)
     return 0;
 
   nsPresContext *presContext = presShell->GetPresContext();
   if (!presContext)
     return 0;
 
   nsEventStateManager *esm = presContext->EventStateManager();
@@ -434,21 +430,17 @@ nsCoreUtils::GetScreenCoordsForWindow(ns
 }
 
 already_AddRefed<nsIDocShellTreeItem>
 nsCoreUtils::GetDocShellTreeItemFor(nsINode *aNode)
 {
   if (!aNode)
     return nsnull;
 
-  nsIDocument *doc = aNode->OwnerDoc();
-  NS_ASSERTION(doc, "No document for node passed in");
-  NS_ENSURE_TRUE(doc, nsnull);
-
-  nsCOMPtr<nsISupports> container = doc->GetContainer();
+  nsCOMPtr<nsISupports> container = aNode->OwnerDoc()->GetContainer();
   nsIDocShellTreeItem *docShellTreeItem = nsnull;
   if (container)
     CallQueryInterface(container, &docShellTreeItem);
 
   return docShellTreeItem;
 }
 
 bool
@@ -598,21 +590,18 @@ already_AddRefed<nsIDOMCSSStyleDeclarati
 nsCoreUtils::GetComputedStyleDeclaration(const nsAString& aPseudoElt,
                                          nsIContent *aContent)
 {
   nsIContent* content = GetDOMElementFor(aContent);
   if (!content)
     return nsnull;
 
   // Returns number of items in style declaration
-  nsIDocument* document = content->OwnerDoc();
-  if (!document)
-    return nsnull;
-
-  nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(document->GetWindow());
+  nsCOMPtr<nsIDOMWindow> window =
+    do_QueryInterface(content->OwnerDoc()->GetWindow());
   if (!window)
     return nsnull;
 
   nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
   nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(content));
   window->GetComputedStyle(domElement, aPseudoElt, getter_AddRefs(cssDecl));
   return cssDecl.forget();
 }
--- a/accessible/src/base/nsCoreUtils.h
+++ b/accessible/src/base/nsCoreUtils.h
@@ -249,18 +249,17 @@ public:
    */
   static bool IsCorrectFrameType(nsIFrame* aFrame, nsIAtom* aAtom);
 
   /**
    * Return presShell for the document containing the given DOM node.
    */
   static nsIPresShell *GetPresShellFor(nsINode *aNode)
   {
-    nsIDocument *document = aNode->OwnerDoc();
-    return document ? document->GetShell() : nsnull;
+    return aNode->OwnerDoc()->GetShell();
   }
   static already_AddRefed<nsIWeakReference> GetWeakShellFor(nsINode *aNode)
   {
     nsCOMPtr<nsIWeakReference> weakShell =
       do_GetWeakReference(GetPresShellFor(aNode));
     return weakShell.forget();
   }
 
--- a/accessible/src/xul/nsXULMenuAccessible.cpp
+++ b/accessible/src/xul/nsXULMenuAccessible.cpp
@@ -458,21 +458,17 @@ nsXULMenuitemAccessible::AccessKey() con
 KeyBinding
 nsXULMenuitemAccessible::KeyboardShortcut() const
 {
   nsAutoString keyElmId;
   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyElmId);
   if (keyElmId.IsEmpty())
     return KeyBinding();
 
-  nsIDocument* document = mContent->OwnerDoc();
-  if (!document)
-    return KeyBinding();
-
-  nsIContent* keyElm = document->GetElementById(keyElmId);
+  nsIContent* keyElm = mContent->OwnerDoc()->GetElementById(keyElmId);
   if (!keyElm)
     return KeyBinding();
 
   PRUint32 key = 0;
 
   nsAutoString keyStr;
   keyElm->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyStr);
   if (keyStr.IsEmpty()) {
--- a/accessible/src/xul/nsXULSliderAccessible.cpp
+++ b/accessible/src/xul/nsXULSliderAccessible.cpp
@@ -199,21 +199,17 @@ nsXULSliderAccessible::GetAllowsAnonChil
 
 already_AddRefed<nsIContent>
 nsXULSliderAccessible::GetSliderNode()
 {
   if (IsDefunct())
     return nsnull;
 
   if (!mSliderNode) {
-    nsIDocument* document = mContent->OwnerDoc();
-    if (!document)
-      return nsnull;
-
-    nsCOMPtr<nsIDOMDocumentXBL> xblDoc(do_QueryInterface(document));
+    nsCOMPtr<nsIDOMDocumentXBL> xblDoc(do_QueryInterface(mContent->OwnerDoc()));
     if (!xblDoc)
       return nsnull;
 
     // XXX: we depend on anonymous content.
     nsCOMPtr<nsIDOMElement> domElm(do_QueryInterface(mContent));
     if (!domElm)
       return nsnull;
 
--- a/accessible/src/xul/nsXULTextAccessible.cpp
+++ b/accessible/src/xul/nsXULTextAccessible.cpp
@@ -256,13 +256,13 @@ nsXULLinkAccessible::AnchorURIAt(PRUint3
   nsAutoString href;
   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
 
   nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
   nsIDocument* document = mContent->OwnerDoc();
 
   nsIURI* anchorURI = nsnull;
   NS_NewURI(&anchorURI, href,
-            document ? document->GetDocumentCharacterSet().get() : nsnull,
+            document->GetDocumentCharacterSet().get(),
             baseURI);
 
   return anchorURI;
 }
--- a/browser/components/shell/src/nsMacShellService.cpp
+++ b/browser/components/shell/src/nsMacShellService.cpp
@@ -169,22 +169,18 @@ nsMacShellService::SetDesktopBackground(
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIURI> imageURI;
   rv = imageContent->GetCurrentURI(getter_AddRefs(imageURI));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We need the referer URI for nsIWebBrowserPersist::saveURI
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsIDocument> doc;
-  doc = content->OwnerDoc();
-  if (!doc)
-    return NS_ERROR_FAILURE;
 
-  nsIURI *docURI = doc->GetDocumentURI();
+  nsIURI *docURI = content->OwnerDoc()->GetDocumentURI();
   if (!docURI)
     return NS_ERROR_FAILURE;
 
   // Get the desired image file name
   nsCOMPtr<nsIURL> imageURL(do_QueryInterface(imageURI));
   if (!imageURL) {
     // XXXmano (bug 300293): Non-URL images (e.g. the data: protocol) are not
     // yet supported. What filename should we take here?
--- a/content/base/public/nsIContent.h
+++ b/content/base/public/nsIContent.h
@@ -273,19 +273,17 @@ public:
   }
 
   /**
    * Return true iff this node is in an HTML document (in the HTML5 sense of
    * the term, i.e. not in an XHTML/XML document).
    */
   inline bool IsInHTMLDocument() const
   {
-    nsIDocument* doc = OwnerDoc();
-    return doc && // XXX clean up after bug 335998 lands
-           doc->IsHTML();
+    return OwnerDoc()->IsHTML();
   }
 
   /**
    * Get the namespace that this element's tag is defined in
    * @return the namespace
    */
   PRInt32 GetNameSpaceID() const
   {
--- a/content/base/src/nsContentList.cpp
+++ b/content/base/src/nsContentList.cpp
@@ -842,19 +842,18 @@ nsContentList::Match(Element *aElement)
   bool wildcard = mMatchNameSpaceId == kNameSpaceID_Wildcard;
   bool toReturn = mMatchAll;
   if (!unknown && !wildcard)
     toReturn &= ni->NamespaceEquals(mMatchNameSpaceId);
 
   if (toReturn)
     return toReturn;
 
-  nsIDocument* doc = aElement->OwnerDoc();
   bool matchHTML = aElement->GetNameSpaceID() == kNameSpaceID_XHTML &&
-    doc && doc->IsHTML();
+    aElement->OwnerDoc()->IsHTML();
  
   if (unknown) {
     return matchHTML ? ni->QualifiedNameEquals(mHTMLMatchAtom) :
                        ni->QualifiedNameEquals(mXMLMatchAtom);
   }
   
   if (wildcard) {
     return matchHTML ? ni->Equals(mHTMLMatchAtom) :
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -3243,19 +3243,16 @@ nsContentUtils::HasNonEmptyAttr(const ns
 
 /* static */
 bool
 nsContentUtils::HasMutationListeners(nsINode* aNode,
                                      PRUint32 aType,
                                      nsINode* aTargetForSubtreeModified)
 {
   nsIDocument* doc = aNode->OwnerDoc();
-  if (!doc) {
-    return false;
-  }
 
   // global object will be null for documents that don't have windows.
   nsPIDOMWindow* window = doc->GetInnerWindow();
   // This relies on nsEventListenerManager::AddEventListener, which sets
   // all mutation bits when there is a listener for DOMSubtreeModified event.
   if (window && !window->HasMutationListeners(aType)) {
     return false;
   }
@@ -3489,18 +3486,16 @@ nsContentUtils::CreateContextualFragment
                                          nsIDOMDocumentFragment** aReturn)
 {
   *aReturn = nsnull;
   NS_ENSURE_ARG(aContextNode);
 
   // If we don't have a document here, we can't get the right security context
   // for compiling event handlers... so just bail out.
   nsCOMPtr<nsIDocument> document = aContextNode->OwnerDoc();
-  NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE);
-
   bool isHTML = document->IsHTML();
 #ifdef DEBUG
   nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(document);
   NS_ASSERTION(!isHTML || htmlDoc, "Should have HTMLDocument here!");
 #endif
 
   if (isHTML) {
     nsCOMPtr<nsIDOMDocumentFragment> frag;
@@ -4731,25 +4726,19 @@ nsContentUtils::SplitURIAtHash(nsIURI *a
 }
 
 /* static */
 nsIScriptContext*
 nsContentUtils::GetContextForEventHandlers(nsINode* aNode,
                                            nsresult* aRv)
 {
   *aRv = NS_OK;
-  nsIDocument* ownerDoc = aNode->OwnerDoc();
-  if (!ownerDoc) {
-    *aRv = NS_ERROR_UNEXPECTED;
-    return nsnull;
-  }
-
   bool hasHadScriptObject = true;
   nsIScriptGlobalObject* sgo =
-    ownerDoc->GetScriptHandlingObject(hasHadScriptObject);
+    aNode->OwnerDoc()->GetScriptHandlingObject(hasHadScriptObject);
   // It is bad if the document doesn't have event handling context,
   // but it used to have one.
   if (!sgo && hasHadScriptObject) {
     *aRv = NS_ERROR_UNEXPECTED;
     return nsnull;
   }
 
   if (sgo) {
@@ -5349,17 +5338,16 @@ AllocClassMatchingInfo(nsINode* aRootNod
 
   if (attrValue.Type() == nsAttrValue::eAtomArray) {
     info->mClasses.SwapElements(*(attrValue.GetAtomArrayValue()));
   } else if (attrValue.Type() == nsAttrValue::eAtom) {
     info->mClasses.AppendElement(attrValue.GetAtomValue());
   }
 
   info->mCaseTreatment =
-    aRootNode->OwnerDoc() &&
     aRootNode->OwnerDoc()->GetCompatibilityMode() == eCompatibility_NavQuirks ?
     eIgnoreCase : eCaseMatters;
   return info;
 }
 
 // static
 
 nsresult
--- a/content/base/src/nsDOMAttribute.cpp
+++ b/content/base/src/nsDOMAttribute.cpp
@@ -176,19 +176,17 @@ nsDOMAttribute::GetContent() const
 
 nsresult
 nsDOMAttribute::SetOwnerDocument(nsIDocument* aDocument)
 {
   NS_ASSERTION(aDocument, "Missing document");
 
   nsIDocument *doc = OwnerDoc();
   NS_ASSERTION(doc != aDocument, "bad call to nsDOMAttribute::SetOwnerDocument");
-  if (doc) {
-    doc->DeleteAllPropertiesFor(this);
-  }
+  doc->DeleteAllPropertiesFor(this);
 
   nsCOMPtr<nsINodeInfo> newNodeInfo;
   newNodeInfo = aDocument->NodeInfoManager()->
     GetNodeInfo(mNodeInfo->NameAtom(), mNodeInfo->GetPrefixAtom(),
                 mNodeInfo->NamespaceID(),
                 nsIDOMNode::ATTRIBUTE_NODE);
   NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY);
   NS_ASSERTION(newNodeInfo, "GetNodeInfo lies");
@@ -270,260 +268,201 @@ nsDOMAttribute::SetValue(const nsAString
   return rv;
 }
 
 
 NS_IMETHODIMP
 nsDOMAttribute::GetSpecified(bool* aSpecified)
 {
   NS_ENSURE_ARG_POINTER(aSpecified);
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eSpecified);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eSpecified);
+
   *aSpecified = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetOwnerElement(nsIDOMElement** aOwnerElement)
 {
   NS_ENSURE_ARG_POINTER(aOwnerElement);
-
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eOwnerElement);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eOwnerElement);
 
   nsIContent* content = GetContentInternal();
   if (content) {
     return CallQueryInterface(content, aOwnerElement);
   }
 
   *aOwnerElement = nsnull;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetNodeName(nsAString& aNodeName)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eNodeName);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eNodeName);
 
   return GetName(aNodeName);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetNodeValue(nsAString& aNodeValue)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eNodeValue);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eNodeValue);
 
   return GetValue(aNodeValue);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::SetNodeValue(const nsAString& aNodeValue)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eNodeValue);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eNodeValue);
 
   return SetValue(aNodeValue);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetNodeType(PRUint16* aNodeType)
 {
   NS_ENSURE_ARG_POINTER(aNodeType);
-
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eNodeType);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eNodeType);
 
   *aNodeType = (PRUint16)nsIDOMNode::ATTRIBUTE_NODE;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetParentNode(nsIDOMNode** aParentNode)
 {
   NS_ENSURE_ARG_POINTER(aParentNode);
-
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eParentNode);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eParentNode);
 
   *aParentNode = nsnull;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetParentElement(nsIDOMElement** aParentElement)
 {
   *aParentElement = nsnull;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetChildNodes(nsIDOMNodeList** aChildNodes)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eChildNodes);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eChildNodes);
 
   return nsINode::GetChildNodes(aChildNodes);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::HasChildNodes(bool* aHasChildNodes)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eHasChildNodes);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eHasChildNodes);
 
   *aHasChildNodes = mFirstChild != nsnull;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::HasAttributes(bool* aHasAttributes)
 {
   NS_ENSURE_ARG_POINTER(aHasAttributes);
-
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eHasAttributes);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eHasAttributes);
 
   *aHasAttributes = false;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetFirstChild(nsIDOMNode** aFirstChild)
 {
   *aFirstChild = nsnull;
 
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eFirstChild);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eFirstChild);
 
   if (mFirstChild) {
     CallQueryInterface(mFirstChild, aFirstChild);
   }
   
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetLastChild(nsIDOMNode** aLastChild)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eLastChild);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eLastChild);
+
   return GetFirstChild(aLastChild);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetPreviousSibling(nsIDOMNode** aPreviousSibling)
 {
   NS_ENSURE_ARG_POINTER(aPreviousSibling);
 
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::ePreviousSibling);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::ePreviousSibling);
 
   *aPreviousSibling = nsnull;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetNextSibling(nsIDOMNode** aNextSibling)
 {
   NS_ENSURE_ARG_POINTER(aNextSibling);
 
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eNextSibling);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eNextSibling);
 
   *aNextSibling = nsnull;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetAttributes(nsIDOMNamedNodeMap** aAttributes)
 {
   NS_ENSURE_ARG_POINTER(aAttributes);
 
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eAttributes);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eAttributes);
 
   *aAttributes = nsnull;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eInsertBefore);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eInsertBefore);
 
   return ReplaceOrInsertBefore(false, aNewChild, aRefChild, aReturn);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eReplaceChild);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eReplaceChild);
 
   return ReplaceOrInsertBefore(true, aNewChild, aOldChild, aReturn);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eRemoveChild);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eRemoveChild);
 
   return nsINode::RemoveChild(aOldChild, aReturn);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eAppendChild);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eAppendChild);
 
   return InsertBefore(aNewChild, nsnull, aReturn);
 }
 
 nsresult
 nsDOMAttribute::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
 {
   nsAutoString value;
@@ -538,31 +477,25 @@ nsDOMAttribute::Clone(nsINodeInfo *aNode
   NS_ADDREF(*aResult);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::CloneNode(bool aDeep, nsIDOMNode** aResult)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eCloneNode);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eCloneNode);
 
   return nsNodeUtils::CloneNodeImpl(this, aDeep, true, aResult);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eOwnerDocument);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eOwnerDocument);
 
   return nsINode::GetOwnerDocument(aOwnerDocument);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetNamespaceURI(nsAString& aNamespaceURI)
 {
   return mNodeInfo->GetNamespaceURI(aNamespaceURI);
@@ -580,34 +513,29 @@ nsDOMAttribute::GetLocalName(nsAString& 
 {
   mNodeInfo->GetName(aLocalName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::Normalize()
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eNormalize);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eNormalize);
 
   // Nothing to do here
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::IsSupported(const nsAString& aFeature,
                             const nsAString& aVersion,
                             bool* aReturn)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eIsSupported);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eIsSupported);
+
   return nsGenericElement::InternalIsSupported(static_cast<nsIDOMAttr*>(this), 
                                                aFeature, aVersion, aReturn);
 }
 
 already_AddRefed<nsIURI>
 nsDOMAttribute::GetBaseURI() const
 {
   nsINode *parent = GetContentInternal();
@@ -626,50 +554,41 @@ nsDOMAttribute::CompareDocumentPosition(
                                         PRUint16 *aResult)
 {
   return nsINode::CompareDocumentPosition(other, aResult);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::IsEqualNode(nsIDOMNode* aOther, bool* aResult)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eIsEqualNode);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eIsEqualNode);
+
   return nsINode::IsEqualNode(aOther, aResult);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::GetTextContent(nsAString &aTextContent)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eTextContent);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eTextContent);
+
   return GetNodeValue(aTextContent);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::SetTextContent(const nsAString& aTextContent)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eTextContent);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eTextContent);
+
   return SetNodeValue(aTextContent);
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::IsSameNode(nsIDOMNode *other, bool *aResult)
 {
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eIsSameNode);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eIsSameNode);
 
   *aResult = other == this;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMAttribute::Contains(nsIDOMNode* aOther, bool* aReturn)
 {
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -395,18 +395,17 @@ nsIdentifierMapEntry::RemoveIdElement(El
   NS_PRECONDITION(aElement, "Missing element");
 
   // This should only be called while the document is in an update.
   // Assertions near the call to this method guarantee this.
 
   // This could fire in OOM situations
   // Only assert this in HTML documents for now as XUL does all sorts of weird
   // crap.
-  NS_ASSERTION(!aElement->OwnerDoc() ||
-               !aElement->OwnerDoc()->IsHTML() ||
+  NS_ASSERTION(!aElement->OwnerDoc()->IsHTML() ||
                mIdContentList.IndexOf(aElement) >= 0,
                "Removing id entry that doesn't exist");
 
   // XXXbz should this ever Compact() I guess when all the content is gone
   // we'll just get cleaned up in the natural order of things...
   Element* currentElement =
     static_cast<Element*>(mIdContentList.SafeElementAt(0));
   mIdContentList.RemoveElement(aElement);
@@ -1124,19 +1123,16 @@ nsExternalResourceMap::PendingLoad::Star
                                  nsContentUtils::GetSecurityManager());
   if (NS_FAILED(rv)) return rv;
   if (NS_CP_REJECTED(shouldLoad)) {
     // Disallowed by content policy
     return NS_ERROR_CONTENT_BLOCKED;
   }
 
   nsIDocument* doc = aRequestingNode->OwnerDoc();
-  if (!doc) {
-    return NS_ERROR_NOT_AVAILABLE;
-  }
 
   nsCOMPtr<nsIInterfaceRequestor> req = nsContentUtils::GetSameOriginChecker();
   NS_ENSURE_TRUE(req, NS_ERROR_OUT_OF_MEMORY);
 
   nsCOMPtr<nsILoadGroup> loadGroup = doc->GetDocumentLoadGroup();
   nsCOMPtr<nsIChannel> channel;
   rv = NS_NewChannel(getter_AddRefs(channel), aURI, nsnull, loadGroup, req);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -4811,22 +4807,20 @@ nsDocument::ImportNode(nsIDOMNode* aImpo
 
       nsCOMPtr<nsIDOMNode> newNode;
       nsCOMArray<nsINode> nodesWithProperties;
       rv = nsNodeUtils::Clone(imported, aDeep, mNodeInfoManager,
                               nodesWithProperties, getter_AddRefs(newNode));
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsIDocument *ownerDoc = imported->OwnerDoc();
-      if (ownerDoc) {
-        rv = nsNodeUtils::CallUserDataHandlers(nodesWithProperties, ownerDoc,
-                                               nsIDOMUserDataHandler::NODE_IMPORTED,
-                                               true);
-        NS_ENSURE_SUCCESS(rv, rv);
-      }
+      rv = nsNodeUtils::CallUserDataHandlers(nodesWithProperties, ownerDoc,
+                                             nsIDOMUserDataHandler::NODE_IMPORTED,
+                                             true);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       newNode.swap(*aResult);
 
       return NS_OK;
     }
     case nsIDOMNode::ENTITY_NODE:
     case nsIDOMNode::ENTITY_REFERENCE_NODE:
     case nsIDOMNode::NOTATION_NODE:
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -335,17 +335,17 @@ nsFrameLoader::nsFrameLoader(Element* aO
 {
 }
 
 nsFrameLoader*
 nsFrameLoader::Create(Element* aOwner, bool aNetworkCreated)
 {
   NS_ENSURE_TRUE(aOwner, nsnull);
   nsIDocument* doc = aOwner->OwnerDoc();
-  NS_ENSURE_TRUE(doc && !doc->GetDisplayDocument() &&
+  NS_ENSURE_TRUE(!doc->GetDisplayDocument() &&
                  ((!doc->IsLoadedAsData() && aOwner->GetCurrentDoc()) ||
                    doc->IsStaticDocument()),
                  nsnull);
 
   return new nsFrameLoader(aOwner, aNetworkCreated);
 }
 
 NS_IMETHODIMP
@@ -358,17 +358,17 @@ nsFrameLoader::LoadFrame()
 
   src.Trim(" \t\n\r");
 
   if (src.IsEmpty()) {
     src.AssignLiteral("about:blank");
   }
 
   nsIDocument* doc = mOwnerContent->OwnerDoc();
-  if (!doc || doc->IsStaticDocument()) {
+  if (doc->IsStaticDocument()) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIURI> base_uri = mOwnerContent->GetBaseURI();
   const nsAFlatCString &doc_charset = doc->GetDocumentCharacterSet();
   const char *charset = doc_charset.IsEmpty() ? nsnull : doc_charset.get();
 
   nsCOMPtr<nsIURI> uri;
@@ -407,19 +407,16 @@ nsFrameLoader::FireErrorEvent()
 NS_IMETHODIMP
 nsFrameLoader::LoadURI(nsIURI* aURI)
 {
   if (!aURI)
     return NS_ERROR_INVALID_POINTER;
   NS_ENSURE_STATE(!mDestroyCalled && mOwnerContent);
 
   nsCOMPtr<nsIDocument> doc = mOwnerContent->OwnerDoc();
-  if (!doc) {
-    return NS_OK;
-  }
 
   nsresult rv = CheckURILoad(aURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mURIToLoad = aURI;
   rv = doc->InitializeFrameLoader(this);
   if (NS_FAILED(rv)) {
     mURIToLoad = nsnull;
@@ -1270,21 +1267,18 @@ nsFrameLoader::Destroy()
   if (mChildMessageManager) {
     static_cast<nsInProcessTabChildGlobal*>(mChildMessageManager.get())->Disconnect();
   }
 
   nsCOMPtr<nsIDocument> doc;
   bool dynamicSubframeRemoval = false;
   if (mOwnerContent) {
     doc = mOwnerContent->OwnerDoc();
-
-    if (doc) {
-      dynamicSubframeRemoval = !mIsTopLevelContent && !doc->InUnlinkOrDeletion();
-      doc->SetSubDocumentFor(mOwnerContent, nsnull);
-    }
+    dynamicSubframeRemoval = !mIsTopLevelContent && !doc->InUnlinkOrDeletion();
+    doc->SetSubDocumentFor(mOwnerContent, nsnull);
 
     SetOwnerContent(nsnull);
   }
   DestroyChild();
 
   // Seems like this is a dynamic frame removal.
   if (dynamicSubframeRemoval) {
     nsCOMPtr<nsIDocShellHistory> dhistory = do_QueryInterface(mDocShell);
@@ -1378,17 +1372,17 @@ nsFrameLoader::MaybeCreateDocShell()
     mRemoteFrame = true;
     return NS_OK;
   }
 
   // Get our parent docshell off the document of mOwnerContent
   // XXXbz this is such a total hack.... We really need to have a
   // better setup for doing this.
   nsIDocument* doc = mOwnerContent->OwnerDoc();
-  if (!doc || !(doc->IsStaticDocument() || mOwnerContent->IsInDoc())) {
+  if (!(doc->IsStaticDocument() || mOwnerContent->IsInDoc())) {
     return NS_ERROR_UNEXPECTED;
   }
 
   if (doc->GetDisplayDocument() || !doc->IsActive()) {
     // Don't allow subframe loads in external reference documents, nor
     // in non-active documents.
     return NS_ERROR_NOT_AVAILABLE;
   }
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -101,20 +101,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
   // Always need to traverse script objects, so do that before we check
   // if we're uncollectable.
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 
   if (!nsINode::Traverse(tmp, cb)) {
     return NS_SUCCESS_INTERRUPTED_TRAVERSE;
   }
 
-  nsIDocument* ownerDoc = tmp->OwnerDoc();
-  if (ownerDoc) {
-    ownerDoc->BindingManager()->Traverse(tmp, cb);
-  }
+  tmp->OwnerDoc()->BindingManager()->Traverse(tmp, cb);
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericDOMDataNode)
   nsINode::Unlink(tmp);
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -212,61 +212,51 @@ nsINode::~nsINode()
 {
   NS_ASSERTION(!HasSlots(), "nsNodeUtils::LastRelease was not called?");
 }
 
 void*
 nsINode::GetProperty(PRUint16 aCategory, nsIAtom *aPropertyName,
                      nsresult *aStatus) const
 {
-  nsIDocument *doc = OwnerDoc();
-  if (!doc)
-    return nsnull;
-
-  return doc->PropertyTable(aCategory)->GetProperty(this, aPropertyName,
-                                                    aStatus);
+  return OwnerDoc()->PropertyTable(aCategory)->GetProperty(this, aPropertyName,
+                                                           aStatus);
 }
 
 nsresult
 nsINode::SetProperty(PRUint16 aCategory, nsIAtom *aPropertyName, void *aValue,
                      NSPropertyDtorFunc aDtor, bool aTransfer,
                      void **aOldValue)
 {
-  nsIDocument *doc = OwnerDoc();
-  if (!doc)
-    return NS_ERROR_FAILURE;
-
-  nsresult rv = doc->PropertyTable(aCategory)->SetProperty(this,
-                                                           aPropertyName, aValue, aDtor,
-                                                           nsnull, aTransfer, aOldValue);
+  nsresult rv = OwnerDoc()->PropertyTable(aCategory)->SetProperty(this,
+                                                                  aPropertyName,
+                                                                  aValue, aDtor,
+                                                                  nsnull,
+                                                                  aTransfer,
+                                                                  aOldValue);
   if (NS_SUCCEEDED(rv)) {
     SetFlags(NODE_HAS_PROPERTIES);
   }
 
   return rv;
 }
 
 void
 nsINode::DeleteProperty(PRUint16 aCategory, nsIAtom *aPropertyName)
 {
-  nsIDocument *doc = OwnerDoc();
-  if (doc)
-    doc->PropertyTable(aCategory)->DeleteProperty(this, aPropertyName);
+  OwnerDoc()->PropertyTable(aCategory)->DeleteProperty(this, aPropertyName);
 }
 
 void*
 nsINode::UnsetProperty(PRUint16 aCategory, nsIAtom *aPropertyName,
                        nsresult *aStatus)
 {
-  nsIDocument *doc = OwnerDoc();
-  if (!doc)
-    return nsnull;
-
-  return doc->PropertyTable(aCategory)->UnsetProperty(this, aPropertyName,
-                                                      aStatus);
+  return OwnerDoc()->PropertyTable(aCategory)->UnsetProperty(this,
+                                                             aPropertyName,
+                                                             aStatus);
 }
 
 nsINode::nsSlots*
 nsINode::CreateSlots()
 {
   return new nsSlots();
 }
 
@@ -1340,22 +1330,20 @@ nsIContent::FindFirstNonNativeAnonymous(
 }
 
 nsIContent*
 nsIContent::GetFlattenedTreeParent() const
 {
   nsIContent *parent = GetParent();
   if (parent && parent->HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
     nsIDocument *doc = parent->OwnerDoc();
-    if (doc) {
-      nsIContent* insertionElement =
-        doc->BindingManager()->GetNestedInsertionPoint(parent, this);
-      if (insertionElement) {
-        parent = insertionElement;
-      }
+    nsIContent* insertionElement =
+      doc->BindingManager()->GetNestedInsertionPoint(parent, this);
+    if (insertionElement) {
+      parent = insertionElement;
     }
   }
   return parent;
 }
 
 PRUint32
 nsIContent::GetDesiredIMEState()
 {
@@ -1458,51 +1446,41 @@ nsIContent::LookupNamespaceURI(const nsA
   } while ((content = content->GetParent()));
   return NS_ERROR_FAILURE;
 }
 
 already_AddRefed<nsIURI>
 nsIContent::GetBaseURI() const
 {
   nsIDocument* doc = OwnerDoc();
-  if (!doc) {
-    // We won't be able to do security checks, etc.  So don't go any
-    // further.  That said, this really shouldn't happen...
-    NS_ERROR("Element without owner document");
-    return nsnull;
-  }
-
   // Start with document base
   nsCOMPtr<nsIURI> base = doc->GetDocBaseURI();
 
   // Collect array of xml:base attribute values up the parent chain. This
   // is slightly slower for the case when there are xml:base attributes, but
   // faster for the far more common case of there not being any such
   // attributes.
   // Also check for SVG elements which require special handling
   nsAutoTArray<nsString, 5> baseAttrs;
   nsString attr;
   const nsIContent *elem = this;
   do {
     // First check for SVG specialness (why is this SVG specific?)
     if (elem->IsSVG()) {
       nsIContent* bindingParent = elem->GetBindingParent();
       if (bindingParent) {
-        nsIDocument* bindingDoc = bindingParent->OwnerDoc();
-        if (bindingDoc) {
-          nsXBLBinding* binding =
-            bindingDoc->BindingManager()->GetBinding(bindingParent);
-          if (binding) {
-            // XXX sXBL/XBL2 issue
-            // If this is an anonymous XBL element use the binding
-            // document for the base URI. 
-            // XXX Will fail with xml:base
-            base = binding->PrototypeBinding()->DocURI();
-            break;
-          }
+        nsXBLBinding* binding =
+          bindingParent->OwnerDoc()->BindingManager()->GetBinding(bindingParent);
+        if (binding) {
+          // XXX sXBL/XBL2 issue
+          // If this is an anonymous XBL element use the binding
+          // document for the base URI. 
+          // XXX Will fail with xml:base
+          base = binding->PrototypeBinding()->DocURI();
+          break;
         }
       }
     }
     
     // Otherwise check for xml:base attribute
     elem->GetAttr(kNameSpaceID_XML, nsGkAtoms::base, attr);
     if (!attr.IsEmpty()) {
       baseAttrs.AppendElement(attr);
@@ -2635,20 +2613,17 @@ nsresult
 nsGenericElement::SetAttributeNode(nsIDOMAttr* aAttribute,
                                    nsIDOMAttr** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   NS_ENSURE_ARG_POINTER(aAttribute);
 
   *aReturn = nsnull;
 
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eSetAttributeNode);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eSetAttributeNode);
 
   nsCOMPtr<nsIDOMNamedNodeMap> map;
   nsresult rv = GetAttributes(getter_AddRefs(map));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMNode> returnNode;
   rv = map->SetNamedItem(aAttribute, getter_AddRefs(returnNode));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -2664,20 +2639,17 @@ nsresult
 nsGenericElement::RemoveAttributeNode(nsIDOMAttr* aAttribute,
                                       nsIDOMAttr** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   NS_ENSURE_ARG_POINTER(aAttribute);
 
   *aReturn = nsnull;
 
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eRemoveAttributeNode);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eRemoveAttributeNode);
 
   nsCOMPtr<nsIDOMNamedNodeMap> map;
   nsresult rv = GetAttributes(getter_AddRefs(map));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoString name;
 
   rv = aAttribute->GetName(name);
@@ -2766,20 +2738,17 @@ nsGenericElement::RemoveAttributeNS(cons
 nsresult
 nsGenericElement::GetAttributeNodeNS(const nsAString& aNamespaceURI,
                                      const nsAString& aLocalName,
                                      nsIDOMAttr** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   *aReturn = nsnull;
 
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eGetAttributeNodeNS);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eGetAttributeNodeNS);
 
   nsCOMPtr<nsIDOMNamedNodeMap> map;
   nsresult rv = GetAttributes(getter_AddRefs(map));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMNode> node;
   rv = map->GetNamedItemNS(aNamespaceURI, aLocalName, getter_AddRefs(node));
 
@@ -2793,20 +2762,17 @@ nsGenericElement::GetAttributeNodeNS(con
 nsresult
 nsGenericElement::SetAttributeNodeNS(nsIDOMAttr* aNewAttr,
                                      nsIDOMAttr** aReturn)
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   NS_ENSURE_ARG_POINTER(aNewAttr);
   *aReturn = nsnull;
 
-  nsIDocument* document = OwnerDoc();
-  if (document) {
-    document->WarnOnceAbout(nsIDocument::eSetAttributeNodeNS);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eSetAttributeNodeNS);
 
   nsCOMPtr<nsIDOMNamedNodeMap> map;
   nsresult rv = GetAttributes(getter_AddRefs(map));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMNode> returnNode;
   rv = map->SetNamedItemNS(aNewAttr, getter_AddRefs(returnNode));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -3029,47 +2995,44 @@ nsGenericElement::BindToTree(nsIDocument
                // And the restyle bits
                ELEMENT_ALL_RESTYLE_FLAGS);
   }
 
   // If NODE_FORCE_XBL_BINDINGS was set we might have anonymous children
   // that also need to be told that they are moving.
   nsresult rv;
   if (hadForceXBL) {
-    nsIDocument* ownerDoc = OwnerDoc();
-    if (ownerDoc) {
-      nsBindingManager* bmgr = ownerDoc->BindingManager();
-
-      // First check if we have a binding...
-      nsXBLBinding* contBinding =
-        GetFirstBindingWithContent(bmgr, this);
-      if (contBinding) {
-        nsCOMPtr<nsIContent> anonRoot = contBinding->GetAnonymousContent();
-        bool allowScripts = contBinding->AllowScripts();
-        for (nsCOMPtr<nsIContent> child = anonRoot->GetFirstChild();
-             child;
-             child = child->GetNextSibling()) {
-          rv = child->BindToTree(aDocument, this, this, allowScripts);
-          NS_ENSURE_SUCCESS(rv, rv);
-        }
-
-        // ...then check if we have content in insertion points that are
-        // direct children of the <content>
-        rv = BindNodesInInsertPoints(contBinding, this, aDocument);
+    nsBindingManager* bmgr = OwnerDoc()->BindingManager();
+
+    // First check if we have a binding...
+    nsXBLBinding* contBinding =
+      GetFirstBindingWithContent(bmgr, this);
+    if (contBinding) {
+      nsCOMPtr<nsIContent> anonRoot = contBinding->GetAnonymousContent();
+      bool allowScripts = contBinding->AllowScripts();
+      for (nsCOMPtr<nsIContent> child = anonRoot->GetFirstChild();
+           child;
+           child = child->GetNextSibling()) {
+        rv = child->BindToTree(aDocument, this, this, allowScripts);
         NS_ENSURE_SUCCESS(rv, rv);
       }
 
-      // ...and finally check if we're in a binding where we have content in
-      // insertion points.
-      if (aBindingParent) {
-        nsXBLBinding* binding = bmgr->GetBinding(aBindingParent);
-        if (binding) {
-          rv = BindNodesInInsertPoints(binding, this, aDocument);
-          NS_ENSURE_SUCCESS(rv, rv);
-        }
+      // ...then check if we have content in insertion points that are
+      // direct children of the <content>
+      rv = BindNodesInInsertPoints(contBinding, this, aDocument);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+
+    // ...and finally check if we're in a binding where we have content in
+    // insertion points.
+    if (aBindingParent) {
+      nsXBLBinding* binding = bmgr->GetBinding(aBindingParent);
+      if (binding) {
+        rv = BindNodesInInsertPoints(binding, this, aDocument);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     }
   }
 
   UpdateEditableState(false);
 
   // Now recurse into our kids
   for (nsIContent* child = GetFirstChild(); child;
@@ -3187,28 +3150,24 @@ nsGenericElement::GetChildren(PRUint32 a
 
   // If XBL is bound to this node then append XBL anonymous content including
   // explict content altered by insertion point if we were requested for XBL
   // anonymous content, otherwise append explicit content with respect to
   // insertion point if any.
   nsINodeList *childList = nsnull;
 
   nsIDocument* document = OwnerDoc();
-  if (document) {
-    if (!(aFilter & eAllButXBL)) {
-      childList = document->BindingManager()->GetXBLChildNodesFor(this);
-      if (!childList) {
-        childList = GetChildNodesList();
-      }
-
-    } else {
-      childList = document->BindingManager()->GetContentListFor(this);
+  if (!(aFilter & eAllButXBL)) {
+    childList = document->BindingManager()->GetXBLChildNodesFor(this);
+    if (!childList) {
+      childList = GetChildNodesList();
     }
+
   } else {
-    childList = GetChildNodesList();
+    childList = document->BindingManager()->GetContentListFor(this);
   }
 
   if (childList) {
     PRUint32 length = 0;
     childList->GetLength(&length);
     for (PRUint32 idx = 0; idx < length; idx++) {
       nsIContent* child = childList->GetNodeAt(idx);
       list->AppendElement(child);
@@ -3346,26 +3305,23 @@ nsIContent::PreHandleEvent(nsEventChainP
     if (content && content->GetBindingParent() == parent) {
       aVisitor.mEventTargetAtParent = parent;
     }
   }
 
   // check for an anonymous parent
   // XXX XBL2/sXBL issue
   if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
-    nsIDocument* ownerDoc = OwnerDoc();
-    if (ownerDoc) {
-      nsIContent* insertionParent = ownerDoc->BindingManager()->
-        GetInsertionParent(this);
-      NS_ASSERTION(!(aVisitor.mEventTargetAtParent && insertionParent &&
-                     aVisitor.mEventTargetAtParent != insertionParent),
-                   "Retargeting and having insertion parent!");
-      if (insertionParent) {
-        parent = insertionParent;
-      }
+    nsIContent* insertionParent = OwnerDoc()->BindingManager()->
+      GetInsertionParent(this);
+    NS_ASSERTION(!(aVisitor.mEventTargetAtParent && insertionParent &&
+                   aVisitor.mEventTargetAtParent != insertionParent),
+                 "Retargeting and having insertion parent!");
+    if (insertionParent) {
+      parent = insertionParent;
     }
   }
 
   if (parent) {
     aVisitor.mParentTarget = parent;
   } else {
     aVisitor.mParentTarget = GetCurrentDoc();
   }
@@ -3818,20 +3774,18 @@ nsGenericElement::GetPrimaryFrame(mozFlu
 
   return GetPrimaryFrame();
 }
 
 void
 nsGenericElement::DestroyContent()
 {
   nsIDocument *document = OwnerDoc();
-  if (document) {
-    document->BindingManager()->RemovedFromDocument(this, document);
-    document->ClearBoxObjectFor(this);
-  }
+  document->BindingManager()->RemovedFromDocument(this, document);
+  document->ClearBoxObjectFor(this);
 
   // XXX We really should let cycle collection do this, but that currently still
   //     leaks (see https://bugzilla.mozilla.org/show_bug.cgi?id=406684).
   nsContentUtils::ReleaseWrapper(this, this);
 
   PRUint32 i, count = mAttrsAndChildren.ChildCount();
   for (i = 0; i < count; ++i) {
     // The child can remove itself from the parent in BindToTree.
@@ -4240,20 +4194,18 @@ nsINode::IsEqualNode(nsIDOMNode* aOther,
   nsCOMPtr<nsINode> other = do_QueryInterface(aOther);
   *aReturn = IsEqualTo(other);
   return NS_OK;
 }
 
 nsresult
 nsINode::IsSameNode(nsIDOMNode* aOther, bool* aReturn)
 {
-  nsIDocument* owner = OwnerDoc();
-  if (owner) {
-    owner->WarnOnceAbout(nsIDocument::eIsSameNode);
-  }
+  OwnerDoc()->WarnOnceAbout(nsIDocument::eIsSameNode);
+
   nsCOMPtr<nsINode> other = do_QueryInterface(aOther);
   *aReturn = other == this;
   return NS_OK;
 }
 
 //----------------------------------------------------------------------
 
 // nsISupports implementation
@@ -4342,20 +4294,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
   // Always need to traverse script objects, so do that before we check
   // if we're uncollectable.
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 
   if (!nsINode::Traverse(tmp, cb)) {
     return NS_SUCCESS_INTERRUPTED_TRAVERSE;
   }
 
-  nsIDocument* ownerDoc = tmp->OwnerDoc();
-  if (ownerDoc) {
-    ownerDoc->BindingManager()->Traverse(tmp, cb);
-  }
+  tmp->OwnerDoc()->BindingManager()->Traverse(tmp, cb);
 
   if (tmp->HasProperties() && tmp->IsXUL()) {
     nsISupports* property =
       static_cast<nsISupports*>
                  (tmp->GetProperty(nsGkAtoms::contextmenulistener));
     cb.NoteXPCOMChild(property);
     property = static_cast<nsISupports*>
                           (tmp->GetProperty(nsGkAtoms::popuplistener));
@@ -4418,24 +4367,18 @@ NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGenericElement)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(nsGenericElement,
                                               nsNodeUtils::LastRelease(this))
 
 nsresult
 nsGenericElement::PostQueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
-  nsIDocument *document = OwnerDoc();
-  if (document) {
-    return document->BindingManager()->GetBindingImplementation(this, aIID,
+  return OwnerDoc()->BindingManager()->GetBindingImplementation(this, aIID,
                                                                 aInstancePtr);
-  }
-
-  *aInstancePtr = nsnull;
-  return NS_ERROR_NO_INTERFACE;
 }
 
 //----------------------------------------------------------------------
 nsresult
 nsGenericElement::LeaveLink(nsPresContext* aPresContext)
 {
   nsILinkHandler *handler = aPresContext->GetLinkHandler();
   if (!handler) {
@@ -4446,17 +4389,17 @@ nsGenericElement::LeaveLink(nsPresContex
 }
 
 nsresult
 nsGenericElement::AddScriptEventListener(nsIAtom* aEventName,
                                          const nsAString& aValue,
                                          bool aDefer)
 {
   nsIDocument *ownerDoc = OwnerDoc();
-  if (!ownerDoc || ownerDoc->IsLoadedAsData()) {
+  if (ownerDoc->IsLoadedAsData()) {
     // Make this a no-op rather than throwing an error to avoid
     // the error causing problems setting the attribute.
     return NS_OK;
   }
 
   NS_PRECONDITION(aEventName, "Must have event name!");
   bool defer = true;
   nsEventListenerManager* manager = GetEventListenerManagerForAttr(aEventName,
@@ -4659,23 +4602,20 @@ nsGenericElement::SetAttrAndNotify(PRInt
                                                    nsIDOMNode::ATTRIBUTE_NODE);
     NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
 
     rv = mAttrsAndChildren.SetAndTakeAttr(ni, aParsedValue);
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (document || HasFlag(NODE_FORCE_XBL_BINDINGS)) {
-    nsIDocument* ownerDoc = OwnerDoc();
-    if (ownerDoc) {
-      nsRefPtr<nsXBLBinding> binding =
-        ownerDoc->BindingManager()->GetBinding(this);
-      if (binding) {
-        binding->AttributeChanged(aName, aNamespaceID, false, aNotify);
-      }
+    nsRefPtr<nsXBLBinding> binding =
+      OwnerDoc()->BindingManager()->GetBinding(this);
+    if (binding) {
+      binding->AttributeChanged(aName, aNamespaceID, false, aNotify);
     }
   }
 
   UpdateState(aNotify);
 
   if (aNotify) {
     nsNodeUtils::AttributeChanged(this, aNamespaceID, aName, aModType);
   }
@@ -4889,23 +4829,20 @@ nsGenericElement::UnsetAttr(PRInt32 aNam
   // react to unexpected attribute changes.
   nsMutationGuard::DidMutate();
 
   nsAttrValue oldValue;
   rv = mAttrsAndChildren.RemoveAttrAt(index, oldValue);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (document || HasFlag(NODE_FORCE_XBL_BINDINGS)) {
-    nsIDocument* ownerDoc = OwnerDoc();
-    if (ownerDoc) {
-      nsRefPtr<nsXBLBinding> binding =
-        ownerDoc->BindingManager()->GetBinding(this);
-      if (binding) {
-        binding->AttributeChanged(aName, aNameSpaceID, true, aNotify);
-      }
+    nsRefPtr<nsXBLBinding> binding =
+      OwnerDoc()->BindingManager()->GetBinding(this);
+    if (binding) {
+      binding->AttributeChanged(aName, aNameSpaceID, true, aNotify);
     }
   }
 
   UpdateState(aNotify);
 
   if (aNotify) {
     nsNodeUtils::AttributeChanged(this, aNameSpaceID, aName,
                                   nsIDOMMutationEvent::REMOVAL);
@@ -5053,66 +4990,65 @@ nsGenericElement::List(FILE* out, PRInt3
   }
 
   fputs(">\n", out);
   
   nsGenericElement* nonConstThis = const_cast<nsGenericElement*>(this);
 
   // XXX sXBL/XBL2 issue! Owner or current document?
   nsIDocument *document = OwnerDoc();
-  if (document) {
-    // Note: not listing nsIAnonymousContentCreator-created content...
-
-    nsBindingManager* bindingManager = document->BindingManager();
-    nsCOMPtr<nsIDOMNodeList> anonymousChildren;
-    bindingManager->GetAnonymousNodesFor(nonConstThis,
-                                         getter_AddRefs(anonymousChildren));
-
-    if (anonymousChildren) {
-      PRUint32 length;
-      anonymousChildren->GetLength(&length);
-      if (length > 0) {
-        for (indent = aIndent; --indent >= 0; ) fputs("  ", out);
-        fputs("anonymous-children<\n", out);
-
-        for (PRUint32 i = 0; i < length; ++i) {
-          nsCOMPtr<nsIDOMNode> node;
-          anonymousChildren->Item(i, getter_AddRefs(node));
-          nsCOMPtr<nsIContent> child = do_QueryInterface(node);
-          child->List(out, aIndent + 1);
-        }
-
-        for (indent = aIndent; --indent >= 0; ) fputs("  ", out);
-        fputs(">\n", out);
+
+  // Note: not listing nsIAnonymousContentCreator-created content...
+
+  nsBindingManager* bindingManager = document->BindingManager();
+  nsCOMPtr<nsIDOMNodeList> anonymousChildren;
+  bindingManager->GetAnonymousNodesFor(nonConstThis,
+                                       getter_AddRefs(anonymousChildren));
+
+  if (anonymousChildren) {
+    PRUint32 length;
+    anonymousChildren->GetLength(&length);
+    if (length > 0) {
+      for (indent = aIndent; --indent >= 0; ) fputs("  ", out);
+      fputs("anonymous-children<\n", out);
+
+      for (PRUint32 i = 0; i < length; ++i) {
+        nsCOMPtr<nsIDOMNode> node;
+        anonymousChildren->Item(i, getter_AddRefs(node));
+        nsCOMPtr<nsIContent> child = do_QueryInterface(node);
+        child->List(out, aIndent + 1);
       }
+
+      for (indent = aIndent; --indent >= 0; ) fputs("  ", out);
+      fputs(">\n", out);
     }
-
-    if (bindingManager->HasContentListFor(nonConstThis)) {
-      nsCOMPtr<nsIDOMNodeList> contentList;
-      bindingManager->GetContentListFor(nonConstThis,
-                                        getter_AddRefs(contentList));
-
-      NS_ASSERTION(contentList != nsnull, "oops, binding manager lied");
-      
-      PRUint32 length;
-      contentList->GetLength(&length);
-      if (length > 0) {
-        for (indent = aIndent; --indent >= 0; ) fputs("  ", out);
-        fputs("content-list<\n", out);
-
-        for (PRUint32 i = 0; i < length; ++i) {
-          nsCOMPtr<nsIDOMNode> node;
-          contentList->Item(i, getter_AddRefs(node));
-          nsCOMPtr<nsIContent> child = do_QueryInterface(node);
-          child->List(out, aIndent + 1);
-        }
-
-        for (indent = aIndent; --indent >= 0; ) fputs("  ", out);
-        fputs(">\n", out);
+  }
+
+  if (bindingManager->HasContentListFor(nonConstThis)) {
+    nsCOMPtr<nsIDOMNodeList> contentList;
+    bindingManager->GetContentListFor(nonConstThis,
+                                      getter_AddRefs(contentList));
+
+    NS_ASSERTION(contentList != nsnull, "oops, binding manager lied");
+    
+    PRUint32 length;
+    contentList->GetLength(&length);
+    if (length > 0) {
+      for (indent = aIndent; --indent >= 0; ) fputs("  ", out);
+      fputs("content-list<\n", out);
+
+      for (PRUint32 i = 0; i < length; ++i) {
+        nsCOMPtr<nsIDOMNode> node;
+        contentList->Item(i, getter_AddRefs(node));
+        nsCOMPtr<nsIContent> child = do_QueryInterface(node);
+        child->List(out, aIndent + 1);
       }
+
+      for (indent = aIndent; --indent >= 0; ) fputs("  ", out);
+      fputs(">\n", out);
     }
   }
 }
 
 void
 nsGenericElement::DumpContent(FILE* out, PRInt32 aIndent,
                               bool aDumpAll) const
 {
@@ -5394,18 +5330,16 @@ nsGenericElement::GetLinkTarget(nsAStrin
 static nsresult
 ParseSelectorList(nsINode* aNode,
                   const nsAString& aSelectorString,
                   nsCSSSelectorList** aSelectorList)
 {
   NS_ENSURE_ARG(aNode);
 
   nsIDocument* doc = aNode->OwnerDoc();
-  NS_ENSURE_STATE(doc);
-
   nsCSSParser parser(doc->CSSLoader());
 
   nsCSSSelectorList* selectorList;
   nsresult rv = parser.ParseSelectorString(aSelectorString,
                                            doc->GetDocumentURI(),
                                            0, // XXXbz get the line number!
                                            &selectorList);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/content/base/src/nsGenericElement.h
+++ b/content/base/src/nsGenericElement.h
@@ -898,26 +898,20 @@ protected:
   }
 
   nsDOMSlots *GetExistingDOMSlots() const
   {
     return static_cast<nsDOMSlots*>(GetExistingSlots());
   }
 
   void RegisterFreezableElement() {
-    nsIDocument* doc = OwnerDoc();
-    if (doc) {
-      doc->RegisterFreezableElement(this);
-    }
+    OwnerDoc()->RegisterFreezableElement(this);
   }
   void UnregisterFreezableElement() {
-    nsIDocument* doc = OwnerDoc();
-    if (doc) {
-      doc->UnregisterFreezableElement(this);
-    }
+    OwnerDoc()->UnregisterFreezableElement(this);
   }
 
   /**
    * Add/remove this element to the documents id cache
    */
   void AddToIdTable(nsIAtom* aId) {
     NS_ASSERTION(HasID(), "Node doesn't have an ID?");
     nsIDocument* doc = GetCurrentDoc();
--- a/content/base/src/nsNodeUtils.cpp
+++ b/content/base/src/nsNodeUtils.cpp
@@ -263,19 +263,17 @@ nsNodeUtils::LastRelease(nsINode* aNode)
     // the properties may want to use the owner document of the nsINode.
     static_cast<nsIDocument*>(aNode)->DeleteAllProperties();
   }
   else {
     if (aNode->HasProperties()) {
       // Strong reference to the document so that deleting properties can't
       // delete the document.
       nsCOMPtr<nsIDocument> document = aNode->OwnerDoc();
-      if (document) {
-        document->DeleteAllPropertiesFor(aNode);
-      }
+      document->DeleteAllPropertiesFor(aNode);
     }
 
     // I wonder whether it's faster to do the HasFlag check first....
     if (aNode->IsNodeOfType(nsINode::eHTML_FORM_CONTROL) &&
         aNode->HasFlag(ADDED_TO_FORM)) {
       // Tell the form (if any) this node is going away.  Don't
       // notify, since we're being destroyed in any case.
       static_cast<nsGenericHTMLFormElement*>(aNode)->ClearForm(true);
@@ -297,30 +295,27 @@ nsNodeUtils::LastRelease(nsINode* aNode)
 
     nsContentUtils::RemoveListenerManager(aNode);
     aNode->UnsetFlags(NODE_HAS_LISTENERMANAGER);
   }
 
   if (aNode->IsElement()) {
     nsIDocument* ownerDoc = aNode->OwnerDoc();
     Element* elem = aNode->AsElement();
-    if (ownerDoc) {
-      ownerDoc->ClearBoxObjectFor(elem);
-    }
+    ownerDoc->ClearBoxObjectFor(elem);
     
     NS_ASSERTION(aNode->HasFlag(NODE_FORCE_XBL_BINDINGS) ||
-                 !ownerDoc ||
                  !ownerDoc->BindingManager() ||
                  !ownerDoc->BindingManager()->GetBinding(elem),
                  "Non-forced node has binding on destruction");
 
     // if NODE_FORCE_XBL_BINDINGS is set, the node might still have a binding
     // attached
     if (aNode->HasFlag(NODE_FORCE_XBL_BINDINGS) &&
-        ownerDoc && ownerDoc->BindingManager()) {
+        ownerDoc->BindingManager()) {
       ownerDoc->BindingManager()->RemovedFromDocument(elem, ownerDoc);
     }
   }
 
   nsContentUtils::ReleaseWrapper(aNode, aNode);
 
   delete aNode;
 }
@@ -411,20 +406,16 @@ NoteUserData(void *aObject, nsIAtom *aKe
 }
 
 /* static */
 void
 nsNodeUtils::TraverseUserData(nsINode* aNode,
                               nsCycleCollectionTraversalCallback &aCb)
 {
   nsIDocument* ownerDoc = aNode->OwnerDoc();
-  if (!ownerDoc) {
-    return;
-  }
-
   ownerDoc->PropertyTable(DOM_USER_DATA)->Enumerate(aNode, NoteUserData, &aCb);
   ownerDoc->PropertyTable(DOM_USER_DATA_HANDLER)->Enumerate(aNode, NoteUserData, &aCb);
 }
 
 /* static */
 nsresult
 nsNodeUtils::CloneNodeImpl(nsINode *aNode, bool aDeep,
                            bool aCallUserDataHandlers,
@@ -433,19 +424,18 @@ nsNodeUtils::CloneNodeImpl(nsINode *aNod
   *aResult = nsnull;
 
   nsCOMPtr<nsIDOMNode> newNode;
   nsCOMArray<nsINode> nodesWithProperties;
   nsresult rv = Clone(aNode, aDeep, nsnull, nodesWithProperties,
                       getter_AddRefs(newNode));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsIDocument *ownerDoc = aNode->OwnerDoc();
-  if (ownerDoc && aCallUserDataHandlers) {
-    rv = CallUserDataHandlers(nodesWithProperties, ownerDoc,
+  if (aCallUserDataHandlers) {
+    rv = CallUserDataHandlers(nodesWithProperties, aNode->OwnerDoc(),
                               nsIDOMUserDataHandler::NODE_CLONED, true);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   newNode.swap(*aResult);
 
   return NS_OK;
 }
@@ -488,18 +478,17 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNod
     // Don't allow importing/adopting nodes from non-privileged "scriptable"
     // documents to "non-scriptable" documents.
     nsIDocument* newDoc = nodeInfoManager->GetDocument();
     NS_ENSURE_STATE(newDoc);
     bool hasHadScriptHandlingObject = false;
     if (!newDoc->GetScriptHandlingObject(hasHadScriptHandlingObject) &&
         !hasHadScriptHandlingObject) {
       nsIDocument* currentDoc = aNode->OwnerDoc();
-      NS_ENSURE_STATE(currentDoc &&
-                      (nsContentUtils::IsChromeDoc(currentDoc) ||
+      NS_ENSURE_STATE((nsContentUtils::IsChromeDoc(currentDoc) ||
                        (!currentDoc->GetScriptHandlingObject(hasHadScriptHandlingObject) &&
                         !hasHadScriptHandlingObject)));
     }
 
     newNodeInfo = nodeInfoManager->GetNodeInfo(nodeInfo->NameAtom(),
                                                nodeInfo->GetPrefixAtom(),
                                                nodeInfo->NamespaceID(),
                                                nodeInfo->NodeType(),
@@ -530,17 +519,17 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNod
       // the cloned document (somewhat like cloning and importing them into the
       // cloned document).
       nodeInfoManager = clone->mNodeInfo->NodeInfoManager();
     }
   }
   else if (nodeInfoManager) {
     nsIDocument* oldDoc = aNode->OwnerDoc();
     bool wasRegistered = false;
-    if (oldDoc && aNode->IsElement()) {
+    if (aNode->IsElement()) {
       Element* element = aNode->AsElement();
       oldDoc->ClearBoxObjectFor(element);
       wasRegistered = oldDoc->UnregisterFreezableElement(element);
     }
 
     aNode->mNodeInfo.swap(newNodeInfo);
     if (elem) {
       elem->NodeInfoChanged(newNodeInfo);
@@ -712,13 +701,11 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNod
 void
 nsNodeUtils::UnlinkUserData(nsINode *aNode)
 {
   NS_ASSERTION(aNode->HasProperties(), "Call to UnlinkUserData not needed.");
 
   // Strong reference to the document so that deleting properties can't
   // delete the document.
   nsCOMPtr<nsIDocument> document = aNode->OwnerDoc();
-  if (document) {
-    document->PropertyTable(DOM_USER_DATA)->DeleteAllPropertiesFor(aNode);
-    document->PropertyTable(DOM_USER_DATA_HANDLER)->DeleteAllPropertiesFor(aNode);
-  }
+  document->PropertyTable(DOM_USER_DATA)->DeleteAllPropertiesFor(aNode);
+  document->PropertyTable(DOM_USER_DATA_HANDLER)->DeleteAllPropertiesFor(aNode);
 }
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -599,20 +599,16 @@ nsObjectLoadingContent::OnStartRequest(n
       contentPolicyType = nsIContentPolicy::TYPE_OBJECT;
       break;
   }
   nsCOMPtr<nsIContent> thisContent = 
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
   NS_ASSERTION(thisContent, "must be a content");
 
   nsIDocument* doc = thisContent->OwnerDoc();
-  if (!doc) {
-    Fallback(false);
-    return NS_BINDING_ABORTED;    
-  }
 
   PRInt16 shouldProcess = nsIContentPolicy::ACCEPT;
   rv =
     NS_CheckContentProcessPolicy(contentPolicyType,
                                  uri,
                                  doc->NodePrincipal(),
                                  static_cast<nsIImageLoadingContent*>(this),
                                  mContentType,
@@ -941,17 +937,17 @@ nsObjectLoadingContent::HasNewFrame(nsIO
 {
   LOG(("OBJLC [%p]: Got frame %p (mInstantiating=%i)\n", this, aFrame,
        mInstantiating));
 
   nsCOMPtr<nsIContent> thisContent = 
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
   NS_ASSERTION(thisContent, "must be a content");
   nsIDocument* doc = thisContent->OwnerDoc();
-  if (!doc || doc->IsStaticDocument() || doc->IsBeingUsedAsImage()) {
+  if (doc->IsStaticDocument() || doc->IsBeingUsedAsImage()) {
     return NS_OK;
   }
 
   // "revoke" any existing instantiate event as it likely has out of
   // date data (frame pointer etc).
   mPendingInstantiateEvent = nsnull;
 
   nsRefPtr<nsNPAPIPluginInstance> instance;
@@ -1195,17 +1191,17 @@ nsObjectLoadingContent::LoadObject(nsIUR
   mURI = aURI;
   mContentType = aTypeHint;
 
   nsCOMPtr<nsIContent> thisContent = 
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
   NS_ASSERTION(thisContent, "must be a content");
 
   nsIDocument* doc = thisContent->OwnerDoc();
-  if (!doc || doc->IsBeingUsedAsImage()) {
+  if (doc->IsBeingUsedAsImage()) {
     return NS_OK;
   }
 
   // From here on, we will always change the content. This means that a
   // possibly-loading channel should be aborted.
   if (mChannel) {
     LOG(("OBJLC [%p]: Cancelling existing load\n", this));
 
--- a/content/base/src/nsRange.cpp
+++ b/content/base/src/nsRange.cpp
@@ -1290,19 +1290,17 @@ nsresult nsRange::CutContents(nsIDOMDocu
     *aFragment = nsnull;
   }
 
   if (IsDetached())
     return NS_ERROR_DOM_INVALID_STATE_ERR;
 
   nsresult rv;
 
-  nsCOMPtr<nsIDocument> doc =
-    do_QueryInterface(mStartParent->OwnerDoc());
-  if (!doc) return NS_ERROR_UNEXPECTED;
+  nsCOMPtr<nsIDocument> doc = mStartParent->OwnerDoc();
 
   nsCOMPtr<nsIDOMNode> commonAncestor;
   rv = GetCommonAncestorContainer(getter_AddRefs(commonAncestor));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // If aFragment isn't null, create a temporary fragment to hold our return.
   nsCOMPtr<nsIDOMDocumentFragment> retval;
   if (aFragment) {
--- a/content/base/src/nsStyledElement.cpp
+++ b/content/base/src/nsStyledElement.cpp
@@ -307,19 +307,19 @@ nsStyledElementNotElementCSSInlineStyle:
 
 void
 nsStyledElementNotElementCSSInlineStyle::ParseStyleAttribute(const nsAString& aValue,
                                                              nsAttrValue& aResult,
                                                              bool aForceInDataDoc)
 {
   nsIDocument* doc = OwnerDoc();
 
-  if (doc && (aForceInDataDoc ||
-              !doc->IsLoadedAsData() ||
-              doc->IsStaticDocument())) {
+  if (aForceInDataDoc ||
+      !doc->IsLoadedAsData() ||
+      doc->IsStaticDocument()) {
     bool isCSS = true; // assume CSS until proven otherwise
 
     if (!IsInNativeAnonymousSubtree()) {  // native anonymous content
                                           // always assumes CSS
       nsAutoString styleType;
       doc->GetHeaderData(nsGkAtoms::headerContentStyleType, styleType);
       if (!styleType.IsEmpty()) {
         static const char textCssStr[] = "text/css";
--- a/content/canvas/src/nsCanvasRenderingContext2D.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp
@@ -614,18 +614,17 @@ protected:
     nsresult DrawRect(const gfxRect& rect, Style style);
 
     /**
      * Gets the pres shell from either the canvas element or the doc shell
      */
     nsIPresShell *GetPresShell() {
       nsCOMPtr<nsIContent> content = do_QueryObject(mCanvasElement);
       if (content) {
-        nsIDocument* ownerDoc = content->OwnerDoc();
-        return ownerDoc ? ownerDoc->GetShell() : nsnull;
+        return content->OwnerDoc()->GetShell();
       }
       if (mDocShell) {
         nsCOMPtr<nsIPresShell> shell;
         mDocShell->GetPresShell(getter_AddRefs(shell));
         return shell.get();
       }
       return nsnull;
     }
--- a/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
@@ -605,18 +605,17 @@ protected:
   }
 
   /**
     * Gets the pres shell from either the canvas element or the doc shell
     */
   nsIPresShell *GetPresShell() {
     nsCOMPtr<nsIContent> content = do_QueryObject(mCanvasElement);
     if (content) {
-      nsIDocument* ownerDoc = content->OwnerDoc();
-      return ownerDoc ? ownerDoc->GetShell() : nsnull;
+      return content->OwnerDoc()->GetShell();
     }
     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
@@ -191,19 +191,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 nsPIDOMWindow*
 nsEventListenerManager::GetInnerWindowForTarget()
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(mTarget);
   if (node) {
     // XXX sXBL/XBL2 issue -- do we really want the owner here?  What
     // if that's the XBL document?
-    nsIDocument* document = node->OwnerDoc();
-    if (document)
-      return document->GetInnerWindow();
+    return node->OwnerDoc()->GetInnerWindow();
   }
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mTarget);
   if (window) {
     NS_ASSERTION(window->IsInnerWindow(), "Target should not be an outer window");
     return window;
   }
 
@@ -462,19 +460,17 @@ nsEventListenerManager::AddScriptEventLi
   nsCOMPtr<nsIDocument> doc;
 
   nsCOMPtr<nsIScriptGlobalObject> global;
 
   if (node) {
     // Try to get context from doc
     // XXX sXBL/XBL2 issue -- do we really want the owner here?  What
     // if that's the XBL document?
-    doc = node->OwnerDoc();
-    if (doc)
-      global = doc->GetScriptGlobalObject();
+    global = node->OwnerDoc()->GetScriptGlobalObject();
   } else {
     nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(mTarget));
     if (win) {
       NS_ASSERTION(win->IsInnerWindow(),
                    "Event listener added to outer window!");
 
       nsCOMPtr<nsIDOMDocument> domdoc;
       win->GetDocument(getter_AddRefs(domdoc));
--- a/content/events/src/nsPLDOMEvent.cpp
+++ b/content/events/src/nsPLDOMEvent.cpp
@@ -65,24 +65,22 @@ NS_IMETHODIMP nsPLDOMEvent::Run()
 
   if (mEvent) {
     NS_ASSERTION(!mDispatchChromeOnly, "Can't do that");
     nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mEventNode);
     bool defaultActionEnabled; // This is not used because the caller is async
     target->DispatchEvent(mEvent, &defaultActionEnabled);
   } else {
     nsIDocument* doc = mEventNode->OwnerDoc();
-    if (doc) {
-      if (mDispatchChromeOnly) {
-        nsContentUtils::DispatchChromeEvent(doc, mEventNode, mEventType,
-                                            mBubbles, false);
-      } else {
-        nsContentUtils::DispatchTrustedEvent(doc, mEventNode, mEventType,
-                                             mBubbles, false);
-      }
+    if (mDispatchChromeOnly) {
+      nsContentUtils::DispatchChromeEvent(doc, mEventNode, mEventType,
+                                          mBubbles, false);
+    } else {
+      nsContentUtils::DispatchTrustedEvent(doc, mEventNode, mEventType,
+                                           mBubbles, false);
     }
   }
 
   return NS_OK;
 }
 
 nsresult nsPLDOMEvent::PostDOMEvent()
 {
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -195,19 +195,16 @@ public:
 
   NS_IMETHOD Run() {
     nsFocusManager* fm = nsFocusManager::GetFocusManager();
     if (!fm) {
       return NS_ERROR_NULL_POINTER;
     }
 
     nsIDocument* document = mElement->OwnerDoc();
-    if (!document) {
-      return NS_OK;
-    }
 
     nsPIDOMWindow* window = document->GetWindow();
     if (!window) {
       return NS_OK;
     }
 
     // Trying to found the top window (equivalent to window.top).
     nsCOMPtr<nsIDOMWindow> top;
@@ -673,19 +670,16 @@ nsGenericHTMLElement::GetOffsetParent(ns
 }
 
 nsresult
 nsGenericHTMLElement::GetInnerHTML(nsAString& aInnerHTML)
 {
   aInnerHTML.Truncate();
 
   nsIDocument* doc = OwnerDoc();
-  if (!doc) {
-    return NS_OK; // We rely on the document for doing HTML conversion
-  }
 
   nsresult rv = NS_OK;
 
   nsAutoString contentType;
   if (IsInHTMLDocument()) {
     contentType.AssignLiteral("text/html");
   } else {
     doc->GetContentType(contentType);
@@ -744,17 +738,16 @@ nsGenericHTMLElement::FireMutationEvents
     nsGenericElement::FireNodeInserted(aDoc, aDest, childNodes);
   }
 }
 
 nsresult
 nsGenericHTMLElement::SetInnerHTML(const nsAString& aInnerHTML)
 {
   nsIDocument* doc = OwnerDoc();
-  NS_ENSURE_STATE(doc);
 
   nsresult rv = NS_OK;
 
   // Batch possible DOMSubtreeModified events.
   mozAutoSubtreeModified subtree(doc, nsnull);
 
   FireNodeRemovedForChildren();
 
@@ -830,17 +823,16 @@ nsGenericHTMLElement::InsertAdjacentHTML
     if (!destination) {
       return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
     }
   } else {
     destination = this;
   }
 
   nsIDocument* doc = OwnerDoc();
-  NS_ENSURE_STATE(doc);
 
   // Needed when insertAdjacentHTML is used in combination with contenteditable
   mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, true);
   nsAutoScriptLoaderDisabler sld(doc);
   
   // Batch possible DOMSubtreeModified events.
   mozAutoSubtreeModified subtree(doc, nsnull);
 
@@ -1267,18 +1259,17 @@ nsGenericHTMLElement::GetEventListenerMa
     nsIDocument *document = OwnerDoc();
 
     // FIXME (https://bugzilla.mozilla.org/show_bug.cgi?id=431767)
     // nsDocument::GetInnerWindow can return an outer window in some cases,
     // we don't want to stick an event listener on an outer window, so
     // bail if it does.  See similar code in nsHTMLBodyElement and
     // nsHTMLFramesetElement
     *aDefer = false;
-    if (document &&
-        (win = document->GetInnerWindow()) && win->IsInnerWindow()) {
+    if ((win = document->GetInnerWindow()) && win->IsInnerWindow()) {
       nsCOMPtr<nsIDOMEventTarget> piTarget(do_QueryInterface(win));
 
       return piTarget->GetListenerManager(true);
     }
 
     return nsnull;
   }
 
@@ -1373,22 +1364,17 @@ nsGenericHTMLElement::UnsetAttr(PRInt32 
   }
 
   return NS_OK;
 }
 
 void
 nsGenericHTMLElement::GetBaseTarget(nsAString& aBaseTarget) const
 {
-  nsIDocument* ownerDoc = OwnerDoc();
-  if (ownerDoc) {
-    ownerDoc->GetBaseTarget(aBaseTarget);
-  } else {
-    aBaseTarget.Truncate();
-  }
+  OwnerDoc()->GetBaseTarget(aBaseTarget);
 }
 
 //----------------------------------------------------------------------
 
 static bool
 CanHaveName(nsIAtom* aTag)
 {
   return aTag == nsGkAtoms::img ||
@@ -3422,17 +3408,16 @@ nsresult nsGenericHTMLElement::MozReques
   // This stops the full-screen from being abused similar to the popups of old,
   // and it also makes it harder for bad guys' script to go full-screen and
   // spoof the browser chrome/window and phish logins etc.
   if (!nsContentUtils::IsRequestFullScreenAllowed()) {
     return NS_OK;
   }
 
   nsIDocument* doc = OwnerDoc();
-  NS_ENSURE_STATE(doc);
   nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(doc));
   NS_ENSURE_STATE(domDocument);
   bool fullScreenEnabled;
   domDocument->GetMozFullScreenEnabled(&fullScreenEnabled);
   if (!fullScreenEnabled) {
     return NS_OK;
   }
 
--- a/content/html/content/src/nsHTMLDNSPrefetch.cpp
+++ b/content/html/content/src/nsHTMLDNSPrefetch.cpp
@@ -287,17 +287,17 @@ void
 nsHTMLDNSPrefetch::nsDeferrals::SubmitQueue()
 {
   NS_ASSERTION(NS_IsMainThread(), "nsDeferrals::SubmitQueue must be on main thread");
   nsCString hostName;
   if (!sDNSService) return;
 
   while (mHead != mTail) {
     nsCOMPtr<nsIContent> content = do_QueryReferent(mEntries[mTail].mElement);
-    if (content && content->OwnerDoc()) {
+    if (content) {
       nsCOMPtr<Link> link = do_QueryInterface(content);
       nsCOMPtr<nsIURI> hrefURI(link ? link->GetURI() : nsnull);
       if (hrefURI)
         hrefURI->GetAsciiHost(hostName);
 
       if (!hostName.IsEmpty()) {
         nsCOMPtr<nsICancelable> tmpOutstanding;
 
--- a/content/html/content/src/nsHTMLImageElement.cpp
+++ b/content/html/content/src/nsHTMLImageElement.cpp
@@ -442,17 +442,17 @@ nsHTMLImageElement::IsHTMLFocusable(bool
   GetTabIndex(&tabIndex);
 
   if (IsInDoc()) {
     nsAutoString usemap;
     GetUseMap(usemap);
     // XXXbz which document should this be using?  sXBL/XBL2 issue!  I
     // think that OwnerDoc() is right, since we don't want to
     // assume stuff about the document we're bound to.
-    if (OwnerDoc() && OwnerDoc()->FindImageMap(usemap)) {
+    if (OwnerDoc()->FindImageMap(usemap)) {
       if (aTabIndex) {
         // Use tab index on individual map areas
         *aTabIndex = (sTabFocusModel & eTabFocus_linksMask)? 0 : -1;
       }
       // Image map is not focusable itself, but flag as tabbable
       // so that image map areas get walked into.
       *aIsFocusable = false;
 
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -236,21 +236,19 @@ class nsHTMLInputElementState : public n
 NS_IMPL_ISUPPORTS1(nsHTMLInputElementState, nsHTMLInputElementState)
 NS_DEFINE_STATIC_IID_ACCESSOR(nsHTMLInputElementState, NS_INPUT_ELEMENT_STATE_IID)
 
 class AsyncClickHandler : public nsRunnable {
 public:
   AsyncClickHandler(nsHTMLInputElement* aInput)
    : mInput(aInput) {
     
-    nsIDocument* doc = aInput->OwnerDoc();
-    if (doc) {
-      nsPIDOMWindow* win = doc->GetWindow();
-      if (win)
-        mPopupControlState = win->GetPopupControlState();
+    nsPIDOMWindow* win = aInput->OwnerDoc()->GetWindow();
+    if (win) {
+      mPopupControlState = win->GetPopupControlState();
     }
   };
 
   NS_IMETHOD Run();
 
 protected:
   nsRefPtr<nsHTMLInputElement> mInput;
   PopupControlState mPopupControlState;
@@ -258,18 +256,16 @@ protected:
 
 NS_IMETHODIMP
 AsyncClickHandler::Run()
 {
   nsresult rv;
 
   // Get parent nsPIDOMWindow object.
   nsCOMPtr<nsIDocument> doc = mInput->OwnerDoc();
-  if (!doc)
-    return NS_ERROR_FAILURE;
 
   nsPIDOMWindow* win = doc->GetWindow();
   if (!win) {
     return NS_ERROR_FAILURE;
   }
 
   // Check if page is allowed to open the popup
   if (mPopupControlState != openAllowed) {
@@ -3733,19 +3729,16 @@ nsHTMLInputElement::HasPatternMismatch()
   nsAutoString value;
   NS_ENSURE_SUCCESS(GetValueInternal(value), false);
 
   if (value.IsEmpty()) {
     return false;
   }
 
   nsIDocument* doc = OwnerDoc();
-  if (!doc) {
-    return false;
-  }
 
   return !nsContentUtils::IsPatternMatching(value, pattern, doc);
 }
 
 void
 nsHTMLInputElement::UpdateTooLongValidityState()
 {
   // TODO: this code will be re-enabled with bug 613016 and bug 613019.
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -1906,19 +1906,16 @@ nsresult nsHTMLMediaElement::FinishDecod
 
 nsresult nsHTMLMediaElement::NewURIFromString(const nsAutoString& aURISpec, nsIURI** aURI)
 {
   NS_ENSURE_ARG_POINTER(aURI);
 
   *aURI = nsnull;
 
   nsCOMPtr<nsIDocument> doc = OwnerDoc();
-  if (!doc) {
-    return NS_ERROR_DOM_INVALID_STATE_ERR;
-  }
 
   nsCOMPtr<nsIURI> baseURI = GetBaseURI();
   nsresult rv = nsContentUtils::NewURIWithDocumentCharset(aURI,
                                                           aURISpec,
                                                           doc,
                                                           baseURI);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -2372,17 +2369,17 @@ void nsHTMLMediaElement::UpdateMediaSize
 }
 
 void nsHTMLMediaElement::NotifyOwnerDocumentActivityChanged()
 {
   nsIDocument* ownerDoc = OwnerDoc();
   // Don't pause if we have no ownerDoc. Something native must have created
   // us and be expecting us to work without a document.
   bool pauseForInactiveDocument =
-    ownerDoc && (!ownerDoc->IsActive() || !ownerDoc->IsVisible());
+    !ownerDoc->IsActive() || !ownerDoc->IsVisible();
 
   if (pauseForInactiveDocument != mPausedForInactiveDocument) {
     mPausedForInactiveDocument = pauseForInactiveDocument;
     if (mDecoder) {
       if (pauseForInactiveDocument) {
         mDecoder->Pause();
         mDecoder->Suspend();
       } else {
@@ -2405,17 +2402,17 @@ void nsHTMLMediaElement::AddRemoveSelfRe
   // potential listener for every event. We would also have to keep the
   // element alive if it was playing and producing audio output --- right now
   // that's covered by the !mPaused check.
   nsIDocument* ownerDoc = OwnerDoc();
 
   // See the comment at the top of this file for the explanation of this
   // boolean expression.
   bool needSelfReference = !mShuttingDown &&
-    (!ownerDoc || ownerDoc->IsActive()) &&
+    ownerDoc->IsActive() &&
     (mDelayingLoadEvent ||
      (!mPaused && mDecoder && !mDecoder->IsEnded()) ||
      (mDecoder && mDecoder->IsSeeking()) ||
      CanActivateAutoplay() ||
      mNetworkState == nsIDOMHTMLMediaElement::NETWORK_LOADING);
 
   if (needSelfReference != mHasSelfReference) {
     mHasSelfReference = needSelfReference;
@@ -2560,18 +2557,17 @@ void nsHTMLMediaElement::ChangeDelayLoad
   }
 
   // We changed mDelayingLoadEvent which can affect AddRemoveSelfReference
   AddRemoveSelfReference();
 }
 
 already_AddRefed<nsILoadGroup> nsHTMLMediaElement::GetDocumentLoadGroup()
 {
-  nsIDocument* doc = OwnerDoc();
-  return doc ? doc->GetDocumentLoadGroup() : nsnull;
+  return OwnerDoc()->GetDocumentLoadGroup();
 }
 
 nsresult
 nsHTMLMediaElement::CopyInnerTo(nsGenericElement* aDest) const
 {
   nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
   if (aDest->OwnerDoc()->IsStaticDocument()) {
@@ -2622,20 +2618,17 @@ void nsHTMLMediaElement::SetRequestHeade
   // which prevents us from estimating the video length (if explicit Content-Duration
   // and a length spec in the container are not present either) and from seeking.
   // So, disable the standard "Accept-Encoding: gzip,deflate" that we usually send.
   // See bug 614760.
   aChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept-Encoding"),
                              NS_LITERAL_CSTRING(""), false);
 
   // Set the Referer header
-  nsIDocument* doc = OwnerDoc();
-  if (doc) {
-    aChannel->SetReferrer(doc->GetDocumentURI());
-  }
+  aChannel->SetReferrer(OwnerDoc()->GetDocumentURI());
 }
 
 void nsHTMLMediaElement::FireTimeUpdate(bool aPeriodic)
 {
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
 
   TimeStamp now = TimeStamp::Now();
   double time = 0;
--- a/content/html/content/src/nsHTMLMenuElement.cpp
+++ b/content/html/content/src/nsHTMLMenuElement.cpp
@@ -203,19 +203,16 @@ nsHTMLMenuElement::BuildSubmenu(const ns
 bool
 nsHTMLMenuElement::CanLoadIcon(nsIContent* aContent, const nsAString& aIcon)
 {
   if (aIcon.IsEmpty()) {
     return false;
   }
 
   nsIDocument* doc = aContent->OwnerDoc();
-  if (!doc) {
-    return false;
-  }
 
   nsCOMPtr<nsIURI> baseURI = aContent->GetBaseURI();
   nsCOMPtr<nsIURI> uri;
   nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri), aIcon, doc,
                                             baseURI);
 
   if (!uri) {
     return false;
--- a/content/html/content/src/nsHTMLSharedElement.cpp
+++ b/content/html/content/src/nsHTMLSharedElement.cpp
@@ -230,20 +230,19 @@ NS_IMPL_STRING_ATTR(nsHTMLSharedElement,
 NS_IMETHODIMP
 nsHTMLSharedElement::GetHref(nsAString& aValue)
 {
   nsAutoString href;
   GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
 
   nsCOMPtr<nsIURI> uri;
   nsIDocument* doc = OwnerDoc();
-  if (doc) {
-    nsContentUtils::NewURIWithDocumentCharset(
-      getter_AddRefs(uri), href, doc, doc->GetDocumentURI());
-  }
+  nsContentUtils::NewURIWithDocumentCharset(
+    getter_AddRefs(uri), href, doc, doc->GetDocumentURI());
+
   if (!uri) {
     aValue = href;
     return NS_OK;
   }
   
   nsCAutoString spec;
   uri->GetSpec(spec);
   CopyUTF8toUTF16(spec, aValue);
--- a/content/mathml/content/src/nsMathMLElement.cpp
+++ b/content/mathml/content/src/nsMathMLElement.cpp
@@ -607,20 +607,17 @@ nsMathMLElement::GetLinkTarget(nsAString
     switch (FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show,
                             sShowVals, eCaseMatters)) {
     case 0:
       aTarget.AssignLiteral("_blank");
       return;
     case 1:
       return;
     }
-    nsIDocument* ownerDoc = OwnerDoc();
-    if (ownerDoc) {
-      ownerDoc->GetBaseTarget(aTarget);
-    }
+    OwnerDoc()->GetBaseTarget(aTarget);
   }
 }
 
 nsLinkState
 nsMathMLElement::GetLinkState() const
 {
   return Link::GetLinkState();
 }
--- a/content/svg/content/src/nsSVGAnimationElement.cpp
+++ b/content/svg/content/src/nsSVGAnimationElement.cpp
@@ -305,22 +305,19 @@ nsSVGAnimationElement::BindToTree(nsIDoc
   AnimationNeedsResample();
 
   return NS_OK;
 }
 
 void
 nsSVGAnimationElement::UnbindFromTree(bool aDeep, bool aNullParent)
 {
-  nsIDocument *doc = OwnerDoc();
-  if (doc) {
-    nsSMILAnimationController *controller = doc->GetAnimationController();
-    if (controller) {
-      controller->UnregisterAnimationElement(this);
-    }
+  nsSMILAnimationController *controller = OwnerDoc()->GetAnimationController();
+  if (controller) {
+    controller->UnregisterAnimationElement(this);
   }
 
   mHrefTarget.Unlink();
   mTimedElement.DissolveReferences();
 
   AnimationNeedsResample();
 
   nsSVGAnimationElementBase::UnbindFromTree(aDeep, aNullParent);
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -808,39 +808,36 @@ nsSVGElement::WalkContentStyleRules(nsRu
 
 #ifdef MOZ_SMIL
   // 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 = OwnerDoc();
-  NS_ASSERTION(doc, "SVG element without doc");
-  if (doc) {
-    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.
-      shell->RestyleForAnimation(this, eRestyle_Self);
-    } else {
-      // Ok, this is an animation restyle -- go ahead and update/walk the
-      // animated content style rule.
-      css::StyleRule* animContentStyleRule = GetAnimatedContentStyleRule();
-      if (!animContentStyleRule) {
-        UpdateAnimatedContentStyleRule();
-        animContentStyleRule = GetAnimatedContentStyleRule();
-      }
-      if (animContentStyleRule) {
-        animContentStyleRule->RuleMatched();
-        aRuleWalker->Forward(animContentStyleRule);
-      }
+  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.
+    shell->RestyleForAnimation(this, eRestyle_Self);
+  } else {
+    // Ok, this is an animation restyle -- go ahead and update/walk the
+    // animated content style rule.
+    css::StyleRule* animContentStyleRule = GetAnimatedContentStyleRule();
+    if (!animContentStyleRule) {
+      UpdateAnimatedContentStyleRule();
+      animContentStyleRule = GetAnimatedContentStyleRule();
+    }
+    if (animContentStyleRule) {
+      animContentStyleRule->RuleMatched();
+      aRuleWalker->Forward(animContentStyleRule);
     }
   }
 #endif // MOZ_SMIL
 
   return NS_OK;
 }
 
 // PresentationAttributes-FillStroke
@@ -1125,21 +1122,16 @@ nsSVGElement::UpdateContentStyleRule()
 
   PRUint32 attrCount = mAttrsAndChildren.AttrCount();
   if (!attrCount) {
     // nothing to do
     return;
   }
 
   nsIDocument* doc = OwnerDoc();
-  if (!doc) {
-    NS_ERROR("SVG element without owner document");
-    return;
-  }
-
   MappedAttrParser mappedAttrParser(doc->CSSLoader(), doc->GetDocumentURI(),
                                     GetBaseURI(), NodePrincipal());
 
   for (PRUint32 i = 0; i < attrCount; ++i) {
     const nsAttrName* attrName = mAttrsAndChildren.AttrNameAt(i);
     if (!attrName->IsAtom() || !IsAttributeMapped(attrName->Atom()))
       continue;
 
--- a/content/svg/content/src/nsSVGFilters.cpp
+++ b/content/svg/content/src/nsSVGFilters.cpp
@@ -5433,24 +5433,22 @@ nsSVGFEImageElement::LoadSVGImage(bool a
   mStringAttributes[HREF].GetAnimValue(href, this);
   href.Trim(" \t\n\r");
 
   if (baseURI && !href.IsEmpty())
     NS_MakeAbsoluteURI(href, href, baseURI);
 
   // Make sure we don't get in a recursive death-spiral
   nsIDocument* doc = OwnerDoc();
-  if (doc) {
-    nsCOMPtr<nsIURI> hrefAsURI;
-    if (NS_SUCCEEDED(StringToURI(href, doc, getter_AddRefs(hrefAsURI)))) {
-      bool isEqual;
-      if (NS_SUCCEEDED(hrefAsURI->Equals(baseURI, &isEqual)) && isEqual) {
-        // Image URI matches our URI exactly! Bail out.
-        return NS_OK;
-      }
+  nsCOMPtr<nsIURI> hrefAsURI;
+  if (NS_SUCCEEDED(StringToURI(href, doc, getter_AddRefs(hrefAsURI)))) {
+    bool isEqual;
+    if (NS_SUCCEEDED(hrefAsURI->Equals(baseURI, &isEqual)) && isEqual) {
+      // Image URI matches our URI exactly! Bail out.
+      return NS_OK;
     }
   }
 
   return LoadImage(href, aForce, aNotify);
 }
 
 //----------------------------------------------------------------------
 // nsIContent methods:
--- a/content/svg/content/src/nsSVGStylableElement.cpp
+++ b/content/svg/content/src/nsSVGStylableElement.cpp
@@ -113,19 +113,15 @@ nsSVGStylableElement::DidAnimateClass()
 {
   nsAutoString src;
   mClassAttribute.GetAnimValue(src, this);
   if (!mClassAnimAttr) {
     mClassAnimAttr = new nsAttrValue();
   }
   mClassAnimAttr->ParseAtomArray(src);
 
-  nsIDocument* doc = OwnerDoc();
-  NS_ASSERTION(doc, "If we're animating we should have an owner");
-  if (doc) {
-    nsIPresShell* shell = doc->GetShell();
-    if (shell) {
-      shell->RestyleForAnimation(this, eRestyle_Self);
-    }
+  nsIPresShell* shell = OwnerDoc()->GetShell();
+  if (shell) {
+    shell->RestyleForAnimation(this, eRestyle_Self);
   }
 
   nsSVGStylableElementBase::DidAnimateClass();
 }
--- a/content/xbl/src/nsBindingManager.cpp
+++ b/content/xbl/src/nsBindingManager.cpp
@@ -928,17 +928,16 @@ nsBindingManager::RemoveLayeredBinding(n
   }
 
   // Hold strong ref in case removing the binding tries to close the
   // window or something.
   // XXXbz should that be ownerdoc?  Wouldn't we need a ref to the
   // currentdoc too?  What's the one that should be passed to
   // ChangeDocument?
   nsCOMPtr<nsIDocument> doc = aContent->OwnerDoc();
-  NS_ASSERTION(doc, "No owner document?");
   
   // Finally remove the binding...
   // XXXbz this doesn't remove the implementation!  Should fix!  Until
   // then we need the explicit UnhookEventHandlers here.
   binding->UnhookEventHandlers();
   binding->ChangeDocument(doc, nsnull);
   SetBinding(aContent, nsnull);
   binding->MarkForDeath();
@@ -1247,18 +1246,16 @@ nsBindingManager::GetBindingImplementati
         // No result was found, so this must be another XBL interface.
         // Fall through to create a new wrapper.
       }
 
       // We have never made a wrapper for this implementation.
       // Create an XPC wrapper for the script object and hand it back.
 
       nsIDocument* doc = aContent->OwnerDoc();
-      if (!doc)
-        return NS_NOINTERFACE;
 
       nsIScriptGlobalObject *global = doc->GetScriptGlobalObject();
       if (!global)
         return NS_NOINTERFACE;
 
       nsIScriptContext *context = global->GetContext();
       if (!context)
         return NS_NOINTERFACE;
--- a/content/xbl/src/nsXBLBinding.cpp
+++ b/content/xbl/src/nsXBLBinding.cpp
@@ -174,19 +174,16 @@ XBLResolve(JSContext *cx, JSObject *obj,
   nsCOMPtr<nsIContent> content = do_QueryWrappedNative(xpcWrapper);
   if (!content) {
     nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED);
     return JS_FALSE;
   }
 
   // This mirrors code in nsXBLProtoImpl::InstallImplementation
   nsIDocument* doc = content->OwnerDoc();
-  if (!doc) {
-    return JS_TRUE;
-  }
 
   nsIScriptGlobalObject* global = doc->GetScriptGlobalObject();
   if (!global) {
     return JS_TRUE;
   }
 
   nsCOMPtr<nsIScriptContext> context = global->GetContext();
   if (!context) {
@@ -549,21 +546,16 @@ RealizeDefaultContent(nsISupports* aKey,
         // actual default content (through cloning).
         // Clone this insertion point element.
         nsCOMPtr<nsIContent> insParent = currPoint->GetInsertionParent();
         if (!insParent) {
           data->mRv = NS_ERROR_FAILURE;
           return PL_DHASH_STOP;
         }
         nsIDocument *document = insParent->OwnerDoc();
-        if (!document) {
-          data->mRv = NS_ERROR_FAILURE;
-          return PL_DHASH_STOP;
-        }
-
         nsCOMPtr<nsIDOMNode> clonedNode;
         nsCOMArray<nsINode> nodesWithProperties;
         nsNodeUtils::Clone(defContent, true, document->NodeInfoManager(),
                            nodesWithProperties, getter_AddRefs(clonedNode));
 
         // Now that we have the cloned content, install the default content as
         // if it were additional anonymous content.
         nsCOMPtr<nsIContent> clonedContent(do_QueryInterface(clonedNode));
@@ -637,20 +629,16 @@ nsXBLBinding::GenerateAnonymousContent()
     message += uri;
     message += " is still using the deprecated\n<content includes=\"\"> syntax! Use <children> instead!\n"; 
     NS_WARNING(message.get());
   }
 #endif
 
   if (hasContent || hasInsertionPoints) {
     nsIDocument* doc = mBoundElement->OwnerDoc();
-
-    // XXX doc will be null if we're in the midst of paint suppression.
-    if (! doc)
-      return;
     
     nsBindingManager *bindingManager = doc->BindingManager();
 
     nsCOMPtr<nsIDOMNodeList> children;
     bindingManager->GetContentListFor(mBoundElement, getter_AddRefs(children));
  
     nsCOMPtr<nsIDOMNode> node;
     nsCOMPtr<nsIContent> childContent;
--- a/content/xbl/src/nsXBLProtoImpl.cpp
+++ b/content/xbl/src/nsXBLProtoImpl.cpp
@@ -77,18 +77,17 @@ nsXBLProtoImpl::InstallImplementation(ns
   // so for the first bound element that needs a concrete implementation, we also build the
   // prototype implementation.
   if (!mMembers && !mFields)  // Constructor and destructor also live in mMembers
     return NS_OK; // Nothing to do, so let's not waste time.
 
   // If the way this gets the script context changes, fix
   // nsXBLProtoImplAnonymousMethod::Execute
   nsIDocument* document = aBoundElement->OwnerDoc();
-  if (!document) return NS_OK;
-
+                                              
   nsIScriptGlobalObject *global = document->GetScopeObject();
   if (!global) return NS_OK;
 
   nsCOMPtr<nsIScriptContext> context = global->GetContext();
   if (!context) return NS_OK;
 
   // InitTarget objects gives us back the JS object that represents the bound element and the
   // class object in the bound document that represents the concrete version of this implementation.
@@ -136,17 +135,17 @@ nsXBLProtoImpl::InitTargetObjects(nsXBLP
 
     if (!mClassObject)
       return NS_OK; // This can be ok, if all we've got are fields (and no methods/properties).
   }
 
   nsIDocument *ownerDoc = aBoundElement->OwnerDoc();
   nsIScriptGlobalObject *sgo;
 
-  if (!ownerDoc || !(sgo = ownerDoc->GetScopeObject())) {
+  if (!(sgo = ownerDoc->GetScopeObject())) {
     return NS_ERROR_UNEXPECTED;
   }
 
   // Because our prototype implementation has a class, we need to build up a corresponding
   // class for the concrete implementation in the bound document.
   JSContext* jscontext = aContext->GetNativeContext();
   JSObject* global = sgo->GetGlobalJSObject();
   nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
--- a/content/xbl/src/nsXBLProtoImplMethod.cpp
+++ b/content/xbl/src/nsXBLProtoImplMethod.cpp
@@ -128,17 +128,17 @@ nsXBLProtoImplMethod::InstallMember(nsIS
 {
   NS_PRECONDITION(IsCompiled(),
                   "Should not be installing an uncompiled method");
   JSContext* cx = aContext->GetNativeContext();
 
   nsIDocument *ownerDoc = aBoundElement->OwnerDoc();
   nsIScriptGlobalObject *sgo;
 
-  if (!ownerDoc || !(sgo = ownerDoc->GetScopeObject())) {
+  if (!(sgo = ownerDoc->GetScopeObject())) {
     return NS_ERROR_UNEXPECTED;
   }
 
   JSObject * scriptObject = (JSObject *) aScriptObject;
   NS_ASSERTION(scriptObject, "uh-oh, script Object should NOT be null or bad things will happen");
   if (!scriptObject)
     return NS_ERROR_FAILURE;
 
@@ -275,19 +275,16 @@ nsXBLProtoImplAnonymousMethod::Execute(n
   if (!mJSMethodObject) {
     // Nothing to do here
     return NS_OK;
   }
 
   // Get the script context the same way
   // nsXBLProtoImpl::InstallImplementation does.
   nsIDocument* document = aBoundElement->OwnerDoc();
-  if (!document) {
-    return NS_OK;
-  }
 
   nsIScriptGlobalObject* global = document->GetScriptGlobalObject();
   if (!global) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIScriptContext> context = global->GetContext();
   if (!context) {
--- a/content/xbl/src/nsXBLProtoImplProperty.cpp
+++ b/content/xbl/src/nsXBLProtoImplProperty.cpp
@@ -155,17 +155,17 @@ nsXBLProtoImplProperty::InstallMember(ns
 {
   NS_PRECONDITION(mIsCompiled,
                   "Should not be installing an uncompiled property");
   JSContext* cx = aContext->GetNativeContext();
 
   nsIDocument *ownerDoc = aBoundElement->OwnerDoc();
   nsIScriptGlobalObject *sgo;
 
-  if (!ownerDoc || !(sgo = ownerDoc->GetScopeObject())) {
+  if (!(sgo = ownerDoc->GetScopeObject())) {
     return NS_ERROR_UNEXPECTED;
   }
 
   JSObject * scriptObject = (JSObject *) aScriptObject;
   NS_ASSERTION(scriptObject, "uh-oh, script Object should NOT be null or bad things will happen");
   if (!scriptObject)
     return NS_ERROR_FAILURE;
 
--- a/content/xbl/src/nsXBLPrototypeHandler.cpp
+++ b/content/xbl/src/nsXBLPrototypeHandler.cpp
@@ -288,18 +288,16 @@ nsXBLPrototypeHandler::ExecuteHandler(ns
   if (!boundGlobal) {
     nsCOMPtr<nsIDocument> boundDocument(do_QueryInterface(aTarget));
     if (!boundDocument) {
       // We must be an element.
       nsCOMPtr<nsIContent> content(do_QueryInterface(aTarget));
       if (!content)
         return NS_OK;
       boundDocument = content->OwnerDoc();
-      if (!boundDocument)
-        return NS_OK;
     }
 
     boundGlobal = boundDocument->GetScopeObject();
   }
 
   if (!boundGlobal)
     return NS_OK;
 
--- a/content/xbl/src/nsXBLService.cpp
+++ b/content/xbl/src/nsXBLService.cpp
@@ -544,20 +544,16 @@ nsXBLService::LoadBindings(nsIContent* a
   
   *aBinding = nsnull;
   *aResolveStyle = false;
 
   nsresult rv;
 
   nsCOMPtr<nsIDocument> document = aContent->OwnerDoc();
 
-  // XXX document may be null if we're in the midst of paint suppression
-  if (!document)
-    return NS_OK;
-
   nsCAutoString urlspec;
   if (nsContentUtils::GetWrapperSafeScriptFilename(document, aURL, urlspec)) {
     // Block an attempt to load a binding that has special wrapper
     // automation needs.
 
     return NS_OK;
   }
 
@@ -654,20 +650,16 @@ nsXBLService::LoadBindings(nsIContent* a
   return NS_OK; 
 }
 
 nsresult
 nsXBLService::FlushStyleBindings(nsIContent* aContent)
 {
   nsCOMPtr<nsIDocument> document = aContent->OwnerDoc();
 
-  // XXX doc will be null if we're in the midst of paint suppression.
-  if (! document)
-    return NS_OK;
-
   nsBindingManager *bindingManager = document->BindingManager();
   
   nsXBLBinding *binding = bindingManager->GetBinding(aContent);
   
   if (binding) {
     nsXBLBinding *styleBinding = binding->GetFirstStyleBinding();
 
     if (styleBinding) {
@@ -682,24 +674,18 @@ nsXBLService::FlushStyleBindings(nsICont
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXBLService::ResolveTag(nsIContent* aContent, PRInt32* aNameSpaceID,
                          nsIAtom** aResult)
 {
   nsIDocument* document = aContent->OwnerDoc();
-  if (document) {
-    *aResult = document->BindingManager()->ResolveTag(aContent, aNameSpaceID);
-    NS_IF_ADDREF(*aResult);
-  }
-  else {
-    *aNameSpaceID = aContent->GetNameSpaceID();
-    NS_ADDREF(*aResult = aContent->Tag());
-  }
+  *aResult = document->BindingManager()->ResolveTag(aContent, aNameSpaceID);
+  NS_IF_ADDREF(*aResult);
 
   return NS_OK;
 }
 
 
 //
 // AttachGlobalKeyHandler
 //
--- a/content/xml/content/src/nsXMLStylesheetPI.cpp
+++ b/content/xml/content/src/nsXMLStylesheetPI.cpp
@@ -175,24 +175,20 @@ nsXMLStylesheetPI::GetStyleSheetURL(bool
   nsAutoString href;
   if (!GetAttrValue(nsGkAtoms::href, href)) {
     return nsnull;
   }
 
   nsIURI *baseURL;
   nsCAutoString charset;
   nsIDocument *document = OwnerDoc();
-  if (document) {
-    baseURL = mOverriddenBaseURI ?
-              mOverriddenBaseURI.get() :
-              document->GetDocBaseURI();
-    charset = document->GetDocumentCharacterSet();
-  } else {
-    baseURL = mOverriddenBaseURI;
-  }
+  baseURL = mOverriddenBaseURI ?
+            mOverriddenBaseURI.get() :
+            document->GetDocBaseURI();
+  charset = document->GetDocumentCharacterSet();
 
   nsCOMPtr<nsIURI> aURI;
   NS_NewURI(getter_AddRefs(aURI), href, charset.get(), baseURL);
   return aURI.forget();
 }
 
 void
 nsXMLStylesheetPI::GetStyleSheetInfo(nsAString& aTitle,
--- a/content/xslt/src/base/txURIUtils.cpp
+++ b/content/xslt/src/base/txURIUtils.cpp
@@ -83,23 +83,16 @@ URIUtils::ResetWithSource(nsIDocument *a
     nsCOMPtr<nsINode> node = do_QueryInterface(aSourceNode);
     if (!node) {
         // XXXbz passing nsnull as the first arg to Reset is illegal
         aNewDoc->Reset(nsnull, nsnull);
         return;
     }
 
     nsCOMPtr<nsIDocument> sourceDoc = node->OwnerDoc();
-    if (!sourceDoc) {
-        NS_ERROR("no source document found");
-        // XXXbz passing nsnull as the first arg to Reset is illegal
-        aNewDoc->Reset(nsnull, nsnull);
-        return;
-    }
-
     nsIPrincipal* sourcePrincipal = sourceDoc->NodePrincipal();
 
     // Copy the channel and loadgroup from the source document.
     nsCOMPtr<nsILoadGroup> loadGroup = sourceDoc->GetDocumentLoadGroup();
     nsCOMPtr<nsIChannel> channel = sourceDoc->GetChannel();
     if (!channel) {
         // Need to synthesize one
         if (NS_FAILED(NS_NewChannel(getter_AddRefs(channel),
--- a/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
+++ b/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
@@ -569,18 +569,17 @@ txXPathNodeUtils::getDocument(const txXP
     nsIDocument* document = aNode.mNode->GetCurrentDoc();
     return document ? new txXPathNode(document) : nsnull;
 }
 
 /* static */
 txXPathNode*
 txXPathNodeUtils::getOwnerDocument(const txXPathNode& aNode)
 {
-    nsIDocument* document = aNode.mNode->OwnerDoc();
-    return document ? new txXPathNode(document) : nsnull;
+    return new txXPathNode(aNode.mNode->OwnerDoc());
 }
 
 #ifndef HAVE_64BIT_OS
 #define kFmtSize 13
 #define kFmtSizeAttr 24
 const char gPrintfFmt[] = "id0x%08p";
 const char gPrintfFmtAttr[] = "id0x%08p-%010i";
 #else
--- a/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp
+++ b/content/xslt/src/xslt/txMozillaStylesheetCompiler.cpp
@@ -716,17 +716,16 @@ void txSyncCompileObserver::onDoneCompil
 
 nsresult
 TX_CompileStylesheet(nsINode* aNode, txMozillaXSLTProcessor* aProcessor,
                      nsIPrincipal* aCallerPrincipal,
                      txStylesheet** aStylesheet)
 {
     // If we move GetBaseURI to nsINode this can be simplified.
     nsCOMPtr<nsIDocument> doc = aNode->OwnerDoc();
-    NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
     nsCOMPtr<nsIURI> uri;
     if (aNode->IsNodeOfType(nsINode::eCONTENT)) {
       uri = static_cast<nsIContent*>(aNode)->GetBaseURI();
     }
     else { 
       NS_ASSERTION(aNode->IsNodeOfType(nsINode::eDOCUMENT), "not a doc");
       uri = static_cast<nsIDocument*>(aNode)->GetBaseURI();
--- a/content/xslt/src/xslt/txMozillaXMLOutput.cpp
+++ b/content/xslt/src/xslt/txMozillaXMLOutput.cpp
@@ -113,22 +113,17 @@ txMozillaXMLOutput::txMozillaXMLOutput(t
       mNoFixup(aNoFixup)
 {
     MOZ_COUNT_CTOR(txMozillaXMLOutput);
     mOutputFormat.merge(*aFormat);
     mOutputFormat.setFromDefaults();
 
     mCurrentNode = do_QueryInterface(aFragment);
     mDocument = mCurrentNode->OwnerDoc();
-    if (mDocument) {
-      mNodeInfoManager = mDocument->NodeInfoManager();
-    }
-    else {
-      mCurrentNode = nsnull;
-    }
+    mNodeInfoManager = mDocument->NodeInfoManager();
 }
 
 txMozillaXMLOutput::~txMozillaXMLOutput()
 {
     MOZ_COUNT_DTOR(txMozillaXMLOutput);
 }
 
 nsresult
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -510,18 +510,16 @@ nsXULElement::GetElementsByAttributeNS(c
 
 nsEventListenerManager*
 nsXULElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer)
 {
     // XXXbz sXBL/XBL2 issue: should we instead use GetCurrentDoc()
     // here, override BindToTree for those classes and munge event
     // listeners there?
     nsIDocument* doc = OwnerDoc();
-    if (!doc)
-        return nsnull; // XXX
 
     nsPIDOMWindow *window;
     Element *root = doc->GetRootElement();
     if ((!root || root == this) && !mNodeInfo->Equals(nsGkAtoms::overlay) &&
         (window = doc->GetInnerWindow()) && window->IsInnerWindow()) {
 
         nsCOMPtr<nsIDOMEventTarget> piTarget = do_QueryInterface(window);
 
@@ -1850,19 +1848,17 @@ nsXULElement::GetControllers(nsIControll
 }
 
 NS_IMETHODIMP
 nsXULElement::GetBoxObject(nsIBoxObject** aResult)
 {
   *aResult = nsnull;
 
   // XXX sXBL/XBL2 issue! Owner or current document?
-  nsIDocument* nsDoc = OwnerDoc();
-
-  return nsDoc ? nsDoc->GetBoxObjectFor(this, aResult) : NS_ERROR_FAILURE;
+  return OwnerDoc()->GetBoxObjectFor(this, aResult);
 }
 
 // Methods for setting/getting attributes from nsIDOMXULElement
 #define NS_IMPL_XUL_STRING_ATTR(_method, _atom)                     \
   NS_IMETHODIMP                                                     \
   nsXULElement::Get##_method(nsAString& aReturn)                    \
   {                                                                 \
     GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aReturn);         \
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -4436,17 +4436,16 @@ nsXULDocument::InsertElement(nsIContent*
 
     if (posStr.IsEmpty()) {
         aChild->GetAttr(kNameSpaceID_None, nsGkAtoms::insertbefore, posStr);
         isInsertAfter = false;
     }
 
     if (!posStr.IsEmpty()) {
         nsIDocument *document = aParent->OwnerDoc();
-        if (!document) return NS_ERROR_FAILURE;
 
         nsIContent *content = nsnull;
 
         char* str = ToNewCString(posStr);
         char* rest;
         char* token = nsCRT::strtok(str, ", ", &rest);
 
         while (token) {
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -385,18 +385,16 @@ ForEachPing(nsIContent *content, ForEach
   if (value.IsEmpty())
     return;
 
   nsCOMPtr<nsIIOService> ios = do_GetIOService();
   if (!ios)
     return;
 
   nsIDocument *doc = content->OwnerDoc();
-  if (!doc)
-    return;
 
   // value contains relative URIs split on spaces (U+0020)
   const PRUnichar *start = value.BeginReading();
   const PRUnichar *end   = value.EndReading();
   const PRUnichar *iter  = start;
   for (;;) {
     if (iter < end && *iter != ' ') {
       ++iter;
@@ -546,18 +544,16 @@ SendPing(void *closure, nsIContent *cont
   if (info->requireSameHost) {
     // Make sure the referrer and the given uri share the same origin.  We
     // only require the same hostname.  The scheme and port may differ.
     if (!IsSameHost(uri, info->referrer))
       return;
   }
 
   nsIDocument *doc = content->OwnerDoc();
-  if (!doc)
-    return;
 
   nsCOMPtr<nsIChannel> chan;
   ios->NewChannelFromURI(uri, getter_AddRefs(chan));
   if (!chan)
     return;
 
   // Don't bother caching the result of this URI load.
   chan->SetLoadFlags(nsIRequest::INHIBIT_CACHING);
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -7252,26 +7252,16 @@ nsNodeSH::PreCreate(nsISupports *nativeO
   // Make sure that we get the owner document of the content node, in case
   // we're in document teardown.  If we are, it's important to *not* use
   // globalObj as the nodes parent since that would give the node the
   // principal of globalObj (i.e. the principal of the document that's being
   // loaded) and not the principal of the document that's being unloaded.
   // See http://bugzilla.mozilla.org/show_bug.cgi?id=227417
   nsIDocument* doc = node->OwnerDoc();
 
-  if (!doc) {
-    // No document reachable from nativeObj, use the global object
-    // that was passed to this method.
-
-    *parentObj = globalObj;
-
-    return node->IsInNativeAnonymousSubtree() ?
-      NS_SUCCESS_CHROME_ACCESS_ONLY : NS_OK;
-  }
-
   // If we have a document, make sure one of these is true
   // (1) it has a script handling object,
   // (2) has had one, or has been marked to have had one,
   // (3) we are running a privileged script.
   // Event handling is possible only if (1). If (2) event handling is prevented.
   // If document has never had a script handling object,
   // untrusted scripts (3) shouldn't touch it!
   bool hasHadScriptHandlingObject = false;
@@ -7614,20 +7604,16 @@ NS_IMETHODIMP
 nsElementSH::Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
                        JSObject *obj, bool *_retval)
 {
   // Make sure to not call the superclass here!
   nsCOMPtr<nsIContent> content(do_QueryWrappedNative(wrapper, obj));
   NS_ENSURE_TRUE(content, NS_ERROR_UNEXPECTED);
 
   nsIDocument* doc = content->OwnerDoc();
-  if (!doc) {
-    // Nothing else to do here
-    return NS_OK;
-  }
 
   nsRefPtr<nsXBLBinding> binding = doc->BindingManager()->GetBinding(content);
   if (!binding) {
     // Nothing else to do here
     return NS_OK;
   }
 
   *_retval = binding->ResolveAllFields(cx, obj);
@@ -8155,17 +8141,16 @@ NS_IMETHODIMP
 nsDOMStringMapSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
                             JSObject *globalObj, JSObject **parentObj)
 {
   *parentObj = globalObj;
 
   nsDOMStringMap* dataset = static_cast<nsDOMStringMap*>(nativeObj);
 
   nsIDocument* document = dataset->GetElement()->OwnerDoc();
-  NS_ENSURE_TRUE(document, NS_OK);
 
   nsCOMPtr<nsIScriptGlobalObject> sgo =
       do_GetInterface(document->GetScopeObject());
 
   if (sgo) {
     JSObject *global = sgo->GetGlobalJSObject();
 
     if (global) {
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -613,28 +613,25 @@ TabParent::RecvGetDPI(float* aValue)
   return true;
 }
 
 bool
 TabParent::RecvGetWidgetNativeData(WindowsHandle* aValue)
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(mFrameElement);
   if (content) {
-    nsIDocument* document = content->OwnerDoc();
-    if (document) {
-      nsIPresShell* shell = document->GetShell();
-      if (shell) {
-        nsIViewManager* vm = shell->GetViewManager();
-        nsCOMPtr<nsIWidget> widget;
-        vm->GetRootWidget(getter_AddRefs(widget));
-        if (widget) {
-          *aValue = reinterpret_cast<WindowsHandle>(
-            widget->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW));
-          return true;
-        }
+    nsIPresShell* shell = content->OwnerDoc()->GetShell();
+    if (shell) {
+      nsIViewManager* vm = shell->GetViewManager();
+      nsCOMPtr<nsIWidget> widget;
+      vm->GetRootWidget(getter_AddRefs(widget));
+      if (widget) {
+        *aValue = reinterpret_cast<WindowsHandle>(
+          widget->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW));
+        return true;
       }
     }
   }
   return false;
 }
 
 bool
 TabParent::ReceiveMessage(const nsString& aMessage,
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -2048,19 +2048,16 @@ nsJSNPRuntime::OnPluginDestroy(NPP npp)
   // XXXbz we MUST have a better way of doing this... perhaps
   // GetWrappedNativeOfNativeObject _should_ call preCreate?
   nsCOMPtr<nsIContent> content(do_QueryInterface(element));
   if (!content) {
     return;
   }
 
   nsIDocument* doc = content->OwnerDoc();
-  if (!doc) {
-    return;
-  }
 
   nsIScriptGlobalObject* sgo = doc->GetScriptGlobalObject();
   if (!sgo) {
     return;
   }
 
   nsCOMPtr<nsIXPConnectWrappedNative> holder;
   xpc->GetWrappedNativeOfNativeObject(cx, sgo->GetGlobalJSObject(), content,
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -964,25 +964,22 @@ nsCSSRendering::FindBackgroundStyleFrame
   // Check if we need to do propagation from BODY rather than HTML.
   if (!result->IsTransparent()) {
     return aForFrame;
   }
 
   nsIContent* content = aForFrame->GetContent();
   // The root element content can't be null. We wouldn't know what
   // frame to create for aFrame.
-  // Use |GetOwnerDoc| so it works during destruction.
+  // Use |OwnerDoc| so it works during destruction.
   if (!content) {
     return aForFrame;
   }
 
   nsIDocument* document = content->OwnerDoc();
-  if (!document) {
-    return aForFrame;
-  }
 
   dom::Element* bodyContent = document->GetBodyElement();
   // We need to null check the body node (bug 118829) since
   // there are cases, thanks to the fix for bug 5569, where we
   // will reflow a document with no body.  In particular, if a
   // SCRIPT element in the head blocks the parser and then has a
   // SCRIPT that does "document.location.href = 'foo'", then
   // nsParser::Terminate will call |DidBuildModel| methods
@@ -1054,18 +1051,16 @@ FindElementBackground(nsIFrame* aForFram
   // It could be a non-HTML "body" element but that's OK, we'd fail the
   // bodyContent check below
 
   if (aForFrame->GetStyleContext()->GetPseudo())
     return true; // A pseudo-element frame.
 
   // We should only look at the <html> background if we're in an HTML document
   nsIDocument* document = content->OwnerDoc();
-  if (!document)
-    return true;
 
   dom::Element* bodyContent = document->GetBodyElement();
   if (bodyContent != content)
     return true; // this wasn't the background that was propagated
 
   // This can be called even when there's no root element yet, during frame
   // construction, via nsLayoutUtils::FrameHasTransparency and
   // nsContainerFrame::SyncFrameViewProperties.
--- a/layout/base/nsChildIterator.cpp
+++ b/layout/base/nsChildIterator.cpp
@@ -54,19 +54,16 @@ ChildIterator::Init(nsIContent*    aCont
   aFirst->mContent = aLast->mContent = nsnull;
   aFirst->mChild   = aLast->mChild   = nsnull;
   
   NS_PRECONDITION(aContent != nsnull, "no content");
   if (! aContent)
     return NS_ERROR_NULL_POINTER;
 
   nsIDocument* doc = aContent->OwnerDoc();
-  NS_ASSERTION(doc, "element not in the document");
-  if (! doc)
-    return NS_ERROR_FAILURE;
 
   // If this node has XBL children, then use them. Otherwise, just use
   // the vanilla content APIs.
   nsINodeList* nodes = doc->BindingManager()->GetXBLChildNodesFor(aContent);
 
   aFirst->mContent = aContent;
   aLast->mContent  = aContent;
   aFirst->mNodes   = nodes;
--- a/layout/inspector/src/inDOMUtils.cpp
+++ b/layout/inspector/src/inDOMUtils.cpp
@@ -254,23 +254,21 @@ inDOMUtils::GetBindingURLs(nsIDOMElement
   nsCOMPtr<nsIMutableArray> urls = do_CreateInstance(NS_ARRAY_CONTRACTID);
   if (!urls)
     return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
   NS_ASSERTION(content, "elements must implement nsIContent");
 
   nsIDocument *ownerDoc = content->OwnerDoc();
-  if (ownerDoc) {
-    nsXBLBinding *binding = ownerDoc->BindingManager()->GetBinding(content);
+  nsXBLBinding *binding = ownerDoc->BindingManager()->GetBinding(content);
 
-    while (binding) {
-      urls->AppendElement(binding->PrototypeBinding()->BindingURI(), false);
-      binding = binding->GetBaseBinding();
-    }
+  while (binding) {
+    urls->AppendElement(binding->PrototypeBinding()->BindingURI(), false);
+    binding = binding->GetBaseBinding();
   }
 
   NS_ADDREF(*_retval = urls);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 inDOMUtils::SetContentState(nsIDOMElement *aElement, nsEventStates::InternalType aState)
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -1252,20 +1252,17 @@ nsCSSStyleSheet::FindOwningWindowInnerID
   PRUint64 windowID = 0;
   if (mDocument) {
     windowID = mDocument->InnerWindowID();
   }
 
   if (windowID == 0 && mOwningNode) {
     nsCOMPtr<nsIContent> node = do_QueryInterface(mOwningNode);
     if (node) {
-      nsIDocument* doc = node->OwnerDoc();
-      if (doc) {
-        windowID = doc->InnerWindowID();
-      }
+      windowID = node->OwnerDoc()->InnerWindowID();
     }
   }
 
   if (windowID == 0 && mOwnerRule) {
     nsCOMPtr<nsIStyleSheet> sheet = static_cast<css::Rule*>(mOwnerRule)->GetStyleSheet();
     if (sheet) {
       nsRefPtr<nsCSSStyleSheet> cssSheet = do_QueryObject(sheet);
       if (cssSheet) {
--- a/layout/style/nsDOMCSSAttrDeclaration.cpp
+++ b/layout/style/nsDOMCSSAttrDeclaration.cpp
@@ -171,22 +171,16 @@ nsDOMCSSAttributeDeclaration::GetCSSDecl
 }
 
 void
 nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
 {
   NS_ASSERTION(mElement, "Something is severely broken -- there should be an Element here!");
 
   nsIDocument* doc = mElement->OwnerDoc();
-  if (!doc) {
-    // document has been destroyed
-    aCSSParseEnv.mPrincipal = nsnull;
-    return;
-  }
-
   aCSSParseEnv.mSheetURI = doc->GetDocumentURI();
   aCSSParseEnv.mBaseURI = mElement->GetBaseURI();
   aCSSParseEnv.mPrincipal = mElement->NodePrincipal();
   aCSSParseEnv.mCSSLoader = doc->CSSLoader();
 }
 
 NS_IMETHODIMP
 nsDOMCSSAttributeDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
--- a/layout/xul/base/src/nsImageBoxFrame.cpp
+++ b/layout/xul/base/src/nsImageBoxFrame.cpp
@@ -96,22 +96,17 @@ public:
 private:
   nsCOMPtr<nsIContent> mContent;
   PRUint32 mMessage;
 };
 
 NS_IMETHODIMP
 nsImageBoxFrameEvent::Run()
 {
-  nsIDocument* doc = mContent->OwnerDoc();
-  if (!doc) {
-    return NS_OK;
-  }
-
-  nsIPresShell *pres_shell = doc->GetShell();
+  nsIPresShell *pres_shell = mContent->OwnerDoc()->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
@@ -162,25 +162,23 @@ nsMenuPopupFrame::Init(nsIContent*      
   // so we use the nsIView::SetFloating() to tell the view manager
   // about that constraint.
   nsIView* ourView = GetView();
   nsIViewManager* viewManager = ourView->GetViewManager();
   viewManager->SetViewFloating(ourView, true);
 
   mPopupType = ePopupTypePanel;
   nsIDocument* doc = aContent->OwnerDoc();
-  if (doc) {
-    PRInt32 namespaceID;
-    nsCOMPtr<nsIAtom> tag = doc->BindingManager()->ResolveTag(aContent, &namespaceID);
-    if (namespaceID == kNameSpaceID_XUL) {
-      if (tag == nsGkAtoms::menupopup || tag == nsGkAtoms::popup)
-        mPopupType = ePopupTypeMenu;
-      else if (tag == nsGkAtoms::tooltip)
-        mPopupType = ePopupTypeTooltip;
-    }
+  PRInt32 namespaceID;
+  nsCOMPtr<nsIAtom> tag = doc->BindingManager()->ResolveTag(aContent, &namespaceID);
+  if (namespaceID == kNameSpaceID_XUL) {
+    if (tag == nsGkAtoms::menupopup || tag == nsGkAtoms::popup)
+      mPopupType = ePopupTypeMenu;
+    else if (tag == nsGkAtoms::tooltip)
+      mPopupType = ePopupTypeTooltip;
   }
 
   if (mPopupType == ePopupTypePanel &&
       aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
                             nsGkAtoms::drag, eIgnoreCase)) {
     mIsDragPopup = true;
   }
 
--- a/layout/xul/base/src/nsSplitterFrame.cpp
+++ b/layout/xul/base/src/nsSplitterFrame.cpp
@@ -698,23 +698,18 @@ nsSplitterFrameInner::MouseDown(nsIDOMEv
   mChildInfosAfterCount = 0;
 
   nsIBox* childBox = mParentBox->GetChildBox();
 
   while (nsnull != childBox) 
   { 
     nsIContent* content = childBox->GetContent();
     nsIDocument* doc = content->OwnerDoc();
-    nsIAtom* atom;
-    if (doc) {
-      PRInt32 dummy;
-      atom = doc->BindingManager()->ResolveTag(content, &dummy);
-    } else {
-      atom = content->Tag();
-    }
+    PRInt32 dummy;
+    nsIAtom* atom = doc->BindingManager()->ResolveTag(content, &dummy);
 
     // skip over any splitters
     if (atom != nsGkAtoms::splitter) { 
         nsSize prefSize = childBox->GetPrefSize(state);
         nsSize minSize = childBox->GetMinSize(state);
         nsSize maxSize = nsBox::BoundsCheckMinMax(minSize, childBox->GetMaxSize(state));
         prefSize = nsBox::BoundsCheck(minSize, prefSize, maxSize);
 
--- a/parser/html/nsHtml5Parser.cpp
+++ b/parser/html/nsHtml5Parser.cpp
@@ -498,17 +498,16 @@ nsHtml5Parser::ParseHtml5Fragment(const 
                                   nsIAtom* aContextLocalName,
                                   PRInt32 aContextNamespace,
                                   bool aQuirks,
                                   bool aPreventScriptExecution)
 {
   NS_ENSURE_TRUE(aSourceBuffer.Length() <= PR_INT32_MAX,
       NS_ERROR_OUT_OF_MEMORY);
   nsIDocument* doc = aTargetNode->OwnerDoc();
-  NS_ENSURE_TRUE(doc, NS_ERROR_NOT_AVAILABLE);
   
   nsIURI* uri = doc->GetDocumentURI();
   NS_ENSURE_TRUE(uri, NS_ERROR_NOT_AVAILABLE);
 
   mExecutor->EnableFragmentMode(aPreventScriptExecution);
 
   Initialize(doc, uri, nsnull, nsnull);
 
--- a/widget/src/cocoa/nsMenuItemIconX.mm
+++ b/widget/src/cocoa/nsMenuItemIconX.mm
@@ -303,17 +303,16 @@ nsMenuItemIconX::LoadIcon(nsIURI* aIconU
     mIconRequest = nsnull;
   }
 
   mLoadedIcon = false;
 
   if (!mContent) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIDocument> document = mContent->OwnerDoc();
-  if (!document) return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsILoadGroup> loadGroup = document->GetDocumentLoadGroup();
   if (!loadGroup) return NS_ERROR_FAILURE;
 
   nsresult rv = NS_ERROR_FAILURE;
   nsCOMPtr<imgILoader> loader = do_GetService("@mozilla.org/image/loader;1",
                                               &rv);
   if (NS_FAILED(rv)) return rv;
--- a/widget/src/cocoa/nsMenuItemX.mm
+++ b/widget/src/cocoa/nsMenuItemX.mm
@@ -199,20 +199,16 @@ void nsMenuItemX::DoCommand()
 
 nsresult nsMenuItemX::DispatchDOMEvent(const nsString &eventName, bool *preventDefaultCalled)
 {
   if (!mContent)
     return NS_ERROR_FAILURE;
 
   // get owner document for content
   nsCOMPtr<nsIDocument> parentDoc = mContent->OwnerDoc();
-  if (!parentDoc) {
-    NS_WARNING("Failed to get owner nsIDocument for menu item content");
-    return NS_ERROR_FAILURE;
-  }
 
   // get interface for creating DOM events from content owner document
   nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(parentDoc);
   if (!domDoc) {
     NS_WARNING("Failed to QI parent nsIDocument to nsIDOMDocument");
     return NS_ERROR_FAILURE;
   }
 
--- a/widget/src/xpwidgets/nsNativeTheme.cpp
+++ b/widget/src/xpwidgets/nsNativeTheme.cpp
@@ -119,21 +119,19 @@ nsNativeTheme::GetContentState(nsIFrame*
 #endif
 #if defined(XP_WIN)
   // On Windows, focused buttons are always drawn as such by the native theme.
   if (aWidgetType == NS_THEME_BUTTON)
     return flags;
 #endif    
 #if defined(XP_MACOSX) || defined(XP_WIN)
   nsIDocument* doc = aFrame->GetContent()->OwnerDoc();
-  if (doc) {
-    nsPIDOMWindow* window = doc->GetWindow();
-    if (window && !window->ShouldShowFocusRing())
-      flags &= ~NS_EVENT_STATE_FOCUS;
-  }
+  nsPIDOMWindow* window = doc->GetWindow();
+  if (window && !window->ShouldShowFocusRing())
+    flags &= ~NS_EVENT_STATE_FOCUS;
 #endif
   
   return flags;
 }
 
 bool
 nsNativeTheme::CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom)
 {