diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 683e0e52e06..9a150d6cf9d 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -573,29 +573,33 @@ nsDocumentViewer::SyncParentSubDocMap() } nsCOMPtr pwin(docShell->GetWindow()); - nsCOMPtr element; - if (mDocument && pwin) { - element = pwin->GetFrameElementInternal(); + if (!mDocument || !pwin) { + return NS_OK; } - if (element) { - nsCOMPtr parent; - docShell->GetParent(getter_AddRefs(parent)); - - nsCOMPtr parent_win = parent ? parent->GetWindow() : nullptr; - if (parent_win) { - nsCOMPtr parent_doc = parent_win->GetDoc(); - if (parent_doc) { - if (mDocument && parent_doc->GetSubDocumentFor(element) != mDocument) { - mDocument->SuppressEventHandling(nsIDocument::eEvents, - parent_doc->EventHandlingSuppressed()); - } - return parent_doc->SetSubDocumentFor(element, mDocument); - } - } + nsCOMPtr element = pwin->GetFrameElementInternal(); + if (!element) { + return NS_OK; } - return NS_OK; + nsCOMPtr parent; + docShell->GetParent(getter_AddRefs(parent)); + + nsCOMPtr parent_win = parent ? parent->GetWindow() : nullptr; + if (!parent_win) { + return NS_OK; + } + + nsCOMPtr parent_doc = parent_win->GetDoc(); + if (!parent_doc) { + return NS_OK; + } + + if (mDocument && parent_doc->GetSubDocumentFor(element) != mDocument) { + mDocument->SuppressEventHandling(nsIDocument::eEvents, + parent_doc->EventHandlingSuppressed()); + } + return parent_doc->SetSubDocumentFor(element, mDocument); } NS_IMETHODIMP