Index: Source/core/html/HTMLMediaElement.cpp |
diff --git a/Source/core/html/HTMLMediaElement.cpp b/Source/core/html/HTMLMediaElement.cpp |
index 82794ff304815ec6a0fe94f87be969867e44ee7b..5d5aad872c97875d0c8ce7eef0e27681c2057f38 100644 |
--- a/Source/core/html/HTMLMediaElement.cpp |
+++ b/Source/core/html/HTMLMediaElement.cpp |
@@ -369,9 +369,14 @@ void HTMLMediaElement::didMoveToNewDocument(Document* oldDocument) |
LOG(Media, "HTMLMediaElement::didMoveToNewDocument"); |
if (m_shouldDelayLoadEvent) { |
- if (oldDocument) |
- oldDocument->decrementLoadEventDelayCount(); |
document().incrementLoadEventDelayCount(); |
+ // Note: Keeping the load event delay count increment on oldDocument that was added |
+ // when m_shouldDelayLoadEvent was set so that destruction of m_player can not |
+ // cause load event dispatching in oldDocument. |
+ } else if (oldDocument) { |
+ // Incrementing the load event delay count so that destruction of m_player can not |
+ // cause load event dispatching in oldDocument. |
+ oldDocument->incrementLoadEventDelayCount(); |
} |
if (oldDocument) |
@@ -386,6 +391,11 @@ void HTMLMediaElement::didMoveToNewDocument(Document* oldDocument) |
// document changes so that playback can be resumed properly. |
userCancelledLoad(); |
+ // Decrement the load event delay count on oldDocument now that m_player has been destroyed |
+ // and there is no risk of dispatching a load event from within the destructor. |
+ if (oldDocument) |
+ oldDocument->decrementLoadEventDelayCount(); |
+ |
HTMLElement::didMoveToNewDocument(oldDocument); |
} |