Index: third_party/WebKit/Source/core/dom/Document.cpp |
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp |
index 85872f18179bc4ea129f9572fcc591b5c599cc6b..d3ceae4d7ea6b75f5f5a8a4cd76a9aae4d61257d 100644 |
--- a/third_party/WebKit/Source/core/dom/Document.cpp |
+++ b/third_party/WebKit/Source/core/dom/Document.cpp |
@@ -1367,6 +1367,11 @@ PageVisibilityState Document::pageVisibilityState() const |
// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html#dom-document-hidden |
if (!m_frame || !m_frame->page()) |
return PageVisibilityStateHidden; |
+ // While visibilitychange is being dispatched during unloading it is |
+ // expected that the visibility is hidden regardless of the page's |
+ // visibility. |
+ if (m_loadEventProgress == UnloadVisibilityChangeInProgress) |
+ return PageVisibilityStateHidden; |
return m_frame->page()->visibilityState(); |
} |
@@ -2763,6 +2768,17 @@ void Document::dispatchUnloadEvents() |
if (!m_frame) |
return; |
+ PageVisibilityState visibilityState = pageVisibilityState(); |
+ m_loadEventProgress = UnloadVisibilityChangeInProgress; |
+ if (visibilityState != PageVisibilityStateHidden && RuntimeEnabledFeatures::visibilityChangeOnUnloadEnabled()) { |
+ // Dispatch visibilitychange event, but don't bother doing |
+ // other notifications as we're about to be unloaded. |
+ dispatchEvent(Event::createBubble(EventTypeNames::visibilitychange)); |
+ dispatchEvent(Event::createBubble(EventTypeNames::webkitvisibilitychange)); |
+ } |
+ if (!m_frame) |
+ return; |
+ |
// The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed |
// while dispatching the event, so protect it to prevent writing the end |
// time into freed memory. |
@@ -2798,6 +2814,8 @@ Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const |
return BeforeUnloadDismissal; |
if (m_loadEventProgress == PageHideInProgress) |
return PageHideDismissal; |
+ if (m_loadEventProgress == UnloadVisibilityChangeInProgress) |
+ return UnloadVisibilityChangeDismissal; |
if (m_loadEventProgress == UnloadEventInProgress) |
return UnloadDismissal; |
return NoDismissal; |