summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/gtk/webkit/webkitapplicationcache.cpp
blob: ab179b5d10731fab796e192bc591cde066800bb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 * Copyright (C) 2009 Jan Michael Alonzo <jmalonzo@gmail.com>
 * Copyright (C) 2011 Lukasz Slachciak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "config.h"
#include "webkitapplicationcache.h"

#include "ApplicationCacheStorage.h"
#include "FileSystem.h"
#include <wtf/UnusedParam.h>
#include <wtf/text/CString.h>

// keeps current directory path to offline web applications cache database
static WTF::CString cacheDirectoryPath = "";
// web application cache maximum storage size
static unsigned long long cacheMaxSize = UINT_MAX;

/**
 * webkit_application_cache_get_maximum_size:
 *
 * Returns the maximum size of the cache storage.
 * By default it is set to UINT_MAX i.e. no quota.
 *
 * Returns: the current application cache maximum storage size
 *
 * Since: 1.3.13
 **/
unsigned long long webkit_application_cache_get_maximum_size()
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
    return (cacheMaxSize = WebCore::cacheStorage().maximumSize());
#else
    return 0;
#endif
}

/**
 * webkit_application_cache_set_maximum_size:
 * @size: the new web application cache maximum storage size
 *
 * Sets new application cache maximum storage size.
 * Changing the application cache storage size will clear the cache
 * and rebuild cache storage.
 *
 * Since: 1.3.13
 **/
void webkit_application_cache_set_maximum_size(unsigned long long size)
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
    if (size != cacheMaxSize) {
        WebCore::cacheStorage().empty();
        WebCore::cacheStorage().vacuumDatabaseFile();
        WebCore::cacheStorage().setMaximumSize(size);
        cacheMaxSize = size;
    }
#else
    UNUSED_PARAM(size);
#endif
}

/**
 * webkit_spplication_cache_get_database_directory_path:
 *
 * Returns the current path to the directory WebKit will write web application
 * cache databases. By default this path is set to $XDG_DATA_HOME/webkit/databases
 * with webkit_application_cache_set_database_directory_path
 *
 * Returns: the current application cache database directory path
 *
 * Since: 1.3.13
 **/
G_CONST_RETURN gchar* webkit_application_cache_get_database_directory_path()
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
    CString path = WebCore::fileSystemRepresentation(WebCore::cacheStorage().cacheDirectory());

    if (path != cacheDirectoryPath)
        cacheDirectoryPath = path;

    return cacheDirectoryPath.data();
#else
    return "";
#endif
}

/**
 * webkit_application_cache_set_database_directory_path:
 * @path: the new web application cache database path
 *
 * Sets the current path to the directory WebKit will write web aplication cache
 * databases.
 *
 * Since: 1.3.13
 **/
void webkit_application_cache_set_database_directory_path(const gchar* path)
{
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
    WTF::CString pathString(path);
    if (pathString != cacheDirectoryPath)
        cacheDirectoryPath = pathString;

    WebCore::cacheStorage().setCacheDirectory(WebCore::filenameToString(cacheDirectoryPath.data()));
#endif
}