Diff
Modified: trunk/Source/WebCore/ChangeLog (96828 => 96829)
--- trunk/Source/WebCore/ChangeLog 2011-10-06 17:34:42 UTC (rev 96828)
+++ trunk/Source/WebCore/ChangeLog 2011-10-06 17:39:21 UTC (rev 96829)
@@ -1,3 +1,17 @@
+2011-10-06 Carlos Garcia Campos <cgar...@igalia.com>
+
+ [GTK] Implement cache model for WebKit2
+ https://bugs.webkit.org/show_bug.cgi?id=68434
+
+ Reviewed by Martin Robinson.
+
+ Add a function to FileSystem to get the free space of the file
+ system where the given path is on.
+
+ * platform/FileSystem.h:
+ * platform/gtk/FileSystemGtk.cpp:
+ (WebCore::getVolumeFreeSizeForPath):
+
2011-10-06 Sergey Glazunov <serg.glazu...@gmail.com>
Add check for _javascript_ URLs in HTMLPlugInImageElement::allowedToLoadFrameURL
Modified: trunk/Source/WebCore/platform/FileSystem.h (96828 => 96829)
--- trunk/Source/WebCore/platform/FileSystem.h 2011-10-06 17:34:42 UTC (rev 96828)
+++ trunk/Source/WebCore/platform/FileSystem.h 2011-10-06 17:39:21 UTC (rev 96829)
@@ -198,6 +198,7 @@
String filenameToString(const char*);
String filenameForDisplay(const String&);
CString applicationDirectoryPath();
+uint64_t getVolumeFreeSizeForPath(const char*);
#endif
#if PLATFORM(WIN) && !OS(WINCE)
Modified: trunk/Source/WebCore/platform/gtk/FileSystemGtk.cpp (96828 => 96829)
--- trunk/Source/WebCore/platform/gtk/FileSystemGtk.cpp 2011-10-06 17:34:42 UTC (rev 96828)
+++ trunk/Source/WebCore/platform/gtk/FileSystemGtk.cpp 2011-10-06 17:39:21 UTC (rev 96829)
@@ -197,6 +197,16 @@
#endif
}
+uint64_t getVolumeFreeSizeForPath(const char* path)
+{
+ GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path));
+ GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_filesystem_info(file.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE, 0, 0));
+ if (!fileInfo)
+ return 0;
+
+ return g_file_info_get_attribute_uint64(fileInfo.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+}
+
String directoryName(const String& path)
{
/* No null checking needed */
Modified: trunk/Source/WebKit2/ChangeLog (96828 => 96829)
--- trunk/Source/WebKit2/ChangeLog 2011-10-06 17:34:42 UTC (rev 96828)
+++ trunk/Source/WebKit2/ChangeLog 2011-10-06 17:39:21 UTC (rev 96829)
@@ -1,3 +1,25 @@
+2011-10-06 Carlos Garcia Campos <cgar...@igalia.com>
+
+ [GTK] Implement cache model for WebKit2
+ https://bugs.webkit.org/show_bug.cgi?id=68434
+
+ Reviewed by Martin Robinson.
+
+ * UIProcess/API/gtk/WebKitWebContext.cpp:
+ (webkit_web_context_set_cache_model):
+ (webkit_web_context_get_cache_model):
+ * UIProcess/API/gtk/WebKitWebContext.h:
+ * UIProcess/API/gtk/tests/testwebcontext.c:
+ (testWebContextCacheModel):
+ (main):
+ * WebProcess/gtk/WebProcessGtk.cpp:
+ (WebKit::getCacheDiskFreeSize): Helper function to get free space
+ of the file system where the cache directory is on.
+ (WebKit::getMemorySize): Helper function to get the total memory
+ of the system in MB.
+ (WebKit::WebProcess::platformSetCacheModel): Implement
+ platformSetCacheModel for Gtk port using calculateCacheSizes().
+
2011-10-05 Alexey Proskuryakov <a...@apple.com>
https://bugs.webkit.org/show_bug.cgi?id=69492
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (96828 => 96829)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp 2011-10-06 17:34:42 UTC (rev 96828)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp 2011-10-06 17:39:21 UTC (rev 96829)
@@ -74,6 +74,84 @@
return WEBKIT_WEB_CONTEXT(g_once(&onceInit, createDefaultWebContext, 0));
}
+/**
+ * webkit_web_context_set_cache_model:
+ * @context: the #WebKitWebContext
+ * @cache_model: a #WebKitCacheModel
+ *
+ * Specifies a usage model for WebViews, which WebKit will use to
+ * determine its caching behavior. All web views follow the cache
+ * model. This cache model determines the RAM and disk space to use
+ * for caching previously viewed content .
+ *
+ * Research indicates that users tend to browse within clusters of
+ * documents that hold resources in common, and to revisit previously
+ * visited documents. WebKit and the frameworks below it include
+ * built-in caches that take advantage of these patterns,
+ * substantially improving document load speed in browsing
+ * situations. The WebKit cache model controls the behaviors of all of
+ * these caches, including various WebCore caches.
+ *
+ * Browsers can improve document load speed substantially by
+ * specifying WEBKIT_CACHE_MODEL_WEB_BROWSER. Applications without a
+ * browsing interface can reduce memory usage substantially by
+ * specifying WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER. The default value is
+ * WEBKIT_CACHE_MODEL_WEB_BROWSER.
+ *
+ */
+void webkit_web_context_set_cache_model(WebKitWebContext* context, WebKitCacheModel model)
+{
+ WKCacheModel cacheModel;
+
+ g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
+
+ switch (model) {
+ case WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER:
+ cacheModel = kWKCacheModelDocumentViewer;
+ break;
+ case WEBKIT_CACHE_MODEL_WEB_BROWSER:
+ cacheModel = kWKCacheModelPrimaryWebBrowser;
+ break;
+ case WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER:
+ cacheModel = kWKCacheModelDocumentBrowser;
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ WebKitWebContextPrivate* priv = context->priv;
+ if (cacheModel != WKContextGetCacheModel(priv->context.get()))
+ WKContextSetCacheModel(priv->context.get(), cacheModel);
+}
+
+/**
+ * webkit_web_context_get_cache_model:
+ * @context: the #WebKitWebContext
+ *
+ * Returns the current cache model. For more information about this
+ * value check the documentation of the function
+ * webkit_web_context_set_cache_model().
+ *
+ * Returns: the current #WebKitCacheModel
+ */
+WebKitCacheModel webkit_web_context_get_cache_model(WebKitWebContext* context)
+{
+ g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), WEBKIT_CACHE_MODEL_WEB_BROWSER);
+
+ WebKitWebContextPrivate* priv = context->priv;
+ switch (WKContextGetCacheModel(priv->context.get())) {
+ case kWKCacheModelDocumentViewer:
+ return WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER;
+ case kWKCacheModelPrimaryWebBrowser:
+ return WEBKIT_CACHE_MODEL_WEB_BROWSER;
+ case kWKCacheModelDocumentBrowser:
+ return WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER;
+ default:
+ g_assert_not_reached();
+ }
+
+ return WEBKIT_CACHE_MODEL_WEB_BROWSER;
+}
+
WKContextRef webkitWebContextGetWKContext(WebKitWebContext* context)
{
g_assert(WEBKIT_IS_WEB_CONTEXT(context));
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h (96828 => 96829)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h 2011-10-06 17:34:42 UTC (rev 96828)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h 2011-10-06 17:39:21 UTC (rev 96829)
@@ -36,6 +36,26 @@
#define WEBKIT_IS_WEB_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEB_CONTEXT))
#define WEBKIT_WEB_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_WEB_CONTEXT, WebKitWebContextClass))
+/*
+ * WebKitCacheModel:
+ * @WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER: Disable the cache completely, which
+ * substantially reduces memory usage. Useful for applications that only
+ * access a single local file, with no navigation to other pages. No remote
+ * resources will be cached.
+ * @WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER: A cache model optimized for viewing
+ * a series of local files -- for example, a documentation viewer or a website
+ * designer. WebKit will cache a moderate number of resources.
+ * @WEBKIT_CACHE_MODEL_WEB_BROWSER: Improve document load speed substantially
+ * by caching a very large number of resources and previously viewed content.
+ *
+ * Enum values used for determining the webview cache model.
+ */
+typedef enum {
+ WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER,
+ WEBKIT_CACHE_MODEL_WEB_BROWSER,
+ WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER
+} WebKitCacheModel;
+
typedef struct _WebKitWebContext WebKitWebContext;
typedef struct _WebKitWebContextClass WebKitWebContextClass;
typedef struct _WebKitWebContextPrivate WebKitWebContextPrivate;
@@ -58,11 +78,17 @@
};
WEBKIT_API GType
-webkit_web_context_get_type (void);
+webkit_web_context_get_type (void);
WEBKIT_API WebKitWebContext *
-webkit_web_context_get_default (void);
+webkit_web_context_get_default (void);
+WEBKIT_API void
+webkit_web_context_set_cache_model (WebKitWebContext *context,
+ WebKitCacheModel cache_model);
+WEBKIT_API WebKitCacheModel
+webkit_web_context_get_cache_model (WebKitWebContext *context);
+
G_END_DECLS
#endif
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/testwebcontext.c (96828 => 96829)
--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/testwebcontext.c 2011-10-06 17:34:42 UTC (rev 96828)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/testwebcontext.c 2011-10-06 17:39:21 UTC (rev 96829)
@@ -27,6 +27,23 @@
g_assert(webkit_web_context_get_default() == webkit_web_context_get_default());
}
+static void testWebContextCacheModel(void)
+{
+ WebKitWebContext *context = webkit_web_context_get_default();
+
+ /* Check default cache model is web browser. */
+ g_assert(webkit_web_context_get_cache_model(context) == WEBKIT_CACHE_MODEL_WEB_BROWSER);
+
+ webkit_web_context_set_cache_model(context, WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
+ g_assert(webkit_web_context_get_cache_model(context) == WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
+
+ webkit_web_context_set_cache_model(context, WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER);
+ g_assert(webkit_web_context_get_cache_model(context) == WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER);
+
+ webkit_web_context_set_cache_model(context, WEBKIT_CACHE_MODEL_WEB_BROWSER);
+ g_assert(webkit_web_context_get_cache_model(context) == WEBKIT_CACHE_MODEL_WEB_BROWSER);
+}
+
int main(int argc, char **argv)
{
g_thread_init(NULL);
@@ -35,6 +52,8 @@
g_test_bug_base("https://bugs.webkit.org/");
g_test_add_func("/webkit2/webcontext/default_context",
testWebContextDefault);
+ g_test_add_func("/webkit2/webcontext/cache_model",
+ testWebContextCacheModel);
return g_test_run();
}
Modified: trunk/Source/WebKit2/WebProcess/gtk/WebProcessGtk.cpp (96828 => 96829)
--- trunk/Source/WebKit2/WebProcess/gtk/WebProcessGtk.cpp 2011-10-06 17:34:42 UTC (rev 96828)
+++ trunk/Source/WebKit2/WebProcess/gtk/WebProcessGtk.cpp 2011-10-06 17:39:21 UTC (rev 96829)
@@ -27,16 +27,86 @@
#include "config.h"
#include "WebProcess.h"
+#define LIBSOUP_USE_UNSTABLE_REQUEST_API
+
#include "WebProcessCreationParameters.h"
+#include <WebCore/FileSystem.h>
+#include <WebCore/MemoryCache.h>
#include <WebCore/NotImplemented.h>
+#include <WebCore/PageCache.h>
+#include <WebCore/ResourceHandle.h>
+#include <libsoup/soup-cache.h>
+#include <wtf/gobject/GOwnPtr.h>
+#include <wtf/gobject/GRefPtr.h>
+#if !OS(WINDOWS)
+#include <unistd.h>
+#endif
+
namespace WebKit {
-void WebProcess::platformSetCacheModel(CacheModel)
+static uint64_t getCacheDiskFreeSize(SoupCache* cache)
{
- notImplemented();
+ if (!cache)
+ return 0;
+
+ GOwnPtr<char> cacheDir;
+ g_object_get(G_OBJECT(cache), "cache-dir", &cacheDir.outPtr(), NULL);
+ if (!cacheDir)
+ return 0;
+
+ return WebCore::getVolumeFreeSizeForPath(cacheDir.get());
}
+static uint64_t getMemorySize()
+{
+ static uint64_t kDefaultMemorySize = 512;
+#if !OS(WINDOWS)
+ long pageSize = sysconf(_SC_PAGESIZE);
+ if (pageSize == -1)
+ return kDefaultMemorySize;
+
+ long physPages = sysconf(_SC_PHYS_PAGES);
+ if (physPages == -1)
+ return kDefaultMemorySize;
+
+ return ((pageSize / 1024) * physPages) / 1024;
+#else
+ // Fallback to default for other platforms.
+ return kDefaultMemorySize;
+#endif
+}
+
+void WebProcess::platformSetCacheModel(CacheModel cacheModel)
+{
+ unsigned cacheTotalCapacity = 0;
+ unsigned cacheMinDeadCapacity = 0;
+ unsigned cacheMaxDeadCapacity = 0;
+ double deadDecodedDataDeletionInterval = 0;
+ unsigned pageCacheCapacity = 0;
+
+ unsigned long urlCacheMemoryCapacity = 0;
+ unsigned long urlCacheDiskCapacity = 0;
+
+ SoupSession* session = WebCore::ResourceHandle::defaultSession();
+ SoupCache* cache = reinterpret_cast<SoupCache*>(soup_session_get_feature(session, SOUP_TYPE_CACHE));
+ uint64_t diskFreeSize = getCacheDiskFreeSize(cache);
+
+ uint64_t memSize = getMemorySize();
+ calculateCacheSizes(cacheModel, memSize, diskFreeSize,
+ cacheTotalCapacity, cacheMinDeadCapacity, cacheMaxDeadCapacity, deadDecodedDataDeletionInterval,
+ pageCacheCapacity, urlCacheMemoryCapacity, urlCacheDiskCapacity);
+
+ WebCore::memoryCache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
+ WebCore::memoryCache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
+ WebCore::pageCache()->setCapacity(pageCacheCapacity);
+
+ if (cache) {
+ if (urlCacheDiskCapacity > soup_cache_get_max_size(cache))
+ soup_cache_set_max_size(cache, urlCacheDiskCapacity);
+ }
+}
+
void WebProcess::platformClearResourceCaches(ResourceCachesToClear)
{
notImplemented();