Merge "[CherryPick] Refactoring: Move the content of HTMLInputElement::subtreeHasChan...
[framework/web/webkit-efl.git] / Source / WebCore / page / Settings.cpp
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "config.h"
27 #include "Settings.h"
28
29 #include "BackForwardController.h"
30 #include "CachedResourceLoader.h"
31 #include "CookieStorage.h"
32 #include "DOMTimer.h"
33 #include "Database.h"
34 #include "Document.h"
35 #include "Frame.h"
36 #include "FrameTree.h"
37 #include "FrameView.h"
38 #include "HistoryItem.h"
39 #include "Page.h"
40 #include "PageCache.h"
41 #include "ResourceHandle.h"
42 #include "StorageMap.h"
43 #include <limits>
44
45 using namespace std;
46
47 namespace WebCore {
48
49 static void setLoadsImagesAutomaticallyInAllFrames(Page* page)
50 {
51     for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext())
52         frame->document()->cachedResourceLoader()->setAutoLoadImages(page->settings()->loadsImagesAutomatically());
53 }
54
55 #if ENABLE(TIZEN_LOAD_REMOTE_IMAGES)
56 static void setLoadsRemoteImagesInAllFrames(Page* page)
57 {
58     for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext())
59         frame->document()->cachedResourceLoader()->setLoadRemoteImages(page->settings()->loadRemoteImages());
60 }
61 #endif
62
63 // Sets the entry in the font map for the given script. If family is the empty string, removes the entry instead.
64 static inline void setGenericFontFamilyMap(ScriptFontFamilyMap& fontMap, const AtomicString& family, UScriptCode script, Page* page)
65 {
66     ScriptFontFamilyMap::iterator it = fontMap.find(static_cast<int>(script));
67     if (family.isEmpty()) {
68         if (it == fontMap.end())
69             return;
70         fontMap.remove(it);
71     } else if (it != fontMap.end() && it->second == family)
72         return;
73     else
74         fontMap.set(static_cast<int>(script), family);
75
76     if (page)
77         page->setNeedsRecalcStyleInAllFrames();
78 }
79
80 static inline const AtomicString& getGenericFontFamilyForScript(const ScriptFontFamilyMap& fontMap, UScriptCode script)
81 {
82     ScriptFontFamilyMap::const_iterator it = fontMap.find(static_cast<int>(script));
83     if (it != fontMap.end())
84         return it->second;
85     if (script != USCRIPT_COMMON)
86         return getGenericFontFamilyForScript(fontMap, USCRIPT_COMMON);
87     return emptyAtom;
88 }
89
90 #if USE(SAFARI_THEME)
91 bool Settings::gShouldPaintNativeControls = true;
92 #endif
93
94 #if USE(AVFOUNDATION)
95 bool Settings::gAVFoundationEnabled(false);
96 #endif
97
98 bool Settings::gMockScrollbarsEnabled = false;
99
100 #if PLATFORM(WIN) || (OS(WINDOWS) && PLATFORM(WX))
101 bool Settings::gShouldUseHighResolutionTimers = true;
102 #endif
103     
104 #if USE(JSC)
105 bool Settings::gShouldRespectPriorityInCSSAttributeSetters = false;
106 #endif
107
108 // NOTEs
109 //  1) EditingMacBehavior comprises Tiger, Leopard, SnowLeopard and iOS builds, as well QtWebKit and Chromium when built on Mac;
110 //  2) EditingWindowsBehavior comprises Win32 and WinCE builds, as well as QtWebKit and Chromium when built on Windows;
111 //  3) EditingUnixBehavior comprises all unix-based systems, but Darwin/MacOS (and then abusing the terminology);
112 // 99) MacEditingBehavior is used a fallback.
113 static EditingBehaviorType editingBehaviorTypeForPlatform()
114 {
115     return
116 #if OS(DARWIN)
117     EditingMacBehavior
118 #elif OS(WINDOWS)
119     EditingWindowsBehavior
120 #elif OS(UNIX)
121     EditingUnixBehavior
122 #else
123     // Fallback
124     EditingMacBehavior
125 #endif
126     ;
127 }
128
129 static const double defaultIncrementalRenderingSuppressionTimeoutInSeconds = 5;
130
131 Settings::Settings(Page* page)
132     : m_page(0)
133     , m_editableLinkBehavior(EditableLinkDefaultBehavior)
134     , m_textDirectionSubmenuInclusionBehavior(TextDirectionSubmenuAutomaticallyIncluded)
135     , m_passwordEchoDurationInSeconds(1)
136     , m_minimumFontSize(0)
137     , m_minimumLogicalFontSize(0)
138     , m_defaultFontSize(0)
139     , m_defaultFixedFontSize(0)
140     , m_validationMessageTimerMagnification(50)
141     , m_minimumAccelerated2dCanvasSize(257 * 256)
142     , m_layoutFallbackWidth(980)
143     , m_maximumDecodedImageSize(numeric_limits<size_t>::max())
144     , m_deviceWidth(0)
145     , m_deviceHeight(0)
146     , m_sessionStorageQuota(StorageMap::noQuota)
147     , m_editingBehaviorType(editingBehaviorTypeForPlatform())
148     , m_maximumHTMLParserDOMTreeDepth(defaultMaximumHTMLParserDOMTreeDepth)
149 #if ENABLE(TEXT_AUTOSIZING)
150     , m_textAutosizingFontScaleFactor(1)
151 #if HACK_FORCE_TEXT_AUTOSIZING_ON_DESKTOP
152     , m_textAutosizingWindowSizeOverride(320, 480)
153     , m_textAutosizingEnabled(true)
154 #else
155     , m_textAutosizingEnabled(false)
156 #endif
157 #endif
158     , m_isSpatialNavigationEnabled(false)
159     , m_isJavaEnabled(false)
160     , m_isJavaEnabledForLocalFiles(true)
161     , m_loadsImagesAutomatically(false)
162     , m_loadsSiteIconsIgnoringImageLoadingSetting(false)
163     , m_privateBrowsingEnabled(false)
164     , m_caretBrowsingEnabled(false)
165     , m_areImagesEnabled(true)
166     , m_isMediaEnabled(true)
167     , m_arePluginsEnabled(false)
168     , m_localStorageEnabled(false)
169     , m_isScriptEnabled(false)
170     , m_isWebSecurityEnabled(true)
171     , m_allowUniversalAccessFromFileURLs(true)
172     , m_allowFileAccessFromFileURLs(true)
173     , m_javaScriptCanOpenWindowsAutomatically(false)
174     , m_javaScriptCanAccessClipboard(false)
175     , m_shouldPrintBackgrounds(false)
176     , m_textAreasAreResizable(false)
177 #if ENABLE(DASHBOARD_SUPPORT)
178     , m_usesDashboardBackwardCompatibilityMode(false)
179 #endif
180     , m_needsAdobeFrameReloadingQuirk(false)
181     , m_needsKeyboardEventDisambiguationQuirks(false)
182     , m_treatsAnyTextCSSLinkAsStylesheet(false)
183     , m_needsLeopardMailQuirks(false)
184     , m_isDOMPasteAllowed(false)
185     , m_shrinksStandaloneImagesToFit(true)
186     , m_usesPageCache(false)
187     , m_pageCacheSupportsPlugins(false)
188     , m_showsURLsInToolTips(false)
189     , m_showsToolTipOverTruncatedText(false)
190     , m_forceFTPDirectoryListings(false)
191     , m_developerExtrasEnabled(false)
192     , m_javaScriptExperimentsEnabled(false)
193     , m_authorAndUserStylesEnabled(true)
194     , m_needsSiteSpecificQuirks(false)
195     , m_fontRenderingMode(0)
196     , m_frameFlatteningEnabled(false)
197 #if ENABLE(WEB_ARCHIVE)
198     , m_webArchiveDebugModeEnabled(false)
199 #endif
200     , m_localFileContentSniffingEnabled(false)
201     , m_inApplicationChromeMode(false)
202     , m_offlineWebApplicationCacheEnabled(false)
203     , m_enforceCSSMIMETypeInNoQuirksMode(true)
204     , m_usesEncodingDetector(false)
205     , m_allowScriptsToCloseWindows(false)
206     , m_canvasUsesAcceleratedDrawing(false)
207     , m_acceleratedDrawingEnabled(false)
208     , m_acceleratedFiltersEnabled(false)
209     , m_isCSSCustomFilterEnabled(false)
210 #if ENABLE(CSS_REGIONS)
211     , m_cssRegionsEnabled(false)
212 #endif
213 #if ENABLE(CSS_VARIABLES)
214     , m_cssVariablesEnabled(false)
215 #endif
216     , m_regionBasedColumnsEnabled(false)
217     , m_cssGridLayoutEnabled(false)
218     // FIXME: This should really be disabled by default as it makes platforms that don't support the feature download files
219     // they can't use by. Leaving enabled for now to not change existing behavior.
220     , m_downloadableBinaryFontsEnabled(true)
221     , m_xssAuditorEnabled(false)
222     , m_acceleratedCompositingEnabled(true)
223     , m_acceleratedCompositingFor3DTransformsEnabled(true)
224     , m_acceleratedCompositingForVideoEnabled(true)
225     , m_acceleratedCompositingForPluginsEnabled(true)
226     , m_acceleratedCompositingForCanvasEnabled(true)
227     , m_acceleratedCompositingForAnimationEnabled(true)
228     , m_acceleratedCompositingForFixedPositionEnabled(false)
229     , m_acceleratedCompositingForScrollableFramesEnabled(false)
230 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
231     , m_alwaysUseAcceleratedOverflowScroll(false)
232 #endif
233     , m_showDebugBorders(false)
234     , m_showRepaintCounter(false)
235     , m_experimentalNotificationsEnabled(false)
236     , m_webGLEnabled(false)
237     , m_webGLErrorsToConsoleEnabled(false)
238     , m_openGLMultisamplingEnabled(true)
239     , m_privilegedWebGLExtensionsEnabled(false)
240     , m_webAudioEnabled(false)
241     , m_acceleratedCanvas2dEnabled(false)
242     , m_deferredCanvas2dEnabled(false)
243     , m_loadDeferringEnabled(true)
244     , m_tiledBackingStoreEnabled(false)
245     , m_paginateDuringLayoutEnabled(false)
246     , m_dnsPrefetchingEnabled(false)
247 #if ENABLE(FULLSCREEN_API)
248     , m_fullScreenAPIEnabled(false)
249 #endif
250     , m_asynchronousSpellCheckingEnabled(false)
251 #if USE(UNIFIED_TEXT_CHECKING)
252     , m_unifiedTextCheckerEnabled(true)
253 #else
254     , m_unifiedTextCheckerEnabled(false)
255 #endif
256     , m_memoryInfoEnabled(false)
257     , m_quantizedMemoryInfoEnabled(false)
258     , m_interactiveFormValidation(false)
259     , m_usePreHTML5ParserQuirks(false)
260     , m_hyperlinkAuditingEnabled(false)
261     , m_crossOriginCheckInGetMatchedCSSRulesDisabled(false)
262     , m_forceCompositingMode(false)
263     , m_shouldInjectUserScriptsInInitialEmptyDocument(false)
264     , m_fixedElementsLayoutRelativeToFrame(false)
265     , m_allowDisplayOfInsecureContent(true)
266     , m_allowRunningOfInsecureContent(true)
267 #if ENABLE(SMOOTH_SCROLLING)
268     , m_scrollAnimatorEnabled(true)
269 #endif
270     , m_mediaPlaybackRequiresUserGesture(false)
271     , m_mediaPlaybackAllowsInline(true)
272     , m_passwordEchoEnabled(false)
273     , m_suppressesIncrementalRendering(false)
274     , m_backspaceKeyNavigationEnabled(true)
275     , m_visualWordMovementEnabled(false)
276 #if ENABLE(VIDEO_TRACK)
277     , m_shouldDisplaySubtitles(false)
278     , m_shouldDisplayCaptions(false)
279     , m_shouldDisplayTextDescriptions(false)
280 #endif
281     , m_scrollingCoordinatorEnabled(false)
282     , m_notificationsEnabled(true)
283     , m_needsIsLoadingInAPISenseQuirk(false)
284 #if ENABLE(TOUCH_EVENTS)
285     , m_touchEventEmulationEnabled(false)
286 #endif
287     , m_shouldRespectImageOrientation(false)
288     , m_wantsBalancedSetDefersLoadingBehavior(false)
289     , m_requestAnimationFrameEnabled(true)
290     , m_deviceSupportsTouch(false)
291 #if ENABLE(TIZEN_DONT_DISPATCH_FAKEMOUSEMOVEEVENT_WHEN_SCROLLING_ON_TOUCH_DEVICES)
292     , m_deviceSupportsMouse(false)
293 #else
294     , m_deviceSupportsMouse(true)
295 #endif
296     , m_needsDidFinishLoadOrderQuirk(false)
297     , m_fixedPositionCreatesStackingContext(false)
298     , m_syncXHRInDocumentsEnabled(true)
299     , m_cookieEnabled(true)
300     , m_windowFocusRestricted(true)
301     , m_diagnosticLoggingEnabled(false)
302     , m_applyPageScaleFactorInCompositor(false)
303     , m_loadsImagesAutomaticallyTimer(this, &Settings::loadsImagesAutomaticallyTimerFired)
304     , m_incrementalRenderingSuppressionTimeoutInSeconds(defaultIncrementalRenderingSuppressionTimeoutInSeconds)
305 #if ENABLE(TIZEN_LOAD_REMOTE_IMAGES)
306     , m_loadRemoteImagesTimer(this, &Settings::loadRemoteImagesTimerFired)
307     , m_loadRemoteImages(true)
308 #endif
309 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
310     , m_memorySavingModeEnabled(false)
311 #endif
312 {
313     // A Frame may not have been created yet, so we initialize the AtomicString
314     // hash before trying to use it.
315     AtomicString::init();
316     initializeDefaultFontFamilies();
317     m_page = page; // Page is not yet fully initialized wen constructing Settings, so keeping m_page null over initializeDefaultFontFamilies() call.
318 }
319
320 PassOwnPtr<Settings> Settings::create(Page* page)
321 {
322     return adoptPtr(new Settings(page));
323
324
325 #if !PLATFORM(MAC) && !PLATFORM(BLACKBERRY)
326 void Settings::initializeDefaultFontFamilies()
327 {
328     // Other platforms can set up fonts from a client, but on Mac, we want it in WebCore to share code between WebKit1 and WebKit2.
329 }
330 #endif
331
332 const AtomicString& Settings::standardFontFamily(UScriptCode script) const
333 {
334     return getGenericFontFamilyForScript(m_standardFontFamilyMap, script);
335 }
336
337 void Settings::setStandardFontFamily(const AtomicString& family, UScriptCode script)
338 {
339     setGenericFontFamilyMap(m_standardFontFamilyMap, family, script, m_page);
340 }
341
342 const AtomicString& Settings::fixedFontFamily(UScriptCode script) const
343 {
344     return getGenericFontFamilyForScript(m_fixedFontFamilyMap, script);
345 }
346
347 void Settings::setFixedFontFamily(const AtomicString& family, UScriptCode script)
348 {
349     setGenericFontFamilyMap(m_fixedFontFamilyMap, family, script, m_page);
350 }
351
352 const AtomicString& Settings::serifFontFamily(UScriptCode script) const
353 {
354     return getGenericFontFamilyForScript(m_serifFontFamilyMap, script);
355 }
356
357 void Settings::setSerifFontFamily(const AtomicString& family, UScriptCode script)
358 {
359      setGenericFontFamilyMap(m_serifFontFamilyMap, family, script, m_page);
360 }
361
362 const AtomicString& Settings::sansSerifFontFamily(UScriptCode script) const
363 {
364     return getGenericFontFamilyForScript(m_sansSerifFontFamilyMap, script);
365 }
366
367 void Settings::setSansSerifFontFamily(const AtomicString& family, UScriptCode script)
368 {
369     setGenericFontFamilyMap(m_sansSerifFontFamilyMap, family, script, m_page);
370 }
371
372 const AtomicString& Settings::cursiveFontFamily(UScriptCode script) const
373 {
374     return getGenericFontFamilyForScript(m_cursiveFontFamilyMap, script);
375 }
376
377 void Settings::setCursiveFontFamily(const AtomicString& family, UScriptCode script)
378 {
379     setGenericFontFamilyMap(m_cursiveFontFamilyMap, family, script, m_page);
380 }
381
382 const AtomicString& Settings::fantasyFontFamily(UScriptCode script) const
383 {
384     return getGenericFontFamilyForScript(m_fantasyFontFamilyMap, script);
385 }
386
387 void Settings::setFantasyFontFamily(const AtomicString& family, UScriptCode script)
388 {
389     setGenericFontFamilyMap(m_fantasyFontFamilyMap, family, script, m_page);
390 }
391
392 const AtomicString& Settings::pictographFontFamily(UScriptCode script) const
393 {
394     return getGenericFontFamilyForScript(m_pictographFontFamilyMap, script);
395 }
396
397 void Settings::setPictographFontFamily(const AtomicString& family, UScriptCode script)
398 {
399     setGenericFontFamilyMap(m_pictographFontFamilyMap, family, script, m_page);
400 }
401
402 void Settings::setMinimumFontSize(int minimumFontSize)
403 {
404     if (m_minimumFontSize == minimumFontSize)
405         return;
406
407     m_minimumFontSize = minimumFontSize;
408     m_page->setNeedsRecalcStyleInAllFrames();
409 }
410
411 void Settings::setMinimumLogicalFontSize(int minimumLogicalFontSize)
412 {
413     if (m_minimumLogicalFontSize == minimumLogicalFontSize)
414         return;
415
416     m_minimumLogicalFontSize = minimumLogicalFontSize;
417     m_page->setNeedsRecalcStyleInAllFrames();
418 }
419
420 void Settings::setDefaultFontSize(int defaultFontSize)
421 {
422     if (m_defaultFontSize == defaultFontSize)
423         return;
424
425     m_defaultFontSize = defaultFontSize;
426     m_page->setNeedsRecalcStyleInAllFrames();
427 }
428
429 void Settings::setDefaultFixedFontSize(int defaultFontSize)
430 {
431     if (m_defaultFixedFontSize == defaultFontSize)
432         return;
433
434     m_defaultFixedFontSize = defaultFontSize;
435     m_page->setNeedsRecalcStyleInAllFrames();
436 }
437
438 #if ENABLE(TEXT_AUTOSIZING)
439 void Settings::setTextAutosizingEnabled(bool textAutosizingEnabled)
440 {
441     if (m_textAutosizingEnabled == textAutosizingEnabled)
442         return;
443
444     m_textAutosizingEnabled = textAutosizingEnabled;
445     m_page->setNeedsRecalcStyleInAllFrames();
446 }
447
448 void Settings::setTextAutosizingWindowSizeOverride(const IntSize& textAutosizingWindowSizeOverride)
449 {
450     if (m_textAutosizingWindowSizeOverride == textAutosizingWindowSizeOverride)
451         return;
452
453     m_textAutosizingWindowSizeOverride = textAutosizingWindowSizeOverride;
454     m_page->setNeedsRecalcStyleInAllFrames();
455 }
456
457 void Settings::setTextAutosizingFontScaleFactor(float fontScaleFactor)
458 {
459     m_textAutosizingFontScaleFactor = fontScaleFactor;
460     m_page->setNeedsRecalcStyleInAllFrames();
461 }
462
463 #endif
464
465 void Settings::setLoadsImagesAutomatically(bool loadsImagesAutomatically)
466 {
467     m_loadsImagesAutomatically = loadsImagesAutomatically;
468     
469     // Changing this setting to true might immediately start new loads for images that had previously had loading disabled.
470     // If this happens while a WebView is being dealloc'ed, and we don't know the WebView is being dealloc'ed, these new loads
471     // can cause crashes downstream when the WebView memory has actually been free'd.
472     // One example where this can happen is in Mac apps that subclass WebView then do work in their overridden dealloc methods.
473     // Starting these loads synchronously is not important.  By putting it on a 0-delay, properly closing the Page cancels them
474     // before they have a chance to really start.
475     // See http://webkit.org/b/60572 for more discussion.
476     m_loadsImagesAutomaticallyTimer.startOneShot(0);
477 }
478
479 void Settings::loadsImagesAutomaticallyTimerFired(Timer<Settings>*)
480 {
481     setLoadsImagesAutomaticallyInAllFrames(m_page);
482 }
483
484 void Settings::setLoadsSiteIconsIgnoringImageLoadingSetting(bool loadsSiteIcons)
485 {
486     m_loadsSiteIconsIgnoringImageLoadingSetting = loadsSiteIcons;
487 }
488
489 void Settings::setScriptEnabled(bool isScriptEnabled)
490 {
491     m_isScriptEnabled = isScriptEnabled;
492 }
493
494 void Settings::setWebSecurityEnabled(bool isWebSecurityEnabled)
495 {
496     m_isWebSecurityEnabled = isWebSecurityEnabled;
497 }
498
499 void Settings::setAllowUniversalAccessFromFileURLs(bool allowUniversalAccessFromFileURLs)
500 {
501     m_allowUniversalAccessFromFileURLs = allowUniversalAccessFromFileURLs;
502 }
503
504 void Settings::setAllowFileAccessFromFileURLs(bool allowFileAccessFromFileURLs)
505 {
506     m_allowFileAccessFromFileURLs = allowFileAccessFromFileURLs;
507 }
508
509 void Settings::setSpatialNavigationEnabled(bool isSpatialNavigationEnabled)
510 {
511     m_isSpatialNavigationEnabled = isSpatialNavigationEnabled;
512 }
513
514 void Settings::setJavaEnabled(bool isJavaEnabled)
515 {
516     m_isJavaEnabled = isJavaEnabled;
517 }
518
519 void Settings::setJavaEnabledForLocalFiles(bool isJavaEnabledForLocalFiles)
520 {
521     m_isJavaEnabledForLocalFiles = isJavaEnabledForLocalFiles;
522 }
523
524 void Settings::setImagesEnabled(bool areImagesEnabled)
525 {
526     m_areImagesEnabled = areImagesEnabled;
527 }
528
529 void Settings::setMediaEnabled(bool isMediaEnabled)
530 {
531     m_isMediaEnabled = isMediaEnabled;
532 }
533
534 void Settings::setPluginsEnabled(bool arePluginsEnabled)
535 {
536     m_arePluginsEnabled = arePluginsEnabled;
537 }
538
539 void Settings::setLocalStorageEnabled(bool localStorageEnabled)
540 {
541     m_localStorageEnabled = localStorageEnabled;
542 }
543
544 void Settings::setSessionStorageQuota(unsigned sessionStorageQuota)
545 {
546     m_sessionStorageQuota = sessionStorageQuota;
547 }
548
549 void Settings::setPrivateBrowsingEnabled(bool privateBrowsingEnabled)
550 {
551     // FIXME http://webkit.org/b/67870: The private browsing storage session and cookie private
552     // browsing mode (which is used if storage sessions are not available) are global settings, so
553     // it is misleading to have them as per-page settings.
554     // In addition, if they are treated as a per Page settings, the global values can get out of
555     // sync with the per Page value in the following situation:
556     // 1. The global values get set to true when setPrivateBrowsingEnabled(true) is called.
557     // 2. All Pages are closed, so all Settings objects go away.
558     // 3. A new Page is created, and a corresponding new Settings object is created - with
559     //    m_privateBrowsingEnabled starting out as false in the constructor.
560     // 4. The WebPage settings get applied to the new Page and setPrivateBrowsingEnabled(false)
561     //    is called, but an if (m_privateBrowsingEnabled == privateBrowsingEnabled) early return
562     //    prevents the global values from getting changed from true to false.
563 #if USE(CFURLSTORAGESESSIONS) || ENABLE(TIZEN_PRIVATE_BROWSING)
564     ResourceHandle::setPrivateBrowsingEnabled(privateBrowsingEnabled);
565 #endif
566     setCookieStoragePrivateBrowsingEnabled(privateBrowsingEnabled);
567
568     if (m_privateBrowsingEnabled == privateBrowsingEnabled)
569         return;
570
571     m_privateBrowsingEnabled = privateBrowsingEnabled;
572     m_page->privateBrowsingStateChanged();
573 }
574
575 void Settings::setJavaScriptCanOpenWindowsAutomatically(bool javaScriptCanOpenWindowsAutomatically)
576 {
577     m_javaScriptCanOpenWindowsAutomatically = javaScriptCanOpenWindowsAutomatically;
578 }
579
580 void Settings::setJavaScriptCanAccessClipboard(bool javaScriptCanAccessClipboard)
581 {
582     m_javaScriptCanAccessClipboard = javaScriptCanAccessClipboard;
583 }
584
585 void Settings::setDefaultTextEncodingName(const String& defaultTextEncodingName)
586 {
587     m_defaultTextEncodingName = defaultTextEncodingName;
588 }
589
590 void Settings::setUserStyleSheetLocation(const KURL& userStyleSheetLocation)
591 {
592     if (m_userStyleSheetLocation == userStyleSheetLocation)
593         return;
594
595     m_userStyleSheetLocation = userStyleSheetLocation;
596
597     m_page->userStyleSheetLocationChanged();
598 }
599
600 void Settings::setFixedElementsLayoutRelativeToFrame(bool fixedElementsLayoutRelativeToFrame)
601 {
602     m_fixedElementsLayoutRelativeToFrame = fixedElementsLayoutRelativeToFrame;
603 }
604
605 void Settings::setShouldPrintBackgrounds(bool shouldPrintBackgrounds)
606 {
607     m_shouldPrintBackgrounds = shouldPrintBackgrounds;
608 }
609
610 void Settings::setTextAreasAreResizable(bool textAreasAreResizable)
611 {
612     if (m_textAreasAreResizable == textAreasAreResizable)
613         return;
614
615     m_textAreasAreResizable = textAreasAreResizable;
616     m_page->setNeedsRecalcStyleInAllFrames();
617 }
618
619 void Settings::setEditableLinkBehavior(EditableLinkBehavior editableLinkBehavior)
620 {
621     m_editableLinkBehavior = editableLinkBehavior;
622 }
623
624 void Settings::setTextDirectionSubmenuInclusionBehavior(TextDirectionSubmenuInclusionBehavior behavior)
625 {
626     m_textDirectionSubmenuInclusionBehavior = behavior;
627 }
628
629 #if ENABLE(DASHBOARD_SUPPORT)
630 void Settings::setUsesDashboardBackwardCompatibilityMode(bool usesDashboardBackwardCompatibilityMode)
631 {
632     m_usesDashboardBackwardCompatibilityMode = usesDashboardBackwardCompatibilityMode;
633 }
634 #endif
635
636 // FIXME: This quirk is needed because of Radar 4674537 and 5211271. We need to phase it out once Adobe
637 // can fix the bug from their end.
638 void Settings::setNeedsAdobeFrameReloadingQuirk(bool shouldNotReloadIFramesForUnchangedSRC)
639 {
640     m_needsAdobeFrameReloadingQuirk = shouldNotReloadIFramesForUnchangedSRC;
641 }
642
643 // This is a quirk we are pro-actively applying to old applications. It changes keyboard event dispatching,
644 // making keyIdentifier available on keypress events, making charCode available on keydown/keyup events,
645 // and getting keypress dispatched in more cases.
646 void Settings::setNeedsKeyboardEventDisambiguationQuirks(bool needsQuirks)
647 {
648     m_needsKeyboardEventDisambiguationQuirks = needsQuirks;
649 }
650
651 void Settings::setTreatsAnyTextCSSLinkAsStylesheet(bool treatsAnyTextCSSLinkAsStylesheet)
652 {
653     m_treatsAnyTextCSSLinkAsStylesheet = treatsAnyTextCSSLinkAsStylesheet;
654 }
655
656 void Settings::setNeedsLeopardMailQuirks(bool needsQuirks)
657 {
658     m_needsLeopardMailQuirks = needsQuirks;
659 }
660
661 void Settings::setDOMPasteAllowed(bool DOMPasteAllowed)
662 {
663     m_isDOMPasteAllowed = DOMPasteAllowed;
664 }
665
666 void Settings::setDefaultMinDOMTimerInterval(double interval)
667 {
668     DOMTimer::setDefaultMinTimerInterval(interval);
669 }
670
671 double Settings::defaultMinDOMTimerInterval()
672 {
673     return DOMTimer::defaultMinTimerInterval();
674 }
675
676 void Settings::setMinDOMTimerInterval(double interval)
677 {
678     m_page->setMinimumTimerInterval(interval);
679 }
680
681 double Settings::minDOMTimerInterval()
682 {
683     return m_page->minimumTimerInterval();
684 }
685
686 void Settings::setUsesPageCache(bool usesPageCache)
687 {
688     if (m_usesPageCache == usesPageCache)
689         return;
690         
691     m_usesPageCache = usesPageCache;
692     if (!m_usesPageCache) {
693         int first = -m_page->backForward()->backCount();
694         int last = m_page->backForward()->forwardCount();
695         for (int i = first; i <= last; i++)
696             pageCache()->remove(m_page->backForward()->itemAtIndex(i));
697         pageCache()->releaseAutoreleasedPagesNow();
698     }
699 }
700
701 void Settings::setShrinksStandaloneImagesToFit(bool shrinksStandaloneImagesToFit)
702 {
703     m_shrinksStandaloneImagesToFit = shrinksStandaloneImagesToFit;
704 }
705
706 void Settings::setShowsURLsInToolTips(bool showsURLsInToolTips)
707 {
708     m_showsURLsInToolTips = showsURLsInToolTips;
709 }
710
711 void Settings::setShowsToolTipOverTruncatedText(bool showsToolTipForTruncatedText)
712 {
713     m_showsToolTipOverTruncatedText = showsToolTipForTruncatedText;
714 }
715
716 void Settings::setFTPDirectoryTemplatePath(const String& path)
717 {
718     m_ftpDirectoryTemplatePath = path;
719 }
720
721 void Settings::setForceFTPDirectoryListings(bool force)
722 {
723     m_forceFTPDirectoryListings = force;
724 }
725
726 void Settings::setDeveloperExtrasEnabled(bool developerExtrasEnabled)
727 {
728     m_developerExtrasEnabled = developerExtrasEnabled;
729 }
730
731 void Settings::setJavaScriptExperimentsEnabled(bool javaScriptExperimentsEnabled)
732 {
733     m_javaScriptExperimentsEnabled = javaScriptExperimentsEnabled;
734 }
735
736 void Settings::setAuthorAndUserStylesEnabled(bool authorAndUserStylesEnabled)
737 {
738     if (m_authorAndUserStylesEnabled == authorAndUserStylesEnabled)
739         return;
740
741     m_authorAndUserStylesEnabled = authorAndUserStylesEnabled;
742     m_page->setNeedsRecalcStyleInAllFrames();
743 }
744
745 void Settings::setFontRenderingMode(FontRenderingMode mode)
746 {
747     if (fontRenderingMode() == mode)
748         return;
749     m_fontRenderingMode = mode;
750     m_page->setNeedsRecalcStyleInAllFrames();
751 }
752
753 FontRenderingMode Settings::fontRenderingMode() const
754 {
755     return static_cast<FontRenderingMode>(m_fontRenderingMode);
756 }
757
758 void Settings::setNeedsSiteSpecificQuirks(bool needsQuirks)
759 {
760     m_needsSiteSpecificQuirks = needsQuirks;
761 }
762
763 void Settings::setFrameFlatteningEnabled(bool frameFlatteningEnabled)
764 {
765     m_frameFlatteningEnabled = frameFlatteningEnabled;
766 }
767
768 #if ENABLE(WEB_ARCHIVE)
769 void Settings::setWebArchiveDebugModeEnabled(bool enabled)
770 {
771     m_webArchiveDebugModeEnabled = enabled;
772 }
773 #endif
774
775 void Settings::setLocalFileContentSniffingEnabled(bool enabled)
776 {
777     m_localFileContentSniffingEnabled = enabled;
778 }
779
780 void Settings::setLocalStorageDatabasePath(const String& path)
781 {
782     m_localStorageDatabasePath = path;
783 }
784
785 void Settings::setApplicationChromeMode(bool mode)
786 {
787     m_inApplicationChromeMode = mode;
788 }
789
790 void Settings::setOfflineWebApplicationCacheEnabled(bool enabled)
791 {
792     m_offlineWebApplicationCacheEnabled = enabled;
793 }
794
795 void Settings::setEnforceCSSMIMETypeInNoQuirksMode(bool enforceCSSMIMETypeInNoQuirksMode)
796 {
797     m_enforceCSSMIMETypeInNoQuirksMode = enforceCSSMIMETypeInNoQuirksMode;
798 }
799
800 #if USE(SAFARI_THEME)
801 void Settings::setShouldPaintNativeControls(bool shouldPaintNativeControls)
802 {
803     gShouldPaintNativeControls = shouldPaintNativeControls;
804 }
805 #endif
806
807 void Settings::setUsesEncodingDetector(bool usesEncodingDetector)
808 {
809     m_usesEncodingDetector = usesEncodingDetector;
810 }
811
812 void Settings::setDNSPrefetchingEnabled(bool dnsPrefetchingEnabled)
813 {
814     if (m_dnsPrefetchingEnabled == dnsPrefetchingEnabled)
815         return;
816
817     m_dnsPrefetchingEnabled = dnsPrefetchingEnabled;
818     m_page->dnsPrefetchingStateChanged();
819 }
820
821 void Settings::setAllowScriptsToCloseWindows(bool allowScriptsToCloseWindows)
822 {
823     m_allowScriptsToCloseWindows = allowScriptsToCloseWindows;
824 }
825
826 void Settings::setCaretBrowsingEnabled(bool caretBrowsingEnabled)
827 {
828     m_caretBrowsingEnabled = caretBrowsingEnabled;
829 }
830
831 void Settings::setDownloadableBinaryFontsEnabled(bool downloadableBinaryFontsEnabled)
832 {
833     m_downloadableBinaryFontsEnabled = downloadableBinaryFontsEnabled;
834 }
835
836 void Settings::setXSSAuditorEnabled(bool xssAuditorEnabled)
837 {
838     m_xssAuditorEnabled = xssAuditorEnabled;
839 }
840
841 void Settings::setAcceleratedCompositingEnabled(bool enabled)
842 {
843     if (m_acceleratedCompositingEnabled == enabled)
844         return;
845         
846     m_acceleratedCompositingEnabled = enabled;
847     m_page->setNeedsRecalcStyleInAllFrames();
848 }
849
850 void Settings::setCanvasUsesAcceleratedDrawing(bool enabled)
851 {
852     m_canvasUsesAcceleratedDrawing = enabled;
853 }
854
855 void Settings::setAcceleratedCompositingFor3DTransformsEnabled(bool enabled)
856 {
857     m_acceleratedCompositingFor3DTransformsEnabled = enabled;
858 }
859
860 void Settings::setAcceleratedCompositingForVideoEnabled(bool enabled)
861 {
862     m_acceleratedCompositingForVideoEnabled = enabled;
863 }
864
865 void Settings::setAcceleratedCompositingForPluginsEnabled(bool enabled)
866 {
867     m_acceleratedCompositingForPluginsEnabled = enabled;
868 }
869
870 void Settings::setAcceleratedCompositingForCanvasEnabled(bool enabled)
871 {
872     m_acceleratedCompositingForCanvasEnabled = enabled;
873 }
874
875 void Settings::setAcceleratedCompositingForAnimationEnabled(bool enabled)
876 {
877     m_acceleratedCompositingForAnimationEnabled = enabled;
878 }
879
880 void Settings::setShowDebugBorders(bool enabled)
881 {
882     if (m_showDebugBorders == enabled)
883         return;
884         
885     m_showDebugBorders = enabled;
886     m_page->setNeedsRecalcStyleInAllFrames();
887 }
888
889 void Settings::setShowRepaintCounter(bool enabled)
890 {
891     if (m_showRepaintCounter == enabled)
892         return;
893         
894     m_showRepaintCounter = enabled;
895     m_page->setNeedsRecalcStyleInAllFrames();
896 }
897
898 void Settings::setExperimentalNotificationsEnabled(bool enabled)
899 {
900     m_experimentalNotificationsEnabled = enabled;
901 }
902
903 #if PLATFORM(WIN) || (OS(WINDOWS) && PLATFORM(WX))
904 void Settings::setShouldUseHighResolutionTimers(bool shouldUseHighResolutionTimers)
905 {
906     gShouldUseHighResolutionTimers = shouldUseHighResolutionTimers;
907 }
908 #endif
909
910 void Settings::setWebAudioEnabled(bool enabled)
911 {
912     m_webAudioEnabled = enabled;
913 }
914
915 void Settings::setWebGLEnabled(bool enabled)
916 {
917     m_webGLEnabled = enabled;
918 }
919
920 void Settings::setWebGLErrorsToConsoleEnabled(bool enabled)
921 {
922     m_webGLErrorsToConsoleEnabled = enabled;
923 }
924
925 void Settings::setOpenGLMultisamplingEnabled(bool enabled)
926 {
927     m_openGLMultisamplingEnabled = enabled;
928 }
929
930 void Settings::setPrivilegedWebGLExtensionsEnabled(bool enabled)
931 {
932     m_privilegedWebGLExtensionsEnabled = enabled;
933 }
934
935 void Settings::setAccelerated2dCanvasEnabled(bool enabled)
936 {
937     m_acceleratedCanvas2dEnabled = enabled;
938 }
939
940 void Settings::setDeferred2dCanvasEnabled(bool enabled)
941 {
942     m_deferredCanvas2dEnabled = enabled;
943 }
944
945 void Settings::setMinimumAccelerated2dCanvasSize(int numPixels)
946 {
947     m_minimumAccelerated2dCanvasSize = numPixels;
948 }
949
950 void Settings::setLoadDeferringEnabled(bool enabled)
951 {
952     m_loadDeferringEnabled = enabled;
953 }
954
955 void Settings::setTiledBackingStoreEnabled(bool enabled)
956 {
957     m_tiledBackingStoreEnabled = enabled;
958 #if USE(TILED_BACKING_STORE)
959     if (m_page->mainFrame())
960         m_page->mainFrame()->setTiledBackingStoreEnabled(enabled);
961 #endif
962 }
963
964 void Settings::setMockScrollbarsEnabled(bool flag)
965 {
966     gMockScrollbarsEnabled = flag;
967 }
968
969 bool Settings::mockScrollbarsEnabled()
970 {
971     return gMockScrollbarsEnabled;
972 }
973
974 #if ENABLE(TIZEN_LOAD_REMOTE_IMAGES)
975 void Settings::setLoadRemoteImages(bool loadRemoteImages)
976 {
977     m_loadRemoteImages = loadRemoteImages;
978
979     m_loadRemoteImagesTimer.startOneShot(0);
980 }
981
982 void Settings::loadRemoteImagesTimerFired(Timer<Settings>*)
983 {
984     setLoadsRemoteImagesInAllFrames(m_page);
985 }
986 #endif
987
988 #if USE(JSC)
989 void Settings::setShouldRespectPriorityInCSSAttributeSetters(bool flag)
990 {
991     gShouldRespectPriorityInCSSAttributeSetters = flag;
992 }
993
994 bool Settings::shouldRespectPriorityInCSSAttributeSetters()
995 {
996     return gShouldRespectPriorityInCSSAttributeSetters;
997 }
998 #endif
999
1000 } // namespace WebCore