[evolution/wip/webkit2] Correctly check the return value from various WebKit DOM functions



commit 9c7ebeccf24281b23416393b34d598f3dd02ea69
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Mar 29 17:49:57 2016 +0200

    Correctly check the return value from various WebKit DOM functions

 .../e-html-editor-selection-dom-functions.c        |   11 +--
 .../composer/e-html-editor-view-dom-functions.c    |   65 ++++++++++++-------
 web-extensions/e-dom-utils.c                       |   20 ++++--
 3 files changed, 59 insertions(+), 37 deletions(-)
---
diff --git a/web-extensions/composer/e-html-editor-selection-dom-functions.c 
b/web-extensions/composer/e-html-editor-selection-dom-functions.c
index 918cbfa..6c96d7f 100644
--- a/web-extensions/composer/e-html-editor-selection-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-selection-dom-functions.c
@@ -3276,9 +3276,8 @@ get_has_style (WebKitDOMDocument *document,
                 * has type=cite, then ignore it unless style_tag is "citation" */
                if (result && WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (element)) {
                        if (webkit_dom_element_has_attribute (element, "type")) {
-                               gchar *type;
-                               type = webkit_dom_element_get_attribute (element, "type");
-                               if (!accept_citation && (g_ascii_strncasecmp (type, "cite", 4) == 0)) {
+                               gchar *type = webkit_dom_element_get_attribute (element, "type");
+                               if (!accept_citation && (type && g_ascii_strncasecmp (type, "cite", 4) == 0)) 
{
                                        result = FALSE;
                                }
                                g_free (type);
@@ -3841,8 +3840,7 @@ is_monospaced_element (WebKitDOMElement *element)
                return FALSE;
 
        value = webkit_dom_element_get_attribute (element, "face");
-
-       if (g_strcmp0 (value, "monospace") == 0)
+       if (value && g_strcmp0 (value, "monospace") == 0)
                ret_val = TRUE;
 
        g_free (value);
@@ -4592,9 +4590,8 @@ dom_selection_is_citation (WebKitDOMDocument *document)
        g_free (text_content);
 
        value = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "type");
-
        /* citation == <blockquote type='cite'> */
-       if (strstr (value, "cite"))
+       if (value && strstr (value, "cite"))
                ret_val = TRUE;
        else
                ret_val = get_has_style (document, "citation");
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 66a6361..28bc3ad 100644
--- a/web-extensions/composer/e-html-editor-view-dom-functions.c
+++ b/web-extensions/composer/e-html-editor-view-dom-functions.c
@@ -430,7 +430,7 @@ dom_node_is_citation_node (WebKitDOMNode *node)
        value = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "type");
 
        /* citation == <blockquote type='cite'> */
-       if (g_strcmp0 (value, "cite") == 0) {
+       if (value && g_strcmp0 (value, "cite") == 0) {
                g_free (value);
                return TRUE;
        } else {
@@ -858,7 +858,8 @@ move_elements_to_body (WebKitDOMDocument *document,
 
                element = dom_get_paragraph_element (document, extension, -1, 0);
                credits = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "data-credits");
-               webkit_dom_html_element_set_inner_text (WEBKIT_DOM_HTML_ELEMENT (element), credits, NULL);
+               if (credits)
+                       webkit_dom_html_element_set_inner_text (WEBKIT_DOM_HTML_ELEMENT (element), credits, 
NULL);
                g_free (credits);
 
                webkit_dom_node_insert_before (
@@ -5451,7 +5452,8 @@ dom_convert_content (WebKitDOMDocument *document,
 
                element = dom_get_paragraph_element (document, extension, -1, 0);
                credits = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "data-credits");
-               webkit_dom_html_element_set_inner_text (WEBKIT_DOM_HTML_ELEMENT (element), credits, NULL);
+               if (credits)
+                       webkit_dom_html_element_set_inner_text (WEBKIT_DOM_HTML_ELEMENT (element), credits, 
NULL);
                g_free (credits);
 
                webkit_dom_node_insert_before (
@@ -6710,7 +6712,7 @@ process_elements (EHTMLEditorWebExtension *extension,
                                const gchar *css_align;
 
                                class = webkit_dom_element_get_class_name (WEBKIT_DOM_ELEMENT (node));
-                               if ((css_align = strstr (class, "-x-evo-align-"))) {
+                               if (class && (css_align = strstr (class, "-x-evo-align-"))) {
                                        gchar *align;
                                        gchar *content_with_align;
                                        gint length;
@@ -6800,7 +6802,7 @@ process_elements (EHTMLEditorWebExtension *extension,
                        const gchar *css_align;
 
                        class = webkit_dom_element_get_class_name (WEBKIT_DOM_ELEMENT (child));
-                       if ((css_align = strstr (class, "-x-evo-align-"))) {
+                       if (class && (css_align = strstr (class, "-x-evo-align-"))) {
                                if (!g_str_has_prefix (css_align + 13, "left")) {
                                        if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (child))
                                                webkit_dom_element_set_attribute (
@@ -7211,7 +7213,7 @@ toggle_paragraphs_style_in_element (WebKitDOMDocument *document,
                        style = webkit_dom_element_get_attribute (
                                WEBKIT_DOM_ELEMENT (node), "style");
 
-                       if ((css_align = strstr (style, "text-align: "))) {
+                       if (style && (css_align = strstr (style, "text-align: "))) {
                                webkit_dom_element_set_attribute (
                                        WEBKIT_DOM_ELEMENT (node),
                                        "style",
@@ -7244,7 +7246,7 @@ toggle_paragraphs_style_in_element (WebKitDOMDocument *document,
                                style = webkit_dom_element_get_attribute (
                                        WEBKIT_DOM_ELEMENT (node), "style");
 
-                               if ((css_align = strstr (style, "text-align: "))) {
+                               if (style && (css_align = strstr (style, "text-align: "))) {
                                        style_to_add = g_str_has_prefix (
                                                css_align + 12, "center") ?
                                                        "text-align: center;" :
@@ -7836,7 +7838,8 @@ adapt_to_editor_dom_changes (WebKitDOMDocument *document)
                        webkit_dom_node_append_child (WEBKIT_DOM_NODE (element), child, NULL);
 
                style = webkit_dom_element_get_attribute (WEBKIT_DOM_ELEMENT (node), "style");
-               webkit_dom_element_set_attribute (element, "style", style, NULL);
+               if (style)
+                       webkit_dom_element_set_attribute (element, "style", style, NULL);
 
                remove_node (node);
                g_object_unref (node);
@@ -7958,21 +7961,28 @@ dom_get_inline_images_data (WebKitDOMDocument *document,
                gchar *src = webkit_dom_element_get_attribute (
                        WEBKIT_DOM_ELEMENT (node), "src");
 
+               if (!src)
+                       continue;
+
                if ((id = g_hash_table_lookup (added, src)) != NULL) {
                        cid = g_strdup_printf ("cid:%s", id);
                        g_free (src);
                } else {
                        gchar *data_name = webkit_dom_element_get_attribute (
                                WEBKIT_DOM_ELEMENT (node), "data-name");
-                       gchar *new_id;
 
-                       new_id = camel_header_msgid_generate (uid_domain);
-                       g_variant_builder_add (
-                               builder, "sss", src, data_name, new_id);
-                       cid = g_strdup_printf ("cid:%s", new_id);
+                       if (data_name) {
+                               gchar *new_id;
+
+                               new_id = camel_header_msgid_generate (uid_domain);
+                               g_variant_builder_add (
+                                       builder, "sss", src, data_name, new_id);
+                               cid = g_strdup_printf ("cid:%s", new_id);
 
-                       g_hash_table_insert (added, src, new_id);
-                       g_free (new_id);
+                               g_hash_table_insert (added, src, new_id);
+                               g_free (new_id);
+                       }
+                       g_free (data_name);
                }
                webkit_dom_element_set_attribute (
                        WEBKIT_DOM_ELEMENT (node), "src", cid, NULL);
@@ -7997,6 +8007,9 @@ dom_get_inline_images_data (WebKitDOMDocument *document,
                gchar *src = webkit_dom_element_get_attribute (
                        WEBKIT_DOM_ELEMENT (node), "background");
 
+               if (!src)
+                       continue;
+
                if ((id = g_hash_table_lookup (added, src)) != NULL) {
                        cid = g_strdup_printf ("cid:%s", id);
                        webkit_dom_element_set_attribute (
@@ -8005,18 +8018,22 @@ dom_get_inline_images_data (WebKitDOMDocument *document,
                } else {
                        gchar *data_name = webkit_dom_element_get_attribute (
                                WEBKIT_DOM_ELEMENT (node), "data-name");
-                       gchar *new_id;
 
-                       new_id = camel_header_msgid_generate (uid_domain);
-                       g_variant_builder_add (
-                               builder, "sss", src, data_name, new_id);
-                       cid = g_strdup_printf ("cid:%s", new_id);
+                       if (data_name) {
+                               gchar *new_id;
 
-                       g_hash_table_insert (added, src, new_id);
-                       g_free (new_id);
+                               new_id = camel_header_msgid_generate (uid_domain);
+                               g_variant_builder_add (
+                                       builder, "sss", src, data_name, new_id);
+                               cid = g_strdup_printf ("cid:%s", new_id);
 
-                       webkit_dom_element_set_attribute (
-                               WEBKIT_DOM_ELEMENT (node), "background", cid, NULL);
+                               g_hash_table_insert (added, src, new_id);
+                               g_free (new_id);
+
+                               webkit_dom_element_set_attribute (
+                                       WEBKIT_DOM_ELEMENT (node), "background", cid, NULL);
+                       }
+                       g_free (data_name);
                }
                g_free (cid);
                g_object_unref (node);
diff --git a/web-extensions/e-dom-utils.c b/web-extensions/e-dom-utils.c
index 951d83d..99db999 100644
--- a/web-extensions/e-dom-utils.c
+++ b/web-extensions/e-dom-utils.c
@@ -543,6 +543,9 @@ collapse_contacts_list (WebKitDOMEventTarget *event_target,
        document = user_data;
        id = webkit_dom_element_get_id (WEBKIT_DOM_ELEMENT (event_target));
 
+       if (!id)
+               return;
+
        list_id = g_strconcat ("list-", id, NULL);
        list = webkit_dom_document_get_element_by_id (document, list_id);
        g_free (id);
@@ -1026,7 +1029,7 @@ e_dom_utils_e_mail_part_headers_bind_dom_element (WebKitDOMDocument *document,
        WebKitDOMDocument *element_document;
        WebKitDOMElement *element;
        WebKitDOMElement *photo;
-       gchar *addr, *uri;
+       gchar *addr;
 
        element = e_dom_utils_find_element_by_id (document, element_id);
        if (!element)
@@ -1042,13 +1045,18 @@ e_dom_utils_e_mail_part_headers_bind_dom_element (WebKitDOMDocument *document,
                return;
 
        addr = webkit_dom_element_get_attribute (photo, "data-mailaddr");
-       uri = g_strdup_printf ("mail://contact-photo?mailaddr=%s", addr);
+       if (addr) {
+               gchar *uri;
 
-       webkit_dom_html_image_element_set_src (
-               WEBKIT_DOM_HTML_IMAGE_ELEMENT (photo), uri);
+               uri = g_strdup_printf ("mail://contact-photo?mailaddr=%s", addr);
+
+               webkit_dom_html_image_element_set_src (
+                       WEBKIT_DOM_HTML_IMAGE_ELEMENT (photo), uri);
+
+               g_free (uri);
+       }
 
        g_free (addr);
-       g_free (uri);
 }
 
 void
@@ -1249,7 +1257,7 @@ display_mode_toggle_button_cb (WebKitDOMElement *button,
                E_WEB_EXTENSION_OBJECT_PATH,
                E_WEB_EXTENSION_INTERFACE,
                "VCardInlineDisplayModeToggled",
-               g_variant_new ("(s)", element_id),
+               g_variant_new ("(s)", element_id ? element_id : ""),
                &error);
 
        if (error) {


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