#include "config.h"
#include "ewk_settings.h"
#include "EWebKit.h"
#include "IconDatabase.h"
#include "Image.h"
#include "IntSize.h"
#include "KURL.h"
#include "ewk_private.h"
#include <wtf/text/CString.h>
#include <eina_safety_checks.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
static uint64_t _ewk_default_web_database_quota = 1 * 1024;
uint64_t ewk_settings_web_database_default_quota_get()
{
return _ewk_default_web_database_quota;
}
Eina_Bool ewk_settings_icon_database_path_set(const char *directory)
{
WebCore::iconDatabase()->delayDatabaseCleanup();
if (directory) {
struct stat st;
if (stat(directory, &st)) {
ERR("could not stat(%s): %s", directory, strerror(errno));
return EINA_FALSE;
}
if (!S_ISDIR(st.st_mode)) {
ERR("not a directory: %s", directory);
return EINA_FALSE;
}
if (access(directory, R_OK | W_OK)) {
ERR("could not access directory '%s' for read and write: %s",
directory, strerror(errno));
return EINA_FALSE;
}
WebCore::iconDatabase()->setEnabled(true);
WebCore::iconDatabase()->open(WebCore::String::fromUTF8(directory));
} else {
WebCore::iconDatabase()->setEnabled(false);
WebCore::iconDatabase()->close();
}
return EINA_TRUE;
}
char* ewk_settings_icon_database_path_get(void)
{
if (!WebCore::iconDatabase()->isEnabled())
return 0;
if (!WebCore::iconDatabase()->isOpen())
return 0;
WebCore::String path = WebCore::iconDatabase()->databasePath();
if (path.isEmpty())
return 0;
return strdup(path.utf8().data());
}
Eina_Bool ewk_settings_icon_database_clear(void)
{
if (!WebCore::iconDatabase()->isEnabled())
return EINA_FALSE;
if (!WebCore::iconDatabase()->isOpen())
return EINA_FALSE;
WebCore::iconDatabase()->removeAllIcons();
return EINA_TRUE;
}
cairo_surface_t* ewk_settings_icon_database_icon_surface_get(const char *url)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(url, 0);
WebCore::KURL kurl(WebCore::KURL(), WebCore::String::fromUTF8(url));
WebCore::Image *icon = WebCore::iconDatabase()->iconForPageURL(kurl.string(), WebCore::IntSize(16, 16));
if (!icon) {
ERR("no icon for url %s", url);
return 0;
}
return icon->nativeImageForCurrentFrame();
}
Evas_Object* ewk_settings_icon_database_icon_object_add(const char* url, Evas* canvas)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(url, 0);
EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
WebCore::KURL kurl(WebCore::KURL(), WebCore::String::fromUTF8(url));
WebCore::Image* icon = WebCore::iconDatabase()->iconForPageURL(kurl.string(), WebCore::IntSize(16, 16));
cairo_surface_t* surface;
if (!icon) {
ERR("no icon for url %s", url);
return 0;
}
surface = icon->nativeImageForCurrentFrame();
return ewk_util_image_from_cairo_surface_add(canvas, surface);
}