From 892a166eea7bf5f6009ba6ee33d42718a8fdd337 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sat, 26 Jul 2008 02:26:58 +0200 Subject: [PATCH] Emulate window-object-cleared if it wasn't emitted --- midori/midori-webview.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/midori/midori-webview.c b/midori/midori-webview.c index a9d72403..3f1423d2 100644 --- a/midori/midori-webview.c +++ b/midori/midori-webview.c @@ -29,6 +29,7 @@ webkit_web_view_get_selected_text (WebKitWebView* web_view); struct _MidoriWebView { WebKitWebView parent_instance; + gboolean window_object_cleared; GdkPixbuf* icon; gchar* uri; @@ -268,6 +269,8 @@ static void webkit_web_view_load_started (MidoriWebView* web_view, WebKitWebFrame* web_frame) { + web_view->window_object_cleared = FALSE; + web_view->load_status = MIDORI_LOAD_PROVISIONAL; g_object_notify (G_OBJECT (web_view), "mload-status"); 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"); } +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) void loadable_icon_finish_cb (GdkPixbuf* icon, @@ -475,10 +487,21 @@ webkit_web_frame_load_done (WebKitWebFrame* web_frame, gboolean success, MidoriWebView* web_view) { + JSContextRef js_context; + JSValueRef js_window; GjsValue* value; GjsValue* document; 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); document = gjs_value_get_by_name (value, "document"); 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, "signal::load-started", webkit_web_view_load_started, NULL, + "signal::window-object-cleared", + webkit_web_view_window_object_cleared_cb, NULL, "signal::load-committed", webkit_web_view_load_committed, NULL, "signal::icon-ready",