[evolution/webkit: 130/182] Use native WebKit placeholder for missing images (fix #668582)



commit 19aafafa073ed391afae0340d5572c0e262818fa
Author: Dan VrÃtil <dvratil redhat com>
Date:   Wed Jan 25 10:58:56 2012 +0100

    Use native WebKit placeholder for missing images (fix #668582)
    
    Instead of sending content of GTK-STOCK-MISSING-IMAGE when we are not allowed to laod
    an image, redirect the request to an invalid URI which makes WebKit to put in it's
    native placeholder.

 mail/e-mail-display.c |   17 +++++++++++++++++
 mail/e-mail-request.c |   22 ----------------------
 2 files changed, 17 insertions(+), 22 deletions(-)
---
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 8ddc6ba..6166827 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -574,6 +574,23 @@ mail_display_resource_requested (WebKitWebView *web_view,
                 gchar *new_uri, *mail_uri, *enc;
                 SoupURI *soup_uri;
                 GHashTable *query;
+                gchar *uri_md5;
+                CamelStream *stream;
+
+                /* Open Evolution's cache */
+                uri_md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
+                stream = camel_data_cache_get (
+                                emd_global_http_cache, "http", uri_md5, NULL);
+                g_free (uri_md5);
+
+                /* If the URI is not cached and we are not allowed to load it
+                 * then redirect to invalid URI, so that webkit would display
+                 * a native placeholder for it. */
+                if (!stream && !display->priv->force_image_load &&
+                    !em_format_html_can_load_images (display->priv->formatter)) {
+                        webkit_network_request_set_uri (request, "invalid://protocol");
+                        return;
+                }
 
                 new_uri = g_strconcat ("evo-", uri, NULL);
                 /* Don't free, will be freed when the hash table is destroyed */
diff --git a/mail/e-mail-request.c b/mail/e-mail-request.c
index aabf23f..a80c410 100644
--- a/mail/e-mail-request.c
+++ b/mail/e-mail-request.c
@@ -415,28 +415,6 @@ handle_http_request (GSimpleAsyncResult *res,
 
                 goto cleanup;
 
-        /* Item not found in cache and image loading policy forbids us from fetching
-         * the resource from network, so we only send GTK_STOCK_MISSING_IMAGE */
-        } else {
-
-                GFile *icon;
-                gchar *icon_path;
-                gchar *data;
-
-                d(printf (" '%s' not in cache and image loading policy prevents "
-                          "us from loading it; returing GTK_STOCK_MISSING_IMAGE\n",
-                          uri));
-
-                icon_path = e_icon_factory_get_icon_filename (GTK_STOCK_MISSING_IMAGE,
-                                        GTK_ICON_SIZE_LARGE_TOOLBAR);
-
-                icon = g_file_new_for_path (icon_path);
-                g_file_load_contents (icon, cancellable, &data, (gsize *) &len, NULL, NULL);
-
-                stream = g_memory_input_stream_new_from_data (data, len, NULL);
-                g_simple_async_result_set_op_res_gpointer (res, stream, NULL);
-
-                g_free (data);
         }
 
 cleanup:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]