-
Notifications
You must be signed in to change notification settings - Fork 11
/
qultralightsettings.cpp
486 lines (408 loc) · 17 KB
/
qultralightsettings.cpp
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/*
Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2008 Holger Hans Peter Freyther
Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
Copyright (C) 2021 Jerzy Głowacki
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 "qultralightsettings.h"
#include <QFont>
QUltralightSettings::QUltralightSettings()
{
// Initialize our global defaults
_fontSizes.insert(QUltralightSettings::MinimumFontSize, 0);
_fontSizes.insert(QUltralightSettings::MinimumLogicalFontSize, 0);
_fontSizes.insert(QUltralightSettings::DefaultFontSize, 16);
_fontSizes.insert(QUltralightSettings::DefaultFixedFontSize, 13);
QFont defaultFont;
defaultFont.setStyleHint(QFont::Serif);
_fontFamilies.insert(QUltralightSettings::StandardFont, defaultFont.defaultFamily());
_fontFamilies.insert(QUltralightSettings::SerifFont, defaultFont.defaultFamily());
defaultFont.setStyleHint(QFont::Fantasy);
_fontFamilies.insert(QUltralightSettings::FantasyFont, defaultFont.defaultFamily());
defaultFont.setStyleHint(QFont::Cursive);
_fontFamilies.insert(QUltralightSettings::CursiveFont, defaultFont.defaultFamily());
defaultFont.setStyleHint(QFont::SansSerif);
_fontFamilies.insert(QUltralightSettings::SansSerifFont, defaultFont.defaultFamily());
defaultFont.setStyleHint(QFont::Monospace);
_fontFamilies.insert(QUltralightSettings::FixedFont, defaultFont.defaultFamily());
_attributes.insert(QUltralightSettings::AutoLoadImages, true);
_attributes.insert(QUltralightSettings::DnsPrefetchEnabled, false);
_attributes.insert(QUltralightSettings::JavascriptEnabled, true);
_attributes.insert(QUltralightSettings::SpatialNavigationEnabled, false);
_attributes.insert(QUltralightSettings::LinksIncludedInFocusChain, true);
_attributes.insert(QUltralightSettings::ZoomTextOnly, false);
_attributes.insert(QUltralightSettings::PrintElementBackgrounds, true);
_attributes.insert(QUltralightSettings::OfflineStorageDatabaseEnabled, false);
_attributes.insert(QUltralightSettings::OfflineWebApplicationCacheEnabled, false);
_attributes.insert(QUltralightSettings::LocalStorageEnabled, false);
_attributes.insert(QUltralightSettings::LocalContentCanAccessRemoteUrls, false);
_attributes.insert(QUltralightSettings::LocalContentCanAccessFileUrls, true);
_attributes.insert(QUltralightSettings::AcceleratedCompositingEnabled, false);
_attributes.insert(QUltralightSettings::WebGLEnabled, true);
_attributes.insert(QUltralightSettings::WebAudioEnabled, false);
_attributes.insert(QUltralightSettings::MediaSourceEnabled, false);
_attributes.insert(QUltralightSettings::MediaEnabled, true);
_attributes.insert(QUltralightSettings::CSSRegionsEnabled, true);
_attributes.insert(QUltralightSettings::CSSGridLayoutEnabled, false);
_attributes.insert(QUltralightSettings::HyperlinkAuditingEnabled, false);
_attributes.insert(QUltralightSettings::TiledBackingStoreEnabled, false);
_attributes.insert(QUltralightSettings::FrameFlatteningEnabled, false);
_attributes.insert(QUltralightSettings::SiteSpecificQuirksEnabled, true);
_attributes.insert(QUltralightSettings::ScrollAnimatorEnabled, false);
_attributes.insert(QUltralightSettings::CaretBrowsingEnabled, false);
_attributes.insert(QUltralightSettings::NotificationsEnabled, true);
_attributes.insert(QUltralightSettings::Accelerated2dCanvasEnabled, false);
_attributes.insert(QUltralightSettings::WebSecurityEnabled, true);
_attributes.insert(QUltralightSettings::FullScreenSupportEnabled, true);
_attributes.insert(QUltralightSettings::ImagesEnabled, true);
_attributes.insert(QUltralightSettings::AllowRunningInsecureContent, false);
_attributes.insert(QUltralightSettings::ErrorPageEnabled, true);
_offlineStorageDefaultQuota = 5 * 1024 * 1024;
_defaultTextEncoding = QLatin1String("iso-8859-1");
_thirdPartyCookiePolicy = AlwaysAllowThirdPartyCookies;
apply();
}
QUltralightSettings* QUltralightSettings::globalSettings()
{
static QUltralightSettings* global = 0;
if (!global) {
global = new QUltralightSettings;
}
return global;
}
QUltralightSettings::QUltralightSettings(WebCore::Page* page)
{
apply();
}
QUltralightSettings::~QUltralightSettings()
{
}
void QUltralightSettings::setFontSize(FontSize type, int size)
{
_fontSizes.insert(type, size);
apply();
}
int QUltralightSettings::fontSize(FontSize type) const
{
int defaultValue = globalSettings()->_fontSizes.value(type);
return _fontSizes.value(type, defaultValue);
}
void QUltralightSettings::resetFontSize(FontSize type)
{
_fontSizes.remove(type);
apply();
}
void QUltralightSettings::setUserStyleSheetUrl(const QUrl& location)
{
_userStyleSheetLocation = location;
apply();
}
QUrl QUltralightSettings::userStyleSheetUrl() const
{
return _userStyleSheetLocation;
}
void QUltralightSettings::setDefaultTextEncoding(const QString& encoding)
{
_defaultTextEncoding = encoding;
apply();
}
QString QUltralightSettings::defaultTextEncoding() const
{
return _defaultTextEncoding;
}
void QUltralightSettings::setIconDatabasePath(const QString& path)
{
// WebCore::initializeWebCoreQt();
//#if ENABLE(ICONDATABASE)
// // Make sure that IconDatabaseClientQt is instantiated.
// WebCore::IconDatabaseClientQt::instance();
//#endif
// WebCore::IconDatabase::delayDatabaseCleanup();
// WebCore::IconDatabaseBase& db = WebCore::iconDatabase();
// if (!path.isEmpty()) {
// db.setEnabled(true);
// if (db.isOpen())
// db.close();
// QFileInfo info(path);
// if (info.isDir() && info.isWritable())
// db.open(path, WebCore::IconDatabase::defaultDatabaseFilename());
// } else {
// db.setEnabled(false);
// db.close();
// }
}
QString QUltralightSettings::iconDatabasePath()
{
// WebCore::initializeWebCoreQt();
// if (WebCore::iconDatabase().isEnabled() && WebCore::iconDatabase().isOpen())
// return WebCore::iconDatabase().databasePath();
// else
return QString();
}
void QUltralightSettings::clearIconDatabase()
{
// WebCore::initializeWebCoreQt();
// if (WebCore::iconDatabase().isEnabled() && WebCore::iconDatabase().isOpen())
// WebCore::iconDatabase().removeAllIcons();
}
QIcon QUltralightSettings::iconForUrl(const QUrl& url)
{
// WebCore::initializeWebCoreQt();
// QPixmap* icon = WebCore::iconDatabase().synchronousNativeIconForPageURL(WebCore::URL(url).string(),
// WebCore::IntSize(16, 16));
// if (!icon)
// return QIcon();
// return* icon;
return QIcon();
}
void QUltralightSettings::setPluginSearchPaths(const QStringList& paths)
{
// WebCore::initializeWebCoreQt();
// Vector<String> directories;
// for (int i = 0; i < paths.count(); ++i)
// directories.append(paths.at(i));
// WebCore::PluginDatabase::installedPlugins()->setPluginDirectories(directories);
// // PluginDatabase::setPluginDirectories() does not refresh the database.
// WebCore::PluginDatabase::installedPlugins()->refresh();
}
QStringList QUltralightSettings::pluginSearchPaths()
{
// WebCore::initializeWebCoreQt();
// QStringList paths;
// const Vector<String>& directories = WebCore::PluginDatabase::installedPlugins()->pluginDirectories();
// for (unsigned i = 0; i < directories.size(); ++i)
// paths.append(directories[i]);
// return paths;
return QStringList();
}
static const char* resourceNameForWebGraphic(QUltralightSettings::WebGraphic type)
{
switch (type) {
case QUltralightSettings::MissingImageGraphic: return "missingImage";
case QUltralightSettings::MissingPluginGraphic: return "nullPlugin";
case QUltralightSettings::DefaultFrameIconGraphic: return "urlIcon";
case QUltralightSettings::TextAreaSizeGripCornerGraphic: return "textAreaResizeCorner";
case QUltralightSettings::DeleteButtonGraphic: return "deleteButton";
case QUltralightSettings::InputSpeechButtonGraphic: return "inputSpeech";
case QUltralightSettings::SearchCancelButtonGraphic: return "searchCancelButton";
case QUltralightSettings::SearchCancelButtonPressedGraphic: return "searchCancelButtonPressed";
}
return 0;
}
void QUltralightSettings::setWebGraphic(WebGraphic type, const QPixmap& graphic)
{
// WebCore::initializeWebCoreQt();
// WebCore::Image::setPlatformResource(resourceNameForWebGraphic(type), graphic);
}
QPixmap QUltralightSettings::webGraphic(WebGraphic type)
{
// WebCore::initializeWebCoreQt();
// RefPtr<WebCore::Image> img = WebCore::Image::loadPlatformResource(resourceNameForWebGraphic(type));
// if (!img)
// return QPixmap();
// QPixmap* pixmap = img->nativeImageForCurrentFrame();
// if (!pixmap)
// return QPixmap();
// return *pixmap;
return QPixmap();
}
void QUltralightSettings::clearMemoryCaches()
{
// WebCore::initializeWebCoreQt();
// //FIXME: This code is very similar to QtTestSupport::clearMemoryCaches().
// // Turn the cache on and off. Disabling the object cache will remove all
// // resources from the cache. They may still live on if they are referenced
// // by some Web page though.
// auto& memoryCache = WebCore::MemoryCache::singleton();
// if (!memoryCache.disabled()) {
// memoryCache.setDisabled(true);
// memoryCache.setDisabled(false);
// }
// auto& pageCache = WebCore::PageCache::singleton();
// int pageCacheMaxSize = pageCache.maxSize();
// // Setting size to 0, makes all pages be released.
// pageCache.setMaxSize(0);
// pageCache.setMaxSize(pageCacheMaxSize);
// // Invalidating the font cache and freeing all inactive font data.
// WebCore::FontCache::singleton().invalidate();
// // Empty the Cross-Origin Preflight cache
// WebCore::CrossOriginPreflightResultCache::singleton().empty();
// // Drop JIT compiled code from ExecutableAllocator.
// WebCore::GCController::singleton().deleteAllCode();
// // Garbage Collect to release the references of CachedResource from dead objects.
// WebCore::GCController::singleton().garbageCollectNow();
// // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself.
// WebCore::StorageThread::releaseFastMallocFreeMemoryInAllThreads();
// WebCore::WorkerThread::releaseFastMallocFreeMemoryInAllThreads();
// WTF::releaseFastMallocFreeMemory();
}
void QUltralightSettings::setMaximumPagesInCache(int pages)
{
// QUltralightSettingsPrivate* global = QUltralightSettings::globalSettings()->d;
// WebCore::PageCache::singleton().setMaxSize(qMax(0, pages));
// global->apply();
}
int QUltralightSettings::maximumPagesInCache()
{
// WebCore::initializeWebCoreQt();
// return WebCore::PageCache::singleton().maxSize();
return 1000;
}
void QUltralightSettings::setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)
{
// WebCore::initializeWebCoreQt();
// bool disableCache = !cacheMinDeadCapacity && !cacheMaxDead && !totalCapacity;
// auto& memoryCache = WebCore::MemoryCache::singleton();
// memoryCache.setDisabled(disableCache);
// memoryCache.setCapacities(qMax(0, cacheMinDeadCapacity),
// qMax(0, cacheMaxDead),
// qMax(0, totalCapacity));
// memoryCache.setDeadDecodedDataDeletionInterval(disableCache ? std::chrono::seconds{0}
// : std::chrono::seconds{60});
}
void QUltralightSettings::setThirdPartyCookiePolicy(ThirdPartyCookiePolicy policy)
{
_thirdPartyCookiePolicy = policy;
}
QUltralightSettings::ThirdPartyCookiePolicy QUltralightSettings::thirdPartyCookiePolicy() const
{
return _thirdPartyCookiePolicy;
}
void QUltralightSettings::setCSSMediaType(const QString& type)
{
_mediaType = type;
apply();
}
QString QUltralightSettings::cssMediaType() const
{
return _mediaType;
}
void QUltralightSettings::setFontFamily(FontFamily which, const QString& family)
{
_fontFamilies.insert(which, family);
apply();
}
QString QUltralightSettings::fontFamily(FontFamily which) const
{
QString defaultValue = globalSettings()->_fontFamilies.value(which);
return _fontFamilies.value(which, defaultValue);
}
void QUltralightSettings::resetFontFamily(FontFamily which)
{
_fontFamilies.remove(which);
apply();
}
void QUltralightSettings::setAttribute(WebAttribute attr, bool on)
{
_attributes.insert(attr, on);
apply();
}
bool QUltralightSettings::testAttribute(WebAttribute attr) const
{
bool defaultValue = globalSettings()->_attributes.value(attr);
return _attributes.value(attr, defaultValue);
}
void QUltralightSettings::resetAttribute(WebAttribute attr)
{
_attributes.remove(attr);
apply();
}
void QUltralightSettings::setOfflineStoragePath(const QString& path)
{
globalSettings()->_offlineDatabasePath = path;
// WebCore::DatabaseManager::singleton().setDatabaseDirectoryPath(path);
}
QString QUltralightSettings::offlineStoragePath()
{
return globalSettings()->_offlineDatabasePath;
}
void QUltralightSettings::setOfflineStorageDefaultQuota(qint64 maximumSize)
{
globalSettings()->_offlineStorageDefaultQuota = maximumSize;
}
qint64 QUltralightSettings::offlineStorageDefaultQuota()
{
return globalSettings()->_offlineStorageDefaultQuota;
}
void QUltralightSettings::setOfflineWebApplicationCachePath(const QString& path)
{
// WebCore::initializeWebCoreQt();
// WebCore::ApplicationCacheStorage::singleton().setCacheDirectory(path);
}
QString QUltralightSettings::offlineWebApplicationCachePath()
{
// WebCore::initializeWebCoreQt();
// return WebCore::ApplicationCacheStorage::singleton().cacheDirectory();
return QString();
}
void QUltralightSettings::setOfflineWebApplicationCacheQuota(qint64 maximumSize)
{
// WebCore::initializeWebCoreQt();
// auto& applicationCacheStorage = WebCore::ApplicationCacheStorage::singleton();
// applicationCacheStorage.empty();
// applicationCacheStorage.vacuumDatabaseFile();
// applicationCacheStorage.setMaximumSize(maximumSize);
}
qint64 QUltralightSettings::offlineWebApplicationCacheQuota()
{
// WebCore::initializeWebCoreQt();
// return WebCore::ApplicationCacheStorage::singleton().maximumSize();
return 1000;
}
void QUltralightSettings::setLocalStoragePath(const QString& path)
{
_localStoragePath = path;
apply();
}
QString QUltralightSettings::localStoragePath() const
{
return _localStoragePath;
}
void QUltralightSettings::enablePersistentStorage(const QString& path)
{
// WebCore::initializeWebCoreQt();
//#ifndef QT_NO_DESKTOPSERVICES
// QString storagePath;
// if (path.isEmpty()) {
// storagePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
// if (storagePath.isEmpty())
// storagePath = WebCore::pathByAppendingComponent(QDir::homePath(), QCoreApplication::applicationName());
// } else
// storagePath = path;
// WebCore::makeAllDirectories(storagePath);
// QUltralightSettings::setIconDatabasePath(storagePath);
// QUltralightSettings::setOfflineWebApplicationCachePath(storagePath);
// QUltralightSettings::setOfflineStoragePath(WebCore::pathByAppendingComponent(storagePath, "Databases"));
// QUltralightSettings::globalSettings()->setLocalStoragePath(WebCore::pathByAppendingComponent(storagePath, "LocalStorage"));
// QUltralightSettings::globalSettings()->setAttribute(QUltralightSettings::LocalStorageEnabled, true);
// QUltralightSettings::globalSettings()->setAttribute(QUltralightSettings::OfflineStorageDatabaseEnabled, true);
// QUltralightSettings::globalSettings()->setAttribute(QUltralightSettings::OfflineWebApplicationCacheEnabled, true);
//#if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
// // All applications can share the common QtWebkit cache file(s).
// // Path is not configurable and uses QDesktopServices::CacheLocation by default.
// QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
// WebCore::makeAllDirectories(cachePath);
// QFileInfo info(cachePath);
// if (info.isDir() && info.isWritable()) {
// WebCore::PluginDatabase::setPersistentMetadataCacheEnabled(true);
// WebCore::PluginDatabase::setPersistentMetadataCachePath(cachePath);
// }
//#endif
//#endif
}
void QUltralightSettings::apply()
{
//TODO
}