Changeset 180211 in webkit
- Timestamp:
- Feb 16, 2015 11:34:29 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r180210 r180211 1 2015-02-16 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] WebKitFrame objects are never released 4 https://bugs.webkit.org/show_bug.cgi?id=141641 5 6 Reviewed by Martin Robinson. 7 8 Use a FrameDestructionObserver derived class to wrap our 9 WebKitFrame objects and delete them when the frame is destroyed, 10 instead of using willDestroyFrame callback of WKBundlePageLoaderClient 11 that has never worked. 12 13 * WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp: 14 (webkitFrameGetWebFrame): 15 * WebProcess/InjectedBundle/API/gtk/WebKitFramePrivate.h: 16 * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp: 17 (webkitFrameGetOrCreate): 18 (webkitFrameDestroy): 19 (webkitWebPageCreate): 20 (willDestroyFrame): Deleted. 21 1 22 2015-02-16 Tim Horton <timothy_horton@apple.com> 2 23 -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFrame.cpp
r165760 r180211 46 46 frame->priv->webFrame = webFrame; 47 47 return frame; 48 } 49 50 WebFrame* webkitFrameGetWebFrame(WebKitFrame* frame) 51 { 52 return frame->priv->webFrame.get(); 48 53 } 49 54 -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitFramePrivate.h
r154540 r180211 25 25 26 26 WebKitFrame* webkitFrameCreate(WebKit::WebFrame*); 27 WebKit::WebFrame* webkitFrameGetWebFrame(WebKitFrame*); 27 28 28 29 #endif // WebKitFramePrivate_h -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
r179409 r180211 43 43 #include <WebCore/DocumentLoader.h> 44 44 #include <WebCore/Frame.h> 45 #include <WebCore/FrameDestructionObserver.h> 45 46 #include <WebCore/FrameView.h> 46 47 #include <WebCore/MainFrame.h> … … 76 77 WEBKIT_DEFINE_TYPE(WebKitWebPage, webkit_web_page, G_TYPE_OBJECT) 77 78 78 typedef HashMap<WebFrame*, GRefPtr<WebKitFrame>> WebFrameMap; 79 static void webFrameDestroyed(WebFrame*); 80 81 class WebKitFrameWrapper final: public FrameDestructionObserver { 82 public: 83 WebKitFrameWrapper(WebFrame& webFrame) 84 : FrameDestructionObserver(webFrame.coreFrame()) 85 , m_webkitFrame(adoptGRef(webkitFrameCreate(&webFrame))) 86 { 87 } 88 89 WebKitFrame* webkitFrame() const { return m_webkitFrame.get(); } 90 91 private: 92 virtual void frameDestroyed() override 93 { 94 FrameDestructionObserver::frameDestroyed(); 95 webFrameDestroyed(webkitFrameGetWebFrame(m_webkitFrame.get())); 96 } 97 98 GRefPtr<WebKitFrame> m_webkitFrame; 99 }; 100 101 typedef HashMap<WebFrame*, std::unique_ptr<WebKitFrameWrapper>> WebFrameMap; 79 102 80 103 static WebFrameMap& webFrameMap() … … 86 109 static WebKitFrame* webkitFrameGetOrCreate(WebFrame* webFrame) 87 110 { 88 GRefPtr<WebKitFrame> frame = webFrameMap().get(webFrame); 89 if (frame) 90 return frame.get(); 91 92 frame = adoptGRef(webkitFrameCreate(webFrame)); 93 webFrameMap().set(webFrame, frame); 94 95 return frame.get(); 111 auto wrapperPtr = webFrameMap().get(webFrame); 112 if (wrapperPtr) 113 return wrapperPtr->webkitFrame(); 114 115 std::unique_ptr<WebKitFrameWrapper> wrapper = std::make_unique<WebKitFrameWrapper>(*webFrame); 116 wrapperPtr = wrapper.get(); 117 webFrameMap().set(webFrame, WTF::move(wrapper)); 118 return wrapperPtr->webkitFrame(); 119 } 120 121 static void webFrameDestroyed(WebFrame* webFrame) 122 { 123 webFrameMap().remove(webFrame); 96 124 } 97 125 … … 144 172 145 173 g_signal_emit(WEBKIT_WEB_PAGE(clientInfo), signals[DOCUMENT_LOADED], 0); 146 }147 148 static void willDestroyFrame(WKBundlePageRef, WKBundleFrameRef frame, const void* /* clientInfo */)149 {150 webFrameMap().remove(toImpl(frame));151 174 } 152 175 … … 393 416 0, // didFirstLayoutForFrame 394 417 0, // didFirstVisuallyNonEmptyLayoutForFrame 395 0, // didRemoveFrameFromHierarchy 418 0, // didRemoveFrameFromHierarchy, 396 419 0, // didDisplayInsecureContentForFrame 397 420 0, // didRunInsecureContentForFrame … … 416 439 0, // willLoadURLRequest 417 440 0, // willLoadDataRequest 418 willDestroyFrame441 0, // willDestroyFrame 419 442 }; 420 443 WKBundlePageSetPageLoaderClient(toAPI(webPage), &loaderClient.base); -
trunk/Tools/ChangeLog
r180164 r180211 1 2015-02-16 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] WebKitFrame objects are never released 4 https://bugs.webkit.org/show_bug.cgi?id=141641 5 6 Reviewed by Martin Robinson. 7 8 Add a way to check GObjects leaks for WebProcess tests and check 9 WebKitFrame objects are not leaked. 10 11 * TestWebKitAPI/Tests/WebKit2Gtk/FrameTest.cpp: 12 (WebKitFrameTest::testMainFrame): 13 (WebKitFrameTest::testURI): 14 (WebKitFrameTest::testJavaScriptContext): 15 * TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp: 16 (WebProcessTest::assertObjectIsDeletedWhenTestFinishes): 17 (runTest): 18 * TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.h: 19 1 20 2015-02-16 Tim Horton <timothy_horton@apple.com> 2 21 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/FrameTest.cpp
r176563 r180211 33 33 WebKitFrame* frame = webkit_web_page_get_main_frame(page); 34 34 g_assert(WEBKIT_IS_FRAME(frame)); 35 assertObjectIsDeletedWhenTestFinishes(G_OBJECT(frame)); 35 36 g_assert(webkit_frame_is_main_frame(frame)); 36 37 … … 42 43 WebKitFrame* frame = webkit_web_page_get_main_frame(page); 43 44 g_assert(WEBKIT_IS_FRAME(frame)); 45 assertObjectIsDeletedWhenTestFinishes(G_OBJECT(frame)); 44 46 g_assert_cmpstr(webkit_web_page_get_uri(page), ==, webkit_frame_get_uri(frame)); 45 47 … … 51 53 WebKitFrame* frame = webkit_web_page_get_main_frame(page); 52 54 g_assert(WEBKIT_IS_FRAME(frame)); 55 assertObjectIsDeletedWhenTestFinishes(G_OBJECT(frame)); 53 56 g_assert(webkit_frame_get_javascript_global_context(frame)); 54 57 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp
r176563 r180211 23 23 #include <JavaScriptCore/JSRetainPtr.h> 24 24 #include <gio/gio.h> 25 #include <wtf/HashSet.h> 25 26 #include <wtf/NeverDestroyed.h> 26 27 #include <wtf/gobject/GUniquePtr.h> 28 29 static HashSet<GObject*> s_watchedObjects; 27 30 28 31 typedef HashMap<String, std::function<std::unique_ptr<WebProcessTest> ()>> TestsMap; … … 36 39 { 37 40 testsMap().add(testName, WTF::move(closure)); 41 } 42 43 void WebProcessTest::assertObjectIsDeletedWhenTestFinishes(GObject* object) 44 { 45 s_watchedObjects.add(object); 46 g_object_weak_ref(object, [](gpointer, GObject* finalizedObject) { 47 s_watchedObjects.remove(finalizedObject); 48 }, nullptr); 38 49 } 39 50 … … 54 65 WebKitWebPage* webPage = WEBKIT_WEB_PAGE(JSObjectGetPrivate(thisObject)); 55 66 g_assert(WEBKIT_IS_WEB_PAGE(webPage)); 67 WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage)); 56 68 57 69 std::unique_ptr<WebProcessTest> test = WebProcessTest::create(String::fromUTF8(testPath.get())); … … 68 80 { 69 81 g_object_unref(JSObjectGetPrivate(object)); 82 83 if (s_watchedObjects.isEmpty()) 84 return; 85 86 g_print("Leaked objects in WebProcess:"); 87 for (const auto object : s_watchedObjects) 88 g_print(" %s(%p)", g_type_name_from_instance(reinterpret_cast<GTypeInstance*>(object)), object); 89 g_print("\n"); 90 91 g_assert(s_watchedObjects.isEmpty()); 70 92 } 71 93 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.h
r176563 r180211 29 29 virtual bool runTest(const char* testName, WebKitWebPage*) = 0; 30 30 31 static void assertObjectIsDeletedWhenTestFinishes(GObject*); 32 31 33 static void add(const String& testName, std::function<std::unique_ptr<WebProcessTest> ()>); 32 34 static std::unique_ptr<WebProcessTest> create(const String& testName);
Note: See TracChangeset
for help on using the changeset viewer.