Emulate window-object-cleared if it wasn't emitted

This commit is contained in:
Christian Dywan 2008-07-26 02:26:58 +02:00
parent 549310a7cd
commit 892a166eea

View file

@ -29,6 +29,7 @@ webkit_web_view_get_selected_text (WebKitWebView* web_view);
struct _MidoriWebView struct _MidoriWebView
{ {
WebKitWebView parent_instance; WebKitWebView parent_instance;
gboolean window_object_cleared;
GdkPixbuf* icon; GdkPixbuf* icon;
gchar* uri; gchar* uri;
@ -268,6 +269,8 @@ static void
webkit_web_view_load_started (MidoriWebView* web_view, webkit_web_view_load_started (MidoriWebView* web_view,
WebKitWebFrame* web_frame) WebKitWebFrame* web_frame)
{ {
web_view->window_object_cleared = FALSE;
web_view->load_status = MIDORI_LOAD_PROVISIONAL; web_view->load_status = MIDORI_LOAD_PROVISIONAL;
g_object_notify (G_OBJECT (web_view), "mload-status"); g_object_notify (G_OBJECT (web_view), "mload-status");
if (web_view->tab_icon) if (web_view->tab_icon)
@ -277,6 +280,15 @@ webkit_web_view_load_started (MidoriWebView* web_view,
g_object_notify (G_OBJECT (web_view), "progress"); g_object_notify (G_OBJECT (web_view), "progress");
} }
static void
webkit_web_view_window_object_cleared_cb (MidoriWebView* web_view,
WebKitWebFrame* web_frame,
JSGlobalContextRef js_context,
JSObjectRef js_window)
{
web_view->window_object_cleared = TRUE;
}
#if GLIB_CHECK_VERSION (2, 16, 0) #if GLIB_CHECK_VERSION (2, 16, 0)
void void
loadable_icon_finish_cb (GdkPixbuf* icon, loadable_icon_finish_cb (GdkPixbuf* icon,
@ -475,10 +487,21 @@ webkit_web_frame_load_done (WebKitWebFrame* web_frame,
gboolean success, gboolean success,
MidoriWebView* web_view) MidoriWebView* web_view)
{ {
JSContextRef js_context;
JSValueRef js_window;
GjsValue* value; GjsValue* value;
GjsValue* document; GjsValue* document;
GjsValue* links; GjsValue* links;
/* If WebKit didn't emit the signal due to a bug, we will */
if (!web_view->window_object_cleared)
{
js_context = webkit_web_frame_get_global_context (web_frame);
js_window = JSContextGetGlobalObject (js_context);
g_signal_emit_by_name (web_view, "window-object-cleared",
web_frame, js_context, js_window);
}
value = gjs_value_new (webkit_web_frame_get_global_context (web_frame), NULL); value = gjs_value_new (webkit_web_frame_get_global_context (web_frame), NULL);
document = gjs_value_get_by_name (value, "document"); document = gjs_value_get_by_name (value, "document");
links = gjs_value_get_elements_by_tag_name (document, "link"); links = gjs_value_get_elements_by_tag_name (document, "link");
@ -717,6 +740,8 @@ midori_web_view_init (MidoriWebView* web_view)
g_object_connect (web_view, g_object_connect (web_view,
"signal::load-started", "signal::load-started",
webkit_web_view_load_started, NULL, webkit_web_view_load_started, NULL,
"signal::window-object-cleared",
webkit_web_view_window_object_cleared_cb, NULL,
"signal::load-committed", "signal::load-committed",
webkit_web_view_load_committed, NULL, webkit_web_view_load_committed, NULL,
"signal::icon-ready", "signal::icon-ready",