diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 97165ac43a6..74404b0e219 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -85,6 +85,7 @@ #include "nsVideoFrame.h" #include "BasicLayers.h" #include +#include "nsIDocShellTreeItem.h" #ifdef MOZ_OGG #include "nsOggDecoder.h" @@ -1752,26 +1753,42 @@ void nsHTMLMediaElement::NotifyAutoplayDataReady() */ static already_AddRefed GetLayerManagerForDoc(nsIDocument* aDoc) { - while (aDoc) { - nsIDocument* displayDoc = aDoc->GetDisplayDocument(); - if (displayDoc) { - aDoc = displayDoc; - continue; - } + nsIDocument* doc = aDoc; + nsIDocument* displayDoc = doc->GetDisplayDocument(); + if (displayDoc) { + doc = displayDoc; + } - nsIPresShell* shell = aDoc->GetPrimaryShell(); - if (shell) { - nsIFrame* rootFrame = shell->FrameManager()->GetRootFrame(); - if (rootFrame) { - nsIWidget* widget = - nsLayoutUtils::GetDisplayRootFrame(rootFrame)->GetWindow(); - if (widget) { - nsRefPtr manager = widget->GetLayerManager(); - return manager.forget(); - } + nsIPresShell* shell = doc->GetPrimaryShell(); + nsCOMPtr container = doc->GetContainer(); + nsCOMPtr docShellTreeItem = do_QueryInterface(container); + while (!shell && docShellTreeItem) { + // We may be in a display:none subdocument, or we may not have a presshell + // created yet. + // Walk the docshell tree to find the nearest container that has a presshell, + // and find the root widget from that. + nsCOMPtr docShell = do_QueryInterface(docShellTreeItem); + nsCOMPtr presShell; + docShell->GetPresShell(getter_AddRefs(presShell)); + if (presShell) { + shell = presShell; + } else { + nsCOMPtr parent; + docShellTreeItem->GetParent(getter_AddRefs(parent)); + docShellTreeItem = parent; + } + } + + if (shell) { + nsIFrame* rootFrame = shell->FrameManager()->GetRootFrame(); + if (rootFrame) { + nsIWidget* widget = + nsLayoutUtils::GetDisplayRootFrame(rootFrame)->GetWindow(); + if (widget) { + nsRefPtr manager = widget->GetLayerManager(); + return manager.forget(); } } - aDoc = aDoc->GetParentDocument(); } nsRefPtr manager = new BasicLayerManager(nsnull);