aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-09-22 00:42:12 +0800
committerCarlos Garcia Campos <cgarcia@igalia.com>2013-01-11 16:54:05 +0800
commitf256d7fc2dac4f1a3abbcc594be51f62b6f13496 (patch)
tree9fe4f720f9cff3b1adf72b2b42fbfb9dc7afdf9b
parent148238b49a703b0b3c971a3ae7d430d44a20693a (diff)
downloadgsoc2013-epiphany-f256d7fc2dac4f1a3abbcc594be51f62b6f13496.tar
gsoc2013-epiphany-f256d7fc2dac4f1a3abbcc594be51f62b6f13496.tar.gz
gsoc2013-epiphany-f256d7fc2dac4f1a3abbcc594be51f62b6f13496.tar.bz2
gsoc2013-epiphany-f256d7fc2dac4f1a3abbcc594be51f62b6f13496.tar.lz
gsoc2013-epiphany-f256d7fc2dac4f1a3abbcc594be51f62b6f13496.tar.xz
gsoc2013-epiphany-f256d7fc2dac4f1a3abbcc594be51f62b6f13496.tar.zst
gsoc2013-epiphany-f256d7fc2dac4f1a3abbcc594be51f62b6f13496.zip
Don't use DOM bindings to delete a web application from about:applications
Use a different form for every web application with a hidden value containing the application id. Then use the policy client to ignore any form submission from about:applications and delete the application instead, reloading the about:applications page. This solution will work for WebKit2 too.
-rw-r--r--embed/ephy-about-handler.c15
-rw-r--r--embed/ephy-web-view.c89
-rw-r--r--src/ephy-window.c32
3 files changed, 44 insertions, 92 deletions
diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c
index 9f4caf665..e9328a118 100644
--- a/embed/ephy-about-handler.c
+++ b/embed/ephy-about-handler.c
@@ -210,7 +210,7 @@ ephy_about_handler_handle_applications (GString *data_str)
_("Applications"),
_("List of installed web applications"));
- g_string_append (data_str, "<form><table>");
+ g_string_append (data_str, "<table>");
applications = ephy_web_application_get_application_list ();
for (p = applications; p; p = p->next) {
@@ -220,16 +220,21 @@ ephy_about_handler_handle_applications (GString *data_str)
if (g_file_get_contents (app->icon_url, &img_data, &data_length, NULL))
img_data_base64 = g_base64_encode ((guchar*)img_data, data_length);
- g_string_append_printf (data_str, "<tbody><tr><td class=\"icon\"><img width=64 height=64 src=\"data:image/png;base64,%s\">" \
- " </img></td><td class=\"data\"><div class=\"appname\">%s</div><div class=\"appurl\">%s</div></td><td class=\"input\"><input type=\"submit\" value=\"Delete\" id=\"%s\"></td><td class=\"date\">%s <br /> %s</td></tr>",
- img_data_base64, app->name, app->url, app->name,
+ g_string_append_printf (data_str,
+ "<form>" \
+ "<tbody><tr>" \
+ "<td class=\"icon\"><img width=64 height=64 src=\"data:image/png;base64,%s\"></img></td>" \
+ "<td class=\"data\"><div class=\"appname\">%s</div><div class=\"appurl\">%s</div></td>" \
+ "<td class=\"input\"><input type=\"hidden\" name=\"app_id\" value=\"%s\"><input type=\"submit\" value=\"Delete\" id=\"%s\">" \
+ "</td><td class=\"date\">%s <br /> %s</td></tr></tbody></form>",
+ img_data_base64, app->name, app->url, app->name, app->name,
/* Note for translators: this refers to the installation date. */
_("Installed on:"), app->install_date);
g_free (img_data_base64);
g_free (img_data);
}
- g_string_append (data_str, "</form></table></body>");
+ g_string_append (data_str, "</table></body>");
ephy_web_application_free_application_list (applications);
}
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 9b096ae09..c70d9d497 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2013,26 +2013,6 @@ geolocation_policy_decision_requested_cb (WebKitWebView *web_view,
return TRUE;
}
-#ifdef HAVE_WEBKIT2
-/* TODO: DOM Bindings */
-#else
-static gboolean
-delete_web_app_cb (WebKitDOMHTMLElement *button,
- WebKitDOMEvent *dom_event,
- EphyWebView *web_view)
-{
- char *id = NULL;
-
- id = webkit_dom_html_element_get_id (button);
- if (id)
- ephy_web_application_delete (id);
-
- g_free (id);
-
- return FALSE;
-}
-#endif
-
static void
get_host_for_url_cb (gpointer service,
gboolean success,
@@ -2220,9 +2200,7 @@ load_changed_cb (WebKitWebView *web_view,
break;
}
- case WEBKIT_LOAD_FINISHED: {
- SoupURI *uri;
-
+ case WEBKIT_LOAD_FINISHED:
g_free (priv->status_message);
priv->status_message = NULL;
g_object_notify (object, "status-message");
@@ -2241,37 +2219,6 @@ load_changed_cb (WebKitWebView *web_view,
_ephy_web_view_hook_into_links (view);
#endif
- /* FIXME: It sucks to do this here, but it's not really possible
- * to hook the DOM actions nicely in the about: generator. */
- uri = soup_uri_new (webkit_web_view_get_uri (web_view));
- if (uri &&
- !g_strcmp0 (uri->scheme, "ephy-about") &&
- !g_strcmp0 (uri->path, "applications")) {
-#if 0
- /* TODO: DOM bindings */
- WebKitDOMDocument *document;
- WebKitDOMNodeList *buttons;
- gulong buttons_n;
- int i;
-
- document = webkit_web_view_get_dom_document (web_view);
- buttons = webkit_dom_document_get_elements_by_tag_name (document, "input");
- buttons_n = webkit_dom_node_list_get_length (buttons);
-
- for (i = 0; i < buttons_n; i++) {
- WebKitDOMNode *button;
-
- button = webkit_dom_node_list_item (buttons, i);
- webkit_dom_event_target_add_event_listener (WEBKIT_DOM_EVENT_TARGET (button), "click",
- G_CALLBACK (delete_web_app_cb), false,
- NULL);
- }
-#endif
- }
-
- if (uri)
- soup_uri_free (uri);
-
/* Ensure we load the icon for this web view, if available. */
_ephy_web_view_update_icon (view);
@@ -2280,7 +2227,6 @@ load_changed_cb (WebKitWebView *web_view,
break;
}
- }
g_object_thaw_notify (object);
}
@@ -2378,9 +2324,7 @@ load_status_cb (WebKitWebView *web_view,
break;
}
- case WEBKIT_LOAD_FINISHED: {
- SoupURI *uri;
-
+ case WEBKIT_LOAD_FINISHED:
g_free (priv->status_message);
priv->status_message = NULL;
g_object_notify (object, "status-message");
@@ -2396,34 +2340,6 @@ load_status_cb (WebKitWebView *web_view,
_ephy_web_view_hook_into_links (view);
- /* FIXME: It sucks to do this here, but it's not really possible
- * to hook the DOM actions nicely in the about: generator. */
- uri = soup_uri_new (webkit_web_view_get_uri (web_view));
- if (uri &&
- !g_strcmp0 (uri->scheme, "ephy-about") &&
- !g_strcmp0 (uri->path, "applications")) {
- WebKitDOMDocument *document;
- WebKitDOMNodeList *buttons;
- gulong buttons_n;
- int i;
-
- document = webkit_web_view_get_dom_document (web_view);
- buttons = webkit_dom_document_get_elements_by_tag_name (document, "input");
- buttons_n = webkit_dom_node_list_get_length (buttons);
-
- for (i = 0; i < buttons_n; i++) {
- WebKitDOMNode *button;
-
- button = webkit_dom_node_list_item (buttons, i);
- webkit_dom_event_target_add_event_listener (WEBKIT_DOM_EVENT_TARGET (button), "click",
- G_CALLBACK (delete_web_app_cb), false,
- NULL);
- }
- }
-
- if (uri)
- soup_uri_free (uri);
-
/* Reset visit type. */
priv->visit_type = EPHY_PAGE_VISIT_NONE;
@@ -2435,7 +2351,6 @@ load_status_cb (WebKitWebView *web_view,
ephy_web_view_thaw_history (view);
break;
- }
case WEBKIT_LOAD_FAILED:
priv->load_failed = TRUE;
ephy_web_view_set_link_message (view, NULL);
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 3fcd3eed0..5b309a09c 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -54,6 +54,7 @@
#include "ephy-shell.h"
#include "ephy-toolbar.h"
#include "ephy-type-builtins.h"
+#include "ephy-web-app-utils.h"
#include "ephy-web-view.h"
#include "ephy-zoom-action.h"
#include "ephy-zoom.h"
@@ -2466,6 +2467,28 @@ create_web_view_cb (WebKitWebView *web_view,
return new_web_view;
}
+static void
+delete_web_app (const char *request_uri)
+{
+ SoupURI *uri = soup_uri_new (request_uri);
+
+ if (uri->query)
+ {
+ GHashTable *form;
+ const char *app_id;
+
+ form = soup_form_decode (uri->query);
+ app_id = g_hash_table_lookup (form, "app_id");
+ if (app_id)
+ {
+ ephy_web_application_delete (app_id);
+ }
+ g_hash_table_destroy (form);
+ }
+
+ soup_uri_free (uri);
+}
+
#ifdef HAVE_WEBKIT2
static gboolean
decide_policy_cb (WebKitWebView *web_view,
@@ -2737,6 +2760,15 @@ policy_decision_required_cb (WebKitWebView *web_view,
return TRUE;
}
+ if (reason == WEBKIT_WEB_NAVIGATION_REASON_FORM_SUBMITTED && uri &&
+ g_str_has_prefix (uri, "ephy-about:applications"))
+ {
+ delete_web_app (uri);
+ webkit_web_policy_decision_use (decision);
+
+ return TRUE;
+ }
+
return FALSE;
}
#endif