Bug 1521603 - Add a helper method to check if the top level content document hasn't yet got first contentful paint and there is high prio event pending, r=jesup
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Tue, 22 Jan 2019 01:13:01 +0200
changeset 514786 8ad35cea96d9c6c64c7f6c5e9e8f57a6b04f161a
parent 514780 d94203c1f6b52716801969622868a56361af7cb5
child 514787 d02c0a90a085a4f75fab25dba9fa305bd97d7532
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1521603
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1521603 - Add a helper method to check if the top level content document hasn't yet got first contentful paint and there is high prio event pending, r=jesup
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -232,17 +232,17 @@
 #include "mozilla/dom/TabGroup.h"
 #include "nsIWebNavigationInfo.h"
 #include "nsPluginHost.h"
 #include "nsIBrowser.h"
 #include "mozilla/HangAnnotations.h"
 #include "mozilla/Encoding.h"
 #include "nsXULElement.h"
 #include "mozilla/RecordReplay.h"
-
+#include "nsThreadManager.h"
 #include "nsIBidiKeyboard.h"
 
 #if defined(XP_WIN)
 // Undefine LoadImage to prevent naming conflict with Windows.
 #  undef LoadImage
 #endif
 
 extern "C" int MOZ_XMLTranslateEntity(const char* ptr, const char* end,
@@ -10430,16 +10430,30 @@ static bool JSONCreator(const char16_t* 
   nsAutoString serializedValue;
   NS_ENSURE_TRUE(JS_Stringify(aCx, &value, nullptr, JS::NullHandleValue,
                               JSONCreator, &serializedValue),
                  false);
   aOutStr = serializedValue;
   return true;
 }
 
+/* static */
+bool nsContentUtils::HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
+    Document* aDocument) {
+  if (!aDocument) {
+    return false;
+  }
+
+  Document* topLevel = aDocument->GetTopLevelContentDocument();
+  return topLevel && topLevel->GetShell() &&
+         topLevel->GetShell()->GetPresContext() &&
+         !topLevel->GetShell()->GetPresContext()->HadContentfulPaint() &&
+         nsThreadManager::MainThreadHasPendingHighPriorityEvents();
+}
+
 /* static */ bool nsContentUtils::IsURIInPrefList(nsIURI* aURI,
                                                   const char* aPrefName) {
   MOZ_ASSERT(aPrefName);
 
   nsAutoCString blackList;
   Preferences::GetCString(aPrefName, blackList);
   ToLowerCase(blackList);
   return IsURIInList(aURI, blackList);
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -3299,16 +3299,24 @@ class nsContentUtils {
    *
    * Usage:
    *   nsAutoString serializedValue;
    *   nsContentUtils::StringifyJSON(cx, &value, serializedValue);
    */
   static bool StringifyJSON(JSContext* aCx, JS::MutableHandle<JS::Value> vp,
                             nsAString& aOutStr);
 
+  /**
+   * Returns true if the top level ancestor content document of aDocument hasn't
+   * yet had the first contentful paint and there is a high priority event
+   * pending in the main thread.
+   */
+  static bool HighPriorityEventPendingForTopLevelDocumentBeforeContentfulPaint(
+      Document* aDocument);
+
  private:
   static bool InitializeEventTable();
 
   static nsresult EnsureStringBundle(PropertiesFile aFile);
 
   static bool CanCallerAccess(nsIPrincipal* aSubjectPrincipal,
                               nsIPrincipal* aPrincipal);