Store user defaults in a non-mutable CFDictionaryRef
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Aug 2007 21:24:38 +0000 (21:24 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Aug 2007 21:24:38 +0000 (21:24 +0000)
        Also renamed WebPreferences' static members:
            m_standardPreferences -> s_standardPreferences
            m_standardUserDefaults -> s_defaultSettings

        Reviewed by Darin and John.

        * WebPreferences.cpp:
        (WebPreferences::getInstanceForIdentifier):
        (WebPreferences::initializeUserDefaults): Construct the dictionary as a
        local CFMutableDictionaryRef, then assign it to the non-mutable static
        member.
        (WebPreferences::valueForKey):
        (WebPreferences::removeDefaultsIfNeeded):
        (WebPreferences::standardPreferences):
        * WebPreferences.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25075 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/win/ChangeLog
WebKit/win/WebPreferences.cpp
WebKit/win/WebPreferences.h

index 9511c96fe110bd5a6d3eda68e29823c88451abaa..d600ed434a0e6bea2da2328d3dedef3b678e5881 100644 (file)
@@ -1,3 +1,23 @@
+2007-08-12  Adam Roben  <aroben@apple.com>
+
+        Store user defaults in a non-mutable CFDictionaryRef
+
+        Also renamed WebPreferences' static members:
+            m_standardPreferences -> s_standardPreferences
+            m_standardUserDefaults -> s_defaultSettings
+
+        Reviewed by Darin and John.
+
+        * WebPreferences.cpp:
+        (WebPreferences::getInstanceForIdentifier):
+        (WebPreferences::initializeUserDefaults): Construct the dictionary as a
+        local CFMutableDictionaryRef, then assign it to the non-mutable static
+        member.
+        (WebPreferences::valueForKey):
+        (WebPreferences::removeDefaultsIfNeeded):
+        (WebPreferences::standardPreferences):
+        * WebPreferences.h:
+
 2007-08-12  Adam Roben  <aroben@apple.com>
 
         Fix <rdar://problem/5214504> No way to change WebPreferences defaults (all preferences get written to disk)
index 0110b8bf99cb97726741d99c170874926ef31130..7733cb8814d3494a1c86f1ac75885da3e42ca116 100644 (file)
@@ -57,8 +57,8 @@ static unsigned long long WebSystemMainMemory()
 
 // WebPreferences ----------------------------------------------------------------
 
-CFMutableDictionaryRef WebPreferences::m_standardUserDefaults = 0;
-WebPreferences* WebPreferences::m_standardPreferences = 0;
+CFDictionaryRef WebPreferences::s_defaultSettings = 0;
+WebPreferences* WebPreferences::s_standardPreferences = 0;
 
 static HashMap<WebCore::String, WebPreferences*> webPreferencesInstances;
 
@@ -94,8 +94,8 @@ HRESULT WebPreferences::postPreferencesChangesNotification()
 WebPreferences* WebPreferences::getInstanceForIdentifier(BSTR identifier)
 {
     if (!identifier) {
-        if (m_standardPreferences)
-            return m_standardPreferences;
+        if (s_standardPreferences)
+            return s_standardPreferences;
         return 0;
     }    
 
@@ -124,10 +124,10 @@ void WebPreferences::removeReferenceForIdentifier(BSTR identifier)
 
 void WebPreferences::initializeDefaultSettings()
 {
-    if (m_standardUserDefaults)
+    if (s_defaultSettings)
         return;
 
-    m_standardUserDefaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+    CFMutableDictionaryRef defaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 
     // As a fudge factor, use 1000 instead of 1024, in case the reported memory doesn't align exactly to a megabyte boundary.
     unsigned long long memSize = WebSystemMainMemory() / 1024 / 1000;
@@ -160,63 +160,65 @@ void WebPreferences::initializeDefaultSettings()
     else
         objectCacheSize = 23 * 1024 * 1024; 
 
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitSansSerifFontPreferenceKey), CFSTR("Arial"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitCursiveFontPreferenceKey), CFSTR("Comic Sans MS"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitFantasyFontPreferenceKey), CFSTR("Comic Sans MS"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitMinimumFontSizePreferenceKey), CFSTR("1"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), CFSTR("9"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitDefaultFontSizePreferenceKey), CFSTR("16"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitDefaultFixedFontSizePreferenceKey), CFSTR("13"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), CFSTR("ISO-8859-1"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitSansSerifFontPreferenceKey), CFSTR("Arial"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitCursiveFontPreferenceKey), CFSTR("Comic Sans MS"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitFantasyFontPreferenceKey), CFSTR("Comic Sans MS"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumFontSizePreferenceKey), CFSTR("1"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitMinimumLogicalFontSizePreferenceKey), CFSTR("9"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFontSizePreferenceKey), CFSTR("16"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultFixedFontSizePreferenceKey), CFSTR("13"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), CFSTR("ISO-8859-1"));
 
     RetainPtr<CFStringRef> pageCacheSizeString(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), pageCacheSize));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitPageCacheSizePreferenceKey), pageCacheSizeString.get());
+    CFDictionaryAddValue(defaults, CFSTR(WebKitPageCacheSizePreferenceKey), pageCacheSizeString.get());
 
     RetainPtr<CFStringRef> objectCacheSizeString(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), objectCacheSize));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitObjectCacheSizePreferenceKey), objectCacheSizeString.get());
-
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitUserStyleSheetLocationPreferenceKey), CFSTR(""));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitTextAreasAreResizablePreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitJavaEnabledPreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitJavaScriptEnabledPreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitPluginsEnabledPreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitAllowAnimatedImagesPreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitDisplayImagesKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitBackForwardCacheExpirationIntervalKey), CFSTR("1800"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitTabToLinksPreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitShowsURLsInToolTipsPreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitPDFDisplayModePreferenceKey), CFSTR("1"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitPDFScaleFactorPreferenceKey), CFSTR("0"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitObjectCacheSizePreferenceKey), objectCacheSizeString.get());
+
+    CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetLocationPreferenceKey), CFSTR(""));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitTextAreasAreResizablePreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitJavaEnabledPreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptEnabledPreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitPluginsEnabledPreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImagesPreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitDisplayImagesKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitBackForwardCacheExpirationIntervalKey), CFSTR("1800"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitTabToLinksPreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitShowsURLsInToolTipsPreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitPDFDisplayModePreferenceKey), CFSTR("1"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitPDFScaleFactorPreferenceKey), CFSTR("0"));
 
     RetainPtr<CFStringRef> linkBehaviorStringRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitEditableLinkBehaviorPreferenceKey), linkBehaviorStringRef.get());
+    CFDictionaryAddValue(defaults, CFSTR(WebKitEditableLinkBehaviorPreferenceKey), linkBehaviorStringRef.get());
 
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitHistoryItemLimitKey), CFSTR("1000"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitHistoryAgeInDaysLimitKey), CFSTR("7"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitIconDatabaseLocationKey), CFSTR(""));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitIconDatabaseEnabledPreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitFontSmothingTypePreferenceKey), CFSTR("2"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), CFSTR("2"));
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
-    CFDictionaryAddValue(m_standardUserDefaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryItemLimitKey), CFSTR("1000"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitHistoryAgeInDaysLimitKey), CFSTR("7"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseLocationKey), CFSTR(""));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitIconDatabaseEnabledPreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitFontSmothingTypePreferenceKey), CFSTR("2"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey), CFSTR("2"));
+    CFDictionaryAddValue(defaults, CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(WebGrammarCheckingEnabledPreferenceKey), kCFBooleanFalse);
+    CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
+    CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
+
+    s_defaultSettings = defaults;
 }
 
 const void* WebPreferences::valueForKey(CFStringRef key)
 {
     const void* value = CFDictionaryGetValue(m_privatePrefs.get(), key);
     if (!value)
-        value = CFDictionaryGetValue(m_standardUserDefaults, key);
+        value = CFDictionaryGetValue(s_defaultSettings, key);
 
     return value;
 }
@@ -414,7 +416,7 @@ void WebPreferences::migrateDefaultSettingsFromSafari3Beta()
     // The "migration" happening here is a one-time removal of any default values
     // that were stored in the user's preferences due to <rdar://problem/5214504>.
 
-    ASSERT(m_standardUserDefaults);
+    ASSERT(s_defaultSettings);
     if (!m_privatePrefs)
         return;
 
@@ -446,7 +448,7 @@ void WebPreferences::removeValuesMatchingDefaultSettings()
         if (!values[i])
             continue;
 
-        CFTypeRef defaultValue = CFDictionaryGetValue(m_standardUserDefaults, keys[i]);
+        CFTypeRef defaultValue = CFDictionaryGetValue(s_defaultSettings, keys[i]);
         if (!defaultValue)
             continue;
 
@@ -567,22 +569,22 @@ HRESULT STDMETHODCALLTYPE WebPreferences::standardPreferences(
 {
     HRESULT hr = S_OK;
 
-    if (!m_standardPreferences) {
+    if (!s_standardPreferences) {
         IWebPreferences* standardPrefs;
         hr = initWithIdentifier(0, &standardPrefs);
         if (FAILED(hr))
             return hr;
-        m_standardPreferences = static_cast<WebPreferences*>(standardPrefs);
-        hr = m_standardPreferences->setAutosaves(TRUE);
+        s_standardPreferences = static_cast<WebPreferences*>(standardPrefs);
+        hr = s_standardPreferences->setAutosaves(TRUE);
         if (FAILED(hr))
             return hr;
-        hr = m_standardPreferences->postPreferencesChangesNotification();
+        hr = s_standardPreferences->postPreferencesChangesNotification();
         if (FAILED(hr))
             return hr;
     }
 
-    m_standardPreferences->AddRef();
-    *standardPreferences = m_standardPreferences;
+    s_standardPreferences->AddRef();
+    *standardPreferences = s_standardPreferences;
     return hr;
 }
 
index bf152233c6875f31e9970e69baa3e46969a2f991..1e1dc5cb455916d1ad7025089e360690b2804541 100644 (file)
@@ -306,8 +306,8 @@ protected:
     RetainPtr<CFMutableDictionaryRef> m_privatePrefs;
     bool m_autoSaves;
     WebCore::BString m_identifier;
-    static CFMutableDictionaryRef m_standardUserDefaults;
-    static WebPreferences* m_standardPreferences;
+    static CFDictionaryRef s_defaultSettings;
+    static WebPreferences* s_standardPreferences;
 };
 
 #endif