qwebsettings.cpp 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. /*
  2. Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include "config.h"
  17. #include "qwebsettings.h"
  18. #include "qwebplugindatabase_p.h"
  19. #include "ApplicationCacheStorage.h"
  20. #include "CrossOriginPreflightResultCache.h"
  21. #include "DatabaseManager.h"
  22. #include "FileSystem.h"
  23. #include "FontCache.h"
  24. #include "GCController.h"
  25. #include "IconDatabase.h"
  26. #include "Image.h"
  27. #if ENABLE(ICONDATABASE)
  28. #include "IconDatabaseClientQt.h"
  29. #endif
  30. #include "InitWebCoreQt.h"
  31. #include "IntSize.h"
  32. #include "KURL.h"
  33. #include "MemoryCache.h"
  34. #include "NetworkStateNotifier.h"
  35. #include "Page.h"
  36. #include "PageCache.h"
  37. #include "PluginDatabase.h"
  38. #include "RuntimeEnabledFeatures.h"
  39. #include "Settings.h"
  40. #include "StorageThread.h"
  41. #include "WorkerThread.h"
  42. #include <QDir>
  43. #include <QFileInfo>
  44. #include <QFont>
  45. #include <QGuiApplication>
  46. #include <QHash>
  47. #include <QSharedData>
  48. #include <QStandardPaths>
  49. #include <QUrl>
  50. #include <wtf/FastMalloc.h>
  51. #include <wtf/text/WTFString.h>
  52. QWEBKIT_EXPORT void qt_networkAccessAllowed(bool isAllowed)
  53. {
  54. #ifndef QT_NO_BEARERMANAGEMENT
  55. WebCore::networkStateNotifier().setNetworkAccessAllowed(isAllowed);
  56. #endif
  57. }
  58. class QWebSettingsPrivate {
  59. public:
  60. QWebSettingsPrivate(WebCore::Settings* wcSettings = 0)
  61. : settings(wcSettings)
  62. {
  63. }
  64. QHash<int, QString> fontFamilies;
  65. QHash<int, int> fontSizes;
  66. QHash<int, bool> attributes;
  67. QUrl userStyleSheetLocation;
  68. QString defaultTextEncoding;
  69. QString localStoragePath;
  70. QString offlineWebApplicationCachePath;
  71. QString mediaType;
  72. qint64 offlineStorageDefaultQuota;
  73. QWebSettings::ThirdPartyCookiePolicy thirdPartyCookiePolicy;
  74. void apply();
  75. WebCore::Settings* settings;
  76. };
  77. Q_GLOBAL_STATIC(QList<QWebSettingsPrivate*>, allSettings);
  78. void QWebSettingsPrivate::apply()
  79. {
  80. if (settings) {
  81. settings->setTextAreasAreResizable(true);
  82. QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
  83. QString family = fontFamilies.value(QWebSettings::StandardFont,
  84. global->fontFamilies.value(QWebSettings::StandardFont));
  85. settings->setStandardFontFamily(family);
  86. family = fontFamilies.value(QWebSettings::FixedFont,
  87. global->fontFamilies.value(QWebSettings::FixedFont));
  88. settings->setFixedFontFamily(family);
  89. family = fontFamilies.value(QWebSettings::SerifFont,
  90. global->fontFamilies.value(QWebSettings::SerifFont));
  91. settings->setSerifFontFamily(family);
  92. family = fontFamilies.value(QWebSettings::SansSerifFont,
  93. global->fontFamilies.value(QWebSettings::SansSerifFont));
  94. settings->setSansSerifFontFamily(family);
  95. family = fontFamilies.value(QWebSettings::CursiveFont,
  96. global->fontFamilies.value(QWebSettings::CursiveFont));
  97. settings->setCursiveFontFamily(family);
  98. family = fontFamilies.value(QWebSettings::FantasyFont,
  99. global->fontFamilies.value(QWebSettings::FantasyFont));
  100. settings->setFantasyFontFamily(family);
  101. int size = fontSizes.value(QWebSettings::MinimumFontSize,
  102. global->fontSizes.value(QWebSettings::MinimumFontSize));
  103. settings->setMinimumFontSize(size);
  104. size = fontSizes.value(QWebSettings::MinimumLogicalFontSize,
  105. global->fontSizes.value(QWebSettings::MinimumLogicalFontSize));
  106. settings->setMinimumLogicalFontSize(size);
  107. size = fontSizes.value(QWebSettings::DefaultFontSize,
  108. global->fontSizes.value(QWebSettings::DefaultFontSize));
  109. settings->setDefaultFontSize(size);
  110. size = fontSizes.value(QWebSettings::DefaultFixedFontSize,
  111. global->fontSizes.value(QWebSettings::DefaultFixedFontSize));
  112. settings->setDefaultFixedFontSize(size);
  113. bool value = attributes.value(QWebSettings::AutoLoadImages,
  114. global->attributes.value(QWebSettings::AutoLoadImages));
  115. settings->setLoadsImagesAutomatically(value);
  116. value = attributes.value(QWebSettings::DnsPrefetchEnabled,
  117. global->attributes.value(QWebSettings::DnsPrefetchEnabled));
  118. settings->setDNSPrefetchingEnabled(value);
  119. value = attributes.value(QWebSettings::JavascriptEnabled,
  120. global->attributes.value(QWebSettings::JavascriptEnabled));
  121. settings->setScriptEnabled(value);
  122. #if USE(ACCELERATED_COMPOSITING)
  123. value = attributes.value(QWebSettings::AcceleratedCompositingEnabled,
  124. global->attributes.value(QWebSettings::AcceleratedCompositingEnabled));
  125. settings->setAcceleratedCompositingEnabled(value);
  126. settings->setAcceleratedCompositingFor3DTransformsEnabled(value);
  127. settings->setAcceleratedCompositingForAnimationEnabled(value);
  128. settings->setAcceleratedCompositingForVideoEnabled(false);
  129. settings->setAcceleratedCompositingForPluginsEnabled(false);
  130. bool showDebugVisuals = qgetenv("WEBKIT_SHOW_COMPOSITING_DEBUG_VISUALS") == "1";
  131. settings->setShowDebugBorders(showDebugVisuals);
  132. settings->setShowRepaintCounter(showDebugVisuals);
  133. #endif
  134. #if ENABLE(WEBGL)
  135. value = attributes.value(QWebSettings::WebGLEnabled,
  136. global->attributes.value(QWebSettings::WebGLEnabled));
  137. settings->setWebGLEnabled(value);
  138. #if ENABLE(CSS_SHADERS)
  139. // For now, enable CSS shaders when WebGL is enabled.
  140. settings->setCSSCustomFilterEnabled(value);
  141. #endif
  142. #if USE(ACCELERATED_COMPOSITING)
  143. settings->setAcceleratedCompositingForCanvasEnabled(value);
  144. #endif
  145. #endif
  146. #if ENABLE(WEB_AUDIO)
  147. value = attributes.value(QWebSettings::WebAudioEnabled, global->attributes.value(QWebSettings::WebAudioEnabled));
  148. settings->setWebAudioEnabled(value);
  149. #endif
  150. value = attributes.value(QWebSettings::CSSRegionsEnabled,
  151. global->attributes.value(QWebSettings::CSSRegionsEnabled));
  152. WebCore::RuntimeEnabledFeatures::setCSSRegionsEnabled(value);
  153. value = attributes.value(QWebSettings::CSSCompositingEnabled,
  154. global->attributes.value(QWebSettings::CSSCompositingEnabled));
  155. WebCore::RuntimeEnabledFeatures::setCSSCompositingEnabled(value);
  156. value = attributes.value(QWebSettings::CSSGridLayoutEnabled,
  157. global->attributes.value(QWebSettings::CSSGridLayoutEnabled));
  158. settings->setCSSGridLayoutEnabled(value);
  159. value = attributes.value(QWebSettings::HyperlinkAuditingEnabled,
  160. global->attributes.value(QWebSettings::HyperlinkAuditingEnabled));
  161. settings->setHyperlinkAuditingEnabled(value);
  162. value = attributes.value(QWebSettings::JavascriptCanOpenWindows,
  163. global->attributes.value(QWebSettings::JavascriptCanOpenWindows));
  164. settings->setJavaScriptCanOpenWindowsAutomatically(value);
  165. value = attributes.value(QWebSettings::JavascriptCanCloseWindows,
  166. global->attributes.value(QWebSettings::JavascriptCanCloseWindows));
  167. settings->setAllowScriptsToCloseWindows(value);
  168. value = attributes.value(QWebSettings::JavaEnabled,
  169. global->attributes.value(QWebSettings::JavaEnabled));
  170. settings->setJavaEnabled(value);
  171. value = attributes.value(QWebSettings::PluginsEnabled,
  172. global->attributes.value(QWebSettings::PluginsEnabled));
  173. settings->setPluginsEnabled(value);
  174. value = attributes.value(QWebSettings::PrivateBrowsingEnabled,
  175. global->attributes.value(QWebSettings::PrivateBrowsingEnabled));
  176. settings->setPrivateBrowsingEnabled(value);
  177. value = attributes.value(QWebSettings::SpatialNavigationEnabled,
  178. global->attributes.value(QWebSettings::SpatialNavigationEnabled));
  179. settings->setSpatialNavigationEnabled(value);
  180. value = attributes.value(QWebSettings::JavascriptCanAccessClipboard,
  181. global->attributes.value(QWebSettings::JavascriptCanAccessClipboard));
  182. settings->setDOMPasteAllowed(value);
  183. settings->setJavaScriptCanAccessClipboard(value);
  184. value = attributes.value(QWebSettings::DeveloperExtrasEnabled,
  185. global->attributes.value(QWebSettings::DeveloperExtrasEnabled));
  186. settings->setDeveloperExtrasEnabled(value);
  187. value = attributes.value(QWebSettings::FrameFlatteningEnabled,
  188. global->attributes.value(QWebSettings::FrameFlatteningEnabled));
  189. settings->setFrameFlatteningEnabled(value);
  190. QUrl location = !userStyleSheetLocation.isEmpty() ? userStyleSheetLocation : global->userStyleSheetLocation;
  191. settings->setUserStyleSheetLocation(WebCore::KURL(location));
  192. QString encoding = !defaultTextEncoding.isEmpty() ? defaultTextEncoding: global->defaultTextEncoding;
  193. settings->setDefaultTextEncodingName(encoding);
  194. QString storagePath = !localStoragePath.isEmpty() ? localStoragePath : global->localStoragePath;
  195. settings->setLocalStorageDatabasePath(storagePath);
  196. if (mediaType.isEmpty())
  197. mediaType = global->mediaType;
  198. value = attributes.value(QWebSettings::PrintElementBackgrounds,
  199. global->attributes.value(QWebSettings::PrintElementBackgrounds));
  200. settings->setShouldPrintBackgrounds(value);
  201. #if ENABLE(SQL_DATABASE)
  202. value = attributes.value(QWebSettings::OfflineStorageDatabaseEnabled,
  203. global->attributes.value(QWebSettings::OfflineStorageDatabaseEnabled));
  204. WebCore::DatabaseManager::manager().setIsAvailable(value);
  205. #endif
  206. value = attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled,
  207. global->attributes.value(QWebSettings::OfflineWebApplicationCacheEnabled));
  208. settings->setOfflineWebApplicationCacheEnabled(value);
  209. value = attributes.value(QWebSettings::LocalStorageEnabled,
  210. global->attributes.value(QWebSettings::LocalStorageEnabled));
  211. settings->setLocalStorageEnabled(value);
  212. value = attributes.value(QWebSettings::LocalContentCanAccessRemoteUrls,
  213. global->attributes.value(QWebSettings::LocalContentCanAccessRemoteUrls));
  214. settings->setAllowUniversalAccessFromFileURLs(value);
  215. value = attributes.value(QWebSettings::LocalContentCanAccessFileUrls,
  216. global->attributes.value(QWebSettings::LocalContentCanAccessFileUrls));
  217. settings->setAllowFileAccessFromFileURLs(value);
  218. value = attributes.value(QWebSettings::XSSAuditingEnabled,
  219. global->attributes.value(QWebSettings::XSSAuditingEnabled));
  220. settings->setXSSAuditorEnabled(value);
  221. #if USE(TILED_BACKING_STORE)
  222. value = attributes.value(QWebSettings::TiledBackingStoreEnabled,
  223. global->attributes.value(QWebSettings::TiledBackingStoreEnabled));
  224. settings->setTiledBackingStoreEnabled(value);
  225. #endif
  226. #if ENABLE(SMOOTH_SCROLLING)
  227. value = attributes.value(QWebSettings::ScrollAnimatorEnabled,
  228. global->attributes.value(QWebSettings::ScrollAnimatorEnabled));
  229. settings->setScrollAnimatorEnabled(value);
  230. #endif
  231. value = attributes.value(QWebSettings::CaretBrowsingEnabled,
  232. global->attributes.value(QWebSettings::CaretBrowsingEnabled));
  233. settings->setCaretBrowsingEnabled(value);
  234. value = attributes.value(QWebSettings::NotificationsEnabled,
  235. global->attributes.value(QWebSettings::NotificationsEnabled));
  236. settings->setNotificationsEnabled(value);
  237. value = attributes.value(QWebSettings::SiteSpecificQuirksEnabled,
  238. global->attributes.value(QWebSettings::SiteSpecificQuirksEnabled));
  239. settings->setNeedsSiteSpecificQuirks(value);
  240. settings->setUsesPageCache(WebCore::pageCache()->capacity());
  241. } else {
  242. QList<QWebSettingsPrivate*> settings = *::allSettings();
  243. for (int i = 0; i < settings.count(); ++i)
  244. settings[i]->apply();
  245. }
  246. }
  247. /*!
  248. Returns the global settings object.
  249. Any setting changed on the default object is automatically applied to all
  250. QWebPage instances where the particular setting is not overriden already.
  251. */
  252. QWebSettings* QWebSettings::globalSettings()
  253. {
  254. static QWebSettings* global = 0;
  255. if (!global) {
  256. WebCore::initializeWebCoreQt();
  257. global = new QWebSettings;
  258. }
  259. return global;
  260. }
  261. /*!
  262. \class QWebSettings
  263. \since 4.4
  264. \brief The QWebSettings class provides an object to store the settings used
  265. by QWebPage and QWebFrame.
  266. \inmodule QtWebKit
  267. Each QWebPage object has its own QWebSettings object, which configures the
  268. settings for that page. If a setting is not configured, then it is looked
  269. up in the global settings object, which can be accessed using
  270. globalSettings().
  271. QWebSettings allows configuration of browser properties, such as font sizes and
  272. families, the location of a custom style sheet, and generic attributes like
  273. JavaScript and plugins. Individual attributes are set using the setAttribute()
  274. function. The \l{QWebSettings::WebAttribute}{WebAttribute} enum further describes
  275. each attribute.
  276. QWebSettings also configures global properties such as the web page memory
  277. cache, icon database, local database storage and offline
  278. applications storage.
  279. \section1 Enabling Plugins
  280. Support for browser plugins can enabled by setting the
  281. \l{QWebSettings::PluginsEnabled}{PluginsEnabled} attribute. For many applications,
  282. this attribute is enabled for all pages by setting it on the
  283. \l{globalSettings()}{global settings object}. Qt WebKit will always ignore this setting
  284. when processing Qt plugins. The decision to allow a Qt plugin is made by the client
  285. in its reimplementation of QWebPage::createPlugin().
  286. \section1 Web Application Support
  287. WebKit provides support for features specified in \l{HTML 5} that improve the
  288. performance and capabilities of Web applications. These include client-side
  289. (offline) storage and the use of a Web application cache.
  290. Client-side (offline) storage is an improvement over the use of cookies to
  291. store persistent data in Web applications. Applications can configure and
  292. enable the use of an offline storage database by calling the
  293. setOfflineStoragePath() with an appropriate file path, and can limit the quota
  294. for each application by calling setOfflineStorageDefaultQuota().
  295. \sa QWebPage::settings(), QWebView::settings(), {Web Browser}
  296. */
  297. /*!
  298. \enum QWebSettings::FontFamily
  299. This enum describes the generic font families defined by CSS 2.
  300. For more information see the
  301. \l{http://www.w3.org/TR/REC-CSS2/fonts.html#generic-font-families}{CSS standard}.
  302. \value StandardFont
  303. \value FixedFont
  304. \value SerifFont
  305. \value SansSerifFont
  306. \value CursiveFont
  307. \value FantasyFont
  308. */
  309. /*!
  310. \enum QWebSettings::FontSize
  311. This enum describes the font sizes configurable through QWebSettings.
  312. \value MinimumFontSize The hard minimum font size.
  313. \value MinimumLogicalFontSize The minimum logical font size that is applied
  314. when zooming out with QWebFrame::setTextSizeMultiplier().
  315. \value DefaultFontSize The default font size for regular text.
  316. \value DefaultFixedFontSize The default font size for fixed-pitch text.
  317. */
  318. /*!
  319. \enum QWebSettings::ThirdPartyCookiePolicy
  320. This enum describes the policies configurable for accepting and sending
  321. third-party cookies. These are cookies that are set or retrieved when fetching
  322. a resource that is stored for a different registry-controlled domain from the page containing it.
  323. \value AlwaysAllowThirdPartyCookies Allow third-party resources to set and retrieve cookies.
  324. \value AlwaysBlockThirdPartyCookies Never allow third-party resources to set and retrieve cookies.
  325. \value AllowThirdPartyWithExistingCookies If the cookie jar already contains cookies
  326. from a third-party, allow it to set and retrieve new and existing cookies.
  327. \since QtWebKit 2,3
  328. */
  329. /*!
  330. \enum QWebSettings::WebGraphic
  331. This enums describes the standard graphical elements used in webpages.
  332. \value MissingImageGraphic The replacement graphic shown when an image could not be loaded.
  333. \value MissingPluginGraphic The replacement graphic shown when a plugin could not be loaded.
  334. \value DefaultFrameIconGraphic The default icon for QWebFrame::icon().
  335. \value TextAreaSizeGripCornerGraphic The graphic shown for the size grip of text areas.
  336. \value DeleteButtonGraphic The graphic shown for the WebKit-Editing-Delete-Button in Deletion UI.
  337. \value InputSpeechButtonGraphic The graphic shown in input fields that support speech recognition.
  338. \value SearchCancelButtonGraphic The graphic shown for clearing the text in a search field.
  339. \value SearchCancelButtonPressedGraphic The graphic shown when SearchCancelButtonGraphic is pressed.
  340. */
  341. /*!
  342. \enum QWebSettings::WebAttribute
  343. This enum describes various attributes that are configurable through QWebSettings.
  344. \value AutoLoadImages Specifies whether images are automatically loaded in
  345. web pages. This is enabled by default.
  346. \value DnsPrefetchEnabled Specifies whether Qt WebKit will try to pre-fetch DNS entries to
  347. speed up browsing. This only works as a global attribute. Only for Qt 4.6 and later. This is disabled by default.
  348. \value JavascriptEnabled Enables or disables the running of JavaScript
  349. programs. This is enabled by default
  350. \value JavaEnabled Enables or disables Java applets.
  351. Currently Java applets are not supported.
  352. \value PluginsEnabled Enables or disables plugins in Web pages (e.g. using NPAPI). Qt plugins
  353. with a mimetype such as "application/x-qt-plugin" are not affected by this setting. This is disabled by default.
  354. \value PrivateBrowsingEnabled Private browsing prevents WebKit from
  355. recording visited pages in the history and storing web page icons. This is disabled by default.
  356. \value JavascriptCanOpenWindows Specifies whether JavaScript programs
  357. can open new windows. This is disabled by default.
  358. \value JavascriptCanCloseWindows Specifies whether JavaScript programs
  359. can close windows. This is disabled by default.
  360. \value JavascriptCanAccessClipboard Specifies whether JavaScript programs
  361. can read or write to the clipboard. This is disabled by default.
  362. \value DeveloperExtrasEnabled Enables extra tools for Web developers.
  363. Currently this enables the "Inspect" element in the context menu as
  364. well as the use of QWebInspector which controls the web inspector
  365. for web site debugging. This is disabled by default.
  366. \value SpatialNavigationEnabled Enables or disables the Spatial Navigation
  367. feature, which consists in the ability to navigate between focusable
  368. elements in a Web page, such as hyperlinks and form controls, by using
  369. Left, Right, Up and Down arrow keys. For example, if a user presses the
  370. Right key, heuristics determine whether there is an element he might be
  371. trying to reach towards the right and which element he probably wants.
  372. This is disabled by default.
  373. \value LinksIncludedInFocusChain Specifies whether hyperlinks should be
  374. included in the keyboard focus chain. This is enabled by default.
  375. \value ZoomTextOnly Specifies whether the zoom factor on a frame applies
  376. only to the text or to all content. This is disabled by default.
  377. \value PrintElementBackgrounds Specifies whether the background color and images
  378. are also drawn when the page is printed. This is enabled by default.
  379. \value OfflineStorageDatabaseEnabled Specifies whether support for the HTML 5
  380. offline storage feature is enabled or not. This is disabled by default.
  381. \value OfflineWebApplicationCacheEnabled Specifies whether support for the HTML 5
  382. web application cache feature is enabled or not. This is disabled by default.
  383. \value LocalStorageEnabled Specifies whether support for the HTML 5
  384. local storage feature is enabled or not. This is disabled by default.
  385. (This value was introduced in 4.6.)
  386. \value LocalStorageDatabaseEnabled \e{This enum value is deprecated.} Use
  387. QWebSettings::LocalStorageEnabled instead.
  388. \value LocalContentCanAccessRemoteUrls Specifies whether locally loaded documents are
  389. allowed to access remote urls. This is disabled by default. For more information
  390. about security origins and local vs. remote content see QWebSecurityOrigin.
  391. (This value was introduced in 4.6.)
  392. \value LocalContentCanAccessFileUrls Specifies whether locally loaded documents are
  393. allowed to access other local urls. This is enabled by default. For more information
  394. about security origins and local vs. remote content see QWebSecurityOrigin.
  395. \value XSSAuditingEnabled Specifies whether load requests should be monitored for cross-site
  396. scripting attempts. Suspicious scripts will be blocked and reported in the inspector's
  397. JavaScript console. Enabling this feature might have an impact on performance
  398. and it is disabled by default.
  399. \value AcceleratedCompositingEnabled This feature, when used in conjunction with
  400. QGraphicsWebView, accelerates animations of web content. CSS animations of the transform and
  401. opacity properties will be rendered by composing the cached content of the animated elements.
  402. This is enabled by default.
  403. \value TiledBackingStoreEnabled This setting enables the tiled backing store feature
  404. for a QGraphicsWebView. With the tiled backing store enabled, the web page contents in and around
  405. the current visible area is speculatively cached to bitmap tiles. The tiles are automatically kept
  406. in sync with the web page as it changes. Enabling tiling can significantly speed up painting heavy
  407. operations like scrolling. Enabling the feature increases memory consumption. It does not work well
  408. with contents using CSS fixed positioning (see also \l{QGraphicsWebView::}{resizesToContents} property).
  409. \l{QGraphicsWebView::}{tiledBackingStoreFrozen} property allows application to temporarily
  410. freeze the contents of the backing store. This is disabled by default.
  411. \value FrameFlatteningEnabled With this setting each subframe is expanded to its contents.
  412. On touch devices, it is desired to not have any scrollable sub parts of the page
  413. as it results in a confusing user experience, with scrolling sometimes scrolling sub parts
  414. and at other times scrolling the page itself. For this reason iframes and framesets are
  415. barely usable on touch devices. This will flatten all the frames to become one scrollable page.
  416. This is disabled by default.
  417. \value SiteSpecificQuirksEnabled This setting enables WebKit's workaround for broken sites. It is
  418. enabled by default.
  419. \value ScrollAnimatorEnabled This setting enables animated scrolling. It is disabled by default.
  420. \value CaretBrowsingEnabled This setting enables caret browsing. It is disabled by default.
  421. \value NotificationsEnabled Specifies whether support for the HTML 5 web notifications is enabled
  422. or not. This is enabled by default.
  423. */
  424. /*!
  425. \internal
  426. */
  427. QWebSettings::QWebSettings()
  428. : d(new QWebSettingsPrivate)
  429. {
  430. // Initialize our global defaults
  431. d->fontSizes.insert(QWebSettings::MinimumFontSize, 0);
  432. d->fontSizes.insert(QWebSettings::MinimumLogicalFontSize, 0);
  433. d->fontSizes.insert(QWebSettings::DefaultFontSize, 16);
  434. d->fontSizes.insert(QWebSettings::DefaultFixedFontSize, 13);
  435. QFont defaultFont;
  436. defaultFont.setStyleHint(QFont::Serif);
  437. d->fontFamilies.insert(QWebSettings::StandardFont, defaultFont.defaultFamily());
  438. d->fontFamilies.insert(QWebSettings::SerifFont, defaultFont.defaultFamily());
  439. defaultFont.setStyleHint(QFont::Fantasy);
  440. d->fontFamilies.insert(QWebSettings::FantasyFont, defaultFont.defaultFamily());
  441. defaultFont.setStyleHint(QFont::Cursive);
  442. d->fontFamilies.insert(QWebSettings::CursiveFont, defaultFont.defaultFamily());
  443. defaultFont.setStyleHint(QFont::SansSerif);
  444. d->fontFamilies.insert(QWebSettings::SansSerifFont, defaultFont.defaultFamily());
  445. defaultFont.setStyleHint(QFont::Monospace);
  446. d->fontFamilies.insert(QWebSettings::FixedFont, defaultFont.defaultFamily());
  447. d->attributes.insert(QWebSettings::AutoLoadImages, true);
  448. d->attributes.insert(QWebSettings::DnsPrefetchEnabled, false);
  449. d->attributes.insert(QWebSettings::JavascriptEnabled, true);
  450. d->attributes.insert(QWebSettings::SpatialNavigationEnabled, false);
  451. d->attributes.insert(QWebSettings::LinksIncludedInFocusChain, true);
  452. d->attributes.insert(QWebSettings::ZoomTextOnly, false);
  453. d->attributes.insert(QWebSettings::PrintElementBackgrounds, true);
  454. d->attributes.insert(QWebSettings::OfflineStorageDatabaseEnabled, false);
  455. d->attributes.insert(QWebSettings::OfflineWebApplicationCacheEnabled, false);
  456. d->attributes.insert(QWebSettings::LocalStorageEnabled, false);
  457. d->attributes.insert(QWebSettings::LocalContentCanAccessRemoteUrls, false);
  458. d->attributes.insert(QWebSettings::LocalContentCanAccessFileUrls, true);
  459. d->attributes.insert(QWebSettings::AcceleratedCompositingEnabled, true);
  460. d->attributes.insert(QWebSettings::WebGLEnabled, true);
  461. d->attributes.insert(QWebSettings::WebAudioEnabled, false);
  462. d->attributes.insert(QWebSettings::CSSRegionsEnabled, true);
  463. d->attributes.insert(QWebSettings::CSSCompositingEnabled, true);
  464. d->attributes.insert(QWebSettings::CSSGridLayoutEnabled, false);
  465. d->attributes.insert(QWebSettings::HyperlinkAuditingEnabled, false);
  466. d->attributes.insert(QWebSettings::TiledBackingStoreEnabled, false);
  467. d->attributes.insert(QWebSettings::FrameFlatteningEnabled, false);
  468. d->attributes.insert(QWebSettings::SiteSpecificQuirksEnabled, true);
  469. d->attributes.insert(QWebSettings::ScrollAnimatorEnabled, false);
  470. d->attributes.insert(QWebSettings::CaretBrowsingEnabled, false);
  471. d->attributes.insert(QWebSettings::NotificationsEnabled, true);
  472. d->offlineStorageDefaultQuota = 5 * 1024 * 1024;
  473. d->defaultTextEncoding = QLatin1String("iso-8859-1");
  474. d->thirdPartyCookiePolicy = AlwaysAllowThirdPartyCookies;
  475. }
  476. /*!
  477. \internal
  478. */
  479. QWebSettings::QWebSettings(WebCore::Settings* settings)
  480. : d(new QWebSettingsPrivate(settings))
  481. {
  482. d->settings = settings;
  483. d->apply();
  484. allSettings()->append(d);
  485. }
  486. /*!
  487. \internal
  488. */
  489. QWebSettings::~QWebSettings()
  490. {
  491. if (d->settings)
  492. allSettings()->removeAll(d);
  493. delete d;
  494. }
  495. /*!
  496. Sets the font size for \a type to \a size.
  497. */
  498. void QWebSettings::setFontSize(FontSize type, int size)
  499. {
  500. d->fontSizes.insert(type, size);
  501. d->apply();
  502. }
  503. /*!
  504. Returns the default font size for \a type.
  505. */
  506. int QWebSettings::fontSize(FontSize type) const
  507. {
  508. int defaultValue = 0;
  509. if (d->settings) {
  510. QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
  511. defaultValue = global->fontSizes.value(type);
  512. }
  513. return d->fontSizes.value(type, defaultValue);
  514. }
  515. /*!
  516. Resets the font size for \a type to the size specified in the global
  517. settings object.
  518. This function has no effect on the global QWebSettings instance.
  519. */
  520. void QWebSettings::resetFontSize(FontSize type)
  521. {
  522. if (d->settings) {
  523. d->fontSizes.remove(type);
  524. d->apply();
  525. }
  526. }
  527. /*!
  528. Specifies the location of a user stylesheet to load with every web page.
  529. The \a location must be either a path on the local filesystem, or a data URL
  530. with UTF-8 and Base64 encoded data, such as:
  531. "data:text/css;charset=utf-8;base64,cCB7IGJhY2tncm91bmQtY29sb3I6IHJlZCB9Ow=="
  532. \note If the base64 data is not valid, the style will not be applied.
  533. \sa userStyleSheetUrl()
  534. */
  535. void QWebSettings::setUserStyleSheetUrl(const QUrl& location)
  536. {
  537. d->userStyleSheetLocation = location;
  538. d->apply();
  539. }
  540. /*!
  541. Returns the location of the user stylesheet.
  542. \sa setUserStyleSheetUrl()
  543. */
  544. QUrl QWebSettings::userStyleSheetUrl() const
  545. {
  546. return d->userStyleSheetLocation;
  547. }
  548. /*!
  549. \since 4.6
  550. Specifies the default text encoding system.
  551. The \a encoding, must be a string describing an encoding such as "utf-8",
  552. "iso-8859-1", etc. If left empty a default value will be used. For a more
  553. extensive list of encoding names see \l{QTextCodec}
  554. \sa defaultTextEncoding()
  555. */
  556. void QWebSettings::setDefaultTextEncoding(const QString& encoding)
  557. {
  558. d->defaultTextEncoding = encoding;
  559. d->apply();
  560. }
  561. /*!
  562. \since 4.6
  563. Returns the default text encoding.
  564. \sa setDefaultTextEncoding()
  565. */
  566. QString QWebSettings::defaultTextEncoding() const
  567. {
  568. return d->defaultTextEncoding;
  569. }
  570. /*!
  571. Sets the path of the icon database to \a path. The icon database is used
  572. to store "favicons" associated with web sites.
  573. \a path must point to an existing directory.
  574. Setting an empty path disables the icon database.
  575. \sa iconDatabasePath(), clearIconDatabase()
  576. */
  577. void QWebSettings::setIconDatabasePath(const QString& path)
  578. {
  579. WebCore::initializeWebCoreQt();
  580. #if ENABLE(ICONDATABASE)
  581. // Make sure that IconDatabaseClientQt is instantiated.
  582. WebCore::IconDatabaseClientQt::instance();
  583. #endif
  584. WebCore::IconDatabase::delayDatabaseCleanup();
  585. WebCore::IconDatabaseBase& db = WebCore::iconDatabase();
  586. if (!path.isEmpty()) {
  587. db.setEnabled(true);
  588. if (db.isOpen())
  589. db.close();
  590. QFileInfo info(path);
  591. if (info.isDir() && info.isWritable())
  592. db.open(path, WebCore::IconDatabase::defaultDatabaseFilename());
  593. } else {
  594. db.setEnabled(false);
  595. db.close();
  596. }
  597. }
  598. /*!
  599. Returns the path of the icon database or an empty string if the icon
  600. database is disabled.
  601. \sa setIconDatabasePath(), clearIconDatabase()
  602. */
  603. QString QWebSettings::iconDatabasePath()
  604. {
  605. WebCore::initializeWebCoreQt();
  606. if (WebCore::iconDatabase().isEnabled() && WebCore::iconDatabase().isOpen())
  607. return WebCore::iconDatabase().databasePath();
  608. else
  609. return QString();
  610. }
  611. /*!
  612. Clears the icon database.
  613. */
  614. void QWebSettings::clearIconDatabase()
  615. {
  616. WebCore::initializeWebCoreQt();
  617. if (WebCore::iconDatabase().isEnabled() && WebCore::iconDatabase().isOpen())
  618. WebCore::iconDatabase().removeAllIcons();
  619. }
  620. /*!
  621. Returns the web site's icon for \a url.
  622. If the web site does not specify an icon \b OR if the icon is not in the
  623. database, a null QIcon is returned.
  624. \note The returned icon's size is arbitrary.
  625. \sa setIconDatabasePath()
  626. */
  627. QIcon QWebSettings::iconForUrl(const QUrl& url)
  628. {
  629. WebCore::initializeWebCoreQt();
  630. QPixmap* icon = WebCore::iconDatabase().synchronousNativeIconForPageURL(WebCore::KURL(url).string(),
  631. WebCore::IntSize(16, 16));
  632. if (!icon)
  633. return QIcon();
  634. return* icon;
  635. }
  636. /*
  637. Returns the plugin database object.
  638. QWebPluginDatabase *QWebSettings::pluginDatabase()
  639. {
  640. WebCore::initializeWebCoreQt();
  641. static QWebPluginDatabase* database = 0;
  642. if (!database)
  643. database = new QWebPluginDatabase();
  644. return database;
  645. }
  646. */
  647. static const char* resourceNameForWebGraphic(QWebSettings::WebGraphic type)
  648. {
  649. switch (type) {
  650. case QWebSettings::MissingImageGraphic: return "missingImage";
  651. case QWebSettings::MissingPluginGraphic: return "nullPlugin";
  652. case QWebSettings::DefaultFrameIconGraphic: return "urlIcon";
  653. case QWebSettings::TextAreaSizeGripCornerGraphic: return "textAreaResizeCorner";
  654. case QWebSettings::DeleteButtonGraphic: return "deleteButton";
  655. case QWebSettings::InputSpeechButtonGraphic: return "inputSpeech";
  656. case QWebSettings::SearchCancelButtonGraphic: return "searchCancelButton";
  657. case QWebSettings::SearchCancelButtonPressedGraphic: return "searchCancelButtonPressed";
  658. }
  659. return 0;
  660. }
  661. /*!
  662. Sets \a graphic to be drawn when Qt WebKit needs to draw an image of the
  663. given \a type.
  664. For example, when an image cannot be loaded, the pixmap specified by
  665. \l{QWebSettings::WebGraphic}{MissingImageGraphic} is drawn instead.
  666. \sa webGraphic()
  667. */
  668. void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap& graphic)
  669. {
  670. WebCore::initializeWebCoreQt();
  671. WebCore::Image::setPlatformResource(resourceNameForWebGraphic(type), graphic);
  672. }
  673. /*!
  674. Returns a previously set pixmap used to draw replacement graphics of the
  675. specified \a type.
  676. \sa setWebGraphic()
  677. */
  678. QPixmap QWebSettings::webGraphic(WebGraphic type)
  679. {
  680. WebCore::initializeWebCoreQt();
  681. RefPtr<WebCore::Image> img = WebCore::Image::loadPlatformResource(resourceNameForWebGraphic(type));
  682. if (!img)
  683. return QPixmap();
  684. QPixmap* pixmap = img->nativeImageForCurrentFrame();
  685. if (!pixmap)
  686. return QPixmap();
  687. return *pixmap;
  688. }
  689. /*!
  690. Frees up as much memory as possible by calling the JavaScript garbage collector and cleaning all memory caches such
  691. as page, object and font cache.
  692. \since 4.6
  693. */
  694. void QWebSettings::clearMemoryCaches()
  695. {
  696. WebCore::initializeWebCoreQt();
  697. // Turn the cache on and off. Disabling the object cache will remove all
  698. // resources from the cache. They may still live on if they are referenced
  699. // by some Web page though.
  700. if (!WebCore::memoryCache()->disabled()) {
  701. WebCore::memoryCache()->setDisabled(true);
  702. WebCore::memoryCache()->setDisabled(false);
  703. }
  704. int pageCapacity = WebCore::pageCache()->capacity();
  705. // Setting size to 0, makes all pages be released.
  706. WebCore::pageCache()->setCapacity(0);
  707. WebCore::pageCache()->setCapacity(pageCapacity);
  708. // Invalidating the font cache and freeing all inactive font data.
  709. WebCore::fontCache()->invalidate();
  710. // Empty the Cross-Origin Preflight cache
  711. WebCore::CrossOriginPreflightResultCache::shared().empty();
  712. // Drop JIT compiled code from ExecutableAllocator.
  713. WebCore::gcController().discardAllCompiledCode();
  714. // Garbage Collect to release the references of CachedResource from dead objects.
  715. WebCore::gcController().garbageCollectNow();
  716. // FastMalloc has lock-free thread specific caches that can only be cleared from the thread itself.
  717. WebCore::StorageThread::releaseFastMallocFreeMemoryInAllThreads();
  718. #if ENABLE(WORKERS)
  719. WebCore::WorkerThread::releaseFastMallocFreeMemoryInAllThreads();
  720. #endif
  721. WTF::releaseFastMallocFreeMemory();
  722. }
  723. /*!
  724. Sets the maximum number of pages to hold in the memory page cache to \a pages.
  725. The Page Cache allows for a nicer user experience when navigating forth or back
  726. to pages in the forward/back history, by pausing and resuming up to \a pages.
  727. For more information about the feature, please refer to:
  728. http://webkit.org/blog/427/webkit-page-cache-i-the-basics/
  729. */
  730. void QWebSettings::setMaximumPagesInCache(int pages)
  731. {
  732. QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
  733. WebCore::pageCache()->setCapacity(qMax(0, pages));
  734. global->apply();
  735. }
  736. /*!
  737. Returns the maximum number of web pages that are kept in the memory cache.
  738. */
  739. int QWebSettings::maximumPagesInCache()
  740. {
  741. WebCore::initializeWebCoreQt();
  742. return WebCore::pageCache()->capacity();
  743. }
  744. /*!
  745. Specifies the capacities for the memory cache for dead objects such as
  746. stylesheets or scripts.
  747. The \a cacheMinDeadCapacity specifies the \e minimum number of bytes that
  748. dead objects should consume when the cache is under pressure.
  749. \a cacheMaxDead is the \e maximum number of bytes that dead objects should
  750. consume when the cache is \b not under pressure.
  751. \a totalCapacity specifies the \e maximum number of bytes that the cache
  752. should consume \b overall.
  753. The cache is enabled by default. Calling setObjectCacheCapacities(0, 0, 0)
  754. will disable the cache. Calling it with one non-zero enables it again.
  755. */
  756. void QWebSettings::setObjectCacheCapacities(int cacheMinDeadCapacity, int cacheMaxDead, int totalCapacity)
  757. {
  758. WebCore::initializeWebCoreQt();
  759. bool disableCache = !cacheMinDeadCapacity && !cacheMaxDead && !totalCapacity;
  760. WebCore::memoryCache()->setDisabled(disableCache);
  761. WebCore::memoryCache()->setCapacities(qMax(0, cacheMinDeadCapacity),
  762. qMax(0, cacheMaxDead),
  763. qMax(0, totalCapacity));
  764. WebCore::memoryCache()->setDeadDecodedDataDeletionInterval(disableCache ? 0 : 60);
  765. }
  766. /*!
  767. Sets the third-party cookie policy, the default is AlwaysAllowThirdPartyCookies.
  768. */
  769. void QWebSettings::setThirdPartyCookiePolicy(ThirdPartyCookiePolicy policy)
  770. {
  771. d->thirdPartyCookiePolicy = policy;
  772. }
  773. /*!
  774. Returns the third-party cookie policy.
  775. */
  776. QWebSettings::ThirdPartyCookiePolicy QWebSettings::thirdPartyCookiePolicy() const
  777. {
  778. return d->thirdPartyCookiePolicy;
  779. }
  780. /*!
  781. Sets the CSS media type to \a type.
  782. Setting this will override the normal value of the CSS media property.
  783. \note Setting the value to null QString will restore the default value.
  784. */
  785. void QWebSettings::setCSSMediaType(const QString& type)
  786. {
  787. d->mediaType = type;
  788. d->apply();
  789. }
  790. /*!
  791. Returns the current CSS media type.
  792. \note It will only return the value set through setCSSMediaType and not the one used internally.
  793. */
  794. QString QWebSettings::cssMediaType() const
  795. {
  796. return d->mediaType;
  797. }
  798. /*!
  799. Sets the actual font family to \a family for the specified generic family,
  800. \a which.
  801. */
  802. void QWebSettings::setFontFamily(FontFamily which, const QString& family)
  803. {
  804. d->fontFamilies.insert(which, family);
  805. d->apply();
  806. }
  807. /*!
  808. Returns the actual font family for the specified generic font family,
  809. \a which.
  810. */
  811. QString QWebSettings::fontFamily(FontFamily which) const
  812. {
  813. QString defaultValue;
  814. if (d->settings) {
  815. QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
  816. defaultValue = global->fontFamilies.value(which);
  817. }
  818. return d->fontFamilies.value(which, defaultValue);
  819. }
  820. /*!
  821. Resets the actual font family specified by \a which to the one set
  822. in the global QWebSettings instance.
  823. This function has no effect on the global QWebSettings instance.
  824. */
  825. void QWebSettings::resetFontFamily(FontFamily which)
  826. {
  827. if (d->settings) {
  828. d->fontFamilies.remove(which);
  829. d->apply();
  830. }
  831. }
  832. /*!
  833. \fn void QWebSettings::setAttribute(WebAttribute attribute, bool on)
  834. Enables or disables the specified \a attribute feature depending on the
  835. value of \a on.
  836. */
  837. void QWebSettings::setAttribute(WebAttribute attr, bool on)
  838. {
  839. d->attributes.insert(attr, on);
  840. d->apply();
  841. }
  842. /*!
  843. \fn bool QWebSettings::testAttribute(WebAttribute attribute) const
  844. Returns true if \a attribute is enabled; otherwise returns false.
  845. */
  846. bool QWebSettings::testAttribute(WebAttribute attr) const
  847. {
  848. bool defaultValue = false;
  849. if (d->settings) {
  850. QWebSettingsPrivate* global = QWebSettings::globalSettings()->d;
  851. defaultValue = global->attributes.value(attr);
  852. }
  853. return d->attributes.value(attr, defaultValue);
  854. }
  855. /*!
  856. \fn void QWebSettings::resetAttribute(WebAttribute attribute)
  857. Resets the setting of \a attribute to the value specified in the
  858. global QWebSettings instance.
  859. This function has no effect on the global QWebSettings instance.
  860. \sa globalSettings()
  861. */
  862. void QWebSettings::resetAttribute(WebAttribute attr)
  863. {
  864. if (d->settings) {
  865. d->attributes.remove(attr);
  866. d->apply();
  867. }
  868. }
  869. /*!
  870. \since 4.5
  871. Sets \a path as the save location for HTML5 client-side database storage data.
  872. \a path must point to an existing directory.
  873. Setting an empty path disables the feature.
  874. Support for client-side databases can enabled by setting the
  875. \l{QWebSettings::OfflineStorageDatabaseEnabled}{OfflineStorageDatabaseEnabled} attribute.
  876. \sa offlineStoragePath()
  877. */
  878. void QWebSettings::setOfflineStoragePath(const QString& path)
  879. {
  880. WebCore::initializeWebCoreQt();
  881. #if ENABLE(SQL_DATABASE)
  882. WebCore::DatabaseManager::manager().setDatabaseDirectoryPath(path);
  883. #endif
  884. }
  885. /*!
  886. \since 4.5
  887. Returns the path of the HTML5 client-side database storage or an empty string if the
  888. feature is disabled.
  889. \sa setOfflineStoragePath()
  890. */
  891. QString QWebSettings::offlineStoragePath()
  892. {
  893. WebCore::initializeWebCoreQt();
  894. #if ENABLE(SQL_DATABASE)
  895. return WebCore::DatabaseManager::manager().databaseDirectoryPath();
  896. #else
  897. return QString();
  898. #endif
  899. }
  900. /*!
  901. \since 4.5
  902. Sets the value of the default quota for new offline storage databases
  903. to \a maximumSize.
  904. */
  905. void QWebSettings::setOfflineStorageDefaultQuota(qint64 maximumSize)
  906. {
  907. QWebSettings::globalSettings()->d->offlineStorageDefaultQuota = maximumSize;
  908. }
  909. /*!
  910. \since 4.5
  911. Returns the value of the default quota for new offline storage databases.
  912. */
  913. qint64 QWebSettings::offlineStorageDefaultQuota()
  914. {
  915. return QWebSettings::globalSettings()->d->offlineStorageDefaultQuota;
  916. }
  917. /*!
  918. \since 4.6
  919. Sets the path for HTML5 offline web application cache storage to \a path.
  920. An application cache acts like an HTTP cache in some sense. For documents
  921. that use the application cache via JavaScript, the loader engine will
  922. first ask the application cache for the contents, before hitting the
  923. network.
  924. The feature is described in details at:
  925. http://dev.w3.org/html5/spec/Overview.html#appcache
  926. \a path must point to an existing directory.
  927. Setting an empty path disables the feature.
  928. Support for offline web application cache storage can enabled by setting the
  929. \l{QWebSettings::OfflineWebApplicationCacheEnabled}{OfflineWebApplicationCacheEnabled} attribute.
  930. \sa offlineWebApplicationCachePath()
  931. */
  932. void QWebSettings::setOfflineWebApplicationCachePath(const QString& path)
  933. {
  934. WebCore::initializeWebCoreQt();
  935. WebCore::cacheStorage().setCacheDirectory(path);
  936. }
  937. /*!
  938. \since 4.6
  939. Returns the path of the HTML5 offline web application cache storage
  940. or an empty string if the feature is disabled.
  941. \sa setOfflineWebApplicationCachePath()
  942. */
  943. QString QWebSettings::offlineWebApplicationCachePath()
  944. {
  945. WebCore::initializeWebCoreQt();
  946. return WebCore::cacheStorage().cacheDirectory();
  947. }
  948. /*!
  949. \since 4.6
  950. Sets the value of the quota for the offline web application cache
  951. to \a maximumSize.
  952. */
  953. void QWebSettings::setOfflineWebApplicationCacheQuota(qint64 maximumSize)
  954. {
  955. WebCore::initializeWebCoreQt();
  956. WebCore::cacheStorage().empty();
  957. WebCore::cacheStorage().vacuumDatabaseFile();
  958. WebCore::cacheStorage().setMaximumSize(maximumSize);
  959. }
  960. /*!
  961. \since 4.6
  962. Returns the value of the quota for the offline web application cache.
  963. */
  964. qint64 QWebSettings::offlineWebApplicationCacheQuota()
  965. {
  966. WebCore::initializeWebCoreQt();
  967. return WebCore::cacheStorage().maximumSize();
  968. }
  969. /*!
  970. \since 4.6
  971. Sets the path for HTML5 local storage to \a path.
  972. For more information on HTML5 local storage see the
  973. \l{http://www.w3.org/TR/webstorage/#the-localstorage-attribute}{Web Storage standard}.
  974. Support for local storage can enabled by setting the
  975. \l{QWebSettings::LocalStorageEnabled}{LocalStorageEnabled} attribute.
  976. \sa localStoragePath()
  977. */
  978. void QWebSettings::setLocalStoragePath(const QString& path)
  979. {
  980. d->localStoragePath = path;
  981. d->apply();
  982. }
  983. /*!
  984. \since 4.6
  985. Returns the path for HTML5 local storage.
  986. \sa setLocalStoragePath()
  987. */
  988. QString QWebSettings::localStoragePath() const
  989. {
  990. return d->localStoragePath;
  991. }
  992. /*!
  993. \since 4.6
  994. Enables WebKit data persistence and sets the path to \a path.
  995. If \a path is empty, the user-specific data location specified by
  996. \l{QDesktopServices::DataLocation}{DataLocation} will be used instead.
  997. This method will simultaneously set and enable the iconDatabasePath(),
  998. localStoragePath(), offlineStoragePath() and offlineWebApplicationCachePath().
  999. \sa localStoragePath()
  1000. */
  1001. void QWebSettings::enablePersistentStorage(const QString& path)
  1002. {
  1003. WebCore::initializeWebCoreQt();
  1004. #ifndef QT_NO_DESKTOPSERVICES
  1005. QString storagePath;
  1006. if (path.isEmpty()) {
  1007. storagePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
  1008. if (storagePath.isEmpty())
  1009. storagePath = WebCore::pathByAppendingComponent(QDir::homePath(), QCoreApplication::applicationName());
  1010. } else
  1011. storagePath = path;
  1012. WebCore::makeAllDirectories(storagePath);
  1013. QWebSettings::setIconDatabasePath(storagePath);
  1014. QWebSettings::setOfflineWebApplicationCachePath(storagePath);
  1015. QWebSettings::setOfflineStoragePath(WebCore::pathByAppendingComponent(storagePath, "Databases"));
  1016. QWebSettings::globalSettings()->setLocalStoragePath(WebCore::pathByAppendingComponent(storagePath, "LocalStorage"));
  1017. QWebSettings::globalSettings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
  1018. QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
  1019. QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
  1020. #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE)
  1021. // All applications can share the common QtWebkit cache file(s).
  1022. // Path is not configurable and uses QDesktopServices::CacheLocation by default.
  1023. QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
  1024. WebCore::makeAllDirectories(cachePath);
  1025. QFileInfo info(cachePath);
  1026. if (info.isDir() && info.isWritable()) {
  1027. WebCore::PluginDatabase::setPersistentMetadataCacheEnabled(true);
  1028. WebCore::PluginDatabase::setPersistentMetadataCachePath(cachePath);
  1029. }
  1030. #endif
  1031. #endif
  1032. }
  1033. /*!
  1034. \fn QWebSettingsPrivate* QWebSettings::handle() const
  1035. \internal
  1036. */