[evolution/gnome-3-28] Bug 793583 - webkit_web_view_load_html() garbages linked CSS content



commit de0a5b9ed7834a0297ebfdd9c925b6446ed392c8
Author: Milan Crha <mcrha redhat com>
Date:   Tue Apr 10 11:48:38 2018 +0200

    Bug 793583 - webkit_web_view_load_html() garbages linked CSS content

 src/e-util/e-mail-signature-preview.c       |    6 +---
 src/e-util/e-web-view.c                     |   13 +++++-----
 src/modules/webkit-editor/e-webkit-editor.c |   33 ++++++++++++++++++++------
 3 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/src/e-util/e-mail-signature-preview.c b/src/e-util/e-mail-signature-preview.c
index bce4988..80adfb8 100644
--- a/src/e-util/e-mail-signature-preview.c
+++ b/src/e-util/e-mail-signature-preview.c
@@ -95,14 +95,12 @@ mail_signature_preview_load_cb (ESource *source,
        mime_type = e_source_mail_signature_get_mime_type (extension);
 
        if (g_strcmp0 (mime_type, "text/html") == 0) {
-               webkit_web_view_load_html (
-                       WEBKIT_WEB_VIEW (preview), contents, "file:///");
+               e_web_view_load_string (E_WEB_VIEW (preview), contents);
        } else {
                gchar *string;
 
                string = g_markup_printf_escaped ("<pre>%s</pre>", contents);
-               webkit_web_view_load_html (
-                       WEBKIT_WEB_VIEW (preview), string, "file:///");
+               e_web_view_load_string (E_WEB_VIEW (preview), string);
                g_free (string);
        }
 
diff --git a/src/e-util/e-web-view.c b/src/e-util/e-web-view.c
index 679a91f..24e169b 100644
--- a/src/e-util/e-web-view.c
+++ b/src/e-util/e-web-view.c
@@ -1448,11 +1448,14 @@ static void
 web_view_load_string (EWebView *web_view,
                       const gchar *string)
 {
+       GBytes *bytes;
+
        if (string == NULL)
                string = "";
 
-       webkit_web_view_load_html (
-               WEBKIT_WEB_VIEW (web_view), string, "evo-file:///");
+       bytes = g_bytes_new (string, strlen (string));
+       webkit_web_view_load_bytes (WEBKIT_WEB_VIEW (web_view), bytes, NULL, NULL, "evo-file:///");
+       g_bytes_unref (bytes);
 }
 
 static void
@@ -2574,13 +2577,11 @@ e_web_view_clear (EWebView *web_view)
 
        e_web_view_replace_load_cancellable (web_view, FALSE);
 
-       webkit_web_view_load_html (
-               WEBKIT_WEB_VIEW (web_view),
+       e_web_view_load_string (web_view,
                "<html>"
                "<head></head>"
                "<body class=\"-e-web-view-background-color -e-web-view-text-color\"></body>"
-               "</html>",
-               NULL);
+               "</html>");
 }
 
 void
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 720e7eb..ff8d351 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -1763,6 +1763,26 @@ set_convert_in_situ (EWebKitEditor *wk_editor,
 }
 
 static void
+e_webkit_editor_load_html_as_bytes (EWebKitEditor *wk_editor,
+                                   const gchar *html)
+{
+       GBytes *bytes;
+
+       g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
+
+       if (!html)
+               html = "";
+
+       bytes = g_bytes_new (html, strlen (html));
+
+       /* Make WebKit think we are displaying a local file, so that it
+        * does not block loading resources from file:// protocol */
+       webkit_web_view_load_bytes (WEBKIT_WEB_VIEW (wk_editor), bytes, NULL, NULL, "file://");
+
+       g_bytes_unref (bytes);
+}
+
+static void
 webkit_editor_insert_content (EContentEditor *editor,
                               const gchar *content,
                               EContentEditorInsertContentFlags flags)
@@ -1823,14 +1843,14 @@ webkit_editor_insert_content (EContentEditor *editor,
                if ((strstr (content, "data-evo-draft") ||
                     strstr (content, "data-evo-signature-plain-text-mode"))) {
                        wk_editor->priv->reload_in_progress = TRUE;
-                       webkit_web_view_load_html (WEBKIT_WEB_VIEW (wk_editor), content, "file://");
+                       e_webkit_editor_load_html_as_bytes (wk_editor, content);
                        return;
                }
 
                if (strstr (content, "data-evo-draft") && !(wk_editor->priv->html_mode)) {
                        set_convert_in_situ (wk_editor, TRUE);
                        wk_editor->priv->reload_in_progress = TRUE;
-                       webkit_web_view_load_html (WEBKIT_WEB_VIEW (wk_editor), content, "file://");
+                       e_webkit_editor_load_html_as_bytes (wk_editor, content);
                        return;
                }
 
@@ -1840,8 +1860,7 @@ webkit_editor_insert_content (EContentEditor *editor,
                                if (!show_lose_formatting_dialog (wk_editor)) {
                                        wk_editor->priv->reload_in_progress = TRUE;
                                        webkit_editor_set_html_mode (wk_editor, TRUE);
-                                       webkit_web_view_load_html (
-                                               WEBKIT_WEB_VIEW (wk_editor), content, "file://");
+                                       e_webkit_editor_load_html_as_bytes (wk_editor, content);
                                        return;
                                }
                        }
@@ -1849,7 +1868,7 @@ webkit_editor_insert_content (EContentEditor *editor,
                }
 
                wk_editor->priv->reload_in_progress = TRUE;
-               webkit_web_view_load_html (WEBKIT_WEB_VIEW (wk_editor), content, "file://");
+               e_webkit_editor_load_html_as_bytes (wk_editor, content);
        } else if ((flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL) &&
                   (flags & E_CONTENT_EDITOR_INSERT_TEXT_PLAIN)) {
                e_util_invoke_g_dbus_proxy_call_with_error_check (
@@ -5204,9 +5223,7 @@ webkit_editor_constructed (GObject *object)
        webkit_settings_set_allow_file_access_from_file_urls (web_settings, TRUE);
        webkit_settings_set_enable_developer_extras (web_settings, e_util_get_webkit_developer_mode_enabled 
());
 
-       /* Make WebKit think we are displaying a local file, so that it
-        * does not block loading resources from file:// protocol */
-       webkit_web_view_load_html (WEBKIT_WEB_VIEW (object), "", "file://");
+       e_webkit_editor_load_html_as_bytes (wk_editor, "");
 }
 
 static GObjectConstructParam*


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