[evolution/wip/mcrha/webkit-jsc-api] Change EMailDisplayPopupExtension and add EWebView::before-popup-event



commit 10a64dadaa3c060acf02f0e466b38f0000f2d578
Author: Milan Crha <mcrha redhat com>
Date:   Wed Oct 2 15:10:52 2019 +0200

    Change EMailDisplayPopupExtension and add EWebView::before-popup-event

 src/e-util/e-web-view.c                            | 109 ++++++---------------
 src/e-util/e-web-view.h                            |  15 ++-
 src/mail/e-mail-display-popup-extension.c          |   8 +-
 src/mail/e-mail-display-popup-extension.h          |   6 +-
 src/mail/e-mail-display.c                          |  20 ++--
 .../e-mail-display-popup-prefer-plain.c            |  43 ++++----
 .../e-mail-display-popup-text-highlight.c          |  43 ++++----
 src/modules/vcard-inline/e-mail-formatter-vcard.c  |   3 +-
 8 files changed, 109 insertions(+), 138 deletions(-)
---
diff --git a/src/e-util/e-web-view.c b/src/e-util/e-web-view.c
index 0b97041dbb..9dba47a704 100644
--- a/src/e-util/e-web-view.c
+++ b/src/e-util/e-web-view.c
@@ -143,6 +143,7 @@ enum {
        PROCESS_MAILTO,
        URI_REQUESTED,
        CONTENT_LOADED,
+       BEFORE_POPUP_EVENT,
        LAST_SIGNAL
 };
 
@@ -626,6 +627,9 @@ web_view_got_elem_from_point_for_popup_event_cb (GObject *source_object,
        if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
                gboolean handled = FALSE;
 
+               g_signal_emit (web_view, signals[BEFORE_POPUP_EVENT], 0,
+                       web_view->priv->last_popup_link_uri, NULL);
+
                g_signal_emit (web_view, signals[POPUP_EVENT], 0,
                        web_view->priv->last_popup_link_uri, event, &handled);
        }
@@ -1817,6 +1821,14 @@ web_view_suggest_filename (EWebView *web_view,
        return g_strdup (cp);
 }
 
+static void
+web_view_before_popup_event (EWebView *web_view,
+                            const gchar *uri)
+{
+       e_web_view_set_selected_uri (web_view, uri);
+       e_web_view_update_actions (web_view);
+}
+
 static gboolean
 web_view_popup_event (EWebView *web_view,
                       const gchar *uri,
@@ -2265,6 +2277,7 @@ e_web_view_class_init (EWebViewClass *class)
        class->load_string = web_view_load_string;
        class->load_uri = web_view_load_uri;
        class->suggest_filename = web_view_suggest_filename;
+       class->before_popup_event = web_view_before_popup_event;
        class->popup_event = web_view_popup_event;
        class->stop_loading = web_view_stop_loading;
        class->update_actions = web_view_update_actions;
@@ -2412,6 +2425,15 @@ e_web_view_class_init (EWebViewClass *class)
                NULL,
                G_TYPE_BOOLEAN, 2, G_TYPE_STRING, GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
 
+       signals[BEFORE_POPUP_EVENT] = g_signal_new (
+               "before-popup-event",
+               G_TYPE_FROM_CLASS (class),
+               G_SIGNAL_RUN_LAST,
+               G_STRUCT_OFFSET (EWebViewClass, before_popup_event),
+               NULL, NULL,
+               g_cclosure_marshal_VOID__STRING,
+               G_TYPE_NONE, 1, G_TYPE_STRING);
+
        signals[STATUS_MESSAGE] = g_signal_new (
                "status-message",
                G_TYPE_FROM_CLASS (class),
@@ -4273,72 +4295,10 @@ e_web_view_add_css_rule_into_style_sheet (EWebView *web_view,
 }
 
 /**
- * e_web_view_get_document_uri_from_point:
- * @web_view: an #EWebView
- * @x: x-coordinate
- * @y: y-coordinate
- *
- * Returns: A document URI which is under the @x, @y coordinates or %NULL,
- * if there is none. Free the returned pointer with g_free() when done with it.
- *
- * Since: 3.22
- **/
-gchar *
-e_web_view_get_document_uri_from_point (EWebView *web_view,
-                                       gint32 x,
-                                       gint32 y)
-{
-       GDBusProxy *web_extension;
-       GVariant *result;
-       GError *local_error = NULL;
-
-       g_return_val_if_fail (E_IS_WEB_VIEW (web_view), NULL);
-
-       web_extension = e_web_view_get_web_extension_proxy (web_view);
-       if (!web_extension)
-               return NULL;
-
-       result = e_util_invoke_g_dbus_proxy_call_sync_wrapper_full (
-               web_extension,
-               "GetDocumentURIFromPoint",
-               g_variant_new (
-                       "(tii)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (web_view)),
-                       x,
-                       y),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               &local_error);
-
-       if (local_error)
-               g_dbus_error_strip_remote_error (local_error);
-
-       e_util_claim_dbus_proxy_call_error (web_extension, "GetDocumentURIFromPoint", local_error);
-       g_clear_error (&local_error);
-
-       if (result) {
-               gchar *uri = NULL;
-
-               g_variant_get (result, "(s)", &uri);
-               g_variant_unref (result);
-
-               if (g_strcmp0 (uri, "") == 0) {
-                       g_free (uri);
-                       uri = NULL;
-               }
-
-               return uri;
-       }
-
-       return NULL;
-}
-
-/**
- * e_web_view_set_document_iframe_src:
+ * e_web_view_set_iframe_src:
  * @web_view: an #EWebView
  * @document_uri: a document URI for whose IFrame change the source
- * @new_iframe_src: the source to change the IFrame to
+ * @src_uri: the source to change the IFrame to
  *
  * Change IFrame source for the given @document_uri IFrame
  * to the @new_iframe_src.
@@ -4346,24 +4306,15 @@ e_web_view_get_document_uri_from_point (EWebView *web_view,
  * Since: 3.22
  **/
 void
-e_web_view_set_document_iframe_src (EWebView *web_view,
-                                   const gchar *document_uri,
-                                   const gchar *new_iframe_src)
+e_web_view_set_iframe_src (EWebView *web_view,
+                          const gchar *iframe_id,
+                          const gchar *src_uri)
 {
-       guint64 page_id;
-
        g_return_if_fail (E_IS_WEB_VIEW (web_view));
 
-       /* Cannot call this synchronously, blocking the local main loop, because the reload
-          can on the WebProcess side can be asking for a redirection policy, waiting
-          for a response which may be waiting in the blocked main loop. */
-
-       page_id = webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (web_view));
-
-       e_web_extension_container_call_simple (web_view->priv->container,
-               page_id, web_view->priv->stamp,
-               "SetDocumentIFrameSrc",
-               g_variant_new ("(tss)", page_id, document_uri, new_iframe_src));
+       e_web_view_jsc_run_script (WEBKIT_WEB_VIEW (web_view), web_view->priv->load_cancellable,
+               "Evo.SetIFrameSrc(%s, %s);",
+               iframe_id, src_uri);
 }
 
 /**
diff --git a/src/e-util/e-web-view.h b/src/e-util/e-web-view.h
index 871f848ed2..6208afe7f8 100644
--- a/src/e-util/e-web-view.h
+++ b/src/e-util/e-web-view.h
@@ -115,9 +115,11 @@ struct _EWebViewClass {
                                                 gchar **redirect_to_uri);
        void            (*content_loaded)       (EWebView *web_view,
                                                 const gchar *frame_id);
+       void            (*before_popup_event)   (EWebView *web_view,
+                                                const gchar *uri);
 
        /* Padding for future expansion */
-       gpointer reserved[16];
+       gpointer reserved[15];
 };
 
 GType          e_web_view_get_type             (void) G_GNUC_CONST;
@@ -241,14 +243,9 @@ void               e_web_view_add_css_rule_into_style_sheet
                                                 const gchar *style);
 const gchar *  e_web_view_get_citation_color_for_level
                                                (gint level);
-gchar *                e_web_view_get_document_uri_from_point
-                                               (EWebView *web_view,
-                                                gint32 x,
-                                                gint32 y);
-void           e_web_view_set_document_iframe_src
-                                               (EWebView *web_view,
-                                                const gchar *document_uri,
-                                                const gchar *new_iframe_src);
+void           e_web_view_set_iframe_src       (EWebView *web_view,
+                                                const gchar *iframe_id,
+                                                const gchar *new_src);
 void           e_web_view_register_element_clicked
                                                (EWebView *web_view,
                                                 const gchar *element_class,
diff --git a/src/mail/e-mail-display-popup-extension.c b/src/mail/e-mail-display-popup-extension.c
index 2f9e91948e..b199f4f249 100644
--- a/src/mail/e-mail-display-popup-extension.c
+++ b/src/mail/e-mail-display-popup-extension.c
@@ -33,14 +33,16 @@ e_mail_display_popup_extension_default_init (EMailDisplayPopupExtensionInterface
  * e_mail_display_popup_extension_update_actions:
  *
  * @extension: An object derived from #EMailDisplayPopupExtension
- * @popup_document_uri: Document URI on top of which the popup menu had been invoked
+ * @popup_iframe_src: iframe source URI on top of which the popup menu had been invoked
+ * @popup_iframe_id: iframe ID on top of which the popup menu had been invoked
  *
  * When #EMailDisplay is about to display a popup menu, it calls this function
  * on every extension so that they can add their items to the menu.
  */
 void
 e_mail_display_popup_extension_update_actions (EMailDisplayPopupExtension *extension,
-                                              const gchar *popup_document_uri)
+                                              const gchar *popup_iframe_src,
+                                              const gchar *popup_iframe_id)
 {
        EMailDisplayPopupExtensionInterface *iface;
 
@@ -49,5 +51,5 @@ e_mail_display_popup_extension_update_actions (EMailDisplayPopupExtension *exten
        iface = E_MAIL_DISPLAY_POPUP_EXTENSION_GET_INTERFACE (extension);
        g_return_if_fail (iface->update_actions != NULL);
 
-       iface->update_actions (extension, popup_document_uri);
+       iface->update_actions (extension, popup_iframe_src, popup_iframe_id);
 }
diff --git a/src/mail/e-mail-display-popup-extension.h b/src/mail/e-mail-display-popup-extension.h
index bedd23ed7d..3ea5b1d3c5 100644
--- a/src/mail/e-mail-display-popup-extension.h
+++ b/src/mail/e-mail-display-popup-extension.h
@@ -48,14 +48,16 @@ struct _EMailDisplayPopupExtensionInterface {
        GTypeInterface parent_interface;
 
        void    (*update_actions)               (EMailDisplayPopupExtension *extension,
-                                                const gchar *popup_document_uri);
+                                                const gchar *popup_iframe_src,
+                                                const gchar *popup_iframe_id);
 };
 
 GType          e_mail_display_popup_extension_get_type (void);
 
 void           e_mail_display_popup_extension_update_actions
                                                        (EMailDisplayPopupExtension *extension,
-                                                        const gchar *popup_document_uri);
+                                                        const gchar *popup_iframe_src,
+                                                        const gchar *popup_iframe_id);
 
 G_END_DECLS
 
diff --git a/src/mail/e-mail-display.c b/src/mail/e-mail-display.c
index 9f0b55e9ab..533e18bdaa 100644
--- a/src/mail/e-mail-display.c
+++ b/src/mail/e-mail-display.c
@@ -1652,15 +1652,14 @@ mail_display_style_updated (GtkWidget *widget)
                style_updated (widget);
 }
 
-static gboolean
-mail_display_popup_event (EWebView *web_view,
-                         const gchar *uri,
-                         GdkEvent *event)
+static void
+mail_display_before_popup_event (EWebView *web_view,
+                                const gchar *uri)
 {
-       gchar *popup_document_uri;
+       gchar *popup_iframe_src = NULL, *popup_iframe_id = NULL;
        GList *list, *link;
 
-       e_web_view_get_last_popup_place (web_view, &popup_document_uri, NULL, NULL, NULL);
+       e_web_view_get_last_popup_place (web_view, &popup_iframe_src, &popup_iframe_id, NULL, NULL);
 
        list = e_extensible_list_extensions (E_EXTENSIBLE (web_view), E_TYPE_EXTENSION);
 
@@ -1670,14 +1669,15 @@ mail_display_popup_event (EWebView *web_view,
                if (!E_IS_MAIL_DISPLAY_POPUP_EXTENSION (extension))
                        continue;
 
-               e_mail_display_popup_extension_update_actions (E_MAIL_DISPLAY_POPUP_EXTENSION (extension), 
popup_document_uri);
+               e_mail_display_popup_extension_update_actions (E_MAIL_DISPLAY_POPUP_EXTENSION (extension), 
popup_iframe_src, popup_iframe_id);
        }
 
-       g_free (popup_document_uri);
+       g_free (popup_iframe_src);
+       g_free (popup_iframe_id);
        g_list_free (list);
 
        /* Chain up to parent's method. */
-       return E_WEB_VIEW_CLASS (e_mail_display_parent_class)->popup_event (web_view, uri, event);
+       E_WEB_VIEW_CLASS (e_mail_display_parent_class)->before_popup_event (web_view, uri);
 }
 
 static gboolean
@@ -2130,7 +2130,7 @@ e_mail_display_class_init (EMailDisplayClass *class)
        web_view_class = E_WEB_VIEW_CLASS (class);
        web_view_class->suggest_filename = mail_display_suggest_filename;
        web_view_class->set_fonts = mail_display_set_fonts;
-       web_view_class->popup_event = mail_display_popup_event;
+       web_view_class->before_popup_event = mail_display_before_popup_event;
 
        g_object_class_install_property (
                object_class,
diff --git a/src/modules/prefer-plain/e-mail-display-popup-prefer-plain.c 
b/src/modules/prefer-plain/e-mail-display-popup-prefer-plain.c
index 4d6c360242..8b613fb546 100644
--- a/src/modules/prefer-plain/e-mail-display-popup-prefer-plain.c
+++ b/src/modules/prefer-plain/e-mail-display-popup-prefer-plain.c
@@ -35,7 +35,8 @@ struct _EMailDisplayPopupPreferPlain {
 
        gchar *text_plain_id;
        gchar *text_html_id;
-       gchar *document_uri;
+       gchar *iframe_src;
+       gchar *iframe_id;
 
        GtkActionGroup *action_group;
 };
@@ -95,10 +96,10 @@ toggle_part (GtkAction *action,
        GHashTable *query;
        gchar *uri;
 
-       if (!pp_extension->document_uri)
+       if (!pp_extension->iframe_src)
                return;
 
-       soup_uri = soup_uri_new (pp_extension->document_uri);
+       soup_uri = soup_uri_new (pp_extension->iframe_src);
 
        if (!soup_uri || !soup_uri->query) {
                if (soup_uri)
@@ -124,8 +125,8 @@ toggle_part (GtkAction *action,
        uri = soup_uri_to_string (soup_uri, FALSE);
        soup_uri_free (soup_uri);
 
-       e_web_view_set_document_iframe_src (E_WEB_VIEW (e_extension_get_extensible (E_EXTENSION (extension))),
-               pp_extension->document_uri, uri);
+       e_web_view_set_iframe_src (E_WEB_VIEW (e_extension_get_extensible (E_EXTENSION (extension))),
+               pp_extension->iframe_id, uri);
 
        g_free (uri);
 }
@@ -168,14 +169,19 @@ set_text_html_id (EMailDisplayPopupPreferPlain *extension,
 }
 
 static void
-set_document_uri (EMailDisplayPopupPreferPlain *extension,
-                  const gchar *document_uri)
+set_popup_place (EMailDisplayPopupPreferPlain *extension,
+                const gchar *iframe_src,
+                const gchar *iframe_id)
 {
-       if (extension->document_uri == document_uri)
-               return;
+       if (g_strcmp0 (extension->iframe_src, iframe_src)) {
+               g_free (extension->iframe_src);
+               extension->iframe_src = g_strdup (iframe_src);
+       }
 
-       g_free (extension->document_uri);
-       extension->document_uri = g_strdup (document_uri);
+       if (g_strcmp0 (extension->iframe_id, iframe_id)) {
+               g_free (extension->iframe_id);
+               extension->iframe_id = g_strdup (iframe_id);
+       }
 }
 
 static GtkActionGroup *
@@ -227,7 +233,8 @@ create_group (EMailDisplayPopupExtension *extension)
 
 static void
 mail_display_popup_prefer_plain_update_actions (EMailDisplayPopupExtension *extension,
-                                               const gchar *popup_document_uri)
+                                               const gchar *popup_iframe_src,
+                                               const gchar *popup_iframe_id)
 {
        EMailDisplay *display;
        EMailDisplayPopupPreferPlain *pp_extension;
@@ -249,10 +256,10 @@ mail_display_popup_prefer_plain_update_actions (EMailDisplayPopupExtension *exte
        if (!pp_extension->action_group)
                pp_extension->action_group = create_group (extension);
 
-       set_document_uri (pp_extension, popup_document_uri);
+       set_popup_place (pp_extension, popup_iframe_src, popup_iframe_id);
 
-       if (pp_extension->document_uri)
-               soup_uri = soup_uri_new (pp_extension->document_uri);
+       if (pp_extension->iframe_src)
+               soup_uri = soup_uri_new (pp_extension->iframe_src);
        else
                soup_uri = NULL;
 
@@ -383,7 +390,8 @@ e_mail_display_popup_prefer_plain_finalize (GObject *object)
 
        g_free (extension->text_html_id);
        g_free (extension->text_plain_id);
-       g_free (extension->document_uri);
+       g_free (extension->iframe_src);
+       g_free (extension->iframe_id);
 
        /* Chain up to parent's finalize() method. */
        G_OBJECT_CLASS (e_mail_display_popup_prefer_plain_parent_class)->finalize (object);
@@ -420,5 +428,6 @@ e_mail_display_popup_prefer_plain_init (EMailDisplayPopupPreferPlain *extension)
        extension->action_group = NULL;
        extension->text_html_id = NULL;
        extension->text_plain_id = NULL;
-       extension->document_uri = NULL;
+       extension->iframe_src = NULL;
+       extension->iframe_id = NULL;
 }
diff --git a/src/modules/text-highlight/e-mail-display-popup-text-highlight.c 
b/src/modules/text-highlight/e-mail-display-popup-text-highlight.c
index cae12f12f1..51cd3acbe8 100644
--- a/src/modules/text-highlight/e-mail-display-popup-text-highlight.c
+++ b/src/modules/text-highlight/e-mail-display-popup-text-highlight.c
@@ -35,7 +35,8 @@ typedef struct _EMailDisplayPopupTextHighlight {
        GtkActionGroup *action_group;
 
        volatile gint updating;
-       gchar *document_uri;
+       gchar *iframe_src;
+       gchar *iframe_id;
 } EMailDisplayPopupTextHighlight;
 
 typedef struct _EMailDisplayPopupTextHighlightClass {
@@ -106,14 +107,19 @@ static GtkActionEntry entries[] = {
 };
 
 static void
-set_document_uri (EMailDisplayPopupTextHighlight *extension,
-                  const gchar *document_uri)
+set_popup_place (EMailDisplayPopupTextHighlight *extension,
+                const gchar *iframe_src,
+                const gchar *iframe_id)
 {
-       if (extension->document_uri == document_uri)
-               return;
+       if (g_strcmp0 (extension->iframe_src, iframe_src)) {
+               g_free (extension->iframe_src);
+               extension->iframe_src = g_strdup (iframe_src);
+       }
 
-       g_free (extension->document_uri);
-       extension->document_uri = g_strdup (document_uri);
+       if (g_strcmp0 (extension->iframe_id, iframe_id)) {
+               g_free (extension->iframe_id);
+               extension->iframe_id = g_strdup (iframe_id);
+       }
 }
 
 static void
@@ -131,8 +137,8 @@ reformat (GtkAction *old,
        if (g_atomic_int_get (&th_extension->updating))
                return;
 
-       if (th_extension->document_uri)
-               soup_uri = soup_uri_new (th_extension->document_uri);
+       if (th_extension->iframe_src)
+               soup_uri = soup_uri_new (th_extension->iframe_src);
        else
                soup_uri = NULL;
 
@@ -158,8 +164,8 @@ reformat (GtkAction *old,
        uri = soup_uri_to_string (soup_uri, FALSE);
        soup_uri_free (soup_uri);
 
-       e_web_view_set_document_iframe_src (E_WEB_VIEW (e_extension_get_extensible (E_EXTENSION 
(th_extension))),
-               th_extension->document_uri, uri);
+       e_web_view_set_iframe_src (E_WEB_VIEW (e_extension_get_extensible (E_EXTENSION (th_extension))),
+               th_extension->iframe_id, uri);
 
        g_free (uri);
 }
@@ -293,7 +299,8 @@ emdp_text_highlight_is_enabled (void)
 
 static void
 update_actions (EMailDisplayPopupExtension *extension,
-               const gchar *popup_document_uri)
+               const gchar *popup_iframe_src,
+               const gchar *popup_iframe_id)
 {
        EMailDisplayPopupTextHighlight *th_extension;
 
@@ -302,17 +309,17 @@ update_actions (EMailDisplayPopupExtension *extension,
        if (!th_extension->action_group)
                th_extension->action_group = create_group (extension);
 
-       set_document_uri (th_extension, popup_document_uri);
+       set_popup_place (th_extension, popup_iframe_src, popup_iframe_id);
 
        /* If the part below context menu was made by text-highlight formatter,
         * then try to check what formatter it's using at the moment and set
         * it as active in the popup menu */
-       if (th_extension->document_uri && strstr (th_extension->document_uri, ".text-highlight") != NULL) {
+       if (th_extension->iframe_src && strstr (th_extension->iframe_src, ".text-highlight") != NULL) {
                SoupURI *soup_uri;
                gtk_action_group_set_visible (
                        th_extension->action_group, TRUE);
 
-               soup_uri = soup_uri_new (th_extension->document_uri);
+               soup_uri = soup_uri_new (th_extension->iframe_src);
                if (soup_uri && soup_uri->query) {
                        GHashTable *query = soup_form_decode (soup_uri->query);
                        const gchar *highlighter;
@@ -356,7 +363,8 @@ e_mail_display_popup_text_highlight_finalize (GObject *object)
        extension = E_MAIL_DISPLAY_POPUP_TEXT_HIGHLIGHT (object);
 
        g_clear_object (&extension->action_group);
-       g_free (extension->document_uri);
+       g_free (extension->iframe_src);
+       g_free (extension->iframe_id);
 
        /* Chain up to parent's method */
        G_OBJECT_CLASS (e_mail_display_popup_text_highlight_parent_class)->finalize (object);
@@ -398,5 +406,6 @@ static void
 e_mail_display_popup_text_highlight_init (EMailDisplayPopupTextHighlight *extension)
 {
        extension->action_group = NULL;
-       extension->document_uri = NULL;
+       extension->iframe_src = NULL;
+       extension->iframe_id = NULL;
 }
diff --git a/src/modules/vcard-inline/e-mail-formatter-vcard.c 
b/src/modules/vcard-inline/e-mail-formatter-vcard.c
index a92ce37e44..e930bce9c1 100644
--- a/src/modules/vcard-inline/e-mail-formatter-vcard.c
+++ b/src/modules/vcard-inline/e-mail-formatter-vcard.c
@@ -170,10 +170,11 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
                                "<iframe width=\"100%%\" height=\"auto\" "
                                " class=\"-e-mail-formatter-frame-color -e-web-view-background-color\" "
                                " style=\"border: 1px solid;\""
-                               " src=\"%s\" name=\"%s\"></iframe>"
+                               " src=\"%s\" id=\"%s\" name=\"%s\"></iframe>"
                        "</div>",
                        e_mail_part_get_id (part),
                        access_key, html_label, uri,
+                       e_mail_part_get_id (part),
                        e_mail_part_get_id (part));
                g_output_stream_write_all (
                        stream, str, strlen (str), NULL, cancellable, NULL);


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