Don't put pages that have not reached the non-visually empty layout milestone in the back/forward cache
https://bugs.webkit.org/show_bug.cgi?id=203108

Reviewed by Geoffrey Garen.

We don't want to go back to a visually empty page on back/forward navigation.

* history/BackForwardCache.cpp:
(WebCore::canCacheFrame):
* page/DiagnosticLoggingKeys.cpp:
(WebCore::DiagnosticLoggingKeys::visuallyEmptyKey):
* page/DiagnosticLoggingKeys.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251255 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 17ee39b..186110d 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,18 @@
+2019-10-17  Chris Dumez  <cdumez@apple.com>
+
+        Don't put pages that have not reached the non-visually empty layout milestone in the back/forward cache
+        https://bugs.webkit.org/show_bug.cgi?id=203108
+
+        Reviewed by Geoffrey Garen.
+
+        We don't want to go back to a visually empty page on back/forward navigation.
+
+        * history/BackForwardCache.cpp:
+        (WebCore::canCacheFrame):
+        * page/DiagnosticLoggingKeys.cpp:
+        (WebCore::DiagnosticLoggingKeys::visuallyEmptyKey):
+        * page/DiagnosticLoggingKeys.h:
+
 2019-10-17  Dirk Schulze  <krit@webkit.org>
 
         transform-box: content-box, stroke-box missing
diff --git a/Source/WebCore/history/BackForwardCache.cpp b/Source/WebCore/history/BackForwardCache.cpp
index 937353f..02acd95 100644
--- a/Source/WebCore/history/BackForwardCache.cpp
+++ b/Source/WebCore/history/BackForwardCache.cpp
@@ -132,6 +132,11 @@
         logBackForwardCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::noCurrentHistoryItemKey());
         isCacheable = false;
     }
+    if (frame.isMainFrame() && frame.view() && !frame.view()->isVisuallyNonEmpty()) {
+        PCLOG("   -Main frame is visually empty");
+        logBackForwardCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::visuallyEmptyKey());
+        isCacheable = false;
+    }
     if (frameLoader.quickRedirectComing()) {
         PCLOG("   -Quick redirect is coming");
         logBackForwardCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::quirkRedirectComingKey());
diff --git a/Source/WebCore/page/DiagnosticLoggingKeys.cpp b/Source/WebCore/page/DiagnosticLoggingKeys.cpp
index 98bd0c7..84ff08b 100644
--- a/Source/WebCore/page/DiagnosticLoggingKeys.cpp
+++ b/Source/WebCore/page/DiagnosticLoggingKeys.cpp
@@ -218,6 +218,11 @@
     return "backForwardCacheFailure"_s;
 }
 
+String DiagnosticLoggingKeys::visuallyEmptyKey()
+{
+    return "visuallyEmpty"_s;
+}
+
 String DiagnosticLoggingKeys::noDocumentLoaderKey()
 {
     return "noDocumentLoader"_s;
diff --git a/Source/WebCore/page/DiagnosticLoggingKeys.h b/Source/WebCore/page/DiagnosticLoggingKeys.h
index 972a0df..92ac3b6 100644
--- a/Source/WebCore/page/DiagnosticLoggingKeys.h
+++ b/Source/WebCore/page/DiagnosticLoggingKeys.h
@@ -116,6 +116,7 @@
     WEBCORE_EXPORT static String otherKey();
     static String backForwardCacheKey();
     static String backForwardCacheFailureKey();
+    static String visuallyEmptyKey();
     static String pageContainsAtLeastOneMediaEngineKey();
     static String pageContainsAtLeastOnePluginKey();
     static String pageContainsMediaEngineKey();