Title: [274155] trunk/Source/WebCore
Revision
274155
Author
megan_gard...@apple.com
Date
2021-03-09 10:01:59 -0800 (Tue, 09 Mar 2021)

Log Message

Hold onto AppHighlights and restore them once the page is loaded.
https://bugs.webkit.org/show_bug.cgi?id=222640

Reviewed by Devin Rousso.

* Modules/highlight/AppHighlightStorage.cpp:
(WebCore::AppHighlightStorage::restoreAppHighlight):
(WebCore::AppHighlightStorage::restoreUnrestoredAppHighlights):
* Modules/highlight/AppHighlightStorage.h:
* dom/Document.cpp:
(WebCore::Document::finishedParsing):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (274154 => 274155)


--- trunk/Source/WebCore/ChangeLog	2021-03-09 17:38:47 UTC (rev 274154)
+++ trunk/Source/WebCore/ChangeLog	2021-03-09 18:01:59 UTC (rev 274155)
@@ -1,3 +1,17 @@
+2021-03-09  Megan Gardner  <megan_gard...@apple.com>
+
+        Hold onto AppHighlights and restore them once the page is loaded.
+        https://bugs.webkit.org/show_bug.cgi?id=222640
+
+        Reviewed by Devin Rousso.
+
+        * Modules/highlight/AppHighlightStorage.cpp:
+        (WebCore::AppHighlightStorage::restoreAppHighlight):
+        (WebCore::AppHighlightStorage::restoreUnrestoredAppHighlights):
+        * Modules/highlight/AppHighlightStorage.h:
+        * dom/Document.cpp:
+        (WebCore::Document::finishedParsing):
+
 2021-03-09  Youenn Fablet  <you...@apple.com>
 
         MediaRecorder.requestData() not returning all captured media after a pause

Modified: trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp (274154 => 274155)


--- trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp	2021-03-09 17:38:47 UTC (rev 274154)
+++ trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp	2021-03-09 18:01:59 UTC (rev 274155)
@@ -214,6 +214,8 @@
 {
 }
 
+AppHighlightStorage::~AppHighlightStorage() = default;
+
 void AppHighlightStorage::storeAppHighlight(Ref<StaticRange>&& range)
 {
     auto data = ""
@@ -227,24 +229,43 @@
     m_document->page()->chrome().storeAppHighlight(WTFMove(highlight));
 }
 
-bool AppHighlightStorage::restoreAppHighlight(Ref<SharedBuffer>&& buffer)
+void AppHighlightStorage::restoreAppHighlight(Ref<SharedBuffer>&& buffer)
 {
+    if (!m_document)
+        return;
+    
     auto strongDocument = makeRefPtr(m_document.get());
 
-    if (!m_document)
-        return false;
-
     auto appHighlightRangeData = AppHighlightRangeData::create(buffer);
     if (!appHighlightRangeData)
-        return false;
+        return;
 
     auto range = findRange(*appHighlightRangeData, *strongDocument);
     
     if (!range)
-        return false;
-    strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
+        m_unrestoredHighlights.append(appHighlightRangeData.value());
+    else
+        strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
+}
 
-    return true;
+void AppHighlightStorage::restoreUnrestoredAppHighlights()
+{
+    Vector<AppHighlightRangeData> remainingRanges;
+
+    if (!m_document)
+        return;
+    
+    auto strongDocument = makeRefPtr(m_document.get());
+    
+    for (auto& highlight : m_unrestoredHighlights) {
+        auto range = findRange(highlight, *strongDocument);
+        
+        if (!range)
+            remainingRanges.append(highlight);
+        else
+            strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
+    }
+    m_unrestoredHighlights = WTFMove(remainingRanges);
 }
 
 #endif

Modified: trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.h (274154 => 274155)


--- trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.h	2021-03-09 17:38:47 UTC (rev 274154)
+++ trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.h	2021-03-09 18:01:59 UTC (rev 274155)
@@ -43,16 +43,19 @@
 
 enum class CreateNewGroupForHighlight : bool;
 
-class AppHighlightStorage : RefCounted<AppHighlightStorage> {
+class AppHighlightStorage final : RefCounted<AppHighlightStorage> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     AppHighlightStorage(Document&);
+    ~AppHighlightStorage();
 
-    WEBCORE_EXPORT void storeAppHighlight(Ref<StaticRange>&&);
-    WEBCORE_EXPORT bool restoreAppHighlight(Ref<SharedBuffer>&&);
+    WEBCORE_EXPORT void storeAppHighlight(StaticRange&&);
+    WEBCORE_EXPORT void restoreAppHighlight(Ref<SharedBuffer>&&);
+    void restoreUnrestoredAppHighlights();
 
 private:
     WeakPtr<Document> m_document;
+    Vector<AppHighlightRangeData> m_unrestoredHighlights;
 };
 
 #endif

Modified: trunk/Source/WebCore/dom/Document.cpp (274154 => 274155)


--- trunk/Source/WebCore/dom/Document.cpp	2021-03-09 17:38:47 UTC (rev 274154)
+++ trunk/Source/WebCore/dom/Document.cpp	2021-03-09 18:01:59 UTC (rev 274155)
@@ -6019,6 +6019,11 @@
             serviceWorkerContainer->startMessages();
     }
 #endif
+    
+#if ENABLE(APP_HIGHLIGHTS)
+    if (auto* appHighlightStorage = appHighlightStorageIfExists())
+        appHighlightStorage->restoreUnrestoredAppHighlights();
+#endif
 }
 
 void Document::clearSharedObjectPool()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to