[webkit-gtk] Unexpected behaviour of webkit_web_view_set_settings
Gavin Lambert
gavinl at compacsort.com
Tue Apr 19 20:36:50 PDT 2011
Quoth myself:
> Ah! Ok, I found the problem. m_web was a member variable of my main
> window class, which was a member variable of the application class,
> which led to it being created before WebKit::init() was called. I've
> moved the WebKit::init() call so it gets called before the application
> class gets constructed, and now get_settings() is giving me a non-null
> settings object.
Then again, I may have spoken too soon :)
m_web.get_settings() now returns a valid object to me, but there's still
something odd going on with its refcount.
In particular, this code will still trigger a SIGSEGV, because the second
call to get_settings() returns a deleted object:
m_web.get_settings()->get_property("user-agent", /*out*/
m_defaultUserAgent);
m_web.get_settings()->set_property("user-agent", "Test/1.0 " +
m_defaultUserAgent);
This particular disconnect is I think coming from the (admittedly hinted at
in the docs) behaviour that webkit_web_view_get_settings doesn't increment
the refcount of the object it returns, but webkitmm is just using
boilerplate gtkmmproc code, which seems to assume that it does. (I'm not
sure which side is in the "wrong" here [webkit or webkitmm], or whether that
affects webkit_web_view_get_property or not [since I *presume* that would be
required to increment the refcount].)
I can mitigate this by ensuring I explicitly call reference() after every
get_settings() call, but that kinda defeats the point of trying to use smart
pointers in the first place. :)
Glib::RefPtr<WebKit::WebSettings> settings = m_web.get_settings();
settings->reference(); // because it "forgets" to do this internally
settings->get_property("user-agent", /*out*/ m_defaultUserAgent);
settings->set_property("user-agent", "Test/1.0 " + m_defaultUserAgent);
More information about the webkit-gtk
mailing list