Changeset 277013 in webkit


Ignore:
Timestamp:
May 5, 2021 6:14:26 AM (3 years ago)
Author:
rniwa@webkit.org
Message:

Use WeakHashSet instead of HashSet of raw pointes in Document and SVGDocumentExtensions
https://bugs.webkit.org/show_bug.cgi?id=225390

Reviewed by Antti Koivisto.

Replaced Document's m_documentSuspensionCallbackElements and m_articleElements as well as
SVGDocumentExtensions's m_timeContainers and m_svgFontFaceElements with WeakHashSet.

Also moved m_svgUseElements from Document to SVGDocumentExtensions as a WeakHashSet.

This patch also deletes Document::m_mediaStreamStateChangeElements which was never used,
m_mainArticleElement a WeakPtr instead of a raw pointer, replaces SVGDocumentExtensions's
m_rebuildElements, which is a temporary Vector used during tree mutations, with a Vector
of Refs instead of raw pointers.

No new tests since there should be no observable behavior differences.

  • dom/Document.cpp:

(WebCore::Document::~Document): The release assert is moved to ~SVGDocumentExtensions.
(WebCore::Document::resolveStyle):
(WebCore::Document::suspend):
(WebCore::Document::resume):
(WebCore::Document::registerForDocumentSuspensionCallbacks):
(WebCore::Document::unregisterForDocumentSuspensionCallbacks):
(WebCore::Document::addSVGUseElement): Moved to SVGDocumentExtensions.
(WebCore::Document::removeSVGUseElement): Ditto.
(WebCore::Document::registerArticleElement):
(WebCore::Document::unregisterArticleElement):
(WebCore::Document::updateMainArticleElementAfterLayout):
(WebCore::Document::prepareCanvasesForDisplayIfNeeded):
(WebCore::Document::clearCanvasPreparation):
(WebCore::Document::canvasChanged):
(WebCore::Document::canvasDestroyed):

  • dom/Document.h:

(WebCore::Document:: const const): Deleted.

  • html/HTMLCanvasElement.cpp:

(WebCore::HTMLCanvasElement::~HTMLCanvasElement):
(WebCore::HTMLCanvasElement::didMoveToNewDocument):
(WebCore::HTMLCanvasElement::removedFromAncestor):

  • style/StyleResolver.cpp:

(WebCore::Style::Resolver::addCurrentSVGFontFaceRules):

  • svg/SVGDocumentExtensions.cpp:

(WebCore::SVGDocumentExtensions::~SVGDocumentExtensions): Moved the release assertion
from ~Document.
(WebCore::SVGDocumentExtensions::addTimeContainer):
(WebCore::SVGDocumentExtensions::removeTimeContainer):
(WebCore::SVGDocumentExtensions::addUseElementWithPendingShadowTreeUpdate): Moved here
Document::addSVGUseElement.
(WebCore::SVGDocumentExtensions::removeUseElementWithPendingShadowTreeUpdate): Ditto.
(WebCore::SVGDocumentExtensions::startAnimations):
(WebCore::SVGDocumentExtensions::pauseAnimations):
(WebCore::SVGDocumentExtensions::unpauseAnimations):
(WebCore::SVGDocumentExtensions::dispatchLoadEventToOutermostSVGElements):
(WebCore::SVGDocumentExtensions::rebuildElements):
(WebCore::SVGDocumentExtensions::clearTargetDependencies):
(WebCore::SVGDocumentExtensions::removeAllElementReferencesForTarget):
(WebCore::SVGDocumentExtensions::registerSVGFontFaceElement):
(WebCore::SVGDocumentExtensions::unregisterSVGFontFaceElement):

  • svg/SVGDocumentExtensions.h:

(WebCore::SVGDocumentExtensions::useElementsWithPendingShadowTreeUpdate const): Added.
(WebCore::SVGDocumentExtensions::svgFontFaceElements const):

  • svg/SVGUseElement.cpp:

(WebCore::SVGUseElement::insertedIntoAncestor):
(WebCore::SVGUseElement::removedFromAncestor):
(WebCore::SVGUseElement::updateShadowTree):
(WebCore::SVGUseElement::invalidateShadowTree):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r277011 r277013  
     12021-05-05  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Use WeakHashSet instead of HashSet of raw pointes in Document and SVGDocumentExtensions
     4        https://bugs.webkit.org/show_bug.cgi?id=225390
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Replaced Document's m_documentSuspensionCallbackElements and m_articleElements as well as
     9        SVGDocumentExtensions's m_timeContainers and m_svgFontFaceElements with WeakHashSet.
     10
     11        Also moved m_svgUseElements from Document to SVGDocumentExtensions as a WeakHashSet.
     12
     13        This patch also deletes Document::m_mediaStreamStateChangeElements which was never used,
     14        m_mainArticleElement a WeakPtr instead of a raw pointer, replaces SVGDocumentExtensions's
     15        m_rebuildElements, which is a temporary Vector used during tree mutations, with a Vector
     16        of Refs instead of raw pointers.
     17
     18        No new tests since there should be no observable behavior differences.
     19
     20        * dom/Document.cpp:
     21        (WebCore::Document::~Document): The release assert is moved to ~SVGDocumentExtensions.
     22        (WebCore::Document::resolveStyle):
     23        (WebCore::Document::suspend):
     24        (WebCore::Document::resume):
     25        (WebCore::Document::registerForDocumentSuspensionCallbacks):
     26        (WebCore::Document::unregisterForDocumentSuspensionCallbacks):
     27        (WebCore::Document::addSVGUseElement): Moved to SVGDocumentExtensions.
     28        (WebCore::Document::removeSVGUseElement): Ditto.
     29        (WebCore::Document::registerArticleElement):
     30        (WebCore::Document::unregisterArticleElement):
     31        (WebCore::Document::updateMainArticleElementAfterLayout):
     32        (WebCore::Document::prepareCanvasesForDisplayIfNeeded):
     33        (WebCore::Document::clearCanvasPreparation):
     34        (WebCore::Document::canvasChanged):
     35        (WebCore::Document::canvasDestroyed):
     36        * dom/Document.h:
     37        (WebCore::Document:: const const): Deleted.
     38        * html/HTMLCanvasElement.cpp:
     39        (WebCore::HTMLCanvasElement::~HTMLCanvasElement):
     40        (WebCore::HTMLCanvasElement::didMoveToNewDocument):
     41        (WebCore::HTMLCanvasElement::removedFromAncestor):
     42        * style/StyleResolver.cpp:
     43        (WebCore::Style::Resolver::addCurrentSVGFontFaceRules):
     44        * svg/SVGDocumentExtensions.cpp:
     45        (WebCore::SVGDocumentExtensions::~SVGDocumentExtensions): Moved the release assertion
     46        from ~Document.
     47        (WebCore::SVGDocumentExtensions::addTimeContainer):
     48        (WebCore::SVGDocumentExtensions::removeTimeContainer):
     49        (WebCore::SVGDocumentExtensions::addUseElementWithPendingShadowTreeUpdate): Moved here
     50        Document::addSVGUseElement.
     51        (WebCore::SVGDocumentExtensions::removeUseElementWithPendingShadowTreeUpdate): Ditto.
     52        (WebCore::SVGDocumentExtensions::startAnimations):
     53        (WebCore::SVGDocumentExtensions::pauseAnimations):
     54        (WebCore::SVGDocumentExtensions::unpauseAnimations):
     55        (WebCore::SVGDocumentExtensions::dispatchLoadEventToOutermostSVGElements):
     56        (WebCore::SVGDocumentExtensions::rebuildElements):
     57        (WebCore::SVGDocumentExtensions::clearTargetDependencies):
     58        (WebCore::SVGDocumentExtensions::removeAllElementReferencesForTarget):
     59        (WebCore::SVGDocumentExtensions::registerSVGFontFaceElement):
     60        (WebCore::SVGDocumentExtensions::unregisterSVGFontFaceElement):
     61        * svg/SVGDocumentExtensions.h:
     62        (WebCore::SVGDocumentExtensions::useElementsWithPendingShadowTreeUpdate const): Added.
     63        (WebCore::SVGDocumentExtensions::svgFontFaceElements const):
     64        * svg/SVGUseElement.cpp:
     65        (WebCore::SVGUseElement::insertedIntoAncestor):
     66        (WebCore::SVGUseElement::removedFromAncestor):
     67        (WebCore::SVGUseElement::updateShadowTree):
     68        (WebCore::SVGUseElement::invalidateShadowTree):
     69
    1702021-05-05  Chris Lord  <clord@igalia.com>
    271
  • trunk/Source/WebCore/dom/Document.cpp

    r276952 r277013  
    780780    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_listsInvalidatedAtDocument.isEmpty());
    781781    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_collectionsInvalidatedAtDocument.isEmpty());
    782     RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_svgUseElements.isEmpty());
    783782
    784783    for (unsigned count : m_nodeListAndCollectionCounts)
     
    20082007
    20092008    // FIXME: Do this update per tree scope.
    2010     {
    2011         auto elements = copyToVectorOf<RefPtr<SVGUseElement>>(m_svgUseElements);
     2009    if (auto* extensions = m_svgExtensions.get()) {
     2010        auto elements = copyToVectorOf<Ref<SVGUseElement>>(extensions->useElementsWithPendingShadowTreeUpdate());
    20122011        // We can't clear m_svgUseElements here because updateShadowTree may end up executing arbitrary scripts
    20132012        // which may insert new SVG use elements or remove existing ones inside sync IPC via ImageLoader::updateFromElement.
     
    56495648    documentWillBecomeInactive();
    56505649
    5651     for (auto* element : m_documentSuspensionCallbackElements)
    5652         element->prepareForDocumentSuspension();
     5650    for (auto& element : m_documentSuspensionCallbackElements)
     5651        element.prepareForDocumentSuspension();
    56535652
    56545653#if ASSERT_ENABLED
     
    56975696        return;
    56985697
    5699     for (auto* element : copyToVector(m_documentSuspensionCallbackElements))
     5698    for (auto element : copyToVectorOf<Ref<Element>>(m_documentSuspensionCallbackElements))
    57005699        element->resumeFromDocumentSuspension();
    57015700
     
    57275726void Document::registerForDocumentSuspensionCallbacks(Element& element)
    57285727{
    5729     m_documentSuspensionCallbackElements.add(&element);
     5728    m_documentSuspensionCallbackElements.add(element);
    57305729}
    57315730
    57325731void Document::unregisterForDocumentSuspensionCallbacks(Element& element)
    57335732{
    5734     m_documentSuspensionCallbackElements.remove(&element);
     5733    m_documentSuspensionCallbackElements.remove(element);
    57355734}
    57365735
     
    60536052        m_svgExtensions = makeUnique<SVGDocumentExtensions>(*this);
    60546053    return *m_svgExtensions;
    6055 }
    6056 
    6057 void Document::addSVGUseElement(SVGUseElement& element)
    6058 {
    6059     auto result = m_svgUseElements.add(&element);
    6060     RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.isNewEntry);
    6061 }
    6062 
    6063 void Document::removeSVGUseElement(SVGUseElement& element)
    6064 {
    6065     m_svgUseElements.remove(&element);
    6066     // FIXME: Assert that element was in m_svgUseElements once re-entrancy to update style and layout have been removed.
    60676054}
    60686055
     
    83438330void Document::registerArticleElement(Element& article)
    83448331{
    8345     m_articleElements.add(&article);
     8332    m_articleElements.add(article);
    83468333}
    83478334
    83488335void Document::unregisterArticleElement(Element& article)
    83498336{
    8350     m_articleElements.remove(&article);
     8337    m_articleElements.remove(article);
    83518338    if (m_mainArticleElement == &article)
    83528339        m_mainArticleElement = nullptr;
     
    83688355    m_mainArticleElement = nullptr;
    83698356
    8370     auto numberOfArticles = m_articleElements.size();
     8357    auto numberOfArticles = m_articleElements.computeSize();
    83718358    if (!numberOfArticles || numberOfArticles > maxNumberOfArticlesBeforeIgnoringMainContentArticle)
    83728359        return;
    83738360
    8374     Element* tallestArticle = nullptr;
     8361    RefPtr<Element> tallestArticle;
    83758362    float tallestArticleHeight = 0;
    83768363    float tallestArticleWidth = 0;
    83778364    float secondTallestArticleHeight = 0;
    83788365
    8379     for (auto* article : m_articleElements) {
    8380         auto* box = article->renderBox();
     8366    for (auto& article : m_articleElements) {
     8367        auto* box = article.renderBox();
    83818368        float height = box ? box->height().toFloat() : 0;
    83828369        if (height >= tallestArticleHeight) {
     
    83848371            tallestArticleHeight = height;
    83858372            tallestArticleWidth = box ? box->width().toFloat() : 0;
    8386             tallestArticle = article;
     8373            tallestArticle = &article;
    83878374        } else if (height >= secondTallestArticleHeight)
    83888375            secondTallestArticleHeight = height;
     
    83908377
    83918378    if (numberOfArticles == 1) {
    8392         m_mainArticleElement = tallestArticle;
     8379        m_mainArticleElement = makeWeakPtr(tallestArticle.get());
    83938380        return;
    83948381    }
     
    84048391        return;
    84058392
    8406     m_mainArticleElement = tallestArticle;
     8393    m_mainArticleElement = makeWeakPtr(tallestArticle.get());
    84078394}
    84088395
     
    89588945    // would be nice if this could be enforced to remove the copyToVector.
    89598946
    8960     for (auto* canvas : copyToVector(m_canvasesNeedingDisplayPreparation)) {
     8947    auto canvases = copyToVectorOf<Ref<HTMLCanvasElement>>(m_canvasesNeedingDisplayPreparation);
     8948    m_canvasesNeedingDisplayPreparation.clear();
     8949    for (auto& canvas : canvases) {
    89618950        // However, if they are not in the document body, then they won't
    89628951        // be composited and thus don't need preparation. Unfortunately they
     
    89658954        if (!canvas->isInTreeScope())
    89668955            continue;
    8967 
    8968         auto protectedCanvas = makeRef(*canvas);
    8969         protectedCanvas->prepareForDisplay();
    8970     }
    8971     m_canvasesNeedingDisplayPreparation.clear();
    8972 }
    8973 
    8974 void Document::clearCanvasPreparation(HTMLCanvasElement* canvas)
     8956        canvas->prepareForDisplay();
     8957    }
     8958}
     8959
     8960void Document::clearCanvasPreparation(HTMLCanvasElement& canvas)
    89758961{
    89768962    m_canvasesNeedingDisplayPreparation.remove(canvas);
     
    89798965void Document::canvasChanged(CanvasBase& canvasBase, const Optional<FloatRect>&)
    89808966{
    8981     if (is<HTMLCanvasElement>(canvasBase)) {
    8982         auto* canvas = downcast<HTMLCanvasElement>(&canvasBase);
    8983         if (canvas->needsPreparationForDisplay())
    8984             m_canvasesNeedingDisplayPreparation.add(canvas);
    8985     }
     8967    if (!is<HTMLCanvasElement>(canvasBase))
     8968        return;
     8969    auto& canvas = downcast<HTMLCanvasElement>(canvasBase);
     8970    if (canvas.needsPreparationForDisplay())
     8971        m_canvasesNeedingDisplayPreparation.add(canvas);
    89868972}
    89878973
    89888974void Document::canvasDestroyed(CanvasBase& canvasBase)
    89898975{
    8990     if (is<HTMLCanvasElement>(canvasBase)) {
    8991         auto* canvas = downcast<HTMLCanvasElement>(&canvasBase);
    8992         m_canvasesNeedingDisplayPreparation.remove(canvas);
    8993     }
     8976    if (!is<HTMLCanvasElement>(canvasBase))
     8977        return;
     8978    auto& canvas = downcast<HTMLCanvasElement>(canvasBase);
     8979    m_canvasesNeedingDisplayPreparation.remove(canvas);
    89948980}
    89958981
  • trunk/Source/WebCore/dom/Document.h

    r276952 r277013  
    11511151    WEBCORE_EXPORT SVGDocumentExtensions& accessSVGExtensions();
    11521152
    1153     void addSVGUseElement(SVGUseElement&);
    1154     void removeSVGUseElement(SVGUseElement&);
    1155     HashSet<SVGUseElement*> const svgUseElements() const { return m_svgUseElements; }
    1156 
    11571153    void initSecurityContext();
    11581154    void initContentSecurityPolicy();
     
    16121608
    16131609    void prepareCanvasesForDisplayIfNeeded();
    1614     void clearCanvasPreparation(HTMLCanvasElement*);
     1610    void clearCanvasPreparation(HTMLCanvasElement&);
    16151611    void canvasChanged(CanvasBase&, const Optional<FloatRect>&) final;
    16161612    void canvasResized(CanvasBase&) final { };
     
    18601856
    18611857    std::unique_ptr<SVGDocumentExtensions> m_svgExtensions;
    1862     HashSet<SVGUseElement*> m_svgUseElements;
    18631858
    18641859    // Collection of canvas objects that need to do work after they've
    18651860    // rendered but before compositing, for the next frame. The set is
    18661861    // cleared after they've been called.
    1867     HashSet<HTMLCanvasElement*> m_canvasesNeedingDisplayPreparation;
     1862    WeakHashSet<HTMLCanvasElement> m_canvasesNeedingDisplayPreparation;
    18681863
    18691864#if ENABLE(DARK_MODE_CSS)
     
    18741869    HashMap<String, RefPtr<HTMLCanvasElement>> m_cssCanvasElements;
    18751870
    1876     HashSet<Element*> m_documentSuspensionCallbackElements;
     1871    WeakHashSet<Element> m_documentSuspensionCallbackElements;
    18771872
    18781873#if ENABLE(VIDEO)
     
    18851880#endif
    18861881
    1887     Element* m_mainArticleElement { nullptr };
    1888     HashSet<Element*> m_articleElements;
     1882    WeakPtr<Element> m_mainArticleElement;
     1883    WeakHashSet<Element> m_articleElements;
    18891884
    18901885    HashSet<VisibilityChangeClient*> m_visibilityStateCallbackClients;
     
    21322127
    21332128#if ENABLE(MEDIA_STREAM)
    2134     HashSet<HTMLMediaElement*> m_mediaStreamStateChangeElements;
    21352129    String m_idHashSalt;
    21362130    bool m_hasHadCaptureMediaStreamTrack { false };
  • trunk/Source/WebCore/html/HTMLCanvasElement.cpp

    r276999 r277013  
    156156    // avoided in destructors, but works as long as it's done before HTMLCanvasElement destructs completely.
    157157    notifyObserversCanvasDestroyed();
    158     document().clearCanvasPreparation(this);
     158    document().clearCanvasPreparation(*this);
    159159
    160160    m_context = nullptr; // Ensure this goes away before the ImageBuffer.
     
    10561056{
    10571057    if (needsPreparationForDisplay()) {
    1058         oldDocument.clearCanvasPreparation(this);
     1058        oldDocument.clearCanvasPreparation(*this);
    10591059        removeObserver(oldDocument);
    10601060        addObserver(newDocument);
     
    10811081{
    10821082    if (needsPreparationForDisplay() && removalType.disconnectedFromDocument) {
    1083         oldParentOfRemovedTree.document().clearCanvasPreparation(this);
     1083        oldParentOfRemovedTree.document().clearCanvasPreparation(*this);
    10841084        removeObserver(oldParentOfRemovedTree.document());
    10851085    }
  • trunk/Source/WebCore/style/StyleResolver.cpp

    r276588 r277013  
    131131{
    132132    if (m_document.svgExtensions()) {
    133         const HashSet<SVGFontFaceElement*>& svgFontFaceElements = m_document.svgExtensions()->svgFontFaceElements();
    134         for (auto* svgFontFaceElement : svgFontFaceElements)
    135             m_document.fontSelector().addFontFaceRule(svgFontFaceElement->fontFaceRule(), svgFontFaceElement->isInUserAgentShadowTree());
     133        auto& svgFontFaceElements = m_document.svgExtensions()->svgFontFaceElements();
     134        for (auto& svgFontFaceElement : svgFontFaceElements)
     135            m_document.fontSelector().addFontFaceRule(svgFontFaceElement.fontFaceRule(), svgFontFaceElement.isInUserAgentShadowTree());
    136136    }
    137137}
  • trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp

    r267497 r277013  
    3131#include "SMILTimeContainer.h"
    3232#include "SVGElement.h"
     33#include "SVGFontFaceElement.h"
    3334#include "SVGResourcesCache.h"
    3435#include "SVGSMILElement.h"
     
    4748}
    4849
    49 SVGDocumentExtensions::~SVGDocumentExtensions() = default;
     50SVGDocumentExtensions::~SVGDocumentExtensions()
     51{
     52    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_useElementsWithPendingShadowTreeUpdate.computesEmpty());
     53}
    5054
    5155void SVGDocumentExtensions::addTimeContainer(SVGSVGElement& element)
    5256{
    53     m_timeContainers.add(&element);
     57    m_timeContainers.add(element);
    5458    if (m_areAnimationsPaused)
    5559        element.pauseAnimations();
     
    5862void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement& element)
    5963{
    60     m_timeContainers.remove(&element);
     64    m_timeContainers.remove(element);
    6165}
    6266
     
    8589    return m_resources.get(id);
    8690}
     91
     92
     93void SVGDocumentExtensions::addUseElementWithPendingShadowTreeUpdate(SVGUseElement& element)
     94{
     95    auto result = m_useElementsWithPendingShadowTreeUpdate.add(element);
     96    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.isNewEntry);
     97}
     98
     99void SVGDocumentExtensions::removeUseElementWithPendingShadowTreeUpdate(SVGUseElement& element)
     100{
     101    m_useElementsWithPendingShadowTreeUpdate.remove(element);
     102    // FIXME: Assert that element was in m_svgUseElements once re-entrancy to update style and layout have been removed.
     103}
     104
    87105
    88106void SVGDocumentExtensions::startAnimations()
     
    92110    // FIXME: We hold a ref pointers to prevent a shadow tree from getting removed out from underneath us.
    93111    // In the future we should refactor the use-element to avoid this. See https://webkit.org/b/53704
    94     Vector<RefPtr<SVGSVGElement>> timeContainers;
    95     timeContainers.appendRange(m_timeContainers.begin(), m_timeContainers.end());
     112    auto timeContainers = copyToVectorOf<Ref<SVGSVGElement>>(m_timeContainers);
    96113    for (auto& element : timeContainers)
    97114        element->timeContainer().begin();
     
    101118{
    102119    for (auto& container : m_timeContainers)
    103         container->pauseAnimations();
     120        container.pauseAnimations();
    104121    m_areAnimationsPaused = true;
    105122}
     
    108125{
    109126    for (auto& container : m_timeContainers)
    110         container->unpauseAnimations();
     127        container.unpauseAnimations();
    111128    m_areAnimationsPaused = false;
    112129}
     
    114131void SVGDocumentExtensions::dispatchLoadEventToOutermostSVGElements()
    115132{
    116     Vector<RefPtr<SVGSVGElement>> timeContainers;
    117     timeContainers.appendRange(m_timeContainers.begin(), m_timeContainers.end());
    118 
     133    auto timeContainers = copyToVectorOf<Ref<SVGSVGElement>>(m_timeContainers);
    119134    for (auto& container : timeContainers) {
    120135        if (!container->isOutermostSVGSVGElement())
     
    303318void SVGDocumentExtensions::rebuildElements()
    304319{
    305     Vector<SVGElement*> shadowRebuildElements = WTFMove(m_rebuildElements);
    306     for (auto* element : shadowRebuildElements)
     320    auto shadowRebuildElements = std::exchange(m_rebuildElements, { });
     321    for (auto& element : shadowRebuildElements)
    307322        element->svgAttributeChanged(SVGNames::hrefAttr);
    308323}
     
    314329        return;
    315330    for (auto* element : *referencingElements) {
    316         m_rebuildElements.append(element);
     331        m_rebuildElements.append(*element);
    317332        element->callClearTarget();
    318333    }
     
    339354{
    340355    m_elementDependencies.remove(&referencedElement);
    341     m_rebuildElements.removeFirst(&referencedElement);
     356    m_rebuildElements.removeFirst(referencedElement);
    342357}
    343358
    344359void SVGDocumentExtensions::registerSVGFontFaceElement(SVGFontFaceElement& element)
    345360{
    346     m_svgFontFaceElements.add(&element);
     361    m_svgFontFaceElements.add(element);
    347362}
    348363
    349364void SVGDocumentExtensions::unregisterSVGFontFaceElement(SVGFontFaceElement& element)
    350365{
    351     ASSERT(m_svgFontFaceElements.contains(&element));
    352     m_svgFontFaceElements.remove(&element);
    353 }
    354 
    355 }
     366    ASSERT(m_svgFontFaceElements.contains(element));
     367    m_svgFontFaceElements.remove(element);
     368}
     369
     370}
  • trunk/Source/WebCore/svg/SVGDocumentExtensions.h

    r267497 r277013  
    5151    RenderSVGResourceContainer* resourceById(const AtomString& id) const;
    5252
     53    void addUseElementWithPendingShadowTreeUpdate(SVGUseElement&);
     54    void removeUseElementWithPendingShadowTreeUpdate(SVGUseElement&);
     55    const WeakHashSet<SVGUseElement>& useElementsWithPendingShadowTreeUpdate() const { return m_useElementsWithPendingShadowTreeUpdate; }
     56
    5357    void startAnimations();
    5458    void pauseAnimations();
     
    7175    void rebuildElements();
    7276
    73     const HashSet<SVGFontFaceElement*>& svgFontFaceElements() const { return m_svgFontFaceElements; }
     77    const WeakHashSet<SVGFontFaceElement>& svgFontFaceElements() const { return m_svgFontFaceElements; }
    7478    void registerSVGFontFaceElement(SVGFontFaceElement&);
    7579    void unregisterSVGFontFaceElement(SVGFontFaceElement&);
     
    7781private:
    7882    Document& m_document;
    79     HashSet<SVGSVGElement*> m_timeContainers; // For SVG 1.2 support this will need to be made more general.
    80     HashSet<SVGFontFaceElement*> m_svgFontFaceElements;
     83    WeakHashSet<SVGSVGElement> m_timeContainers; // For SVG 1.2 support this will need to be made more general.
     84    WeakHashSet<SVGFontFaceElement> m_svgFontFaceElements;
    8185    HashMap<AtomString, RenderSVGResourceContainer*> m_resources;
    8286    HashMap<AtomString, std::unique_ptr<PendingElements>> m_pendingResources; // Resources that are pending.
     
    8589    std::unique_ptr<SVGResourcesCache> m_resourcesCache;
    8690
    87     Vector<SVGElement*> m_rebuildElements;
     91    Vector<Ref<SVGElement>> m_rebuildElements;
     92    WeakHashSet<SVGUseElement> m_useElementsWithPendingShadowTreeUpdate;
    8893    bool m_areAnimationsPaused;
    8994
  • trunk/Source/WebCore/svg/SVGUseElement.cpp

    r275410 r277013  
    100100    if (insertionType.connectedToDocument) {
    101101        if (m_shadowTreeNeedsUpdate)
    102             document().addSVGUseElement(*this);
     102            document().accessSVGExtensions().addUseElementWithPendingShadowTreeUpdate(*this);
    103103        invalidateShadowTree();
    104104        // FIXME: Move back the call to updateExternalDocument() here once notifyFinished is made always async.
     
    119119    if (removalType.disconnectedFromDocument) {
    120120        if (m_shadowTreeNeedsUpdate)
    121             document().removeSVGUseElement(*this);
     121            document().accessSVGExtensions().removeUseElementWithPendingShadowTreeUpdate(*this);
    122122    }
    123123    SVGGraphicsElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
     
    226226    if (!isConnected())
    227227        return;
    228     document().removeSVGUseElement(*this);
     228    document().accessSVGExtensions().removeUseElementWithPendingShadowTreeUpdate(*this);
    229229
    230230    String targetID;
     
    530530    invalidateDependentShadowTrees();
    531531    if (isConnected())
    532         document().addSVGUseElement(*this);
     532        document().accessSVGExtensions().addUseElementWithPendingShadowTreeUpdate(*this);
    533533}
    534534
Note: See TracChangeset for help on using the changeset viewer.