[epiphany] Implement get web app title in WebKit2
- From: Xan Lopez <xan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Implement get web app title in WebKit2
- Date: Sat, 2 Mar 2013 14:11:51 +0000 (UTC)
commit 81cbba2fe0acce1de3d78749415fe6eb2374fd71
Author: Manuel Rego Casasnovas <rego igalia com>
Date: Mon Feb 25 13:22:30 2013 +0100
Implement get web app title in WebKit2
https://bugzilla.gnome.org/show_bug.cgi?id=694144
embed/web-extension/ephy-web-extension.c | 9 ++++
src/window-commands.c | 65 ++++++++++++++++++++++++-----
2 files changed, 62 insertions(+), 12 deletions(-)
---
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index d6e9f53..8d82c1a 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -31,6 +31,10 @@ static const char introspection_xml[] =
" <arg type='t' name='page_id' direction='in'/>"
" <arg type='b' name='has_modified_forms' direction='out'/>"
" </method>"
+ " <method name='GetWebAppTitle'>"
+ " <arg type='t' name='page_id' direction='in'/>"
+ " <arg type='s' name='title' direction='out'/>"
+ " </method>"
" </interface>"
"</node>";
@@ -64,6 +68,11 @@ handle_method_call (GDBusConnection *connection,
gboolean has_modifed_forms = ephy_web_dom_utils_has_modified_forms (document);
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", has_modifed_forms));
+ } else if (g_strcmp0 (method_name, "GetWebAppTitle") == 0) {
+ WebKitDOMDocument *document = webkit_web_page_get_dom_document (web_page);
+ char *title = ephy_web_dom_utils_get_application_title (document);
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", title ? title : ""));
}
}
diff --git a/src/window-commands.c b/src/window-commands.c
index 04b1e29..8d774e3 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -696,17 +696,10 @@ get_special_case_application_title_for_host (const char *host)
}
static void
-fill_default_application_title (EphyApplicationDialogData *data)
+set_default_application_title (EphyApplicationDialogData *data,
+ char *title)
{
- char *title = NULL;
-#ifdef HAVE_WEBKIT2
- /* TODO: DOM Bindindgs */
-#else
- WebKitDOMDocument *document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (data->view));
- title = ephy_web_dom_utils_get_application_title (document);
-#endif
-
- if (title == NULL)
+ if (title == NULL || title[0] == '\0')
{
SoupURI *uri;
const char *host;
@@ -717,7 +710,7 @@ fill_default_application_title (EphyApplicationDialogData *data)
if (host != NULL && host[0] != '\0')
title = get_special_case_application_title_for_host (host);
- if (title == NULL)
+ if (title == NULL || title[0] == '\0')
{
if (g_str_has_prefix (host, "www."))
title = g_strdup (host + strlen ("www."));
@@ -728,7 +721,7 @@ fill_default_application_title (EphyApplicationDialogData *data)
soup_uri_free (uri);
}
- if (title == NULL)
+ if (title == NULL || title[0] == '\0')
{
title = g_strdup (ephy_web_view_get_title (data->view));
}
@@ -737,6 +730,54 @@ fill_default_application_title (EphyApplicationDialogData *data)
g_free (title);
}
+#ifdef HAVE_WEBKIT2
+static void
+fill_default_application_title_cb (GObject *source,
+ GAsyncResult *async_result,
+ gpointer user_data)
+{
+ EphyApplicationDialogData *data = user_data;
+ GVariant *result;
+ char *title = NULL;
+
+ result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source),
+ async_result,
+ NULL);
+
+ if (result)
+ {
+ g_variant_get (result, "(s)", &title);
+ g_variant_unref (result);
+ }
+
+ set_default_application_title (data, title);
+}
+#endif
+
+static void
+fill_default_application_title (EphyApplicationDialogData *data)
+{
+#ifdef HAVE_WEBKIT2
+ GDBusProxy *web_extension;
+ web_extension = ephy_embed_shell_get_web_extension_proxy (ephy_embed_shell_get_default ());
+ if (web_extension)
+ g_dbus_proxy_call (web_extension,
+ "GetWebAppTitle",
+ g_variant_new("(t)", webkit_web_view_get_page_id (WEBKIT_WEB_VIEW
(data->view))),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ fill_default_application_title_cb,
+ data);
+ else
+ set_default_application_title (data, NULL);
+#else
+ WebKitDOMDocument *document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (data->view));
+ char *title = ephy_web_dom_utils_get_application_title (document);
+ set_default_application_title (data, title);
+#endif
+}
+
static void
notify_launch_cb (NotifyNotification *notification,
char *action,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]