#include "config.h"
#include "webkitglobals.h"
#include "ApplicationCacheStorage.h"
#include "Chrome.h"
#include "FrameNetworkingContextGtk.h"
#include "GOwnPtr.h"
#include "IconDatabase.h"
#include "Logging.h"
#include "MemoryCache.h"
#include "Page.h"
#include "PageCache.h"
#include "PageGroup.h"
#include "TextEncodingRegistry.h"
#include "Pasteboard.h"
#include "PasteboardHelperGtk.h"
#include "ResourceHandle.h"
#include "ResourceHandleClient.h"
#include "ResourceHandleInternal.h"
#include "ResourceResponse.h"
#include "webkitapplicationcache.h"
#include "webkitglobalsprivate.h"
#include "webkiticondatabase.h"
#include "webkitsoupauthdialog.h"
#include "webkitwebdatabase.h"
#include "webkitwebplugindatabaseprivate.h"
#include <libintl.h>
#include <runtime/InitializeThreading.h>
#include <stdlib.h>
#include <wtf/Threading.h>
static WebKitCacheModel cacheModel = WEBKIT_CACHE_MODEL_DEFAULT;
using namespace WebCore;
SoupSession* webkit_get_default_session ()
{
webkitInit();
return ResourceHandle::defaultSession();
}
void webkit_set_cache_model(WebKitCacheModel model)
{
webkitInit();
if (cacheModel == model)
return;
guint cacheTotalCapacity;
guint cacheMinDeadCapacity;
guint cacheMaxDeadCapacity;
gdouble deadDecodedDataDeletionInterval;
guint pageCacheCapacity;
switch (model) {
case WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER:
pageCacheCapacity = 0;
cacheTotalCapacity = 0; cacheMinDeadCapacity = 0;
cacheMaxDeadCapacity = 0;
deadDecodedDataDeletionInterval = 0;
break;
case WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER:
pageCacheCapacity = 2;
cacheTotalCapacity = 16 * 1024 * 1024;
cacheMinDeadCapacity = cacheTotalCapacity / 8;
cacheMaxDeadCapacity = cacheTotalCapacity / 4;
deadDecodedDataDeletionInterval = 0;
break;
case WEBKIT_CACHE_MODEL_WEB_BROWSER:
pageCacheCapacity = 3;
cacheTotalCapacity = 32 * 1024 * 1024;
cacheMinDeadCapacity = cacheTotalCapacity / 4;
cacheMaxDeadCapacity = cacheTotalCapacity / 2;
deadDecodedDataDeletionInterval = 60;
break;
default:
g_return_if_reached();
}
memoryCache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
memoryCache()->setDeadDecodedDataDeletionInterval(deadDecodedDataDeletionInterval);
pageCache()->setCapacity(pageCacheCapacity);
cacheModel = model;
}
WebKitCacheModel webkit_get_cache_model()
{
webkitInit();
return cacheModel;
}
WebKitWebPluginDatabase* webkit_get_web_plugin_database()
{
static WebKitWebPluginDatabase* database = 0;
webkitInit();
if (!database)
database = webkit_web_plugin_database_new();
return database;
}
static GtkWidget* currentToplevelCallback(WebKitSoupAuthDialog* feature, SoupMessage* message, gpointer userData)
{
gpointer messageData = g_object_get_data(G_OBJECT(message), "resourceHandle");
if (!messageData)
return NULL;
ResourceHandle* handle = static_cast<ResourceHandle*>(messageData);
if (!handle)
return NULL;
ResourceHandleInternal* d = handle->getInternal();
if (!d)
return NULL;
WebKit::FrameNetworkingContextGtk* context = static_cast<WebKit::FrameNetworkingContextGtk*>(d->m_context.get());
if (!context)
return NULL;
if (!context->coreFrame())
return NULL;
GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(context->coreFrame()->page()->chrome()->platformPageClient()));
if (gtk_widget_is_toplevel(toplevel))
return toplevel;
else
return NULL;
}
WebKitIconDatabase* webkit_get_icon_database()
{
webkitInit();
static WebKitIconDatabase* database = 0;
if (!database)
database = WEBKIT_ICON_DATABASE(g_object_new(WEBKIT_TYPE_ICON_DATABASE, NULL));
return database;
}
void webkitInit()
{
static bool isInitialized = false;
if (isInitialized)
return;
isInitialized = true;
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
JSC::initializeThreading();
WTF::initializeMainThread();
WebCore::InitializeLoggingChannelsIfNecessary();
atomicCanonicalTextEncodingName("UTF-8");
gchar* databaseDirectory = g_build_filename(g_get_user_data_dir(), "webkit", "databases", NULL);
webkit_set_web_database_directory_path(databaseDirectory);
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
WebCore::cacheStorage().setCacheDirectory(databaseDirectory);
#endif
g_free(databaseDirectory);
PageGroup::setShouldTrackVisitedLinks(true);
Pasteboard::generalPasteboard()->setHelper(WebKit::pasteboardHelperInstance());
GOwnPtr<gchar> iconDatabasePath(g_build_filename(g_get_user_data_dir(), "webkit", "icondatabase", NULL));
webkit_icon_database_set_path(webkit_get_icon_database(), iconDatabasePath.get());
SoupSession* session = webkit_get_default_session();
SoupSessionFeature* authDialog = static_cast<SoupSessionFeature*>(g_object_new(WEBKIT_TYPE_SOUP_AUTH_DIALOG, NULL));
g_signal_connect(authDialog, "current-toplevel", G_CALLBACK(currentToplevelCallback), NULL);
soup_session_add_feature(session, authDialog);
g_object_unref(authDialog);
SoupSessionFeature* sniffer = static_cast<SoupSessionFeature*>(g_object_new(SOUP_TYPE_CONTENT_SNIFFER, NULL));
soup_session_add_feature(session, sniffer);
g_object_unref(sniffer);
soup_session_add_feature_by_type(session, SOUP_TYPE_CONTENT_DECODER);
}
namespace WebKit {
PasteboardHelperGtk* pasteboardHelperInstance()
{
static PasteboardHelperGtk* helper = new PasteboardHelperGtk();
return helper;
}
}