2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
30 #include "FrameTree.h"
31 #include "HistoryItem.h"
32 #include "JavaScriptDebugServer.h"
34 #include "PageCache.h"
37 #include "DatabaseTracker.h"
42 static void setNeedsReapplyStylesInAllFrames(Page* page)
44 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext())
45 frame->setNeedsReapplyStyles();
49 bool Settings::gShouldPaintNativeControls = false;
52 Settings::Settings(Page* page)
54 , m_editableLinkBehavior(EditableLinkDefaultBehavior)
55 , m_minimumFontSize(0)
56 , m_minimumLogicalFontSize(0)
57 , m_defaultFontSize(0)
58 , m_defaultFixedFontSize(0)
59 , m_isJavaEnabled(false)
60 , m_loadsImagesAutomatically(false)
61 , m_privateBrowsingEnabled(false)
62 , m_arePluginsEnabled(false)
63 , m_isJavaScriptEnabled(false)
64 , m_javaScriptCanOpenWindowsAutomatically(false)
65 , m_shouldPrintBackgrounds(false)
66 , m_textAreasAreResizable(false)
67 #if ENABLE(DASHBOARD_SUPPORT)
68 , m_usesDashboardBackwardCompatibilityMode(false)
70 , m_needsAdobeFrameReloadingQuirk(false)
71 , m_needsKeyboardEventDisambiguationQuirks(false)
72 , m_isDOMPasteAllowed(false)
73 , m_shrinksStandaloneImagesToFit(true)
74 , m_usesPageCache(false)
75 , m_showsURLsInToolTips(false)
76 , m_forceFTPDirectoryListings(false)
77 , m_developerExtrasEnabled(false)
78 , m_didInitializeDeveloperExtrasEnabled(false)
79 , m_authorAndUserStylesEnabled(true)
80 , m_needsSiteSpecificQuirks(false)
81 , m_fontRenderingMode(0)
82 , m_webArchiveDebugModeEnabled(false)
83 , m_inApplicationChromeMode(false)
84 , m_offlineWebApplicationCacheEnabled(false)
85 , m_rangeMutationDisabledForOldAppleMail(false)
86 , m_shouldPaintCustomScrollbars(false)
87 , m_zoomsTextOnly(false)
88 , m_enforceCSSMIMETypeInStrictMode(true)
90 // A Frame may not have been created yet, so we initialize the AtomicString
91 // hash before trying to use it.
95 void Settings::setStandardFontFamily(const AtomicString& standardFontFamily)
97 if (standardFontFamily == m_standardFontFamily)
100 m_standardFontFamily = standardFontFamily;
101 setNeedsReapplyStylesInAllFrames(m_page);
104 void Settings::setFixedFontFamily(const AtomicString& fixedFontFamily)
106 if (m_fixedFontFamily == fixedFontFamily)
109 m_fixedFontFamily = fixedFontFamily;
110 setNeedsReapplyStylesInAllFrames(m_page);
113 void Settings::setSerifFontFamily(const AtomicString& serifFontFamily)
115 if (m_serifFontFamily == serifFontFamily)
118 m_serifFontFamily = serifFontFamily;
119 setNeedsReapplyStylesInAllFrames(m_page);
122 void Settings::setSansSerifFontFamily(const AtomicString& sansSerifFontFamily)
124 if (m_sansSerifFontFamily == sansSerifFontFamily)
127 m_sansSerifFontFamily = sansSerifFontFamily;
128 setNeedsReapplyStylesInAllFrames(m_page);
131 void Settings::setCursiveFontFamily(const AtomicString& cursiveFontFamily)
133 if (m_cursiveFontFamily == cursiveFontFamily)
136 m_cursiveFontFamily = cursiveFontFamily;
137 setNeedsReapplyStylesInAllFrames(m_page);
140 void Settings::setFantasyFontFamily(const AtomicString& fantasyFontFamily)
142 if (m_fantasyFontFamily == fantasyFontFamily)
145 m_fantasyFontFamily = fantasyFontFamily;
146 setNeedsReapplyStylesInAllFrames(m_page);
149 void Settings::setMinimumFontSize(int minimumFontSize)
151 if (m_minimumFontSize == minimumFontSize)
154 m_minimumFontSize = minimumFontSize;
155 setNeedsReapplyStylesInAllFrames(m_page);
158 void Settings::setMinimumLogicalFontSize(int minimumLogicalFontSize)
160 if (m_minimumLogicalFontSize == minimumLogicalFontSize)
163 m_minimumLogicalFontSize = minimumLogicalFontSize;
164 setNeedsReapplyStylesInAllFrames(m_page);
167 void Settings::setDefaultFontSize(int defaultFontSize)
169 if (m_defaultFontSize == defaultFontSize)
172 m_defaultFontSize = defaultFontSize;
173 setNeedsReapplyStylesInAllFrames(m_page);
176 void Settings::setDefaultFixedFontSize(int defaultFontSize)
178 if (m_defaultFixedFontSize == defaultFontSize)
181 m_defaultFixedFontSize = defaultFontSize;
182 setNeedsReapplyStylesInAllFrames(m_page);
185 void Settings::setLoadsImagesAutomatically(bool loadsImagesAutomatically)
187 m_loadsImagesAutomatically = loadsImagesAutomatically;
190 void Settings::setJavaScriptEnabled(bool isJavaScriptEnabled)
192 m_isJavaScriptEnabled = isJavaScriptEnabled;
195 void Settings::setJavaEnabled(bool isJavaEnabled)
197 m_isJavaEnabled = isJavaEnabled;
200 void Settings::setPluginsEnabled(bool arePluginsEnabled)
202 m_arePluginsEnabled = arePluginsEnabled;
205 void Settings::setPrivateBrowsingEnabled(bool privateBrowsingEnabled)
207 m_privateBrowsingEnabled = privateBrowsingEnabled;
210 void Settings::setJavaScriptCanOpenWindowsAutomatically(bool javaScriptCanOpenWindowsAutomatically)
212 m_javaScriptCanOpenWindowsAutomatically = javaScriptCanOpenWindowsAutomatically;
215 void Settings::setDefaultTextEncodingName(const String& defaultTextEncodingName)
217 m_defaultTextEncodingName = defaultTextEncodingName;
220 void Settings::setUserStyleSheetLocation(const KURL& userStyleSheetLocation)
222 if (m_userStyleSheetLocation == userStyleSheetLocation)
225 m_userStyleSheetLocation = userStyleSheetLocation;
227 m_page->userStyleSheetLocationChanged();
228 setNeedsReapplyStylesInAllFrames(m_page);
231 void Settings::setShouldPrintBackgrounds(bool shouldPrintBackgrounds)
233 m_shouldPrintBackgrounds = shouldPrintBackgrounds;
236 void Settings::setTextAreasAreResizable(bool textAreasAreResizable)
238 if (m_textAreasAreResizable == textAreasAreResizable)
241 m_textAreasAreResizable = textAreasAreResizable;
242 setNeedsReapplyStylesInAllFrames(m_page);
245 void Settings::setEditableLinkBehavior(EditableLinkBehavior editableLinkBehavior)
247 m_editableLinkBehavior = editableLinkBehavior;
250 #if ENABLE(DASHBOARD_SUPPORT)
251 void Settings::setUsesDashboardBackwardCompatibilityMode(bool usesDashboardBackwardCompatibilityMode)
253 m_usesDashboardBackwardCompatibilityMode = usesDashboardBackwardCompatibilityMode;
257 // FIXME: This quirk is needed because of Radar 4674537 and 5211271. We need to phase it out once Adobe
258 // can fix the bug from their end.
259 void Settings::setNeedsAdobeFrameReloadingQuirk(bool shouldNotReloadIFramesForUnchangedSRC)
261 m_needsAdobeFrameReloadingQuirk = shouldNotReloadIFramesForUnchangedSRC;
264 // This is a quirk we are pro-actively applying to old applications. It changes keyboard event dispatching,
265 // making keyIdentifier available on keypress events, making charCode available on keydown/keyup events,
266 // and getting keypress dispatched in more cases.
267 void Settings::setNeedsKeyboardEventDisambiguationQuirks(bool needsQuirks)
269 m_needsKeyboardEventDisambiguationQuirks = needsQuirks;
272 void Settings::setDOMPasteAllowed(bool DOMPasteAllowed)
274 m_isDOMPasteAllowed = DOMPasteAllowed;
277 void Settings::setUsesPageCache(bool usesPageCache)
279 if (m_usesPageCache == usesPageCache)
282 m_usesPageCache = usesPageCache;
283 if (!m_usesPageCache) {
284 HistoryItemVector& historyItems = m_page->backForwardList()->entries();
285 for (unsigned i = 0; i < historyItems.size(); i++)
286 pageCache()->remove(historyItems[i].get());
287 pageCache()->releaseAutoreleasedPagesNow();
291 void Settings::setShrinksStandaloneImagesToFit(bool shrinksStandaloneImagesToFit)
293 m_shrinksStandaloneImagesToFit = shrinksStandaloneImagesToFit;
296 void Settings::setShowsURLsInToolTips(bool showsURLsInToolTips)
298 m_showsURLsInToolTips = showsURLsInToolTips;
301 void Settings::setFTPDirectoryTemplatePath(const String& path)
303 m_ftpDirectoryTemplatePath = path;
306 void Settings::setForceFTPDirectoryListings(bool force)
308 m_forceFTPDirectoryListings = force;
311 void Settings::setDeveloperExtrasEnabled(bool developerExtrasEnabled)
313 if (m_developerExtrasEnabled == developerExtrasEnabled)
316 m_developerExtrasEnabled = developerExtrasEnabled;
318 // Avoid recompiling when initializing a page.
319 if (!m_didInitializeDeveloperExtrasEnabled) {
320 m_didInitializeDeveloperExtrasEnabled = true;
324 JavaScriptDebugServer::shared().recompileAllJSFunctionsSoon();
327 void Settings::setAuthorAndUserStylesEnabled(bool authorAndUserStylesEnabled)
329 if (m_authorAndUserStylesEnabled == authorAndUserStylesEnabled)
332 m_authorAndUserStylesEnabled = authorAndUserStylesEnabled;
333 setNeedsReapplyStylesInAllFrames(m_page);
336 void Settings::setFontRenderingMode(FontRenderingMode mode)
338 if (fontRenderingMode() == mode)
340 m_fontRenderingMode = mode;
341 setNeedsReapplyStylesInAllFrames(m_page);
344 FontRenderingMode Settings::fontRenderingMode() const
346 return static_cast<FontRenderingMode>(m_fontRenderingMode);
349 void Settings::setNeedsSiteSpecificQuirks(bool needsQuirks)
351 m_needsSiteSpecificQuirks = needsQuirks;
354 void Settings::setWebArchiveDebugModeEnabled(bool enabled)
356 m_webArchiveDebugModeEnabled = enabled;
359 void Settings::setLocalStorageDatabasePath(const String& path)
361 m_localStorageDatabasePath = path;
364 void Settings::disableRangeMutationForOldAppleMail(bool disable)
366 m_rangeMutationDisabledForOldAppleMail = disable;
369 void Settings::setApplicationChromeMode(bool mode)
371 m_inApplicationChromeMode = mode;
374 void Settings::setOfflineWebApplicationCacheEnabled(bool enabled)
376 m_offlineWebApplicationCacheEnabled = enabled;
379 void Settings::setShouldPaintCustomScrollbars(bool shouldPaintCustomScrollbars)
381 m_shouldPaintCustomScrollbars = shouldPaintCustomScrollbars;
384 void Settings::setZoomsTextOnly(bool zoomsTextOnly)
386 if (zoomsTextOnly == m_zoomsTextOnly)
389 m_zoomsTextOnly = zoomsTextOnly;
390 setNeedsReapplyStylesInAllFrames(m_page);
393 void Settings::setEnforceCSSMIMETypeInStrictMode(bool enforceCSSMIMETypeInStrictMode)
395 m_enforceCSSMIMETypeInStrictMode = enforceCSSMIMETypeInStrictMode;
398 #if USE(SAFARI_THEME)
399 void Settings::setShouldPaintNativeControls(bool shouldPaintNativeControls)
401 gShouldPaintNativeControls = shouldPaintNativeControls;
405 } // namespace WebCore