| 1 | /* |
| 2 | * Copyright (C) 2015-2017 Igalia S.L. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "APIWebsiteDataStore.h" |
| 28 | |
| 29 | #include <wtf/FileSystem.h> |
| 30 | #include <wtf/glib/GUniquePtr.h> |
| 31 | |
| 32 | #if PLATFORM(GTK) |
| 33 | #define BASE_DIRECTORY "webkitgtk" |
| 34 | #elif PLATFORM(WPE) |
| 35 | #define BASE_DIRECTORY "wpe" |
| 36 | #endif |
| 37 | |
| 38 | namespace API { |
| 39 | |
| 40 | WTF::String WebsiteDataStore::defaultApplicationCacheDirectory() |
| 41 | { |
| 42 | return cacheDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "applications" ); |
| 43 | } |
| 44 | |
| 45 | // FIXME: The other directories in this file are shared between all applications using WebKitGTK+. |
| 46 | // Why is only this directory namespaced to a particular application? |
| 47 | WTF::String WebsiteDataStore::defaultNetworkCacheDirectory() |
| 48 | { |
| 49 | return cacheDirectoryFileSystemRepresentation(FileSystem::pathByAppendingComponent(FileSystem::stringFromFileSystemRepresentation(g_get_prgname()), "WebKitCache" )); |
| 50 | } |
| 51 | |
| 52 | WTF::String WebsiteDataStore::defaultCacheStorageDirectory() |
| 53 | { |
| 54 | return cacheDirectoryFileSystemRepresentation(FileSystem::pathByAppendingComponent(FileSystem::stringFromFileSystemRepresentation(g_get_prgname()), "CacheStorage" )); |
| 55 | } |
| 56 | |
| 57 | WTF::String WebsiteDataStore::defaultIndexedDBDatabaseDirectory() |
| 58 | { |
| 59 | return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "databases" G_DIR_SEPARATOR_S "indexeddb" ); |
| 60 | } |
| 61 | |
| 62 | WTF::String WebsiteDataStore::defaultServiceWorkerRegistrationDirectory() |
| 63 | { |
| 64 | return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "serviceworkers" ); |
| 65 | } |
| 66 | |
| 67 | WTF::String WebsiteDataStore::defaultLocalStorageDirectory() |
| 68 | { |
| 69 | return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "localstorage" ); |
| 70 | } |
| 71 | |
| 72 | WTF::String WebsiteDataStore::defaultMediaKeysStorageDirectory() |
| 73 | { |
| 74 | return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "mediakeys" ); |
| 75 | } |
| 76 | |
| 77 | String WebsiteDataStore::defaultDeviceIdHashSaltsStorageDirectory() |
| 78 | { |
| 79 | return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "deviceidhashsalts" ); |
| 80 | } |
| 81 | |
| 82 | WTF::String WebsiteDataStore::defaultWebSQLDatabaseDirectory() |
| 83 | { |
| 84 | return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "databases" ); |
| 85 | } |
| 86 | |
| 87 | WTF::String WebsiteDataStore::defaultResourceLoadStatisticsDirectory() |
| 88 | { |
| 89 | return websiteDataDirectoryFileSystemRepresentation(BASE_DIRECTORY G_DIR_SEPARATOR_S "ResourceLoadStatistics" ); |
| 90 | } |
| 91 | |
| 92 | WTF::String WebsiteDataStore::cacheDirectoryFileSystemRepresentation(const WTF::String& directoryName) |
| 93 | { |
| 94 | return FileSystem::pathByAppendingComponent(FileSystem::stringFromFileSystemRepresentation(g_get_user_cache_dir()), directoryName); |
| 95 | } |
| 96 | |
| 97 | WTF::String WebsiteDataStore::websiteDataDirectoryFileSystemRepresentation(const WTF::String& directoryName) |
| 98 | { |
| 99 | return FileSystem::pathByAppendingComponent(FileSystem::stringFromFileSystemRepresentation(g_get_user_data_dir()), directoryName); |
| 100 | } |
| 101 | |
| 102 | WTF::String WebsiteDataStore::legacyDefaultApplicationCacheDirectory() |
| 103 | { |
| 104 | #if PLATFORM(WPE) |
| 105 | GUniquePtr<gchar> cacheDirectory(g_build_filename(g_get_user_cache_dir(), "wpe" , "appcache" , nullptr)); |
| 106 | return FileSystem::stringFromFileSystemRepresentation(cacheDirectory.get()); |
| 107 | #endif |
| 108 | return defaultApplicationCacheDirectory(); |
| 109 | } |
| 110 | |
| 111 | WTF::String WebsiteDataStore::legacyDefaultNetworkCacheDirectory() |
| 112 | { |
| 113 | #if PLATFORM(WPE) |
| 114 | GUniquePtr<char> diskCacheDirectory(g_build_filename(g_get_user_cache_dir(), "wpe" , "cache" , nullptr)); |
| 115 | return FileSystem::stringFromFileSystemRepresentation(diskCacheDirectory.get()); |
| 116 | #endif |
| 117 | return defaultNetworkCacheDirectory(); |
| 118 | } |
| 119 | |
| 120 | WTF::String WebsiteDataStore::legacyDefaultWebSQLDatabaseDirectory() |
| 121 | { |
| 122 | #if PLATFORM(WPE) |
| 123 | GUniquePtr<gchar> databaseDirectory(g_build_filename(g_get_user_data_dir(), "wpe" , "databases" , nullptr)); |
| 124 | return FileSystem::stringFromFileSystemRepresentation(databaseDirectory.get()); |
| 125 | #endif |
| 126 | return defaultWebSQLDatabaseDirectory(); |
| 127 | } |
| 128 | |
| 129 | WTF::String WebsiteDataStore::legacyDefaultIndexedDBDatabaseDirectory() |
| 130 | { |
| 131 | #if PLATFORM(WPE) |
| 132 | GUniquePtr<gchar> indexedDBDatabaseDirectory(g_build_filename(g_get_user_data_dir(), "wpe" , "databases" , "indexeddb" , nullptr)); |
| 133 | return FileSystem::stringFromFileSystemRepresentation(indexedDBDatabaseDirectory.get()); |
| 134 | #endif |
| 135 | return defaultIndexedDBDatabaseDirectory(); |
| 136 | } |
| 137 | |
| 138 | WTF::String WebsiteDataStore::legacyDefaultLocalStorageDirectory() |
| 139 | { |
| 140 | #if PLATFORM(WPE) |
| 141 | GUniquePtr<gchar> storageDirectory(g_build_filename(g_get_user_data_dir(), "wpe" , "localstorage" , nullptr)); |
| 142 | return FileSystem::stringFromFileSystemRepresentation(storageDirectory.get()); |
| 143 | #endif |
| 144 | return defaultLocalStorageDirectory(); |
| 145 | } |
| 146 | |
| 147 | WTF::String WebsiteDataStore::legacyDefaultMediaCacheDirectory() |
| 148 | { |
| 149 | #if PLATFORM(WPE) |
| 150 | GUniquePtr<gchar> cacheDirectory(g_build_filename(g_get_user_cache_dir(), "wpe" , "mediacache" , nullptr)); |
| 151 | return FileSystem::stringFromFileSystemRepresentation(cacheDirectory.get()); |
| 152 | #endif |
| 153 | return defaultMediaCacheDirectory(); |
| 154 | } |
| 155 | |
| 156 | WTF::String WebsiteDataStore::legacyDefaultMediaKeysStorageDirectory() |
| 157 | { |
| 158 | #if PLATFORM(WPE) |
| 159 | GUniquePtr<gchar> mediaKeysStorageDirectory(g_build_filename(g_get_user_data_dir(), "wpe" , "mediakeys" , nullptr)); |
| 160 | return FileSystem::stringFromFileSystemRepresentation(mediaKeysStorageDirectory.get()); |
| 161 | #endif |
| 162 | return defaultMediaKeysStorageDirectory(); |
| 163 | } |
| 164 | |
| 165 | String WebsiteDataStore::legacyDefaultDeviceIdHashSaltsStorageDirectory() |
| 166 | { |
| 167 | #if PLATFORM(WPE) |
| 168 | GUniquePtr<gchar> deviceIdHashSaltsStorageDirectory(g_build_filename(g_get_user_data_dir(), "wpe" , "deviceidhashsalts" , nullptr)); |
| 169 | return FileSystem::stringFromFileSystemRepresentation(deviceIdHashSaltsStorageDirectory.get()); |
| 170 | #endif |
| 171 | return defaultDeviceIdHashSaltsStorageDirectory(); |
| 172 | } |
| 173 | |
| 174 | WTF::String WebsiteDataStore::legacyDefaultJavaScriptConfigurationDirectory() |
| 175 | { |
| 176 | GUniquePtr<gchar> javaScriptCoreConfigDirectory(g_build_filename(g_get_user_data_dir(), BASE_DIRECTORY, "JavaScriptCoreDebug" , nullptr)); |
| 177 | return FileSystem::stringFromFileSystemRepresentation(javaScriptCoreConfigDirectory.get()); |
| 178 | } |
| 179 | |
| 180 | } // namespace API |
| 181 | |