2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
21 #include "qwebsettings.h"
24 #include "qwebpage_p.h"
25 #include "qwebplugindatabase_p.h"
27 #include "AbstractDatabase.h"
28 #include "MemoryCache.h"
29 #include "CrossOriginPreflightResultCache.h"
30 #include "FontCache.h"
31 #if ENABLE(ICONDATABASE)
32 #include "IconDatabaseClientQt.h"
35 #include "PageCache.h"
38 #include "PlatformString.h"
39 #include "IconDatabase.h"
40 #include "PluginDatabase.h"
43 #include "ApplicationCacheStorage.h"
44 #include "DatabaseTracker.h"
45 #include "FileSystem.h"
47 #include <QApplication>
48 #include <QDesktopServices>
51 #include <QSharedData>
56 #include "NetworkStateNotifier.h"
58 void QWEBKIT_EXPORT qt_networkAccessAllowed(bool isAllowed)
60 #ifndef QT_NO_BEARERMANAGEMENT
61 WebCore::networkStateNotifier().setNetworkAccessAllowed(isAllowed);
65 class QWebSettingsPrivate {
67 QWebSettingsPrivate(WebCore::Settings* wcSettings = 0)
68 : settings(wcSettings)
72 QHash<int, QString> fontFamilies;
73 QHash<int, int> fontSizes;
74 QHash<int, bool> attributes;
75 QUrl userStyleSheetLocation;
76 QString defaultTextEncoding;
77 QString localStoragePath;
78 QString offlineWebApplicationCachePath;
79 qint64 offlineStorageDefaultQuota;
80 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
81 QWebSettings::ThirdPartyCookiePolicy thirdPartyCookiePolicy;
84 WebCore::Settings* settings;
87 typedef QHash<int, QPixmap> WebGraphicHash;
88 Q_GLOBAL_STATIC(WebGraphicHash, _graphics)
90 static void earlyClearGraphics()
95 static WebGraphicHash* graphics()
97 WebGraphicHash* hash = _graphics();
99 if (hash->isEmpty()) {
101 // prevent ~QPixmap running after ~QApplication (leaks native pixmaps)
102 qAddPostRoutine(earlyClearGraphics);
104 hash->insert(QWebSettings::MissingImageGraphic, QPixmap(QLatin1String(":webkit/resources/missingImage.png")));
105 hash->insert(QWebSettings::MissingPluginGraphic, QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));
106 hash->insert(QWebSettings::DefaultFrameIconGraphic, QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));
107 hash->insert(QWebSettings::TextAreaSizeGripCornerGraphic, QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
108 hash->insert(QWebSettings::DeleteButtonGraphic, QPixmap(QLatin1String(":webkit/resources/deleteButton.png")));
109 hash->insert(QWebSettings::InputSpeechButtonGraphic, QPixmap(QLatin1String(":webkit/resources/inputSpeech.png")));
110 hash->insert(QWebSettings::SearchCancelButtonGraphic, QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
111 hash->insert(QWebSettings::SearchCancelButtonPressedGraphic, QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
117 Q_GLOBAL_STATIC(QList<QWebSettingsPrivate*>, allSettings);
119 void QWebSettingsPrivate::apply()
122 settings->setTextAreasAreResizable(true);
124 QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
126 QString family = fontFamilies.value(QWebSettings::StandardFont,
127 global->fontFamilies.value(QWebSettings::StandardFont));
128 settings->setStandardFontFamily(family);
130 family = fontFamilies.value(QWebSettings::FixedFont,
131 global->fontFamilies.value(QWebSettings::FixedFont));
132 settings->setFixedFontFamily(family);
134 family = fontFamilies.value(QWebSettings::SerifFont,
135 global->fontFamilies.value(QWebSettings::SerifFont));
136 settings->setSerifFontFamily(family);
138 family = fontFamilies.value(QWebSettings::SansSerifFont,
139 global->fontFamilies.value(QWebSettings::SansSerifFont));
140 settings->setSansSerifFontFamily(family);
142 family = fontFamilies.value(QWebSettings::CursiveFont,
143 global->fontFamilies.value(QWebSettings::CursiveFont));
144 settings->setCursiveFontFamily(family);
146 family = fontFamilies.value(QWebSettings::FantasyFont,
147 global->fontFamilies.value(QWebSettings::FantasyFont));
148 settings->setFantasyFontFamily(family);
150 int size = fontSizes.value(QWebSettings::MinimumFontSize,
151 global->fontSizes.value(QWebSettings::MinimumFontSize));
152 settings->setMinimumFontSize(size);
154 size = fontSizes.value(QWebSettings::MinimumLogicalFontSize,
155 global->fontSizes.value(QWebSettings::MinimumLogicalFontSize));
156 settings->setMinimumLogicalFontSize(size);
158 size = fontSizes.value(QWebSettings::DefaultFontSize,
159 global->fontSizes.value(QWebSettings::DefaultFontSize));
160 settings->setDefaultFontSize(size);
162 size = fontSizes.value(QWebSettings::DefaultFixedFontSize,
163 global->fontSizes.value(QWebSettings::DefaultFixedFontSize));
164 settings->setDefaultFixedFontSize(size);
166 bool value = attributes.value(QWebSettings::AutoLoadImages,
167 global->attributes.value(QWebSettings::AutoLoadImages));
168 settings->setLoadsImagesAutomatically(value);
170 value = attributes.value(QWebSettings::JavascriptEnabled,
171 global->attributes.value(QWebSettings::JavascriptEnabled));
172 settings->setJavaScriptEnabled(value);
173 #if USE(ACCELERATED_COMPOSITING)
174 value = attributes.value(QWebSettings::AcceleratedCompositingEnabled,
175 global->attributes.value(QWebSettings::AcceleratedCompositingEnabled));
177 settings->setAcceleratedCompositingEnabled(value);
178 settings->setAcceleratedCompositingFor3DTransformsEnabled(value);
179 settings->setAcceleratedCompositingForAnimationEnabled(value);
180 #if USE(TEXTURE_MAPPER)
181 settings->setAcceleratedCompositingForVideoEnabled(false);
182 settings->setAcceleratedCompositingForPluginsEnabled(false);
186 value = attributes.value(QWebSettings::WebGLEnabled,
187 global->attributes.value(QWebSettings::WebGLEnabled));
189 settings->setWebGLEnabled(value);
190 #if USE(ACCELERATED_COMPOSITING)
191 settings->setAcceleratedCompositingForCanvasEnabled(value);
195 value = attributes.value(QWebSettings::HyperlinkAuditingEnabled,
196 global->attributes.value(QWebSettings::HyperlinkAuditingEnabled));
198 settings->setHyperlinkAuditingEnabled(value);
200 value = attributes.value(QWebSettings::JavascriptCanOpenWindows,
201 global->attributes.value(QWebSettings::JavascriptCanOpenWindows));
202 settings->setJavaScriptCanOpenWindowsAutomatically(value);
204 value = attributes.value(QWebSettings::JavascriptCanCloseWindows,
205 global->attributes.value(QWebSettings::JavascriptCanCloseWindows));
206 settings->setAllowScriptsToCloseWindows(value);
208 value = attributes.value(QWebSettings::JavaEnabled,
209 global->attributes.value(QWebSettings::JavaEnabled));
210 settings->setJavaEnabled(value);
212 value = attributes.value(QWebSettings::PluginsEnabled,
213 global->attributes.value(QWebSettings::PluginsEnabled));
214 settings->setPluginsEnabled(value);
216 value = attributes.value(QWebSettings::PrivateBrowsingEnabled,
217 global->attributes.value(QWebSettings::PrivateBrowsingEnabled));
218 settings->setPrivateBrowsingEnabled(value);
220 value = attributes.value(QWebSettings::SpatialNavigationEnabled,
221 global->attributes.value(QWebSettings::SpatialNavigationEnabled));
222 settings->setSpatialNavigationEnabled(value);
224 value = attributes.value(QWebSettings::JavascriptCanAccessClipboard,
225 global->attributes.value(QWebSettings::JavascriptCanAccessClipboard));
226 settings->setDOMPasteAllowed(value);
227 settings->setJavaScriptCanAccessClipboard(value);
229 value = attributes.value(QWebSettings::DeveloperExtrasEnabled,
230 global->attributes.value(QWebSettings::DeveloperExtrasEnabled));
231 settings->setDeveloperExtrasEnabled(value);
233 value = attributes.value(QWebSettings::FrameFlatteningEnabled,
234 global->attributes.value(QWebSettings::FrameFlatteningEnabled));
235 settings->setFrameFlatteningEnabled(value);
237 QUrl location = !userStyleSheetLocation.isEmpty() ? userStyleSheetLocation : global->userStyleSheetLocation;
238 settings->setUserStyleSheetLocation(WebCore::KURL(location));
240 QString encoding = !defaultTextEncoding.isEmpty() ? defaultTextEncoding: global->defaultTextEncoding;
241 settings->setDefaultTextEncodingName(encoding);
243 QString storagePath = !localStoragePath.isEmpty() ? localStoragePath : global->localStoragePath;
244 settings->setLocalStorageDatabasePath(storagePath);
246 value = attributes.value(QWebSettings::PrintElementBackgrounds,
247 global->attributes.value(QWebSettings::PrintElementBackgrounds));
248 settings->setShouldPrintBackgrounds(value);
251 value = attributes.value(QWebSettings::OfflineStorageDatabaseEnabled,
252 global->attributes.value(QWebSettings::OfflineStorageDatabaseEnabled));
253 WebCore::AbstractDatabase::setIsAvailable(value);
256 value = attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled,
257 global->attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled));
258 settings->setOfflineWebApplicationCacheEnabled(value);
260 value = attributes.value(QWebSettings::LocalStorageEnabled,
261 global->attributes.value(QWebSettings::LocalStorageEnabled));
262 settings->setLocalStorageEnabled(value);
264 value = attributes.value(QWebSettings::LocalContentCanAccessRemoteUrls,
265 global->attributes.value(QWebSettings::LocalContentCanAccessRemoteUrls));
266 settings->setAllowUniversalAccessFromFileURLs(value);
268 value = attributes.value(QWebSettings::LocalContentCanAccessFileUrls,
269 global->attributes.value(QWebSettings::LocalContentCanAccessFileUrls));
270 settings->setAllowFileAccessFromFileURLs(value);
272 value = attributes.value(QWebSettings::XSSAuditingEnabled,
273 global->attributes.value(QWebSettings::XSSAuditingEnabled));
274 settings->setXSSAuditorEnabled(value);
276 #if ENABLE(TILED_BACKING_STORE)
277 value = attributes.value(QWebSettings::TiledBackingStoreEnabled,
278 global->attributes.value(QWebSettings::TiledBackingStoreEnabled));
279 settings->setTiledBackingStoreEnabled(value);
282 value = attributes.value(QWebSettings::SiteSpecificQuirksEnabled,
283 global->attributes.value(QWebSettings::SiteSpecificQuirksEnabled));
284 settings->setNeedsSiteSpecificQuirks(value);
286 settings->setUsesPageCache(WebCore::pageCache()->capacity());
288 #if ENABLE(PASSWORD_ECHO)
289 settings->setPasswordEchoEnabled(true);
290 settings->setPasswordEchoDurationInSeconds(1);
293 QList<QWebSettingsPrivate*> settings = *::allSettings();
294 for (int i = 0; i < settings.count(); ++i)
295 settings[i]->apply();
300 Returns the global settings object.
302 Any setting changed on the default object is automatically applied to all
303 QWebPage instances where the particular setting is not overriden already.
305 QWebSettings* QWebSettings::globalSettings()
307 static QWebSettings* global = 0;
309 global = new QWebSettings;
316 \brief The QWebSettings class provides an object to store the settings used
317 by QWebPage and QWebFrame.
321 Each QWebPage object has its own QWebSettings object, which configures the
322 settings for that page. If a setting is not configured, then it is looked
323 up in the global settings object, which can be accessed using
326 QWebSettings allows configuration of browser properties, such as font sizes and
327 families, the location of a custom style sheet, and generic attributes like
328 JavaScript and plugins. Individual attributes are set using the setAttribute()
329 function. The \l{QWebSettings::WebAttribute}{WebAttribute} enum further describes
332 QWebSettings also configures global properties such as the web page memory
333 cache, icon database, local database storage and offline
334 applications storage.
336 \section1 Enabling Plugins
338 Support for browser plugins can enabled by setting the
339 \l{QWebSettings::PluginsEnabled}{PluginsEnabled} attribute. For many applications,
340 this attribute is enabled for all pages by setting it on the
341 \l{globalSettings()}{global settings object}. QtWebKit will always ignore this setting
342 when processing Qt plugins. The decision to allow a Qt plugin is made by the client
343 in its reimplementation of QWebPage::createPlugin().
345 \section1 Web Application Support
347 WebKit provides support for features specified in \l{HTML 5} that improve the
348 performance and capabilities of Web applications. These include client-side
349 (offline) storage and the use of a Web application cache.
351 Client-side (offline) storage is an improvement over the use of cookies to
352 store persistent data in Web applications. Applications can configure and
353 enable the use of an offline storage database by calling the
354 setOfflineStoragePath() with an appropriate file path, and can limit the quota
355 for each application by calling setOfflineStorageDefaultQuota().
357 \sa QWebPage::settings(), QWebView::settings(), {Web Browser}
361 \enum QWebSettings::FontFamily
363 This enum describes the generic font families defined by CSS 2.
364 For more information see the
365 \l{http://www.w3.org/TR/REC-CSS2/fonts.html#generic-font-families}{CSS standard}.
376 \enum QWebSettings::FontSize
378 This enum describes the font sizes configurable through QWebSettings.
380 \value MinimumFontSize The hard minimum font size.
381 \value MinimumLogicalFontSize The minimum logical font size that is applied
382 when zooming out with QWebFrame::setTextSizeMultiplier().
383 \value DefaultFontSize The default font size for regular text.
384 \value DefaultFixedFontSize The default font size for fixed-pitch text.
387 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
389 \enum QWebSettings::ThirdPartyCookiePolicy
391 This enum describes the policies configurable for accepting and sending
392 third-party cookies. These are cookies that are set or retrieved when fetching
393 a resource that is stored for a different registry-controlled domain from the page containing it.
395 \value AlwaysAllowThirdPartyCookies Allow third-party resources to set and retrieve cookies.
396 \value AlwaysBlockThirdPartyCookies Never allow third-party resources to set and retrieve cookies.
397 \value AllowThirdPartyWithExistingCookies If the cookie jar already contains cookies
398 from a third-party, allow it to set and retrieve new and existing cookies.
405 \enum QWebSettings::WebGraphic
407 This enums describes the standard graphical elements used in webpages.
409 \value MissingImageGraphic The replacement graphic shown when an image could not be loaded.
410 \value MissingPluginGraphic The replacement graphic shown when a plugin could not be loaded.
411 \value DefaultFrameIconGraphic The default icon for QWebFrame::icon().
412 \value TextAreaSizeGripCornerGraphic The graphic shown for the size grip of text areas.
413 \value DeleteButtonGraphic The graphic shown for the WebKit-Editing-Delete-Button in Deletion UI.
414 \value InputSpeechButtonGraphic The graphic shown in input fields that support speech recognition.
415 \value SearchCancelButtonGraphic The graphic shown for clearing the text in a search field.
416 \value SearchCancelButtonPressedGraphic The graphic shown when SearchCancelButtonGraphic is pressed.
420 \enum QWebSettings::WebAttribute
422 This enum describes various attributes that are configurable through QWebSettings.
424 \value AutoLoadImages Specifies whether images are automatically loaded in
425 web pages. This is enabled by default.
426 \value DnsPrefetchEnabled Specifies whether QtWebkit will try to pre-fetch DNS entries to
427 speed up browsing. This only works as a global attribute. Only for Qt 4.6 and later. This is disabled by default.
428 \value JavascriptEnabled Enables or disables the running of JavaScript
429 programs. This is enabled by default
430 \value JavaEnabled Enables or disables Java applets.
431 Currently Java applets are not supported.
432 \value PluginsEnabled Enables or disables plugins in Web pages (e.g. using NPAPI). Qt plugins
433 with a mimetype such as "application/x-qt-plugin" are not affected by this setting. This is disabled by default.
434 \value PrivateBrowsingEnabled Private browsing prevents WebKit from
435 recording visited pages in the history and storing web page icons. This is disabled by default.
436 \value JavascriptCanOpenWindows Specifies whether JavaScript programs
437 can open new windows. This is disabled by default.
438 \value JavascriptCanCloseWindows Specifies whether JavaScript programs
439 can close windows. This is disabled by default.
440 \value JavascriptCanAccessClipboard Specifies whether JavaScript programs
441 can read or write to the clipboard. This is disabled by default.
442 \value DeveloperExtrasEnabled Enables extra tools for Web developers.
443 Currently this enables the "Inspect" element in the context menu as
444 well as the use of QWebInspector which controls the web inspector
445 for web site debugging. This is disabled by default.
446 \value SpatialNavigationEnabled Enables or disables the Spatial Navigation
447 feature, which consists in the ability to navigate between focusable
448 elements in a Web page, such as hyperlinks and form controls, by using
449 Left, Right, Up and Down arrow keys. For example, if a user presses the
450 Right key, heuristics determine whether there is an element he might be
451 trying to reach towards the right and which element he probably wants.
452 This is disabled by default.
453 \value LinksIncludedInFocusChain Specifies whether hyperlinks should be
454 included in the keyboard focus chain. This is enabled by default.
455 \value ZoomTextOnly Specifies whether the zoom factor on a frame applies
456 only to the text or to all content. This is disabled by default.
457 \value PrintElementBackgrounds Specifies whether the background color and images
458 are also drawn when the page is printed. This is enabled by default.
459 \value OfflineStorageDatabaseEnabled Specifies whether support for the HTML 5
460 offline storage feature is enabled or not. This is disabled by default.
461 \value OfflineWebApplicationCacheEnabled Specifies whether support for the HTML 5
462 web application cache feature is enabled or not. This is disabled by default.
463 \value LocalStorageEnabled Specifies whether support for the HTML 5
464 local storage feature is enabled or not. This is disabled by default.
465 \value LocalStorageDatabaseEnabled \e{This enum value is deprecated.} Use
466 QWebSettings::LocalStorageEnabled instead.
467 \value LocalContentCanAccessRemoteUrls Specifies whether locally loaded documents are
468 allowed to access remote urls. This is disabled by default. For more information
469 about security origins and local vs. remote content see QWebSecurityOrigin.
470 \value LocalContentCanAccessFileUrls Specifies whether locally loaded documents are
471 allowed to access other local urls. This is enabled by default. For more information
472 about security origins and local vs. remote content see QWebSecurityOrigin.
473 \value XSSAuditingEnabled Specifies whether load requests should be monitored for cross-site
474 scripting attempts. Suspicious scripts will be blocked and reported in the inspector's
475 JavaScript console. Enabling this feature might have an impact on performance
476 and it is disabled by default.
477 \value AcceleratedCompositingEnabled This feature, when used in conjunction with
478 QGraphicsWebView, accelerates animations of web content. CSS animations of the transform and
479 opacity properties will be rendered by composing the cached content of the animated elements.
480 This is enabled by default.
481 \value TiledBackingStoreEnabled This setting enables the tiled backing store feature
482 for a QGraphicsWebView. With the tiled backing store enabled, the web page contents in and around
483 the current visible area is speculatively cached to bitmap tiles. The tiles are automatically kept
484 in sync with the web page as it changes. Enabling tiling can significantly speed up painting heavy
485 operations like scrolling. Enabling the feature increases memory consumption. It does not work well
486 with contents using CSS fixed positioning (see also \l{QGraphicsWebView::}{resizesToContents} property).
487 \l{QGraphicsWebView::}{tiledBackingStoreFrozen} property allows application to temporarily
488 freeze the contents of the backing store. This is disabled by default.
489 \value FrameFlatteningEnabled With this setting each subframe is expanded to its contents.
490 On touch devices, it is desired to not have any scrollable sub parts of the page
491 as it results in a confusing user experience, with scrolling sometimes scrolling sub parts
492 and at other times scrolling the page itself. For this reason iframes and framesets are
493 barely usable on touch devices. This will flatten all the frames to become one scrollable page.
494 This is disabled by default.
495 \value SiteSpecificQuirksEnabled This setting enables WebKit's workaround for broken sites. It is
502 QWebSettings::QWebSettings()
503 : d(new QWebSettingsPrivate)
505 // Initialize our global defaults
506 d->fontSizes.insert(QWebSettings::MinimumFontSize, 0);
507 d->fontSizes.insert(QWebSettings::MinimumLogicalFontSize, 0);
508 d->fontSizes.insert(QWebSettings::DefaultFontSize, 16);
509 d->fontSizes.insert(QWebSettings::DefaultFixedFontSize, 13);
512 defaultFont.setStyleHint(QFont::Serif);
513 d->fontFamilies.insert(QWebSettings::StandardFont, defaultFont.defaultFamily());
514 d->fontFamilies.insert(QWebSettings::SerifFont, defaultFont.defaultFamily());
516 defaultFont.setStyleHint(QFont::Fantasy);
517 d->fontFamilies.insert(QWebSettings::FantasyFont, defaultFont.defaultFamily());
519 defaultFont.setStyleHint(QFont::Cursive);
520 d->fontFamilies.insert(QWebSettings::CursiveFont, defaultFont.defaultFamily());
522 defaultFont.setStyleHint(QFont::SansSerif);
523 d->fontFamilies.insert(QWebSettings::SansSerifFont, defaultFont.defaultFamily());
525 defaultFont.setStyleHint(QFont::Monospace);
526 d->fontFamilies.insert(QWebSettings::FixedFont, defaultFont.defaultFamily());
528 d->attributes.insert(QWebSettings::AutoLoadImages, true);
529 d->attributes.insert(QWebSettings::DnsPrefetchEnabled, false);
530 d->attributes.insert(QWebSettings::JavascriptEnabled, true);
531 d->attributes.insert(QWebSettings::SpatialNavigationEnabled, false);
532 d->attributes.insert(QWebSettings::LinksIncludedInFocusChain, true);
533 d->attributes.insert(QWebSettings::ZoomTextOnly, false);
534 d->attributes.insert(QWebSettings::PrintElementBackgrounds, true);
535 d->attributes.insert(QWebSettings::OfflineStorageDatabaseEnabled, false);
536 d->attributes.insert(QWebSettings::OfflineWebApplicationCacheEnabled, false);
537 d->attributes.insert(QWebSettings::LocalStorageEnabled, false);
538 d->attributes.insert(QWebSettings::LocalContentCanAccessRemoteUrls, false);
539 d->attributes.insert(QWebSettings::LocalContentCanAccessFileUrls, true);
540 d->attributes.insert(QWebSettings::AcceleratedCompositingEnabled, true);
541 d->attributes.insert(QWebSettings::WebGLEnabled, false);
542 d->attributes.insert(QWebSettings::HyperlinkAuditingEnabled, false);
543 d->attributes.insert(QWebSettings::TiledBackingStoreEnabled, false);
544 d->attributes.insert(QWebSettings::FrameFlatteningEnabled, false);
545 d->attributes.insert(QWebSettings::SiteSpecificQuirksEnabled, true);
546 d->offlineStorageDefaultQuota = 5 * 1024 * 1024;
547 d->defaultTextEncoding = QLatin1String("iso-8859-1");
548 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
549 d->thirdPartyCookiePolicy = AlwaysAllowThirdPartyCookies;
556 QWebSettings::QWebSettings(WebCore::Settings* settings)
557 : d(new QWebSettingsPrivate(settings))
559 d->settings = settings;
561 allSettings()->append(d);
567 QWebSettings::~QWebSettings()
570 allSettings()->removeAll(d);
576 Sets the font size for \a type to \a size.
578 void QWebSettings::setFontSize(FontSize type, int size)
580 d->fontSizes.insert(type, size);
585 Returns the default font size for \a type.
587 int QWebSettings::fontSize(FontSize type) const
589 int defaultValue = 0;
591 QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
592 defaultValue = global->fontSizes.value(type);
594 return d->fontSizes.value(type, defaultValue);
598 Resets the font size for \a type to the size specified in the global
601 This function has no effect on the global QWebSettings instance.
603 void QWebSettings::resetFontSize(FontSize type)
606 d->fontSizes.remove(type);
612 Specifies the location of a user stylesheet to load with every web page.
614 The \a location must be either a path on the local filesystem, or a data URL
615 with UTF-8 and Base64 encoded data, such as:
617 "data:text/css;charset=utf-8;base64,cCB7IGJhY2tncm91bmQtY29sb3I6IHJlZCB9Ow=="
619 \note If the base64 data is not valid, the style will not be applied.
621 \sa userStyleSheetUrl()
623 void QWebSettings::setUserStyleSheetUrl(const QUrl& location)
625 d->userStyleSheetLocation = location;
630 Returns the location of the user stylesheet.
632 \sa setUserStyleSheetUrl()
634 QUrl QWebSettings::userStyleSheetUrl() const
636 return d->userStyleSheetLocation;
641 Specifies the default text encoding system.
643 The \a encoding, must be a string describing an encoding such as "utf-8",
644 "iso-8859-1", etc. If left empty a default value will be used. For a more
645 extensive list of encoding names see \l{QTextCodec}
647 \sa defaultTextEncoding()
649 void QWebSettings::setDefaultTextEncoding(const QString& encoding)
651 d->defaultTextEncoding = encoding;
657 Returns the default text encoding.
659 \sa setDefaultTextEncoding()
661 QString QWebSettings::defaultTextEncoding() const
663 return d->defaultTextEncoding;
667 Sets the path of the icon database to \a path. The icon database is used
668 to store "favicons" associated with web sites.
670 \a path must point to an existing directory.
672 Setting an empty path disables the icon database.
674 \sa iconDatabasePath(), clearIconDatabase()
676 void QWebSettings::setIconDatabasePath(const QString& path)
678 #if ENABLE(ICONDATABASE)
679 // Make sure that IconDatabaseClientQt is instantiated.
680 WebCore::IconDatabaseClientQt::instance();
683 WebCore::IconDatabase::delayDatabaseCleanup();
685 if (!path.isEmpty()) {
686 WebCore::iconDatabase().setEnabled(true);
687 QFileInfo info(path);
688 if (info.isDir() && info.isWritable())
689 WebCore::iconDatabase().open(path, WebCore::IconDatabase::defaultDatabaseFilename());
691 WebCore::iconDatabase().setEnabled(false);
692 WebCore::iconDatabase().close();
697 Returns the path of the icon database or an empty string if the icon
698 database is disabled.
700 \sa setIconDatabasePath(), clearIconDatabase()
702 QString QWebSettings::iconDatabasePath()
704 if (WebCore::iconDatabase().isEnabled() && WebCore::iconDatabase().isOpen())
705 return WebCore::iconDatabase().databasePath();
711 Clears the icon database.
713 void QWebSettings::clearIconDatabase()
715 if (WebCore::iconDatabase().isEnabled() && WebCore::iconDatabase().isOpen())
716 WebCore::iconDatabase().removeAllIcons();
720 Returns the web site's icon for \a url.
722 If the web site does not specify an icon \bold OR if the icon is not in the
723 database, a null QIcon is returned.
725 \note The returned icon's size is arbitrary.
727 \sa setIconDatabasePath()
729 QIcon QWebSettings::iconForUrl(const QUrl& url)
731 WebCore::Image* image = WebCore::iconDatabase().synchronousIconForPageURL(WebCore::KURL(url).string(),
732 WebCore::IntSize(16, 16));
736 QPixmap* icon = image->nativeImageForCurrentFrame();
744 Returns the plugin database object.
746 QWebPluginDatabase *QWebSettings::pluginDatabase()
748 static QWebPluginDatabase* database = 0;
750 database = new QWebPluginDatabase();
756 Sets \a graphic to be drawn when QtWebKit needs to draw an image of the
759 For example, when an image cannot be loaded, the pixmap specified by
760 \l{QWebSettings::WebGraphic}{MissingImageGraphic} is drawn instead.
764 void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap& graphic)
766 WebGraphicHash* h = graphics();
767 if (graphic.isNull())
770 h->insert(type, graphic);
774 Returns a previously set pixmap used to draw replacement graphics of the
779 QPixmap QWebSettings::webGraphic(WebGraphic type)
781 return graphics()->value(type);
785 Frees up as much memory as possible by cleaning all memory caches such
786 as page, object and font cache.
790 void QWebSettings::clearMemoryCaches()
792 // Turn the cache on and off. Disabling the object cache will remove all
793 // resources from the cache. They may still live on if they are referenced
794 // by some Web page though.
795 if (!WebCore::memoryCache()->disabled()) {
796 WebCore::memoryCache()->setDisabled(true);
797 WebCore::memoryCache()->setDisabled(false);
800 int pageCapacity = WebCore::pageCache()->capacity();
801 // Setting size to 0, makes all pages be released.
802 WebCore::pageCache()->setCapacity(0);
803 WebCore::pageCache()->releaseAutoreleasedPagesNow();
804 WebCore::pageCache()->setCapacity(pageCapacity);
806 // Invalidating the font cache and freeing all inactive font data.
807 WebCore::fontCache()->invalidate();
809 // Empty the Cross-Origin Preflight cache
810 WebCore::CrossOriginPreflightResultCache::shared().empty();
814 Sets the maximum number of pages to hold in the memory page cache to \a pages.
816 The Page Cache allows for a nicer user experience when navigating forth or back
817 to pages in the forward/back history, by pausing and resuming up to \a pages.
819 For more information about the feature, please refer to:
821 http://webkit.org/blog/427/webkit-page-cache-i-the-basics/
823 void QWebSettings::setMaximumPagesInCache(int pages)
825 QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
826 WebCore::pageCache()->setCapacity(qMax(0, pages));
831 Returns the maximum number of web pages that are kept in the memory cache.
833 int QWebSettings::maximumPagesInCache()
835 return WebCore::pageCache()->capacity();
839 Specifies the capacities for the memory cache for dead objects such as
840 stylesheets or scripts.
842 The \a cacheMinDeadCapacity specifies the \e minimum number of bytes that
843 dead objects should consume when the cache is under pressure.
845 \a cacheMaxDead is the \e maximum number of bytes that dead objects should
846 consume when the cache is \bold not under pressure.
848 \a totalCapacity specifies the \e maximum number of bytes that the cache
849 should consume \bold overall.
851 The cache is enabled by default. Calling setObjectCacheCapacities(0, 0, 0)
852 will disable the cache. Calling it with one non-zero enables it again.
854 void QWebSettings::setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)
856 bool disableCache = !cacheMinDeadCapacity && !cacheMaxDead && !totalCapacity;
857 WebCore::memoryCache()->setDisabled(disableCache);
859 WebCore::memoryCache()->setCapacities(qMax(0, cacheMinDeadCapacity),
860 qMax(0, cacheMaxDead),
861 qMax(0, totalCapacity));
864 #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
866 Sets the third-party cookie policy, the default is AlwaysAllowThirdPartyCookies.
868 void QWebSettings::setThirdPartyCookiePolicy(ThirdPartyCookiePolicy policy)
870 d->thirdPartyCookiePolicy = policy;
874 Returns the third-party cookie policy.
876 QWebSettings::ThirdPartyCookiePolicy QWebSettings::thirdPartyCookiePolicy() const
878 return d->thirdPartyCookiePolicy;
883 Sets the actual font family to \a family for the specified generic family,
886 void QWebSettings::setFontFamily(FontFamily which, const QString& family)
888 d->fontFamilies.insert(which, family);
893 Returns the actual font family for the specified generic font family,
896 QString QWebSettings::fontFamily(FontFamily which) const
898 QString defaultValue;
900 QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
901 defaultValue = global->fontFamilies.value(which);
903 return d->fontFamilies.value(which, defaultValue);
907 Resets the actual font family specified by \a which to the one set
908 in the global QWebSettings instance.
910 This function has no effect on the global QWebSettings instance.
912 void QWebSettings::resetFontFamily(FontFamily which)
915 d->fontFamilies.remove(which);
921 \fn void QWebSettings::setAttribute(WebAttribute attribute, bool on)
923 Enables or disables the specified \a attribute feature depending on the
926 void QWebSettings::setAttribute(WebAttribute attr, bool on)
928 d->attributes.insert(attr, on);
933 \fn bool QWebSettings::testAttribute(WebAttribute attribute) const
935 Returns true if \a attribute is enabled; otherwise returns false.
937 bool QWebSettings::testAttribute(WebAttribute attr) const
939 bool defaultValue = false;
941 QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
942 defaultValue = global->attributes.value(attr);
944 return d->attributes.value(attr, defaultValue);
948 \fn void QWebSettings::resetAttribute(WebAttribute attribute)
950 Resets the setting of \a attribute to the value specified in the
951 global QWebSettings instance.
953 This function has no effect on the global QWebSettings instance.
957 void QWebSettings::resetAttribute(WebAttribute attr)
960 d->attributes.remove(attr);
968 Sets \a path as the save location for HTML5 client-side database storage data.
970 \a path must point to an existing directory.
972 Setting an empty path disables the feature.
974 Support for client-side databases can enabled by setting the
975 \l{QWebSettings::OfflineStorageDatabaseEnabled}{OfflineStorageDatabaseEnabled} attribute.
977 \sa offlineStoragePath()
979 void QWebSettings::setOfflineStoragePath(const QString& path)
982 WebCore::DatabaseTracker::tracker().setDatabaseDirectoryPath(path);
989 Returns the path of the HTML5 client-side database storage or an empty string if the
992 \sa setOfflineStoragePath()
994 QString QWebSettings::offlineStoragePath()
997 return WebCore::DatabaseTracker::tracker().databaseDirectoryPath();
1006 Sets the value of the default quota for new offline storage databases
1009 void QWebSettings::setOfflineStorageDefaultQuota(qint64 maximumSize)
1011 QWebSettings::globalSettings()->d->offlineStorageDefaultQuota = maximumSize;
1017 Returns the value of the default quota for new offline storage databases.
1019 qint64 QWebSettings::offlineStorageDefaultQuota()
1021 return QWebSettings::globalSettings()->d->offlineStorageDefaultQuota;
1027 Sets the path for HTML5 offline web application cache storage to \a path.
1029 An application cache acts like an HTTP cache in some sense. For documents
1030 that use the application cache via JavaScript, the loader engine will
1031 first ask the application cache for the contents, before hitting the
1034 The feature is described in details at:
1035 http://dev.w3.org/html5/spec/Overview.html#appcache
1037 \a path must point to an existing directory.
1039 Setting an empty path disables the feature.
1041 Support for offline web application cache storage can enabled by setting the
1042 \l{QWebSettings::OfflineWebApplicationCacheEnabled}{OfflineWebApplicationCacheEnabled} attribute.
1044 \sa offlineWebApplicationCachePath()
1046 void QWebSettings::setOfflineWebApplicationCachePath(const QString& path)
1048 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
1049 WebCore::cacheStorage().setCacheDirectory(path);
1056 Returns the path of the HTML5 offline web application cache storage
1057 or an empty string if the feature is disabled.
1059 \sa setOfflineWebApplicationCachePath()
1061 QString QWebSettings::offlineWebApplicationCachePath()
1063 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
1064 return WebCore::cacheStorage().cacheDirectory();
1073 Sets the value of the quota for the offline web application cache
1076 void QWebSettings::setOfflineWebApplicationCacheQuota(qint64 maximumSize)
1078 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
1079 WebCore::cacheStorage().empty();
1080 WebCore::cacheStorage().vacuumDatabaseFile();
1081 WebCore::cacheStorage().setMaximumSize(maximumSize);
1088 Returns the value of the quota for the offline web application cache.
1090 qint64 QWebSettings::offlineWebApplicationCacheQuota()
1092 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
1093 return WebCore::cacheStorage().maximumSize();
1102 Sets the path for HTML5 local storage to \a path.
1104 For more information on HTML5 local storage see the
1105 \l{http://www.w3.org/TR/webstorage/#the-localstorage-attribute}{Web Storage standard}.
1107 Support for local storage can enabled by setting the
1108 \l{QWebSettings::LocalStorageEnabled}{LocalStorageEnabled} attribute.
1110 \sa localStoragePath()
1112 void QWebSettings::setLocalStoragePath(const QString& path)
1114 d->localStoragePath = path;
1121 Returns the path for HTML5 local storage.
1123 \sa setLocalStoragePath()
1125 QString QWebSettings::localStoragePath() const
1127 return d->localStoragePath;
1133 Enables WebKit data persistence and sets the path to \a path.
1134 If \a path is empty, the user-specific data location specified by
1135 \l{QDesktopServices::DataLocation}{DataLocation} will be used instead.
1137 This method will simultaneously set and enable the iconDatabasePath(),
1138 localStoragePath(), offlineStoragePath() and offlineWebApplicationCachePath().
1140 \sa localStoragePath()
1142 void QWebSettings::enablePersistentStorage(const QString& path)
1144 #ifndef QT_NO_DESKTOPSERVICES
1145 QString storagePath;
1147 if (path.isEmpty()) {
1149 storagePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
1150 if (storagePath.isEmpty())
1151 storagePath = WebCore::pathByAppendingComponent(QDir::homePath(), QCoreApplication::applicationName());
1155 WebCore::makeAllDirectories(storagePath);
1157 QWebSettings::setIconDatabasePath(storagePath);
1158 QWebSettings::setOfflineWebApplicationCachePath(storagePath);
1159 QWebSettings::setOfflineStoragePath(WebCore::pathByAppendingComponent(storagePath, "Databases"));
1160 QWebSettings::globalSettings()->setLocalStoragePath(WebCore::pathByAppendingComponent(storagePath, "LocalStorage"));
1161 QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
1162 QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
1163 QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
1165 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
1166 // All applications can share the common QtWebkit cache file(s).
1167 // Path is not configurable and uses QDesktopServices::CacheLocation by default.
1168 QString cachePath = QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
1169 WebCore::makeAllDirectories(cachePath);
1171 QFileInfo info(cachePath);
1172 if (info.isDir() && info.isWritable()) {
1173 WebCore::PluginDatabase::setPersistentMetadataCacheEnabled(true);
1174 WebCore::PluginDatabase::setPersistentMetadataCachePath(cachePath);
1181 \fn QWebSettingsPrivate* QWebSettings::handle() const