diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp index 210ea3be9e4..89e1d85608d 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -1408,27 +1408,29 @@ nsXBLPrototypeBinding::NotifyBoundElements() nsCOMPtr doc; content->GetDocument(*getter_AddRefs(doc)); - // Flush first - doc->FlushPendingNotifications(); + if (doc) { + // Flush first + doc->FlushPendingNotifications(); - // Notify - nsCOMPtr parent; - content->GetParent(*getter_AddRefs(parent)); - PRInt32 index = 0; - if (parent) - parent->IndexOf(content, index); + // Notify + nsCOMPtr parent; + content->GetParent(*getter_AddRefs(parent)); + PRInt32 index = 0; + if (parent) + parent->IndexOf(content, index); - nsCOMPtr shell = getter_AddRefs(doc->GetShellAt(0)); - if (shell) { - nsIFrame* childFrame; - shell->GetPrimaryFrameFor(content, &childFrame); - nsCOMPtr obs(do_QueryInterface(shell)); - if (!childFrame) - obs->ContentInserted(doc, parent, content, index); - } + nsCOMPtr shell = getter_AddRefs(doc->GetShellAt(0)); + if (shell) { + nsIFrame* childFrame; + shell->GetPrimaryFrameFor(content, &childFrame); + nsCOMPtr obs(do_QueryInterface(shell)); + if (!childFrame) + obs->ContentInserted(doc, parent, content, index); + } - // Flush again - doc->FlushPendingNotifications(); + // Flush again + doc->FlushPendingNotifications(); + } } } diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 62fac6bce08..45fd75a0956 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -8495,6 +8495,16 @@ nsCSSFrameConstructor::ContentInserted(nsIPresContext* aPresContext, nsIFrame* parentFrame = GetFrameFor(shell, aPresContext, aContainer); if (parentFrame) { + // See if we have an XBL insertion point. If so, then see if the + // frame for it has been built yet. If it hasn't been built yet, + // then we just bail. + nsCOMPtr frameManager; + shell->GetFrameManager(getter_AddRefs(frameManager)); + nsIFrame* insertionPoint = nsnull; + frameManager->GetInsertionPoint(shell, parentFrame, aChild, &insertionPoint); + if (!insertionPoint) + return NS_OK; // Don't build the frames. + // Find the frame that precedes the insertion point. nsIFrame* prevSibling = (aIndexInContainer == -1) ? FindPreviousAnonymousSibling(shell, aContainer, aChild) : diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 085c782822e..682ec5b13c5 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -4456,7 +4456,8 @@ PresShell::UnsuppressAndInvalidate() mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); nsCOMPtr ourWindow = do_QueryInterface(globalObject); nsCOMPtr focusController; - ourWindow->GetRootFocusController(getter_AddRefs(focusController)); + if (ourWindow) + ourWindow->GetRootFocusController(getter_AddRefs(focusController)); if (focusController) // Suppress focus. The act of tearing down the old content viewer // causes us to blur incorrectly. @@ -4489,7 +4490,8 @@ PresShell::UnsuppressAndInvalidate() ((nsFrame*)rootFrame)->Invalidate(mPresContext, rect, PR_FALSE); } - CheckForFocus(ourWindow, focusController, mDocument); + if (ourWindow) + CheckForFocus(ourWindow, focusController, mDocument); if (focusController) // Unsuppress now that we've shown the new window and focused it. focusController->SetSuppressFocus(PR_FALSE, "PresShell suppression on Web page loads"); diff --git a/layout/html/base/src/nsPresShell.cpp b/layout/html/base/src/nsPresShell.cpp index 085c782822e..682ec5b13c5 100644 --- a/layout/html/base/src/nsPresShell.cpp +++ b/layout/html/base/src/nsPresShell.cpp @@ -4456,7 +4456,8 @@ PresShell::UnsuppressAndInvalidate() mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); nsCOMPtr ourWindow = do_QueryInterface(globalObject); nsCOMPtr focusController; - ourWindow->GetRootFocusController(getter_AddRefs(focusController)); + if (ourWindow) + ourWindow->GetRootFocusController(getter_AddRefs(focusController)); if (focusController) // Suppress focus. The act of tearing down the old content viewer // causes us to blur incorrectly. @@ -4489,7 +4490,8 @@ PresShell::UnsuppressAndInvalidate() ((nsFrame*)rootFrame)->Invalidate(mPresContext, rect, PR_FALSE); } - CheckForFocus(ourWindow, focusController, mDocument); + if (ourWindow) + CheckForFocus(ourWindow, focusController, mDocument); if (focusController) // Unsuppress now that we've shown the new window and focused it. focusController->SetSuppressFocus(PR_FALSE, "PresShell suppression on Web page loads"); diff --git a/layout/html/style/src/nsCSSFrameConstructor.cpp b/layout/html/style/src/nsCSSFrameConstructor.cpp index 62fac6bce08..45fd75a0956 100644 --- a/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -8495,6 +8495,16 @@ nsCSSFrameConstructor::ContentInserted(nsIPresContext* aPresContext, nsIFrame* parentFrame = GetFrameFor(shell, aPresContext, aContainer); if (parentFrame) { + // See if we have an XBL insertion point. If so, then see if the + // frame for it has been built yet. If it hasn't been built yet, + // then we just bail. + nsCOMPtr frameManager; + shell->GetFrameManager(getter_AddRefs(frameManager)); + nsIFrame* insertionPoint = nsnull; + frameManager->GetInsertionPoint(shell, parentFrame, aChild, &insertionPoint); + if (!insertionPoint) + return NS_OK; // Don't build the frames. + // Find the frame that precedes the insertion point. nsIFrame* prevSibling = (aIndexInContainer == -1) ? FindPreviousAnonymousSibling(shell, aContainer, aChild) : diff --git a/layout/xul/base/src/nsMenuBarFrame.cpp b/layout/xul/base/src/nsMenuBarFrame.cpp index 8351c360d7e..51ca523e047 100644 --- a/layout/xul/base/src/nsMenuBarFrame.cpp +++ b/layout/xul/base/src/nsMenuBarFrame.cpp @@ -219,7 +219,8 @@ static void GetInsertionPoint(nsIPresShell* aShell, nsIFrame* aFrame, nsIFrame* nsCOMPtr frameManager; aShell->GetFrameManager(getter_AddRefs(frameManager)); nsCOMPtr child; - aChild->GetContent(getter_AddRefs(child)); + if (aChild) + aChild->GetContent(getter_AddRefs(child)); frameManager->GetInsertionPoint(aShell, aFrame, child, aResult); } diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index e1c1b04568b..300466bab89 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -903,7 +903,8 @@ static void GetInsertionPoint(nsIPresShell* aShell, nsIFrame* aFrame, nsIFrame* nsCOMPtr frameManager; aShell->GetFrameManager(getter_AddRefs(frameManager)); nsCOMPtr child; - aChild->GetContent(getter_AddRefs(child)); + if (aChild) + aChild->GetContent(getter_AddRefs(child)); frameManager->GetInsertionPoint(aShell, aFrame, child, aResult); }