[epiphany/gnome-40] Fix reload buttons on error pages
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/gnome-40] Fix reload buttons on error pages
- Date: Tue, 21 Dec 2021 00:25:52 +0000 (UTC)
commit 14ae864a5d1ff93ec9780e8cfc6ac8f06ebd54a7
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 | 110 +++++++++++++++++++++++++++--------------------
2 files changed, 100 insertions(+), 46 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 278cdefd8..67e3a03bd 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -78,6 +78,7 @@ enum {
WEB_VIEW_CREATED,
ALLOW_TLS_CERTIFICATE,
ALLOW_UNSAFE_BROWSING,
+ RELOAD_PAGE,
PASSWORD_FORM_FOCUSED,
LAST_SIGNAL
@@ -308,6 +309,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,
@@ -1115,6 +1127,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
@@ -1353,6 +1382,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);
@@ -1366,6 +1396,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 29158ab05..baa253af2 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -668,6 +668,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)
@@ -1774,20 +1785,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;
@@ -1823,8 +1834,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");
@@ -1833,18 +1844,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)
-{
- g_autofree char *html_encoded_uri = NULL;
- g_autofree char *js_encoded_uri = NULL;
+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 *encoded_uri = NULL;
g_autofree char *formatted_uri = NULL;
g_autofree char *formatted_distributor = NULL;
g_autofree char *first_paragraph = NULL;
@@ -1856,8 +1867,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."),
@@ -1876,8 +1887,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");
@@ -1886,17 +1897,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. */
@@ -1912,8 +1923,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");
@@ -2167,7 +2178,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,
@@ -2181,7 +2193,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,
@@ -2192,7 +2205,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,
@@ -3922,6 +3936,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]