Changeset 181631 in webkit


Ignore:
Timestamp:
Mar 17, 2015 4:10:13 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] WebKitDOM objects leaking
https://bugs.webkit.org/show_bug.cgi?id=118788

Reviewed by Darin Adler and Sergio Villar Senin.

Source/WebCore:

Use a DOMwindowObserver class, derived from DOMWindowProperty to
be notified when the window object is detached from the frame to
clear the DOM objects associated to that frame in that case too.

  • bindings/gobject/DOMObjectCache.cpp:

Tools:

Update DOMObjectCache unit test to check that DOM objects are also
released when new contents are loaded in the web view, and the old
document is detached from the frame.

  • TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp:

(testWebKitDOMObjectCache):

  • TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp:

(runTest):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181629 r181631  
     12015-03-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] WebKitDOM objects leaking
     4        https://bugs.webkit.org/show_bug.cgi?id=118788
     5
     6        Reviewed by Darin Adler and Sergio Villar Senin.
     7
     8        Use a DOMwindowObserver class, derived from DOMWindowProperty to
     9        be notified when the window object is detached from the frame to
     10        clear the DOM objects associated to that frame in that case too.
     11
     12        * bindings/gobject/DOMObjectCache.cpp:
     13
    1142015-03-17  Zan Dobersek  <zdobersek@igalia.com>
    215
  • trunk/Source/WebCore/bindings/gobject/DOMObjectCache.cpp

    r180216 r181631  
    2020#include "DOMObjectCache.h"
    2121
     22#include "DOMWindowProperty.h"
    2223#include "Document.h"
     24#include "Frame.h"
    2325#include "FrameDestructionObserver.h"
    2426#include "Node.h"
     
    9597        ASSERT(!m_objects.contains(&data));
    9698
     99        if (!m_domWindowObserver && m_frame->document()->domWindow())
     100            m_domWindowObserver = std::make_unique<DOMWindowObserver>(*m_frame, *this);
     101
    97102        m_objects.append(&data);
    98103        g_object_weak_ref(data.object, DOMObjectCacheFrameObserver::objectFinalizedCallback, this);
     
    100105
    101106private:
     107    class DOMWindowObserver final: public WebCore::DOMWindowProperty {
     108        WTF_MAKE_FAST_ALLOCATED;
     109    public:
     110        DOMWindowObserver(WebCore::Frame& frame, DOMObjectCacheFrameObserver& frameObserver)
     111            : DOMWindowProperty(&frame)
     112            , m_frameObserver(frameObserver)
     113        {
     114        }
     115
     116        virtual ~DOMWindowObserver()
     117        {
     118        }
     119
     120    private:
     121        virtual void willDetachGlobalObjectFromFrame() override
     122        {
     123            // Clear the DOMWindowProperty first, and then notify the Frame observer.
     124            DOMWindowProperty::willDetachGlobalObjectFromFrame();
     125            m_frameObserver.willDetachGlobalObjectFromFrame();
     126        }
     127
     128        DOMObjectCacheFrameObserver& m_frameObserver;
     129    };
     130
    102131    static void objectFinalizedCallback(gpointer userData, GObject* finalizedObject)
    103132    {
     
    133162    }
    134163
     164    void willDetachGlobalObjectFromFrame()
     165    {
     166        clear();
     167        m_domWindowObserver = nullptr;
     168    }
     169
    135170    Vector<DOMObjectCacheData*, 8> m_objects;
     171    std::unique_ptr<DOMWindowObserver> m_domWindowObserver;
    136172};
    137173
  • trunk/Tools/ChangeLog

    r181627 r181631  
     12015-03-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] WebKitDOM objects leaking
     4        https://bugs.webkit.org/show_bug.cgi?id=118788
     5
     6        Reviewed by Darin Adler and Sergio Villar Senin.
     7
     8        Update DOMObjectCache unit test to check that DOM objects are also
     9        released when new contents are loaded in the web view, and the old
     10        document is detached from the frame.
     11
     12        * TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp:
     13        (testWebKitDOMObjectCache):
     14        * TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp:
     15        (runTest):
     16
    1172015-03-17  Youenn Fablet  <youenn.fablet@crf.canon.fr>
    218
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp

    r180214 r181631  
    6363{
    6464    static const char* testHTML = "<html><body><div id='container'><p>DOM Cache test</p><a id='link href='#'>link</a></div></body></html>";
    65     test->loadHtml(testHTML, nullptr);
    66     test->waitUntilLoadFinished();
    6765
    68     g_assert(test->runWebProcessTest("WebKitDOMNode", "dom-cache"));
     66    // Run the test 3 times to make sure the DOM objects are correctly released when the
     67    // document is detached from the frame for every new document created.
     68    for (unsigned i = 0; i < 3; ++i) {
     69        test->loadHtml(testHTML, nullptr);
     70        test->waitUntilLoadFinished();
     71
     72        g_assert(test->runWebProcessTest("WebKitDOMNode", "dom-cache"));
     73    }
    6974}
    7075
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp

    r180211 r181631  
    6565    WebKitWebPage* webPage = WEBKIT_WEB_PAGE(JSObjectGetPrivate(thisObject));
    6666    g_assert(WEBKIT_IS_WEB_PAGE(webPage));
    67     WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
     67    // Test /WebKitDOMNode/dom-cache is an exception, because it's called 3 times, so
     68    // the WebPage is destroyed after the third time.
     69    if (g_str_equal(testPath.get(), "WebKitDOMNode/dom-cache")) {
     70        static unsigned domCacheTestRunCount = 0;
     71        if (++domCacheTestRunCount == 3)
     72            WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
     73    } else
     74        WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
    6875
    6976    std::unique_ptr<WebProcessTest> test = WebProcessTest::create(String::fromUTF8(testPath.get()));
Note: See TracChangeset for help on using the changeset viewer.