[evolution/wip/webkit2] Let the remote content code work again
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/webkit2] Let the remote content code work again
- Date: Tue, 29 Mar 2016 12:08:41 +0000 (UTC)
commit 363c6ab7dade9df4749cd6d5b8bdd0e958e895e7
Author: Milan Crha <mcrha redhat com>
Date: Tue Mar 29 14:08:24 2016 +0200
Let the remote content code work again
e-util/e-web-view.c | 35 +++++++++
e-util/e-web-view.h | 3 +
mail/e-mail-display.c | 123 ++++++++++++++++++++----------
web-extensions/e-web-extension.c | 157 +++-----------------------------------
4 files changed, 133 insertions(+), 185 deletions(-)
---
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index 6efd68e..0fd44cc 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -120,6 +120,7 @@ enum {
STOP_LOADING,
UPDATE_ACTIONS,
PROCESS_MAILTO,
+ URI_REQUESTED,
LAST_SIGNAL
};
@@ -1034,6 +1035,7 @@ web_view_process_uri_request_cb (WebKitURISchemeRequest *request,
{
EContentRequest *content_request = user_data;
const gchar *uri;
+ gchar *redirect_to_uri = NULL;
GObject *requester;
g_return_if_fail (WEBKIT_IS_URI_SCHEME_REQUEST (request));
@@ -1044,8 +1046,30 @@ web_view_process_uri_request_cb (WebKitURISchemeRequest *request,
g_return_if_fail (e_content_request_can_process_uri (content_request, uri));
+ if (E_IS_WEB_VIEW (requester)) {
+ /* Expects an empty string to abandon the request,
+ or NULL to keep the passed-in uri,
+ or a new uri to load instead. */
+ g_signal_emit (requester, signals[URI_REQUESTED], 0, uri, &redirect_to_uri);
+
+ if (redirect_to_uri && *redirect_to_uri) {
+ uri = redirect_to_uri;
+ } else if (redirect_to_uri) {
+ GError *error;
+
+ g_free (redirect_to_uri);
+
+ error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CANCELLED, "Cancelled");
+
+ webkit_uri_scheme_request_finish_error (request, error);
+ return;
+ }
+ }
+
e_content_request_process (content_request, uri, requester, NULL,
web_view_uri_request_done_cb, g_object_ref (request));
+
+ g_free (redirect_to_uri);
}
/* 'scheme' is like "file", not "file:" */
@@ -2001,6 +2025,17 @@ e_web_view_class_init (EWebViewClass *class)
NULL, NULL,
e_marshal_BOOLEAN__STRING,
G_TYPE_BOOLEAN, 1, G_TYPE_STRING);
+
+ /* Expects an empty string to abandon the request,
+ or NULL to keep the passed-in uri,
+ or a new uri to load instead. */
+ signals[URI_REQUESTED] = g_signal_new (
+ "uri-requested",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EWebViewClass, uri_requested),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_POINTER);
}
static void
diff --git a/e-util/e-web-view.h b/e-util/e-web-view.h
index 0b7e4c4..5701127 100644
--- a/e-util/e-web-view.h
+++ b/e-util/e-web-view.h
@@ -107,6 +107,9 @@ struct _EWebViewClass {
void (*update_actions) (EWebView *web_view);
gboolean (*process_mailto) (EWebView *web_view,
const gchar *mailto_uri);
+ void (*uri_requested) (EWebView *web_view,
+ const gchar *uri,
+ gchar **redirect_to_uri);
};
GType e_web_view_get_type (void) G_GNUC_CONST;
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index b821887..c29beb4 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -85,6 +85,8 @@ enum {
PROP_REMOTE_CONTENT
};
+static CamelDataCache *emd_global_http_cache = NULL;
+
static const gchar *ui =
"<ui>"
" <popup name='context'>"
@@ -1528,10 +1530,43 @@ mail_display_button_press_event (GtkWidget *widget,
return GTK_WIDGET_CLASS (e_mail_display_parent_class)->
button_press_event (widget, event);
}
-#if 0 /* FIXME WK2 */
-static gchar *
-mail_display_redirect_uri (EWebView *web_view,
- const gchar *uri)
+
+
+static gboolean
+mail_display_image_exists_in_cache (const gchar *image_uri)
+{
+ gchar *filename;
+ gchar *hash;
+ gboolean exists = FALSE;
+
+ if (!emd_global_http_cache)
+ return FALSE;
+
+ hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, image_uri, -1);
+ filename = camel_data_cache_get_filename (
+ emd_global_http_cache, "http", hash);
+
+ if (filename != NULL) {
+ struct stat st;
+
+ exists = g_file_test (filename, G_FILE_TEST_EXISTS);
+ if (exists && g_stat (filename, &st) == 0) {
+ exists = st.st_size != 0;
+ } else {
+ exists = FALSE;
+ }
+ g_free (filename);
+ }
+
+ g_free (hash);
+
+ return exists;
+}
+
+static void
+mail_display_uri_requested_cb (EWebView *web_view,
+ const gchar *uri,
+ gchar **redirect_to_uri)
{
EMailDisplay *display;
EMailPartList *part_list;
@@ -1541,7 +1576,7 @@ mail_display_redirect_uri (EWebView *web_view,
part_list = e_mail_display_get_part_list (display);
if (part_list == NULL)
- goto chainup;
+ return;
uri_is_http =
g_str_has_prefix (uri, "http:") ||
@@ -1563,7 +1598,8 @@ mail_display_redirect_uri (EWebView *web_view,
can_download_uri = e_mail_display_can_download_uri (display, uri);
if (!can_download_uri) {
/* Check Evolution's cache */
- can_download_uri = mail_display_image_exists_in_cache (uri);
+ can_download_uri = mail_display_image_exists_in_cache (
+ uri + (g_str_has_prefix (uri, "evo-") ? 4 : 0));
}
/* If the URI is not cached and we are not allowed to load it
@@ -1574,17 +1610,26 @@ mail_display_redirect_uri (EWebView *web_view,
if (!can_download_uri && !display->priv->force_image_load &&
(image_policy == E_IMAGE_LOADING_POLICY_NEVER)) {
e_mail_display_claim_skipped_uri (display, uri);
- return g_strdup ("about:blank");
+ g_free (*redirect_to_uri);
+ *redirect_to_uri = g_strdup ("");
+ return;
}
folder = e_mail_part_list_get_folder (part_list);
message_uid = e_mail_part_list_get_message_uid (part_list);
- new_uri = g_strconcat ("evo-", uri, NULL);
+ if (g_str_has_prefix (uri, "evo-")) {
+ soup_uri = soup_uri_new (uri);
+ } else {
+ new_uri = g_strconcat ("evo-", uri, NULL);
+ soup_uri = soup_uri_new (new_uri);
+
+ g_free (new_uri);
+ }
+
mail_uri = e_mail_part_build_uri (
folder, message_uid, NULL, NULL);
- soup_uri = soup_uri_new (new_uri);
if (soup_uri->query)
query = soup_form_decode (soup_uri->query);
else
@@ -1606,22 +1651,18 @@ mail_display_redirect_uri (EWebView *web_view,
g_free (mail_uri);
soup_uri_set_query_from_form (soup_uri, query);
- g_free (new_uri);
new_uri = soup_uri_to_string (soup_uri, FALSE);
soup_uri_free (soup_uri);
g_hash_table_unref (query);
- return new_uri;
+ g_free (*redirect_to_uri);
+ *redirect_to_uri = new_uri;
}
-
-chainup:
- /* Chain up to parent's redirect_uri() method. */
- return E_WEB_VIEW_CLASS (e_mail_display_parent_class)->
- redirect_uri (web_view, uri);
}
+#if 0 /* FIXME WK2 */
static CamelMimePart *
camel_mime_part_from_cid (EMailDisplay *display,
const gchar *uri)
@@ -1776,7 +1817,6 @@ e_mail_display_class_init (EMailDisplayClass *class)
web_view_class = E_WEB_VIEW_CLASS (class);
#if 0
- web_view_class->redirect_uri = mail_display_redirect_uri;
web_view_class->suggest_filename = mail_display_suggest_filename;
#endif
web_view_class->set_fonts = mail_display_set_fonts;
@@ -1920,6 +1960,29 @@ e_mail_display_init (EMailDisplay *display)
g_mutex_init (&display->priv->remote_content_lock);
display->priv->remote_content = NULL;
display->priv->skipped_remote_content_sites = g_hash_table_new_full (camel_strcase_hash,
camel_strcase_equal, g_free, NULL);
+
+ g_signal_connect (display, "uri-requested", G_CALLBACK (mail_display_uri_requested_cb), NULL);
+
+ if (emd_global_http_cache == NULL) {
+ const gchar *user_cache_dir;
+ GError *error = NULL;
+
+ user_cache_dir = e_get_user_cache_dir ();
+ emd_global_http_cache = camel_data_cache_new (user_cache_dir, &error);
+
+ if (emd_global_http_cache) {
+ /* cache expiry - 2 hour access, 1 day max */
+ camel_data_cache_set_expire_age (
+ emd_global_http_cache, 24 * 60 * 60);
+ camel_data_cache_set_expire_access (
+ emd_global_http_cache, 2 * 60 * 60);
+ } else {
+ e_alert_submit (
+ E_ALERT_SINK (display), "mail:folder-open",
+ error ? error->message : _("Unknown error"), NULL);
+ g_clear_error (&error);
+ }
+ }
}
static void
@@ -2352,30 +2415,12 @@ void
e_mail_display_set_force_load_images (EMailDisplay *display,
gboolean force_load_images)
{
- GDBusProxy *web_extension;
-
g_return_if_fail (E_IS_MAIL_DISPLAY (display));
- web_extension = e_web_view_get_web_extension_proxy (E_WEB_VIEW (display));
- if (web_extension) {
- g_dbus_connection_call (
- g_dbus_proxy_get_connection (web_extension),
- g_dbus_proxy_get_name (web_extension),
- E_WEB_EXTENSION_OBJECT_PATH,
- "org.freedesktop.DBus.Properties",
- "Set",
- g_variant_new (
- "(ssv)",
- E_WEB_EXTENSION_INTERFACE,
- "ForceImageLoad",
- g_variant_new_boolean (force_load_images)),
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL,
- NULL);
- }
+ if ((display->priv->force_image_load ? 1 : 0) == (force_load_images ? 1 : 0))
+ return;
+
+ display->priv->force_image_load = force_load_images;
}
gboolean
diff --git a/web-extensions/e-web-extension.c b/web-extensions/e-web-extension.c
index cce5ea6..0e5ebba 100644
--- a/web-extensions/e-web-extension.c
+++ b/web-extensions/e-web-extension.c
@@ -49,11 +49,8 @@ struct _EWebExtensionPrivate {
gboolean initialized;
gboolean need_input;
- gboolean force_image_load;
};
-static CamelDataCache *emd_global_http_cache = NULL;
-
static const char introspection_xml[] =
"<node>"
" <interface name='" E_WEB_EXTENSION_INTERFACE "'>"
@@ -142,7 +139,6 @@ static const char introspection_xml[] =
" <arg type='s' name='new_iframe_src' direction='in'/>"
" </method>"
" <property type='b' name='NeedInput' access='readwrite'/>"
-" <property type='b' name='ForceImageLoad' access='readwrite'/>"
" </interface>"
"</node>";
@@ -462,8 +458,6 @@ handle_get_property (GDBusConnection *connection,
if (g_strcmp0 (property_name, "NeedInput") == 0) {
variant = g_variant_new_boolean (extension->priv->need_input);
- } else if (g_strcmp0 (property_name, "ForceImageLoad") == 0) {
- variant = g_variant_new_boolean (extension->priv->force_image_load);
}
return variant;
@@ -497,18 +491,6 @@ handle_set_property (GDBusConnection *connection,
"{sv}",
"NeedInput",
g_variant_new_boolean (value));
- } else if (g_strcmp0 (property_name, "ForceImageLoad") == 0) {
- gboolean value = g_variant_get_boolean (variant);
-
- if (value == extension->priv->force_image_load)
- goto exit;
-
- extension->priv->force_image_load = value;
-
- g_variant_builder_add (builder,
- "{sv}",
- "ForceImageLoad",
- g_variant_new_boolean (value));
}
g_dbus_connection_emit_signal (connection,
@@ -572,7 +554,6 @@ e_web_extension_init (EWebExtension *extension)
extension->priv->initialized = FALSE;
extension->priv->need_input = FALSE;
- extension->priv->force_image_load = FALSE;
}
static gpointer
@@ -589,120 +570,13 @@ e_web_extension_get (void)
}
static gboolean
-image_exists_in_cache (const gchar *image_uri)
-{
- gchar *filename;
- gchar *hash;
- gboolean exists = FALSE;
-
- g_return_val_if_fail (emd_global_http_cache != NULL, FALSE);
-
- hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, image_uri, -1);
- filename = camel_data_cache_get_filename (
- emd_global_http_cache, "http", hash);
-
- if (filename != NULL) {
- struct stat st;
-
- exists = g_file_test (filename, G_FILE_TEST_EXISTS);
- if (exists && g_stat (filename, &st) == 0) {
- exists = st.st_size != 0;
- } else {
- exists = FALSE;
- }
- g_free (filename);
- }
-
- g_free (hash);
-
- return exists;
-}
-
-static EImageLoadingPolicy
-get_image_loading_policy (void)
-{
- GSettings *settings;
- EImageLoadingPolicy image_policy;
-
- settings = e_util_ref_settings ("org.gnome.evolution.mail");
- image_policy = g_settings_get_enum (settings, "image-loading-policy");
- g_object_unref (settings);
-
- return image_policy;
-}
-
-static void
-redirect_http_uri (EWebExtension *extension,
- WebKitWebPage *web_page,
- WebKitURIRequest *request)
-{
- const gchar *uri, *page_uri;
- gchar *new_uri, *mail_uri, *enc;
- SoupURI *soup_uri;
- GHashTable *query;
- gboolean image_exists;
- EImageLoadingPolicy image_policy;
-
- uri = webkit_uri_request_get_uri (request);
- page_uri = webkit_web_page_get_uri (web_page);
-
- /* Check Evolution's cache */
- image_exists = image_exists_in_cache (uri);
-
- /* If the URI is not cached and we are not allowed to load it
- * then redirect to invalid URI, so that webkit would display
- * a native placeholder for it. */
- image_policy = get_image_loading_policy ();
- if (!image_exists && !extension->priv->force_image_load &&
- (image_policy == E_IMAGE_LOADING_POLICY_NEVER)) {
- webkit_uri_request_set_uri (request, "about:blank");
- return;
- }
-
- new_uri = g_strconcat ("evo-", uri, NULL);
- mail_uri = g_strndup (page_uri, strstr (page_uri, "?") - page_uri);
-
- soup_uri = soup_uri_new (new_uri);
- if (soup_uri->query)
- query = soup_form_decode (soup_uri->query);
- else
- query = g_hash_table_new_full (
- g_str_hash, g_str_equal,
- g_free, g_free);
-
- enc = soup_uri_encode (mail_uri, NULL);
- g_hash_table_insert (query, g_strdup ("__evo-mail"), enc);
-
- if (extension->priv->force_image_load) {
- g_hash_table_insert (
- query,
- g_strdup ("__evo-load-images"),
- g_strdup ("true"));
- }
-
- g_free (mail_uri);
-
- soup_uri_set_query_from_form (soup_uri, query);
- g_free (new_uri);
-
- new_uri = soup_uri_to_string (soup_uri, FALSE);
-
- webkit_uri_request_set_uri (request, new_uri);
-
- soup_uri_free (soup_uri);
- g_hash_table_unref (query);
- g_free (new_uri);
-}
-
-static gboolean
web_page_send_request_cb (WebKitWebPage *web_page,
WebKitURIRequest *request,
WebKitURIResponse *redirected_response,
EWebExtension *extension)
{
- const char *request_uri;
- const char *page_uri;
- gboolean uri_is_http;
+ const gchar *request_uri;
+ const gchar *page_uri;
request_uri = webkit_uri_request_get_uri (request);
page_uri = webkit_web_page_get_uri (web_page);
@@ -714,14 +588,16 @@ web_page_send_request_cb (WebKitWebPage *web_page,
g_str_has_prefix (page_uri, "https:"))
return FALSE;
- uri_is_http =
- g_str_has_prefix (request_uri, "http:") ||
- g_str_has_prefix (request_uri, "https:") ||
- g_str_has_prefix (request_uri, "evo-http:") ||
- g_str_has_prefix (request_uri, "evo-https:");
+ if (g_str_has_prefix (request_uri, "http:") ||
+ g_str_has_prefix (request_uri, "https:")) {
+ gchar *new_uri;
- if (uri_is_http)
- redirect_http_uri (extension, web_page, request);
+ new_uri = g_strconcat ("evo-", request_uri, NULL);
+
+ webkit_uri_request_set_uri (request, new_uri);
+
+ g_free (new_uri);
+ }
return FALSE;
}
@@ -762,17 +638,6 @@ e_web_extension_initialize (EWebExtension *extension,
extension->priv->wk_extension = g_object_ref (wk_extension);
- if (emd_global_http_cache == NULL) {
- emd_global_http_cache = camel_data_cache_new (
- e_get_user_cache_dir (), NULL);
-
- /* cache expiry - 2 hour access, 1 day max */
- camel_data_cache_set_expire_age (
- emd_global_http_cache, 24 * 60 * 60);
- camel_data_cache_set_expire_access (
- emd_global_http_cache, 2 * 60 * 60);
- }
-
g_signal_connect (
wk_extension, "page-created",
G_CALLBACK (web_page_created_cb), extension);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]