|
1 /* |
|
2 * Copyright (C) 2006, 2007 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 "WebKitDLL.h" |
|
28 #include "WebPreferences.h" |
|
29 |
|
30 #include "WebNotificationCenter.h" |
|
31 #include "WebPreferenceKeysPrivate.h" |
|
32 |
|
33 #pragma warning( push, 0 ) |
|
34 #include <WebCore/Font.h> |
|
35 #include <WebCore/PlatformString.h> |
|
36 #include <WebCore/StringHash.h> |
|
37 #include "WebLocalizableStrings.h" |
|
38 #pragma warning( pop ) |
|
39 |
|
40 #include <CoreFoundation/CoreFoundation.h> |
|
41 #include <CoreGraphics/CoreGraphics.h> |
|
42 #include <shlobj.h> |
|
43 #include <shfolder.h> |
|
44 #include <tchar.h> |
|
45 #include <WebKitSystemInterface/WebKitSystemInterface.h> |
|
46 #include <wtf/HashMap.h> |
|
47 #include <wtf/OwnPtr.h> |
|
48 #include <wtf/Vector.h> |
|
49 |
|
50 #include <initguid.h> |
|
51 // {A20B5645-692D-4147-BF80-E8CD84BE82A1} |
|
52 DEFINE_GUID(IID_WebPreferences, 0xa20b5645, 0x692d, 0x4147, 0xbf, 0x80, 0xe8, 0xcd, 0x84, 0xbe, 0x82, 0xa1); |
|
53 |
|
54 static unsigned long long WebSystemMainMemory() |
|
55 { |
|
56 MEMORYSTATUSEX statex; |
|
57 |
|
58 statex.dwLength = sizeof(statex); |
|
59 GlobalMemoryStatusEx(&statex); |
|
60 return statex.ullTotalPhys; |
|
61 } |
|
62 |
|
63 // WebPreferences ---------------------------------------------------------------- |
|
64 |
|
65 CFDictionaryRef WebPreferences::s_defaultSettings = 0; |
|
66 |
|
67 static HashMap<WebCore::String, WebPreferences*> webPreferencesInstances; |
|
68 |
|
69 WebPreferences* WebPreferences::sharedStandardPreferences() |
|
70 { |
|
71 static WebPreferences* standardPreferences; |
|
72 if (!standardPreferences) { |
|
73 standardPreferences = WebPreferences::createInstance(); |
|
74 standardPreferences->load(); |
|
75 standardPreferences->setAutosaves(TRUE); |
|
76 standardPreferences->postPreferencesChangesNotification(); |
|
77 } |
|
78 |
|
79 return standardPreferences; |
|
80 } |
|
81 |
|
82 WebPreferences::WebPreferences() |
|
83 : m_refCount(0) |
|
84 , m_autoSaves(0) |
|
85 { |
|
86 gClassCount++; |
|
87 } |
|
88 |
|
89 WebPreferences::~WebPreferences() |
|
90 { |
|
91 gClassCount--; |
|
92 } |
|
93 |
|
94 WebPreferences* WebPreferences::createInstance() |
|
95 { |
|
96 WebPreferences* instance = new WebPreferences(); |
|
97 instance->AddRef(); |
|
98 return instance; |
|
99 } |
|
100 |
|
101 HRESULT WebPreferences::postPreferencesChangesNotification() |
|
102 { |
|
103 IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal(); |
|
104 HRESULT hr = nc->postNotificationName(webPreferencesChangedNotification(), static_cast<IWebPreferences*>(this), 0); |
|
105 if (FAILED(hr)) |
|
106 return hr; |
|
107 |
|
108 return S_OK; |
|
109 } |
|
110 |
|
111 WebPreferences* WebPreferences::getInstanceForIdentifier(BSTR identifier) |
|
112 { |
|
113 if (!identifier) |
|
114 return sharedStandardPreferences(); |
|
115 |
|
116 WebCore::String identifierString(identifier, SysStringLen(identifier)); |
|
117 return webPreferencesInstances.get(identifierString); |
|
118 } |
|
119 |
|
120 void WebPreferences::setInstance(WebPreferences* instance, BSTR identifier) |
|
121 { |
|
122 if (!identifier || !instance) |
|
123 return; |
|
124 WebCore::String identifierString(identifier, SysStringLen(identifier)); |
|
125 webPreferencesInstances.add(identifierString, instance); |
|
126 } |
|
127 |
|
128 void WebPreferences::removeReferenceForIdentifier(BSTR identifier) |
|
129 { |
|
130 if (!identifier || webPreferencesInstances.isEmpty()) |
|
131 return; |
|
132 |
|
133 WebCore::String identifierString(identifier, SysStringLen(identifier)); |
|
134 WebPreferences* webPreference = webPreferencesInstances.get(identifierString); |
|
135 if (webPreference && webPreference->m_refCount == 1) |
|
136 webPreferencesInstances.remove(identifierString); |
|
137 } |
|
138 |
|
139 void WebPreferences::initializeDefaultSettings() |
|
140 { |
|
141 if (s_defaultSettings) |
|
142 return; |
|
143 |
|
144 CFMutableDictionaryRef defaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); |
|
145 |
|
146 // As a fudge factor, use 1000 instead of 1024, in case the reported memory doesn't align exactly to a megabyte boundary. |
|
147 unsigned long long memSize = WebSystemMainMemory() / 1024 / 1000; |
|
148 |
|
149 // Page cache size (in pages) |
|
150 int pageCacheSize; |
|
151 if (memSize >= 1024) |
|
152 pageCacheSize = 10; |
|
153 else if (memSize >= 512) |
|
154 pageCacheSize = 5; |
|
155 else if (memSize >= 384) |
|
156 pageCacheSize = 4; |
|
157 else if (memSize >= 256) |
|
158 pageCacheSize = 3; |
|
159 else if (memSize >= 128) |
|
160 pageCacheSize = 2; |
|
161 else if (memSize >= 64) |
|
162 pageCacheSize = 1; |
|
163 else |
|
164 pageCacheSize = 0; |
|
165 |
|
166 // Object cache size (in bytes) |
|
167 int objectCacheSize; |
|
168 if (memSize >= 2048) |
|
169 objectCacheSize = 128 * 1024 * 1024; |
|
170 else if (memSize >= 1024) |
|
171 objectCacheSize = 64 * 1024 * 1024; |
|
172 else if (memSize >= 512) |
|
173 objectCacheSize = 32 * 1024 * 1024; |
|
174 else |
|
175 objectCacheSize = 24 * 1024 * 1024; |
|
176 |
|
177 CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman")); |
|
178 CFDictionaryAddValue(defaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New")); |
|
179 CFDictionaryAddValue(defaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman")); |
|
180 CFDictionaryAddValue(defaults, CFSTR(WebKitSansSerifFontPreferenceKey), CFSTR("Arial")); |
|
181 CFDictionaryAddValue(defaults, CFSTR(WebKitCursiveFontPreferenceKey), CFSTR("Comic Sans MS")); |
|
182 CFDictionaryAddValue(defaults, CFSTR(WebKitFantasyFontPreferenceKey), CFSTR("Comic Sans MS")); |
|
183 CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumFontSizePreferenceKey), CFSTR("1")); |
|
184 CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), CFSTR("9")); |
|
185 CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFontSizePreferenceKey), CFSTR("16")); |
|
186 CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFixedFontSizePreferenceKey), CFSTR("13")); |
|
187 WebCore::String defaultDefaultEncoding(LPCTSTR_UI_STRING("ISO-8859-1", "The default, default character encoding")); |
|
188 CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), defaultDefaultEncoding.createCFString()); |
|
189 |
|
190 RetainPtr<CFStringRef> pageCacheSizeString(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), pageCacheSize)); |
|
191 CFDictionaryAddValue(defaults, CFSTR(WebKitPageCacheSizePreferenceKey), pageCacheSizeString.get()); |
|
192 |
|
193 RetainPtr<CFStringRef> objectCacheSizeString(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), objectCacheSize)); |
|
194 CFDictionaryAddValue(defaults, CFSTR(WebKitObjectCacheSizePreferenceKey), objectCacheSizeString.get()); |
|
195 |
|
196 CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), kCFBooleanFalse); |
|
197 CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetLocationPreferenceKey), CFSTR("")); |
|
198 CFDictionaryAddValue(defaults, CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), kCFBooleanFalse); |
|
199 CFDictionaryAddValue(defaults, CFSTR(WebKitTextAreasAreResizablePreferenceKey), kCFBooleanFalse); |
|
200 CFDictionaryAddValue(defaults, CFSTR(WebKitJavaEnabledPreferenceKey), kCFBooleanTrue); |
|
201 CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptEnabledPreferenceKey), kCFBooleanTrue); |
|
202 CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), kCFBooleanTrue); |
|
203 CFDictionaryAddValue(defaults, CFSTR(WebKitPluginsEnabledPreferenceKey), kCFBooleanTrue); |
|
204 CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImagesPreferenceKey), kCFBooleanTrue); |
|
205 CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), kCFBooleanTrue); |
|
206 CFDictionaryAddValue(defaults, CFSTR(WebKitDisplayImagesKey), kCFBooleanTrue); |
|
207 CFDictionaryAddValue(defaults, CFSTR(WebKitBackForwardCacheExpirationIntervalKey), CFSTR("1800")); |
|
208 CFDictionaryAddValue(defaults, CFSTR(WebKitTabToLinksPreferenceKey), kCFBooleanFalse); |
|
209 CFDictionaryAddValue(defaults, CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), kCFBooleanFalse); |
|
210 CFDictionaryAddValue(defaults, CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey), kCFBooleanFalse); |
|
211 CFDictionaryAddValue(defaults, CFSTR(WebKitShowsURLsInToolTipsPreferenceKey), kCFBooleanFalse); |
|
212 CFDictionaryAddValue(defaults, CFSTR(WebKitPDFDisplayModePreferenceKey), CFSTR("1")); |
|
213 CFDictionaryAddValue(defaults, CFSTR(WebKitPDFScaleFactorPreferenceKey), CFSTR("0")); |
|
214 |
|
215 RetainPtr<CFStringRef> linkBehaviorStringRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior)); |
|
216 CFDictionaryAddValue(defaults, CFSTR(WebKitEditableLinkBehaviorPreferenceKey), linkBehaviorStringRef.get()); |
|
217 |
|
218 CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryItemLimitKey), CFSTR("1000")); |
|
219 CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryAgeInDaysLimitKey), CFSTR("7")); |
|
220 CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseLocationKey), CFSTR("")); |
|
221 CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseEnabledPreferenceKey), kCFBooleanTrue); |
|
222 CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmothingTypePreferenceKey), CFSTR("2")); |
|
223 CFDictionaryAddValue(defaults, CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), CFSTR("2")); |
|
224 CFDictionaryAddValue(defaults, CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), kCFBooleanFalse); |
|
225 CFDictionaryAddValue(defaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse); |
|
226 CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue); |
|
227 CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue); |
|
228 |
|
229 s_defaultSettings = defaults; |
|
230 } |
|
231 |
|
232 const void* WebPreferences::valueForKey(CFStringRef key) |
|
233 { |
|
234 const void* value = CFDictionaryGetValue(m_privatePrefs.get(), key); |
|
235 if (!value) |
|
236 value = CFDictionaryGetValue(s_defaultSettings, key); |
|
237 |
|
238 return value; |
|
239 } |
|
240 |
|
241 BSTR WebPreferences::stringValueForKey(CFStringRef key) |
|
242 { |
|
243 CFStringRef str = (CFStringRef)valueForKey(key); |
|
244 |
|
245 if (!str || (CFGetTypeID(str) != CFStringGetTypeID())) |
|
246 return 0; |
|
247 |
|
248 CFIndex length = CFStringGetLength(str); |
|
249 const UniChar* uniChars = CFStringGetCharactersPtr(str); |
|
250 if (uniChars) |
|
251 return SysAllocStringLen((LPCTSTR)uniChars, length); |
|
252 |
|
253 BSTR bstr = SysAllocStringLen(0, length); |
|
254 if (!bstr) |
|
255 return 0; |
|
256 |
|
257 if (!CFStringGetCString(str, (char*)bstr, (length+1)*sizeof(WCHAR), kCFStringEncodingUTF16)) { |
|
258 SysFreeString(bstr); |
|
259 return 0; |
|
260 } |
|
261 |
|
262 bstr[length] = 0; |
|
263 return bstr; |
|
264 } |
|
265 |
|
266 int WebPreferences::integerValueForKey(CFStringRef key) |
|
267 { |
|
268 CFTypeRef cfVal = (CFStringRef)valueForKey(key); |
|
269 if (!cfVal) |
|
270 return 0; |
|
271 |
|
272 CFTypeID cfType = CFGetTypeID(cfVal); |
|
273 if (cfType == CFStringGetTypeID()) |
|
274 return CFStringGetIntValue((CFStringRef)cfVal); |
|
275 else if (cfType == CFBooleanGetTypeID()) { |
|
276 Boolean boolVal = CFBooleanGetValue((CFBooleanRef)cfVal); |
|
277 return (boolVal) ? 1 : 0; |
|
278 } |
|
279 else if (cfType == CFNumberGetTypeID()) { |
|
280 int val = 0; |
|
281 CFNumberGetValue((CFNumberRef)cfVal, kCFNumberSInt32Type, &val); |
|
282 return val; |
|
283 } |
|
284 |
|
285 return 0; |
|
286 } |
|
287 |
|
288 BOOL WebPreferences::boolValueForKey(CFStringRef key) |
|
289 { |
|
290 return (integerValueForKey(key) != 0); |
|
291 } |
|
292 |
|
293 float WebPreferences::floatValueForKey(CFStringRef key) |
|
294 { |
|
295 CFTypeRef cfVal = (CFStringRef)valueForKey(key); |
|
296 if (!cfVal) |
|
297 return 0.0; |
|
298 |
|
299 CFTypeID cfType = CFGetTypeID(cfVal); |
|
300 if (cfType == CFStringGetTypeID()) |
|
301 return (float)CFStringGetDoubleValue((CFStringRef)cfVal); |
|
302 else if (cfType == CFBooleanGetTypeID()) { |
|
303 Boolean boolVal = CFBooleanGetValue((CFBooleanRef)cfVal); |
|
304 return (boolVal) ? 1.0f : 0.0f; |
|
305 } |
|
306 else if (cfType == CFNumberGetTypeID()) { |
|
307 float val = 0.0; |
|
308 CFNumberGetValue((CFNumberRef)cfVal, kCFNumberFloatType, &val); |
|
309 return val; |
|
310 } |
|
311 |
|
312 return 0.0; |
|
313 } |
|
314 |
|
315 void WebPreferences::setStringValue(CFStringRef key, LPCTSTR value) |
|
316 { |
|
317 BSTR val = stringValueForKey(key); |
|
318 if (val && !_tcscmp(val, value)) |
|
319 return; |
|
320 SysFreeString(val); |
|
321 |
|
322 RetainPtr<CFStringRef> valueRef(AdoptCF, |
|
323 CFStringCreateWithCharactersNoCopy(0, (UniChar*)_wcsdup(value), (CFIndex)_tcslen(value), kCFAllocatorMalloc)); |
|
324 CFDictionarySetValue(m_privatePrefs.get(), key, valueRef.get()); |
|
325 if (m_autoSaves) |
|
326 save(); |
|
327 |
|
328 postPreferencesChangesNotification(); |
|
329 } |
|
330 |
|
331 BSTR WebPreferences::webPreferencesChangedNotification() |
|
332 { |
|
333 static BSTR webPreferencesChangedNotification = SysAllocString(WebPreferencesChangedNotification); |
|
334 return webPreferencesChangedNotification; |
|
335 } |
|
336 |
|
337 void WebPreferences::setIntegerValue(CFStringRef key, int value) |
|
338 { |
|
339 if (integerValueForKey(key) == value) |
|
340 return; |
|
341 |
|
342 RetainPtr<CFNumberRef> valueRef(AdoptCF, CFNumberCreate(0, kCFNumberSInt32Type, &value)); |
|
343 CFDictionarySetValue(m_privatePrefs.get(), key, valueRef.get()); |
|
344 if (m_autoSaves) |
|
345 save(); |
|
346 |
|
347 postPreferencesChangesNotification(); |
|
348 } |
|
349 |
|
350 void WebPreferences::setBoolValue(CFStringRef key, BOOL value) |
|
351 { |
|
352 if (boolValueForKey(key) == value) |
|
353 return; |
|
354 |
|
355 CFDictionarySetValue(m_privatePrefs.get(), key, value ? kCFBooleanTrue : kCFBooleanFalse); |
|
356 if (m_autoSaves) |
|
357 save(); |
|
358 |
|
359 postPreferencesChangesNotification(); |
|
360 } |
|
361 |
|
362 void WebPreferences::save() |
|
363 { |
|
364 TCHAR appDataPath[MAX_PATH]; |
|
365 if (FAILED(preferencesPath(appDataPath, MAX_PATH))) |
|
366 return; |
|
367 |
|
368 RetainPtr<CFWriteStreamRef> stream(AdoptCF, |
|
369 CFWriteStreamCreateWithAllocatedBuffers(kCFAllocatorDefault, kCFAllocatorDefault)); |
|
370 if (!stream) |
|
371 return; |
|
372 |
|
373 if (!CFWriteStreamOpen(stream.get())) |
|
374 return; |
|
375 |
|
376 if (!CFPropertyListWriteToStream(m_privatePrefs.get(), stream.get(), kCFPropertyListXMLFormat_v1_0, 0)) { |
|
377 CFWriteStreamClose(stream.get()); |
|
378 return; |
|
379 } |
|
380 CFWriteStreamClose(stream.get()); |
|
381 |
|
382 RetainPtr<CFDataRef> dataRef(AdoptCF, |
|
383 (CFDataRef)CFWriteStreamCopyProperty(stream.get(), kCFStreamPropertyDataWritten)); |
|
384 if (!dataRef) |
|
385 return; |
|
386 |
|
387 void* bytes = (void*)CFDataGetBytePtr(dataRef.get()); |
|
388 size_t length = CFDataGetLength(dataRef.get()); |
|
389 safeCreateFileWithData(appDataPath, bytes, length); |
|
390 } |
|
391 |
|
392 void WebPreferences::load() |
|
393 { |
|
394 initializeDefaultSettings(); |
|
395 |
|
396 TCHAR appDataPath[MAX_PATH]; |
|
397 if (FAILED(preferencesPath(appDataPath, MAX_PATH))) |
|
398 return; |
|
399 |
|
400 DWORD appDataPathLength = (DWORD) _tcslen(appDataPath)+1; |
|
401 int result = WideCharToMultiByte(CP_UTF8, 0, appDataPath, appDataPathLength, 0, 0, 0, 0); |
|
402 Vector<UInt8> utf8Path(result); |
|
403 if (!WideCharToMultiByte(CP_UTF8, 0, appDataPath, appDataPathLength, (LPSTR)utf8Path.data(), result, 0, 0)) |
|
404 return; |
|
405 |
|
406 RetainPtr<CFURLRef> urlRef(AdoptCF, CFURLCreateFromFileSystemRepresentation(0, utf8Path.data(), result-1, false)); |
|
407 if (!urlRef) |
|
408 return; |
|
409 |
|
410 RetainPtr<CFReadStreamRef> stream(AdoptCF, CFReadStreamCreateWithFile(0, urlRef.get())); |
|
411 if (!stream) |
|
412 return; |
|
413 |
|
414 if (CFReadStreamOpen(stream.get())) { |
|
415 CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0; |
|
416 RetainPtr<CFPropertyListRef> plist(AdoptCF, CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0)); |
|
417 CFReadStreamClose(stream.get()); |
|
418 |
|
419 if (CFGetTypeID(plist.get()) == CFDictionaryGetTypeID()) |
|
420 m_privatePrefs.adoptCF(const_cast<CFMutableDictionaryRef>(reinterpret_cast<CFDictionaryRef>(plist.releaseRef()))); |
|
421 } |
|
422 |
|
423 if (!m_privatePrefs) |
|
424 m_privatePrefs.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); |
|
425 |
|
426 migrateDefaultSettingsFromSafari3Beta(); |
|
427 } |
|
428 |
|
429 void WebPreferences::migrateDefaultSettingsFromSafari3Beta() |
|
430 { |
|
431 // The "migration" happening here is a one-time removal of any default values |
|
432 // that were stored in the user's preferences due to <rdar://problem/5214504>. |
|
433 |
|
434 ASSERT(s_defaultSettings); |
|
435 if (!m_privatePrefs) |
|
436 return; |
|
437 |
|
438 CFStringRef didMigrateKey = CFSTR(WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey); |
|
439 if (boolValueForKey(didMigrateKey)) |
|
440 return; |
|
441 |
|
442 removeValuesMatchingDefaultSettings(); |
|
443 |
|
444 bool oldValue = m_autoSaves; |
|
445 m_autoSaves = true; |
|
446 setBoolValue(didMigrateKey, TRUE); |
|
447 m_autoSaves = oldValue; |
|
448 } |
|
449 |
|
450 void WebPreferences::removeValuesMatchingDefaultSettings() |
|
451 { |
|
452 ASSERT(m_privatePrefs); |
|
453 |
|
454 int count = CFDictionaryGetCount(m_privatePrefs.get()); |
|
455 if (count <= 0) |
|
456 return; |
|
457 |
|
458 Vector<CFTypeRef> keys(count); |
|
459 Vector<CFTypeRef> values(count); |
|
460 CFDictionaryGetKeysAndValues(m_privatePrefs.get(), keys.data(), values.data()); |
|
461 |
|
462 for (int i = 0; i < count; ++i) { |
|
463 if (!values[i]) |
|
464 continue; |
|
465 |
|
466 CFTypeRef defaultValue = CFDictionaryGetValue(s_defaultSettings, keys[i]); |
|
467 if (!defaultValue) |
|
468 continue; |
|
469 |
|
470 if (CFEqual(values[i], defaultValue)) |
|
471 CFDictionaryRemoveValue(m_privatePrefs.get(), keys[i]); |
|
472 } |
|
473 } |
|
474 |
|
475 HRESULT WebPreferences::preferencesPath(LPTSTR path, size_t cchPath) |
|
476 { |
|
477 // get the path to the user's Application Data folder (Example: C:\Documents and Settings\{username}\Application Data\Apple Computer\WebKit) |
|
478 HRESULT hr = SHGetFolderPath(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, path); |
|
479 if (FAILED(hr)) |
|
480 return hr; |
|
481 |
|
482 if (_tcscat_s(path, cchPath, TEXT("\\Apple Computer\\"))) |
|
483 return E_FAIL; |
|
484 |
|
485 WebCore::String appName = "WebKit"; |
|
486 CFBundleRef bundle = CFBundleGetMainBundle(); |
|
487 if (bundle) { |
|
488 CFStringRef bundleExecutable = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleExecutableKey); |
|
489 if (bundleExecutable) |
|
490 appName = bundleExecutable; |
|
491 } |
|
492 if (_tcscat_s(path, cchPath, appName.charactersWithNullTermination())) |
|
493 return E_FAIL; |
|
494 |
|
495 int err = SHCreateDirectoryEx(0, path, 0); |
|
496 if (err != ERROR_SUCCESS && err != ERROR_ALREADY_EXISTS) |
|
497 return E_FAIL; |
|
498 |
|
499 if (_tcscat_s(path, cchPath, TEXT("\\WebKitPreferences.plist"))) |
|
500 return E_FAIL; |
|
501 |
|
502 return S_OK; |
|
503 } |
|
504 |
|
505 HRESULT WebPreferences::safeCreateFileWithData(LPCTSTR path, void* data, size_t length) |
|
506 { |
|
507 TCHAR tempDirPath[MAX_PATH]; |
|
508 TCHAR tempPath[MAX_PATH]; |
|
509 HANDLE tempFileHandle = INVALID_HANDLE_VALUE; |
|
510 HRESULT hr = S_OK; |
|
511 tempPath[0] = 0; |
|
512 |
|
513 // create a temporary file |
|
514 if (!GetTempPath(sizeof(tempDirPath)/sizeof(tempDirPath[0]), tempDirPath)) { |
|
515 hr = HRESULT_FROM_WIN32(GetLastError()); |
|
516 goto exit; |
|
517 } |
|
518 if (!GetTempFileName(tempDirPath, TEXT("WEBKIT"), 0, tempPath)) |
|
519 return HRESULT_FROM_WIN32(GetLastError()); |
|
520 tempFileHandle = CreateFile(tempPath, GENERIC_READ|GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); |
|
521 if (tempFileHandle == INVALID_HANDLE_VALUE) { |
|
522 hr = HRESULT_FROM_WIN32(GetLastError()); |
|
523 goto exit; |
|
524 } |
|
525 |
|
526 // write the data to this temp file |
|
527 DWORD written; |
|
528 if (!WriteFile(tempFileHandle, data, (DWORD)length, &written, 0)) { |
|
529 hr = HRESULT_FROM_WIN32(GetLastError()); |
|
530 goto exit; |
|
531 } |
|
532 |
|
533 // copy the temp file to the destination file |
|
534 CloseHandle(tempFileHandle); |
|
535 tempFileHandle = INVALID_HANDLE_VALUE; |
|
536 if (!MoveFileEx(tempPath, path, MOVEFILE_REPLACE_EXISTING)) { |
|
537 hr = HRESULT_FROM_WIN32(GetLastError()); |
|
538 goto exit; |
|
539 } |
|
540 |
|
541 exit: |
|
542 if (tempFileHandle != INVALID_HANDLE_VALUE) |
|
543 CloseHandle(tempFileHandle); |
|
544 if (tempPath[0]) |
|
545 DeleteFile(tempPath); |
|
546 |
|
547 return hr; |
|
548 } |
|
549 |
|
550 // IUnknown ------------------------------------------------------------------- |
|
551 |
|
552 HRESULT STDMETHODCALLTYPE WebPreferences::QueryInterface(REFIID riid, void** ppvObject) |
|
553 { |
|
554 *ppvObject = 0; |
|
555 if (IsEqualGUID(riid, IID_IUnknown)) |
|
556 *ppvObject = static_cast<IWebPreferences*>(this); |
|
557 else if (IsEqualGUID(riid, IID_IWebPreferences)) |
|
558 *ppvObject = static_cast<IWebPreferences*>(this); |
|
559 else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate)) |
|
560 *ppvObject = static_cast<IWebPreferencesPrivate*>(this); |
|
561 else if (IsEqualGUID(riid, IID_WebPreferences)) |
|
562 *ppvObject = static_cast<WebPreferences*>(this); |
|
563 else |
|
564 return E_NOINTERFACE; |
|
565 |
|
566 AddRef(); |
|
567 return S_OK; |
|
568 } |
|
569 |
|
570 ULONG STDMETHODCALLTYPE WebPreferences::AddRef(void) |
|
571 { |
|
572 return ++m_refCount; |
|
573 } |
|
574 |
|
575 ULONG STDMETHODCALLTYPE WebPreferences::Release(void) |
|
576 { |
|
577 ULONG newRef = --m_refCount; |
|
578 if (!newRef) |
|
579 delete(this); |
|
580 |
|
581 return newRef; |
|
582 } |
|
583 |
|
584 // IWebPreferences ------------------------------------------------------------ |
|
585 |
|
586 HRESULT STDMETHODCALLTYPE WebPreferences::standardPreferences( |
|
587 /* [retval][out] */ IWebPreferences** standardPreferences) |
|
588 { |
|
589 if (!standardPreferences) |
|
590 return E_POINTER; |
|
591 *standardPreferences = sharedStandardPreferences(); |
|
592 (*standardPreferences)->AddRef(); |
|
593 return S_OK; |
|
594 } |
|
595 |
|
596 HRESULT STDMETHODCALLTYPE WebPreferences::initWithIdentifier( |
|
597 /* [in] */ BSTR anIdentifier, |
|
598 /* [retval][out] */ IWebPreferences** preferences) |
|
599 { |
|
600 WebPreferences *instance = getInstanceForIdentifier(anIdentifier); |
|
601 if (instance) { |
|
602 *preferences = instance; |
|
603 instance->AddRef(); |
|
604 return S_OK; |
|
605 } |
|
606 |
|
607 load(); |
|
608 |
|
609 *preferences = this; |
|
610 AddRef(); |
|
611 |
|
612 if (anIdentifier) { |
|
613 m_identifier = anIdentifier; |
|
614 setInstance(this, m_identifier); |
|
615 } |
|
616 |
|
617 return S_OK; |
|
618 } |
|
619 |
|
620 HRESULT STDMETHODCALLTYPE WebPreferences::identifier( |
|
621 /* [retval][out] */ BSTR* ident) |
|
622 { |
|
623 if (!ident) |
|
624 return E_POINTER; |
|
625 *ident = m_identifier ? SysAllocString(m_identifier) : 0; |
|
626 return S_OK; |
|
627 } |
|
628 |
|
629 HRESULT STDMETHODCALLTYPE WebPreferences::standardFontFamily( |
|
630 /* [retval][out] */ BSTR* family) |
|
631 { |
|
632 *family = stringValueForKey(CFSTR(WebKitStandardFontPreferenceKey)); |
|
633 return (*family) ? S_OK : E_FAIL; |
|
634 } |
|
635 |
|
636 HRESULT STDMETHODCALLTYPE WebPreferences::setStandardFontFamily( |
|
637 /* [in] */ BSTR family) |
|
638 { |
|
639 setStringValue(CFSTR(WebKitStandardFontPreferenceKey), family); |
|
640 return S_OK; |
|
641 } |
|
642 |
|
643 HRESULT STDMETHODCALLTYPE WebPreferences::fixedFontFamily( |
|
644 /* [retval][out] */ BSTR* family) |
|
645 { |
|
646 *family = stringValueForKey(CFSTR(WebKitFixedFontPreferenceKey)); |
|
647 return (*family) ? S_OK : E_FAIL; |
|
648 } |
|
649 |
|
650 HRESULT STDMETHODCALLTYPE WebPreferences::setFixedFontFamily( |
|
651 /* [in] */ BSTR family) |
|
652 { |
|
653 setStringValue(CFSTR(WebKitFixedFontPreferenceKey), family); |
|
654 return S_OK; |
|
655 } |
|
656 |
|
657 HRESULT STDMETHODCALLTYPE WebPreferences::serifFontFamily( |
|
658 /* [retval][out] */ BSTR* fontFamily) |
|
659 { |
|
660 *fontFamily = stringValueForKey(CFSTR(WebKitSerifFontPreferenceKey)); |
|
661 return (*fontFamily) ? S_OK : E_FAIL; |
|
662 } |
|
663 |
|
664 HRESULT STDMETHODCALLTYPE WebPreferences::setSerifFontFamily( |
|
665 /* [in] */ BSTR family) |
|
666 { |
|
667 setStringValue(CFSTR(WebKitSerifFontPreferenceKey), family); |
|
668 return S_OK; |
|
669 } |
|
670 |
|
671 HRESULT STDMETHODCALLTYPE WebPreferences::sansSerifFontFamily( |
|
672 /* [retval][out] */ BSTR* family) |
|
673 { |
|
674 *family = stringValueForKey(CFSTR(WebKitSansSerifFontPreferenceKey)); |
|
675 return (*family) ? S_OK : E_FAIL; |
|
676 } |
|
677 |
|
678 HRESULT STDMETHODCALLTYPE WebPreferences::setSansSerifFontFamily( |
|
679 /* [in] */ BSTR family) |
|
680 { |
|
681 setStringValue(CFSTR(WebKitSansSerifFontPreferenceKey), family); |
|
682 return S_OK; |
|
683 } |
|
684 |
|
685 HRESULT STDMETHODCALLTYPE WebPreferences::cursiveFontFamily( |
|
686 /* [retval][out] */ BSTR* family) |
|
687 { |
|
688 *family = stringValueForKey(CFSTR(WebKitCursiveFontPreferenceKey)); |
|
689 return (*family) ? S_OK : E_FAIL; |
|
690 } |
|
691 |
|
692 HRESULT STDMETHODCALLTYPE WebPreferences::setCursiveFontFamily( |
|
693 /* [in] */ BSTR family) |
|
694 { |
|
695 setStringValue(CFSTR(WebKitCursiveFontPreferenceKey), family); |
|
696 return S_OK; |
|
697 } |
|
698 |
|
699 HRESULT STDMETHODCALLTYPE WebPreferences::fantasyFontFamily( |
|
700 /* [retval][out] */ BSTR* family) |
|
701 { |
|
702 *family = stringValueForKey(CFSTR(WebKitFantasyFontPreferenceKey)); |
|
703 return (*family) ? S_OK : E_FAIL; |
|
704 } |
|
705 |
|
706 HRESULT STDMETHODCALLTYPE WebPreferences::setFantasyFontFamily( |
|
707 /* [in] */ BSTR family) |
|
708 { |
|
709 setStringValue(CFSTR(WebKitFantasyFontPreferenceKey), family); |
|
710 return S_OK; |
|
711 } |
|
712 |
|
713 HRESULT STDMETHODCALLTYPE WebPreferences::defaultFontSize( |
|
714 /* [retval][out] */ int* fontSize) |
|
715 { |
|
716 *fontSize = integerValueForKey(CFSTR(WebKitDefaultFontSizePreferenceKey)); |
|
717 return S_OK; |
|
718 } |
|
719 |
|
720 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultFontSize( |
|
721 /* [in] */ int fontSize) |
|
722 { |
|
723 setIntegerValue(CFSTR(WebKitDefaultFontSizePreferenceKey), fontSize); |
|
724 return S_OK; |
|
725 } |
|
726 |
|
727 HRESULT STDMETHODCALLTYPE WebPreferences::defaultFixedFontSize( |
|
728 /* [retval][out] */ int* fontSize) |
|
729 { |
|
730 *fontSize = integerValueForKey(CFSTR(WebKitDefaultFixedFontSizePreferenceKey)); |
|
731 return S_OK; |
|
732 } |
|
733 |
|
734 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultFixedFontSize( |
|
735 /* [in] */ int fontSize) |
|
736 { |
|
737 setIntegerValue(CFSTR(WebKitDefaultFixedFontSizePreferenceKey), fontSize); |
|
738 return S_OK; |
|
739 } |
|
740 |
|
741 HRESULT STDMETHODCALLTYPE WebPreferences::minimumFontSize( |
|
742 /* [retval][out] */ int* fontSize) |
|
743 { |
|
744 *fontSize = integerValueForKey(CFSTR(WebKitMinimumFontSizePreferenceKey)); |
|
745 return S_OK; |
|
746 } |
|
747 |
|
748 HRESULT STDMETHODCALLTYPE WebPreferences::setMinimumFontSize( |
|
749 /* [in] */ int fontSize) |
|
750 { |
|
751 setIntegerValue(CFSTR(WebKitMinimumFontSizePreferenceKey), fontSize); |
|
752 return S_OK; |
|
753 } |
|
754 |
|
755 HRESULT STDMETHODCALLTYPE WebPreferences::minimumLogicalFontSize( |
|
756 /* [retval][out] */ int* fontSize) |
|
757 { |
|
758 *fontSize = integerValueForKey(CFSTR(WebKitMinimumLogicalFontSizePreferenceKey)); |
|
759 return S_OK; |
|
760 } |
|
761 |
|
762 HRESULT STDMETHODCALLTYPE WebPreferences::setMinimumLogicalFontSize( |
|
763 /* [in] */ int fontSize) |
|
764 { |
|
765 setIntegerValue(CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), fontSize); |
|
766 return S_OK; |
|
767 } |
|
768 |
|
769 HRESULT STDMETHODCALLTYPE WebPreferences::defaultTextEncodingName( |
|
770 /* [retval][out] */ BSTR* name) |
|
771 { |
|
772 *name = stringValueForKey(CFSTR(WebKitDefaultTextEncodingNamePreferenceKey)); |
|
773 return (*name) ? S_OK : E_FAIL; |
|
774 } |
|
775 |
|
776 HRESULT STDMETHODCALLTYPE WebPreferences::setDefaultTextEncodingName( |
|
777 /* [in] */ BSTR name) |
|
778 { |
|
779 setStringValue(CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), name); |
|
780 return S_OK; |
|
781 } |
|
782 |
|
783 HRESULT STDMETHODCALLTYPE WebPreferences::userStyleSheetEnabled( |
|
784 /* [retval][out] */ BOOL* enabled) |
|
785 { |
|
786 *enabled = boolValueForKey(CFSTR(WebKitUserStyleSheetEnabledPreferenceKey)); |
|
787 return S_OK; |
|
788 } |
|
789 |
|
790 HRESULT STDMETHODCALLTYPE WebPreferences::setUserStyleSheetEnabled( |
|
791 /* [in] */ BOOL enabled) |
|
792 { |
|
793 setBoolValue(CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), enabled); |
|
794 return S_OK; |
|
795 } |
|
796 |
|
797 HRESULT STDMETHODCALLTYPE WebPreferences::userStyleSheetLocation( |
|
798 /* [retval][out] */ BSTR* location) |
|
799 { |
|
800 *location = stringValueForKey(CFSTR(WebKitUserStyleSheetLocationPreferenceKey)); |
|
801 return (*location) ? S_OK : E_FAIL; |
|
802 } |
|
803 |
|
804 HRESULT STDMETHODCALLTYPE WebPreferences::setUserStyleSheetLocation( |
|
805 /* [in] */ BSTR location) |
|
806 { |
|
807 setStringValue(CFSTR(WebKitUserStyleSheetLocationPreferenceKey), location); |
|
808 return S_OK; |
|
809 } |
|
810 |
|
811 HRESULT STDMETHODCALLTYPE WebPreferences::isJavaEnabled( |
|
812 /* [retval][out] */ BOOL* enabled) |
|
813 { |
|
814 *enabled = boolValueForKey(CFSTR(WebKitJavaEnabledPreferenceKey)); |
|
815 return S_OK; |
|
816 } |
|
817 |
|
818 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaEnabled( |
|
819 /* [in] */ BOOL enabled) |
|
820 { |
|
821 setBoolValue(CFSTR(WebKitJavaEnabledPreferenceKey), enabled); |
|
822 return S_OK; |
|
823 } |
|
824 |
|
825 HRESULT STDMETHODCALLTYPE WebPreferences::isJavaScriptEnabled( |
|
826 /* [retval][out] */ BOOL* enabled) |
|
827 { |
|
828 *enabled = boolValueForKey(CFSTR(WebKitJavaScriptEnabledPreferenceKey)); |
|
829 return S_OK; |
|
830 } |
|
831 |
|
832 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptEnabled( |
|
833 /* [in] */ BOOL enabled) |
|
834 { |
|
835 setBoolValue(CFSTR(WebKitJavaScriptEnabledPreferenceKey), enabled); |
|
836 return S_OK; |
|
837 } |
|
838 |
|
839 HRESULT STDMETHODCALLTYPE WebPreferences::javaScriptCanOpenWindowsAutomatically( |
|
840 /* [retval][out] */ BOOL* enabled) |
|
841 { |
|
842 *enabled = boolValueForKey(CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey)); |
|
843 return S_OK; |
|
844 } |
|
845 |
|
846 HRESULT STDMETHODCALLTYPE WebPreferences::setJavaScriptCanOpenWindowsAutomatically( |
|
847 /* [in] */ BOOL enabled) |
|
848 { |
|
849 setBoolValue(CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), enabled); |
|
850 return S_OK; |
|
851 } |
|
852 |
|
853 HRESULT STDMETHODCALLTYPE WebPreferences::arePlugInsEnabled( |
|
854 /* [retval][out] */ BOOL* enabled) |
|
855 { |
|
856 *enabled = boolValueForKey(CFSTR(WebKitPluginsEnabledPreferenceKey)); |
|
857 return S_OK; |
|
858 } |
|
859 |
|
860 HRESULT STDMETHODCALLTYPE WebPreferences::setPlugInsEnabled( |
|
861 /* [in] */ BOOL enabled) |
|
862 { |
|
863 setBoolValue(CFSTR(WebKitPluginsEnabledPreferenceKey), enabled); |
|
864 return S_OK; |
|
865 } |
|
866 |
|
867 HRESULT STDMETHODCALLTYPE WebPreferences::allowsAnimatedImages( |
|
868 /* [retval][out] */ BOOL* enabled) |
|
869 { |
|
870 *enabled = boolValueForKey(CFSTR(WebKitAllowAnimatedImagesPreferenceKey)); |
|
871 return S_OK; |
|
872 } |
|
873 |
|
874 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowsAnimatedImages( |
|
875 /* [in] */ BOOL enabled) |
|
876 { |
|
877 setBoolValue(CFSTR(WebKitAllowAnimatedImagesPreferenceKey), enabled); |
|
878 return S_OK; |
|
879 } |
|
880 |
|
881 HRESULT STDMETHODCALLTYPE WebPreferences::allowAnimatedImageLooping( |
|
882 /* [retval][out] */ BOOL* enabled) |
|
883 { |
|
884 *enabled = boolValueForKey(CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey)); |
|
885 return S_OK; |
|
886 } |
|
887 |
|
888 HRESULT STDMETHODCALLTYPE WebPreferences::setAllowAnimatedImageLooping( |
|
889 /* [in] */ BOOL enabled) |
|
890 { |
|
891 setBoolValue(CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), enabled); |
|
892 return S_OK; |
|
893 } |
|
894 |
|
895 HRESULT STDMETHODCALLTYPE WebPreferences::setLoadsImagesAutomatically( |
|
896 /* [in] */ BOOL enabled) |
|
897 { |
|
898 setBoolValue(CFSTR(WebKitDisplayImagesKey), enabled); |
|
899 return S_OK; |
|
900 } |
|
901 |
|
902 HRESULT STDMETHODCALLTYPE WebPreferences::loadsImagesAutomatically( |
|
903 /* [retval][out] */ BOOL* enabled) |
|
904 { |
|
905 *enabled = boolValueForKey(CFSTR(WebKitDisplayImagesKey)); |
|
906 return S_OK; |
|
907 } |
|
908 |
|
909 HRESULT STDMETHODCALLTYPE WebPreferences::setAutosaves( |
|
910 /* [in] */ BOOL enabled) |
|
911 { |
|
912 m_autoSaves = !!enabled; |
|
913 return S_OK; |
|
914 } |
|
915 |
|
916 HRESULT STDMETHODCALLTYPE WebPreferences::autosaves( |
|
917 /* [retval][out] */ BOOL* enabled) |
|
918 { |
|
919 *enabled = m_autoSaves ? TRUE : FALSE; |
|
920 return S_OK; |
|
921 } |
|
922 |
|
923 HRESULT STDMETHODCALLTYPE WebPreferences::setShouldPrintBackgrounds( |
|
924 /* [in] */ BOOL enabled) |
|
925 { |
|
926 setBoolValue(CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), enabled); |
|
927 return S_OK; |
|
928 } |
|
929 |
|
930 HRESULT STDMETHODCALLTYPE WebPreferences::shouldPrintBackgrounds( |
|
931 /* [retval][out] */ BOOL* enabled) |
|
932 { |
|
933 *enabled = boolValueForKey(CFSTR(WebKitShouldPrintBackgroundsPreferenceKey)); |
|
934 return S_OK; |
|
935 } |
|
936 |
|
937 HRESULT STDMETHODCALLTYPE WebPreferences::setPrivateBrowsingEnabled( |
|
938 /* [in] */ BOOL enabled) |
|
939 { |
|
940 setBoolValue(CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), enabled); |
|
941 return S_OK; |
|
942 } |
|
943 |
|
944 HRESULT STDMETHODCALLTYPE WebPreferences::privateBrowsingEnabled( |
|
945 /* [retval][out] */ BOOL* enabled) |
|
946 { |
|
947 *enabled = boolValueForKey(CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey)); |
|
948 return S_OK; |
|
949 } |
|
950 |
|
951 HRESULT STDMETHODCALLTYPE WebPreferences::setTabsToLinks( |
|
952 /* [in] */ BOOL enabled) |
|
953 { |
|
954 setBoolValue(CFSTR(WebKitTabToLinksPreferenceKey), enabled); |
|
955 return S_OK; |
|
956 } |
|
957 |
|
958 HRESULT STDMETHODCALLTYPE WebPreferences::tabsToLinks( |
|
959 /* [retval][out] */ BOOL* enabled) |
|
960 { |
|
961 *enabled = boolValueForKey(CFSTR(WebKitTabToLinksPreferenceKey)); |
|
962 return S_OK; |
|
963 } |
|
964 |
|
965 HRESULT STDMETHODCALLTYPE WebPreferences::setUsesPageCache( |
|
966 /* [in] */ BOOL usesPageCache) |
|
967 { |
|
968 setBoolValue(CFSTR(WebKitUsesPageCachePreferenceKey), usesPageCache); |
|
969 return S_OK; |
|
970 } |
|
971 |
|
972 HRESULT STDMETHODCALLTYPE WebPreferences::usesPageCache( |
|
973 /* [retval][out] */ BOOL* usesPageCache) |
|
974 { |
|
975 *usesPageCache = boolValueForKey(CFSTR(WebKitUsesPageCachePreferenceKey)); |
|
976 return S_OK; |
|
977 } |
|
978 |
|
979 HRESULT STDMETHODCALLTYPE WebPreferences::textAreasAreResizable( |
|
980 /* [retval][out] */ BOOL* enabled) |
|
981 { |
|
982 *enabled = boolValueForKey(CFSTR(WebKitTextAreasAreResizablePreferenceKey)); |
|
983 return S_OK; |
|
984 } |
|
985 |
|
986 HRESULT STDMETHODCALLTYPE WebPreferences::setTextAreasAreResizable( |
|
987 /* [in] */ BOOL enabled) |
|
988 { |
|
989 setBoolValue(CFSTR(WebKitTextAreasAreResizablePreferenceKey), enabled); |
|
990 return S_OK; |
|
991 } |
|
992 |
|
993 HRESULT WebPreferences::historyItemLimit(int* limit) |
|
994 { |
|
995 *limit = integerValueForKey(CFSTR(WebKitHistoryItemLimitKey)); |
|
996 return S_OK; |
|
997 } |
|
998 |
|
999 HRESULT WebPreferences::setHistoryItemLimit(int limit) |
|
1000 { |
|
1001 setIntegerValue(CFSTR(WebKitHistoryItemLimitKey), limit); |
|
1002 return S_OK; |
|
1003 } |
|
1004 |
|
1005 HRESULT WebPreferences::historyAgeInDaysLimit(int* limit) |
|
1006 { |
|
1007 *limit = integerValueForKey(CFSTR(WebKitHistoryAgeInDaysLimitKey)); |
|
1008 return S_OK; |
|
1009 } |
|
1010 |
|
1011 HRESULT WebPreferences::setHistoryAgeInDaysLimit(int limit) |
|
1012 { |
|
1013 setIntegerValue(CFSTR(WebKitHistoryAgeInDaysLimitKey), limit); |
|
1014 return S_OK; |
|
1015 } |
|
1016 |
|
1017 HRESULT WebPreferences::pageCacheSize(unsigned int* limit) |
|
1018 { |
|
1019 *limit = integerValueForKey(CFSTR(WebKitPageCacheSizePreferenceKey)); |
|
1020 return S_OK; |
|
1021 } |
|
1022 |
|
1023 HRESULT WebPreferences::objectCacheSize(unsigned int* limit) |
|
1024 { |
|
1025 *limit = integerValueForKey(CFSTR(WebKitObjectCacheSizePreferenceKey)); |
|
1026 return S_OK; |
|
1027 } |
|
1028 |
|
1029 HRESULT WebPreferences::iconDatabaseLocation( |
|
1030 /* [out] */ BSTR* location) |
|
1031 { |
|
1032 *location = stringValueForKey(CFSTR(WebKitIconDatabaseLocationKey)); |
|
1033 return (*location) ? S_OK : E_FAIL; |
|
1034 } |
|
1035 |
|
1036 HRESULT WebPreferences::setIconDatabaseLocation( |
|
1037 /* [in] */ BSTR location) |
|
1038 { |
|
1039 setStringValue(CFSTR(WebKitIconDatabaseLocationKey), location); |
|
1040 return S_OK; |
|
1041 } |
|
1042 |
|
1043 HRESULT WebPreferences::iconDatabaseEnabled(BOOL* enabled)//location) |
|
1044 { |
|
1045 *enabled = boolValueForKey(CFSTR(WebKitIconDatabaseEnabledPreferenceKey)); |
|
1046 return S_OK; |
|
1047 } |
|
1048 |
|
1049 HRESULT WebPreferences::setIconDatabaseEnabled(BOOL enabled )//location) |
|
1050 { |
|
1051 setBoolValue(CFSTR(WebKitIconDatabaseEnabledPreferenceKey), enabled); |
|
1052 return S_OK; |
|
1053 } |
|
1054 |
|
1055 HRESULT STDMETHODCALLTYPE WebPreferences::fontSmoothing( |
|
1056 /* [retval][out] */ FontSmoothingType* smoothingType) |
|
1057 { |
|
1058 *smoothingType = (FontSmoothingType) integerValueForKey(CFSTR(WebKitFontSmothingTypePreferenceKey)); |
|
1059 return S_OK; |
|
1060 } |
|
1061 |
|
1062 HRESULT STDMETHODCALLTYPE WebPreferences::setFontSmoothing( |
|
1063 /* [in] */ FontSmoothingType smoothingType) |
|
1064 { |
|
1065 setIntegerValue(CFSTR(WebKitFontSmothingTypePreferenceKey), smoothingType); |
|
1066 wkSetFontSmoothingLevel((int)smoothingType); |
|
1067 return S_OK; |
|
1068 } |
|
1069 |
|
1070 HRESULT STDMETHODCALLTYPE WebPreferences::editableLinkBehavior( |
|
1071 /* [out, retval] */ WebKitEditableLinkBehavior* editableLinkBehavior) |
|
1072 { |
|
1073 WebKitEditableLinkBehavior value = (WebKitEditableLinkBehavior) integerValueForKey(CFSTR(WebKitEditableLinkBehaviorPreferenceKey)); |
|
1074 switch (value) { |
|
1075 case WebKitEditableLinkDefaultBehavior: |
|
1076 case WebKitEditableLinkAlwaysLive: |
|
1077 case WebKitEditableLinkOnlyLiveWithShiftKey: |
|
1078 case WebKitEditableLinkLiveWhenNotFocused: |
|
1079 case WebKitEditableLinkNeverLive: |
|
1080 *editableLinkBehavior = value; |
|
1081 break; |
|
1082 default: // ensure that a valid result is returned |
|
1083 *editableLinkBehavior = WebKitEditableLinkDefaultBehavior; |
|
1084 break; |
|
1085 } |
|
1086 return S_OK; |
|
1087 } |
|
1088 |
|
1089 HRESULT STDMETHODCALLTYPE WebPreferences::setEditableLinkBehavior( |
|
1090 /* [in] */ WebKitEditableLinkBehavior behavior) |
|
1091 { |
|
1092 setIntegerValue(CFSTR(WebKitEditableLinkBehaviorPreferenceKey), behavior); |
|
1093 return S_OK; |
|
1094 } |
|
1095 |
|
1096 HRESULT STDMETHODCALLTYPE WebPreferences::cookieStorageAcceptPolicy( |
|
1097 /* [retval][out] */ WebKitCookieStorageAcceptPolicy *acceptPolicy ) |
|
1098 { |
|
1099 if (!acceptPolicy) |
|
1100 return E_POINTER; |
|
1101 |
|
1102 *acceptPolicy = (WebKitCookieStorageAcceptPolicy)integerValueForKey(CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey)); |
|
1103 return S_OK; |
|
1104 } |
|
1105 |
|
1106 HRESULT STDMETHODCALLTYPE WebPreferences::setCookieStorageAcceptPolicy( |
|
1107 /* [in] */ WebKitCookieStorageAcceptPolicy acceptPolicy) |
|
1108 { |
|
1109 setIntegerValue(CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), acceptPolicy); |
|
1110 return S_OK; |
|
1111 } |
|
1112 |
|
1113 |
|
1114 HRESULT WebPreferences::continuousSpellCheckingEnabled(BOOL* enabled) |
|
1115 { |
|
1116 *enabled = boolValueForKey(CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey)); |
|
1117 return S_OK; |
|
1118 } |
|
1119 |
|
1120 HRESULT WebPreferences::setContinuousSpellCheckingEnabled(BOOL enabled) |
|
1121 { |
|
1122 setBoolValue(CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), enabled); |
|
1123 return S_OK; |
|
1124 } |
|
1125 |
|
1126 HRESULT WebPreferences::grammarCheckingEnabled(BOOL* enabled) |
|
1127 { |
|
1128 *enabled = boolValueForKey(CFSTR(WebGrammarCheckingEnabledPreferenceKey)); |
|
1129 return S_OK; |
|
1130 } |
|
1131 |
|
1132 HRESULT WebPreferences::setGrammarCheckingEnabled(BOOL enabled) |
|
1133 { |
|
1134 setBoolValue(CFSTR(WebGrammarCheckingEnabledPreferenceKey), enabled); |
|
1135 return S_OK; |
|
1136 } |
|
1137 |
|
1138 HRESULT WebPreferences::allowContinuousSpellChecking(BOOL* enabled) |
|
1139 { |
|
1140 *enabled = boolValueForKey(CFSTR(AllowContinuousSpellCheckingPreferenceKey)); |
|
1141 return S_OK; |
|
1142 } |
|
1143 |
|
1144 HRESULT WebPreferences::setAllowContinuousSpellChecking(BOOL enabled) |
|
1145 { |
|
1146 setBoolValue(CFSTR(AllowContinuousSpellCheckingPreferenceKey), enabled); |
|
1147 return S_OK; |
|
1148 } |
|
1149 |
|
1150 HRESULT WebPreferences::isDOMPasteAllowed(BOOL* enabled) |
|
1151 { |
|
1152 *enabled = boolValueForKey(CFSTR(WebKitDOMPasteAllowedPreferenceKey)); |
|
1153 return S_OK; |
|
1154 } |
|
1155 |
|
1156 HRESULT WebPreferences::setDOMPasteAllowed(BOOL enabled) |
|
1157 { |
|
1158 setBoolValue(CFSTR(WebKitDOMPasteAllowedPreferenceKey), enabled); |
|
1159 return S_OK; |
|
1160 } |
|
1161 |
|
1162 HRESULT WebPreferences::setDeveloperExtrasEnabled(BOOL enabled) |
|
1163 { |
|
1164 setBoolValue(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey), enabled); |
|
1165 return S_OK; |
|
1166 } |
|
1167 |
|
1168 HRESULT WebPreferences::developerExtrasEnabled(BOOL* enabled) |
|
1169 { |
|
1170 if (!enabled) |
|
1171 return E_POINTER; |
|
1172 |
|
1173 *enabled = boolValueForKey(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey)); |
|
1174 return S_OK; |
|
1175 } |
|
1176 |
|
1177 bool WebPreferences::developerExtrasDisabledByOverride() |
|
1178 { |
|
1179 return !!boolValueForKey(CFSTR(DisableWebKitDeveloperExtrasPreferenceKey)); |
|
1180 } |