Skip to content
Permalink
Browse files
[GTK] Add GMainLoop and GMainContext to be handled by GRefPtr
https://bugs.webkit.org/show_bug.cgi?id=79496

Reviewed by Martin Robinson.

Source/JavaScriptCore:

Handle GMainLoop and GMainContext in GRefPtr, by calling
g_main_loop_(un)ref and g_main_context_(un)ref in the
implementation of the refGPtr and derefGPtr template functions.

* wtf/gobject/GRefPtr.cpp:
(WTF::refGPtr):
(WTF):
(WTF::derefGPtr):
* wtf/gobject/GRefPtr.h:
(WTF):
* wtf/gobject/GTypedefs.h:

Source/WebCore:

Updated places where raw pointers to GMainLoop and GMainContext
were being used, replacing them with GRefPtr-based code.

* platform/RunLoop.h:
(RunLoop):
* platform/gtk/RunLoopGtk.cpp:
(WebCore::RunLoop::RunLoop):
(WebCore::RunLoop::~RunLoop):
(WebCore::RunLoop::mainLoop):
(WebCore::RunLoop::stop):
(WebCore::RunLoop::wakeUp):
(WebCore::RunLoop::TimerBase::start):
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::~WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::didFinishLoading):
(WebCore::WebCoreSynchronousLoader::run):

Source/WebKit2:

Updated places where raw pointers to GMainLoop and GMainContext
were being used, replacing them with GRefPtr-based code.

* Platform/WorkQueue.h:
(WorkQueue):
* Platform/gtk/WorkQueueGtk.cpp:
(WorkQueue::platformInitialize):
(WorkQueue::platformInvalidate):
(WorkQueue::workQueueThreadBody):
(WorkQueue::registerEventSourceHandler):
(WorkQueue::dispatchOnSource):
* UIProcess/gtk/WebPopupMenuProxyGtk.cpp:
(WebKit::WebPopupMenuProxyGtk::WebPopupMenuProxyGtk):
(WebKit::WebPopupMenuProxyGtk::showPopupMenu):
(WebKit::WebPopupMenuProxyGtk::shutdownRunLoop):
* UIProcess/gtk/WebPopupMenuProxyGtk.h:
(WebPopupMenuProxyGtk):

Canonical link: https://commits.webkit.org/96889@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@109129 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
mariospr committed Feb 28, 2012
1 parent 89e1b2d commit 5b3a7188f127c15a339ef1a89608623d209b88de
@@ -1,3 +1,22 @@
2012-02-28 Mario Sanchez Prada <msanchez@igalia.com>

[GTK] Add GMainLoop and GMainContext to be handled by GRefPtr
https://bugs.webkit.org/show_bug.cgi?id=79496

Reviewed by Martin Robinson.

Handle GMainLoop and GMainContext in GRefPtr, by calling
g_main_loop_(un)ref and g_main_context_(un)ref in the
implementation of the refGPtr and derefGPtr template functions.

* wtf/gobject/GRefPtr.cpp:
(WTF::refGPtr):
(WTF):
(WTF::derefGPtr):
* wtf/gobject/GRefPtr.h:
(WTF):
* wtf/gobject/GTypedefs.h:

2012-02-28 Yong Li <yoli@rim.com>

JSString::resolveRope() should report extra memory cost to the heap.
@@ -37,6 +37,32 @@ template <> void derefGPtr(GHashTable* ptr)
g_hash_table_unref(ptr);
}

template <> GMainContext* refGPtr(GMainContext* ptr)
{
if (ptr)
g_main_context_ref(ptr);
return ptr;
}

template <> void derefGPtr(GMainContext* ptr)
{
if (ptr)
g_main_context_unref(ptr);
}

template <> GMainLoop* refGPtr(GMainLoop* ptr)
{
if (ptr)
g_main_loop_ref(ptr);
return ptr;
}

template <> void derefGPtr(GMainLoop* ptr)
{
if (ptr)
g_main_loop_unref(ptr);
}

#if GLIB_CHECK_VERSION(2, 24, 0)
template <> GVariant* refGPtr(GVariant* ptr)
{
@@ -201,6 +201,10 @@ template <typename T> GRefPtr<T> adoptGRef(T* p)

template <> GHashTable* refGPtr(GHashTable* ptr);
template <> void derefGPtr(GHashTable* ptr);
template <> GMainContext* refGPtr(GMainContext* ptr);
template <> void derefGPtr(GMainContext* ptr);
template <> GMainLoop* refGPtr(GMainLoop* ptr);
template <> void derefGPtr(GMainLoop* ptr);
template <> GVariant* refGPtr(GVariant* ptr);
template <> void derefGPtr(GVariant* ptr);
template <> GSource* refGPtr(GSource* ptr);
@@ -51,6 +51,8 @@ typedef struct _GFile GFile;
typedef struct _GHashTable GHashTable;
typedef struct _GInputStream GInputStream;
typedef struct _GList GList;
typedef struct _GMainContext GMainContext;
typedef struct _GMainLoop GMainLoop;
typedef struct _GPatternSpec GPatternSpec;
typedef struct _GPollableOutputStream GPollableOutputStream;
typedef struct _GSList GSList;
@@ -1,3 +1,29 @@
2012-02-28 Mario Sanchez Prada <msanchez@igalia.com>

[GTK] Add GMainLoop and GMainContext to be handled by GRefPtr
https://bugs.webkit.org/show_bug.cgi?id=79496

Reviewed by Martin Robinson.

Updated places where raw pointers to GMainLoop and GMainContext
were being used, replacing them with GRefPtr-based code.

* platform/RunLoop.h:
(RunLoop):
* platform/gtk/RunLoopGtk.cpp:
(WebCore::RunLoop::RunLoop):
(WebCore::RunLoop::~RunLoop):
(WebCore::RunLoop::mainLoop):
(WebCore::RunLoop::stop):
(WebCore::RunLoop::wakeUp):
(WebCore::RunLoop::TimerBase::start):
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::~WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::didFinishLoading):
(WebCore::WebCoreSynchronousLoader::run):

2012-02-28 Alok Priyadarshi <alokp@chromium.org>

Heap-use-after-free in WebCore::RenderLayer::addChild
@@ -37,10 +37,6 @@

#if PLATFORM(GTK)
#include <wtf/gobject/GRefPtr.h>
typedef struct _GSource GSource;
typedef struct _GMainLoop GMainLoop;
typedef struct _GMainContext GMainContext;
typedef int gboolean;
#endif

namespace WebCore {
@@ -157,8 +153,8 @@ class RunLoop {
static gboolean queueWork(RunLoop*);
GMainLoop* mainLoop();
private:
GMainContext* m_runLoopContext;
GMainLoop* m_runLoopMain;
GRefPtr<GMainContext> m_runLoopContext;
GRefPtr<GMainLoop> m_runLoopMain;
#endif
};

@@ -33,22 +33,17 @@ namespace WebCore {

RunLoop::RunLoop()
{
// g_main_context_default() doesn't add an extra reference.
m_runLoopContext = g_main_context_default();
ASSERT(m_runLoopContext);
m_runLoopMain = g_main_loop_new(m_runLoopContext, FALSE);
m_runLoopMain = adoptGRef(g_main_loop_new(m_runLoopContext.get(), FALSE));
ASSERT(m_runLoopMain);
}

RunLoop::~RunLoop()
{
if (m_runLoopMain) {
if (g_main_loop_is_running(m_runLoopMain))
g_main_loop_quit(m_runLoopMain);
g_main_loop_unref(m_runLoopMain);
}

if (m_runLoopContext)
g_main_context_unref(m_runLoopContext);
if (m_runLoopMain && g_main_loop_is_running(m_runLoopMain.get()))
g_main_loop_quit(m_runLoopMain.get());
}

void RunLoop::run()
@@ -58,12 +53,12 @@ void RunLoop::run()

GMainLoop* RunLoop::mainLoop()
{
return m_runLoopMain;
return m_runLoopMain.get();
}

void RunLoop::stop()
{
g_main_loop_quit(m_runLoopMain);
g_main_loop_quit(m_runLoopMain.get());
}

gboolean RunLoop::queueWork(RunLoop* runLoop)
@@ -77,9 +72,9 @@ void RunLoop::wakeUp()
GRefPtr<GSource> source = adoptGRef(g_idle_source_new());
g_source_set_priority(source.get(), G_PRIORITY_DEFAULT);
g_source_set_callback(source.get(), reinterpret_cast<GSourceFunc>(&RunLoop::queueWork), this, 0);
g_source_attach(source.get(), m_runLoopContext);
g_source_attach(source.get(), m_runLoopContext.get());

g_main_context_wakeup(m_runLoopContext);
g_main_context_wakeup(m_runLoopContext.get());
}

RunLoop::TimerBase::TimerBase(RunLoop* runLoop)
@@ -117,7 +112,7 @@ void RunLoop::TimerBase::start(double fireInterval, bool repeat)
m_timerSource = adoptGRef(g_timeout_source_new(static_cast<guint>(fireInterval * 1000)));
m_isRepeating = repeat;
g_source_set_callback(m_timerSource.get(), reinterpret_cast<GSourceFunc>(&RunLoop::TimerBase::timerFiredCallback), this, 0);
g_source_attach(m_timerSource.get(), m_runLoop->m_runLoopContext);
g_source_attach(m_timerSource.get(), m_runLoop->m_runLoopContext.get());
}

void RunLoop::TimerBase::stop()
@@ -56,6 +56,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <wtf/gobject/GRefPtr.h>
#include <wtf/text/CString.h>

#if ENABLE(BLOB)
@@ -86,7 +87,7 @@ class WebCoreSynchronousLoader : public ResourceHandleClient {
ResourceResponse& m_response;
Vector<char>& m_data;
bool m_finished;
GMainLoop* m_mainLoop;
GRefPtr<GMainLoop> m_mainLoop;
};

WebCoreSynchronousLoader::WebCoreSynchronousLoader(ResourceError& error, ResourceResponse& response, Vector<char>& data)
@@ -95,12 +96,11 @@ WebCoreSynchronousLoader::WebCoreSynchronousLoader(ResourceError& error, Resourc
, m_data(data)
, m_finished(false)
{
m_mainLoop = g_main_loop_new(0, false);
m_mainLoop = adoptGRef(g_main_loop_new(0, false));
}

WebCoreSynchronousLoader::~WebCoreSynchronousLoader()
{
g_main_loop_unref(m_mainLoop);
}

void WebCoreSynchronousLoader::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
@@ -115,7 +115,7 @@ void WebCoreSynchronousLoader::didReceiveData(ResourceHandle*, const char* data,

void WebCoreSynchronousLoader::didFinishLoading(ResourceHandle*, double)
{
g_main_loop_quit(m_mainLoop);
g_main_loop_quit(m_mainLoop.get());
m_finished = true;
}

@@ -128,7 +128,7 @@ void WebCoreSynchronousLoader::didFail(ResourceHandle* handle, const ResourceErr
void WebCoreSynchronousLoader::run()
{
if (!m_finished)
g_main_loop_run(m_mainLoop);
g_main_loop_run(m_mainLoop.get());
}

static void cleanupSoupRequestOperation(ResourceHandle*, bool isDestroying);
@@ -1,3 +1,28 @@
2012-02-28 Mario Sanchez Prada <msanchez@igalia.com>

[GTK] Add GMainLoop and GMainContext to be handled by GRefPtr
https://bugs.webkit.org/show_bug.cgi?id=79496

Reviewed by Martin Robinson.

Updated places where raw pointers to GMainLoop and GMainContext
were being used, replacing them with GRefPtr-based code.

* Platform/WorkQueue.h:
(WorkQueue):
* Platform/gtk/WorkQueueGtk.cpp:
(WorkQueue::platformInitialize):
(WorkQueue::platformInvalidate):
(WorkQueue::workQueueThreadBody):
(WorkQueue::registerEventSourceHandler):
(WorkQueue::dispatchOnSource):
* UIProcess/gtk/WebPopupMenuProxyGtk.cpp:
(WebKit::WebPopupMenuProxyGtk::WebPopupMenuProxyGtk):
(WebKit::WebPopupMenuProxyGtk::showPopupMenu):
(WebKit::WebPopupMenuProxyGtk::shutdownRunLoop):
* UIProcess/gtk/WebPopupMenuProxyGtk.h:
(WebPopupMenuProxyGtk):

2012-02-28 Jocelyn Turcotte <jocelyn.turcotte@nokia.com>

[Qt] Initialize QtWebContext as much as we can in its constructor.
@@ -48,8 +48,7 @@ class QObject;
class QThread;
#elif PLATFORM(GTK)
#include "PlatformProcessIdentifier.h"
typedef struct _GMainContext GMainContext;
typedef struct _GMainLoop GMainLoop;
#include <wtf/gobject/GRefPtr.h>
typedef gboolean (*GSourceFunc) (gpointer data);
#endif

@@ -171,9 +170,9 @@ class WorkQueue {
void dispatchOnSource(GSource*, const Function<void()>&, GSourceFunc);

ThreadIdentifier m_workQueueThread;
GMainContext* m_eventContext;
GRefPtr<GMainContext> m_eventContext;
Mutex m_eventLoopLock;
GMainLoop* m_eventLoop;
GRefPtr<GMainLoop> m_eventLoop;
Mutex m_eventSourcesLock;
class EventSource;
HashMap<int, Vector<EventSource*> > m_eventSources;
@@ -103,9 +103,9 @@ static const size_t kVisualStudioThreadNameLimit = 31;

void WorkQueue::platformInitialize(const char* name)
{
m_eventContext = g_main_context_new();
m_eventContext = adoptGRef(g_main_context_new());
ASSERT(m_eventContext);
m_eventLoop = g_main_loop_new(m_eventContext, FALSE);
m_eventLoop = adoptGRef(g_main_loop_new(m_eventContext.get(), FALSE));
ASSERT(m_eventLoop);

// This name can be com.apple.WebKit.ProcessLauncher or com.apple.CoreIPC.ReceiveQueue.
@@ -129,17 +129,12 @@ void WorkQueue::platformInvalidate()
MutexLocker locker(m_eventLoopLock);

if (m_eventLoop) {
if (g_main_loop_is_running(m_eventLoop))
g_main_loop_quit(m_eventLoop);

g_main_loop_unref(m_eventLoop);
m_eventLoop = 0;
if (g_main_loop_is_running(m_eventLoop.get()))
g_main_loop_quit(m_eventLoop.get());
m_eventLoop.clear();
}

if (m_eventContext) {
g_main_context_unref(m_eventContext);
m_eventContext = 0;
}
m_eventContext.clear();
}

void WorkQueue::startWorkQueueThread(WorkQueue* workQueue)
@@ -149,7 +144,7 @@ void WorkQueue::startWorkQueueThread(WorkQueue* workQueue)

void WorkQueue::workQueueThreadBody()
{
g_main_loop_run(m_eventLoop);
g_main_loop_run(m_eventLoop.get());
}

void WorkQueue::registerEventSourceHandler(int fileDescriptor, int condition, const Function<void()>& function)
@@ -177,7 +172,7 @@ void WorkQueue::registerEventSourceHandler(int fileDescriptor, int condition, co
m_eventSources.set(fileDescriptor, sources);
}

g_source_attach(dispatchSource.get(), m_eventContext);
g_source_attach(dispatchSource.get(), m_eventContext.get());
}

void WorkQueue::unregisterEventSourceHandler(int fileDescriptor)
@@ -206,7 +201,7 @@ void WorkQueue::dispatchOnSource(GSource* dispatchSource, const Function<void()>
g_source_set_callback(dispatchSource, sourceCallback, eventSource,
reinterpret_cast<GDestroyNotify>(&WorkQueue::EventSource::deleteEventSource));

g_source_attach(dispatchSource, m_eventContext);
g_source_attach(dispatchSource, m_eventContext.get());
}

void WorkQueue::dispatch(const Function<void()>& function)
@@ -41,7 +41,6 @@ WebPopupMenuProxyGtk::WebPopupMenuProxyGtk(GtkWidget* webView, WebPopupMenuProxy
: WebPopupMenuProxy(client)
, m_webView(webView)
, m_activeItem(-1)
, m_runLoop(0)
{
}

@@ -96,14 +95,13 @@ void WebPopupMenuProxyGtk::showPopupMenu(const IntRect& rect, TextDirection text

// WebPageProxy expects the menu to run in a nested run loop, since it invalidates the
// menu right after calling WebPopupMenuProxy::showPopupMenu().
m_runLoop = g_main_loop_new(0, FALSE);
m_runLoop = adoptGRef(g_main_loop_new(0, FALSE));

GDK_THREADS_LEAVE();
g_main_loop_run(m_runLoop);
g_main_loop_run(m_runLoop.get());
GDK_THREADS_ENTER();

g_main_loop_unref(m_runLoop);
m_runLoop = 0;
m_runLoop.clear();

g_signal_handler_disconnect(m_popup->platformMenu(), unmapHandler);

@@ -120,8 +118,8 @@ void WebPopupMenuProxyGtk::hidePopupMenu()

void WebPopupMenuProxyGtk::shutdownRunLoop()
{
if (g_main_loop_is_running(m_runLoop))
g_main_loop_quit(m_runLoop);
if (g_main_loop_is_running(m_runLoop.get()))
g_main_loop_quit(m_runLoop.get());
}

void WebPopupMenuProxyGtk::menuItemActivated(GtkAction* action, WebPopupMenuProxyGtk* popupMenu)

0 comments on commit 5b3a718

Please sign in to comment.