Implement new libsoup cache for >= WebKitGTK+ 1.3.11

The web cache extension is automatically hidden/ disabled if
WebKitGTK+ is new enough, the new cache is a core feature.

By default 100 MB of pages can be cached on disk.

The 'Applications' preference tab is resurrected.

The same folder ~/.cache/midori/web is used for old and new cache.
This commit is contained in:
Christian Dywan 2011-05-01 06:59:00 +02:00
parent ad99d10433
commit 47437114c7
5 changed files with 95 additions and 16 deletions

View file

@ -21,6 +21,8 @@
#include <unistd.h>
#endif
#if !WEBKIT_CHECK_VERSION (1, 3, 11)
#define MAXLENGTH 1024 * 1024
static gchar*
@ -464,10 +466,14 @@ web_cache_clear_cache_cb (void)
{
sokoke_remove_path (web_cache_get_cache_dir (), TRUE);
}
#endif
MidoriExtension*
extension_init (void)
{
#if WEBKIT_CHECK_VERSION (1, 3, 11)
return NULL;
#else
MidoriExtension* extension = g_object_new (MIDORI_TYPE_EXTENSION,
"name", _("Web Cache"),
"description", _("Cache HTTP communication on disk"),
@ -482,4 +488,5 @@ extension_init (void)
G_CALLBACK (web_cache_clear_cache_cb));
return extension;
#endif
}

View file

@ -34,6 +34,11 @@
#include <webkit/webkit.h>
#include <sqlite3.h>
#if WEBKIT_CHECK_VERSION (1, 3, 11)
#define LIBSOUP_USE_UNSTABLE_REQUEST_API
#include <libsoup/soup-cache.h>
#endif
#if ENABLE_NLS
#include <libintl.h>
#include <locale.h>
@ -1236,6 +1241,17 @@ midori_load_soup_session_full (gpointer settings)
soup_session_add_feature (session, feature);
g_object_unref (feature);
#if WEBKIT_CHECK_VERSION (1, 3, 11)
config_file = g_build_filename (g_get_user_cache_dir (),
PACKAGE_NAME, "web", NULL);
feature = SOUP_SESSION_FEATURE (soup_cache_new (config_file, 0));
g_free (config_file);
soup_session_add_feature (session, feature);
soup_cache_set_max_size (SOUP_CACHE (feature),
katze_object_get_int (settings, "maximum-cache-size") * 1024 * 1024);
soup_cache_load (SOUP_CACHE (feature));
#endif
return FALSE;
}
@ -1315,6 +1331,10 @@ midori_load_extensions (gpointer data)
if (!extension)
{
/* No extension, no error: not available, not shown */
if (g_module_error () == NULL)
continue;
extension = g_object_new (MIDORI_TYPE_EXTENSION,
"name", filename,
"description", g_module_error (),
@ -1887,6 +1907,21 @@ midori_clear_html5_databases_cb (void)
webkit_remove_all_web_databases ();
}
#endif
#if WEBKIT_CHECK_VERSION (1, 3, 11)
static void
midori_clear_web_cache_cb (void)
{
SoupSession* session = webkit_get_default_session ();
SoupSessionFeature* feature = soup_session_get_feature (session, SOUP_TYPE_CACHE);
gchar* path = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME, "web", NULL);
soup_cache_clear (SOUP_CACHE (feature));
soup_cache_flush (SOUP_CACHE (feature));
sokoke_remove_path (path, TRUE);
g_free (path);
}
#endif
#if WEBKIT_CHECK_VERSION (1, 3, 13)
static void
midori_clear_offline_appcache_cb (void)
@ -2155,6 +2190,10 @@ main (int argc,
sokoke_register_privacy_item ("html5-databases", _("HTML5 _Databases"),
G_CALLBACK (midori_clear_html5_databases_cb));
#endif
#if WEBKIT_CHECK_VERSION (1, 3, 11)
sokoke_register_privacy_item ("web-cache", _("Web Cache"),
G_CALLBACK (midori_clear_web_cache_cb));
#endif
#if WEBKIT_CHECK_VERSION (1, 3, 13)
sokoke_register_privacy_item ("offline-appcache", _("Offline Application Cache"),
G_CALLBACK (midori_clear_offline_appcache_cb));

View file

@ -435,11 +435,19 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
INDENTED_ADD (button);
button = katze_property_proxy (settings, "open-tabs-in-the-background", NULL);
SPANNED_ADD (button);
/* Page "Applications" */
#if !HAVE_HILDON
PAGE_NEW (GTK_STOCK_CONVERT, _("Applications"));
FRAME_NEW (_("External applications"));
label = katze_property_label (settings, "text-editor");
INDENTED_ADD (label);
entry = katze_property_proxy (settings, "text-editor", "application-text/plain");
SPANNED_ADD (entry);
label = katze_property_label (settings, "news-aggregator");
INDENTED_ADD (label);
entry = katze_property_proxy (settings, "news-aggregator", "application-News");
SPANNED_ADD (entry);
#endif
/* Page "Network" */
@ -458,14 +466,16 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
G_CALLBACK (midori_preferences_notify_proxy_type_cb), entry);
midori_preferences_notify_proxy_type_cb (settings, NULL, entry);
#endif
#if WEBKIT_CHECK_VERSION (1, 3, 11)
label = katze_property_label (settings, "maximum-cache-size");
INDENTED_ADD (label);
button = katze_property_proxy (settings, "maximum-cache-size", NULL);
SPANNED_ADD (button);
label = gtk_label_new (_("MB"));
SPANNED_ADD (label);
#endif
label = katze_property_label (settings, "identify-as");
INDENTED_ADD (label);
button = katze_property_proxy (settings, "identify-as", "custom-user-agent");
SPANNED_ADD (button);
#if !HAVE_HILDON
label = katze_property_label (settings, "news-aggregator");
INDENTED_ADD (label);
entry = katze_property_proxy (settings, "news-aggregator", "application-News");
SPANNED_ADD (entry);
#endif
}

View file

@ -89,7 +89,6 @@ struct _MidoriView
GtkWidget* thumb_view;
KatzeArray* news_feeds;
gchar* news_aggregator;
gboolean middle_click_opens_selection;
gboolean open_tabs_in_the_background;
gboolean close_buttons_on_tabs;
@ -3292,7 +3291,6 @@ midori_view_init (MidoriView* view)
view->scrollh = view->scrollv = -2;
view->back_forward_set = FALSE;
view->news_aggregator = NULL;
view->web_view = NULL;
/* Adjustments are not created initially, but overwritten later */
view->scrolled_window = katze_scrolled_new (NULL, NULL);
@ -3348,8 +3346,6 @@ midori_view_finalize (GObject* object)
katze_object_assign (view->settings, NULL);
katze_object_assign (view->item, NULL);
katze_assign (view->news_aggregator, NULL);
G_OBJECT_CLASS (midori_view_parent_class)->finalize (object);
}
@ -3491,10 +3487,7 @@ _midori_view_set_settings (MidoriView* view,
g_object_set (view->web_view, "settings", settings, NULL);
g_free (view->news_aggregator);
g_object_get (view->settings,
"news-aggregator", &view->news_aggregator,
"zoom-text-and-images", &zoom_text_and_images,
"kinetic-scrolling", &kinetic_scrolling,
"close-buttons-on-tabs", &view->close_buttons_on_tabs,
@ -3549,9 +3542,7 @@ midori_view_settings_notify_cb (MidoriWebSettings* settings,
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (view->settings), name, &value);
if (name == g_intern_string ("news-aggregator"))
katze_assign (view->news_aggregator, g_value_dup_string (&value));
else if (name == g_intern_string ("zoom-text-and-images"))
if (name == g_intern_string ("zoom-text-and-images"))
{
if (view->web_view)
g_object_set (view->web_view, "full-content-zoom",

View file

@ -81,6 +81,9 @@ struct _MidoriWebSettings
gchar* news_aggregator;
gchar* location_entry_search;
gchar* http_proxy;
#if WEBKIT_CHECK_VERSION (1, 3, 11)
gint maximum_cache_size;
#endif
gchar* http_accept_language;
gchar* ident_string;
@ -167,6 +170,7 @@ enum
PROP_PROXY_TYPE,
PROP_HTTP_PROXY,
PROP_MAXIMUM_CACHE_SIZE,
PROP_IDENTIFY_AS,
PROP_USER_AGENT,
PROP_PREFERRED_LANGUAGES,
@ -1038,6 +1042,24 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
NULL,
flags));
#if WEBKIT_CHECK_VERSION (1, 3, 11)
/**
* MidoriWebSettings:maximum-cache-size:
*
* The maximum size of cached pages on disk.
*
* Since: 0.3.4
*/
g_object_class_install_property (gobject_class,
PROP_MAXIMUM_CACHE_SIZE,
g_param_spec_int (
"maximum-cache-size",
_("Web Cache"),
_("The maximum size of cached pages on disk"),
0, G_MAXINT, 100,
flags));
#endif
/**
* MidoriWebSettings:identify-as:
*
@ -1538,6 +1560,11 @@ midori_web_settings_set_property (GObject* object,
case PROP_HTTP_PROXY:
katze_assign (web_settings->http_proxy, g_value_dup_string (value));
break;
#if WEBKIT_CHECK_VERSION (1, 3, 11)
case PROP_MAXIMUM_CACHE_SIZE:
web_settings->maximum_cache_size = g_value_get_int (value);
break;
#endif
case PROP_IDENTIFY_AS:
web_settings->identify_as = g_value_get_enum (value);
if (web_settings->identify_as != MIDORI_IDENT_CUSTOM)
@ -1791,6 +1818,11 @@ midori_web_settings_get_property (GObject* object,
case PROP_HTTP_PROXY:
g_value_set_string (value, web_settings->http_proxy);
break;
#if WEBKIT_CHECK_VERSION (1, 3, 11)
case PROP_MAXIMUM_CACHE_SIZE:
g_value_set_int (value, web_settings->maximum_cache_size);
break;
#endif
case PROP_IDENTIFY_AS:
g_value_set_enum (value, web_settings->identify_as);
break;