[epiphany/gnome-3-38] ephy-reader-handler: Only fetch existing source data for user triggered actions
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/gnome-3-38] ephy-reader-handler: Only fetch existing source data for user triggered actions
- Date: Sat, 26 Sep 2020 13:58:16 +0000 (UTC)
commit f1bfc423c6f6ecc32ab114e2158c60c192b0b386
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Fri Sep 25 15:50:57 2020 +0000
ephy-reader-handler: Only fetch existing source data for user triggered actions
Store user reader mode toggle request as EphyWebView property. Based on this information
load the existing source data or trigger a new load.
Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/1339
(cherry picked from commit 4d85e4fbd540fb36c55b3c299a72a871c8aabd0d)
embed/ephy-reader-handler.c | 69 +++++++++++++++------------------------------
embed/ephy-web-view.c | 26 +++++++++++++++++
2 files changed, 49 insertions(+), 46 deletions(-)
---
diff --git a/embed/ephy-reader-handler.c b/embed/ephy-reader-handler.c
index 79b4c4710..e10604dd8 100644
--- a/embed/ephy-reader-handler.c
+++ b/embed/ephy-reader-handler.c
@@ -45,7 +45,6 @@ typedef struct {
WebKitWebView *web_view;
GCancellable *cancellable;
guint load_changed_id;
- char *uri;
} EphyReaderRequest;
static EphyReaderRequest *
@@ -70,7 +69,6 @@ ephy_reader_request_free (EphyReaderRequest *request)
if (request->load_changed_id > 0)
g_signal_handler_disconnect (request->web_view, request->load_changed_id);
- g_clear_pointer (&request->uri, g_free);
g_object_unref (request->source_handler);
g_object_unref (request->scheme_request);
g_clear_object (&request->web_view);
@@ -252,43 +250,12 @@ ephy_reader_request_begin_get_source_from_uri (EphyReaderRequest *request,
webkit_web_view_load_uri (request->web_view, uri);
}
-static void
-web_resource_data_cb (WebKitWebResource *resource,
- GAsyncResult *result,
- EphyReaderRequest *request)
-{
- g_autofree guchar *data = NULL;
- g_autoptr (GError) error = NULL;
- gsize length;
-
- data = webkit_web_resource_get_data_finish (resource, result, &length, &error);
- if (!data || !*data || length == 0) {
- g_clear_object (&request->web_view);
- ephy_reader_request_begin_get_source_from_uri (request, request->uri);
- } else {
- ephy_reader_request_begin_get_source_from_web_view (request, request->web_view);
- }
-}
-
-static void
-ephy_reader_request_begin_get_source_from_initiator (EphyReaderRequest *request,
- WebKitWebView *web_view)
-{
- WebKitWebResource *resource = webkit_web_view_get_main_resource (web_view);
-
- g_assert (resource);
- webkit_web_resource_get_data (resource,
- request->cancellable,
- (GAsyncReadyCallback)web_resource_data_cb,
- request);
-}
-
static void
ephy_reader_request_start (EphyReaderRequest *request)
{
g_autoptr (SoupURI) soup_uri = NULL;
- const char *modified_uri;
const char *original_uri;
+ WebKitWebView *web_view;
original_uri = webkit_uri_scheme_request_get_uri (request->scheme_request);
soup_uri = soup_uri_new (original_uri);
@@ -303,18 +270,28 @@ ephy_reader_request_start (EphyReaderRequest *request)
return;
}
- /* Extract URI:
- * ephy-reader:https://example.com/whatever?xyz into https://example.com/whatever?xyz
- */
- modified_uri = soup_uri_to_string (soup_uri, TRUE);
- g_assert (modified_uri);
-
- request->uri = g_strdup (modified_uri);
- request->web_view = webkit_uri_scheme_request_get_web_view (request->scheme_request);
- if (request->web_view && webkit_web_view_get_main_resource (request->web_view))
- ephy_reader_request_begin_get_source_from_initiator (request, g_object_ref (request->web_view));
- else
- ephy_reader_request_begin_get_source_from_uri (request, request->uri);
+ web_view = webkit_uri_scheme_request_get_web_view (request->scheme_request);
+ if (web_view) {
+ gboolean entering_reader_mode;
+
+ g_object_get (G_OBJECT (web_view), "entering-reader-mode", &entering_reader_mode, NULL);
+ if (!entering_reader_mode)
+ web_view = NULL;
+ }
+
+ if (web_view) {
+ ephy_reader_request_begin_get_source_from_web_view (request, web_view);
+ } else {
+ const char *source_uri;
+
+ /* Extract URI:
+ * ephy-reader:https://example.com/whatever?xyz into https://example.com/whatever?xyz
+ */
+ source_uri = soup_uri_to_string (soup_uri, TRUE);
+ g_assert (source_uri);
+
+ ephy_reader_request_begin_get_source_from_uri (request, source_uri);
+ }
request->source_handler->outstanding_requests =
g_list_prepend (request->source_handler->outstanding_requests, request);
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 5f30abf49..13119f2df 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -91,6 +91,7 @@ struct _EphyWebView {
GdkPixbuf *icon;
/* Reader mode */
+ gboolean entering_reader_mode;
gboolean reader_mode_available;
guint reader_js_timeout;
@@ -139,6 +140,7 @@ enum {
PROP_IS_BLANK,
PROP_READER_MODE,
PROP_DISPLAY_ADDRESS,
+ PROP_ENTERING_READER_MODE,
LAST_PROP
};
@@ -244,6 +246,9 @@ ephy_web_view_get_property (GObject *object,
case PROP_DISPLAY_ADDRESS:
g_value_set_string (value, view->display_address);
break;
+ case PROP_ENTERING_READER_MODE:
+ g_value_set_boolean (value, view->entering_reader_mode);
+ break;
default:
break;
}
@@ -269,6 +274,7 @@ ephy_web_view_set_property (GObject *object,
case PROP_IS_BLANK:
case PROP_READER_MODE:
case PROP_DISPLAY_ADDRESS:
+ case PROP_ENTERING_READER_MODE:
/* read only */
break;
default:
@@ -1589,6 +1595,11 @@ load_changed_cb (WebKitWebView *web_view,
/* Reset visit type. */
view->visit_type = EPHY_PAGE_VISIT_NONE;
+ if (view->entering_reader_mode) {
+ view->entering_reader_mode = FALSE;
+ g_object_notify_by_pspec (G_OBJECT (web_view), obj_properties[PROP_ENTERING_READER_MODE]);
+ }
+
if (!ephy_web_view_is_history_frozen (view) &&
ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) != EPHY_EMBED_SHELL_MODE_INCOGNITO) {
/* FIXME: The 1s delay is a workaround to allow time to render the page and get a favicon.
@@ -3649,6 +3660,9 @@ ephy_web_view_toggle_reader_mode (EphyWebView *view,
reader_uri = g_strconcat (EPHY_READER_SCHEME, ":", address, NULL);
+ view->entering_reader_mode = TRUE;
+ g_object_notify_by_pspec (G_OBJECT (web_view), obj_properties[PROP_ENTERING_READER_MODE]);
+
webkit_web_view_load_uri (web_view, reader_uri);
}
@@ -3996,6 +4010,18 @@ ephy_web_view_class_init (EphyWebViewClass *klass)
"",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+/**
+ * EphyWebView:entering-reader-mode:
+ *
+ * Whether the view is entering reader mode.
+ **/
+ obj_properties[PROP_ENTERING_READER_MODE] =
+ g_param_spec_boolean ("entering-reader-mode",
+ "Entering reader mode",
+ "If the EphyWebView is entering reader mode",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (gobject_class, LAST_PROP, obj_properties);
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]