Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Unified Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 1778753003: Fire visibilitychange event on unload (behind the flag) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a1cf59db7c956423f8e84681d2729ddb1ab74deb..36e2b80fe33f4b8e911227bee7d6fbf81fe1b948 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -1366,6 +1366,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();
}
@@ -2779,6 +2784,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.
@@ -2810,12 +2826,24 @@ void Document::dispatchUnloadEvents()
Document::PageDismissalType Document::pageDismissalEventBeingDispatched() const
{
- if (m_loadEventProgress == BeforeUnloadEventInProgress)
+ switch (m_loadEventProgress) {
+ case BeforeUnloadEventInProgress:
return BeforeUnloadDismissal;
- if (m_loadEventProgress == PageHideInProgress)
+ case PageHideInProgress:
return PageHideDismissal;
- if (m_loadEventProgress == UnloadEventInProgress)
+ case UnloadVisibilityChangeInProgress:
+ return UnloadVisibilityChangeDismissal;
+ case UnloadEventInProgress:
return UnloadDismissal;
+
+ case LoadEventNotRun:
+ case LoadEventInProgress:
+ case LoadEventCompleted:
+ case BeforeUnloadEventCompleted:
+ case UnloadEventHandled:
+ return NoDismissal;
+ }
+ ASSERT_NOT_REACHED();
return NoDismissal;
}
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.h ('k') | third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698