[evolution/wip/webkit2] Bug 762376 - Embedded images in signature only displays under evolution and not other clients



commit 94ce1851dfa880f773d552a390f3f702a6132f2f
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Mar 3 17:35:20 2016 +0100

    Bug 762376 - Embedded images in signature only displays under evolution and not other clients

 e-util/e-html-editor-view.c                        |   45 +++-
 e-util/e-html-editor-view.h                        |    2 +
 e-util/e-mail-signature-editor.c                   |    9 +-
 .../composer/e-html-editor-view-dom-functions.c    |  245 +++++++++++---------
 .../composer/e-html-editor-view-dom-functions.h    |    3 +-
 .../composer/e-html-editor-web-extension.c         |    8 +-
 6 files changed, 183 insertions(+), 129 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 9cc52cd..84aa20e 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -2032,10 +2032,12 @@ e_html_editor_view_get_spell_checker (EHTMLEditorView *view)
 
 static gchar *
 process_document (EHTMLEditorView *view,
-                  const gchar *function)
+                  const gchar *function,
+                 gboolean with_bool,
+                 gboolean bool_value)
 {
        GDBusProxy *web_extension;
-       GVariant *result;
+       GVariant *result, *params;
 
        g_return_val_if_fail (view != NULL, NULL);
 
@@ -2043,12 +2045,20 @@ process_document (EHTMLEditorView *view,
        if (!web_extension)
                return NULL;
 
+       if (with_bool) {
+               params = g_variant_new (
+                       "(tb)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+                       bool_value);
+       } else {
+               params = g_variant_new (
+                       "(t)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)));
+       }
        result = g_dbus_proxy_call_sync (
                web_extension,
                function,
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
+               params,
                G_DBUS_CALL_FLAGS_NONE,
                -1,
                NULL,
@@ -2170,7 +2180,7 @@ html_editor_view_get_parts_for_inline_images (EHTMLEditorView *view,
  * e_html_editor_view_get_text_html:
  * @view: an #EHTMLEditorView:
  *
- * Returns processed HTML content of the editor document (with elements attributes
+ * Returns processed HTML content of the editor document (without elements attributes
  * used in Evolution composer)
  *
  * Returns: A newly allocated string
@@ -2220,15 +2230,30 @@ e_html_editor_view_get_text_html (EHTMLEditorView *view,
  * e_html_editor_view_get_text_html_for_drafts:
  * @view: an #EHTMLEditorView:
  *
- * Returns HTML content of the editor document (without elements attributes
- * used in Evolution composer)
+ * Returns HTML content of the editor document (with elements attributes used in
+ * Evolution composer)
  *
  * Returns: A newly allocated string
  */
 gchar *
 e_html_editor_view_get_text_html_for_drafts (EHTMLEditorView *view)
 {
-       return process_document (view, "DOMProcessContentForDraft");
+       return process_document (view, "DOMProcessContentForDraft", TRUE, FALSE);
+}
+
+/**
+ * e_html_editor_view_get_text_html_for_drafts:
+ * @view: an #EHTMLEditorView:
+ *
+ * Returns HTML content of the editor document (with elements attributes used in
+ * Evolution composer)
+ *
+ * Returns: A newly allocated string
+ */
+gchar *
+e_html_editor_view_get_body_text_html_for_drafts (EHTMLEditorView *view)
+{
+       return process_document (view, "DOMProcessContentForDraft", TRUE, TRUE);
 }
 
 /**
@@ -2244,7 +2269,7 @@ e_html_editor_view_get_text_html_for_drafts (EHTMLEditorView *view)
 gchar *
 e_html_editor_view_get_text_plain (EHTMLEditorView *view)
 {
-       return process_document (view, "DOMProcessContentForPlainText");
+       return process_document (view, "DOMProcessContentForPlainText", FALSE, FALSE);
 }
 
 void
diff --git a/e-util/e-html-editor-view.h b/e-util/e-html-editor-view.h
index 4b21c99..14b47c7 100644
--- a/e-util/e-html-editor-view.h
+++ b/e-util/e-html-editor-view.h
@@ -154,6 +154,8 @@ gchar *             e_html_editor_view_get_text_html
                                                 GList **inline_images);
 gchar *                e_html_editor_view_get_text_html_for_drafts
                                                (EHTMLEditorView *view);
+gchar *                e_html_editor_view_get_body_text_html_for_drafts
+                                               (EHTMLEditorView *view);
 gchar *                e_html_editor_view_get_text_plain
                                                (EHTMLEditorView *view);
 void           e_html_editor_view_convert_and_insert_plain_text
diff --git a/e-util/e-mail-signature-editor.c b/e-util/e-mail-signature-editor.c
index 221bfcb..a92ab4b 100644
--- a/e-util/e-mail-signature-editor.c
+++ b/e-util/e-mail-signature-editor.c
@@ -851,13 +851,8 @@ e_mail_signature_editor_commit (EMailSignatureEditor *window,
        editor = e_mail_signature_editor_get_editor (window);
        view = e_html_editor_get_view (editor);
 
-       if (e_html_editor_view_get_html_mode (view)) {
-               mime_type = "text/html";
-               contents = e_html_editor_view_get_text_html (view, NULL, NULL);
-       } else {
-               mime_type = "text/plain";
-               contents = e_html_editor_view_get_text_plain (view);
-       }
+       mime_type = "text/html";
+       contents = e_html_editor_view_get_body_text_html_for_drafts (view);
 
        extension_name = E_SOURCE_EXTENSION_MAIL_SIGNATURE;
        extension = e_source_get_extension (source, extension_name);
diff --git a/web-extensions/composer/e-html-editor-view-dom-functions.c 
b/web-extensions/composer/e-html-editor-view-dom-functions.c
index 3ad9e33..3442175 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -6239,6 +6239,114 @@ remove_evolution_attributes (WebKitDOMElement *element)
 }
 
 static void
+convert_element_from_html_to_plain_text (WebKitDOMDocument *document,
+                                        EHTMLEditorWebExtension *extension,
+                                         WebKitDOMElement *element,
+                                         gboolean *wrap,
+                                         gboolean *quote)
+{
+       gint blockquotes_count;
+       gchar *inner_text, *inner_html;
+       WebKitDOMElement *top_signature, *signature, *blockquote, *main_blockquote;
+       WebKitDOMNode *signature_clone, *from;
+
+       top_signature = webkit_dom_element_query_selector (
+               element, ".-x-evo-top-signature", NULL);
+       signature = webkit_dom_element_query_selector (
+               element, "span.-x-evo-signature", NULL);
+       main_blockquote = webkit_dom_element_query_selector (
+               element, "#-x-evo-main-cite", NULL);
+
+       blockquote = webkit_dom_document_create_element (
+               document, "blockquote", NULL);
+
+       if (main_blockquote) {
+               webkit_dom_element_set_attribute (
+                       blockquote, "type", "cite", NULL);
+               from = WEBKIT_DOM_NODE (main_blockquote);
+       } else {
+               if (signature) {
+                       WebKitDOMNode *parent = webkit_dom_node_get_parent_node (
+                               WEBKIT_DOM_NODE (signature));
+                       signature_clone = webkit_dom_node_clone_node (parent, TRUE);
+                       remove_node (parent);
+               }
+               from = WEBKIT_DOM_NODE (element);
+       }
+
+       blockquotes_count = create_text_markers_for_citations_in_element (WEBKIT_DOM_ELEMENT (from));
+       create_text_markers_for_selection_in_element (WEBKIT_DOM_ELEMENT (from));
+
+       inner_text = webkit_dom_html_element_get_inner_text (
+               WEBKIT_DOM_HTML_ELEMENT (from));
+
+       webkit_dom_html_element_set_inner_text (
+               WEBKIT_DOM_HTML_ELEMENT (blockquote), inner_text, NULL);
+
+       inner_html = webkit_dom_html_element_get_inner_html (
+               WEBKIT_DOM_HTML_ELEMENT (blockquote));
+
+       parse_html_into_blocks (
+               document, extension,
+               main_blockquote ? blockquote : WEBKIT_DOM_ELEMENT (element),
+               NULL,
+               inner_html);
+
+       if (main_blockquote) {
+               webkit_dom_node_replace_child (
+                       webkit_dom_node_get_parent_node (
+                               WEBKIT_DOM_NODE (main_blockquote)),
+                       WEBKIT_DOM_NODE (blockquote),
+                       WEBKIT_DOM_NODE (main_blockquote),
+                       NULL);
+
+               remove_evolution_attributes (WEBKIT_DOM_ELEMENT (element));
+       } else {
+               WebKitDOMNode *first_child;
+
+               if (signature) {
+                       if (!top_signature) {
+                               signature_clone = webkit_dom_node_append_child (
+                                       WEBKIT_DOM_NODE (element),
+                                       signature_clone,
+                                       NULL);
+                       } else {
+                               webkit_dom_node_insert_before (
+                                       WEBKIT_DOM_NODE (element),
+                                       signature_clone,
+                                       webkit_dom_node_get_first_child (
+                                               WEBKIT_DOM_NODE (element)),
+                                       NULL);
+                       }
+               }
+
+               first_child = webkit_dom_node_get_first_child (
+                       WEBKIT_DOM_NODE (element));
+               if (first_child) {
+                       if (!webkit_dom_node_has_child_nodes (first_child)) {
+                               webkit_dom_html_element_set_inner_html (
+                                       WEBKIT_DOM_HTML_ELEMENT (first_child),
+                                       "<br>",
+                                       NULL);
+                       }
+                       dom_add_selection_markers_into_element_start (
+                               document, WEBKIT_DOM_ELEMENT (first_child), NULL, NULL);
+               }
+       }
+
+       if (wrap)
+               *wrap = TRUE;
+       if (quote)
+               *quote = main_blockquote || blockquotes_count > 0;
+
+       webkit_dom_element_set_attribute (
+               WEBKIT_DOM_ELEMENT (element), "data-converted", "", NULL);
+
+       g_free (inner_text);
+       g_free (inner_html);
+}
+
+static void
 process_elements (EHTMLEditorWebExtension *extension,
                   WebKitDOMNode *node,
                   gboolean changing_mode,
@@ -6556,6 +6664,8 @@ process_elements (EHTMLEditorWebExtension *extension,
                                }
                                g_object_unref (list_pre);
 
+                               convert_element_from_html_to_plain_text (
+                                       document, extension, WEBKIT_DOM_ELEMENT (first_child), NULL, NULL);
                                content = webkit_dom_html_element_get_inner_text (
                                        WEBKIT_DOM_HTML_ELEMENT (first_child));
                                g_string_append (buffer, content);
@@ -6569,6 +6679,8 @@ process_elements (EHTMLEditorWebExtension *extension,
                                g_free (content);
                        }
                        skip_node = TRUE;
+                       if (!to_plain_text && !changing_mode)
+                               skip_node = FALSE;
                        goto next;
                }
 
@@ -6888,7 +7000,8 @@ toggle_paragraphs_style (WebKitDOMDocument *document,
 }
 
 gchar *
-dom_process_content_for_draft (WebKitDOMDocument *document)
+dom_process_content_for_draft (WebKitDOMDocument *document,
+                              gboolean only_inner_body)
 {
        gchar *content;
        gint ii, length;
@@ -6919,7 +7032,29 @@ dom_process_content_for_draft (WebKitDOMDocument *document)
        }
        g_object_unref (list);
 
-       content = webkit_dom_element_get_outer_html (WEBKIT_DOM_ELEMENT (document_element_clone));
+       list = webkit_dom_element_query_selector_all (
+               WEBKIT_DOM_ELEMENT (document_element_clone), "#-x-evo-input-start", NULL);
+       length = webkit_dom_node_list_get_length (list);
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node;
+
+               node = webkit_dom_node_list_item (list, ii);
+               webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (node), "id");
+               g_object_unref (node);
+       }
+
+       g_object_unref (list);
+
+       if (only_inner_body) {
+               WebKitDOMElement *body;
+
+               body = webkit_dom_element_query_selector (
+                       WEBKIT_DOM_ELEMENT (document_element_clone), "body", NULL);
+               content = webkit_dom_html_element_get_inner_html (
+                       WEBKIT_DOM_HTML_ELEMENT (body));
+       } else
+               content = webkit_dom_html_element_get_outer_html (
+                       WEBKIT_DOM_HTML_ELEMENT (document_element_clone));
 
        webkit_dom_element_remove_attribute (
                WEBKIT_DOM_ELEMENT (body), "data-evo-draft");
@@ -6948,112 +7083,6 @@ process_content_for_mode_change (WebKitDOMDocument *document,
        return g_string_free (plain_text, FALSE);
 }
 
-static void
-convert_element_from_html_to_plain_text (WebKitDOMDocument *document,
-                                         EHTMLEditorWebExtension *extension,
-                                         WebKitDOMElement *element,
-                                         gboolean *wrap,
-                                         gboolean *quote)
-{
-       gint blockquotes_count;
-       gchar *inner_text, *inner_html;
-       WebKitDOMElement *top_signature, *signature, *blockquote, *main_blockquote;
-       WebKitDOMNode *signature_clone, *from;
-
-       top_signature = webkit_dom_element_query_selector (
-               element, ".-x-evo-top-signature", NULL);
-       signature = webkit_dom_element_query_selector (
-               element, "span.-x-evo-signature", NULL);
-       main_blockquote = webkit_dom_element_query_selector (
-               element, "#-x-evo-main-cite", NULL);
-
-       blockquote = webkit_dom_document_create_element (
-               document, "blockquote", NULL);
-
-       if (main_blockquote) {
-               webkit_dom_element_set_attribute (
-                       blockquote, "type", "cite", NULL);
-               from = WEBKIT_DOM_NODE (main_blockquote);
-       } else {
-               if (signature) {
-                       WebKitDOMNode *parent = webkit_dom_node_get_parent_node (
-                               WEBKIT_DOM_NODE (signature));
-                       signature_clone = webkit_dom_node_clone_node (parent, TRUE);
-                       remove_node (parent);
-               }
-               from = WEBKIT_DOM_NODE (element);
-       }
-
-       blockquotes_count = create_text_markers_for_citations_in_element (WEBKIT_DOM_ELEMENT (from));
-       create_text_markers_for_selection_in_element (WEBKIT_DOM_ELEMENT (from));
-
-       inner_text = webkit_dom_html_element_get_inner_text (
-               WEBKIT_DOM_HTML_ELEMENT (from));
-
-       webkit_dom_html_element_set_inner_text (
-               WEBKIT_DOM_HTML_ELEMENT (blockquote), inner_text, NULL);
-
-       inner_html = webkit_dom_element_get_inner_html (blockquote);
-
-       parse_html_into_blocks (
-               document,
-               extension,
-               main_blockquote ? blockquote : WEBKIT_DOM_ELEMENT (element),
-               NULL,
-               inner_html);
-
-       if (main_blockquote) {
-               webkit_dom_node_replace_child (
-                       webkit_dom_node_get_parent_node (
-                               WEBKIT_DOM_NODE (main_blockquote)),
-                       WEBKIT_DOM_NODE (blockquote),
-                       WEBKIT_DOM_NODE (main_blockquote),
-                       NULL);
-
-               remove_evolution_attributes (WEBKIT_DOM_ELEMENT (element));
-       } else {
-               WebKitDOMNode *first_child;
-
-               if (signature) {
-                       if (!top_signature) {
-                               signature_clone = webkit_dom_node_append_child (
-                                       WEBKIT_DOM_NODE (element),
-                                       signature_clone,
-                                       NULL);
-                       } else {
-                               webkit_dom_node_insert_before (
-                                       WEBKIT_DOM_NODE (element),
-                                       signature_clone,
-                                       webkit_dom_node_get_first_child (
-                                               WEBKIT_DOM_NODE (element)),
-                                       NULL);
-                       }
-               }
-
-               first_child = webkit_dom_node_get_first_child (
-                       WEBKIT_DOM_NODE (element));
-               if (first_child) {
-                       if (!webkit_dom_node_has_child_nodes (first_child)) {
-                               webkit_dom_element_set_inner_html (
-                                       WEBKIT_DOM_ELEMENT (first_child),
-                                       "<br>",
-                                       NULL);
-                       }
-                       dom_add_selection_markers_into_element_start (
-                               document, WEBKIT_DOM_ELEMENT (first_child), NULL, NULL);
-               }
-       }
-
-       *wrap = TRUE;
-       *quote = main_blockquote || blockquotes_count > 0;
-
-       webkit_dom_element_set_attribute (
-               WEBKIT_DOM_ELEMENT (element), "data-converted", "", NULL);
-
-       g_free (inner_text);
-       g_free (inner_html);
-}
-
 gchar *
 dom_process_content_for_plain_text (WebKitDOMDocument *document,
                                     EHTMLEditorWebExtension *extension)
diff --git a/web-extensions/composer/e-html-editor-view-dom-functions.h 
b/web-extensions/composer/e-html-editor-view-dom-functions.h
index 177946e..eb47b54 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.h
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.h
@@ -130,7 +130,8 @@ gboolean    dom_process_on_key_press        (WebKitDOMDocument *document,
                                                 guint key_val,
                                                 guint state);
 
-gchar *                dom_process_content_for_draft   (WebKitDOMDocument *document);
+gchar *                dom_process_content_for_draft   (WebKitDOMDocument *document,
+                                                gboolean only_inner_body);
 
 gchar *                dom_process_content_for_plain_text
                                                (WebKitDOMDocument *document,
diff --git a/web-extensions/composer/e-html-editor-web-extension.c 
b/web-extensions/composer/e-html-editor-web-extension.c
index b611fab..b88fb44 100644
--- a/web-extensions/composer/e-html-editor-web-extension.c
+++ b/web-extensions/composer/e-html-editor-web-extension.c
@@ -508,6 +508,7 @@ static const char introspection_xml[] =
 "    </method>"
 "    <method name='DOMProcessContentForDraft'>"
 "      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='b' name='only_inner_body' direction='in'/>"
 "      <arg type='s' name='content' direction='out'/>"
 "    </method>"
 "    <method name='DOMProcessContentForPlainText'>"
@@ -1894,7 +1895,7 @@ handle_method_call (GDBusConnection *connection,
                dom_convert_when_changing_composer_mode (document, extension);
                g_dbus_method_invocation_return_value (invocation, NULL);
        } else if (g_strcmp0 (method_name, "DOMProcessContentAfterModeChange") == 0) {
-               g_variant_get (parameters, "(t)", &page_id);
+               g_variant_get (parameters, "(tb)", &page_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1905,9 +1906,10 @@ handle_method_call (GDBusConnection *connection,
                dom_process_content_after_mode_change (document, extension);
                g_dbus_method_invocation_return_value (invocation, NULL);
        } else if (g_strcmp0 (method_name, "DOMProcessContentForDraft") == 0) {
+               gboolean only_inner_body;
                gchar *value = NULL;
 
-               g_variant_get (parameters, "(t)", &page_id);
+               g_variant_get (parameters, "(tb)", &page_id, &only_inner_body);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1915,7 +1917,7 @@ handle_method_call (GDBusConnection *connection,
                        goto error;
 
                document = webkit_web_page_get_dom_document (web_page);
-               value = dom_process_content_for_draft (document);
+               value = dom_process_content_for_draft (document, only_inner_body);
 
                g_dbus_method_invocation_return_value (
                        invocation,


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