2 * Copyright (C) 2006, 2007 Apple Computer, 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.
29 #include "DatabaseTracker.h"
31 #include "FrameTree.h"
33 #include "PageCache.h"
34 #include "HistoryItem.h"
38 static void setNeedsReapplyStylesInAllFrames(Page* page)
40 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext())
41 frame->setNeedsReapplyStyles();
44 Settings::Settings(Page* page)
46 , m_editableLinkBehavior(EditableLinkDefaultBehavior)
47 , m_minimumFontSize(0)
48 , m_minimumLogicalFontSize(0)
49 , m_defaultFontSize(0)
50 , m_defaultFixedFontSize(0)
51 , m_isJavaEnabled(false)
52 , m_loadsImagesAutomatically(false)
53 , m_privateBrowsingEnabled(false)
54 , m_arePluginsEnabled(false)
55 , m_isJavaScriptEnabled(false)
56 , m_javaScriptCanOpenWindowsAutomatically(false)
57 , m_shouldPrintBackgrounds(false)
58 , m_textAreasAreResizable(false)
59 , m_usesDashboardBackwardCompatibilityMode(false)
60 , m_needsAdobeFrameReloadingQuirk(false)
61 , m_needsKeyboardEventDisambiguationQuirks(false)
62 , m_isDOMPasteAllowed(false)
63 , m_shrinksStandaloneImagesToFit(true)
64 , m_usesPageCache(false)
65 , m_showsURLsInToolTips(false)
66 , m_forceFTPDirectoryListings(false)
67 , m_developerExtrasEnabled(false)
68 , m_authorAndUserStylesEnabled(true)
70 // A Frame may not have been created yet, so we initialize the AtomicString
71 // hash before trying to use it.
75 void Settings::setStandardFontFamily(const AtomicString& standardFontFamily)
77 if (standardFontFamily == m_standardFontFamily)
80 m_standardFontFamily = standardFontFamily;
81 setNeedsReapplyStylesInAllFrames(m_page);
84 void Settings::setFixedFontFamily(const AtomicString& fixedFontFamily)
86 if (m_fixedFontFamily == fixedFontFamily)
89 m_fixedFontFamily = fixedFontFamily;
90 setNeedsReapplyStylesInAllFrames(m_page);
93 void Settings::setSerifFontFamily(const AtomicString& serifFontFamily)
95 if (m_serifFontFamily == serifFontFamily)
98 m_serifFontFamily = serifFontFamily;
99 setNeedsReapplyStylesInAllFrames(m_page);
102 void Settings::setSansSerifFontFamily(const AtomicString& sansSerifFontFamily)
104 if (m_sansSerifFontFamily == sansSerifFontFamily)
107 m_sansSerifFontFamily = sansSerifFontFamily;
108 setNeedsReapplyStylesInAllFrames(m_page);
111 void Settings::setCursiveFontFamily(const AtomicString& cursiveFontFamily)
113 if (m_cursiveFontFamily == cursiveFontFamily)
116 m_cursiveFontFamily = cursiveFontFamily;
117 setNeedsReapplyStylesInAllFrames(m_page);
120 void Settings::setFantasyFontFamily(const AtomicString& fantasyFontFamily)
122 if (m_fantasyFontFamily == fantasyFontFamily)
125 m_fantasyFontFamily = fantasyFontFamily;
126 setNeedsReapplyStylesInAllFrames(m_page);
129 void Settings::setMinimumFontSize(int minimumFontSize)
131 if (m_minimumFontSize == minimumFontSize)
134 m_minimumFontSize = minimumFontSize;
135 setNeedsReapplyStylesInAllFrames(m_page);
138 void Settings::setMinimumLogicalFontSize(int minimumLogicalFontSize)
140 if (m_minimumLogicalFontSize == minimumLogicalFontSize)
143 m_minimumLogicalFontSize = minimumLogicalFontSize;
144 setNeedsReapplyStylesInAllFrames(m_page);
147 void Settings::setDefaultFontSize(int defaultFontSize)
149 if (m_defaultFontSize == defaultFontSize)
152 m_defaultFontSize = defaultFontSize;
153 setNeedsReapplyStylesInAllFrames(m_page);
156 void Settings::setDefaultFixedFontSize(int defaultFontSize)
158 if (m_defaultFixedFontSize == defaultFontSize)
161 m_defaultFixedFontSize = defaultFontSize;
162 setNeedsReapplyStylesInAllFrames(m_page);
165 void Settings::setLoadsImagesAutomatically(bool loadsImagesAutomatically)
167 m_loadsImagesAutomatically = loadsImagesAutomatically;
170 void Settings::setJavaScriptEnabled(bool isJavaScriptEnabled)
172 m_isJavaScriptEnabled = isJavaScriptEnabled;
175 void Settings::setJavaEnabled(bool isJavaEnabled)
177 m_isJavaEnabled = isJavaEnabled;
180 void Settings::setPluginsEnabled(bool arePluginsEnabled)
182 m_arePluginsEnabled = arePluginsEnabled;
185 void Settings::setPrivateBrowsingEnabled(bool privateBrowsingEnabled)
187 m_privateBrowsingEnabled = privateBrowsingEnabled;
190 void Settings::setJavaScriptCanOpenWindowsAutomatically(bool javaScriptCanOpenWindowsAutomatically)
192 m_javaScriptCanOpenWindowsAutomatically = javaScriptCanOpenWindowsAutomatically;
195 void Settings::setDefaultTextEncodingName(const String& defaultTextEncodingName)
197 m_defaultTextEncodingName = defaultTextEncodingName;
200 void Settings::setUserStyleSheetLocation(const KURL& userStyleSheetLocation)
202 if (m_userStyleSheetLocation == userStyleSheetLocation)
205 m_userStyleSheetLocation = userStyleSheetLocation;
206 setNeedsReapplyStylesInAllFrames(m_page);
209 void Settings::setShouldPrintBackgrounds(bool shouldPrintBackgrounds)
211 m_shouldPrintBackgrounds = shouldPrintBackgrounds;
214 void Settings::setTextAreasAreResizable(bool textAreasAreResizable)
216 if (m_textAreasAreResizable == textAreasAreResizable)
219 m_textAreasAreResizable = textAreasAreResizable;
220 setNeedsReapplyStylesInAllFrames(m_page);
223 void Settings::setEditableLinkBehavior(EditableLinkBehavior editableLinkBehavior)
225 m_editableLinkBehavior = editableLinkBehavior;
228 void Settings::setUsesDashboardBackwardCompatibilityMode(bool usesDashboardBackwardCompatibilityMode)
230 m_usesDashboardBackwardCompatibilityMode = usesDashboardBackwardCompatibilityMode;
233 // FIXME: This quirk is needed because of Radar 4674537 and 5211271. We need to phase it out once Adobe
234 // can fix the bug from their end.
235 void Settings::setNeedsAdobeFrameReloadingQuirk(bool shouldNotReloadIFramesForUnchangedSRC)
237 m_needsAdobeFrameReloadingQuirk = shouldNotReloadIFramesForUnchangedSRC;
240 // This is a quirk we are pro-actively applying to old applications. It changes keyboard event dispatching,
241 // making keyIdentifier available on keypress events, making charCode available on keydown/keyup events,
242 // and getting keypress dispatched in more cases.
243 void Settings::setNeedsKeyboardEventDisambiguationQuirks(bool needsQuirks)
245 m_needsKeyboardEventDisambiguationQuirks = needsQuirks;
248 void Settings::setDOMPasteAllowed(bool DOMPasteAllowed)
250 m_isDOMPasteAllowed = DOMPasteAllowed;
253 void Settings::setUsesPageCache(bool usesPageCache)
255 if (m_usesPageCache == usesPageCache)
258 m_usesPageCache = usesPageCache;
259 if (!m_usesPageCache) {
260 HistoryItemVector& historyItems = m_page->backForwardList()->entries();
261 for (unsigned i = 0; i < historyItems.size(); i++)
262 pageCache()->remove(historyItems[i].get());
263 pageCache()->releaseAutoreleasedPagesNow();
267 void Settings::setShrinksStandaloneImagesToFit(bool shrinksStandaloneImagesToFit)
269 m_shrinksStandaloneImagesToFit = shrinksStandaloneImagesToFit;
272 void Settings::setShowsURLsInToolTips(bool showsURLsInToolTips)
274 m_showsURLsInToolTips = showsURLsInToolTips;
277 void Settings::setFTPDirectoryTemplatePath(const String& path)
279 m_ftpDirectoryTemplatePath = path;
282 void Settings::setForceFTPDirectoryListings(bool force)
284 m_forceFTPDirectoryListings = force;
287 void Settings::setDeveloperExtrasEnabled(bool developerExtrasEnabled)
289 m_developerExtrasEnabled = developerExtrasEnabled;
292 void Settings::setAuthorAndUserStylesEnabled(bool authorAndUserStylesEnabled)
294 if (m_authorAndUserStylesEnabled == authorAndUserStylesEnabled)
297 m_authorAndUserStylesEnabled = authorAndUserStylesEnabled;
298 setNeedsReapplyStylesInAllFrames(m_page);
301 void Settings::setDefaultDatabaseOriginQuota(unsigned long long quota)
304 DatabaseTracker::tracker().setDefaultOriginQuota(quota);
308 unsigned long long Settings::defaultDatabaseOriginQuota() const
311 return DatabaseTracker::tracker().defaultOriginQuota();
317 } // namespace WebCore