--- a/pidgin/gtkwebview.c Fri Jun 15 02:55:02 2012 -0400
+++ b/pidgin/gtkwebview.c Fri Jun 15 03:06:35 2012 -0400
@@ -53,7 +53,6 @@
*****************************************************************************/
typedef struct _GtkWebViewPriv {
- GHashTable *images; /**< a map from id to temporary file for the image */
gboolean empty; /**< whether anything has been appended **/
@@ -84,97 +83,44 @@
*****************************************************************************/
-get_image_src_from_id(GtkWebViewPriv *priv, int id)
- PurpleStoredImage *img;
- /* Check for already loaded image */
- src = (char *)g_hash_table_lookup(priv->images, GINT_TO_POINTER(id));
- priv->images = g_hash_table_new_full(g_direct_hash, g_direct_equal,
- /* Find image in store */
- img = purple_imgstore_find_by_id(id);
- src = (char *)purple_imgstore_get_filename(img);
- src = g_strdup_printf("file://%s", src);
- tmp = purple_base64_encode(purple_imgstore_get_data(img),
- purple_imgstore_get_size(img));
- src = g_strdup_printf("data:base64,%s", tmp);
- g_hash_table_insert(priv->images, GINT_TO_POINTER(id), src);
- * Replace all <img id=""> tags with <img src="">. I hoped to never
- * write any HTML parsing code, but I'm forced to do this, until
- * purple changes the way it works.
-replace_img_id_with_src(GtkWebViewPriv *priv, const char *html)
+webview_resource_loading(WebKitWebView *webview, + WebKitWebResource *resource, + WebKitNetworkRequest *request, + WebKitNetworkResponse *response, - GString *buffer = g_string_new(NULL);
- const char *cur = html;
- const char *img = strstr(cur, "<img");
- g_string_append(buffer, cur);
- g_string_append_len(buffer, cur, img - cur);
+ uri = webkit_network_request_get_uri(request); + if (purple_str_has_prefix(uri, PURPLE_STORED_IMAGE_PROTOCOL)) { + PurpleStoredImage *img; - cur = strstr(img, "/>");
- cur = strstr(img, ">");
+ uri += sizeof(PURPLE_STORED_IMAGE_PROTOCOL) - 1; + id = strtoul(uri, NULL, 10); - if (!cur) { /* invalid html? */
- g_string_printf(buffer, "%s", html);
+ img = purple_imgstore_find_by_id(id); - if (strstr(img, "src=") || !strstr(img, "id=")) {
- g_string_printf(buffer, "%s", html);
+ filename = purple_imgstore_get_filename(img); + if (filename && g_path_is_absolute(filename)) { + char *tmp = g_strdup_printf("file://%s", filename); + webkit_network_request_set_uri(request, tmp); + char *b64 = purple_base64_encode(purple_imgstore_get_data(img), + purple_imgstore_get_size(img)); + const char *type = purple_imgstore_get_extension(img); + char *tmp = g_strdup_printf("data:image/%s;base64,%s", type, b64); + webkit_network_request_set_uri(request, tmp);
- * if this is valid HTML, then I can be sure that it
- * has an id= and does not have an src=, since
- * '=' cannot appear in parameters.
- id = strstr(img, "id=") + 3;
- /* *id can't be \0, since a ">" appears after this */
- /* let's dump this, tag and then dump the src information */
- g_string_append_len(buffer, img, cur - img);
- g_string_append_printf(buffer, " src='%s' ", get_image_src_from_id(priv, nid));
- return g_string_free(buffer, FALSE);
@@ -441,9 +387,6 @@
g_queue_free(priv->js_queue);
- g_hash_table_unref(priv->images);
G_OBJECT_CLASS(parent_class)->finalize(G_OBJECT(webview));
@@ -535,6 +478,9 @@
g_signal_connect(webview, "load-finished",
G_CALLBACK(webview_load_finished), NULL);
+ g_signal_connect(G_OBJECT(webview), "resource-request-starting", + G_CALLBACK(webview_resource_loading), NULL); @@ -612,18 +558,8 @@
gtk_webview_load_html_string(GtkWebView *webview, const char *html)
- GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
- g_hash_table_unref(priv->images);
- html_imged = replace_img_id_with_src(priv, html);
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview), html_imged, NULL,
+ webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview), html, NULL, NULL, @@ -1067,7 +1003,8 @@
dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview));
- img = g_strdup_printf("<img src='%s'/>", get_image_src_from_id(priv, id));
+ img = g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'/>", priv->edit.block_changed = TRUE;
webkit_dom_document_exec_command(dom, "insertHTML", FALSE, img);
--- a/pidgin/gtkwebview.h Fri Jun 15 02:55:02 2012 -0400
+++ b/pidgin/gtkwebview.h Fri Jun 15 03:06:35 2012 -0400
@@ -114,9 +114,7 @@
void gtk_webview_append_html(GtkWebView *webview, const char *markup);
- * Rather than use webkit_webview_load_string, this routine
- * parses and displays the \<img id=?\> tags that make use of the
+ * Requests loading of the given content. * @param webview The GtkWebView object
* @param html The HTML content to load