[epiphany] Implement get best web app icon in WebKit2
- From: Xan Lopez <xan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Implement get best web app icon in WebKit2
- Date: Wed, 6 Mar 2013 10:39:13 +0000 (UTC)
commit f296357b33972af85e80de6ec42ff135197e3cb1
Author: Manuel Rego Casasnovas <rego igalia com>
Date: Mon Feb 25 17:11:06 2013 +0100
Implement get best web app icon in WebKit2
https://bugzilla.gnome.org/show_bug.cgi?id=694091
embed/web-extension/ephy-web-extension.c | 86 +++++++++++++++++++----
src/window-commands.c | 110 +++++++++++++++++++++---------
2 files changed, 149 insertions(+), 47 deletions(-)
---
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index 8d82c1a..24e416e 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -1,4 +1,5 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
/*
* Copyright © 2012 Igalia S.L.
*
@@ -19,6 +20,7 @@
#include "config.h"
#include "ephy-web-extension.h"
+
#include "ephy-web-dom-utils.h"
#include <gio/gio.h>
@@ -35,9 +37,29 @@ static const char introspection_xml[] =
" <arg type='t' name='page_id' direction='in'/>"
" <arg type='s' name='title' direction='out'/>"
" </method>"
+ " <method name='GetBestWebAppIcon'>"
+ " <arg type='t' name='page_id' direction='in'/>"
+ " <arg type='s' name='base_uri' direction='in'/>"
+ " <arg type='b' name='result' direction='out'/>"
+ " <arg type='s' name='uri' direction='out'/>"
+ " <arg type='s' name='color' 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,
@@ -49,31 +71,67 @@ handle_method_call (GDBusConnection *connection,
gpointer user_data)
{
WebKitWebExtension *web_extension = WEBKIT_WEB_EXTENSION (user_data);
- WebKitWebPage *web_page;
- guint64 page_id;
if (g_strcmp0 (interface_name, EPHY_WEB_EXTENSION_INTERFACE) != 0)
return;
- g_variant_get(parameters, "(t)", &page_id);
- 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;
- }
-
if (g_strcmp0 (method_name, "HasModifiedForms") == 0) {
- WebKitDOMDocument *document = webkit_web_page_get_dom_document (web_page);
- gboolean has_modifed_forms = ephy_web_dom_utils_has_modified_forms (document);
+ WebKitWebPage *web_page;
+ WebKitDOMDocument *document;
+ guint64 page_id;
+ gboolean has_modifed_forms;
+
+ 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);
+ 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);
+ WebKitWebPage *web_page;
+ WebKitDOMDocument *document;
+ char *title = NULL;
+ guint64 page_id;
+
+ 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);
+ title = ephy_web_dom_utils_get_application_title (document);
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", title ? title : ""));
+ } else if (g_strcmp0 (method_name, "GetBestWebAppIcon") == 0) {
+ WebKitWebPage *web_page;
+ WebKitDOMDocument *document;
+ char *base_uri = NULL;
+ char *uri = NULL;
+ char *color = NULL;
+ guint64 page_id;
+ gboolean result;
+
+ g_variant_get(parameters, "(ts)", &page_id, &base_uri);
+ web_page = get_webkit_web_page_or_return_dbus_error (invocation, web_extension, page_id);
+ if (!web_page)
+ return;
+
+ if (base_uri == NULL || base_uri == '\0') {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
+ "Base URI cannot be NULL or empty");
+ return;
+ }
+
+ document= webkit_web_page_get_dom_document (web_page);
+ result = ephy_web_dom_utils_get_best_icon (document, base_uri, &uri, &color);
+
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(bss)", result, uri ? uri : "", color ? color :
""));
}
+
}
static const GDBusInterfaceVTable interface_vtable = {
diff --git a/src/window-commands.c b/src/window-commands.c
index 3532d5a..87f140e 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1,4 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* vim: set sw=8 ts=8 sts=8 noet: */
/*
* Copyright © 2000-2004 Marco Pesenti Gritti
* Copyright © 2009 Collabora Ltd.
@@ -655,47 +656,27 @@ download_icon_and_set_image (EphyApplicationDialogData *data)
#endif
}
-
static void
-fill_default_application_image (EphyApplicationDialogData *data)
+download_icon_or_take_snapshot (EphyApplicationDialogData *data,
+ gboolean res,
+ char *uri,
+ char *color)
{
- WebKitDOMDocument *document;
- const char *base_uri;
- char *image = NULL;
- char *color = NULL;
- gboolean res;
-
- data->icon_rgba.red = 0.5;
- data->icon_rgba.green = 0.5;
- data->icon_rgba.blue = 0.5;
- data->icon_rgba.alpha = 0.3;
-
- base_uri = webkit_web_view_get_uri (WEBKIT_WEB_VIEW (data->view));
-
-#ifdef HAVE_WEBKIT2
- /* TODO use web extension to get image and color */
- res = FALSE;
-#else
- document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (data->view));
- res = ephy_web_dom_utils_get_best_icon (document,
- base_uri,
- &image,
- &color);
-#endif
+ if (uri != NULL && uri[0] != '\0')
+ data->icon_href = uri;
- if (image != NULL)
+ if (color != NULL && color[0] != '\0')
{
- data->icon_href = g_strdup (image);
+ gdk_rgba_parse (&data->icon_rgba, color);
}
-
- if (color != NULL)
+ else
{
- gdk_rgba_parse (&data->icon_rgba, color);
+ data->icon_rgba.red = 0.5;
+ data->icon_rgba.green = 0.5;
+ data->icon_rgba.blue = 0.5;
+ data->icon_rgba.alpha = 0.3;
}
- g_free (image);
- g_free (color);
-
if (res)
{
download_icon_and_set_image (data);
@@ -707,6 +688,69 @@ fill_default_application_image (EphyApplicationDialogData *data)
}
}
+#ifdef HAVE_WEBKIT2
+static void
+fill_default_application_image_cb (GObject *source,
+ GAsyncResult *async_result,
+ gpointer user_data)
+{
+ EphyApplicationDialogData *data = user_data;
+ GVariant *result;
+ char *uri = NULL;
+ char *color = NULL;
+ gboolean res = FALSE;
+
+ result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source),
+ async_result,
+ NULL);
+
+ if (result)
+ {
+ g_variant_get (result, "(bss)", &res, &uri, &color);
+ g_variant_unref (result);
+ }
+
+ download_icon_or_take_snapshot (data, res, uri, color);
+}
+#endif
+
+static void
+fill_default_application_image (EphyApplicationDialogData *data)
+{
+ const char *base_uri;
+#ifdef HAVE_WEBKIT2
+ GDBusProxy *web_extension;
+#else
+ char *uri = NULL;
+ char *color = NULL;
+ gboolean res;
+#endif
+
+ base_uri = webkit_web_view_get_uri (WEBKIT_WEB_VIEW (data->view));
+
+#ifdef HAVE_WEBKIT2
+ web_extension = ephy_embed_shell_get_web_extension_proxy (ephy_embed_shell_get_default ());
+ if (web_extension)
+ g_dbus_proxy_call (web_extension,
+ "GetBestWebAppIcon",
+ g_variant_new("(ts)", webkit_web_view_get_page_id (WEBKIT_WEB_VIEW
(data->view)), base_uri),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ fill_default_application_image_cb,
+ data);
+ else
+ download_icon_or_take_snapshot (data, FALSE, NULL, NULL);
+#else
+ res = ephy_web_dom_utils_get_best_icon (webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW
(data->view)),
+ base_uri,
+ &uri,
+ &color);
+
+ download_icon_or_take_snapshot (data, res, uri, color);
+#endif
+}
+
typedef struct {
const char *host;
const char *name;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]