[epiphany] Use user a script message instead of a DBus signal for AllowTLSCertificate
- 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 AllowTLSCertificate
- Date: Mon, 24 Nov 2014 13:03:34 +0000 (UTC)
commit 701b6a959b4aaeff49941e88101f82159a76655f
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 AllowTLSCertificate
embed/ephy-embed-shell.c | 61 ++++++++--------
embed/ephy-embed-utils.c | 11 +++
embed/ephy-embed-utils.h | 1 +
embed/ephy-web-extension-proxy.c | 26 -------
embed/ephy-web-extension-proxy.h | 2 -
embed/ephy-web-view.c | 7 +-
embed/web-extension/ephy-web-extension.c | 117 ------------------------------
7 files changed, 46 insertions(+), 179 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index a047d42..e43e509 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -62,7 +62,6 @@ struct _EphyEmbedShellPrivate
GList *web_extensions;
guint web_extensions_page_created_signal_id;
guint web_extensions_form_auth_save_signal_id;
- guint web_extensions_allow_tls_certificate_signal_id;
};
enum
@@ -71,6 +70,7 @@ enum
RESTORED_WINDOW,
WEB_VIEW_CREATED,
PAGE_CREATED,
+ ALLOW_TLS_CERTIFICATE,
LAST_SIGNAL
};
@@ -269,23 +269,14 @@ web_extension_overview_message_received_cb (WebKitUserContentManager *manager,
}
static void
-web_extension_allow_tls_certificate (GDBusConnection *connection,
- const char *sender_name,
- const char *object_path,
- const char *interface_name,
- const char *signal_name,
- GVariant *parameters,
- EphyEmbedShell *shell)
+web_extension_tls_error_page_message_received_cb (WebKitUserContentManager *manager,
+ WebKitJavascriptResult *message,
+ EphyEmbedShell *shell)
{
- EphyWebExtensionProxy *web_extension;
guint64 page_id;
- web_extension = ephy_embed_shell_find_web_extension (shell, sender_name);
- if (!web_extension)
- return;
-
- g_variant_get (parameters, "(t)", &page_id);
- ephy_web_extension_proxy_allow_tls_certificate (web_extension, page_id);
+ page_id = ephy_embed_utils_get_js_result_as_number (message);
+ g_signal_emit (shell, signals[ALLOW_TLS_CERTIFICATE], 0, page_id);
}
static void
@@ -552,17 +543,6 @@ ephy_embed_shell_setup_web_extensions_connection (EphyEmbedShell *shell)
(GDBusSignalCallback)web_extension_form_auth_save_requested,
shell,
NULL);
- shell->priv->web_extensions_allow_tls_certificate_signal_id =
- g_dbus_connection_signal_subscribe (shell->priv->bus,
- NULL,
- EPHY_WEB_EXTENSION_INTERFACE,
- "AllowTLSCertificate",
- EPHY_WEB_EXTENSION_OBJECT_PATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- (GDBusSignalCallback)web_extension_allow_tls_certificate,
- shell,
- NULL);
}
static void
@@ -613,6 +593,12 @@ ephy_embed_shell_startup (GApplication* application)
G_CALLBACK (web_extension_overview_message_received_cb),
shell);
+ webkit_user_content_manager_register_script_message_handler (shell->priv->user_content,
+ "tlsErrorPage");
+ g_signal_connect (shell->priv->user_content, "script-message-received::tlsErrorPage",
+ G_CALLBACK (web_extension_tls_error_page_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",
@@ -663,6 +649,7 @@ ephy_embed_shell_shutdown (GApplication* application)
G_APPLICATION_CLASS (ephy_embed_shell_parent_class)->shutdown (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");
if (priv->web_extensions_page_created_signal_id > 0) {
g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_page_created_signal_id);
@@ -674,11 +661,6 @@ ephy_embed_shell_shutdown (GApplication* application)
priv->web_extensions_form_auth_save_signal_id = 0;
}
- if (priv->web_extensions_allow_tls_certificate_signal_id > 0) {
- g_dbus_connection_signal_unsubscribe (priv->bus, priv->web_extensions_allow_tls_certificate_signal_id);
- priv->web_extensions_allow_tls_certificate_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 ());
@@ -825,6 +807,23 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *klass)
G_TYPE_UINT64,
EPHY_TYPE_WEB_EXTENSION_PROXY);
+ /**
+ * EphyEmbedShell::allow-tls-certificate:
+ * @shell: the #EphyEmbedShell
+ * @page_id: the identifier of the web page
+ *
+ * Emitted when the web extension requests an exception be
+ * permitted for the invalid TLS certificate on the given page
+ */
+ signals[ALLOW_TLS_CERTIFICATE] =
+ g_signal_new ("allow-tls-certificate",
+ EPHY_TYPE_EMBED_SHELL,
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 1,
+ G_TYPE_UINT64);
+
g_type_class_add_private (object_class, sizeof (EphyEmbedShellPrivate));
}
diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c
index 8672ea5..a43cee9 100644
--- a/embed/ephy-embed-utils.c
+++ b/embed/ephy-embed-utils.c
@@ -346,6 +346,17 @@ ephy_embed_utils_get_js_result_as_string (WebKitJavascriptResult *js_result)
return retval;
}
+double
+ephy_embed_utils_get_js_result_as_number (WebKitJavascriptResult *js_result)
+{
+ JSValueRef js_value;
+
+ js_value = webkit_javascript_result_get_value (js_result);
+
+ return JSValueToNumber (webkit_javascript_result_get_global_context (js_result),
+ js_value, NULL);
+}
+
void
ephy_embed_utils_shutdown (void)
{
diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h
index ae8b02b..a857dd7 100644
--- a/embed/ephy-embed-utils.h
+++ b/embed/ephy-embed-utils.h
@@ -50,6 +50,7 @@ char *ephy_embed_utils_get_title_from_address (const char *add
gboolean ephy_embed_utils_urls_have_same_origin (const char *a_url,
const char *b_url);
char *ephy_embed_utils_get_js_result_as_string (WebKitJavascriptResult *js_result);
+double ephy_embed_utils_get_js_result_as_number (WebKitJavascriptResult *js_result);
void ephy_embed_utils_shutdown (void);
G_END_DECLS
diff --git a/embed/ephy-web-extension-proxy.c b/embed/ephy-web-extension-proxy.c
index 7254be0..5787fd7 100644
--- a/embed/ephy-web-extension-proxy.c
+++ b/embed/ephy-web-extension-proxy.c
@@ -36,7 +36,6 @@ struct _EphyWebExtensionProxyPrivate
enum
{
FORM_AUTH_DATA_SAVE_REQUESTED,
- ALLOW_TLS_CERTIFICATE,
LAST_SIGNAL
};
@@ -110,22 +109,6 @@ ephy_web_extension_proxy_class_init (EphyWebExtensionProxyClass *klass)
G_TYPE_STRING,
G_TYPE_STRING);
- /**
- * EphyWebExtensionProxy::allow-tls-certificate:
- * @shell: the #EphyWebExtensionProxy
- *
- * Emitted when the web extension requests an exception be
- * permitted for the invalid TLS certificate on the current page.
- */
- signals[ALLOW_TLS_CERTIFICATE] =
- g_signal_new ("allow-tls-certificate",
- EPHY_TYPE_WEB_EXTENSION_PROXY,
- G_SIGNAL_RUN_FIRST,
- 0, NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 1,
- G_TYPE_UINT64);
-
g_type_class_add_private (object_class, sizeof (EphyWebExtensionProxyPrivate));
}
@@ -245,15 +228,6 @@ ephy_web_extension_proxy_form_auth_data_save_confirmation_response (EphyWebExten
NULL, NULL);
}
-void
-ephy_web_extension_proxy_allow_tls_certificate (EphyWebExtensionProxy *web_extension,
- guint64 page_id)
-{
- g_return_if_fail (EPHY_IS_WEB_EXTENSION_PROXY (web_extension));
-
- g_signal_emit (web_extension, signals[ALLOW_TLS_CERTIFICATE], 0, page_id);
-}
-
static void
has_modified_forms_cb (GDBusProxy *proxy,
GAsyncResult *result,
diff --git a/embed/ephy-web-extension-proxy.h b/embed/ephy-web-extension-proxy.h
index 99afcfb..094a544 100644
--- a/embed/ephy-web-extension-proxy.h
+++ b/embed/ephy-web-extension-proxy.h
@@ -66,8 +66,6 @@ void ephy_web_extension_proxy_form_auth_save_requested
void ephy_web_extension_proxy_form_auth_data_save_confirmation_response
(EphyWebExtensionProxy *web_extension,
guint
request_id,
gboolean
response);
-void ephy_web_extension_proxy_allow_tls_certificate
(EphyWebExtensionProxy *web_extension,
- guint64
page_id);
void ephy_web_extension_proxy_web_page_has_modified_forms
(EphyWebExtensionProxy *web_extension,
guint64
page_id,
GCancellable
*cancellable,
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index aed3c1a..db2da11 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -699,7 +699,7 @@ form_auth_data_save_requested (EphyWebExtensionProxy *web_extension,
}
static void
-allow_tls_certificate_cb (EphyWebExtensionProxy *shell,
+allow_tls_certificate_cb (EphyEmbedShell *shell,
guint64 page_id,
EphyWebView *web_view)
{
@@ -738,7 +738,7 @@ page_created_cb (EphyEmbedShell *shell,
G_CALLBACK (form_auth_data_save_requested),
web_view, 0);
- g_signal_connect_object (priv->web_extension, "allow-tls-certificate",
+ g_signal_connect_object (shell, "allow-tls-certificate",
G_CALLBACK (allow_tls_certificate_cb),
web_view, 0);
}
@@ -1908,7 +1908,8 @@ ephy_web_view_load_error_page (EphyWebView *view,
/* Button on error page when a website's TLS certificate is invalid. */
button_label = g_strdup (_("Load Anyway"));
custom_class = "tls-error";
- load_anyway_js = g_strdup ("EpiphanyTLSCertificateErrorPage.allowException();");
+ load_anyway_js = g_strdup_printf
("window.webkit.messageHandlers.tlsErrorPage.postMessage(%"G_GUINT64_FORMAT");",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)));
break;
default:
return;
diff --git a/embed/web-extension/ephy-web-extension.c b/embed/web-extension/ephy-web-extension.c
index 057faad..a199c8f 100644
--- a/embed/web-extension/ephy-web-extension.c
+++ b/embed/web-extension/ephy-web-extension.c
@@ -104,9 +104,6 @@ static const char introspection_xml[] =
" <arg type='s' name='host' direction='in'/>"
" </method>"
" <method name='HistoryClear'/>"
- " <signal name='AllowTLSCertificate'>"
- " <arg type='t' name='page_id' direction='out'/>"
- " </signal>"
" </interface>"
"</node>";
@@ -1222,115 +1219,6 @@ static const GDBusInterfaceVTable interface_vtable = {
NULL
};
-typedef struct {
- EphyWebExtension *extension;
- guint64 page_id;
-} AllowTLSCertificateData;
-
-static JSValueRef
-allow_tls_certificate_cb (JSContextRef context,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argument_count,
- const JSValueRef arguments[],
- JSValueRef *exception)
-{
- AllowTLSCertificateData *data;
- EphyWebExtension *extension;
- GError *error = NULL;
-
- data = (AllowTLSCertificateData *)JSObjectGetPrivate (this_object);
- extension = data->extension;
-
- if (!extension->priv->dbus_connection)
- return JSValueMakeUndefined (context);
-
- g_dbus_connection_emit_signal (extension->priv->dbus_connection,
- NULL,
- EPHY_WEB_EXTENSION_OBJECT_PATH,
- EPHY_WEB_EXTENSION_INTERFACE,
- "AllowTLSCertificate",
- g_variant_new ("(t)", data->page_id),
- &error);
-
- if (error) {
- g_warning ("Error emitting signal AllowTLSCertificate: %s\n", error->message);
- g_error_free (error);
- }
-
- return JSValueMakeUndefined (context);
-}
-
-static const JSStaticFunction tls_certificate_error_page_static_funcs[] =
-{
- { "allowException", allow_tls_certificate_cb, kJSPropertyAttributeReadOnly |
kJSPropertyAttributeDontDelete },
- { NULL, NULL, 0 }
-};
-
-static void
-tls_certificate_error_page_finalize (JSObjectRef object)
-{
- g_slice_free (AllowTLSCertificateData, JSObjectGetPrivate (object));
-}
-
-static void
-prepare_certificate_exception_js (WebKitScriptWorld *world,
- WebKitWebPage *web_page,
- WebKitFrame *frame,
- EphyWebExtension *extension)
-{
- JSGlobalContextRef context;
- JSObjectRef global_object;
- JSClassDefinition class_def;
- JSClassRef class;
- JSObjectRef class_object;
- JSStringRef str;
- AllowTLSCertificateData *data;
-
- context = webkit_frame_get_javascript_context_for_script_world (frame, world);
- global_object = JSContextGetGlobalObject (context);
-
- class_def = kJSClassDefinitionEmpty;
- class_def.className = "EpiphanyTLSCertificateErrorPage";
- class_def.staticFunctions = tls_certificate_error_page_static_funcs;
- class_def.finalize = tls_certificate_error_page_finalize;
-
- data = g_slice_alloc (sizeof (AllowTLSCertificateData));
- data->extension = extension;
- data->page_id = webkit_web_page_get_id (web_page);
-
- class = JSClassCreate (&class_def);
- class_object = JSObjectMake (context, class, data);
- str = JSStringCreateWithUTF8CString ("EpiphanyTLSCertificateErrorPage");
- JSObjectSetProperty (context, global_object, str, class_object, kJSPropertyAttributeNone, NULL);
-
- JSClassRelease (class);
- JSStringRelease (str);
-}
-
-static void
-window_object_cleared_cb (WebKitScriptWorld *world,
- WebKitWebPage *web_page,
- WebKitFrame *frame,
- EphyWebExtension *extension)
-{
- WebKitDOMDocument *dom_document;
- char *dom_url;
-
- dom_document = webkit_web_page_get_dom_document (web_page);
- dom_url = webkit_dom_document_get_url (dom_document);
-
- /* If webkit_web_page_get_uri is not about:blank and webkit_dom_document_get_url is
- * about:blank, we are likely loading alternate content, so it's safe to make the
- * certificate exception js available. This is needed by the TLS error page. */
- if (g_strcmp0 (webkit_web_page_get_uri (web_page), "about:blank") != 0 &&
- g_strcmp0 (dom_url, "about:blank") == 0) {
- prepare_certificate_exception_js (world, web_page, frame, extension);
- }
-
- g_free (dom_url);
-}
-
static void
ephy_web_extension_dispose (GObject *object)
{
@@ -1378,11 +1266,6 @@ ephy_web_extension_init (EphyWebExtension *extension)
{
extension->priv = G_TYPE_INSTANCE_GET_PRIVATE (extension, EPHY_TYPE_WEB_EXTENSION,
EphyWebExtensionPrivate);
extension->priv->overview_model = ephy_web_overview_model_new ();
-
- g_signal_connect (webkit_script_world_get_default (),
- "window-object-cleared",
- G_CALLBACK (window_object_cleared_cb),
- extension);
}
static gpointer
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]