diff --git a/mozilla/content/html/document/src/nsMediaDocument.cpp b/mozilla/content/html/document/src/nsMediaDocument.cpp
index 20df54534d5..1ef208cf51d 100644
--- a/mozilla/content/html/document/src/nsMediaDocument.cpp
+++ b/mozilla/content/html/document/src/nsMediaDocument.cpp
@@ -269,8 +269,15 @@ nsMediaDocument::StartLayout()
nsPresShellIterator iter(this);
nsCOMPtr shell;
while ((shell = iter.GetNextShell())) {
+ PRBool didInitialReflow = PR_FALSE;
+ shell->GetDidInitialReflow(&didInitialReflow);
+ if (didInitialReflow) {
+ // Don't mess with this presshell: someone has already handled
+ // its initial reflow.
+ continue;
+ }
+
nsRect visibleArea = shell->GetPresContext()->GetVisibleArea();
- nsCOMPtr shellGrip = shell;
nsresult rv = shell->InitialReflow(visibleArea.width, visibleArea.height);
NS_ENSURE_SUCCESS(rv, rv);