[epiphany/gnome-3-36] Fix reload buttons on error pages
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/gnome-3-36] Fix reload buttons on error pages
- Date: Tue, 21 Dec 2021 00:34:10 +0000 (UTC)
commit 4bb41cded4792b0ebc194b4930bf09acb7fc0e4f
Author: Michael Catanzaro <mcatanzaro redhat com>
Date: Mon Dec 20 10:32:36 2021 -0600
Fix reload buttons on error pages
The encoded URL here does not work. And we cannot reload via the web
process, because the window.location is about:blank for alternate HTML,
so we'll have to send a message to the UI process to have it do so
instead.
Fixes #1663
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1050>
embed/ephy-embed-shell.c | 36 ++++++++++++++++
embed/ephy-web-view.c | 108 +++++++++++++++++++++++++++--------------------
2 files changed, 99 insertions(+), 45 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 51a90038d..0625d76ee 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -74,6 +74,7 @@ enum {
WEB_VIEW_CREATED,
ALLOW_TLS_CERTIFICATE,
ALLOW_UNSAFE_BROWSING,
+ RELOAD_PAGE,
PASSWORD_FORM_FOCUSED,
LAST_SIGNAL
@@ -302,6 +303,17 @@ web_process_extension_tls_error_page_message_received_cb (WebKitUserContentManag
g_signal_emit (shell, signals[ALLOW_TLS_CERTIFICATE], 0, page_id);
}
+static void
+web_process_extension_reload_page_message_received_cb (WebKitUserContentManager *manager,
+ WebKitJavascriptResult *message,
+ EphyEmbedShell *shell)
+{
+ guint64 page_id;
+
+ page_id = jsc_value_to_double (webkit_javascript_result_get_js_value (message));
+ g_signal_emit (shell, signals[RELOAD_PAGE], 0, page_id);
+}
+
static void
web_process_extension_unsafe_browsing_error_page_message_received_cb (WebKitUserContentManager *manager,
WebKitJavascriptResult *message,
@@ -1082,6 +1094,23 @@ ephy_embed_shell_class_init (EphyEmbedShellClass *klass)
G_TYPE_NONE, 1,
G_TYPE_UINT64);
+ /**
+ * EphyEmbedShell::reload-page:
+ * @shell: the #EphyEmbedShell
+ * @page_id: the identifier of the web page
+ *
+ * Emitted when the web process extension requests a view be reloaded.
+ * This is needed when window.location.reload() doesn't work properly,
+ * specifically after loading alternate HTML.
+ */
+ signals[RELOAD_PAGE] =
+ g_signal_new ("reload-page",
+ EPHY_TYPE_EMBED_SHELL,
+ G_SIGNAL_RUN_FIRST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 1,
+ G_TYPE_UINT64);
+
/**
* EphyEmbedShell::password-form-focused
* @shell: the #EphyEmbedShell
@@ -1320,6 +1349,7 @@ ephy_embed_shell_register_ucm_handler (EphyEmbedShell *shell,
EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
/* User content manager */
+ /* FIXME: See https://gitlab.gnome.org/GNOME/epiphany/-/issues/1664 */
webkit_user_content_manager_register_script_message_handler_in_world (ucm,
"overview",
priv->guid);
@@ -1333,6 +1363,12 @@ ephy_embed_shell_register_ucm_handler (EphyEmbedShell *shell,
G_CALLBACK (web_process_extension_tls_error_page_message_received_cb),
shell, 0);
+ webkit_user_content_manager_register_script_message_handler (ucm,
+ "reloadPage");
+ g_signal_connect_object (ucm, "script-message-received::reloadPage",
+ G_CALLBACK (web_process_extension_reload_page_message_received_cb),
+ shell, 0);
+
webkit_user_content_manager_register_script_message_handler (ucm,
"unsafeBrowsingErrorPage");
g_signal_connect_object (ucm, "script-message-received::unsafeBrowsingErrorPage",
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 04e0d5fee..3fb423191 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -660,6 +660,17 @@ allow_unsafe_browsing_cb (EphyEmbedShell *shell,
ephy_web_view_load_url (view, ephy_web_view_get_address (view));
}
+static void
+reload_page_cb (EphyEmbedShell *shell,
+ guint64 page_id,
+ EphyWebView *view)
+{
+ if (webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)) != page_id)
+ return;
+
+ webkit_web_view_reload (WEBKIT_WEB_VIEW (view));
+}
+
static void
_ephy_web_view_set_is_blank (EphyWebView *view,
gboolean is_blank)
@@ -1634,20 +1645,20 @@ ephy_web_view_get_error_page (EphyWebView *view)
* strings. Everywhere, but also here on the error pages in particular. */
static void
-format_network_error_page (const char *uri,
- const char *origin,
- const char *reason,
- char **page_title,
- char **message_title,
- char **message_body,
- char **message_details,
- char **button_label,
- char **button_action,
- const char **button_accesskey,
- const char **icon_name,
- const char **style)
+format_network_error_page (EphyWebView *view,
+ const char *uri,
+ const char *origin,
+ const char *reason,
+ char **page_title,
+ char **message_title,
+ char **message_body,
+ char **message_details,
+ char **button_label,
+ char **button_action,
+ const char **button_accesskey,
+ const char **icon_name,
+ const char **style)
{
- g_autofree char *encoded_uri = NULL;
g_autofree char *encoded_origin = NULL;
g_autofree char *formatted_origin = NULL;
g_autofree char *formatted_reason = NULL;
@@ -1683,8 +1694,8 @@ format_network_error_page (const char *uri,
/* The button on the network error page. DO NOT ADD MNEMONICS HERE. */
*button_label = g_strdup (_("Reload"));
- encoded_uri = ephy_encode_for_javascript (uri);
- *button_action = g_strdup_printf ("window.location = '%s';", encoded_uri);
+ *button_action = g_strdup_printf ("window.webkit.messageHandlers.reloadPage.postMessage(%"
G_GUINT64_FORMAT ");",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)));
/* Mnemonic for the Reload button on browser error pages. */
*button_accesskey = C_("reload-access-key", "R");
@@ -1693,18 +1704,18 @@ format_network_error_page (const char *uri,
}
static void
-format_crash_error_page (const char *uri,
- char **page_title,
- char **message_title,
- char **message_body,
- char **button_label,
- char **button_action,
- const char **button_accesskey,
- const char **icon_name,
- const char **style)
+format_crash_error_page (EphyWebView *view,
+ const char *uri,
+ char **page_title,
+ char **message_title,
+ char **message_body,
+ char **button_label,
+ char **button_action,
+ const char **button_accesskey,
+ const char **icon_name,
+ const char **style)
{
- g_autofree char *html_encoded_uri = NULL;
- g_autofree char *js_encoded_uri = NULL;
+ g_autofree char *encoded_uri = NULL;
g_autofree char *formatted_uri = NULL;
g_autofree char *formatted_distributor = NULL;
g_autofree char *first_paragraph = NULL;
@@ -1716,8 +1727,8 @@ format_crash_error_page (const char *uri,
/* Message title when a site cannot be loaded due to a page crash error. */
*message_title = g_strdup (_("Oops! There may be a problem"));
- html_encoded_uri = ephy_encode_for_html_entity (uri);
- formatted_uri = g_strdup_printf ("<strong>%s</strong>", html_encoded_uri);
+ encoded_uri = ephy_encode_for_html_entity (uri);
+ formatted_uri = g_strdup_printf ("<strong>%s</strong>", encoded_uri);
/* Error details when a site cannot be loaded due to a page crash error. */
first_paragraph = g_strdup_printf (_("The page %s may have caused Web to "
"close unexpectedly."),
@@ -1736,8 +1747,8 @@ format_crash_error_page (const char *uri,
/* The button on the page crash error page. DO NOT ADD MNEMONICS HERE. */
*button_label = g_strdup (_("Reload"));
- js_encoded_uri = ephy_encode_for_javascript (uri);
- *button_action = g_strdup_printf ("window.location = '%s';", js_encoded_uri);
+ *button_action = g_strdup_printf ("window.webkit.messageHandlers.reloadPage.postMessage(%"
G_GUINT64_FORMAT ");",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)));
/* Mnemonic for the Reload button on browser error pages. */
*button_accesskey = C_("reload-access-key", "R");
@@ -1746,17 +1757,17 @@ format_crash_error_page (const char *uri,
}
static void
-format_process_crash_error_page (const char *uri,
- char **page_title,
- char **message_title,
- char **message_body,
- char **button_label,
- char **button_action,
- const char **button_accesskey,
- const char **icon_name,
- const char **style)
+format_process_crash_error_page (EphyWebView *view,
+ const char *uri,
+ char **page_title,
+ char **message_title,
+ char **message_body,
+ char **button_label,
+ char **button_action,
+ const char **button_accesskey,
+ const char **icon_name,
+ const char **style)
{
- g_autofree char *encoded_uri = NULL;
const char *first_paragraph;
/* Page title when a site cannot be loaded due to a process crash error. */
@@ -1772,8 +1783,8 @@ format_process_crash_error_page (const char *uri,
/* The button on the process crash error page. DO NOT ADD MNEMONICS HERE. */
*button_label = g_strdup (_("Reload"));
- encoded_uri = ephy_encode_for_javascript (uri);
- *button_action = g_strdup_printf ("window.location = '%s';", encoded_uri);
+ *button_action = g_strdup_printf ("window.webkit.messageHandlers.reloadPage.postMessage(%"
G_GUINT64_FORMAT ");",
+ webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)));
/* Mnemonic for the Reload button on browser error pages. */
*button_accesskey = C_("reload-access-key", "R");
@@ -2027,7 +2038,8 @@ ephy_web_view_load_error_page (EphyWebView *view,
switch (page) {
case EPHY_WEB_VIEW_ERROR_PAGE_NETWORK_ERROR:
- format_network_error_page (uri,
+ format_network_error_page (view,
+ uri,
origin,
reason,
&page_title,
@@ -2041,7 +2053,8 @@ ephy_web_view_load_error_page (EphyWebView *view,
&style);
break;
case EPHY_WEB_VIEW_ERROR_PAGE_CRASH:
- format_crash_error_page (uri,
+ format_crash_error_page (view,
+ uri,
&page_title,
&msg_title,
&msg_body,
@@ -2052,7 +2065,8 @@ ephy_web_view_load_error_page (EphyWebView *view,
&style);
break;
case EPHY_WEB_VIEW_ERROR_PROCESS_CRASH:
- format_process_crash_error_page (uri,
+ format_process_crash_error_page (view,
+ uri,
&page_title,
&msg_title,
&msg_body,
@@ -3615,6 +3629,10 @@ ephy_web_view_init (EphyWebView *web_view)
g_signal_connect_object (shell, "allow-unsafe-browsing",
G_CALLBACK (allow_unsafe_browsing_cb),
web_view, 0);
+
+ g_signal_connect_object (shell, "reload-page",
+ G_CALLBACK (reload_page_cb),
+ web_view, 0);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]