Title: [268979] trunk/Source
Revision
268979
Author
[email protected]
Date
2020-10-26 08:35:35 -0700 (Mon, 26 Oct 2020)

Log Message

Use a WeakHashSet for Document::m_captionPreferencesChangedElements
https://bugs.webkit.org/show_bug.cgi?id=218170

Reviewed by Eric Carlson.

Source/WebCore:

Refactoring to move from raw pointer to weak pointer.
For that purpose, we use WeakHashSet and WeakHashSet::forEach for extra safety.
No observable change of behavior.

* dom/Document.cpp:
(WebCore::Document::registerForCaptionPreferencesChangedCallbacks):
(WebCore::Document::unregisterForCaptionPreferencesChangedCallbacks):
(WebCore::Document::captionPreferencesChanged):
* dom/Document.h:

Source/WTF:

* wtf/WeakHashSet.h:
Add a static cast for classes inheriting CanMakeWeakPtr like done for the set iterator.
Update code to compile in WinCairo.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (268978 => 268979)


--- trunk/Source/WTF/ChangeLog	2020-10-26 14:54:53 UTC (rev 268978)
+++ trunk/Source/WTF/ChangeLog	2020-10-26 15:35:35 UTC (rev 268979)
@@ -1,3 +1,14 @@
+2020-10-26  Youenn Fablet  <[email protected]>
+
+        Use a WeakHashSet for Document::m_captionPreferencesChangedElements
+        https://bugs.webkit.org/show_bug.cgi?id=218170
+
+        Reviewed by Eric Carlson.
+
+        * wtf/WeakHashSet.h:
+        Add a static cast for classes inheriting CanMakeWeakPtr like done for the set iterator.
+        Update code to compile in WinCairo.
+
 2020-10-26  Zan Dobersek  <[email protected]>
 
         Remove Accelerated2dCanvasEnabled WebPreferences entry

Modified: trunk/Source/WTF/wtf/WeakHashSet.h (268978 => 268979)


--- trunk/Source/WTF/wtf/WeakHashSet.h	2020-10-26 14:54:53 UTC (rev 268978)
+++ trunk/Source/WTF/wtf/WeakHashSet.h	2020-10-26 15:35:35 UTC (rev 268979)
@@ -139,7 +139,11 @@
 
     void forEach(const Function<void(T&)>& callback)
     {
-        for (auto& item : map(m_set, [](auto& item) { return makeWeakPtr(item->template get<T>()); })) {
+        auto items = map(m_set, [](const Ref<WeakPtrImpl<Counter>>& item) {
+            auto* pointer = static_cast<T*>(item->template get<T>());
+            return makeWeakPtr(pointer);
+        });
+        for (auto& item : items) {
             if (item && m_set.contains(*item.m_impl))
                 callback(*item);
         }

Modified: trunk/Source/WebCore/ChangeLog (268978 => 268979)


--- trunk/Source/WebCore/ChangeLog	2020-10-26 14:54:53 UTC (rev 268978)
+++ trunk/Source/WebCore/ChangeLog	2020-10-26 15:35:35 UTC (rev 268979)
@@ -1,5 +1,22 @@
 2020-10-26  Youenn Fablet  <[email protected]>
 
+        Use a WeakHashSet for Document::m_captionPreferencesChangedElements
+        https://bugs.webkit.org/show_bug.cgi?id=218170
+
+        Reviewed by Eric Carlson.
+
+        Refactoring to move from raw pointer to weak pointer.
+        For that purpose, we use WeakHashSet and WeakHashSet::forEach for extra safety.
+        No observable change of behavior.
+
+        * dom/Document.cpp:
+        (WebCore::Document::registerForCaptionPreferencesChangedCallbacks):
+        (WebCore::Document::unregisterForCaptionPreferencesChangedCallbacks):
+        (WebCore::Document::captionPreferencesChanged):
+        * dom/Document.h:
+
+2020-10-26  Youenn Fablet  <[email protected]>
+
         Make use of signalling thread when creating the peer connection factory
         https://bugs.webkit.org/show_bug.cgi?id=218169
 

Modified: trunk/Source/WebCore/dom/Document.cpp (268978 => 268979)


--- trunk/Source/WebCore/dom/Document.cpp	2020-10-26 14:54:53 UTC (rev 268978)
+++ trunk/Source/WebCore/dom/Document.cpp	2020-10-26 15:35:35 UTC (rev 268979)
@@ -5528,18 +5528,20 @@
     if (page())
         page()->group().captionPreferences().setInterestedInCaptionPreferenceChanges();
 
-    m_captionPreferencesChangedElements.add(&element);
+    m_captionPreferencesChangedElements.add(element);
 }
 
 void Document::unregisterForCaptionPreferencesChangedCallbacks(HTMLMediaElement& element)
 {
-    m_captionPreferencesChangedElements.remove(&element);
+    m_captionPreferencesChangedElements.remove(element);
 }
 
 void Document::captionPreferencesChanged()
 {
-    for (auto* element : m_captionPreferencesChangedElements)
-        element->captionPreferencesChanged();
+    ASSERT(!m_captionPreferencesChangedElements.hasNullReferences());
+    m_captionPreferencesChangedElements.forEach([](HTMLMediaElement& element) {
+        element.captionPreferencesChanged();
+    });
 }
 
 void Document::setMediaElementShowingTextTrack(const HTMLMediaElement& element)

Modified: trunk/Source/WebCore/dom/Document.h (268978 => 268979)


--- trunk/Source/WebCore/dom/Document.h	2020-10-26 14:54:53 UTC (rev 268978)
+++ trunk/Source/WebCore/dom/Document.h	2020-10-26 15:35:35 UTC (rev 268979)
@@ -1836,7 +1836,7 @@
 #endif
 
 #if ENABLE(VIDEO)
-    HashSet<HTMLMediaElement*> m_captionPreferencesChangedElements;
+    WeakHashSet<HTMLMediaElement> m_captionPreferencesChangedElements;
     WeakPtr<HTMLMediaElement> m_mediaElementShowingTextTrack;
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to