[evolution/webkit] Render text/html parts in <iframe>



commit 1b5ad24a931235fcabf051db07468e43f33b8249
Author: Dan VrÃtil <dvratil redhat com>
Date:   Fri Feb 10 17:47:46 2012 +0100

    Render text/html parts in <iframe>

 mail/e-mail-display.c |    4 ++
 mail/em-format-html.c |   78 +++++++++++++++++++-----------------------------
 2 files changed, 35 insertions(+), 47 deletions(-)
---
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 6a6f40e..a551da0 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -745,6 +745,7 @@ e_mail_display_init (EMailDisplay *display)
         SoupSession *session;
 	SoupSessionFeature *feature;
 	const gchar *user_cache_dir;
+        WebKitWebSettings *settings;
 
 	display->priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
 
@@ -759,6 +760,9 @@ e_mail_display_init (EMailDisplay *display)
 
         webkit_web_view_set_full_content_zoom (WEBKIT_WEB_VIEW (display), TRUE);
 
+        settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (display));
+        g_object_set (settings, "enable-frame-flattening", TRUE, NULL);
+
         g_signal_connect (display, "navigation-policy-decision-requested",
                           G_CALLBACK (mail_display_link_clicked), NULL);
         g_signal_connect (display, "window-object-cleared",
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index dbac850..b8d8017 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -57,6 +57,7 @@
 #include <glib/gi18n.h>
 
 #include <JavaScriptCore/JavaScript.h>
+#include <webkit/webkit.h>
 
 #include <libemail-utils/mail-mt.h>
 #include <libemail-engine/e-mail-enumtypes.h>
@@ -757,57 +758,40 @@ efh_write_text_html (EMFormat *emf,
 		     EMFormatWriterInfo *info,
 		     GCancellable *cancellable)
 {
-	EMFormatHTML *efh;
-	CamelStream *format_stream;
-	GString *str;
-	GByteArray *ba;
-	gchar *pos, *header;
+        EMFormatHTML *efh = (EMFormatHTML *) emf;
 
 	if (g_cancellable_is_cancelled (cancellable))
 		return;
 
-	efh = (EMFormatHTML *) emf;
-
-	format_stream = camel_stream_mem_new ();
-	em_format_format_text (
-		emf, format_stream, (CamelDataWrapper *) puri->part, cancellable);
-
-	str  = g_string_new ("");
-	ba = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (format_stream));
-	g_string_append_len (str, (gchar *) ba->data, ba->len);
-
-	/* Here we remove the <head>...</head> part and replace
-	 <body...>...</body> by <div...>...</div> so that we can embed this
-	 part simply into the rest of the email */
-	pos = strcasestr (str->str, "<body");
-	if (pos)
-		g_string_erase (str, 0, (pos - str->str) + 5);
-
-	/* The second <div> is unclosed because we want to keep all
-	 * attributes from the <body> element */
-	header = g_strdup_printf (
-		"<div class=\"part-container\" style=\"border: solid #%06x 1px; "
-		"background-color: #%06x; color: #%06x;\" >"
-		"<div class=\"part-container-inner-margin\" ",
-		e_color_to_value (&efh->priv->colors[
-			EM_FORMAT_HTML_COLOR_FRAME]),
-		e_color_to_value (&efh->priv->colors[
-			EM_FORMAT_HTML_COLOR_CONTENT]),
-		e_color_to_value (&efh->priv->colors[
-			EM_FORMAT_HTML_COLOR_TEXT]));
-	g_string_prepend (str, header);
-	g_free (header);
-
-	/* Remove </body> */
-	pos = strcasestr (str->str, "</body>");
-	if (pos)
-		g_string_truncate (str, (pos - str->str));
-
-	g_string_append (str, "</div></div>");
-
-	camel_stream_write_string (stream, str->str, cancellable, NULL);
+        if (info->mode == EM_FORMAT_WRITE_MODE_RAW) {
+                em_format_format_text (emf, stream,
+                        (CamelDataWrapper *) puri->part, cancellable);
 
-	g_string_free (str, TRUE);
+        } else {
+                gchar *str;
+                gchar *uri;
+
+                uri = em_format_build_mail_uri (emf->folder, emf->message_uid,
+                        "part_id", G_TYPE_STRING, puri->uri,
+                        "mode", G_TYPE_INT, EM_FORMAT_WRITE_MODE_RAW,
+                        NULL);
+
+                str = g_strdup_printf (
+                        "<div class=\"part-container\" style=\"border: solid #%06x 1px; "
+                        "background-color: #%06x;\">"
+                        "<div class=\"part-container-inner-margin\">\n"
+                        "<iframe width=\"100%%\" height=\"auto\""
+                        " frameborder=\"0\" src=\"%s\"></iframe>"
+                        "</div></div>",
+                        e_color_to_value (&efh->priv->colors[EM_FORMAT_HTML_COLOR_FRAME]),
+                        e_color_to_value (&efh->priv->colors[EM_FORMAT_HTML_COLOR_CONTENT]),
+                        uri);
+
+                camel_stream_write_string (stream, str, cancellable, NULL);
+
+                g_free (str);
+                g_free (uri);
+        }
 }
 
 static void



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