aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2013-02-21 02:21:55 +0800
committerMilan Crha <mcrha@redhat.com>2013-02-21 02:21:55 +0800
commit39645fa1b90b319aa024b89f56dd2567a3a54686 (patch)
tree8d6152fed7d7f98a9567779a46e4531eae2a3957 /e-util
parent30cc64835da651e25cd09c3b01ca8f430ba45c61 (diff)
downloadgsoc2013-evolution-39645fa1b90b319aa024b89f56dd2567a3a54686.tar
gsoc2013-evolution-39645fa1b90b319aa024b89f56dd2567a3a54686.tar.gz
gsoc2013-evolution-39645fa1b90b319aa024b89f56dd2567a3a54686.tar.bz2
gsoc2013-evolution-39645fa1b90b319aa024b89f56dd2567a3a54686.tar.lz
gsoc2013-evolution-39645fa1b90b319aa024b89f56dd2567a3a54686.tar.xz
gsoc2013-evolution-39645fa1b90b319aa024b89f56dd2567a3a54686.tar.zst
gsoc2013-evolution-39645fa1b90b319aa024b89f56dd2567a3a54686.zip
Show local images in Signature preview
WebKit deny in loading local URIs (file://...) when an HTML body is constructed from a string, not from a local file, thus fix the URIs into "evo-file://", which are passed into our request handlers, which can load the local files.
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-mail-signature-preview.c64
1 files changed, 62 insertions, 2 deletions
diff --git a/e-util/e-mail-signature-preview.c b/e-util/e-mail-signature-preview.c
index 8bf27fdb52..d4b57f40be 100644
--- a/e-util/e-mail-signature-preview.c
+++ b/e-util/e-mail-signature-preview.c
@@ -57,6 +57,64 @@ G_DEFINE_TYPE (
E_TYPE_WEB_VIEW)
static void
+replace_local_image_links (WebKitDOMElement *element)
+{
+ if (!element)
+ return;
+
+ if (WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT (element)) {
+ WebKitDOMHTMLImageElement *img;
+ gchar *src;
+
+ img = WEBKIT_DOM_HTML_IMAGE_ELEMENT (element);
+ src = webkit_dom_html_image_element_get_src (img);
+ if (src && g_ascii_strncasecmp (src, "file://", 7) == 0) {
+ gchar *new_src;
+
+ /* this forms "evo-file://", which can be loaded,
+ while "file://" cannot be, due to webkit policy */
+ new_src = g_strconcat ("evo-", src, NULL);
+ webkit_dom_html_image_element_set_src (img, new_src);
+ g_free (new_src);
+ }
+
+ g_free (src);
+ }
+
+ if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (element)) {
+ WebKitDOMDocument *frame_document;
+
+ frame_document =
+ webkit_dom_html_iframe_element_get_content_document (
+ WEBKIT_DOM_HTML_IFRAME_ELEMENT (element));
+ replace_local_image_links (WEBKIT_DOM_ELEMENT (frame_document));
+ }
+
+ replace_local_image_links (webkit_dom_element_get_first_element_child (element));
+
+ while (element = webkit_dom_element_get_next_element_sibling (element), element) {
+ replace_local_image_links (element);
+ }
+}
+
+static void
+signature_preview_document_loaded_cb (WebKitWebView *web_view,
+ WebKitWebFrame *web_frame,
+ gpointer user_data)
+{
+ WebKitDOMDocument *document;
+ WebKitDOMNode *node;
+
+ document = webkit_web_view_get_dom_document (web_view);
+ for (node = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (document));
+ node;
+ node = webkit_dom_node_get_next_sibling (node)) {
+ if (WEBKIT_DOM_IS_ELEMENT (node))
+ replace_local_image_links (WEBKIT_DOM_ELEMENT (node));
+ }
+}
+
+static void
mail_signature_preview_load_cb (ESource *source,
GAsyncResult *result,
EMailSignaturePreview *preview)
@@ -94,9 +152,9 @@ mail_signature_preview_load_cb (ESource *source,
extension = e_source_get_extension (source, extension_name);
mime_type = e_source_mail_signature_get_mime_type (extension);
- if (g_strcmp0 (mime_type, "text/html") == 0)
+ if (g_strcmp0 (mime_type, "text/html") == 0) {
e_web_view_load_string (E_WEB_VIEW (preview), contents);
- else {
+ } else {
gchar *string;
string = g_markup_printf_escaped ("<pre>%s</pre>", contents);
@@ -303,6 +361,8 @@ static void
e_mail_signature_preview_init (EMailSignaturePreview *preview)
{
preview->priv = E_MAIL_SIGNATURE_PREVIEW_GET_PRIVATE (preview);
+
+ g_signal_connect (preview, "document-load-finished", G_CALLBACK (signature_preview_document_loaded_cb), NULL);
}
GtkWidget *