[epiphany] Use user a script message instead of a DBus signal for FormAuthDataSaveConfirmationRequired
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Use user a script message instead of a DBus signal for FormAuthDataSaveConfirmationRequired
- Date: Mon, 24 Nov 2014 13:03:39 +0000 (UTC)
commit d6dbc20b01eacccdf419916a13cf0ec18b43951d
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Fri Nov 21 15:44:17 2014 +0100
Use user a script message instead of a DBus signal for FormAuthDataSaveConfirmationRequired
embed/ephy-embed-shell.c | 75 +++++++++++++++++-----------
embed/ephy-web-extension-proxy.c | 47 -----------------
embed/ephy-web-extension-proxy.h | 5 --
embed/ephy-web-view.c | 4 +-
embed/web-extension/ephy-embed-form-auth.c | 6 ++
embed/web-extension/ephy-embed-form-auth.h | 1 +
embed/web-extension/ephy-web-extension.c | 46 +++++++----------
7 files changed, 74 insertions(+), 110 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index e43e509..94dbf96 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -61,7 +61,6 @@ struct _EphyEmbedShellPrivate
GDBusConnection *bus;
GList *web_extensions;
guint web_extensions_page_created_signal_id;
- guint web_extensions_form_auth_save_signal_id;
};
enum
@@ -71,6 +70,7 @@ enum
WEB_VIEW_CREATED,
PAGE_CREATED,
ALLOW_TLS_CERTIFICATE,
+ FORM_AUTH_DATA_SAVE_REQUESTED,
LAST_SIGNAL
};
@@ -132,25 +132,25 @@ ephy_embed_shell_find_web_extension (EphyEmbedShell *shell,
}
static void
-web_extension_form_auth_save_requested (GDBusConnection *connection,
- const char *sender_name,
- const char *object_path,
- const char *interface_name,
- const char *signal_name,
- GVariant *parameters,
- EphyEmbedShell *shell)
+web_extension_form_auth_data_message_received_cb (WebKitUserContentManager *manager,
+ WebKitJavascriptResult *message,
+ EphyEmbedShell *shell)
{
- EphyWebExtensionProxy *web_extension;
guint request_id;
guint64 page_id;
const char *hostname;
const char *username;
+ GVariant *variant;
+ gchar *message_str;
- g_variant_get (parameters, "(ut&s&s)", &request_id, &page_id, &hostname, &username);
- web_extension = ephy_embed_shell_find_web_extension (shell, sender_name);
- if (!web_extension)
- return;
- ephy_web_extension_proxy_form_auth_save_requested (web_extension, request_id, page_id, hostname, username);
+ message_str = ephy_embed_utils_get_js_result_as_string (message);
+ variant = g_variant_parse (G_VARIANT_TYPE ("(utss)"), message_str, NULL, NULL, NULL);
+ g_free (message_str);
+
+ g_variant_get (variant, "(ut&s&s)", &request_id, &page_id, &hostname, &username);
+ g_signal_emit (shell, signals[FORM_AUTH_DATA_SAVE_REQUESTED], 0,
+ request_id, page_id, hostname, username);
+ g_variant_unref (variant);
}
static void
@@ -532,17 +532,6 @@ ephy_embed_shell_setup_web_extensions_connection (EphyEmbedShell *shell)
(GDBusSignalCallback)web_extension_page_created,
shell,
NULL);
- shell->priv->web_extensions_form_auth_save_signal_id =
- g_dbus_connection_signal_subscribe (shell->priv->bus,
- NULL,
- EPHY_WEB_EXTENSION_INTERFACE,
- "FormAuthDataSaveConfirmationRequired",
- EPHY_WEB_EXTENSION_OBJECT_PATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- (GDBusSignalCallback)web_extension_form_auth_save_requested,
- shell,
- NULL);
}
static void
@@ -599,6 +588,12 @@ ephy_embed_shell_startup (GApplication* application)
G_CALLBACK (web_extension_tls_error_page_message_received_cb),
shell);
+ webkit_user_content_manager_register_script_message_handler (shell->priv->user_content,
+ "formAuthData");
+ g_signal_connect (shell->priv->user_content, "script-message-received::formAuthData",
+ G_CALLBACK (web_extension_form_auth_data_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",
@@ -650,17 +645,13 @@ 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");
if (priv->web_extensions_page_created_signal_id > 0) {
g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_page_created_signal_id);
priv->web_extensions_page_created_signal_id = 0;
}
- if (priv->web_extensions_form_auth_save_signal_id > 0) {
- g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_form_auth_save_signal_id);
- priv->web_extensions_form_auth_save_signal_id = 0;
- }
-
g_list_foreach (priv->web_extensions, (GFunc)ephy_embed_shell_unwatch_web_extension, application);
g_object_unref (ephy_embed_prefs_get_settings ());
@@ -824,6 +815,30 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *klass)
G_TYPE_NONE, 1,
G_TYPE_UINT64);
+ /**
+ * EphyEmbedShell::form-auth-data-save-requested:
+ * @shell: the #EphyEmbedShell
+ * @request_id: the identifier of the request
+ * @page_id: the identifier of the web page
+ * @hostname: the hostname
+ * @username: the username
+ *
+ * Emitted when a web page requests confirmation to save
+ * the form authentication data for the given @hostname and
+ * @username
+ */
+ signals[FORM_AUTH_DATA_SAVE_REQUESTED] =
+ g_signal_new ("form-auth-data-save-requested",
+ EPHY_TYPE_EMBED_SHELL,
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 4,
+ G_TYPE_UINT,
+ G_TYPE_UINT64,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+
g_type_class_add_private (object_class, sizeof (EphyEmbedShellPrivate));
}
diff --git a/embed/ephy-web-extension-proxy.c b/embed/ephy-web-extension-proxy.c
index 5787fd7..773e0f9 100644
--- a/embed/ephy-web-extension-proxy.c
+++ b/embed/ephy-web-extension-proxy.c
@@ -30,18 +30,8 @@ struct _EphyWebExtensionProxyPrivate
gchar *name_owner;
GCancellable *cancellable;
guint watch_name_id;
- guint form_auth_save_signal_id;
};
-enum
-{
- FORM_AUTH_DATA_SAVE_REQUESTED,
-
- LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL];
-
G_DEFINE_TYPE (EphyWebExtensionProxy, ephy_web_extension_proxy, G_TYPE_OBJECT)
static void
@@ -85,30 +75,6 @@ ephy_web_extension_proxy_class_init (EphyWebExtensionProxyClass *klass)
object_class->finalize = ephy_web_extension_proxy_finalize;
object_class->dispose = ephy_web_extension_proxy_dispose;
- /**
- * EphyWebExtensionProxy::form-auth-data-save-requested:
- * @web_extension: the #EphyWebExtensionProxy
- * @request_id: the identifier of the request
- * @page_id: the identifier of the web page
- * @hostname: the hostname
- * @username: the username
- *
- * Emitted when a web page requests confirmation to save
- * the form authentication data for the given @hostname and
- * @username
- **/
- signals[FORM_AUTH_DATA_SAVE_REQUESTED] =
- g_signal_new ("form-auth-data-save-requested",
- EPHY_TYPE_WEB_EXTENSION_PROXY,
- G_SIGNAL_RUN_FIRST,
- 0, NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 4,
- G_TYPE_UINT,
- G_TYPE_UINT64,
- G_TYPE_STRING,
- G_TYPE_STRING);
-
g_type_class_add_private (object_class, sizeof (EphyWebExtensionProxyPrivate));
}
@@ -197,19 +163,6 @@ ephy_web_extension_proxy_get_name_owner (EphyWebExtensionProxy *web_extension)
}
void
-ephy_web_extension_proxy_form_auth_save_requested (EphyWebExtensionProxy *web_extension,
- guint request_id,
- guint64 page_id,
- const char *hostname,
- const char *username)
-{
- g_return_if_fail (EPHY_IS_WEB_EXTENSION_PROXY (web_extension));
-
- g_signal_emit (web_extension, signals[FORM_AUTH_DATA_SAVE_REQUESTED], 0,
- request_id, page_id, hostname, username);
-}
-
-void
ephy_web_extension_proxy_form_auth_data_save_confirmation_response (EphyWebExtensionProxy *web_extension,
guint request_id,
gboolean response)
diff --git a/embed/ephy-web-extension-proxy.h b/embed/ephy-web-extension-proxy.h
index 094a544..6ea9d1d 100644
--- a/embed/ephy-web-extension-proxy.h
+++ b/embed/ephy-web-extension-proxy.h
@@ -58,11 +58,6 @@ GType ephy_web_extension_proxy_get_type
EphyWebExtensionProxy *ephy_web_extension_proxy_new (GDBusConnection
*bus,
const char
*service_name);
const char * ephy_web_extension_proxy_get_name_owner
(EphyWebExtensionProxy *web_extension);
-void ephy_web_extension_proxy_form_auth_save_requested
(EphyWebExtensionProxy *web_extension,
- guint
request_id,
- guint64
page_id,
- const char
*hostname,
- const char
*username);
void ephy_web_extension_proxy_form_auth_data_save_confirmation_response
(EphyWebExtensionProxy *web_extension,
guint
request_id,
gboolean
response);
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index db2da11..615b786 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -674,7 +674,7 @@ form_auth_data_save_confirmation_response (GtkInfoBar *info_bar,
}
static void
-form_auth_data_save_requested (EphyWebExtensionProxy *web_extension,
+form_auth_data_save_requested (EphyEmbedShell *shell,
guint request_id,
guint64 page_id,
const char *hostname,
@@ -734,7 +734,7 @@ page_created_cb (EphyEmbedShell *shell,
priv->web_extension = web_extension;
g_object_add_weak_pointer (G_OBJECT (priv->web_extension), (gpointer *)&priv->web_extension);
- g_signal_connect_object (priv->web_extension, "form-auth-data-save-requested",
+ g_signal_connect_object (shell, "form-auth-data-save-requested",
G_CALLBACK (form_auth_data_save_requested),
web_view, 0);
diff --git a/embed/web-extension/ephy-embed-form-auth.c b/embed/web-extension/ephy-embed-form-auth.c
index 669b4aa..1cd232a 100644
--- a/embed/web-extension/ephy-embed-form-auth.c
+++ b/embed/web-extension/ephy-embed-form-auth.c
@@ -110,3 +110,9 @@ ephy_embed_form_auth_get_username (EphyEmbedFormAuth *form_auth)
{
return form_auth->priv->username;
}
+
+WebKitDOMDocument *
+ephy_embed_form_auth_get_owner_document (EphyEmbedFormAuth *form_auth)
+{
+ return webkit_dom_node_get_owner_document (form_auth->priv->password_node);
+}
diff --git a/embed/web-extension/ephy-embed-form-auth.h b/embed/web-extension/ephy-embed-form-auth.h
index 099ded5..9e31248 100644
--- a/embed/web-extension/ephy-embed-form-auth.h
+++ b/embed/web-extension/ephy-embed-form-auth.h
@@ -57,6 +57,7 @@ WebKitDOMNode *ephy_embed_form_auth_get_password_node (EphyEmbedFormAuth *fo
SoupURI *ephy_embed_form_auth_get_uri (EphyEmbedFormAuth *form_auth);
guint64 ephy_embed_form_auth_get_page_id (EphyEmbedFormAuth *form_auth);
const char *ephy_embed_form_auth_get_username (EphyEmbedFormAuth *form_auth);
+WebKitDOMDocument *ephy_embed_form_auth_get_owner_document(EphyEmbedFormAuth *form_auth);
G_END_DECLS
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index a199c8f..d932a45 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -76,12 +76,6 @@ static const char introspection_xml[] =
" <arg type='s' name='uri' direction='out'/>"
" <arg type='s' name='color' direction='out'/>"
" </method>"
- " <signal name='FormAuthDataSaveConfirmationRequired'>"
- " <arg type='u' name='request_id' direction='out'/>"
- " <arg type='t' name='page_id' direction='out'/>"
- " <arg type='s' name='hostname' direction='out'/>"
- " <arg type='s' name='username' direction='out'/>"
- " </signal>"
" <method name='FormAuthDataSaveConfirmationResponse'>"
" <arg type='u' name='request_id' direction='in'/>"
" <arg type='b' name='should_store' direction='in'/>"
@@ -235,11 +229,13 @@ request_decision_on_storing (EphyEmbedFormAuth *form_auth)
char *username_field_value = NULL;
guint request_id;
SoupURI *uri;
- GError *error = NULL;
WebKitDOMNode *username_node;
- EphyWebExtension *extension = ephy_web_extension_get ();
+ WebKitDOMDOMWindow *dom_window;
+ GVariant *variant;
+ gchar *message;
- if (!extension->priv->dbus_connection) {
+ dom_window = webkit_dom_document_get_default_view (ephy_embed_form_auth_get_owner_document (form_auth));
+ if (!dom_window) {
g_object_unref (form_auth);
return;
}
@@ -250,27 +246,25 @@ request_decision_on_storing (EphyEmbedFormAuth *form_auth)
if (username_node)
g_object_get (username_node, "value", &username_field_value, NULL);
- g_dbus_connection_emit_signal (extension->priv->dbus_connection,
- NULL,
- EPHY_WEB_EXTENSION_OBJECT_PATH,
- EPHY_WEB_EXTENSION_INTERFACE,
- "FormAuthDataSaveConfirmationRequired",
- g_variant_new ("(utss)",
- request_id,
- ephy_embed_form_auth_get_page_id (form_auth),
- uri ? uri->host : "",
- username_field_value ? username_field_value : ""),
- &error);
- if (error) {
- g_warning ("Error emitting signal FormAuthDataSaveConfirmationRequired: %s\n", error->message);
- g_error_free (error);
- } else {
- g_hash_table_insert (ephy_web_extension_get_form_auth_data_save_requests (extension),
+ variant = g_variant_new ("(utss)",
+ request_id,
+ ephy_embed_form_auth_get_page_id (form_auth),
+ uri ? uri->host : "",
+ username_field_value ? username_field_value : "");
+ g_free (username_field_value);
+
+ message = g_variant_print (variant, FALSE);
+ g_variant_unref (variant);
+
+ if (webkit_dom_dom_window_webkit_message_handlers_post_message (dom_window, "formAuthData", message)) {
+ g_hash_table_insert (ephy_web_extension_get_form_auth_data_save_requests (ephy_web_extension_get ()),
GINT_TO_POINTER (request_id),
g_object_ref (form_auth));
+ } else {
+ g_warning ("Error sending formAuthData message");
}
- g_free (username_field_value);
+ g_free (message);
g_object_unref (form_auth);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]