/dev/qulogic/ckeditor: 95248e4e81a5: Factor out webview's loadin...
Elliott Sales de Andrade
qulogic at pidgin.im
Fri Aug 9 03:13:32 EDT 2013
Changeset: 95248e4e81a5463a1b785dcbb04bf2d29a60f39c
Author: Elliott Sales de Andrade <qulogic at pidgin.im>
Date: 2013-08-09 01:32 -0400
Branch: default
URL: https://hg.pidgin.im/dev/qulogic/ckeditor/rev/95248e4e81a5
Description:
Factor out webview's loading queue.
Hopefully, this will reduce a few strdups a bit.
diffstat:
pidgin/gtkwebview.c | 50 +++++++++++++++++++++++++-------------------------
1 files changed, 25 insertions(+), 25 deletions(-)
diffs (135 lines):
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -642,6 +642,8 @@ gtk_webview_remove_smileys(GtkWebView *w
priv->default_smilies = gtk_smiley_tree_new();
}
+static void
+push_to_load_queue(GtkWebView *webview, int type, char *str);
void
gtk_webview_insert_smiley(GtkWebView *webview, const char *sml,
const char *smiley)
@@ -662,10 +664,9 @@ gtk_webview_insert_smiley(GtkWebView *we
/* TODO Better smiley insertion... */
tmp = g_strdup_printf("<img isEmoticon src='purple-smiley:%p' alt='%s'>",
webview_smiley, smiley);
- gtk_webview_append_html(webview, tmp);
- g_free(tmp);
+ push_to_load_queue(webview, LOAD_HTML, tmp);
} else {
- gtk_webview_append_html(webview, smiley);
+ push_to_load_queue(webview, LOAD_HTML, g_strdup(smiley));
}
g_free(unescaped);
@@ -861,6 +862,16 @@ process_load_queue(GtkWebView *webview)
}
static void
+push_to_load_queue(GtkWebView *webview, int type, char *str)
+{
+ GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
+ g_queue_push_tail(priv->load_queue, GINT_TO_POINTER(type));
+ g_queue_push_tail(priv->load_queue, str);
+ if (!priv->is_loading && priv->loader == 0)
+ priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
+}
+
+static void
webview_load_started(WebKitWebView *webview, WebKitWebFrame *frame,
gpointer userdata)
{
@@ -1649,15 +1660,9 @@ gtk_webview_quote_js_string(const char *
void
gtk_webview_safe_execute_script(GtkWebView *webview, const char *script)
{
- GtkWebViewPriv *priv;
-
g_return_if_fail(webview != NULL);
- priv = GTK_WEBVIEW_GET_PRIVATE(webview);
- g_queue_push_tail(priv->load_queue, GINT_TO_POINTER(LOAD_JS));
- g_queue_push_tail(priv->load_queue, g_strdup(script));
- if (!priv->is_loading && priv->loader == 0)
- priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
+ push_to_load_queue(webview, LOAD_JS, g_strdup(script));
}
void
@@ -1675,7 +1680,7 @@ gtk_webview_load_html_string_with_select
g_return_if_fail(webview != NULL);
gtk_webview_load_html_string(webview, html);
- gtk_webview_safe_execute_script(webview,
+ push_to_load_queue(webview, LOAD_JS, g_strdup(
"var s = window.getSelection();"
"var r = document.createRange();"
"var n = document.getElementById('caret');"
@@ -1685,7 +1690,7 @@ gtk_webview_load_html_string_with_select
"r.insertNode(f);"
"n.parentNode.removeChild(n);"
"s.removeAllRanges();"
- "s.addRange(r);");
+ "s.addRange(r);"));
}
void
@@ -1701,14 +1706,10 @@ gtk_webview_append_html(GtkWebView *webv
char *tmp = g_strdup_printf("CKEDITOR.instances.input.insertHtml(%s);", quoted);
g_free(quoted);
- g_queue_push_tail(priv->load_queue, GINT_TO_POINTER(LOAD_JS));
- g_queue_push_tail(priv->load_queue, tmp);
+ push_to_load_queue(webview, LOAD_JS, tmp);
} else {
- g_queue_push_tail(priv->load_queue, GINT_TO_POINTER(LOAD_HTML));
- g_queue_push_tail(priv->load_queue, g_strdup(html));
+ push_to_load_queue(webview, LOAD_HTML, g_strdup(html));
}
- if (!priv->is_loading && priv->loader == 0)
- priv->loader = g_idle_add((GSourceFunc)process_load_queue, webview);
}
void
@@ -1892,8 +1893,7 @@ gtk_webview_set_minimum_height(GtkWebVie
"CKEDITOR.config.autoGrow_minHeight = size;"
""
"})();", lines);
- gtk_webview_safe_execute_script(webview, scr);
- g_free(scr);
+ push_to_load_queue(webview, LOAD_JS, scr);
}
void
@@ -1994,9 +1994,9 @@ gtk_webview_set_format_functions(GtkWebV
script = g_string_append(script, "\";");
- gtk_webview_safe_execute_script(webview, script->str);
-
- g_string_free(script, TRUE);
+ push_to_load_queue(webview, LOAD_JS, script->str);
+
+ g_string_free(script, FALSE);
}
void
@@ -2359,7 +2359,7 @@ gtk_webview_show_toolbar(GtkWebView *web
g_return_if_fail(webview != NULL);
/* TODO: Toolbar visibility */
- gtk_webview_safe_execute_script(webview, "");
+ push_to_load_queue(webview, LOAD_JS, g_strdup(""));
}
void
@@ -2368,7 +2368,7 @@ gtk_webview_hide_toolbar(GtkWebView *web
g_return_if_fail(webview != NULL);
/* TODO: Toolbar visibility */
- gtk_webview_safe_execute_script(webview, "");
+ push_to_load_queue(webview, LOAD_JS, g_strdup(""));
}
void
More information about the Commits
mailing list