[epiphany/mcatanzaro/regressions: 1/3] Fix reload buttons on error pages
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mcatanzaro/regressions: 1/3] Fix reload buttons on error pages
- Date: Mon, 20 Dec 2021 17:03:33 +0000 (UTC)
commit b44a18348d57377a1151403dc13c744b7a48616e
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
embed/ephy-embed-shell.c | 36 +++++++++++++++++++++++++++
embed/ephy-web-view.c | 65 +++++++++++++++++++++++++++++++-----------------
2 files changed, 78 insertions(+), 23 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 189370bd8..99d1fb0ef 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
@@ -309,6 +310,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,
@@ -1170,6 +1182,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
@@ -1408,6 +1437,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);
@@ -1421,6 +1451,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 ae8413e94..3a8e4d672 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -670,6 +670,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)
@@ -1846,7 +1857,8 @@ 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,
+format_network_error_page (EphyWebView *view,
+ const char *uri,
const char *origin,
const char *reason,
char **page_title,
@@ -1859,7 +1871,6 @@ format_network_error_page (const char *uri,
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;
@@ -1895,8 +1906,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");
@@ -1905,7 +1916,8 @@ format_network_error_page (const char *uri,
}
static void
-format_crash_error_page (const char *uri,
+format_crash_error_page (EphyWebView *view,
+ const char *uri,
char **page_title,
char **message_title,
char **message_body,
@@ -1915,8 +1927,7 @@ format_crash_error_page (const char *uri,
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;
@@ -1928,8 +1939,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."),
@@ -1948,8 +1959,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");
@@ -1958,7 +1969,8 @@ format_crash_error_page (const char *uri,
}
static void
-format_process_crash_error_page (const char *uri,
+format_process_crash_error_page (EphyWebView *view,
+ const char *uri,
char **page_title,
char **message_title,
char **message_body,
@@ -1968,7 +1980,6 @@ format_process_crash_error_page (const char *uri,
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. */
@@ -1984,8 +1995,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");
@@ -1994,7 +2005,8 @@ format_process_crash_error_page (const char *uri,
}
static void
-format_unresponsive_process_error_page (const char *uri,
+format_unresponsive_process_error_page (EphyWebView *view,
+ const char *uri,
char **page_title,
char **message_title,
char **message_body,
@@ -2004,7 +2016,6 @@ format_unresponsive_process_error_page (const char *uri,
const char **icon_name,
const char **style)
{
- g_autofree char *encoded_uri = NULL;
const char *first_paragraph;
/* Page title when web content has become unresponsive. */
@@ -2020,8 +2031,8 @@ format_unresponsive_process_error_page (const char *uri,
/* The button on the unresponsive process 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");
@@ -2275,7 +2286,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,
@@ -2289,7 +2301,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,
@@ -2300,7 +2313,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,
@@ -2311,7 +2325,8 @@ ephy_web_view_load_error_page (EphyWebView *view,
&style);
break;
case EPHY_WEB_VIEW_ERROR_UNRESPONSIVE_PROCESS:
- format_unresponsive_process_error_page (uri,
+ format_unresponsive_process_error_page (view,
+ uri,
&page_title,
&msg_title,
&msg_body,
@@ -4079,6 +4094,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]