• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19 
20 #include "config.h"
21 #include "qwebsettings.h"
22 
23 #include "qwebpage.h"
24 #include "qwebpage_p.h"
25 #include "qwebplugindatabase.h"
26 
27 #include "Cache.h"
28 #include "CrossOriginPreflightResultCache.h"
29 #include "FontCache.h"
30 #include "Page.h"
31 #include "PageCache.h"
32 #include "Settings.h"
33 #include "KURL.h"
34 #include "PlatformString.h"
35 #include "IconDatabase.h"
36 #include "Image.h"
37 #include "IntSize.h"
38 #include "ApplicationCacheStorage.h"
39 #include "DatabaseTracker.h"
40 
41 #include <QHash>
42 #include <QSharedData>
43 #include <QUrl>
44 #include <QFileInfo>
45 
46 class QWebSettingsPrivate {
47 public:
QWebSettingsPrivate(WebCore::Settings * wcSettings=0)48     QWebSettingsPrivate(WebCore::Settings* wcSettings = 0)
49         : settings(wcSettings)
50     {
51     }
52 
53     QHash<int, QString> fontFamilies;
54     QHash<int, int> fontSizes;
55     QHash<int, bool> attributes;
56     QUrl userStyleSheetLocation;
57     QString defaultTextEncoding;
58     QString localStorageDatabasePath;
59     QString offlineWebApplicationCachePath;
60     qint64 offlineStorageDefaultQuota;
61 
62     void apply();
63     WebCore::Settings* settings;
64 };
65 
66 typedef QHash<int, QPixmap> WebGraphicHash;
Q_GLOBAL_STATIC(WebGraphicHash,_graphics)67 Q_GLOBAL_STATIC(WebGraphicHash, _graphics)
68 
69 static WebGraphicHash* graphics()
70 {
71     WebGraphicHash* hash = _graphics();
72 
73     if (hash->isEmpty()) {
74         hash->insert(QWebSettings::MissingImageGraphic, QPixmap(QLatin1String(":webkit/resources/missingImage.png")));
75         hash->insert(QWebSettings::MissingPluginGraphic, QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));
76         hash->insert(QWebSettings::DefaultFrameIconGraphic, QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));
77         hash->insert(QWebSettings::TextAreaSizeGripCornerGraphic, QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
78     }
79 
80     return hash;
81 }
82 
83 Q_GLOBAL_STATIC(QList<QWebSettingsPrivate*>, allSettings);
84 
apply()85 void QWebSettingsPrivate::apply()
86 {
87     if (settings) {
88         settings->setTextAreasAreResizable(true);
89 
90         QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
91 
92         QString family = fontFamilies.value(QWebSettings::StandardFont,
93                                             global->fontFamilies.value(QWebSettings::StandardFont));
94         settings->setStandardFontFamily(family);
95 
96         family = fontFamilies.value(QWebSettings::FixedFont,
97                                     global->fontFamilies.value(QWebSettings::FixedFont));
98         settings->setFixedFontFamily(family);
99 
100         family = fontFamilies.value(QWebSettings::SerifFont,
101                                     global->fontFamilies.value(QWebSettings::SerifFont));
102         settings->setSerifFontFamily(family);
103 
104         family = fontFamilies.value(QWebSettings::SansSerifFont,
105                                     global->fontFamilies.value(QWebSettings::SansSerifFont));
106         settings->setSansSerifFontFamily(family);
107 
108         family = fontFamilies.value(QWebSettings::CursiveFont,
109                                     global->fontFamilies.value(QWebSettings::CursiveFont));
110         settings->setCursiveFontFamily(family);
111 
112         family = fontFamilies.value(QWebSettings::FantasyFont,
113                                     global->fontFamilies.value(QWebSettings::FantasyFont));
114         settings->setFantasyFontFamily(family);
115 
116         int size = fontSizes.value(QWebSettings::MinimumFontSize,
117                                    global->fontSizes.value(QWebSettings::MinimumFontSize));
118         settings->setMinimumFontSize(size);
119 
120         size = fontSizes.value(QWebSettings::MinimumLogicalFontSize,
121                                    global->fontSizes.value(QWebSettings::MinimumLogicalFontSize));
122         settings->setMinimumLogicalFontSize(size);
123 
124         size = fontSizes.value(QWebSettings::DefaultFontSize,
125                                    global->fontSizes.value(QWebSettings::DefaultFontSize));
126         settings->setDefaultFontSize(size);
127 
128         size = fontSizes.value(QWebSettings::DefaultFixedFontSize,
129                                    global->fontSizes.value(QWebSettings::DefaultFixedFontSize));
130         settings->setDefaultFixedFontSize(size);
131 
132         bool value = attributes.value(QWebSettings::AutoLoadImages,
133                                       global->attributes.value(QWebSettings::AutoLoadImages));
134         settings->setLoadsImagesAutomatically(value);
135 
136         value = attributes.value(QWebSettings::JavascriptEnabled,
137                                       global->attributes.value(QWebSettings::JavascriptEnabled));
138         settings->setJavaScriptEnabled(value);
139 
140         value = attributes.value(QWebSettings::JavascriptCanOpenWindows,
141                                       global->attributes.value(QWebSettings::JavascriptCanOpenWindows));
142         settings->setJavaScriptCanOpenWindowsAutomatically(value);
143 
144         value = attributes.value(QWebSettings::JavaEnabled,
145                                       global->attributes.value(QWebSettings::JavaEnabled));
146         settings->setJavaEnabled(value);
147 
148         value = attributes.value(QWebSettings::PluginsEnabled,
149                                       global->attributes.value(QWebSettings::PluginsEnabled));
150         settings->setPluginsEnabled(value);
151 
152         value = attributes.value(QWebSettings::PrivateBrowsingEnabled,
153                                       global->attributes.value(QWebSettings::PrivateBrowsingEnabled));
154         settings->setPrivateBrowsingEnabled(value);
155 
156         value = attributes.value(QWebSettings::JavascriptCanAccessClipboard,
157                                       global->attributes.value(QWebSettings::JavascriptCanAccessClipboard));
158         settings->setDOMPasteAllowed(value);
159 
160         value = attributes.value(QWebSettings::DeveloperExtrasEnabled,
161                                       global->attributes.value(QWebSettings::DeveloperExtrasEnabled));
162         settings->setDeveloperExtrasEnabled(value);
163 
164         QUrl location = !userStyleSheetLocation.isEmpty() ? userStyleSheetLocation : global->userStyleSheetLocation;
165         settings->setUserStyleSheetLocation(WebCore::KURL(location));
166 
167         QString encoding = !defaultTextEncoding.isEmpty() ? defaultTextEncoding: global->defaultTextEncoding;
168         settings->setDefaultTextEncodingName(encoding);
169 
170         QString localStoragePath = !localStorageDatabasePath.isEmpty() ? localStorageDatabasePath : global->localStorageDatabasePath;
171         settings->setLocalStorageDatabasePath(localStoragePath);
172 
173         value = attributes.value(QWebSettings::ZoomTextOnly,
174                                  global->attributes.value(QWebSettings::ZoomTextOnly));
175         settings->setZoomsTextOnly(value);
176 
177         value = attributes.value(QWebSettings::PrintElementBackgrounds,
178                                       global->attributes.value(QWebSettings::PrintElementBackgrounds));
179         settings->setShouldPrintBackgrounds(value);
180 
181         value = attributes.value(QWebSettings::OfflineStorageDatabaseEnabled,
182                                       global->attributes.value(QWebSettings::OfflineStorageDatabaseEnabled));
183         settings->setDatabasesEnabled(value);
184 
185         value = attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled,
186                                       global->attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled));
187         settings->setOfflineWebApplicationCacheEnabled(value);
188 
189         value = attributes.value(QWebSettings::LocalStorageDatabaseEnabled,
190                                       global->attributes.value(QWebSettings::LocalStorageDatabaseEnabled));
191         settings->setLocalStorageEnabled(value);
192 
193         value = attributes.value(QWebSettings::LocalContentCanAccessRemoteUrls,
194                                       global->attributes.value(QWebSettings::LocalContentCanAccessRemoteUrls));
195         settings->setAllowUniversalAccessFromFileURLs(value);
196     } else {
197         QList<QWebSettingsPrivate*> settings = *::allSettings();
198         for (int i = 0; i < settings.count(); ++i)
199             settings[i]->apply();
200     }
201 }
202 
203 /*!
204     Returns the global settings object.
205 
206     Any setting changed on the default object is automatically applied to all
207     QWebPage instances where the particular setting is not overriden already.
208 */
globalSettings()209 QWebSettings* QWebSettings::globalSettings()
210 {
211     static QWebSettings* global = 0;
212     if (!global)
213         global = new QWebSettings;
214     return global;
215 }
216 
217 /*!
218     \class QWebSettings
219     \since 4.4
220     \brief The QWebSettings class provides an object to store the settings used
221     by QWebPage and QWebFrame.
222 
223     Each QWebPage object has its own QWebSettings object, which configures the
224     settings for that page. If a setting is not configured, then it is looked
225     up in the global settings object, which can be accessed using
226     globalSettings().
227 
228     QWebSettings allows configuration of browser properties, such as font sizes and
229     families, the location of a custom style sheet, and generic attributes like
230     JavaScript and plugins. Individual attributes are set using the setAttribute()
231     function. The \l{QWebSettings::WebAttribute}{WebAttribute} enum further describes
232     each attribute.
233 
234     QWebSettings also configures global properties such as the Web page memory
235     cache and the Web page icon database, local database storage and offline
236     applications storage.
237 
238     \section1 Enabling Plugins
239 
240     Support for browser plugins can enabled by setting the
241     \l{QWebSettings::PluginsEnabled}{PluginsEnabled} attribute. For many applications,
242     this attribute is enabled for all pages by setting it on the
243     \l{globalSettings()}{global settings object}.
244 
245     \section1 Web Application Support
246 
247     WebKit provides support for features specified in \l{HTML 5} that improve the
248     performance and capabilities of Web applications. These include client-side
249     (offline) storage and the use of a Web application cache.
250 
251     Client-side (offline) storage is an improvement over the use of cookies to
252     store persistent data in Web applications. Applications can configure and
253     enable the use of an offline storage database by calling the
254     setOfflineStoragePath() with an appropriate file path, and can limit the quota
255     for each application by calling setOfflineStorageDefaultQuota().
256 
257     \sa QWebPage::settings(), QWebView::settings(), {Browser}
258 */
259 
260 /*!
261     \enum QWebSettings::FontFamily
262 
263     This enum describes the generic font families defined by CSS 2.
264     For more information see the
265     \l{http://www.w3.org/TR/REC-CSS2/fonts.html#generic-font-families}{CSS standard}.
266 
267     \value StandardFont
268     \value FixedFont
269     \value SerifFont
270     \value SansSerifFont
271     \value CursiveFont
272     \value FantasyFont
273 */
274 
275 /*!
276     \enum QWebSettings::FontSize
277 
278     This enum describes the font sizes configurable through QWebSettings.
279 
280     \value MinimumFontSize The hard minimum font size.
281     \value MinimumLogicalFontSize The minimum logical font size that is applied
282         after zooming with QWebFrame's textSizeMultiplier().
283     \value DefaultFontSize The default font size for regular text.
284     \value DefaultFixedFontSize The default font size for fixed-pitch text.
285 */
286 
287 /*!
288     \enum QWebSettings::WebGraphic
289 
290     This enums describes the standard graphical elements used in webpages.
291 
292     \value MissingImageGraphic The replacement graphic shown when an image could not be loaded.
293     \value MissingPluginGraphic The replacement graphic shown when a plugin could not be loaded.
294     \value DefaultFrameIconGraphic The default icon for QWebFrame::icon().
295     \value TextAreaSizeGripCornerGraphic The graphic shown for the size grip of text areas.
296 */
297 
298 /*!
299     \enum QWebSettings::WebAttribute
300 
301     This enum describes various attributes that are configurable through QWebSettings.
302 
303     \value AutoLoadImages Specifies whether images are automatically loaded in
304         web pages.
305     \value JavascriptEnabled Enables or disables the running of JavaScript
306         programs.
307     \value JavaEnabled Enables or disables Java applets.
308         Currently Java applets are not supported.
309     \value PluginsEnabled Enables or disables plugins in Web pages.
310     \value PrivateBrowsingEnabled Private browsing prevents WebKit from
311         recording visited pages in the history and storing web page icons.
312     \value JavascriptCanOpenWindows Specifies whether JavaScript programs
313         can open new windows.
314     \value JavascriptCanAccessClipboard Specifies whether JavaScript programs
315         can read or write to the clipboard.
316     \value DeveloperExtrasEnabled Enables extra tools for Web developers.
317         Currently this enables the "Inspect" element in the context menu,
318     which shows the WebKit WebInspector for web site debugging.
319     \value LinksIncludedInFocusChain Specifies whether hyperlinks should be
320         included in the keyboard focus chain.
321     \value ZoomTextOnly Specifies whether the zoom factor on a frame applies to
322         only the text or all content.
323     \value PrintElementBackgrounds Specifies whether the background color and images
324         are also drawn when the page is printed.
325     \value OfflineStorageDatabaseEnabled Specifies whether support for the HTML 5
326         offline storage feature is enabled or not.
327     \value OfflineWebApplicationCacheEnabled Specifies whether support for the HTML 5
328         web application cache feature is enabled or not.
329     \value LocalStorageDatabaseEnabled Specifies whether support for the HTML 5
330         local storage feature is enabled or not.
331     \value LocalContentCanAccessRemoteUrls Specifies whether locally loaded documents are allowed to access remote urls.
332 */
333 
334 /*!
335     \internal
336 */
QWebSettings()337 QWebSettings::QWebSettings()
338     : d(new QWebSettingsPrivate)
339 {
340     // Initialize our global defaults
341     d->fontSizes.insert(QWebSettings::MinimumFontSize, 0);
342     d->fontSizes.insert(QWebSettings::MinimumLogicalFontSize, 0);
343     d->fontSizes.insert(QWebSettings::DefaultFontSize, 14);
344     d->fontSizes.insert(QWebSettings::DefaultFixedFontSize, 14);
345     d->fontFamilies.insert(QWebSettings::StandardFont, QLatin1String("Arial"));
346     d->fontFamilies.insert(QWebSettings::FixedFont, QLatin1String("Courier New"));
347     d->fontFamilies.insert(QWebSettings::SerifFont, QLatin1String("Times New Roman"));
348     d->fontFamilies.insert(QWebSettings::SansSerifFont, QLatin1String("Arial"));
349     d->fontFamilies.insert(QWebSettings::CursiveFont, QLatin1String("Arial"));
350     d->fontFamilies.insert(QWebSettings::FantasyFont, QLatin1String("Arial"));
351 
352     d->attributes.insert(QWebSettings::AutoLoadImages, true);
353     d->attributes.insert(QWebSettings::JavascriptEnabled, true);
354     d->attributes.insert(QWebSettings::LinksIncludedInFocusChain, true);
355     d->attributes.insert(QWebSettings::ZoomTextOnly, false);
356     d->attributes.insert(QWebSettings::PrintElementBackgrounds, true);
357     d->attributes.insert(QWebSettings::OfflineStorageDatabaseEnabled, true);
358     d->attributes.insert(QWebSettings::OfflineWebApplicationCacheEnabled, true);
359     d->attributes.insert(QWebSettings::LocalStorageDatabaseEnabled, true);
360     d->attributes.insert(QWebSettings::LocalContentCanAccessRemoteUrls, true);
361     d->offlineStorageDefaultQuota = 5 * 1024 * 1024;
362 }
363 
364 /*!
365     \internal
366 */
QWebSettings(WebCore::Settings * settings)367 QWebSettings::QWebSettings(WebCore::Settings* settings)
368     : d(new QWebSettingsPrivate(settings))
369 {
370     d->settings = settings;
371     d->apply();
372     allSettings()->append(d);
373 }
374 
375 /*!
376     \internal
377 */
~QWebSettings()378 QWebSettings::~QWebSettings()
379 {
380     if (d->settings)
381         allSettings()->removeAll(d);
382 
383     delete d;
384 }
385 
386 /*!
387     Sets the font size for \a type to \a size.
388 */
setFontSize(FontSize type,int size)389 void QWebSettings::setFontSize(FontSize type, int size)
390 {
391     d->fontSizes.insert(type, size);
392     d->apply();
393 }
394 
395 /*!
396     Returns the default font size for \a type.
397 */
fontSize(FontSize type) const398 int QWebSettings::fontSize(FontSize type) const
399 {
400     int defaultValue = 0;
401     if (d->settings) {
402         QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
403         defaultValue = global->fontSizes.value(type);
404     }
405     return d->fontSizes.value(type, defaultValue);
406 }
407 
408 /*!
409     Resets the font size for \a type to the size specified in the global
410     settings object.
411 
412     This function has no effect on the global QWebSettings instance.
413 */
resetFontSize(FontSize type)414 void QWebSettings::resetFontSize(FontSize type)
415 {
416     if (d->settings) {
417         d->fontSizes.remove(type);
418         d->apply();
419     }
420 }
421 
422 /*!
423     Specifies the location of a user stylesheet to load with every web page.
424 
425     The \a location can be a URL or a path on the local filesystem.
426 
427     \sa userStyleSheetUrl()
428 */
setUserStyleSheetUrl(const QUrl & location)429 void QWebSettings::setUserStyleSheetUrl(const QUrl& location)
430 {
431     d->userStyleSheetLocation = location;
432     d->apply();
433 }
434 
435 /*!
436     Returns the location of the user stylesheet.
437 
438     \sa setUserStyleSheetUrl()
439 */
userStyleSheetUrl() const440 QUrl QWebSettings::userStyleSheetUrl() const
441 {
442     return d->userStyleSheetLocation;
443 }
444 
445 /*!
446     \since 4.6
447     Specifies the default text encoding system.
448 
449     The \a encoding, must be a string describing an encoding such as "utf-8",
450     "iso-8859-1", etc. If left empty a default value will be used. For a more
451     extensive list of encoding names see \l{QTextCodec}
452 
453     \sa defaultTextEncoding()
454 */
setDefaultTextEncoding(const QString & encoding)455 void QWebSettings::setDefaultTextEncoding(const QString& encoding)
456 {
457     d->defaultTextEncoding = encoding;
458     d->apply();
459 }
460 
461 /*!
462     \since 4.6
463     Returns the default text encoding.
464 
465     \sa setDefaultTextEncoding()
466 */
defaultTextEncoding() const467 QString QWebSettings::defaultTextEncoding() const
468 {
469     return d->defaultTextEncoding;
470 }
471 
472 /*!
473     Sets the path of the icon database to \a path. The icon database is used
474     to store "favicons" associated with web sites.
475 
476     \a path must point to an existing directory where the icons are stored.
477 
478     Setting an empty path disables the icon database.
479 */
setIconDatabasePath(const QString & path)480 void QWebSettings::setIconDatabasePath(const QString& path)
481 {
482     WebCore::iconDatabase()->delayDatabaseCleanup();
483 
484     if (!path.isEmpty()) {
485         WebCore::iconDatabase()->setEnabled(true);
486         QFileInfo info(path);
487         if (info.isDir() && info.isWritable())
488             WebCore::iconDatabase()->open(path);
489     } else {
490         WebCore::iconDatabase()->setEnabled(false);
491         WebCore::iconDatabase()->close();
492     }
493 }
494 
495 /*!
496     Returns the path of the icon database or an empty string if the icon
497     database is disabled.
498 
499     \sa setIconDatabasePath(), clearIconDatabase()
500 */
iconDatabasePath()501 QString QWebSettings::iconDatabasePath()
502 {
503     if (WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen())
504         return WebCore::iconDatabase()->databasePath();
505     else
506         return QString();
507 }
508 
509 /*!
510     Clears the icon database.
511 */
clearIconDatabase()512 void QWebSettings::clearIconDatabase()
513 {
514     if (WebCore::iconDatabase()->isEnabled() && WebCore::iconDatabase()->isOpen())
515         WebCore::iconDatabase()->removeAllIcons();
516 }
517 
518 /*!
519     Returns the web site's icon for \a url.
520 
521     If the web site does not specify an icon, or the icon is not in the
522     database, a null QIcon is returned.
523 
524     \note The returned icon's size is arbitrary.
525 
526     \sa setIconDatabasePath()
527 */
iconForUrl(const QUrl & url)528 QIcon QWebSettings::iconForUrl(const QUrl& url)
529 {
530     WebCore::Image* image = WebCore::iconDatabase()->iconForPageURL(WebCore::KURL(url).string(),
531                                 WebCore::IntSize(16, 16));
532     if (!image)
533         return QPixmap();
534 
535     QPixmap* icon = image->nativeImageForCurrentFrame();
536     if (!icon)
537         return QPixmap();
538 
539     return* icon;
540 }
541 
542 /*!
543     Returns the plugin database object.
544 */
pluginDatabase()545 QWebPluginDatabase *QWebSettings::pluginDatabase()
546 {
547     static QWebPluginDatabase* database = 0;
548     if (!database)
549         database = new QWebPluginDatabase();
550     return database;
551 }
552 
553 /*!
554     Sets \a graphic to be drawn when QtWebKit needs to draw an image of the
555     given \a type.
556 
557     For example, when an image cannot be loaded the pixmap specified by
558     \l{QWebSettings::WebGraphic}{MissingImageGraphic} is drawn instead.
559 
560     \sa webGraphic()
561 */
setWebGraphic(WebGraphic type,const QPixmap & graphic)562 void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap& graphic)
563 {
564     WebGraphicHash* h = graphics();
565     if (graphic.isNull())
566         h->remove(type);
567     else
568         h->insert(type, graphic);
569 }
570 
571 /*!
572     Returns a previously set pixmap used to draw replacement graphics of the
573     specified \a type.
574 
575     For example, when an image cannot be loaded the pixmap specified by
576     \l{QWebSettings::WebGraphic}{MissingImageGraphic} is drawn instead.
577 
578     \sa setWebGraphic()
579 */
webGraphic(WebGraphic type)580 QPixmap QWebSettings::webGraphic(WebGraphic type)
581 {
582     return graphics()->value(type);
583 }
584 
585 /*!
586     Frees up as much memory as possible by cleaning all memory caches such
587     as page, object and font cache.
588 
589     \since 4.6
590  */
clearMemoryCaches()591 void QWebSettings::clearMemoryCaches()
592 {
593     // Turn the cache on and off.  Disabling the object cache will remove all
594     // resources from the cache.  They may still live on if they are referenced
595     // by some Web page though.
596     if (!WebCore::cache()->disabled()) {
597         WebCore::cache()->setDisabled(true);
598         WebCore::cache()->setDisabled(false);
599     }
600 
601     int pageCapacity = WebCore::pageCache()->capacity();
602     // Setting size to 0, makes all pages be released.
603     WebCore::pageCache()->setCapacity(0);
604     WebCore::pageCache()->releaseAutoreleasedPagesNow();
605     WebCore::pageCache()->setCapacity(pageCapacity);
606 
607     // Invalidating the font cache and freeing all inactive font data.
608     WebCore::fontCache()->invalidate();
609 
610 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
611     // Empty the application cache.
612     WebCore::cacheStorage().empty();
613 #endif
614 
615     // Empty the Cross-Origin Preflight cache
616     WebCore::CrossOriginPreflightResultCache::shared().empty();
617 }
618 
619 /*!
620     Sets the maximum number of pages to hold in the memory cache to \a pages.
621 */
setMaximumPagesInCache(int pages)622 void QWebSettings::setMaximumPagesInCache(int pages)
623 {
624     WebCore::pageCache()->setCapacity(qMax(0, pages));
625 }
626 
627 /*!
628     Returns the maximum number of web pages that are kept in the memory cache.
629 */
maximumPagesInCache()630 int QWebSettings::maximumPagesInCache()
631 {
632     return WebCore::pageCache()->capacity();
633 }
634 
635 /*!
636    Specifies the capacities for the memory cache for dead objects such as
637    stylesheets or scripts.
638 
639    The \a cacheMinDeadCapacity specifies the \e minimum number of bytes that
640    dead objects should consume when the cache is under pressure.
641 
642    \a cacheMaxDead is the \e maximum number of bytes that dead objects should
643    consume when the cache is \bold not under pressure.
644 
645    \a totalCapacity specifies the \e maximum number of bytes that the cache
646    should consume \bold overall.
647 
648    The cache is enabled by default. Calling setObjectCacheCapacities(0, 0, 0)
649    will disable the cache. Calling it with one non-zero enables it again.
650 */
setObjectCacheCapacities(int cacheMinDeadCapacity,int cacheMaxDead,int totalCapacity)651 void QWebSettings::setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)
652 {
653     bool disableCache = !cacheMinDeadCapacity && !cacheMaxDead && !totalCapacity;
654     WebCore::cache()->setDisabled(disableCache);
655 
656     WebCore::cache()->setCapacities(qMax(0, cacheMinDeadCapacity),
657                                     qMax(0, cacheMaxDead),
658                                     qMax(0, totalCapacity));
659 }
660 
661 /*!
662     Sets the actual font family to \a family for the specified generic family,
663     \a which.
664 */
setFontFamily(FontFamily which,const QString & family)665 void QWebSettings::setFontFamily(FontFamily which, const QString& family)
666 {
667     d->fontFamilies.insert(which, family);
668     d->apply();
669 }
670 
671 /*!
672     Returns the actual font family for the specified generic font family,
673     \a which.
674 */
fontFamily(FontFamily which) const675 QString QWebSettings::fontFamily(FontFamily which) const
676 {
677     QString defaultValue;
678     if (d->settings) {
679         QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
680         defaultValue = global->fontFamilies.value(which);
681     }
682     return d->fontFamilies.value(which, defaultValue);
683 }
684 
685 /*!
686     Resets the actual font family to the default font family, specified by
687     \a which.
688 
689     This function has no effect on the global QWebSettings instance.
690 */
resetFontFamily(FontFamily which)691 void QWebSettings::resetFontFamily(FontFamily which)
692 {
693     if (d->settings) {
694         d->fontFamilies.remove(which);
695         d->apply();
696     }
697 }
698 
699 /*!
700     \fn void QWebSettings::setAttribute(WebAttribute attribute, bool on)
701 
702     Enables or disables the specified \a attribute feature depending on the
703     value of \a on.
704 */
setAttribute(WebAttribute attr,bool on)705 void QWebSettings::setAttribute(WebAttribute attr, bool on)
706 {
707     d->attributes.insert(attr, on);
708     d->apply();
709 }
710 
711 /*!
712     \fn bool QWebSettings::testAttribute(WebAttribute attribute) const
713 
714     Returns true if \a attribute is enabled; otherwise returns false.
715 */
testAttribute(WebAttribute attr) const716 bool QWebSettings::testAttribute(WebAttribute attr) const
717 {
718     bool defaultValue = false;
719     if (d->settings) {
720         QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
721         defaultValue = global->attributes.value(attr);
722     }
723     return d->attributes.value(attr, defaultValue);
724 }
725 
726 /*!
727     \fn void QWebSettings::resetAttribute(WebAttribute attribute)
728 
729     Resets the setting of \a attribute.
730     This function has no effect on the global QWebSettings instance.
731 
732     \sa globalSettings()
733 */
resetAttribute(WebAttribute attr)734 void QWebSettings::resetAttribute(WebAttribute attr)
735 {
736     if (d->settings) {
737         d->attributes.remove(attr);
738         d->apply();
739     }
740 }
741 
742 /*!
743     \since 4.5
744 
745     Sets the path for HTML5 offline storage to \a path.
746 
747     \a path must point to an existing directory where the databases are stored.
748 
749     Setting an empty path disables the feature.
750 
751     \sa offlineStoragePath()
752 */
setOfflineStoragePath(const QString & path)753 void QWebSettings::setOfflineStoragePath(const QString& path)
754 {
755 #if ENABLE(DATABASE)
756     WebCore::DatabaseTracker::tracker().setDatabaseDirectoryPath(path);
757 #endif
758 }
759 
760 /*!
761     \since 4.5
762 
763     Returns the path of the HTML5 offline storage or an empty string if the
764     feature is disabled.
765 
766     \sa setOfflineStoragePath()
767 */
offlineStoragePath()768 QString QWebSettings::offlineStoragePath()
769 {
770 #if ENABLE(DATABASE)
771     return WebCore::DatabaseTracker::tracker().databaseDirectoryPath();
772 #else
773     return QString();
774 #endif
775 }
776 
777 /*!
778     \since 4.5
779 
780     Sets the value of the default quota for new offline storage databases
781     to \a maximumSize.
782 */
setOfflineStorageDefaultQuota(qint64 maximumSize)783 void QWebSettings::setOfflineStorageDefaultQuota(qint64 maximumSize)
784 {
785     QWebSettings::globalSettings()->d->offlineStorageDefaultQuota = maximumSize;
786 }
787 
788 /*!
789     \since 4.5
790 
791     Returns the value of the default quota for new offline storage databases.
792 */
offlineStorageDefaultQuota()793 qint64 QWebSettings::offlineStorageDefaultQuota()
794 {
795     return QWebSettings::globalSettings()->d->offlineStorageDefaultQuota;
796 }
797 
798 /*!
799     \since 4.6
800     \relates QWebSettings
801 
802     Sets the path for HTML5 offline web application cache storage to \a path.
803 
804     An application cache acts like an HTTP cache in some sense. For documents
805     that use the application cache via JavaScript, the loader mechinery will
806     first ask the application cache for the contents, before hitting the
807     network.
808 
809     The feature is described in details at:
810     http://dev.w3.org/html5/spec/Overview.html#appcache
811 
812     \a path must point to an existing directory where the cache is stored.
813 
814     Setting an empty path disables the feature.
815 
816     \sa offlineWebApplicationCachePath()
817 */
setOfflineWebApplicationCachePath(const QString & path)818 void QWebSettings::setOfflineWebApplicationCachePath(const QString& path)
819 {
820 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
821     WebCore::cacheStorage().setCacheDirectory(path);
822 #endif
823 }
824 
825 /*!
826     \since 4.6
827     \relates QWebSettings
828 
829     Returns the path of the HTML5 offline web application cache storage
830     or an empty string if the feature is disabled.
831 
832     \sa setOfflineWebApplicationCachePath()
833 */
offlineWebApplicationCachePath()834 QString QWebSettings::offlineWebApplicationCachePath()
835 {
836 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
837     return WebCore::cacheStorage().cacheDirectory();
838 #else
839     return QString();
840 #endif
841 }
842 
843 /*!
844     \since 4.6
845 
846     Sets the value of the quota for the offline web application cache
847     to \a maximumSize.
848 */
setOfflineWebApplicationCacheQuota(qint64 maximumSize)849 void QWebSettings::setOfflineWebApplicationCacheQuota(qint64 maximumSize)
850 {
851 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
852     WebCore::cacheStorage().setMaximumSize(maximumSize);
853 #endif
854 }
855 
856 /*!
857     \since 4.6
858 
859     Returns the value of the quota for the offline web application cache.
860 */
offlineWebApplicationCacheQuota()861 qint64 QWebSettings::offlineWebApplicationCacheQuota()
862 {
863 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
864     return WebCore::cacheStorage().maximumSize();
865 #else
866     return 0;
867 #endif
868 }
869 
870 /*
871     \since 4.5
872     \relates QWebSettings
873 
874     Sets the path for HTML5 local storage databases to \a path.
875 
876     \a path must point to an existing directory where the cache is stored.
877 
878     Setting an empty path disables the feature.
879 
880     \sa localStorageDatabasePath()
881 */
qt_websettings_setLocalStorageDatabasePath(QWebSettings * settings,const QString & path)882 void QWEBKIT_EXPORT qt_websettings_setLocalStorageDatabasePath(QWebSettings* settings, const QString& path)
883 {
884     QWebSettingsPrivate* d = settings->handle();
885     d->localStorageDatabasePath = path;
886     d->apply();
887 }
888 
889 /*
890     \since 4.5
891     \relates QWebSettings
892 
893     Returns the path for HTML5 local storage databases
894     or an empty string if the feature is disabled.
895 
896     \sa setLocalStorageDatabasePath()
897 */
qt_websettings_localStorageDatabasePath(QWebSettings * settings)898 QString QWEBKIT_EXPORT qt_websettings_localStorageDatabasePath(QWebSettings* settings)
899 {
900     return settings->handle()->localStorageDatabasePath;
901 }
902 
903 /*!
904     \fn QWebSettingsPrivate* QWebSettings::handle() const
905     \internal
906 */
907