[evolution/webkit: 142/196] Return back to a single-webview mode



commit e4ee442700cb3cd4061672dec2b1c1a6a7f2ac2c
Author: Dan VrÃtil <dvratil redhat com>
Date:   Thu Feb 9 10:33:37 2012 +0100

    Return back to a single-webview mode
    
    Thanks to Milan's WebKit patch embedding widgets to WebKit works again.
    This patch is a first step towards merging all back to one webview. All
    basic things work but some code still needs to be rewritten.
    
    To test this revision you need WebKit compiled with following patch:
    https://bug-63451-attachments.webkit.org/attachment.cgi?id=126053
    
    The patch should be comitted to WebKit soon.

 data/webview.css                                |   25 +-
 em-format/.em-format-quote.c.kate-swp           |  Bin 94 -> 0 bytes
 em-format/em-format.c                           |   20 +-
 em-format/em-format.h                           |   19 +-
 mail/e-mail-browser.c                           |   37 +-
 mail/e-mail-display.c                           |  967 ++++++-----------------
 mail/e-mail-display.h                           |   30 +-
 mail/e-mail-paned-view.c                        |   25 +-
 mail/e-mail-printer.c                           |    2 +-
 mail/e-mail-reader-utils.c                      |    2 +-
 mail/e-mail-reader.c                            |   63 +-
 mail/e-mail-request.c                           |   46 +-
 mail/em-format-html-display.c                   |   81 ++-
 mail/em-format-html-print.c                     |    2 +-
 mail/em-format-html.c                           |  300 ++++----
 modules/mail/e-mail-shell-content.c             |    1 -
 modules/mail/e-mail-shell-view-actions.c        |   25 +-
 modules/mail/e-mail-shell-view-private.c        |    4 +-
 modules/web-inspector/evolution-web-inspector.c |    4 +-
 plugins/audio-inline/audio-inline.c             |   22 +-
 plugins/itip-formatter/itip-formatter.c         |   21 +
 plugins/mail-to-task/mail-to-task.c             |    2 +-
 widgets/misc/e-preview-pane.c                   |    4 +-
 widgets/misc/e-web-view.c                       |  115 ---
 24 files changed, 653 insertions(+), 1164 deletions(-)
---
diff --git a/data/webview.css b/data/webview.css
index 457183c..8838d9d 100644
--- a/data/webview.css
+++ b/data/webview.css
@@ -3,6 +3,11 @@ html, body {
   margin: 0;
 }
 
+body {
+  /* Use margin so that children can safely use width=100% */
+  margin: 10px;
+}
+
 h1, h2, h3 {
   color: #7f7f7f;
 }
@@ -53,8 +58,22 @@ img.navigable {
 .part-container {
   width: 100%;
   height: 100%;
+  background: #FFF;
+  margin-top: 2px;
+  margin-bottom: 3px;
 }
 
+.part-container-inner-margin {
+  margin: 8px;
+}
+
+object { /* GtkWidgets */
+        margin-top: 2px;
+        margin-bottom: 2px;
+}
+
+/***** PRINTING *******/
+
 .printing-header {
   margin-bottom: 20px;
 }
@@ -72,9 +91,3 @@ img.navigable {
 .attachments-list th {
   font-weight: bold;
 }
-
-#_evo_bottom_element {
-  clear: both;
-  width: 100%;
-  height: 2px; /* Change constant in web_view_get_preferred_height when changing this */
-}
\ No newline at end of file
diff --git a/em-format/em-format.c b/em-format/em-format.c
index a7c2935..0779e47 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -35,7 +35,7 @@
 #include "shell/e-shell.h"
 #include "shell/e-shell-settings.h"
 
-#define d(x) x
+#define d(x)
 
 #define EM_FORMAT_GET_PRIVATE(obj) \
 	(G_TYPE_INSTANCE_GET_PRIVATE \
@@ -1915,14 +1915,28 @@ em_format_parse (EMFormat *emf,
 	g_string_free (part_id, TRUE);
 }
 
+void
+em_format_write (EMFormat *emf,
+                 CamelStream *stream,
+                 EMFormatWriterInfo *info,
+                 GCancellable *cancellable)
+{
+	EMFormatClass *emf_class;
+
+	g_return_if_fail (EM_IS_FORMAT (emf));
+	g_return_if_fail (CAMEL_IS_STREAM (stream));
+
+	emf_class = EM_FORMAT_GET_CLASS (emf);
+	if (emf_class->write)
+		emf_class->write (emf, stream, info, cancellable);
+}
+
 static void
 emf_start_async_parser (GSimpleAsyncResult *result,
                         GObject *object,
                         GCancellable *cancellable)
 {
         em_format_parse (EM_FORMAT (object), NULL, NULL, cancellable);
-
-	g_simple_async_result_complete_in_idle (result);
 }
 
 void
diff --git a/em-format/em-format.h b/em-format/em-format.h
index c9c38be..6319c44 100644
--- a/em-format/em-format.h
+++ b/em-format/em-format.h
@@ -91,7 +91,8 @@ typedef enum {
 	EM_FORMAT_WRITE_MODE_NORMAL= 1 << 0,
 	EM_FORMAT_WRITE_MODE_ALL_HEADERS = 1 << 1,
 	EM_FORMAT_WRITE_MODE_SOURCE = 1 << 2,
-	EM_FORMAT_WRITE_MODE_PRINTING = 1 << 3
+	EM_FORMAT_WRITE_MODE_PRINTING = 1 << 3,
+	EM_FORMAT_WRITE_MODE_RAW = 1 << 4
 } EMFormatWriteMode;
 
 struct _EMFormatHandler {
@@ -123,10 +124,6 @@ struct _EMFormatWriterInfo {
 	EMFormatWriteMode mode;
 	gboolean headers_collapsable;
 	gboolean headers_collapsed;
-
-	/* When TRUE, EMFormatWriteFunc's will put the content of the PURI part
-	   between EFH_HTML_HEADER and EFH_HTML_FOOTER */
-	gboolean with_html_header;
 };
 
 struct _EMFormatHeader {
@@ -188,10 +185,17 @@ struct _EMFormatClass {
 							 CamelMimePart *part,
 							 const EMFormatHandler *handler);
 
+	/* Write the entire message to stream */
+	void		(*write)			(EMFormat *emf,
+							 CamelStream *stream,
+							 EMFormatWriterInfo *info,
+							 GCancellable *cancellable);
+
         void            (*preparse)                     (EMFormat *emf);
 
 	/* signals */
 	void		(*redraw_requested)		(EMFormat *emf);
+
 };
 
 EMFormat*		em_format_new 			(void);
@@ -252,6 +256,11 @@ void			em_format_parse			(EMFormat *emf,
 							 CamelFolder *folder,
 							 GCancellable *cancellable);
 
+void			em_format_write			(EMFormat *emf,
+							 CamelStream *stream,
+							 EMFormatWriterInfo *info,
+							 GCancellable *cancellable);
+
 void                    em_format_parse_async           (EMFormat *emf,
                                                          CamelMimeMessage *message,
                                                          CamelFolder *folder,
diff --git a/mail/e-mail-browser.c b/mail/e-mail-browser.c
index 2bb22d3..54dd264 100644
--- a/mail/e-mail-browser.c
+++ b/mail/e-mail-browser.c
@@ -55,7 +55,6 @@ struct _EMailBrowserPrivate {
 	EMailBackend *backend;
 	GtkUIManager *ui_manager;
 	EFocusTracker *focus_tracker;
-        EMailDisplay *display;
 
 	EMFormatWriteMode mode;
 
@@ -64,7 +63,6 @@ struct _EMailBrowserPrivate {
 	GtkWidget *message_list;
 	GtkWidget *preview_pane;
 	GtkWidget *statusbar;
-        GtkWidget *scrolled_window;        
 
 	guint show_deleted : 1;
 };
@@ -320,7 +318,6 @@ mail_browser_popup_event_cb (EMailBrowser *browser,
                              GdkEventButton *event,
                              const gchar *uri)
 {
-	EMailDisplay *display;
 	EMailReader *reader;
 	EWebView *web_view;
 	GtkMenu *menu;
@@ -330,8 +327,7 @@ mail_browser_popup_event_cb (EMailBrowser *browser,
 		return FALSE;
 
 	reader = E_MAIL_READER (browser);
-	display = e_mail_reader_get_mail_display (reader);
-	web_view = e_mail_display_get_current_web_view (display);
+	web_view = E_WEB_VIEW (e_mail_reader_get_mail_display (reader));
 
 	if (e_web_view_get_cursor_image (web_view) != NULL)
 		return FALSE;
@@ -529,11 +525,11 @@ mail_browser_dispose (GObject *object)
 static void
 mail_browser_constructed (GObject *object)
 {
-	EMailBrowserPrivate *priv;
 	EMailBrowser *browser;
 	EMailReader *reader;
 	EMailBackend *backend;
 	EMailSession *session;
+        EMailDisplay *display;
 	EShellBackend *shell_backend;
 	EShell *shell;
 	EFocusTracker *focus_tracker;
@@ -553,8 +549,6 @@ mail_browser_constructed (GObject *object)
 	G_OBJECT_CLASS (parent_class)->constructed (object);
 
 	browser = E_MAIL_BROWSER (object);
-	priv = E_MAIL_BROWSER_GET_PRIVATE (browser);
-
 	reader = E_MAIL_READER (object);
 	backend = e_mail_reader_get_backend (reader);
 	session = e_mail_backend_get_session (backend);
@@ -571,9 +565,6 @@ mail_browser_constructed (GObject *object)
 	gtk_application_add_window (
 		GTK_APPLICATION (shell), GTK_WINDOW (object));
 
-	//priv->display = e_mail_reader_get_mail_display (reader);
-	e_mail_display_set_mode (priv->display, E_MAIL_BROWSER (object)->priv->mode);
-
 	/* The message list is a widget, but it is not shown in the browser.
 	 * Unfortunately, the widget is inseparable from its model, and the
 	 * model is all we need. */
@@ -588,12 +579,15 @@ mail_browser_constructed (GObject *object)
 		browser->priv->message_list, "message-list-built",
 		G_CALLBACK (mail_browser_message_list_built_cb), object);
 
+        display = g_object_new (E_TYPE_MAIL_DISPLAY, NULL);
+        e_mail_display_set_mode (display, E_MAIL_BROWSER (object)->priv->mode);
+
 	g_signal_connect_swapped (
-		priv->display, "popup-event",
+		display, "popup-event",
 		G_CALLBACK (mail_browser_popup_event_cb), object);
 
 	g_signal_connect_swapped (
-		priv->display, "status-message",
+		display, "status-message",
 		G_CALLBACK (mail_browser_status_message_cb), object);
 
 	/* Add action groups before initializing the reader interface. */
@@ -680,21 +674,16 @@ mail_browser_constructed (GObject *object)
 		gtk_widget_get_style_context (widget),
 		GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
 
-        priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
-        gtk_box_pack_start (GTK_BOX (container), priv->scrolled_window, TRUE, TRUE, 0);
-        gtk_widget_show (priv->scrolled_window);
-
-	widget = GTK_WIDGET (priv->display);
-	gtk_container_add (GTK_CONTAINER (priv->scrolled_window), widget);
+	widget = e_preview_pane_new (E_WEB_VIEW (display));
+	gtk_container_add (GTK_CONTAINER (container), widget);
 	browser->priv->preview_pane = g_object_ref (widget);
 	gtk_widget_show (widget);
 
-	search_bar = e_mail_display_get_search_bar (priv->display);
+	search_bar = e_preview_pane_get_search_bar (E_PREVIEW_PANE (widget));
 
 	g_signal_connect_swapped (
 		search_bar, "changed",
-		G_CALLBACK (e_mail_display_reload),
-		priv->display);
+		G_CALLBACK (e_mail_display_reload), display);
 
 	/* Bind GObject properties to GSettings keys. */
 
@@ -775,7 +764,8 @@ mail_browser_get_mail_display (EMailReader *reader)
 
 	priv = E_MAIL_BROWSER_GET_PRIVATE (E_MAIL_BROWSER (reader));
 
-	return priv->display;
+	return E_MAIL_DISPLAY (e_preview_pane_get_web_view (
+                                        E_PREVIEW_PANE (priv->preview_pane)));
 }
 
 static GtkWidget *
@@ -933,7 +923,6 @@ static void
 e_mail_browser_init (EMailBrowser *browser)
 {
 	browser->priv = E_MAIL_BROWSER_GET_PRIVATE (browser);
-	browser->priv->display = g_object_new (E_TYPE_MAIL_DISPLAY, NULL);
 
 	gtk_window_set_title (GTK_WINDOW (browser), _("Evolution"));
 	gtk_window_set_default_size (GTK_WINDOW (browser), 600, 400);
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 98bf935..06d3cff 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -40,6 +40,7 @@
 #include "mail/e-mail-attachment-bar.h"
 #include "widgets/misc/e-attachment-button.h"
 
+
 #include <camel/camel.h>
 
 #include <libsoup/soup.h>
@@ -49,33 +50,23 @@
 
 #define d(x)
 
+G_DEFINE_TYPE (EMailDisplay, e_mail_display, E_TYPE_WEB_VIEW)
+
 #define E_MAIL_DISPLAY_GET_PRIVATE(obj) \
 	(G_TYPE_INSTANCE_GET_PRIVATE \
 	((obj), E_TYPE_MAIL_DISPLAY, EMailDisplayPrivate))
 
 struct _EMailDisplayPrivate {
-	GtkWidget *box;
-
-	ESearchBar *searchbar;
 	EMFormatHTML *formatter;
 
 	EMFormatWriteMode mode;
 	gboolean headers_collapsable;
 	gboolean headers_collapsed;
 
-	GList *webviews;
-
-        GtkWidget *current_webview;
-
 	GtkActionGroup *mailto_actions;
         GtkActionGroup *images_actions;
 
-        guint caret_mode:1;
-        guint force_image_load:1;
-	gfloat zoom_level;
-
-	WebKitWebSettings *settings;
-        WebKitWebSettings *headers_settings;
+        gint force_image_load: 1;
 };
 
 enum {
@@ -84,18 +75,8 @@ enum {
 	PROP_MODE,
 	PROP_HEADERS_COLLAPSABLE,
 	PROP_HEADERS_COLLAPSED,
-        PROP_CARET_MODE,
-	PROP_ZOOM_LEVEL
-};
-
-enum {
-	POPUP_EVENT,
-	STATUS_MESSAGE,
-        LAST_SIGNAL
 };
 
-static gint signals[LAST_SIGNAL];
-
 static gpointer parent_class;
 
 static CamelDataCache *emd_global_http_cache = 0;
@@ -178,23 +159,6 @@ static GtkActionEntry image_entries[] = {
 };
 
 
-static gboolean
-mail_display_webview_enter_notify_event (GtkWidget *widget,
-                                         GdkEvent *event,
-                                         gpointer user_data)
-{
-      EMailDisplay *display = user_data;
-
-      /* This handler should always be connected to EWebView
-       * signals only! */
-      g_return_val_if_fail (E_IS_WEB_VIEW (widget), FALSE);
-
-      if (event->crossing.mode == GDK_CROSSING_NORMAL)
-              display->priv->current_webview = widget;
-
-      return FALSE;
-}
-
 static void
 mail_display_webview_update_actions (EWebView *web_view,
                                      gpointer user_data)
@@ -223,8 +187,6 @@ mail_display_webview_update_actions (EWebView *web_view,
                 gtk_action_set_visible (action, visible);
 }
 
-
-
 static void
 formatter_image_loading_policy_changed_cb (GObject *object,
                                            GParamSpec *pspec,
@@ -285,8 +247,6 @@ mail_display_set_property (GObject *object,
                            const GValue *value,
                            GParamSpec *pspec)
 {
-	EMailDisplayPrivate *priv = E_MAIL_DISPLAY (object)->priv;
-
 	switch (property_id) {
 		case PROP_FORMATTER:
 			e_mail_display_set_formatter (
@@ -308,12 +268,6 @@ mail_display_set_property (GObject *object,
 				E_MAIL_DISPLAY (object),
 				g_value_get_boolean (value));
 			return;
-                case PROP_CARET_MODE:
-			priv->caret_mode = g_value_get_boolean (value);
-                        return;
-		case PROP_ZOOM_LEVEL:
-			priv->zoom_level = g_value_get_float (value);
-			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -325,8 +279,6 @@ mail_display_get_property (GObject *object,
                            GValue *value,
                            GParamSpec *pspec)
 {
-	EMailDisplayPrivate *priv = E_MAIL_DISPLAY (object)->priv;
-
 	switch (property_id) {
 		case PROP_FORMATTER:
 			g_value_set_object (
@@ -348,12 +300,6 @@ mail_display_get_property (GObject *object,
 				value, e_mail_display_get_headers_collapsed (
 				E_MAIL_DISPLAY (object)));
 			return;
-                case PROP_CARET_MODE:
-                        g_value_set_boolean (value, priv->caret_mode);
-                        return;
-		case PROP_ZOOM_LEVEL:
-			g_value_set_float (value, priv->zoom_level);
-			return;
 	}
 
 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -371,26 +317,6 @@ mail_display_dispose (GObject *object)
 		priv->formatter = NULL;
 	}
 
-	if (priv->searchbar) {
-		g_object_unref (priv->searchbar);
-		priv->searchbar = NULL;
-	}
-
-	if (priv->webviews) {
-		g_list_free (priv->webviews);
-		priv->webviews = NULL;
-	}
-
-	if (priv->settings) {
-		g_object_unref (priv->settings);
-		priv->settings = NULL;
-	}
-
-	if (priv->headers_settings) {
-                g_object_unref (priv->headers_settings);
-                priv->headers_settings = NULL;
-        }
-
 	/* Chain up to parent's dispose() method. */
 	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -418,51 +344,20 @@ mail_display_style_set (GtkWidget *widget,
 	e_mail_display_reload (display);
 }
 
-static void
-mail_display_emit_status_message (EWebView *web_view,
-				  const gchar *message,
-				  gpointer user_data)
-{
-	EMailDisplay *display = user_data;
-
-	g_signal_emit (display, signals[STATUS_MESSAGE], 0, message);
-}
-
-static gboolean
-mail_display_emit_popup_event (EWebView *web_view,
-			       GdkEventButton *event,
-			       const gchar *uri,
-			       gpointer user_data)
-{
-	EMailDisplay *display = user_data;
-	gboolean event_handled;
-
-	g_signal_emit (display, signals[POPUP_EVENT], 0, event, uri, &event_handled);
-
-	return event_handled;
-}
-
 static gboolean
 mail_display_process_mailto (EWebView *web_view,
                              const gchar *mailto_uri,
                              gpointer user_data)
 {
-	EMailDisplay *display = user_data;
-
-	g_return_val_if_fail (web_view != NULL, FALSE);
+	g_return_val_if_fail (E_IS_WEB_VIEW (web_view), FALSE);
 	g_return_val_if_fail (mailto_uri != NULL, FALSE);
-	g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), FALSE);
 
 	if (g_ascii_strncasecmp (mailto_uri, "mailto:";, 7) == 0) {
-		EMailDisplayPrivate *priv;
 		EMFormat *format;
 		CamelFolder *folder = NULL;
 		EShell *shell;
 
-		priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
-		g_return_val_if_fail (priv->formatter != NULL, FALSE);
-
-		format = EM_FORMAT (priv->formatter);
+                format = (EMFormat *) E_MAIL_DISPLAY (web_view)->priv->formatter;
 
 		if (format != NULL && format->folder != NULL)
 			folder = format->folder;
@@ -485,14 +380,14 @@ mail_display_link_clicked (WebKitWebView *web_view,
 			   WebKitWebPolicyDecision *policy_decision,
 			   gpointer user_data)
 {
-	EMailDisplay *display = user_data;
-	EMailDisplayPrivate *priv;
+        EMailDisplay *display;
 	const gchar *uri = webkit_network_request_get_uri (request);
 
-	priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
-	g_return_val_if_fail (priv->formatter != NULL, FALSE);
+	display = E_MAIL_DISPLAY (web_view);
+	if (display->priv->formatter == NULL)
+                return FALSE;
 
-	if (mail_display_process_mailto (E_WEB_VIEW (web_view), uri, display)) {
+	if (mail_display_process_mailto (E_WEB_VIEW (web_view), uri, NULL)) {
 		/* do nothing, function handled the "mailto:"; uri already */
 		webkit_web_policy_decision_ignore (policy_decision);
 		return TRUE;
@@ -547,14 +442,18 @@ mail_display_resource_requested (WebKitWebView *web_view,
 				 WebKitNetworkResponse *response,
 				 gpointer user_data)
 {
-	EMailDisplay *display = user_data;
+	EMailDisplay *display = E_MAIL_DISPLAY (web_view);
 	EMFormat *formatter = EM_FORMAT (display->priv->formatter);
 	const gchar *uri = webkit_network_request_get_uri (request);
 
         /* Redirect cid:part_id to mail://mail_id/cid:part_id */
         if (g_str_has_prefix (uri, "cid:")) {
+
+		/* Always write raw content of CID object */
 		gchar *new_uri = em_format_build_mail_uri (formatter->folder,
-			formatter->message_uid, "part_id", G_TYPE_STRING, uri, NULL);
+			formatter->message_uid,
+			"part_id", G_TYPE_STRING, uri,
+			"mode", G_TYPE_INT, EM_FORMAT_WRITE_MODE_RAW, NULL);
 
                 webkit_network_request_set_uri (request, new_uri);
 
@@ -634,379 +533,137 @@ mail_display_resource_requested (WebKitWebView *web_view,
 }
 
 static void
-mail_display_headers_collapsed_state_changed (EWebView *web_view,
-					      size_t arg_count,
-					      const JSValueRef args[],
-					      gpointer user_data)
+mail_display_plugin_widget_resize (GtkWidget *widget,
+				   GdkRectangle *event,
+				   EMailDisplay *display)
 {
-	EMailDisplay *display = user_data;
-	JSGlobalContextRef ctx = e_web_view_get_global_context (web_view);
+	GtkAllocation allocation;
+	WebKitDOMDocument *document;
+	WebKitDOMNodeList *nodes;
+	gint i;
+	gchar *puri_uri;
+	gint height;
 
-	e_mail_display_set_headers_collapsed (display, JSValueToBoolean (ctx, args[0]));
-}
+	//gtk_widget_get_allocation (widget, &allocation);
+	gtk_widget_get_preferred_height (widget, &height, NULL);
+	//height = allocation.height;
 
-static void
-mail_display_install_js_callbacks (WebKitWebView *web_view,
-			           WebKitWebFrame *frame,
-				   gpointer context,
-				   gpointer window_object,
-				   gpointer user_data)
-{
-	if (frame != webkit_web_view_get_main_frame (web_view))
-		return;
+	puri_uri = g_object_get_data (G_OBJECT (widget), "uri");
 
-	e_web_view_install_js_callback (E_WEB_VIEW (web_view), "headers_collapsed",
-		(EWebViewJSFunctionCallback) mail_display_headers_collapsed_state_changed, user_data);
-}
+	document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (display));
+	nodes = webkit_dom_document_get_elements_by_tag_name (document, "object");
 
-static EWebView*
-mail_display_setup_webview (EMailDisplay *display,
-			    gboolean is_header)
-{
-	EWebView *web_view;
-	GtkUIManager *ui_manager;
-	GError *error = NULL;
+	for (i = 0; i < webkit_dom_node_list_get_length (nodes); i++) {
 
-	web_view = E_WEB_VIEW (e_web_view_new ());
-	webkit_web_view_set_full_content_zoom (WEBKIT_WEB_VIEW (web_view), TRUE);
+		WebKitDOMNode *node = webkit_dom_node_list_item (nodes, i);
 
-        if (is_header) {
-                e_web_view_set_settings (web_view, display->priv->headers_settings);
-        } else {
-	        e_web_view_set_settings (web_view, display->priv->settings);
-        }
+		gchar *uri =webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "data");
 
-	g_signal_connect (web_view, "navigation-policy-decision-requested",
-		G_CALLBACK (mail_display_link_clicked), display);
-	g_signal_connect (web_view, "window-object-cleared",
-		G_CALLBACK (mail_display_install_js_callbacks), display);
-	g_signal_connect (web_view, "resource-request-starting",
-		G_CALLBACK (mail_display_resource_requested), display);
-	g_signal_connect (web_view, "process-mailto",
-		G_CALLBACK (mail_display_process_mailto), display);
-	g_signal_connect (web_view, "status-message",
-		G_CALLBACK (mail_display_emit_status_message), display);
-	g_signal_connect (web_view, "popup-event",
-		G_CALLBACK (mail_display_emit_popup_event), display);
-        g_signal_connect (web_view, "enter-notify-event",
-                G_CALLBACK (mail_display_webview_enter_notify_event), display);
-        g_signal_connect (web_view, "update-actions",
-                G_CALLBACK (mail_display_webview_update_actions), display);
-
-	g_object_bind_property (web_view, "zoom-level", display, "zoom-level", 
-		G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
-
-	/* Because we are loading from a hard-coded string, there is
-	 * no chance of I/O errors.  Failure here implies a malformed
-	 * UI definition.  Full stop. */
-	ui_manager = e_web_view_get_ui_manager (web_view);
-	gtk_ui_manager_insert_action_group (ui_manager, display->priv->mailto_actions, 0);
-	gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error);
+		if (g_strcmp0 (uri, puri_uri) == 0) {
 
-        if (error != NULL) {
-                g_error ("%s", error->message);
-                g_error_free (error);
-        }
+			gchar *dim;
 
-        error = NULL;
-        gtk_ui_manager_insert_action_group (ui_manager, display->priv->images_actions, 0);
-        gtk_ui_manager_add_ui_from_string (ui_manager, image_ui, -1, &error);
+			dim = g_strdup_printf ("%d", height);
+			webkit_dom_html_object_element_set_height (
+				WEBKIT_DOM_HTML_OBJECT_ELEMENT (node), dim);
+			g_free (dim);
 
-	if (error != NULL) {
-		g_error ("%s", error->message);
-                g_error_free (error);
-        }
+			g_free (uri);
 
-	return web_view;
-}
+			gtk_widget_queue_draw (GTK_WIDGET (display));
+			gtk_widget_queue_draw (widget);
 
-static void
-mail_display_on_web_view_sw_hadjustment_changed (GtkAdjustment* adjustment,
-                                                 gpointer user_data)
-{
-        GtkWidget *scrolled_window = user_data;
-        GtkWidget *vscrollbar;
-        GtkWidget *web_view;
-        gint new_width, height;
-
-        web_view = gtk_bin_get_child (GTK_BIN (scrolled_window));
-        gtk_widget_get_preferred_width (web_view, NULL, &new_width);
-
-        vscrollbar = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (scrolled_window));
-        if (vscrollbar && gtk_widget_get_visible (vscrollbar)) {
-                gint scrollbar_width;
-                gtk_widget_get_preferred_width (vscrollbar, &scrollbar_width, NULL);
-                new_width += scrollbar_width;
-        }
+			return;
+		}
 
-        gtk_widget_get_size_request (scrolled_window, NULL, &height);
-        gtk_widget_set_size_request (scrolled_window, new_width, height);
+		g_free (uri);
+	}
 }
 
 
 static void
-mail_display_on_web_view_sw_vadjustment_changed (GtkAdjustment* adjustment,
-						 gpointer user_data)
+mail_display_plugin_widget_realized (GtkWidget *widget,
+				     gpointer user_data)
 {
-	GtkWidget *scrolled_window = user_data;
-	GtkWidget *hscrollbar;
-	GtkWidget *web_view;
-	gint new_height, width;
-
-	web_view = gtk_bin_get_child (GTK_BIN (scrolled_window));
-	gtk_widget_get_preferred_height (web_view, &new_height, NULL);
-
-	/* We now have height of the webview's view, but to correctly resize the
-	 * parent scrolled window we need to add height of horizontal scrollbar (if visible) */
-	hscrollbar = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (scrolled_window));
-	if (hscrollbar && gtk_widget_get_visible (hscrollbar)) {
-		gint scrollbar_height;
-		gtk_widget_get_preferred_height (hscrollbar, &scrollbar_height, NULL);
-		new_height += scrollbar_height;
-	}
-
-	gtk_widget_get_size_request (scrolled_window, &width, NULL);
-	gtk_widget_set_size_request (scrolled_window, width, new_height);
+	mail_display_plugin_widget_resize (widget, NULL, user_data);
 }
 
 static GtkWidget*
-mail_display_insert_web_view (EMailDisplay *display,
-			      EWebView *web_view)
+mail_display_plugin_widget_requested (WebKitWebView *web_view,
+                                      gchar *mime_type,
+                                      gchar *uri,
+                                      GHashTable *param,
+                                      gpointer user_data)
 {
-	GtkWidget *scrolled_window;
-	GtkAdjustment *adjustment;
-        GdkWindow *window;
-
-	display->priv->webviews = g_list_append (display->priv->webviews, web_view);
-	scrolled_window = gtk_scrolled_window_new (NULL, NULL);
-	g_object_set (G_OBJECT (scrolled_window),
-		"vexpand", FALSE,
-		"vexpand-set", TRUE,
-                "hexpand", FALSE,
-                "hexpand-set", TRUE,
-                "shadow-type", GTK_SHADOW_NONE,
-		NULL);
-
-	adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window));
-	g_signal_connect (G_OBJECT (adjustment), "changed",
-		G_CALLBACK (mail_display_on_web_view_sw_vadjustment_changed), scrolled_window);
-
-        adjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (scrolled_window));
-        g_signal_connect (G_OBJECT (adjustment), "changed",
-                G_CALLBACK (mail_display_on_web_view_sw_hadjustment_changed), scrolled_window);
-	
-	gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
+        EMFormat *emf;
+        EMailDisplay *display;
+        EMFormatPURI *puri;
+        GtkWidget *widget;
+        gchar *puri_uri;
 
-        gtk_box_pack_start (GTK_BOX (display->priv->box), scrolled_window, FALSE, TRUE, 0);
-	gtk_widget_show_all (scrolled_window);
+        puri_uri = g_hash_table_lookup (param, "data");
+        if (!puri_uri || !g_str_has_prefix (uri, "mail://"))
+                return NULL;
 
-        /* Enable enter-notify event */
-        window = gtk_widget_get_window (GTK_WIDGET (web_view));
-        if (!(gdk_window_get_events (window) & GDK_ENTER_NOTIFY_MASK)) {
-              gdk_window_set_events (window,
-                      gdk_window_get_events (window) | GDK_ENTER_NOTIFY_MASK);
-        }
-
-        return scrolled_window;
-}
-
-static void
-mail_display_load_as_source (EMailDisplay *display,
-			     const gchar *msg_uid)
-{
-	EWebView *web_view;
-	EMFormat *emf = (EMFormat *) display->priv->formatter;
-	gchar *uri;
+        d(printf("Created widget %s\n", puri_uri));
 
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
+        display = E_MAIL_DISPLAY (web_view);
+        emf = (EMFormat *) display->priv->formatter;
 
-	e_mail_display_clear (display);
-
-	web_view = mail_display_setup_webview (display, TRUE);
-	mail_display_insert_web_view (display, web_view);
+	puri = em_format_find_puri (emf, puri_uri);
+        if (!puri) {
+                return NULL;
+	}
 
-	uri = em_format_build_mail_uri (emf->folder, emf->message_uid,
-		"part_id", G_TYPE_STRING, ".message",
-		"mode", G_TYPE_INT, display->priv->mode,
-		NULL);
-	e_web_view_load_uri (web_view, uri);
+        if (puri->widget_func)
+		widget = puri->widget_func (emf, puri, NULL);
+	else
+		widget = NULL;
+
+	if (widget) {
+		gtk_widget_show (widget);
+		g_object_set_data_full (G_OBJECT (widget), "uri",
+			g_strdup (puri_uri), (GDestroyNotify) g_free);
+
+		/* Ensure that WebKit will resize <object> element by calling
+		 * gtk_widget_set_size_request() of the widget. */
+		g_signal_connect (widget, "size-allocate",
+			G_CALLBACK (mail_display_plugin_widget_resize), display);
+		g_signal_connect (widget, "realize",
+			G_CALLBACK (mail_display_plugin_widget_realized), display);
+	}
 
-	gtk_widget_show_all (display->priv->box);
+        return widget;
 }
 
 static void
-mail_display_load_normal (EMailDisplay *display,
-			  const gchar *msg_uri)
+mail_display_headers_collapsed_state_changed (EWebView *web_view,
+					      size_t arg_count,
+					      const JSValueRef args[],
+					      gpointer user_data)
 {
-	EWebView *web_view;
-	EMFormatPURI *puri;
-	EMFormat *emf = (EMFormat *) display->priv->formatter;
-	EAttachmentView *attachment_view;
-	gchar *uri;
-	GList *iter;
-	GtkBox *box;
-        gchar *start_part_id;
-        GtkWidget *attachment_button;
-
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
-
-	/* Don't use gtk_widget_show_all() to display all widgets at once,
-	   it makes all parts of EMailAttachmentBar visible and that's not
-	   what we want.
-	   FIXME: Maybe using gtk_widget_set_no_show_all() in EAttachmentView
-	          could help...
-	*/
-
-	/* First remove all widgets left after previous message */
-	e_mail_display_clear (display);
-        attachment_view = NULL;
-        attachment_button = NULL;
-
-	box = GTK_BOX (display->priv->box);
-	gtk_widget_show (display->priv->box);
-
-        /* If msg_uri contains part_id, then find it and start 'writing' from
-         * this part_id. When there's no part_id or it's invalid, start from first
-         * PURI in the list. */
-        if ((start_part_id = strstr (msg_uri, "part_id=")) != NULL) {
-                gchar *end_part_id;
-                start_part_id = start_part_id + strlen("part_id=");
-                end_part_id = strstr (start_part_id, "&");
-                if (!end_part_id)
-                        start_part_id = g_strdup (start_part_id);
-                else
-                        start_part_id = g_strndup (start_part_id, end_part_id - start_part_id);
-
-                iter = g_hash_table_lookup (emf->mail_part_table, start_part_id);
-                if (!iter)
-                        iter = emf->mail_part_list;
-                else
-                        iter = iter->next; /* Prevent endless recursion */
-        } else {
-                iter = emf->mail_part_list;
-        }
-
-        g_free (start_part_id);
-
-        for (iter = iter; iter; iter = iter->next) {
-		GtkWidget *widget = NULL;
-
-		puri = iter->data;
-
-                if (g_str_has_suffix (puri->uri, ".end"))
-                        break;
-
-		uri = em_format_build_mail_uri (emf->folder, emf->message_uid,
-			"part_id", G_TYPE_STRING, puri->uri,
-			"mode", G_TYPE_INT, display->priv->mode,
-			"headers_collapsable", G_TYPE_BOOLEAN, display->priv->headers_collapsable,
-			"headers_collapsed", G_TYPE_BOOLEAN, display->priv->headers_collapsed,
-			NULL);
-
-		if (puri->widget_func) {
-                        gboolean expandible = FALSE;
-
-			widget = puri->widget_func (emf, puri, NULL);
-                        d(printf("%p: added %s for PURI %s\n", 
-                                   display, G_OBJECT_TYPE_NAME (widget), puri->uri));
-
-			if (!GTK_IS_WIDGET (widget)) {
-				g_message ("Part %s didn't provide a valid widget, skipping!", puri->uri);
-                                g_free (uri);
-				continue;
-			}
-
-                        gtk_box_pack_start (box, widget, FALSE, TRUE, 0);
-			if (attachment_button) {
-
-                                /* If attachment_button is set and it was followed by
-                                 * another attachment button, then something is wrong.
-                                 * Make the previous button unexpandable and continue */
-                                if (E_IS_ATTACHMENT_BUTTON (widget)) {
-                                        e_attachment_button_set_expandable (
-                                                E_ATTACHMENT_BUTTON (attachment_button), FALSE);
-
-                                } else {
-                                        g_object_bind_property (attachment_button, "expanded",
-                                                widget, "visible", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
-                                        e_attachment_button_set_expandable (
-                                                E_ATTACHMENT_BUTTON (attachment_button), TRUE);
-                                        attachment_button = NULL;
-                                        expandible = TRUE;
-                                }
-                        }
-
-			if (E_IS_ATTACHMENT_BUTTON (widget) && attachment_view) {
-				e_attachment_button_set_view (E_ATTACHMENT_BUTTON (widget),
-					attachment_view);
-                                attachment_button = widget;
-                        }
-
-			if (E_IS_ATTACHMENT_VIEW (widget)) {
-				EAttachmentStore *store;
-
-				attachment_view = E_ATTACHMENT_VIEW (widget);
-				store = e_attachment_view_get_store (attachment_view);
-
-				if (e_attachment_store_get_num_attachments (store) > 0)
-					gtk_widget_show (widget);
-				else
-					gtk_widget_hide (widget);
-                                g_free (uri);
-                                continue;
-
-                        } else if (E_IS_MAIL_DISPLAY (widget)) {
-                                EMFormatPURI *iter_puri;
-
-                                if (!expandible)
-                                        gtk_widget_show (widget);
-
-                                /* Find the PURI with ".end" suffix and continue writing
-                                the message from following PURI */
-                                do {
-                                        iter = iter->next;
-                                        if (iter)
-                                                iter_puri = iter->data;
-                                } while (iter && (!g_str_has_suffix (iter_puri->uri, ".end")));
-
-                                g_free (uri);
-                                continue;
-
-                        } else {
-                                gtk_widget_show (widget);
-                        }
-		}
-
-		if ((!puri->is_attachment && puri->write_func) || (puri->is_attachment && puri->write_func && puri->widget_func)) {
-                        GtkWidget *container;
-
-                        web_view = mail_display_setup_webview (display, g_str_has_suffix (puri->uri, ".headers"));
-			container = mail_display_insert_web_view (display, web_view);
-
-                        e_web_view_load_uri (web_view, uri);
-
-                        if (attachment_button) {
-				g_object_bind_property (widget, "expanded",
-					container, "visible", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
-                                attachment_button = NULL;
-			}
+	JSGlobalContextRef ctx = e_web_view_get_global_context (web_view);
 
-                        d(printf("%p: added EWebView for PURI %s\n", display, puri->uri));
-		}
+	e_mail_display_set_headers_collapsed (E_MAIL_DISPLAY (web_view),
+                JSValueToBoolean (ctx, args[0]));
+}
 
-		g_free (uri);
-	}
+static void
+mail_display_install_js_callbacks (WebKitWebView *web_view,
+			           WebKitWebFrame *frame,
+				   gpointer context,
+				   gpointer window_object,
+				   gpointer user_data)
+{
+	if (frame != webkit_web_view_get_main_frame (web_view))
+		return;
 
-	/* If we created an attachment_button but didn't attach any widget to it,
-         * then make sure it's not expandable. */
-	if (attachment_button) {
-                e_attachment_button_set_expandable (
-                        E_ATTACHMENT_BUTTON (attachment_button), FALSE);
-        }
+	e_web_view_install_js_callback (E_WEB_VIEW (web_view), "headers_collapsed",
+		(EWebViewJSFunctionCallback) mail_display_headers_collapsed_state_changed, user_data);
 }
 
 static void
-mail_display_class_init (EMailDisplayClass *class)
+e_mail_display_class_init (EMailDisplayClass *class)
 {
 	GObjectClass *object_class;
 	GtkWidgetClass *widget_class;
@@ -1064,81 +721,19 @@ mail_display_class_init (EMailDisplayClass *class)
 			NULL,
 			FALSE,
 			G_PARAM_READWRITE));
-
-        g_object_class_install_property (
-                object_class,
-                PROP_CARET_MODE,
-                g_param_spec_boolean (
-                        "caret-mode",
-                        "Caret Mode",
-                        NULL,
-                        FALSE,
-                        G_PARAM_READWRITE));
-
-	g_object_class_install_property (
-		object_class,
-		PROP_ZOOM_LEVEL,
-		g_param_spec_float (
-			"zoom-level",
-			"Zoom Level",
-			NULL,
-			G_MINFLOAT,
-			G_MAXFLOAT,
-			1.0,
-			G_PARAM_READWRITE));
-			
-
-	signals[POPUP_EVENT] = g_signal_new (
-		"popup-event",
-		G_TYPE_FROM_CLASS (class),
-		G_SIGNAL_RUN_LAST,
-		G_STRUCT_OFFSET (EMailDisplayClass, popup_event),
-		g_signal_accumulator_true_handled, NULL,
-		e_marshal_BOOLEAN__BOXED_STRING,
-		G_TYPE_BOOLEAN, 2,
-		GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
-		G_TYPE_STRING);
-
-	signals[STATUS_MESSAGE] = g_signal_new (
-		"status-message",
-		G_TYPE_FROM_CLASS (class),
-		G_SIGNAL_RUN_LAST,
-		G_STRUCT_OFFSET (EMailDisplayClass, status_message),
-		NULL, NULL,
-		g_cclosure_marshal_VOID__STRING,
-		G_TYPE_NONE, 1,
-		G_TYPE_STRING);
 }
 
 static void
-mail_display_init (EMailDisplay *display)
+e_mail_display_init (EMailDisplay *display)
 {
-	SoupSession *session;
+        GtkUIManager *ui_manager;
+        GError *error = NULL;
+        SoupSession *session;
 	SoupSessionFeature *feature;
 	const gchar *user_cache_dir;
 
 	display->priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
 
-	display->priv->settings = e_web_view_get_default_settings (GTK_WIDGET (display));
-	g_object_bind_property (display, "caret-mode",
-		display->priv->settings, "enable-caret-browsing", 
-		G_BINDING_SYNC_CREATE);
-        g_object_set (display->priv->settings,
-                "enable-scripts", FALSE, NULL);
-
-        display->priv->headers_settings = e_web_view_get_default_settings (GTK_WIDGET (display));
-        g_object_bind_property (display, "caret-mode",
-                display->priv->settings, "enable-caret-browsing",
-                G_BINDING_SYNC_CREATE);
-
-	
-
-	display->priv->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
-        gtk_container_set_reallocate_redraws (GTK_CONTAINER (display->priv->box), TRUE);
-	gtk_container_add (GTK_CONTAINER (display), display->priv->box);
-
-	display->priv->webviews = NULL;
-
         display->priv->force_image_load = FALSE;
 	display->priv->mailto_actions = gtk_action_group_new ("mailto");
 	gtk_action_group_add_actions (display->priv->mailto_actions, mailto_entries, 
@@ -1148,8 +743,41 @@ mail_display_init (EMailDisplay *display)
         gtk_action_group_add_actions (display->priv->images_actions, image_entries,
                 G_N_ELEMENTS (image_entries), NULL);
 
+        webkit_web_view_set_full_content_zoom (WEBKIT_WEB_VIEW (display), TRUE);
+
+        g_signal_connect (display, "navigation-policy-decision-requested",
+                          G_CALLBACK (mail_display_link_clicked), NULL);
+        g_signal_connect (display, "window-object-cleared",
+                          G_CALLBACK (mail_display_install_js_callbacks), NULL);
+        g_signal_connect (display, "resource-request-starting",
+                          G_CALLBACK (mail_display_resource_requested), NULL);
+        g_signal_connect (display, "process-mailto",
+                          G_CALLBACK (mail_display_process_mailto), NULL);
+        g_signal_connect (display, "update-actions",
+                          G_CALLBACK (mail_display_webview_update_actions), NULL);
+        g_signal_connect (display, "create-plugin-widget",
+                          G_CALLBACK (mail_display_plugin_widget_requested), NULL);
+
+        /* Because we are loading from a hard-coded string, there is
+         * no chance of I/O errors.  Failure here implies a malformed
+         * UI definition.  Full stop. */
+        ui_manager = e_web_view_get_ui_manager (E_WEB_VIEW (display));
+        gtk_ui_manager_insert_action_group (ui_manager, display->priv->mailto_actions, 0);
+        gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, &error);
 
-	/* WEBKIT TODO: ESearchBar */
+        if (error != NULL) {
+                g_error ("%s", error->message);
+                g_error_free (error);
+        }
+
+        error = NULL;
+        gtk_ui_manager_insert_action_group (ui_manager, display->priv->images_actions, 0);
+        gtk_ui_manager_add_ui_from_string (ui_manager, image_ui, -1, &error);
+
+        if (error != NULL) {
+                g_error ("%s", error->message);
+                g_error_free (error);
+        }
 
 	/* Register our own handler for our own mail:// protocol */
 	session = webkit_get_default_session ();
@@ -1167,32 +795,6 @@ mail_display_init (EMailDisplay *display)
 	}
 }
 
-GType
-e_mail_display_get_type (void)
-{
-	static GType type = 0;
-
-	if (G_UNLIKELY (type == 0)) {
-		static const GTypeInfo type_info = {
-			sizeof (EMailDisplayClass),
-			(GBaseInitFunc) NULL,
-			(GBaseFinalizeFunc) NULL,
-			(GClassInitFunc) mail_display_class_init,
-			(GClassFinalizeFunc) NULL,
-			NULL,  /* class_data */
-			sizeof (EMailDisplay),
-			0,     /* n_preallocs */
-			(GInstanceInitFunc) mail_display_init,
-			NULL   /* value_table */
-		};
-
-		type = g_type_register_static (
-			GTK_TYPE_VIEWPORT, "EMailDisplay", &type_info, 0);
-	}
-
-	return type;
-}
-
 EMFormatHTML *
 e_mail_display_get_formatter (EMailDisplay *display)
 {
@@ -1251,10 +853,7 @@ e_mail_display_set_mode (EMailDisplay *display,
 		return;
 
 	display->priv->mode = mode;
-	if (mode == EM_FORMAT_WRITE_MODE_SOURCE)
-		mail_display_load_as_source (display, NULL);
-	else
-		e_mail_display_reload (display);
+        e_mail_display_reload (display);
 
 	g_object_notify (G_OBJECT (display), "mode");
 }
@@ -1311,74 +910,72 @@ void
 e_mail_display_load (EMailDisplay *display,
 		     const gchar *msg_uri)
 {
+        EMFormat *emf;
+        gchar *uri;
+
+        g_return_if_fail (E_IS_MAIL_DISPLAY (display));
+
         display->priv->force_image_load = FALSE;
 
-	if (display->priv->mode == EM_FORMAT_WRITE_MODE_SOURCE)
-		mail_display_load_as_source  (display, msg_uri);
-	else
-		mail_display_load_normal (display, msg_uri);
+        emf = EM_FORMAT (display->priv->formatter);
+
+        uri = em_format_build_mail_uri (emf->folder, emf->message_uid,
+                "mode", G_TYPE_INT, display->priv->mode,
+                "headers_collapsable", G_TYPE_BOOLEAN, display->priv->headers_collapsable,
+                "headers_collapsed", G_TYPE_BOOLEAN, display->priv->headers_collapsed,
+                NULL);
+
+        e_web_view_load_uri (E_WEB_VIEW (display), uri);
 }
 
 void
 e_mail_display_reload (EMailDisplay *display)
 {
-	GList *iter;
+        EWebView *web_view;
+        const gchar *uri;
+        gchar *base;
+        GString *new_uri;
+        GHashTable *table;
+        GHashTableIter table_iter;
+        gpointer key, val;
+        char separator;
 
 	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
-	/* We can't just call e_web_view_reload() here, we need the URI queries
-	   to reflect possible changes in write mode and headers properties.
-	   Unfortunatelly, nothing provides API good enough to do this more
-	   simple way... */
-
-	for (iter = display->priv->webviews; iter; iter = iter->next) {
-		EWebView *web_view;
-		const gchar *uri;
-		gchar *base;
-		GString *new_uri;
-		GHashTable *table;
-		GHashTableIter table_iter;
-		gpointer key, val;
-		char separator;
-
-		web_view = (EWebView *) iter->data;
-		uri = e_web_view_get_uri (web_view);
-
-		if (!uri)
-			continue;
-
-		base = g_strndup (uri, strstr (uri, "?") - uri);
-		new_uri = g_string_new (base);
-		g_free (base);
-
-		table = soup_form_decode (strstr (uri, "?") + 1);
-		g_hash_table_insert (table, g_strdup ("mode"), g_strdup_printf ("%d", display->priv->mode));
-		g_hash_table_insert (table, g_strdup ("headers_collapsable"), g_strdup_printf ("%d", display->priv->headers_collapsable));
-		g_hash_table_insert (table, g_strdup ("headers_collapsed"), g_strdup_printf ("%d", display->priv->headers_collapsed));
-
-		g_hash_table_iter_init (&table_iter, table);
-		separator = '?';
-		while (g_hash_table_iter_next (&table_iter, &key, &val)) {
-			g_string_append_printf (new_uri, "%c%s=%s", separator,
-				(gchar *) key, (gchar *) val);
-
-			if (separator == '?')
-				separator = '&';
-		}
+	web_view = E_WEB_VIEW (display);
+	uri = e_web_view_get_uri (web_view);
 
-		e_web_view_load_uri (web_view, new_uri->str);
+	if (!uri)
+		return;
 
-		g_string_free (new_uri, TRUE);
-		g_hash_table_destroy (table);
+	if (strstr(uri, "?") == NULL) {
+		e_web_view_reload (web_view);
+		return;
 	}
-}
 
-EWebView*
-e_mail_display_get_current_web_view (EMailDisplay *display)
-{
-	g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), NULL);
+	base = g_strndup (uri, strstr (uri, "?") - uri);
+	new_uri = g_string_new (base);
+	g_free (base);
+
+        table = soup_form_decode (strstr (uri, "?") + 1);
+	g_hash_table_insert (table, g_strdup ("mode"), g_strdup_printf ("%d", display->priv->mode));
+	g_hash_table_insert (table, g_strdup ("headers_collapsable"), g_strdup_printf ("%d", display->priv->headers_collapsable));
+	g_hash_table_insert (table, g_strdup ("headers_collapsed"), g_strdup_printf ("%d", display->priv->headers_collapsed));
+
+	g_hash_table_iter_init (&table_iter, table);
+	separator = '?';
+	while (g_hash_table_iter_next (&table_iter, &key, &val)) {
+		g_string_append_printf (new_uri, "%c%s=%s", separator,
+			(gchar *) key, (gchar *) val);
 
-        return E_WEB_VIEW (display->priv->current_webview);
+        if (separator == '?')
+		separator = '&';
+	}
+
+	e_web_view_load_uri (web_view, new_uri->str);
+
+	g_string_free (new_uri, TRUE);
+	g_hash_table_destroy (table);
 }
 
 GtkAction*
@@ -1401,62 +998,29 @@ void
 e_mail_display_set_status (EMailDisplay *display,
 			   const gchar *status)
 {
-	GtkWidget *label;
-
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
-
-	e_mail_display_clear (display);
-
-	label = gtk_label_new (status);
-        gtk_box_pack_start (GTK_BOX (display->priv->box), label, TRUE, TRUE, 0);
-	gtk_widget_show_all (display->priv->box);
-}
-
-static void
-remove_widget (GtkWidget *widget, gpointer user_data)
-{
-	EMailDisplay *display = user_data;
-
-	if (!GTK_IS_WIDGET (widget))
-		return;
-
-	gtk_container_remove  (GTK_CONTAINER (display->priv->box), widget);
-}
+        gchar *str;
 
-void
-e_mail_display_clear (EMailDisplay *display)
-{
 	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
-	gtk_widget_hide (display->priv->box);
-
-	gtk_container_foreach (GTK_CONTAINER (display->priv->box),
-		(GtkCallback) remove_widget, display);
-
-	g_list_free (display->priv->webviews);
-	display->priv->webviews = NULL;
-}
-
-ESearchBar*
-e_mail_display_get_search_bar (EMailDisplay *display)
-{
-	g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), NULL);
-
-	return display->priv->searchbar;
-}
-
-gboolean
-e_mail_display_is_selection_active (EMailDisplay *display)
-{
-	EWebView *web_view;
-
-	g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), FALSE);
-
-	web_view = e_mail_display_get_current_web_view (display);
-	if (!web_view)
-		return FALSE;
-	else
-		return e_web_view_is_selection_active (web_view);
+        str = g_strdup_printf(
+                "<!DOCTYPE>"
+                "<html>"
+                  "<head><title>Evolution Mail Display</title></head>"
+                  "<body>"
+                    "<table border=\"0\" width=\"100%%\" height=\"100%%\">"
+                      "<tr height=\"100%%\" valign=\"middle\">"
+                        "<td width=\"100%%\" align=\"center\">"
+                          "<strong>%s</strong>"
+                        "</td>"
+                      "</tr>"
+                    "</table>"
+                  "</body>"
+                "</html>", status);
+
+        e_web_view_load_string (E_WEB_VIEW (display), str);
+        g_free (str);
+
+	gtk_widget_show_all (GTK_WIDGET (display));
 }
 
 gchar*
@@ -1472,10 +1036,7 @@ e_mail_display_get_selection_plain_text (EMailDisplay *display,
 
 	g_return_val_if_fail (E_IS_MAIL_DISPLAY (display), NULL);
 
-	web_view = e_mail_display_get_current_web_view (display);
-	if (!web_view)
-		return NULL;
-
+	web_view = E_WEB_VIEW (display);
 	frame = webkit_web_view_get_focused_frame (WEBKIT_WEB_VIEW (web_view));
 	frame_name = webkit_web_frame_get_name (frame);
 
@@ -1491,96 +1052,10 @@ e_mail_display_get_selection_plain_text (EMailDisplay *display,
 }
 
 void
-e_mail_display_zoom_100 (EMailDisplay *display)
-{
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
-
-	display->priv->zoom_level = 1.0;
-
-	g_object_notify (G_OBJECT (display), "zoom-level");
-}
-
-void
-e_mail_display_zoom_in (EMailDisplay *display)
-{
-	gfloat step;
-
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
-
-	g_object_get (G_OBJECT (display->priv->settings), 
-		"zoom-step", &step, NULL);
-
-	display->priv->zoom_level += step;
-
-	g_object_notify (G_OBJECT (display), "zoom-level");
-}
-
-void
-e_mail_display_zoom_out (EMailDisplay *display)
-{
-	float step;
-
-	g_return_if_fail (E_IS_MAIL_DISPLAY (display));
-
-	g_object_get (G_OBJECT (display->priv->settings),
-		"zoom-step", &step, NULL);
-
-	display->priv->zoom_level -= step;
-
-	g_object_notify (G_OBJECT (display), "zoom-level");
-}
-
-static void
-load_images (GtkWidget *widget,
-             gpointer user_data)
-{
-        if (GTK_IS_SCROLLED_WINDOW (widget)) {
-
-                EWebView *web_view;
-
-                if (!E_IS_WEB_VIEW (gtk_bin_get_child (GTK_BIN (widget))))
-                  return;
-
-                web_view = E_WEB_VIEW (gtk_bin_get_child (GTK_BIN (widget)));
-                e_web_view_reload (web_view);
-
-        } else if (E_IS_MAIL_DISPLAY (widget)) {
-
-                e_mail_display_load_images (E_MAIL_DISPLAY (widget));
-
-        }
-}
-
-void
 e_mail_display_load_images (EMailDisplay * display)
 {
         g_return_if_fail (E_IS_MAIL_DISPLAY (display));
 
         display->priv->force_image_load = TRUE;
-
-        gtk_container_foreach (GTK_CONTAINER (display->priv->box),
-                        (GtkCallback) load_images, NULL);
-}
-
-
-void
-e_mail_display_scroll (EMailDisplay* display,
-                       GdkScrollDirection direction)
-{
-        GtkAdjustment *vadjustment;
-        gint d;
-        gdouble step;
-
-        g_return_if_fail (E_IS_MAIL_DISPLAY (display));
-        g_return_if_fail ((direction == GDK_SCROLL_UP) || (direction == GDK_SCROLL_DOWN));
-
-        vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (display));
-
-        if (gtk_adjustment_get_upper (vadjustment) == 0)
-                return;
-
-        d = (direction == GDK_SCROLL_DOWN) ? 1 : -1;
-        step = d * gtk_adjustment_get_page_increment (vadjustment);
-        gtk_adjustment_set_value (vadjustment,
-                gtk_adjustment_get_value (vadjustment) + step);
+        e_web_view_reload (E_WEB_VIEW (display));
 }
diff --git a/mail/e-mail-display.h b/mail/e-mail-display.h
index ec0e64a..37a1c8c 100644
--- a/mail/e-mail-display.h
+++ b/mail/e-mail-display.h
@@ -52,19 +52,13 @@ typedef struct _EMailDisplayClass EMailDisplayClass;
 typedef struct _EMailDisplayPrivate EMailDisplayPrivate;
 
 struct _EMailDisplay {
-	GtkViewport parent;
+	EWebView web_view;
 	EMailDisplayPrivate *priv;
 };
 
 struct _EMailDisplayClass {
-	GtkViewportClass parent_class;
+	EWebViewClass parent_class;
 
-	void		(*status_message)		(EMailDisplay *display,
-							 const gchar *message);
-
-	gboolean	(*popup_event)			(EMailDisplay *display,
-							 GdkEventButton *event,
-							 const gchar *uri);
 };
 
 GType			e_mail_display_get_type		(void);
@@ -90,38 +84,18 @@ void			e_mail_display_load		(EMailDisplay *display,
 						 	 const gchar *msg_uri);
 void			e_mail_display_reload		(EMailDisplay *display);
 
-EWebView *		e_mail_display_get_current_web_view
-							(EMailDisplay *display);
-
 GtkAction *		e_mail_display_get_action	(EMailDisplay *display,
 							 const gchar *action_name);
 
 void			e_mail_display_set_status	(EMailDisplay *display,
 							 const gchar *status);
-void			e_mail_display_clear		(EMailDisplay *display);
-
-ESearchBar*		e_mail_display_get_search_bar	(EMailDisplay *display);
-
-gboolean		e_mail_display_is_selection_active
-							(EMailDisplay *display);
 
 gchar*			e_mail_display_get_selection_plain_text
 							(EMailDisplay *display,
 							 gint *len);
 
-void                    e_mail_display_set_caret_mode   (EMailDisplay *display,
-                                                         gboolean caret_mode);
-gboolean                e_mail_display_get_caret_mode   (EMailDisplay *display);
-
-void			e_mail_display_zoom_100		(EMailDisplay *display);
-void			e_mail_display_zoom_in		(EMailDisplay *display);
-void			e_mail_display_zoom_out		(EMailDisplay *display);
-
 void                    e_mail_display_load_images      (EMailDisplay *display);
 
-void                    e_mail_display_scroll           (EMailDisplay *display,
-                                                         GdkScrollDirection direction);
-
 G_END_DECLS
 
 #endif /* E_MAIL_DISPLAY_H */
diff --git a/mail/e-mail-paned-view.c b/mail/e-mail-paned-view.c
index 941545c..9237a57 100644
--- a/mail/e-mail-paned-view.c
+++ b/mail/e-mail-paned-view.c
@@ -61,7 +61,6 @@ struct _EMailPanedViewPrivate {
 	GtkWidget *preview_pane;
 	GtkWidget *search_bar;
 
-	GtkWidget *display_scrolled_window;
 	EMailDisplay *display;
 	GalViewInstance *view_instance;
 
@@ -633,14 +632,6 @@ mail_paned_view_constructed (GObject *object)
 	priv->display = g_object_new (E_TYPE_MAIL_DISPLAY,
 		"headers-collapsable", TRUE, NULL);
 
-	widget = gtk_scrolled_window_new (NULL, NULL);
-	gtk_scrolled_window_set_shadow_type (
-		GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_NONE);
-	gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (priv->display));
-	priv->display_scrolled_window = widget;
-	gtk_widget_show (GTK_WIDGET (priv->display));
-
-
 	view = E_MAIL_VIEW (object);
 	shell_view = e_mail_view_get_shell_view (view);
 	shell_window = e_shell_view_get_shell_window (shell_view);
@@ -690,9 +681,10 @@ mail_paned_view_constructed (GObject *object)
 
 	container = priv->paned;
 
-	widget = GTK_WIDGET (priv->display_scrolled_window);
+        widget = e_preview_pane_new (E_WEB_VIEW (priv->display));
 	gtk_paned_pack2 (GTK_PANED (container), widget, FALSE, FALSE);
 	priv->preview_pane = g_object_ref (widget);
+        gtk_widget_show (GTK_WIDGET (priv->display));
 	gtk_widget_show (widget);
 
 	g_object_bind_property (
@@ -700,15 +692,10 @@ mail_paned_view_constructed (GObject *object)
 		widget, "visible",
 		G_BINDING_SYNC_CREATE);
 
-	/* FIXME WEBKIT: Searchbar!!! */
-	search_bar = e_mail_display_get_search_bar (priv->display);
-	if (search_bar) {
-		priv->search_bar = g_object_ref (search_bar);
-
-		g_signal_connect_swapped (
-				search_bar, "changed",
-				G_CALLBACK (e_mail_display_reload), priv->display);
-	}
+	search_bar = e_preview_pane_get_search_bar (E_PREVIEW_PANE (widget));
+	g_signal_connect_swapped (
+		search_bar, "changed",
+		G_CALLBACK (e_mail_display_reload), priv->display);
 
 	/* Load the view instance. */
 
diff --git a/mail/e-mail-printer.c b/mail/e-mail-printer.c
index dc2f5f7..934ac12 100644
--- a/mail/e-mail-printer.c
+++ b/mail/e-mail-printer.c
@@ -164,7 +164,7 @@ emp_run_print_operation (EMailPrinter *emp,
 	formatters = g_object_get_data (G_OBJECT (session), "formatters");
 	g_hash_table_insert (formatters, g_strdup (mail_uri), emp->priv->efhp);
 
-	/* Print_layout is a special PURI created by EMFormatHTMLPrint */
+	/* Print_layout is a special EMPart created by EMFormatHTMLPrint */
         if (emp->priv->uri)
                 g_free (emp->priv->uri);
         emp->priv->uri = g_strconcat (mail_uri, "?part_id=print_layout", NULL);
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 68092d3..ffd677a 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -819,7 +819,7 @@ e_mail_reader_reply_to_message (EMailReader *reader,
 	shell_backend = E_SHELL_BACKEND (backend);
 	shell = e_shell_backend_get_shell (shell_backend);
 
-	web_view = e_mail_display_get_current_web_view (display);
+	web_view = E_WEB_VIEW (display);
 
 	if (reply_type == E_MAIL_REPLY_TO_RECIPIENT) {
 		const gchar *uri;
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index 7f38b1b..00f27dd 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -203,7 +203,6 @@ action_add_to_address_book_cb (GtkAction *action,
 	EShell *shell;
 	EMailBackend *backend;
 	EShellBackend *shell_backend;
-	EMailDisplay *display;
 	CamelInternetAddress *cia;
 	EWebView *web_view;
 	CamelURL *curl;
@@ -213,10 +212,9 @@ action_add_to_address_book_cb (GtkAction *action,
 	/* This action is defined in EMailDisplay. */
 
 	backend = e_mail_reader_get_backend (reader);
-	display = e_mail_reader_get_mail_display (reader);
 
-	web_view = e_mail_display_get_current_web_view (display);
-	if (!E_IS_WEB_VIEW (web_view))
+	web_view = E_WEB_VIEW (e_mail_reader_get_mail_display (reader));
+        if (!web_view)
 		return;
 
 	uri = e_web_view_get_selected_uri (web_view);
@@ -283,7 +281,7 @@ action_mail_image_save_cb (GtkAction *action,
         GFile *file;
 
         display = e_mail_reader_get_mail_display (reader);
-        web_view = e_mail_display_get_current_web_view (display);
+        web_view = E_WEB_VIEW (display);
 
         if (!E_IS_WEB_VIEW (web_view))
                 return;
@@ -1788,7 +1786,7 @@ action_mail_zoom_100_cb (GtkAction *action,
 
 	display = e_mail_reader_get_mail_display (reader);
 
-	e_mail_display_zoom_100 (display);
+	webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW (display), 1.0);
 }
 
 static void
@@ -1799,7 +1797,7 @@ action_mail_zoom_in_cb (GtkAction *action,
 
 	display = e_mail_reader_get_mail_display (reader);
 
-	e_mail_display_zoom_in (display);
+        webkit_web_view_zoom_in (WEBKIT_WEB_VIEW (display));
 }
 
 static void
@@ -1810,7 +1808,7 @@ action_mail_zoom_out_cb (GtkAction *action,
 
 	display = e_mail_reader_get_mail_display (reader);
 
-	e_mail_display_zoom_out (display);
+        webkit_web_view_zoom_out (WEBKIT_WEB_VIEW (display));
 }
 
 static void
@@ -1819,7 +1817,6 @@ action_search_folder_recipient_cb (GtkAction *action,
 {
 	EMailBackend *backend;
 	EMailSession *session;
-	EMailDisplay *display;
 	EWebView *web_view;
 	CamelFolder *folder;
 	CamelURL *curl;
@@ -1828,8 +1825,7 @@ action_search_folder_recipient_cb (GtkAction *action,
 	/* This action is defined in EMailDisplay. */
 
 	folder = e_mail_reader_get_folder (reader);
-	display = e_mail_reader_get_mail_display (reader);
-	web_view = e_mail_display_get_current_web_view (display);
+	web_view = E_WEB_VIEW (e_mail_reader_get_mail_display (reader));
 
 	uri = e_web_view_get_selected_uri (web_view);
 	g_return_if_fail (uri != NULL);
@@ -1859,7 +1855,6 @@ action_search_folder_sender_cb (GtkAction *action,
 {
 	EMailBackend *backend;
 	EMailSession *session;
-	EMailDisplay *display;
 	EWebView *web_view;
 	CamelFolder *folder;
 	CamelURL *curl;
@@ -1868,8 +1863,7 @@ action_search_folder_sender_cb (GtkAction *action,
 	/* This action is defined in EMailDisplay. */
 
 	folder = e_mail_reader_get_folder (reader);
-	display = e_mail_reader_get_mail_display (reader);
-	web_view = e_mail_display_get_current_web_view (display);
+	web_view = E_WEB_VIEW (e_mail_reader_get_mail_display (reader));
 
 	uri = e_web_view_get_selected_uri (web_view);
 	g_return_if_fail (uri != NULL);
@@ -2619,7 +2613,10 @@ mail_reader_message_seen_cb (EMailReaderClosure *closure)
 	current_uid = MESSAGE_LIST (message_list)->cursor_uid;
 	uid_is_current &= (g_strcmp0 (current_uid, message_uid) == 0);
 
-	message = EM_FORMAT (formatter)->message;
+        if (formatter)
+        	message = EM_FORMAT (formatter)->message;
+        else
+                message = NULL;
 
 	if (uid_is_current && message != NULL)
 		g_signal_emit (
@@ -2813,6 +2810,7 @@ mail_reader_message_selected_timeout_cb (EMailReader *reader)
 			g_free (string);
 
 			activity = e_mail_reader_new_activity (reader);
+                        e_activity_set_text (activity, _("Retrieving message"));
 			cancellable = e_activity_get_cancellable (activity);
 
 			closure = g_slice_new0 (EMailReaderClosure);
@@ -2990,7 +2988,7 @@ mail_reader_set_folder (EMailReader *reader,
 		em_utils_folder_is_outbox (folder) ||
 		em_utils_folder_is_sent (folder));
 
-	e_mail_display_clear (display);
+	e_web_view_clear (E_WEB_VIEW (display));
 
 	priv->folder_was_just_selected = (folder != NULL);
 
@@ -3042,19 +3040,27 @@ formatter_weak_ref_cb (struct _formatter_weak_ref_closure *data,
 	g_free (data);
 }
 
+struct format_parser_async_closure_ {
+        EMailDisplay *display;
+        EActivity *activity;
+};
+
 static void
 format_parser_async_done_cb (GObject *source,
                              GAsyncResult *result,
                              gpointer user_data)
 {
         EMFormat *emf = EM_FORMAT (source);
-        EMailReader *reader = user_data;
-        EMailDisplay *display;
+        struct format_parser_async_closure_ *closure = user_data;
 
-        display = e_mail_reader_get_mail_display (reader);
+        g_message ("format_parser_async_done for result %p", result);
+
+        e_mail_display_set_formatter (closure->display, EM_FORMAT_HTML (emf));
+        e_mail_display_load (closure->display, emf->uri_base);
 
-        e_mail_display_set_formatter (display, EM_FORMAT_HTML (emf));
-        e_mail_display_load (display, emf->uri_base);
+        g_object_unref (closure->activity);
+        g_object_unref (closure->display);
+        g_free (closure);
 
         /* Remove the reference added when formatter was created,
          * so that only owners are EMailDisplays */
@@ -3072,7 +3078,6 @@ mail_reader_message_loaded (EMailReader *reader,
 	EMailBackend *backend;
 	CamelFolder *folder;
 	EMailDisplay *display;
-	EWebView *web_view;
 	EShellBackend *shell_backend;
 	EShell *shell;
 	EMEvent *event;
@@ -3121,6 +3126,8 @@ mail_reader_message_loaded (EMailReader *reader,
 		struct _formatter_weak_ref_closure *formatter_data =
 			g_new0 (struct _formatter_weak_ref_closure, 1);
 
+                struct format_parser_async_closure_ *closure;
+
 		formatter_data->formatters = g_hash_table_ref (formatters);
 		formatter_data->mail_uri = g_strdup (mail_uri);
 
@@ -3135,9 +3142,14 @@ mail_reader_message_loaded (EMailReader *reader,
 
 		e_mail_reader_connect_headers (reader, formatter);
 
-		/* FIXME WEBKIT Not passing GCancellable */
+                closure = g_new0 (struct format_parser_async_closure_, 1);
+                closure->activity = e_mail_reader_new_activity (reader);
+                e_activity_set_text (closure->activity, _("Parsing message"));
+                closure->display = g_object_ref (display);
+
 		em_format_parse_async (formatter, message, folder,
-			NULL, format_parser_async_done_cb, reader);
+			e_activity_get_cancellable (closure->activity),
+                        format_parser_async_done_cb, closure);
 
 		g_hash_table_insert (formatters, mail_uri, formatter);
 		e_mail_display_set_formatter (display, EM_FORMAT_HTML (formatter));
@@ -3161,9 +3173,8 @@ mail_reader_message_loaded (EMailReader *reader,
 	    schedule_timeout_mark_seen (reader)) {
 		g_clear_error (&error);
 	} else if (error != NULL) {
-		web_view = e_mail_display_get_current_web_view (display);
 		e_alert_submit (
-			E_ALERT_SINK (web_view),
+			E_ALERT_SINK (display),
 			"mail:no-retrieve-message",
 			error->message, NULL);
 		g_error_free (error);
diff --git a/mail/e-mail-request.c b/mail/e-mail-request.c
index ea59a6d..31a5cc5 100644
--- a/mail/e-mail-request.c
+++ b/mail/e-mail-request.c
@@ -14,7 +14,7 @@
 #include <e-util/e-icon-factory.h>
 #include <e-util/e-util.h>
 
-#define d(x)
+#define d(x) x
 #define dd(x)
 
 G_DEFINE_TYPE (EMailRequest, e_mail_request, SOUP_TYPE_REQUEST)
@@ -45,6 +45,8 @@ handle_mail_request (GSimpleAsyncResult *res,
 	GInputStream *stream;
 	GByteArray *ba;
 	gchar *part_id;
+	EMFormatWriterInfo info = {0};
+	gchar *val;
 
 	if (g_cancellable_is_cancelled (cancellable))
 		return;
@@ -55,42 +57,36 @@ handle_mail_request (GSimpleAsyncResult *res,
 
 	request->priv->output_stream = camel_stream_mem_new ();
 
-	part_id = g_hash_table_lookup (request->priv->uri_query, "part_id");
+	val = g_hash_table_lookup (request->priv->uri_query, "headers_collapsed");
+	if (val)
+		info.headers_collapsed = atoi (val);
+
+	val = g_hash_table_lookup (request->priv->uri_query, "headers_collapsable");
+	if (val)
+		info.headers_collapsable = atoi (val);
 
+	val = g_hash_table_lookup (request->priv->uri_query, "mode");
+	if (val)
+		info.mode = atoi (val);
+
+	part_id = g_hash_table_lookup (request->priv->uri_query, "part_id");
 	if (part_id) {
                 /* original part_id is owned by the GHashTable */
                 part_id = soup_uri_decode (part_id);
 		request->priv->puri = em_format_find_puri (emf, part_id);
 
 		if (request->priv->puri) {
-			EMFormatWriterInfo info = {0};
-			gchar *val;
-
-			val = g_hash_table_lookup (request->priv->uri_query, "headers_collapsed");
-			if (val)
-				info.headers_collapsed = atoi (val);
-
-			val = g_hash_table_lookup (request->priv->uri_query, "headers_collapsable");
-			if (val)
-				info.headers_collapsable = atoi (val);
-
-			val = g_hash_table_lookup (request->priv->uri_query, "mode");
-			if (val)
-				info.mode = atoi (val);
-
-			val = g_hash_table_lookup (request->priv->uri_query, "with_html_headers");
-			if (val)
-				info.with_html_header = atoi (val);
-			else
-				info.with_html_header = TRUE; /* By default this is TRUE!! */
-
-			em_format_puri_write (request->priv->puri, request->priv->output_stream, &info, NULL);
+			em_format_puri_write (request->priv->puri,
+				request->priv->output_stream, &info, NULL);
 		} else {
 			g_warning ("Failed to lookup requested part '%s' - this should not happen!", part_id);
 		}
 
 		g_free (part_id);
-	}
+	} else {
+
+                em_format_write (emf, request->priv->output_stream, &info, NULL);
+        }
 
 	/* Convert the GString to GInputStream and send it back to WebKit */
 	ba = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (request->priv->output_stream));
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index d119695..6da565b 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -117,7 +117,12 @@ static GtkWidget* efhd_attachment_bar		(EMFormat *emf, EMFormatPURI *puri, GCanc
 static GtkWidget* efhd_attachment_button	(EMFormat *emf, EMFormatPURI *puri, GCancellable *cancellable);
 static GtkWidget* efhd_attachment_optional	(EMFormat *emf, EMFormatPURI *puri, GCancellable *cancellable);
 
+static void efhd_write_attachment_bar   (EMFormat *emf, EMFormatPURI *emp, CamelStream *stream, EMFormatWriterInfo *info, GCancellable *cancellable);
+static void efhd_write_attachment       (EMFormat *emf, EMFormatPURI *emp, CamelStream *stream, EMFormatWriterInfo *info, GCancellable *cancellable);
+static void efhd_write_secure_button    (EMFormat *emf, EMFormatPURI *emp, CamelStream *stream, EMFormatWriterInfo *info, GCancellable *cancellable);
+
 static void efhd_free_attach_puri_data (EMFormatPURI *puri);
+
 static void efhd_builtin_init (EMFormatHTMLDisplayClass *efhc);
 
 static gpointer parent_class;
@@ -501,6 +506,7 @@ efhd_parse_attachment (EMFormat *emf,
 	puri = (EMFormatAttachmentPURI*) em_format_puri_new (
 			emf, sizeof (EMFormatAttachmentPURI), part, part_id->str);
 	puri->puri.free = efhd_free_attach_puri_data;
+	puri->puri.write_func = efhd_write_attachment;
 	puri->puri.widget_func = efhd_attachment_button;
 	puri->shown = (handler && em_format_is_inline (emf, part_id->str, part, handler));
 	puri->snoop_mime_type = em_format_snoop_type (part);
@@ -607,6 +613,7 @@ efhd_parse_optional (EMFormat *emf,
 	puri = (EMFormatAttachmentPURI *) em_format_puri_new (
 			emf, sizeof (EMFormatAttachmentPURI), part, part_id->str);
 	puri->puri.free = efhd_free_attach_puri_data;
+	puri->puri.write_func = efhd_write_attachment;
 	puri->puri.widget_func = efhd_attachment_optional;
 	puri->attachment_view_part_id = g_strdup (part_id->str);
 	puri->handle = em_format_find_handler (emf, "text/plain");
@@ -649,6 +656,7 @@ efhd_parse_secure (EMFormat *emf,
 		pobj->puri.free = efhd_xpkcs7mime_free;
 		pobj->valid = camel_cipher_validity_clone (info->validity);
 		pobj->puri.widget_func = efhd_xpkcs7mime_button;
+		pobj->puri.write_func = efhd_write_secure_button;
 
 		em_format_add_puri (emf, (EMFormatPURI*) pobj);
 
@@ -683,6 +691,64 @@ efhd_parse_secure (EMFormat *emf,
 	}
 }
 
+/******************************************************************************/
+static void
+efhd_write_attachment_bar (EMFormat *emf,
+			   EMFormatPURI *puri,
+                           CamelStream *stream,
+                           EMFormatWriterInfo *info,
+                           GCancellable *cancellable)
+{
+        gchar *str;
+
+	str = g_strdup_printf (
+                "<object type=\"application/x-attachment-bar\" "
+			"height=\"20\" width=\"100%%\" "
+                        "data=\"%s\"></object>", puri->uri);
+
+	camel_stream_write_string (stream, str, cancellable, NULL);
+
+        g_free (str);
+}
+
+static void
+efhd_write_attachment (EMFormat *emf,
+		       EMFormatPURI *puri,
+                       CamelStream *stream,
+                       EMFormatWriterInfo *info,
+                       GCancellable *cancellable)
+{
+        gchar *str;
+
+	str = g_strdup_printf (
+                "<object type=\"application/x-attachment\" "
+		"height=\"20\" width=\"100%%\" "
+                "data=\"%s\"></object>", puri->uri);
+
+        camel_stream_write_string (stream, str, cancellable, NULL);
+
+        g_free (str);
+}
+
+static void
+efhd_write_secure_button (EMFormat *emf,
+			  EMFormatPURI *puri,
+                          CamelStream *stream,
+                          EMFormatWriterInfo *info,
+                          GCancellable *cancellable)
+{
+        gchar *str;
+
+        str = g_strdup_printf (
+                "<object type=\"application/x-secure-button\" "
+                "height=\"20\" width=\"100%%\" "
+                "data=\"%s\"></object>", puri->uri);
+
+        camel_stream_write_string (stream, str, cancellable, NULL);
+
+        g_free (str);
+}
+
 static void
 efhd_finalize (GObject *object)
 {
@@ -762,9 +828,9 @@ em_format_html_display_new (void)
 
 static EMFormatHandler type_builtin_table[] = {
 	{ (gchar *) "x-evolution/message/prefix", efhd_message_prefix, },
-	{ (gchar *) "x-evolution/message/attachment-bar", (EMFormatParseFunc) efhd_message_add_bar, },
-	{ (gchar *) "x-evolution/message/attachment", efhd_parse_attachment, },
-	{ (gchar *) "x-evolution/message/x-secure-button", efhd_parse_secure, },
+	{ (gchar *) "x-evolution/message/attachment-bar", (EMFormatParseFunc) efhd_message_add_bar, efhd_write_attachment_bar, },
+	{ (gchar *) "x-evolution/message/attachment", efhd_parse_attachment, efhd_write_attachment, },
+	{ (gchar *) "x-evolution/message/x-secure-button", efhd_parse_secure, efhd_write_secure_button, },
 	{ (gchar *) "x-evolution/message/optional", efhd_parse_optional, },
 };
 
@@ -894,6 +960,14 @@ efhd_attachment_bar (EMFormat *emf,
 	EMFormatAttachmentBarPURI *abp = (EMFormatAttachmentBarPURI *) puri;
 	GtkWidget *widget;
 
+	/* Don't display the attachment bar if it's empty.
+	 * At this point the parsing is done so we can be pretty much sure that
+	 * no new attachments will be added.
+	 * Returning NULL would however display "Missing Plugin" message, so
+	 * let's hack it this way. */
+	if (e_attachment_store_get_num_attachments (abp->store) == 0)
+		return gtk_label_new ("");
+
 	widget = e_mail_attachment_bar_new (abp->store);
 
 	return widget;
@@ -916,6 +990,7 @@ efhd_message_add_bar (EMFormat *emf,
 	g_string_append (part_id, ".attachment-bar");
 	puri = (EMFormatAttachmentBarPURI *) em_format_puri_new (
 			emf, sizeof (EMFormatAttachmentBarPURI), part, part_id->str);
+	puri->puri.write_func = efhd_write_attachment_bar;
 	puri->puri.widget_func = efhd_attachment_bar;
 	puri->puri.free = efhd_attachment_bar_puri_free;
 	puri->store = E_ATTACHMENT_STORE (e_attachment_store_new ());
diff --git a/mail/em-format-html-print.c b/mail/em-format-html-print.c
index f968ede..1085183 100644
--- a/mail/em-format-html-print.c
+++ b/mail/em-format-html-print.c
@@ -289,7 +289,7 @@ efhp_write_print_layout (EMFormat *emf,
 {
 	GList *iter;
 	EMFormatWriterInfo print_info = {
-		EM_FORMAT_WRITE_MODE_PRINTING, FALSE, FALSE, FALSE };
+		EM_FORMAT_WRITE_MODE_PRINTING, FALSE, FALSE };
         EMFormatHTMLPrint *efhp = EM_FORMAT_HTML_PRINT (emf);
 
         g_list_free (efhp->priv->attachments);
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index 9548628..d32f9a7 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -72,7 +72,7 @@
 	(G_TYPE_INSTANCE_GET_PRIVATE \
 	((obj), EM_TYPE_FORMAT_HTML, EMFormatHTMLPrivate))
 
-#define d(x)
+#define d(x) x
 
 struct _EMFormatHTMLPrivate {
 	GdkColor colors[EM_FORMAT_HTML_NUM_COLOR_TYPES];
@@ -103,15 +103,6 @@ enum {
 
 #define EFM_MESSAGE_START_ANAME "evolution_message_start"
 #define EFH_MESSAGE_START "<A name=\"" EFM_MESSAGE_START_ANAME "\"></A>"
-#define EFH_HTML_HEADER "<!DOCTYPE HTML>\n<html>\n"  \
-		"<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\" />\n" \
-		"<title>Evolution Mail Display</title>\n" \
-		"<link type=\"text/css\" rel=\"stylesheet\" href=\"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview.css\" />\n" \
-		"<style type=\"text/css\">\n" \
-		"  table th { color: #000; font-weight: bold; }\n" \
-		"</style>\n" \
-		"</head><body>"
-#define EFH_HTML_FOOTER "</body></html>"
 
 static void efh_parse_image			(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
 static void efh_parse_text_enriched		(EMFormat *emf, CamelMimePart *part, GString *part_id, EMFormatParserInfo *info, GCancellable *cancellable);
@@ -606,27 +597,7 @@ efh_write_image (EMFormat *emf,
 	ba = camel_data_wrapper_get_byte_array (dw);
 	content = g_strndup ((gchar *) ba->data, ba->len);
 
-	/* SPECIAL CASE!
-	   When inf->with_html_header is FALSE, assume we want HTML code of the image
-	   (with the image data - e.g. <img src="data:base64;....." />), otherwise
-	   we want only binary content of the image!
-	   This is because when rendering emails the normal way (=TRUE), images are always embedded
-	   either in <img> or in their own webview. When printing (=FALSE), we want the entire
-	   image. */
-	if (!info->with_html_header) {
-		gchar *buffer;
-
-		/* The image is already base64-encrypted so we can directly
-		   paste it to the output */
-		buffer = g_strdup_printf ("<img src=\"data:%s;base64,%s\" style=\"max-width: 100%%;\" />",
-			puri->mime_type, content);
-
-		camel_stream_write_string (stream, buffer, cancellable, NULL);
-
-		g_free (buffer);
-
-	} else {
-
+	if (info->mode == EM_FORMAT_WRITE_MODE_RAW) {
 		CamelStream *stream_filter;
 		CamelMimeFilter *filter;
 
@@ -638,6 +609,18 @@ efh_write_image (EMFormat *emf,
 
 		g_object_unref (filter);
 		g_object_unref (stream_filter);
+
+	} else {
+		gchar *buffer;
+
+		/* The image is already base64-encrypted so we can directly
+		   paste it to the output */
+		buffer = g_strdup_printf (
+			"<img src=\"data:%s;base64,%s\" style=\"max-width: 100%%;\" />",
+			puri->mime_type ? puri->mime_type : "image/*", content);
+
+		camel_stream_write_string (stream, buffer, cancellable, NULL);
+		g_free (buffer);
 	}
 
 	g_free (content);
@@ -687,22 +670,16 @@ efh_write_text_enriched (EMFormat *emf,
 	g_object_unref (enriched);
 
 	buffer = g_string_new ("");
-	if (info->with_html_header) {
-		g_string_append (buffer, EFH_HTML_HEADER);
-	}
 
 	g_string_append_printf (buffer,
-		"<div style=\"border: solid #%06x 1px; "
-		"background-color: #%06x; padding: 10px; "
-		"color: #%06x;\">\n",
-		e_color_to_value (
-			&efh->priv->colors[
+		"<div class=\"part-container\" style=\"border: solid #%06x 1px; "
+		"background-color: #%06x; color: #%06x;\">"
+		"<div class=\"part-container-inner-margin\">\n",
+		e_color_to_value (&efh->priv->colors[
 			EM_FORMAT_HTML_COLOR_FRAME]),
-		e_color_to_value (
-			&efh->priv->colors[
+		e_color_to_value (&efh->priv->colors[
 			EM_FORMAT_HTML_COLOR_CONTENT]),
-		e_color_to_value (
-			&efh->priv->colors[
+		e_color_to_value (&efh->priv->colors[
 			EM_FORMAT_HTML_COLOR_TEXT]));
 
 	camel_stream_write_string (stream, buffer->str, cancellable, NULL);
@@ -713,11 +690,7 @@ efh_write_text_enriched (EMFormat *emf,
 		(CamelDataWrapper *) puri->part, cancellable);
 
 	g_object_unref (filtered_stream);
-	camel_stream_write_string (stream, "</div>", cancellable, NULL);
-
-	if (info->with_html_header)
-		camel_stream_write_string (stream, EFH_HTML_FOOTER,
-			cancellable, NULL);
+	camel_stream_write_string (stream, "</div></div>", cancellable, NULL);
 }
 
 static void
@@ -757,15 +730,16 @@ efh_write_text_plain (EMFormat *emf,
 		CAMEL_STREAM_FILTER (filtered_stream), html_filter);
 	g_object_unref (html_filter);
 
-	if (info->with_html_header)
-		camel_stream_write_string (stream, EFH_HTML_HEADER, cancellable, NULL);
-
 	content = g_strdup_printf (
-			"<div class=\"part-container\" style=\"background: #%06x; color: #%06x;\" >" \
-			"<div id=\"pre\" style=\"background: #%06x; padding: 10px;\">\n",
-			e_color_to_value (&efh->priv->colors[EM_FORMAT_HTML_COLOR_BODY]),
-			e_color_to_value (&efh->priv->colors[EM_FORMAT_HTML_COLOR_HEADER]),
-			e_color_to_value (&efh->priv->colors[EM_FORMAT_HTML_COLOR_CONTENT]));
+		"<div class=\"part-container\" style=\"border: solid #%06x 1px; "
+		"background-color: #%06x; color: #%06x;\">"
+		"<div class=\"part-container-inner-margin\">\n",
+		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]));
 
 	camel_stream_write_string (stream, content, cancellable, NULL);
 	em_format_format_text (emf, filtered_stream, (CamelDataWrapper *) puri->part, cancellable);
@@ -774,9 +748,6 @@ efh_write_text_plain (EMFormat *emf,
 	g_free (content);
 
 	camel_stream_write_string (stream, "</div></div>\n", cancellable, NULL);
-
-	if (info->with_html_header)
-		camel_stream_write_string (stream, EFH_HTML_FOOTER, cancellable, NULL);
 }
 
 static void
@@ -786,48 +757,57 @@ efh_write_text_html (EMFormat *emf,
 		     EMFormatWriterInfo *info,
 		     GCancellable *cancellable)
 {
+	EMFormatHTML *efh;
+	CamelStream *format_stream;
+	GString *str;
+	GByteArray *ba;
+	gchar *pos, *header;
+
 	if (g_cancellable_is_cancelled (cancellable))
 		return;
 
-	if (info->with_html_header) {
-		em_format_format_text (emf, stream,
-			(CamelDataWrapper *) puri->part, cancellable);
-
-	} else {
-		CamelStream *format_stream;
-		GString *str;
-		GByteArray *ba;
-		gchar *pos;
+	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);
-
-		/* Now we are going to remove the <head>...</head> part and replace 
-	   	<body...>...</body> for <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 */
-		g_string_prepend (str, "<div class=\"part-container\"><div ");
+	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);
 
-		pos = strcasestr (str->str, "</body>");
-		if (pos)
-			g_string_truncate (str, (pos - str->str));
+	/* Remove </body> */
+	pos = strcasestr (str->str, "</body>");
+	if (pos)
+		g_string_truncate (str, (pos - str->str));
 
-		g_string_append (str, "</div></div>");
+	g_string_append (str, "</div></div>");
 
-		camel_stream_write_string (stream, str->str, cancellable, NULL);
+	camel_stream_write_string (stream, str->str, cancellable, NULL);
 
-		g_string_free (str, TRUE);
-	}
+	g_string_free (str, TRUE);
 }
 
 static void
@@ -854,8 +834,6 @@ efh_write_source (EMFormat *emf,
 	g_object_unref (filter);
 
 	buffer = g_string_new ("");
-	if (info->with_html_header)
-		g_string_append (buffer, EFH_HTML_HEADER);
 
 	g_string_append_printf (
 		buffer, "<div class=\"part-container\" style=\"background: #%06x; color: #%06x;\" >",
@@ -875,9 +853,6 @@ efh_write_source (EMFormat *emf,
 	camel_stream_write_string (
 		stream, "</code>", cancellable, NULL);
 
-	if (info->with_html_header)
-		camel_stream_write_string (stream, EFH_HTML_FOOTER, cancellable, NULL);
-
 	g_object_unref (filtered_stream);
 	g_string_free (buffer, TRUE);
 }
@@ -905,47 +880,10 @@ efh_write_headers (EMFormat *emf,
 		bg_color = e_color_to_value (&efh->priv->colors[EM_FORMAT_HTML_COLOR_BODY]);
 	}
 
-	if (info->with_html_header)
-		g_string_append_printf (buffer, EFH_HTML_HEADER);
-
 	/* Headers need some fancy JavaScript */
 	g_string_append_printf (
 		buffer,
-		"<script type=\"text/javascript\">\n"
-		"function collapse_addresses(field) {\n"
-		"  var e=window.document.getElementById(\"moreaddr-\"+field).style;\n"
-		"  var f=window.document.getElementById(\"moreaddr-ellipsis-\"+field).style;\n"
-		"  var g=window.document.getElementById(\"moreaddr-img-\"+field);\n"
-		"  if (e.display==\"inline\") { e.display=\"none\"; f.display=\"inline\"; g.src=g.src.substr(0,g.src.lastIndexOf(\"/\"))+\"/plus.png\"; }\n"
-		"  else { e.display=\"inline\"; f.display=\"none\"; g.src=g.src.substr(0,g.src.lastIndexOf(\"/\"))+\"/minus.png\"; }\n"
-		"}\n"
-		"function collapse_headers() {\n"
-		"  var f=window.document.getElementById(\"full-headers\").style;\n"
-		"  var s=window.document.getElementById(\"short-headers\").style;\n"
-		"  var i=window.document.getElementById(\"collapse-headers-img\");\n"
-		"  if (f.display==\"block\") { f.display=\"none\"; s.display=\"block\";\n"
-		"	i.src=i.src.substr(0,i.src.lastIndexOf(\"/\"))+\"/plus.png\"; window.headers_collapsed(true, window.em_format_html); }\n"
-		"  else { f.display=\"block\"; s.display=\"none\";\n"
-		"	 i.src=i.src.substr(0,i.src.lastIndexOf(\"/\"))+\"/minus.png\"; window.headers_collapsed(false, window.em_format_html); }\n"
-		"}\n"
-                "function set_header_visible(header,value,visible) {\n}"
-                "  var hdrs=window.document.getElementsByClassName('header-item');\n"
-                "  for (var i = 0; i < hdrs.length; i++) { \n"
-                "    var hdr = hdrs[i]; \n"
-                "    if (hdr.className.indexOf('rtl') == -1) { \n"
-                "      if ((hdr.firstChild.textContent == header) && \n"
-                "          (hdr.firstChild.nextSibling.textContent == value)) { \n"
-                "        hdr.style.display=(visible ? 'block' : 'none');\n"
-                "      }\n"
-                "    } else { \n"
-                "      if ((hdr.firstChild.textContent == value) && \n"
-                "          (hdr.firstChild.nextSibling.textContent == header)) { \n"
-                "        hdr.style.display=(visible ? 'block' : 'none');\n"
-                "      }\n"
-                "  }\n"
-                "}\n"
-		"</script>\n"
-		"<style type=\"text/css\">body { background: #%06x; }</style>"
+		"<div class=\"headers\" style=\"background: #%06x;\">"
 		"<table border=\"0\" width=\"100%%\" height=\"100%%\" style=\"color: #%06x;\">\n"
 		"<tr><td valign=\"top\" width=\"16\">\n",
 		bg_color,
@@ -967,10 +905,7 @@ efh_write_headers (EMFormat *emf,
 		!info->headers_collapsed,
 		cancellable);
 
-	g_string_append (buffer, "</td></tr></table>");
-
-	if (info->with_html_header)
-		g_string_append (buffer, EFH_HTML_FOOTER);
+	g_string_append (buffer, "</td></tr></table></div>");
 
 	camel_stream_write_string (stream, buffer->str, cancellable, NULL);
 
@@ -988,9 +923,6 @@ efh_write_error (EMFormat *emf,
 	CamelMimeFilter *filter;
 	CamelDataWrapper *dw;
 
-	if (info->with_html_header)
-		camel_stream_write_string (stream, EFH_HTML_HEADER, cancellable, NULL);
-
 	dw = camel_medium_get_content ((CamelMedium *) puri->part);
 
 	camel_stream_write_string (stream, "<em><font color=\"red\">", cancellable, NULL);
@@ -1006,9 +938,6 @@ efh_write_error (EMFormat *emf,
 	g_object_unref (filtered_stream);
 
 	camel_stream_write_string (stream, "</font></em><br>", cancellable, NULL);
-
-	if (info->with_html_header)
-		camel_stream_write_string (stream, EFH_HTML_FOOTER, cancellable, NULL);
 }
 
 /*****************************************************************************/
@@ -1324,6 +1253,84 @@ efh_preparse (EMFormat *emf)
 }
 
 static void
+efh_write (EMFormat *emf,
+	   CamelStream *stream,
+	   EMFormatWriterInfo *info,
+	   GCancellable *cancellable)
+{
+	GList *iter;
+	EMFormatHTML *efh;
+	gchar *header;
+
+	efh = (EMFormatHTML *) emf;
+
+	header = g_strdup_printf (
+		"<!DOCTYPE HTML>\n<html>\n"
+		"<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\" />\n"
+		"<title>Evolution Mail Display</title>\n"
+		"<link type=\"text/css\" rel=\"stylesheet\" href=\"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview.css\" />\n"
+		"<style type=\"text/css\">\n"
+		"  table th { color: #000; font-weight: bold; }\n"
+		"</style>\n"
+		"<script type=\"text/javascript\">\n"
+		"function collapse_addresses(field) {\n"
+		"  var e=window.document.getElementById(\"moreaddr-\"+field).style;\n"
+		"  var f=window.document.getElementById(\"moreaddr-ellipsis-\"+field).style;\n"
+		"  var g=window.document.getElementById(\"moreaddr-img-\"+field);\n"
+		"  if (e.display==\"inline\") { e.display=\"none\"; f.display=\"inline\"; g.src=g.src.substr(0,g.src.lastIndexOf(\"/\"))+\"/plus.png\"; }\n"
+		"  else { e.display=\"inline\"; f.display=\"none\"; g.src=g.src.substr(0,g.src.lastIndexOf(\"/\"))+\"/minus.png\"; }\n"
+		"}\n"
+		"function collapse_headers() {\n"
+		"  var f=window.document.getElementById(\"full-headers\").style;\n"
+		"  var s=window.document.getElementById(\"short-headers\").style;\n"
+		"  var i=window.document.getElementById(\"collapse-headers-img\");\n"
+		"  if (f.display==\"block\") { f.display=\"none\"; s.display=\"block\";\n"
+		"	i.src=i.src.substr(0,i.src.lastIndexOf(\"/\"))+\"/plus.png\"; window.headers_collapsed(true, window.em_format_html); }\n"
+		"  else { f.display=\"block\"; s.display=\"none\";\n"
+		"	 i.src=i.src.substr(0,i.src.lastIndexOf(\"/\"))+\"/minus.png\"; window.headers_collapsed(false, window.em_format_html); }\n"
+		"}\n"
+		"function set_header_visible(header,value,visible) { // Printing\n"
+		"  var hdrs=window.document.getElementsByClassName('header-item');\n"
+		"  for (var i = 0; i < hdrs.length; i++) { \n"
+		"    var hdr = hdrs[i]; \n"
+		"    if (hdr.className.indexOf('rtl') == -1) { \n"
+		"      if ((hdr.firstChild.textContent == header) && \n"
+		"          (hdr.firstChild.nextSibling.textContent == value)) { \n"
+		"        hdr.style.display=(visible ? 'block' : 'none');\n"
+		"      }\n"
+		"    } else { \n"
+		"      if ((hdr.firstChild.textContent == value) && \n"
+		"          (hdr.firstChild.nextSibling.textContent == header)) { \n"
+		"        hdr.style.display=(visible ? 'block' : 'none');\n"
+		"      }\n"
+		"    }\n"
+		"  }\n"
+		"}\n"
+		"</script>\n"
+		"</head><body bgcolor=\"%06x\">",
+		e_color_to_value (&efh->priv->colors[
+			EM_FORMAT_HTML_COLOR_BODY]));
+
+	camel_stream_write_string (stream, header, cancellable, NULL);
+	g_free (header);
+
+	for (iter = emf->mail_part_list; iter; iter = iter->next) {
+
+		EMFormatPURI *puri = iter->data;
+
+		if ((puri->write_func && !puri->is_attachment) ||
+		    (puri->write_func && puri->widget_func && puri->is_attachment)) {
+			puri->write_func (emf, puri, stream, info, cancellable);
+			d(printf("Writing PURI %s\n", puri->uri));
+		} else {
+			d(printf("Skipping PURI %s\n", puri->uri));
+		}
+	}
+
+	camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
+}
+
+static void
 efh_base_init (EMFormatHTMLClass *klass)
 {
 	efh_builtin_init (klass);
@@ -1340,6 +1347,7 @@ efh_class_init (EMFormatHTMLClass *klass)
 
         emf_class = EM_FORMAT_CLASS (klass);
         emf_class->preparse = efh_preparse;
+	emf_class->write = efh_write;
 
 	object_class = G_OBJECT_CLASS (klass);
 	object_class->set_property = efh_set_property;
diff --git a/modules/mail/e-mail-shell-content.c b/modules/mail/e-mail-shell-content.c
index 9643926..678dce7 100644
--- a/modules/mail/e-mail-shell-content.c
+++ b/modules/mail/e-mail-shell-content.c
@@ -311,7 +311,6 @@ static EMailDisplay *
 mail_shell_content_get_mail_display(EMailReader *reader)
 {
 	EMailShellContent *mail_shell_content;
-	EMailDisplay *display;
 
 	mail_shell_content = E_MAIL_SHELL_CONTENT (reader);
 
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index d74e7b0..e37e0db 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -895,6 +895,8 @@ action_mail_smart_backward_cb (GtkAction *action,
 	EMailView *mail_view;
 	GtkWidget *message_list;
 	GtkToggleAction *toggle_action;
+        GtkWidget *window;
+        GtkAdjustment *adj;
 	EMailDisplay *display;
 	gboolean caret_mode;
 	gboolean magic_spacebar;
@@ -922,7 +924,14 @@ action_mail_smart_backward_cb (GtkAction *action,
 	toggle_action = GTK_TOGGLE_ACTION (ACTION (MAIL_CARET_MODE));
 	caret_mode = gtk_toggle_action_get_active (toggle_action);
 
-        e_mail_display_scroll (display, GDK_SCROLL_UP);
+        window = gtk_widget_get_parent (GTK_WIDGET (display));
+        if (!GTK_IS_SCROLLED_WINDOW (window))
+                return;
+
+        adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (window));
+        gtk_adjustment_set_value (adj,
+                gtk_adjustment_get_value(adj) - gtk_adjustment_get_page_increment(adj));
+
 
 	if (caret_mode || !magic_spacebar)
 		return;
@@ -961,6 +970,8 @@ action_mail_smart_forward_cb (GtkAction *action,
 	EMailReader *reader;
 	EMailView *mail_view;
 	GtkWidget *message_list;
+        GtkWidget *window;
+        GtkAdjustment *adj;
 	GtkToggleAction *toggle_action;
 	EMailDisplay *display;
 	gboolean caret_mode;
@@ -989,9 +1000,15 @@ action_mail_smart_forward_cb (GtkAction *action,
 	toggle_action = GTK_TOGGLE_ACTION (ACTION (MAIL_CARET_MODE));
 	caret_mode = gtk_toggle_action_get_active (toggle_action);
 
-        e_mail_display_scroll (display, GDK_SCROLL_DOWN);
-
-
+        window = gtk_widget_get_parent (GTK_WIDGET (display));
+        if (!GTK_IS_SCROLLED_WINDOW (window))
+                return;
+        
+        adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (window));
+        gtk_adjustment_set_value (adj,
+                gtk_adjustment_get_value(adj) + gtk_adjustment_get_page_increment(adj));
+        
+        
 	if (caret_mode || !magic_spacebar)
 		return;
 
diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c
index c8ab233..0335d51 100644
--- a/modules/mail/e-mail-shell-view-private.c
+++ b/modules/mail/e-mail-shell-view-private.c
@@ -335,7 +335,6 @@ mail_shell_view_popup_event_cb (EMailShellView *mail_shell_view,
 	EShellView *shell_view;
 	EMailReader *reader;
 	EMailView *mail_view;
-	EWebView *web_view;
 	GtkMenu *menu;
 
 	if (uri != NULL)
@@ -346,9 +345,8 @@ mail_shell_view_popup_event_cb (EMailShellView *mail_shell_view,
 
 	reader = E_MAIL_READER (mail_view);
 	display = e_mail_reader_get_mail_display (reader);
-	web_view = e_mail_display_get_current_web_view (display);
 
-	if (e_web_view_get_cursor_image (web_view) != NULL)
+	if (e_web_view_get_cursor_image (E_WEB_VIEW (display)) != NULL)
 		return FALSE;
 
 	menu = e_mail_reader_get_popup_menu (reader);
diff --git a/modules/web-inspector/evolution-web-inspector.c b/modules/web-inspector/evolution-web-inspector.c
index 01fd6aa..27a21e0 100644
--- a/modules/web-inspector/evolution-web-inspector.c
+++ b/modules/web-inspector/evolution-web-inspector.c
@@ -43,7 +43,9 @@ struct _EWebInspectorClass {
 static const gchar *ui =
 "<ui>"
 "  <popup name='context'>"
-"    <menuitem action='inspect'/>"
+"    <placeholder name='inspect-menu' >"
+"      <menuitem action='inspect'/>"
+"    </placeholder>"
 "  </popup>"
 "</ui>";
 
diff --git a/plugins/audio-inline/audio-inline.c b/plugins/audio-inline/audio-inline.c
index 4942370..fa22264 100644
--- a/plugins/audio-inline/audio-inline.c
+++ b/plugins/audio-inline/audio-inline.c
@@ -278,10 +278,28 @@ org_gnome_audio_inline_add_button (GtkWidget *box,
 	return button;
 }
 
+static void
+write_button_panel (EMFormat *emf,
+		    EMFormatPURI *puri,
+		    CamelStream *stream,
+		    EMFormatWriterInfo *info,
+		    GCancellable *cancellable)
+{
+	gchar *str;
+
+	str = g_strdup_printf (
+		"<object type=\"application/x-org-gnome-audio-inline-button-panel\" "
+			"width=\"100%%\" height=\"auto\" data=\"%s\"></object>",
+		puri->uri);
+	camel_stream_write_string (stream, str, cancellable, NULL);
+
+	g_free (str);
+}
+
 static GtkWidget*
 org_gnome_audio_inline_button_panel (EMFormat *emf,
-									 EMFormatPURI *puri,
-									 GCancellable *cancellable)
+				     EMFormatPURI *puri,
+				     GCancellable *cancellable)
 {
 	GtkWidget *box;
 	EMFormatInlineAudioPURI *po = (EMFormatInlineAudioPURI *) puri;
diff --git a/plugins/itip-formatter/itip-formatter.c b/plugins/itip-formatter/itip-formatter.c
index 119ee12..503aadc 100644
--- a/plugins/itip-formatter/itip-formatter.c
+++ b/plugins/itip-formatter/itip-formatter.c
@@ -3084,6 +3084,26 @@ puri_free (EMFormatPURI *puri)
 	g_hash_table_destroy (pitip->real_comps);
 }
 
+static void
+write_itip_object (EMFormat *emf,
+		   EMFormatPURI *puri,
+		   CamelStream *stream,
+		   EMFormatWriterInfo *info,
+		   GCancellable *cancellable)
+{
+	gchar *str;
+
+	str = g_strdup_printf (
+		"<object type=\"application/x-itip-widget\" "
+		"height=\"100\" width=\"100%%\" "
+		"data=\"%s\"></object>", puri->uri);
+
+	camel_stream_write_string (stream, str, cancellable, NULL);
+
+	g_free (str);
+}
+
+
 void
 format_itip (EPlugin *ep,
              EMFormatHookTarget *target)
@@ -3106,6 +3126,7 @@ format_itip (EPlugin *ep,
 	settings = g_settings_new ("org.gnome.evolution.plugin.itip");
 
 	puri = (struct _itip_puri *) em_format_puri_new (target->format, sizeof (struct _itip_puri), target->part, target->part_id->str);
+	puri->puri.write_func = write_itip_object;
 	puri->puri.widget_func = format_itip_object;
 	puri->puri.free = puri_free;
 	puri->delete_message = g_settings_get_boolean (settings, CONF_KEY_DELETE);
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index b3c7769..f6d94b8 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -1068,7 +1068,7 @@ get_selected_text (EMailReader *reader)
 
 	display = e_mail_reader_get_mail_display (reader);
 
-	if (!e_mail_display_is_selection_active (display))
+	if (!e_web_view_is_selection_active (E_WEB_VIEW (display)))
 		return NULL;
 
 	text = e_mail_display_get_selection_plain_text (display, &len);
diff --git a/widgets/misc/e-preview-pane.c b/widgets/misc/e-preview-pane.c
index a94b313..92644ec 100644
--- a/widgets/misc/e-preview-pane.c
+++ b/widgets/misc/e-preview-pane.c
@@ -157,14 +157,12 @@ preview_pane_constructed (GObject *object)
 	/* EAlertBar controls its own visibility. */
 
 	widget = gtk_scrolled_window_new (NULL, NULL);
-	gtk_scrolled_window_set_policy (
-		GTK_SCROLLED_WINDOW (widget),
-		GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 	gtk_scrolled_window_set_shadow_type (
 		GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
 	gtk_box_pack_start (GTK_BOX (object), widget, TRUE, TRUE, 0);
 	gtk_container_add (GTK_CONTAINER (widget), priv->web_view);
 	gtk_widget_show (widget);
+	gtk_widget_show (priv->web_view);
 
 	widget = e_search_bar_new (E_WEB_VIEW (priv->web_view));
 	gtk_box_pack_start (GTK_BOX (object), widget, FALSE, FALSE, 0);
diff --git a/widgets/misc/e-web-view.c b/widgets/misc/e-web-view.c
index 1663135..9d0695f 100644
--- a/widgets/misc/e-web-view.c
+++ b/widgets/misc/e-web-view.c
@@ -831,119 +831,6 @@ web_view_scroll_event (GtkWidget *widget,
 	return FALSE;
 }
 
-static void
-web_view_get_preferred_height (GtkWidget *widget,
-			       gint *minimum_height,
-			       gint *natural_height)
-{
-	WebKitWebView *web_view;
-	WebKitDOMDocument *document;
-	WebKitDOMElement *body, *last_el, *style_el;
-	gint doc_height;
-
-	if (!minimum_height && !natural_height)
-		return;
-
-	web_view = WEBKIT_WEB_VIEW (widget);
-	document = webkit_web_view_get_dom_document (web_view);
-	if (!document)
-		return;
-
-	body = WEBKIT_DOM_ELEMENT (webkit_dom_document_get_body (document));
-	if (!body)
-		return;
-
-	/* Make sure our Evo CSS stylesheet is loaded.
-	 * Note: there's 'user-stylesheet-uri' property of WebKitWebSettings but
-	 * it does not seem to be loaded in webviews with native text/html emails. */
-	style_el = webkit_dom_document_get_element_by_id (document, "_evo_stylesheet");
-	if (!style_el) {
-		WebKitDOMNodeList *list;
-		WebKitDOMNode *head;
-		style_el = webkit_dom_document_create_element (document, "LINK", NULL);
-		webkit_dom_html_link_element_set_rel (
-			WEBKIT_DOM_HTML_LINK_ELEMENT (style_el), "stylesheet");
-		webkit_dom_html_link_element_set_href(
-			WEBKIT_DOM_HTML_LINK_ELEMENT (style_el),
-			"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview.css");
-		webkit_dom_element_set_attribute (style_el, "type", "text/css", NULL);
-		webkit_dom_html_element_set_id (
-			WEBKIT_DOM_HTML_ELEMENT (style_el), "_evo_stylesheet");
-
-		list = webkit_dom_document_get_elements_by_tag_name (document, "head");
-		/* Broken HTML! Try to add head */
-		if (webkit_dom_node_list_get_length (list) == 0) {
-			WebKitDOMNodeList *body;
-			head = WEBKIT_DOM_NODE (
-				webkit_dom_document_create_element (
-					document, "HEAD", NULL));
-			body = webkit_dom_document_get_elements_by_tag_name (document, "body");
-			if (webkit_dom_node_list_get_length(body) == 0) {
-				/* The document is totally screwed up, there's
-				 * nothing more we can do. */
-				return;
-			}
-
-			webkit_dom_node_insert_before(WEBKIT_DOM_NODE (document),
-				head, webkit_dom_node_list_item (body, 0), NULL);
-
-		} else {
-			head = webkit_dom_node_list_item (list, 0);
-		}
-
-		webkit_dom_node_append_child (head, WEBKIT_DOM_NODE (style_el), NULL);
-	}
-
-	/* Last element in DOM != the undermost element displayed.
-	 * Thus we create our own element which is guaranteed to be displayed
-	 * at the very bottom (via CSS in webview.css) */
-	last_el = webkit_dom_document_get_element_by_id (document, "_evo_bottom_element");
-	if (!last_el) {
-		last_el = webkit_dom_document_create_element (document, "DIV", NULL);
-		webkit_dom_html_element_set_id (WEBKIT_DOM_HTML_ELEMENT (last_el),
-			"_evo_bottom_element");
-		webkit_dom_node_append_child (WEBKIT_DOM_NODE (body),
-			WEBKIT_DOM_NODE (last_el), NULL);
-
-		/* When the _evo_bottom_element is inserted to the DOM, the
-		 * subsequent call of webkit_dom_element_get_offset_top() makes
-		 * WebKit to recalculate layout and invoke content size change
-		 * which results in a recursive call of this function.
-		 * Gtk would prevent the recursion to happen but it would
-		 * throw an ugly warning, therefor we won't be doing any math now.
-		 * When the email is being rendered, the _get_preferred_height()
-		 * gets called multiple times, so we will calculate the actual
-		 * height next time, when WebKit will not be trying to update the
-		 * layout. */
-
-		return;
-	}
-
-	/* The _actual_ height of page content is top + height of the
-	 * very last element in body. The 2px height is hardocded in
-	 * webview.ccs in #_evo_bottom_element */
-	doc_height = webkit_dom_element_get_offset_top (last_el) + 2;
-
-
-	/* Hardcoded padding */
-	doc_height += 18;
-
-	/* When full content zoom is enabled then the elements are not resized
-	 * but rather scaled and thus they still report their original height
-	 * instead of their actual display height. */
-	if (webkit_web_view_get_full_content_zoom (web_view)) {
-		doc_height = ceil((gfloat) doc_height * 
-				webkit_web_view_get_zoom_level (web_view));
-	}
-
-	if (minimum_height)
-		*minimum_height = doc_height;
-
-	if (natural_height)
-		*natural_height = doc_height;
-
-}
-
 static GtkWidget *
 web_view_create_plugin_widget (EWebView *web_view,
                                const gchar *mime_type,
@@ -1422,7 +1309,6 @@ e_web_view_class_init (EWebViewClass *class)
 	widget_class = GTK_WIDGET_CLASS (class);
 	widget_class->button_press_event = web_view_button_press_event;
 	widget_class->scroll_event = web_view_scroll_event;
-	widget_class->get_preferred_height = web_view_get_preferred_height;
 
 #if 0  /* WEBKIT */
 	html_class = GTK_HTML_CLASS (class);
@@ -2782,7 +2668,6 @@ e_web_view_get_default_settings(GtkWidget *parent_widget)
                 "default-font-size", (pango_font_description_get_size (font) / PANGO_SCALE),
                 "default-monospace-font-size", (pango_font_description_get_size (font) / PANGO_SCALE),
                 "enable-frame-flattening", TRUE, 
-                "enable-plugins", FALSE,
                 "enable-java-applet", FALSE,
                 "enable-html5-database", FALSE,
                 "enable-html5-local-storage", FALSE,



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