[evolution/wip-webkit2] Move EMailDisplay DOM bindings creation to WK2



commit da71dff1749815f6ac6ddead921715dda4eac2f1
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Oct 29 15:40:16 2013 +0100

    Move EMailDisplay DOM bindings creation to WK2

 e-util/e-dom-utils.c                     |  266 ++++++++++++++++++++++++++-
 e-util/e-dom-utils.h                     |   14 ++-
 em-format/e-mail-part-headers.c          |   47 +++---
 em-format/e-mail-part.c                  |    6 +-
 em-format/e-mail-part.h                  |    5 +-
 mail/e-mail-display.c                    |  294 +++++++++++-------------------
 web-extensions/evolution-web-extension.c |   35 ++++
 7 files changed, 440 insertions(+), 227 deletions(-)
---
diff --git a/e-util/e-dom-utils.c b/e-util/e-dom-utils.c
index 475e934..4f48414 100644
--- a/e-util/e-dom-utils.c
+++ b/e-util/e-dom-utils.c
@@ -18,6 +18,8 @@
 
 #include "e-dom-utils.h"
 
+#include "../web-extensions/evolution-web-extension.h"
+
 #include <config.h>
 
 static void
@@ -448,25 +450,244 @@ collapse_contacts_list (WebKitDOMEventTarget *event_target,
        g_free (imagesdir);
 }
 
-void
-e_dom_utils_eab_contact_formatter_bind_dom (WebKitDOMDocument *document)
+static void
+toggle_headers_visibility (WebKitDOMElement *button,
+                           WebKitDOMEvent *event,
+                           WebKitDOMDocument *document)
+{
+       WebKitDOMElement *short_headers, *full_headers;
+       WebKitDOMCSSStyleDeclaration *css_short, *css_full;
+       gboolean expanded;
+       const gchar *path;
+       gchar *css_value;
+
+       short_headers = webkit_dom_document_get_element_by_id (
+               document, "__evo-short-headers");
+       if (short_headers == NULL)
+               return;
+
+       css_short = webkit_dom_element_get_style (short_headers);
+
+       full_headers = webkit_dom_document_get_element_by_id (
+               document, "__evo-full-headers");
+       if (full_headers == NULL)
+               return;
+
+       css_full = webkit_dom_element_get_style (full_headers);
+       css_value = webkit_dom_css_style_declaration_get_property_value (
+               css_full, "display");
+       expanded = (g_strcmp0 (css_value, "table") == 0);
+       g_free (css_value);
+
+       webkit_dom_css_style_declaration_set_property (
+               css_full, "display",
+               expanded ? "none" : "table", "", NULL);
+       webkit_dom_css_style_declaration_set_property (
+               css_short, "display",
+               expanded ? "table" : "none", "", NULL);
+
+       if (expanded)
+               path = "evo-file://" EVOLUTION_IMAGESDIR "/plus.png";
+       else
+               path = "evo-file://" EVOLUTION_IMAGESDIR "/minus.png";
+
+       webkit_dom_html_image_element_set_src (
+               WEBKIT_DOM_HTML_IMAGE_ELEMENT (button), path);
+}
+
+static void
+toggle_address_visibility (WebKitDOMElement *button,
+                           WebKitDOMEvent *event,
+                          GDBusConnection *connection)
+{
+       WebKitDOMElement *full_addr, *ellipsis;
+       WebKitDOMElement *parent;
+       WebKitDOMCSSStyleDeclaration *css_full, *css_ellipsis;
+       const gchar *path;
+       gboolean expanded;
+       GError *error = NULL;
+
+       /* <b> element */
+       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (button));
+       /* <td> element */
+       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (parent));
+
+       full_addr = webkit_dom_element_query_selector (parent, "#__evo-moreaddr", NULL);
+
+       if (!full_addr)
+               return;
+
+       css_full = webkit_dom_element_get_style (full_addr);
+
+       ellipsis = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-ellipsis", NULL);
+
+       if (!ellipsis)
+               return;
+
+       css_ellipsis = webkit_dom_element_get_style (ellipsis);
+
+       expanded = (g_strcmp0 (
+               webkit_dom_css_style_declaration_get_property_value (
+               css_full, "display"), "inline") == 0);
+
+       webkit_dom_css_style_declaration_set_property (
+               css_full, "display", (expanded ? "none" : "inline"), "", NULL);
+       webkit_dom_css_style_declaration_set_property (
+               css_ellipsis, "display", (expanded ? "inline" : "none"), "", NULL);
+
+       if (expanded)
+               path = "evo-file://" EVOLUTION_IMAGESDIR "/plus.png";
+       else
+               path = "evo-file://" EVOLUTION_IMAGESDIR "/minus.png";
+
+       if (!WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT (button)) {
+               button = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-img", NULL);
+
+               if (!button)
+                       return;
+       }
+
+       webkit_dom_html_image_element_set_src (
+               WEBKIT_DOM_HTML_IMAGE_ELEMENT (button), path);
+
+       g_dbus_connection_emit_signal (
+               connection,
+               NULL,
+               EVOLUTION_WEB_EXTENSION_OBJECT_PATH,
+               EVOLUTION_WEB_EXTENSION_INTERFACE,
+               "HeadersCollapsed"
+               g_variant_new ("(b)", expanded),
+               &error);
+
+       if (error) {
+               g_warning ("Error emitting signal HeadersCollapsed: %s\n", error->message);
+               g_error_free (error);
+       }
+}
+
+static void
+e_dom_utils_bind_dom (WebKitDOMDocument *document,
+                      const gchar *selector,
+                      const gchar *event,
+                      gpointer callback,
+                      gpointer user_data)
 {
        WebKitDOMNodeList *nodes;
        gulong ii, length;
 
-       nodes = webkit_dom_document_get_elements_by_class_name (
-               document, "_evo_collapse_button");
+       nodes = webkit_dom_document_query_selector_all (
+                       document, selector, NULL);
 
        length = webkit_dom_node_list_get_length (nodes);
        for (ii = 0; ii < length; ii++) {
-
                WebKitDOMNode *node;
 
                node = webkit_dom_node_list_item (nodes, ii);
                webkit_dom_event_target_add_event_listener (
-                       WEBKIT_DOM_EVENT_TARGET (node), "click",
-                       G_CALLBACK (collapse_contacts_list), FALSE, document);
+                       WEBKIT_DOM_EVENT_TARGET (node), event,
+                       G_CALLBACK (callback), FALSE, user_data);
+       }
+}
+
+void
+e_dom_utils_e_mail_display_bind_dom (WebKitDOMDocument *document,
+                                     GDBusConnection *connection)
+{
+       e_dom_utils_bind_dom (
+               document,
+               "#__evo-collapse-headers-img",
+               "click",
+               toggle_headers_visibility,
+               document);
+
+       e_dom_utils_bind_dom (
+               document,
+               "*[id^=__evo-moreaddr-]",
+               "click",
+               toggle_address_visibility,
+               connetion);
+}
+
+void
+e_dom_utils_eab_contact_formatter_bind_dom (WebKitDOMDocument *document)
+{
+       e_dom_utils_bind_dom (
+               document,
+               "._evo_collapse_button",
+               "click",
+               collapse_contacts_list,
+               document);
+}
+
+/* ! This function can be called only from WK2 web-extension ! */
+WebKitDOMElement *
+e_dom_utils_find_element_by_id (WebKitDOMDocument *document,
+                                const gchar *id)
+{
+       WebKitDOMNodeList *frames;
+       WebKitDOMElement *element;
+       gulong ii, length;
+
+       /* Try to look up the element in this DOM document */
+       element = webkit_dom_document_get_element_by_id (document, id);
+       if (element != NULL)
+               return element;
+
+       /* If the element is not here then recursively scan all frames */
+       frames = webkit_dom_document_get_elements_by_tag_name (
+               document, "iframe");
+       length = webkit_dom_node_list_get_length (frames);
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMHTMLIFrameElement *iframe;
+               WebKitDOMDocument *frame_doc;
+               WebKitDOMElement *element;
+
+               iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (
+                       webkit_dom_node_list_item (frames, ii));
+
+               frame_doc = webkit_dom_html_iframe_element_get_content_document (iframe);
+
+               element = e_dom_utils_find_element_by_id (frame_doc, id);
+
+               if (element != NULL)
+                       return element;
        }
+
+       return NULL;
+}
+
+gboolean
+e_dom_utils_element_exists (WebKitDOMDocument *document,
+                            const gchar *element_id)
+{
+       WebKitDOMNodeList *frames;
+       gboolean element_exists = FALSE;
+       gulong ii, length;
+
+       /* Try to look up the element in this DOM document */
+       if (webkit_dom_document_get_element_by_id (document, element_id))
+               return TRUE;
+
+       /* If the element is not here then recursively scan all frames */
+       frames = webkit_dom_document_get_elements_by_tag_name (
+               document, "iframe");
+       length = webkit_dom_node_list_get_length (frames);
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMHTMLIFrameElement *iframe;
+               WebKitDOMDocument *frame_doc;
+
+               iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (
+                       webkit_dom_node_list_item (frames, ii));
+
+               frame_doc = webkit_dom_html_iframe_element_get_content_document (iframe);
+
+               element_exists = e_dom_utils_element_exists (frame_doc, element_id);
+
+               if (element_exists)
+                       return TRUE;
+       }
+
+       return FALSE;
 }
 
 gchar *
@@ -483,3 +704,34 @@ e_dom_utils_get_active_element_name (WebKitDOMDocument *document)
        return webkit_dom_node_get_local_name (WEBKIT_DOM_NODE (element));
 }
 
+void
+e_dom_utils_e_mail_part_headers_bind_dom_element (WebKitDOMDocument *document,
+                                                  const gchar *element_id)
+{
+       WebKitDOMDocument *element_document;
+       WebKitDOMElement *element;
+       WebKitDOMElement *photo;
+       gchar *addr, *uri;
+
+       element = e_dom_utils_find_element_by_id (document, element_id);
+       if (!element)
+               return;
+
+       element_document = webkit_dom_node_get_owner_document (
+               WEBKIT_DOM_NODE (element));
+       photo = webkit_dom_document_get_element_by_id (
+               element_document, "__evo-contact-photo");
+
+       /* Contact photos disabled, the <img> tag is not there. */
+       if (!photo)
+               return;
+
+       addr = webkit_dom_element_get_attribute (photo, "data-mailaddr");
+       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 (addr);
+       g_free (uri);
+}
diff --git a/e-util/e-dom-utils.h b/e-util/e-dom-utils.h
index b8a6989..35db08b 100644
--- a/e-util/e-dom-utils.h
+++ b/e-util/e-dom-utils.h
@@ -48,8 +48,20 @@ void         e_dom_utils_add_css_rule_into_style_sheet
                                                 const gchar *style);
 void           e_dom_utils_eab_contact_formatter_bind_dom
                                                (WebKitDOMDocument *document);
-gchar *        e_dom_utils_get_active_element_name
+void           e_dom_utils_e_mail_display_bind_dom
+                                               (WebKitDOMDocument *document,
+                                                GDBusConnection *connection);
+WebKitDOMElement *
+               e_dom_utils_find_element_by_id  (WebKitDOMDocument *document,
+                                                const gchar *element_id);
+gboolean       e_dom_utils_element_exists
+                                               (WebKitDOMDocument *document,
+                                                const gchar *element_id);
+gchar *                e_dom_utils_get_active_element_name
                                                (WebKitDOMDocument *document);
+void           e_dom_utils_e_mail_part_headers_bind_dom_element
+                                               (WebKitDOMDocument *document,
+                                                const gchar *element_id);
 G_END_DECLS
 
 #endif /* E_DOM_UTILS_H */
diff --git a/em-format/e-mail-part-headers.c b/em-format/e-mail-part-headers.c
index 9087e8e..005e4ec 100644
--- a/em-format/e-mail-part-headers.c
+++ b/em-format/e-mail-part-headers.c
@@ -215,29 +215,32 @@ mail_part_headers_constructed (GObject *object)
 
 static void
 mail_part_headers_bind_dom_element (EMailPart *part,
-                                    WebKitDOMElement *element)
+                                    const gchar *element_id)
 {
-       WebKitDOMDocument *document;
-       WebKitDOMElement *photo;
-       gchar *addr, *uri;
-
-       document = webkit_dom_node_get_owner_document (
-               WEBKIT_DOM_NODE (element));
-       photo = webkit_dom_document_get_element_by_id (
-               document, "__evo-contact-photo");
-
-       /* Contact photos disabled, the <img> tag is not there. */
-       if (photo == NULL)
-               return;
-
-       addr = webkit_dom_element_get_attribute (photo, "data-mailaddr");
-       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 (addr);
-       g_free (uri);
+       /*FIXME XXX Get the proxy here
+       GDBusProxy *web_extension;
+
+       web_extension = e_web_view_get_web_extension_proxy (web_view);
+       if (web_extension) {
+               GVariant *result;
+
+               result = g_dbus_proxy_call_sync (
+                               web_extension,
+                               "EMailPartHeadersBindDOMElement",
+                               g_variant_new (
+                                       "(ts)",
+                                       webkit_web_view_get_page_id (
+                                               WEBKIT_WEB_VIEW (web_view)),
+                                       element_id),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1,
+                               cancellable,
+                               error);
+
+               if (result)
+                       g_variant_unref (result);
+       }
+       */
 }
 
 static void
diff --git a/em-format/e-mail-part.c b/em-format/e-mail-part.c
index c7b0745..fef4504 100644
--- a/em-format/e-mail-part.c
+++ b/em-format/e-mail-part.c
@@ -488,17 +488,17 @@ e_mail_part_set_is_attachment (EMailPart *part,
 
 void
 e_mail_part_bind_dom_element (EMailPart *part,
-                              WebKitDOMElement *element)
+                              const gchar *element_id)
 {
        EMailPartClass *class;
 
        g_return_if_fail (E_IS_MAIL_PART (part));
-       g_return_if_fail (WEBKIT_DOM_IS_ELEMENT (element));
+       g_return_if_fail (element_id && *element_id);
 
        class = E_MAIL_PART_GET_CLASS (part);
 
        if (class->bind_dom_element != NULL)
-               class->bind_dom_element (part, element);
+               class->bind_dom_element (part, element_id);
 }
 
 static EMailPartValidityPair *
diff --git a/em-format/e-mail-part.h b/em-format/e-mail-part.h
index 75057c2..2325fec 100644
--- a/em-format/e-mail-part.h
+++ b/em-format/e-mail-part.h
@@ -20,7 +20,6 @@
 #define E_MAIL_PART_H
 
 #include <camel/camel.h>
-#include <webkit/webkitdom.h>
 
 #include <e-util/e-util.h>
 
@@ -88,7 +87,7 @@ struct _EMailPartClass {
        GObjectClass parent_class;
 
        void            (*bind_dom_element)     (EMailPart *part,
-                                                WebKitDOMElement *element);
+                                                const gchar *element_id);
 };
 
 GType          e_mail_part_get_type            (void) G_GNUC_CONST;
@@ -116,7 +115,7 @@ gboolean    e_mail_part_get_is_attachment   (EMailPart *part);
 void           e_mail_part_set_is_attachment   (EMailPart *part,
                                                 gboolean is_attachment);
 void           e_mail_part_bind_dom_element    (EMailPart *part,
-                                                WebKitDOMElement *element);
+                                                const gchar *element_id);
 void           e_mail_part_update_validity     (EMailPart *part,
                                                 CamelCipherValidity *validity,
                                                 EMailPartValidityFlags validity_type);
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 85cd1c7..d719d4a 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -40,6 +40,8 @@
 #include "em-composer-utils.h"
 #include "em-utils.h"
 
+#include <web-extensions/evolution-web-extension.h>
+
 #define d(x)
 
 #define E_MAIL_DISPLAY_GET_PRIVATE(obj) \
@@ -60,6 +62,8 @@ struct _EMailDisplayPrivate {
        GHashTable *widgets;
 
        guint scheduled_reload;
+
+       guint web_extension_headers_collapsed_signal_id;
 };
 
 enum {
@@ -292,6 +296,7 @@ decide_policy_cb (WebKitWebView *web_view,
        return FALSE;
 }
 
+#if 0
 static void
 mail_display_resource_requested (WebKitWebView *web_view,
                                  WebKitWebFrame *frame,
@@ -723,114 +728,7 @@ exit:
 
        return widget;
 }
-
-static void
-toggle_headers_visibility (WebKitDOMElement *button,
-                           WebKitDOMEvent *event,
-                           WebKitWebView *web_view)
-{
-       WebKitDOMDocument *document;
-       WebKitDOMElement *short_headers, *full_headers;
-       WebKitDOMCSSStyleDeclaration *css_short, *css_full;
-       gboolean expanded;
-       const gchar *path;
-       gchar *css_value;
-
-       document = webkit_web_view_get_dom_document (web_view);
-
-       short_headers = webkit_dom_document_get_element_by_id (
-               document, "__evo-short-headers");
-       if (short_headers == NULL)
-               return;
-
-       css_short = webkit_dom_element_get_style (short_headers);
-
-       full_headers = webkit_dom_document_get_element_by_id (
-               document, "__evo-full-headers");
-       if (full_headers == NULL)
-               return;
-
-       css_full = webkit_dom_element_get_style (full_headers);
-       css_value = webkit_dom_css_style_declaration_get_property_value (
-               css_full, "display");
-       expanded = (g_strcmp0 (css_value, "table") == 0);
-       g_free (css_value);
-
-       webkit_dom_css_style_declaration_set_property (
-               css_full, "display",
-               expanded ? "none" : "table", "", NULL);
-       webkit_dom_css_style_declaration_set_property (
-               css_short, "display",
-               expanded ? "table" : "none", "", NULL);
-
-       if (expanded)
-               path = "evo-file://" EVOLUTION_IMAGESDIR "/plus.png";
-       else
-               path = "evo-file://" EVOLUTION_IMAGESDIR "/minus.png";
-
-       webkit_dom_html_image_element_set_src (
-               WEBKIT_DOM_HTML_IMAGE_ELEMENT (button), path);
-
-       e_mail_display_set_headers_collapsed (
-               E_MAIL_DISPLAY (web_view), expanded);
-
-       d (printf ("Headers %s!\n", expanded ? "collapsed" : "expanded"));
-}
-
-static void
-toggle_address_visibility (WebKitDOMElement *button,
-                           WebKitDOMEvent *event)
-{
-       WebKitDOMElement *full_addr, *ellipsis;
-       WebKitDOMElement *parent;
-       WebKitDOMCSSStyleDeclaration *css_full, *css_ellipsis;
-       const gchar *path;
-       gboolean expanded;
-
-       /* <b> element */
-       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (button));
-       /* <td> element */
-       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (parent));
-
-       full_addr = webkit_dom_element_query_selector (parent, "#__evo-moreaddr", NULL);
-
-       if (!full_addr)
-               return;
-
-       css_full = webkit_dom_element_get_style (full_addr);
-
-       ellipsis = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-ellipsis", NULL);
-
-       if (!ellipsis)
-               return;
-
-       css_ellipsis = webkit_dom_element_get_style (ellipsis);
-
-       expanded = (g_strcmp0 (
-               webkit_dom_css_style_declaration_get_property_value (
-               css_full, "display"), "inline") == 0);
-
-       webkit_dom_css_style_declaration_set_property (
-               css_full, "display", (expanded ? "none" : "inline"), "", NULL);
-       webkit_dom_css_style_declaration_set_property (
-               css_ellipsis, "display", (expanded ? "inline" : "none"), "", NULL);
-
-       if (expanded)
-               path = "evo-file://" EVOLUTION_IMAGESDIR "/plus.png";
-       else
-               path = "evo-file://" EVOLUTION_IMAGESDIR "/minus.png";
-
-       if (!WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT (button)) {
-               button = webkit_dom_element_query_selector (parent, "#__evo-moreaddr-img", NULL);
-
-               if (!button)
-                       return;
-       }
-
-       webkit_dom_html_image_element_set_src (
-               WEBKIT_DOM_HTML_IMAGE_ELEMENT (button), path);
-}
-
+#endif
 static void
 add_color_css_rule_for_web_view (EWebView *view,
                                 const char *color_name,
@@ -888,99 +786,126 @@ initialize_web_view_colors (EMailDisplay *display)
 }
 
 static void
-setup_dom_bindings (GObject *object,
-                    GParamSpec *pspec,
-                    gpointer user_data)
+headers_collapsed_signal_cb (GDBusConnection *connection,
+                          const gchar *sender_name,
+                          const gchar *object_path,
+                          const gchar *interface_name,
+                          const gchar *signal_name,
+                          GVariant *parameters,
+                          EMailDisplay *display)
 {
-       WebKitWebView *web_view;
-       WebKitWebFrame *frame;
-       WebKitLoadStatus load_status;
-       WebKitDOMDocument *document;
-       WebKitDOMElement *button;
-       WebKitDOMNodeList *list;
-       gint length, ii = 0;
+       gboolean expanded;
 
-       frame = WEBKIT_WEB_FRAME (object);
-       load_status = webkit_web_frame_get_load_status (frame);
-       if (load_status != WEBKIT_LOAD_FINISHED)
+       if (g_strcmp0 (signal_name, "HeadersCollapsed") != 0)
                return;
 
-       web_view = webkit_web_frame_get_web_view (frame);
-       document = webkit_web_view_get_dom_document (web_view);
+       if (parameters)
+               g_variant_get (parameters, "(b)", &expanded);
 
-       button = webkit_dom_document_get_element_by_id (
-               document, "__evo-collapse-headers-img");
-       if (button != NULL)
-               webkit_dom_event_target_add_event_listener (
-                       WEBKIT_DOM_EVENT_TARGET (button), "click",
-                       G_CALLBACK (toggle_headers_visibility),
-                       FALSE, web_view);
+       e_mail_display_set_headers_collapsed (
+               display, expanded);
+}
 
-       list = webkit_dom_document_query_selector_all (document, "*[id^=__evo-moreaddr-]", NULL);
+static void
+setup_dom_bindings (WebKitWebView *web_view,
+                    WebKitLoadEvent load_event,
+                    gpointer user_data)
+{
+       GDBusProxy *web_extension;
+       EMailDisplay *display;
+       GVariant* result;
 
-       length = webkit_dom_node_list_get_length (list);
+       if (load_event != WEBKIT_LOAD_FINISHED)
+               return;
 
-       for (ii = 0; ii < length; ii++) {
-               button = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, ii));
+       display = E_MAIL_DISPLAY (web_view);
+
+       web_extension = e_web_view_get_web_extension_proxy (E_WEB_VIEW (web_view));
 
-               webkit_dom_event_target_add_event_listener (
-                       WEBKIT_DOM_EVENT_TARGET (button), "click",
-                       G_CALLBACK (toggle_address_visibility), FALSE,
+       display->priv->web_extension_headers_collapsed_signal_id =
+               g_dbus_connection_signal_subscribe (
+                       g_dbus_proxy_get_connection (web_extension),
+                       g_dbus_proxy_get_name (web_extension),
+                       EVOLUTION_WEB_EXTENSION_INTERFACE,
+                       "RecurToggled",
+                       EVOLUTION_WEB_EXTENSION_OBJECT_PATH,
+                       NULL,
+                       G_DBUS_SIGNAL_FLAGS_NONE,
+                       (GDBusSignalCallback) headers_collapsed_signal_cb,
+                       display,
                        NULL);
+
+       if (web_extension) {
+               result = g_dbus_proxy_call_sync (
+                               web_extension,
+                               "EMailDisplayBindDOM",
+                               g_variant_new (
+                                       "(t)",
+                                       webkit_web_view_get_page_id (web_view)),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1,
+                               NULL,
+                               NULL);
+               if (result)
+                       g_variant_unref (result);
        }
 }
 
 static void
-mail_parts_bind_dom (GObject *object,
-                     GParamSpec *pspec,
+mail_parts_bind_dom (WebKitWebView *web_view,
+                     WebKitLoadEvent load_event,
                      gpointer user_data)
 {
-       WebKitWebFrame *frame;
-       WebKitLoadStatus load_status;
-       WebKitWebView *web_view;
-       WebKitDOMDocument *document;
        EMailDisplay *display;
        GQueue queue = G_QUEUE_INIT;
        GList *head, *link;
-       const gchar *frame_name;
-
-       frame = WEBKIT_WEB_FRAME (object);
-       load_status = webkit_web_frame_get_load_status (frame);
+       GDBusProxy *web_extension;
 
-       if (load_status != WEBKIT_LOAD_FINISHED)
+       if (load_event != WEBKIT_LOAD_FINISHED)
                return;
 
-       web_view = webkit_web_frame_get_web_view (frame);
        display = E_MAIL_DISPLAY (web_view);
        if (display->priv->part_list == NULL)
                return;
 
        initialize_web_view_colors (display);
-       frame_name = webkit_web_frame_get_name (frame);
-       if (frame_name == NULL || *frame_name == '\0')
-               frame_name = ".message.headers";
 
-       document = webkit_web_view_get_dom_document (web_view);
+       web_extension = e_web_view_get_web_extension_proxy (E_WEB_VIEW (display));
+       if (!web_extension)
+               return;
 
        e_mail_part_list_queue_parts (
-               display->priv->part_list, frame_name, &queue);
+               display->priv->part_list, NULL, &queue);
        head = g_queue_peek_head_link (&queue);
 
        for (link = head; link != NULL; link = g_list_next (link)) {
                EMailPart *part = E_MAIL_PART (link->data);
-               WebKitDOMElement *element;
                const gchar *part_id;
-
-               /* Iterate only the parts rendered in
-                * the frame and all it's subparts. */
-               if (!e_mail_part_id_has_prefix (part, frame_name))
-                       break;
+               GVariant *result;
+               gboolean element_exists = FALSE;
 
                part_id = e_mail_part_get_id (part);
-               element = find_element_by_id (document, part_id);
 
-               if (element != NULL)
-                       e_mail_part_bind_dom_element (part, element);
+               result = g_dbus_proxy_call_sync (
+                               web_extension,
+                               "ElementExists",
+                               g_variant_new (
+                                       "(ts)",
+                                       webkit_web_view_get_page_id (
+                                               WEBKIT_WEB_VIEW (display)),
+                                       part_id),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               -1,
+                               NULL,
+                               NULL);
+
+               if (result) {
+                       g_variant_get (result, "(b)", &element_exists);
+                       g_variant_unref (result);
+               }
+
+               if (element_exists)
+                       e_mail_part_bind_dom_element (part, part_id);
        }
 
        while (!g_queue_is_empty (&queue))
@@ -988,19 +913,6 @@ mail_parts_bind_dom (GObject *object,
 }
 
 static void
-mail_display_frame_created (WebKitWebView *web_view,
-                            WebKitWebFrame *frame,
-                            gpointer user_data)
-{
-       d (printf ("Frame %s created!\n", webkit_web_frame_get_name (frame)));
-
-       /* Call bind_func of all parts written in this frame */
-       g_signal_connect (
-               frame, "notify::load-status",
-               G_CALLBACK (mail_parts_bind_dom), NULL);
-}
-
-static void
 mail_display_uri_changed (EMailDisplay *display,
                           GParamSpec *pspec,
                           gpointer dummy)
@@ -1127,6 +1039,14 @@ mail_display_dispose (GObject *object)
                        priv->settings, G_SIGNAL_MATCH_DATA,
                        0, 0, NULL, NULL, object);
 
+       if (priv->web_extension_headers_collapsed_signal_id > 0) {
+               g_dbus_connection_signal_unsubscribe (
+                       g_dbus_proxy_get_connection (
+                               e_web_view_get_web_extension_proxy (E_WEB_VIEW (object))),
+                       priv->web_extension_headers_collapsed_signal_id);
+               priv->web_extension_headers_collapsed_signal_id = 0;
+       }
+
        g_clear_object (&priv->part_list);
        g_clear_object (&priv->formatter);
        g_clear_object (&priv->settings);
@@ -1424,7 +1344,6 @@ e_mail_display_class_init (EMailDisplayClass *class)
        widget_class = GTK_WIDGET_CLASS (class);
        widget_class->realize = mail_display_realize;
        widget_class->style_updated = mail_display_style_updated;
-       widget_class->button_press_event = mail_display_button_press_event;
 
        web_view_class = E_WEB_VIEW_CLASS (class);
        web_view_class->redirect_uri = mail_display_redirect_uri;
@@ -1491,8 +1410,7 @@ e_mail_display_init (EMailDisplay *display)
 {
        GtkUIManager *ui_manager;
        const gchar *user_cache_dir;
-       WebKitWebSettings *settings;
-       WebKitWebFrame *main_frame;
+       WebKitSettings *settings;
        GtkActionGroup *actions;
 
        display->priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
@@ -1504,26 +1422,21 @@ e_mail_display_init (EMailDisplay *display)
        display->priv->force_image_load = FALSE;
        display->priv->scheduled_reload = 0;
 
-       webkit_web_view_set_full_content_zoom (WEBKIT_WEB_VIEW (display), TRUE);
-
        settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (display));
        g_object_set (settings, "enable-frame-flattening", TRUE, NULL);
 
        g_signal_connect (
                display, "decide-policy",
                G_CALLBACK (decide_policy_cb), NULL);
-       g_signal_connect (
+/*     g_signal_connect (
                display, "resource-request-starting",
-               G_CALLBACK (mail_display_resource_requested), NULL);
+               G_CALLBACK (mail_display_resource_requested), NULL);*/
        g_signal_connect (
                display, "process-mailto",
                G_CALLBACK (mail_display_process_mailto), NULL);
-       g_signal_connect (
+/*     g_signal_connect (
                display, "create-plugin-widget",
-               G_CALLBACK (mail_display_plugin_widget_requested), NULL);
-       g_signal_connect (
-               display, "frame-created",
-               G_CALLBACK (mail_display_frame_created), NULL);
+               G_CALLBACK (mail_display_plugin_widget_requested), NULL);*/
        g_signal_connect (
                display, "notify::uri",
                G_CALLBACK (mail_display_uri_changed), NULL);
@@ -1541,12 +1454,11 @@ e_mail_display_init (EMailDisplay *display)
 
        e_web_view_update_fonts (E_WEB_VIEW (display));
 
-       main_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (display));
        g_signal_connect (
-               main_frame, "notify::load-status",
+               display, "notify::load-changed",
                G_CALLBACK (setup_dom_bindings), NULL);
        g_signal_connect (
-               main_frame, "notify::load-status",
+               display, "notify::load-changed",
                G_CALLBACK (mail_parts_bind_dom), NULL);
 
        actions = e_web_view_get_action_group (E_WEB_VIEW (display), "mailto");
diff --git a/web-extensions/evolution-web-extension.c b/web-extensions/evolution-web-extension.c
index 8f73d1e..cd6e357 100644
--- a/web-extensions/evolution-web-extension.c
+++ b/web-extensions/evolution-web-extension.c
@@ -30,6 +30,9 @@ static GDBusConnection *dbus_connection;
 static const char introspection_xml[] =
 "<node>"
 "  <interface name='org.gnome.Evolution.WebExtension'>"
+"    <signal name='HeadersCollapsed'>"
+"      <arg type='b' name='expanded' direction='out'/>"
+"    </signal>"
 "    <method name='ReplaceLocalImageLinks'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "    </method>"
@@ -58,6 +61,14 @@ static const char introspection_xml[] =
 "    <method name='EABContactFormatterBindDOM'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "    </method>"
+"    <method name='EMailDisplayBindDOM'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"    </method>"
+"    <method name='ElementExists'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='s' name='element_id' direction='in'/>"
+"      <arg type='b' name='element_exists' direction='out'/>"
+"    </method>"
 "    <method name='GetActiveElementName'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_name' direction='out'/>"
@@ -223,6 +234,30 @@ handle_method_call (GDBusConnection *connection,
                e_dom_utils_eab_contact_formatter_bind_dom (document);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "EMailDisplayBindDOM") == 0) {
+               g_variant_get (parameters, "(t)", &page_id);
+               web_page = get_webkit_web_page_or_return_dbus_error (invocation, web_extension, page_id);
+               if (!web_page)
+                       return;
+
+               document = webkit_web_page_get_dom_document (web_page);
+               e_dom_utils_e_mail_display_bind_dom (document, connection);
+
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "ElementExists") == 0) {
+               const gchar *element_id;
+               gboolean element_exists;
+
+               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
+               web_page = get_webkit_web_page_or_return_dbus_error (invocation, web_extension, page_id);
+               if (!web_page)
+                       return;
+
+               document = webkit_web_page_get_dom_document (web_page);
+               element_exists = e_dom_utils_element_exists (document, element_id);
+
+               g_dbus_method_invocation_return_value (
+                       invocation, g_variant_new ("(b)", element_exists));
        } else if (g_strcmp0 (method_name, "GetActiveElementName") == 0) {
                gchar *element_name;
 


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