/pidgin/main: f3236514cb26: Queue HTML appends to a GtkWebView.
Elliott Sales de Andrade
qulogic at pidgin.im
Tue Jul 24 04:03:44 EDT 2012
Changeset: f3236514cb2604af1f9c33556f84c8b80e8c1876
Author: Elliott Sales de Andrade <qulogic at pidgin.im>
Date: 2012-07-23 00:04 -0400
Branch: default
URL: http://hg.pidgin.im/pidgin/main/rev/f3236514cb26
Description:
Queue HTML appends to a GtkWebView.
In fast-appending cases like the Debug Window, appends occurring before
the wrapping HTML is loaded will get applied to whatever appeared before,
and would disappear once the wrapper is loaded.
diffstat:
pidgin/gtkwebview.c | 39 ++++++++++++++++++++++++++++++++-------
1 files changed, 32 insertions(+), 7 deletions(-)
diffs (81 lines):
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -55,7 +55,8 @@
typedef struct _GtkWebViewPriv {
gboolean empty; /**< whether anything has been appended **/
- /* JS execute queue */
+ /* Processing queues */
+ GQueue *html_queue;
GQueue *js_queue;
gboolean is_loading;
@@ -141,6 +142,29 @@
return TRUE; /* there may be more for now */
}
+static gboolean
+process_html_queue(GtkWebView *webview)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ char *html;
+ WebKitDOMDocument *doc;
+ WebKitDOMHTMLElement *body;
+
+ if (priv->is_loading)
+ return FALSE;
+ if (!priv->html_queue || g_queue_is_empty(priv->html_queue))
+ return FALSE;
+
+ html = g_queue_pop_head(priv->html_queue);
+ doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
+ body = webkit_dom_document_get_body(doc);
+ webkit_dom_html_element_insert_adjacent_html(body, "beforeend", html, NULL);
+ g_free(html);
+ priv->empty = FALSE;
+
+ return TRUE;
+}
+
static void
webview_load_started(WebKitWebView *webview, WebKitWebFrame *frame,
gpointer userdata)
@@ -383,6 +407,10 @@
GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
gpointer temp;
+ while ((temp = g_queue_pop_head(priv->html_queue)))
+ g_free(temp);
+ g_queue_free(priv->html_queue);
+
while ((temp = g_queue_pop_head(priv->js_queue)))
g_free(temp);
g_queue_free(priv->js_queue);
@@ -468,6 +496,7 @@
GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
priv->empty = TRUE;
+ priv->html_queue = g_queue_new();
priv->js_queue = g_queue_new();
g_signal_connect(webview, "navigation-policy-decision-requested",
@@ -595,16 +624,12 @@
gtk_webview_append_html(GtkWebView *webview, const char *html)
{
GtkWebViewPriv *priv;
- WebKitDOMDocument *doc;
- WebKitDOMHTMLElement *body;
g_return_if_fail(webview != NULL);
priv = GTK_WEBVIEW_GET_PRIVATE(webview);
- doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
- body = webkit_dom_document_get_body(doc);
- webkit_dom_html_element_insert_adjacent_html(body, "beforeend", html, NULL);
- priv->empty = FALSE;
+ g_queue_push_tail(priv->html_queue, g_strdup(html));
+ g_idle_add((GSourceFunc)process_html_queue, webview);
}
void
More information about the Commits
mailing list