[evolution/wip-webkit2] Move Mail module to WK2
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip-webkit2] Move Mail module to WK2
- Date: Tue, 29 Oct 2013 15:11:18 +0000 (UTC)
commit 34ac1c4cdbf64661ff499c4acdc470421f365028
Author: Tomas Popela <tpopela redhat com>
Date: Tue Oct 29 16:07:08 2013 +0100
Move Mail module to WK2
configure.ac | 1 +
modules/mail/e-mail-shell-view-private.c | 143 +++++++++++++++----
modules/mail/e-mail-shell-view-private.h | 6 +-
modules/mail/module-mail-dom-utils.c | 35 +++++
modules/mail/module-mail-dom-utils.h | 32 ++++
modules/mail/web-extension/Makefile.am | 18 +++
.../mail/web-extension/module-mail-web-extension.c | 151 ++++++++++++++++++++
.../mail/web-extension/module-mail-web-extension.h | 26 ++++
8 files changed, 383 insertions(+), 29 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d1ed324..0576c6a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1540,6 +1540,7 @@ modules/itip-formatter/plugin/Makefile
modules/itip-formatter/web-extension/Makefile
modules/mail-config/Makefile
modules/mail/Makefile
+modules/mail/web-extension/Makefile
modules/mailto-handler/Makefile
modules/mdn/Makefile
modules/offline-alert/Makefile
diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c
index dd980e7..fef6be6 100644
--- a/modules/mail/e-mail-shell-view-private.c
+++ b/modules/mail/e-mail-shell-view-private.c
@@ -24,6 +24,7 @@
#endif
#include "e-mail-shell-view-private.h"
+#include "web-extension/module-mail-web-extension.h"
#include "e-util/e-util-private.h"
@@ -254,36 +255,44 @@ mail_shell_view_folder_tree_popup_event_cb (EShellView *shell_view,
}
static gboolean
-mail_shell_view_mail_display_needs_key (EMailDisplay *mail_display,
+mail_shell_view_mail_display_needs_key (EMailShellView *mail_shell_view,
+ EMailDisplay *mail_display,
gboolean with_input)
{
- gboolean needs_key = FALSE;
-
if (gtk_widget_has_focus (GTK_WIDGET (mail_display))) {
- WebKitWebFrame *frame;
- WebKitDOMDocument *dom;
- WebKitDOMElement *element;
- gchar *name = NULL;
-
- frame = webkit_web_view_get_focused_frame (WEBKIT_WEB_VIEW (mail_display));
- if (!frame)
- return FALSE;
- dom = webkit_web_frame_get_dom_document (frame);
- /* intentionally used "static_cast" */
- element = webkit_dom_html_document_get_active_element ((WebKitDOMHTMLDocument *) dom);
-
- if (element)
- name = webkit_dom_node_get_node_name (WEBKIT_DOM_NODE (element));
-
- /* if INPUT or TEXTAREA has focus, then any key press should go there */
- if (name && ((with_input && g_ascii_strcasecmp (name, "INPUT") == 0) || g_ascii_strcasecmp
(name, "TEXTAREA") == 0)) {
- needs_key = TRUE;
+ GDBusProxy *web_extension;
+
+ web_extension = e_mail_shell_view_get_web_extension_proxy (mail_shell_view);
+ if (web_extension) {
+ GVariant *result;
+ const gchar *element_name = NULL;
+
+ result = g_dbus_proxy_call_sync (
+ web_extension,
+ "GetActiveElementName",
+ g_variant_new (
+ "(t)",
+ webkit_web_view_get_page_id (
+ WEBKIT_WEB_VIEW (mail_display))),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+
+ if (result) {
+ element_name = g_variant_get_string (result, NULL);
+ g_variant_unref (result);
+
+ if (element_name && *element_name) {
+ if ((with_input && g_strcmp0 (element_name, "input") == 0) ||
+ g_strcmp0 (element_name, "textarea") == 0) {
+ return TRUE;
+ }
+ }
+ }
}
-
- g_free (name);
}
-
- return needs_key;
+ return FALSE;
}
static gboolean
@@ -327,7 +336,8 @@ mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view,
case GDK_KEY_Next:
case GDK_KEY_End:
case GDK_KEY_Begin:
- if (!mail_shell_view_mail_display_needs_key (mail_display, FALSE) &&
+#if 0
+ if (!mail_shell_view_mail_display_needs_key (mail_shell_view, mail_display, FALSE) &&
webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (mail_display)) !=
webkit_web_view_get_focused_frame (WEBKIT_WEB_VIEW (mail_display))) {
WebKitDOMDocument *document;
@@ -344,13 +354,13 @@ mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view,
*/
webkit_dom_dom_window_focus (window);
}
-
+#endif
return FALSE;
default:
return FALSE;
}
- if (mail_shell_view_mail_display_needs_key (mail_display, TRUE))
+ if (mail_shell_view_mail_display_needs_key (mail_shell_view, mail_display, TRUE))
return FALSE;
gtk_action_activate (action);
@@ -580,12 +590,82 @@ mail_shell_view_search_filter_changed_cb (EMailShellView *mail_shell_view)
e_mail_reader_avoid_next_mark_as_seen (E_MAIL_READER (mail_view));
}
+static void
+web_extension_proxy_created_cb (GDBusProxy *proxy,
+ GAsyncResult *result,
+ EMailShellView *mail_shell_view)
+{
+ GError *error = NULL;
+
+ mail_shell_view->priv->web_extension = g_dbus_proxy_new_finish (result, &error);
+ if (!mail_shell_view->priv->web_extension) {
+ g_warning ("Error creating web extension proxy: %s\n", error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+web_extension_appeared_cb (GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ EMailShellView *mail_shell_view)
+{
+ g_dbus_proxy_new (
+ connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ name,
+ MODULE_MAIL_WEB_EXTENSION_OBJECT_PATH,
+ MODULE_MAIL_WEB_EXTENSION_INTERFACE,
+ NULL,
+ (GAsyncReadyCallback)web_extension_proxy_created_cb,
+ mail_shell_view);
+}
+
+static void
+web_extension_vanished_cb (GDBusConnection *connection,
+ const gchar *name,
+ EMailShellView *mail_shell_view)
+{
+ g_clear_object (&mail_shell_view->priv->web_extension);
+}
+
+static void
+mail_shell_view_watch_web_extension (EMailShellView *mail_shell_view)
+{
+ char *service_name;
+
+ service_name = g_strdup_printf ("%s-%u", MODULE_MAIL_WEB_EXTENSION_SERVICE_NAME, getpid ());
+ mail_shell_view->priv->web_extension_watch_name_id =
+ g_bus_watch_name (
+ G_BUS_TYPE_SESSION,
+ service_name,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ (GBusNameAppearedCallback) web_extension_appeared_cb,
+ (GBusNameVanishedCallback) web_extension_vanished_cb,
+ mail_shell_view, NULL);
+
+ g_free (service_name);
+}
+
+GDBusProxy *
+e_mail_shell_view_get_web_extension_proxy (EMailShellView *mail_shell_view)
+{
+ g_return_val_if_fail (E_IS_MAIL_SHELL_VIEW (mail_shell_view), NULL);
+
+ return mail_shell_view->priv->web_extension;
+}
+
void
e_mail_shell_view_private_init (EMailShellView *mail_shell_view)
{
g_signal_connect (
mail_shell_view, "notify::view-id",
G_CALLBACK (mail_shell_view_notify_view_id_cb), NULL);
+
+ mail_shell_view_watch_web_extension (mail_shell_view);
}
void
@@ -842,6 +922,13 @@ e_mail_shell_view_private_dispose (EMailShellView *mail_shell_view)
g_object_unref (priv->search_account_cancel);
priv->search_account_cancel = NULL;
}
+
+ if (priv->web_extension_watch_name_id > 0) {
+ g_bus_unwatch_name (priv->web_extension_watch_name_id);
+ priv->web_extension_watch_name_id = 0;
+ }
+
+ g_clear_object (&priv->web_extension);
}
void
diff --git a/modules/mail/e-mail-shell-view-private.h b/modules/mail/e-mail-shell-view-private.h
index 9986feb..874f5c3 100644
--- a/modules/mail/e-mail-shell-view-private.h
+++ b/modules/mail/e-mail-shell-view-private.h
@@ -146,6 +146,9 @@ struct _EMailShellViewPrivate {
GtkToolItem *send_receive_tool_item;
GtkToolItem *send_receive_tool_separator;
+
+ GDBusProxy *web_extension;
+ guint web_extension_watch_name_id;
};
void e_mail_shell_view_private_init
@@ -171,7 +174,8 @@ void e_mail_shell_view_update_sidebar
(EMailShellView *mail_shell_view);
void e_mail_shell_view_update_send_receive_menus
(EMailShellView *mail_shell_view);
-
+GDBusProxy * e_mail_shell_view_get_web_extension_proxy
+ (EMailShellView *mail_shell_view);
G_END_DECLS
#endif /* E_MAIL_SHELL_VIEW_PRIVATE_H */
diff --git a/modules/mail/module-mail-dom-utils.c b/modules/mail/module-mail-dom-utils.c
new file mode 100644
index 0000000..66cf264
--- /dev/null
+++ b/modules/mail/module-mail-dom-utils.c
@@ -0,0 +1,35 @@
+/*
+ * module-mail-dom-utils.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "module-mail-dom-utils.h"
+
+#include <config.h>
+
+gchar *
+module_mail_dom_utils_get_active_element_name (WebKitDOMDocument *document)
+{
+ WebKitDOMElement *element;
+ /* FIXME XXX Do version that checks underlying documents */
+
+ element = webkit_dom_html_document_get_active_element (
+ WEBKIT_DOM_HTML_DOCUMENT (document));
+ if (!element)
+ return NULL;
+
+ return webkit_dom_node_get_local_name (WEBKIT_DOM_NODE (element));
+}
diff --git a/modules/mail/module-mail-dom-utils.h b/modules/mail/module-mail-dom-utils.h
new file mode 100644
index 0000000..98d02a8
--- /dev/null
+++ b/modules/mail/module-mail-dom-utils.h
@@ -0,0 +1,32 @@
+/*
+ * module-mail-dom-utils.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef MODULE_MAIL_DOM_UTILS_H
+#define MODULE_MAIL_DOM_UTILS_H
+
+#include <webkitdom/webkitdom.h>
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+gchar * module_mail_dom_utils_get_active_element_name
+ (WebKitDOMDocument *document);
+G_END_DECLS
+
+#endif /* MODULE_MAIL_DOM_UTILS_H */
diff --git a/modules/mail/web-extension/Makefile.am b/modules/mail/web-extension/Makefile.am
new file mode 100644
index 0000000..6138f71
--- /dev/null
+++ b/modules/mail/web-extension/Makefile.am
@@ -0,0 +1,18 @@
+webextensions_LTLIBRARIES = libmodulemailwebextension.la
+
+libmodulemailwebextension_la_SOURCES = \
+ module-mail-web-extension.c \
+ module-mail-web-extension.h
+
+libmodulemailwebextension_la_CPPFLAGS = \
+ -DWEBEXTENSIONS_COMPILATION \
+ $(GNOME_PLATFORM_CFLAGS) \
+ $(AM_CPPFLAGS) \
+ $(WEB_EXTENSIONS_CFLAGS)
+
+libmodulemailwebextension_la_LIBADD = \
+ $(GNOME_PLATFORM_LIBS) \
+ $(WEB_EXTENSIONS_LIBS)
+
+libmodulemailwebextension_la_LDFLAGS = \
+ -module -avoid-version -no-undefined
diff --git a/modules/mail/web-extension/module-mail-web-extension.c
b/modules/mail/web-extension/module-mail-web-extension.c
new file mode 100644
index 0000000..9f1cd8f
--- /dev/null
+++ b/modules/mail/web-extension/module-mail-web-extension.c
@@ -0,0 +1,151 @@
+/*
+ * module-mail-web-extension.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "module-mail-web-extension.h"
+
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+#include <webkit2/webkit-web-extension.h>
+
+#include "../module-mail-dom-utils.h"
+
+/* FIXME Clean it */
+static GDBusConnection *dbus_connection;
+
+static const char introspection_xml[] =
+"<node>"
+" <interface name='org.gnome.Evolution.Module.Mail.WebExtension'>"
+" <method name='GetActiveElementName'>"
+" <arg type='t' name='page_id' direction='in'/>"
+" <arg type='s' name='element_name' direction='out'/>"
+" </method>"
+" </interface>"
+"</node>";
+
+static WebKitWebPage *
+get_webkit_web_page_or_return_dbus_error (GDBusMethodInvocation *invocation,
+ WebKitWebExtension *web_extension,
+ guint64 page_id)
+{
+ WebKitWebPage *web_page = webkit_web_extension_get_page (web_extension, page_id);
+ if (!web_page) {
+ g_dbus_method_invocation_return_error (
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
+ "Invalid page ID: %"G_GUINT64_FORMAT, page_id);
+ }
+ return web_page;
+}
+
+static void
+handle_method_call (GDBusConnection *connection,
+ const char *sender,
+ const char *object_path,
+ const char *interface_name,
+ const char *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ WebKitWebExtension *web_extension = WEBKIT_WEB_EXTENSION (user_data);
+ WebKitWebPage *web_page;
+ WebKitDOMDocument *document;
+ guint64 page_id;
+
+ if (g_strcmp0 (interface_name, MODULE_MAIL_WEB_EXTENSION_INTERFACE) != 0)
+ return;
+
+ if (g_strcmp0 (method_name, "GetActiveElementName") == 0) {
+ gchar *element_name;
+
+ 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);
+ element_name = e_dom_utils_get_active_element_name (document);
+
+ g_dbus_method_invocation_return_value (
+ invocation, g_variant_new ("(s)", element_name));
+
+ g_free (element_name);
+ }
+}
+
+static const GDBusInterfaceVTable interface_vtable = {
+ handle_method_call,
+ NULL,
+ NULL
+};
+
+static void
+bus_acquired_cb (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ guint registration_id;
+ GError *error = NULL;
+ static GDBusNodeInfo *introspection_data = NULL;
+
+ if (!introspection_data)
+ introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+
+ registration_id =
+ g_dbus_connection_register_object (
+ connection,
+ MODULE_MAIL_WEB_EXTENSION_OBJECT_PATH,
+ introspection_data->interfaces[0],
+ &interface_vtable,
+ g_object_ref (user_data),
+ g_object_unref,
+ &error);
+
+ if (!registration_id) {
+ g_warning ("Failed to register object: %s\n", error->message);
+ g_error_free (error);
+ } else {
+ dbus_connection = connection;
+ g_object_add_weak_pointer (G_OBJECT (connection), (gpointer *)&dbus_connection);
+ }
+}
+
+/* Forward declaration */
+G_MODULE_EXPORT void webkit_web_extension_initialize (WebKitWebExtension *extension);
+
+G_MODULE_EXPORT void
+webkit_web_extension_initialize (WebKitWebExtension *extension)
+{
+ char *service_name;
+
+ service_name =
+ g_strdup_printf (
+ "%s-%s",
+ MODULE_MAIL_WEB_EXTENSION_SERVICE_NAME,
+ g_getenv ("MODULE_MAIL_WEB_EXTENSION_ID"));
+
+ g_bus_own_name (
+ G_BUS_TYPE_SESSION,
+ service_name,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ bus_acquired_cb,
+ NULL, NULL,
+ g_object_ref (extension),
+ g_object_unref);
+
+ g_free (service_name);
+}
diff --git a/modules/mail/web-extension/module-mail-web-extension.h
b/modules/mail/web-extension/module-mail-web-extension.h
new file mode 100644
index 0000000..f1fe0a8
--- /dev/null
+++ b/modules/mail/web-extension/module-mail-web-extension.h
@@ -0,0 +1,26 @@
+/*
+ * module-mail-web-extension.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef MODULE_MAIL_WEB_EXTENSION_H
+#define MODULE_MAIL_WEB_EXTENSION_H
+
+#define MODULE_MAIL_WEB_EXTENSION_SERVICE_NAME "org.gnome.Evolution.Module.Mail.WebExtension"
+#define MODULE_MAIL_WEB_EXTENSION_OBJECT_PATH "/org/gnome/Evolution/Module/Mail/WebExtension"
+#define MODULE_MAIL_WEB_EXTENSION_INTERFACE "org.gnome.Evolution.Module.Mail.WebExtension"
+
+#endif /* MODULE_MAIL_WEB_EXTENSION_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]