[epiphany] about-apps: Use user script message instead of forms to delete web apps



commit 865735b61b0f29285f8769423d6c25dbcdfa50ca
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Mon Nov 24 15:04:29 2014 +0100

    about-apps: Use user script message instead of forms to delete web apps

 embed/ephy-about-handler.c |   20 +++++++++++++-------
 embed/ephy-embed-shell.c   |   20 ++++++++++++++++++++
 src/ephy-window.c          |   32 --------------------------------
 3 files changed, 33 insertions(+), 39 deletions(-)
---
diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c
index b5df6fb..c14f816 100644
--- a/embed/ephy-about-handler.c
+++ b/embed/ephy-about-handler.c
@@ -338,6 +338,13 @@ handle_applications_finished_cb (EphyAboutHandler *handler,
   g_string_append_printf (data_str, "<html><head><title>%s</title>"
                           "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
                           "<link href=\""EPHY_PAGE_TEMPLATE_ABOUT_CSS"\" rel=\"stylesheet\" 
type=\"text/css\">"
+                          "<script>"
+                          "  function deleteWebApp(appID) {"
+                          "    window.webkit.messageHandlers.aboutApps.postMessage(appID);"
+                          "    var row = document.getElementById(appID);"
+                          "    row.parentNode.removeChild(row);"
+                          "  }"
+                          "</script>"
                           "</head><body class=\"applications-body\"><h1>%s</h1>"
                           "<p>%s</p>",
                           _("Applications"),
@@ -351,13 +358,12 @@ handle_applications_finished_cb (EphyAboutHandler *handler,
     EphyWebApplication *app = (EphyWebApplication*)p->data;
 
     g_string_append_printf (data_str,
-                            "<form>" \
-                            "<tbody><tr>" \
-                            "<td class=\"icon\"><img width=64 height=64 src=\"file://%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>",
-                            app->icon_url, app->name, app->url, app->name, app->name,
+                            "<tbody><tr id =\"%s\">"
+                            "<td class=\"icon\"><img width=64 height=64 src=\"file://%s\"></img></td>"
+                            "<td class=\"data\"><div class=\"appname\">%s</div><div 
class=\"appurl\">%s</div></td>"
+                            "<td class=\"input\"><input type=\"button\" value=\"Delete\" 
onclick=\"deleteWebApp('%s');\"></td>"
+                            "<td class=\"date\">%s <br /> %s</td></tr></tbody>",
+                            app->name, app->icon_url, app->url, app->name, app->name,
                             /* Note for translators: this refers to the installation date. */
                             _("Installed on:"), app->install_date);
   }
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 94dbf96..c726b23 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -34,6 +34,7 @@
 #include "ephy-profile-utils.h"
 #include "ephy-settings.h"
 #include "ephy-snapshot-service.h"
+#include "ephy-web-app-utils.h"
 #include "ephy-web-extension-proxy.h"
 #include "ephy-web-extension-names.h"
 
@@ -280,6 +281,18 @@ web_extension_tls_error_page_message_received_cb (WebKitUserContentManager *mana
 }
 
 static void
+web_extension_about_apps_message_received_cb (WebKitUserContentManager *manager,
+                                              WebKitJavascriptResult *message,
+                                              EphyEmbedShell *shell)
+{
+  char *app_id;
+
+  app_id = ephy_embed_utils_get_js_result_as_string (message);
+  ephy_web_application_delete (app_id);
+  g_free (app_id);
+}
+
+static void
 web_extension_destroyed (EphyEmbedShell *shell,
                          GObject *web_extension)
 {
@@ -594,6 +607,12 @@ ephy_embed_shell_startup (GApplication* application)
                     G_CALLBACK (web_extension_form_auth_data_message_received_cb),
                     shell);
 
+  webkit_user_content_manager_register_script_message_handler (shell->priv->user_content,
+                                                               "aboutApps");
+  g_signal_connect (shell->priv->user_content, "script-message-received::aboutApps",
+                    G_CALLBACK (web_extension_about_apps_message_received_cb),
+                    shell);
+
   web_context = webkit_web_context_get_default ();
   ephy_embed_shell_setup_process_model (shell, web_context);
   g_signal_connect (web_context, "initialize-web-extensions",
@@ -646,6 +665,7 @@ ephy_embed_shell_shutdown (GApplication* application)
   webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "overview");
   webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "tlsErrorPage");
   webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "formAuthData");
+  webkit_user_content_manager_unregister_script_message_handler (priv->user_content, "aboutApps");
 
   if (priv->web_extensions_page_created_signal_id > 0) {
     g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_page_created_signal_id);
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 4500469..8a197af 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -52,7 +52,6 @@
 #include "ephy-title-box.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"
@@ -2108,28 +2107,6 @@ 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);
-}
-
 static gboolean
 decide_policy_cb (WebKitWebView *web_view,
                  WebKitPolicyDecision *decision,
@@ -2292,15 +2269,6 @@ decide_policy_cb (WebKitWebView *web_view,
                return TRUE;
        }
 
-       if (navigation_type == WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED && uri &&
-           g_str_has_prefix (uri, "ephy-about:applications"))
-       {
-               delete_web_app (uri);
-               webkit_policy_decision_use (decision);
-
-               return TRUE;
-       }
-
        return FALSE;
 }
 


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