initial import
[vuplus_webkit] / Source / WebKit / gtk / webkit / webkitapplicationcache.cpp
1 /*
2  * Copyright (C) 2009 Jan Michael Alonzo <jmalonzo@gmail.com>
3  * Copyright (C) 2011 Lukasz Slachciak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22 #include "webkitapplicationcache.h"
23
24 #include "ApplicationCacheStorage.h"
25 #include "FileSystem.h"
26 #include <wtf/UnusedParam.h>
27 #include <wtf/text/CString.h>
28
29 // web application cache maximum storage size
30 static unsigned long long cacheMaxSize = UINT_MAX;
31
32 /**
33  * webkit_application_cache_get_maximum_size:
34  *
35  * Returns the maximum size of the cache storage.
36  * By default it is set to UINT_MAX i.e. no quota.
37  *
38  * Returns: the current application cache maximum storage size
39  *
40  * Since: 1.3.13
41  **/
42 unsigned long long webkit_application_cache_get_maximum_size()
43 {
44 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
45     return (cacheMaxSize = WebCore::cacheStorage().maximumSize());
46 #else
47     return 0;
48 #endif
49 }
50
51 /**
52  * webkit_application_cache_set_maximum_size:
53  * @size: the new web application cache maximum storage size
54  *
55  * Sets new application cache maximum storage size.
56  * Changing the application cache storage size will clear the cache
57  * and rebuild cache storage.
58  *
59  * Since: 1.3.13
60  **/
61 void webkit_application_cache_set_maximum_size(unsigned long long size)
62 {
63 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
64     if (size != cacheMaxSize) {
65         WebCore::cacheStorage().empty();
66         WebCore::cacheStorage().vacuumDatabaseFile();
67         WebCore::cacheStorage().setMaximumSize(size);
68         cacheMaxSize = size;
69     }
70 #else
71     UNUSED_PARAM(size);
72 #endif
73 }
74
75 /**
76  * webkit_spplication_cache_get_database_directory_path:
77  *
78  * Returns the current path to the directory WebKit will write web application
79  * cache databases. By default this path is set to $XDG_DATA_HOME/webkit/databases
80  * with webkit_application_cache_set_database_directory_path
81  *
82  * Returns: the current application cache database directory path
83  *
84  * Since: 1.3.13
85  **/
86 const gchar* webkit_application_cache_get_database_directory_path()
87 {
88 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
89     CString path = WebCore::fileSystemRepresentation(WebCore::cacheStorage().cacheDirectory());
90     return path.data();
91 #else
92     return "";
93 #endif
94 }
95