Fix <rdar://problem/5214504> No way to change WebPreferences defaults (all...
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Aug 2007 21:24:28 +0000 (21:24 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Aug 2007 21:24:28 +0000 (21:24 +0000)
        We now only write to disk values that have been explicitly set, and
        never write any default values.

        This is not enough, however, as anyone who has used WebKit prior to
        this change will have the default values sitting in their preferences
        plist on disk. To remedy this, we perform a one-time removal of any
        key-value pairs that match a pair in the defaults dictionary.

        Reviewed by Steve, John, Ada, and Darin.

        * WebPreferenceKeysPrivate.h: Added new key to ensure we only remove
        the defaults once.
        * WebPreferences.cpp:
        (WebPreferences::initializeDefaultSettings): Renamed from initialize, and
        made sure we only set up the defaults dictionary once. Now that the
        defaults dictionary is never modified after creation, we don't need to
        check whether the keys are already present.
        (WebPreferences::setStringValue): Don't modify the defaults dictionary.
        (WebPreferences::setIntegerValue): Ditto.
        (WebPreferences::setBoolValue): Ditto.
        (WebPreferences::save): Write out the user's preferences, not the defaults.
        (WebPreferences::load):
           - Removed gotos and early declarations now that we're using
             RetainPtr everywhere.
           - Initialize m_privatePrefs with an empty dictionary if we didn't
             read in a plist.
           - Call migrateDefaultSettingsFromSafari3Beta after loading.
        (WebPreferences::migrateDefaultSettingsFromSafari3Beta): Added.
        (WebPreferences::removeValuesMatchingDefaultSettings): Added.
        (WebPreferences::initWithIdentifier): Don't initialize m_privatePrefs
        -- load() does this now.
        * WebPreferences.h: Updated/added declarations.

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

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

index a199957cedc30fe2d020ef267c60a78d84b6319b..9511c96fe110bd5a6d3eda68e29823c88451abaa 100644 (file)
@@ -1,3 +1,40 @@
+2007-08-12  Adam Roben  <aroben@apple.com>
+
+        Fix <rdar://problem/5214504> No way to change WebPreferences defaults (all preferences get written to disk)
+
+        We now only write to disk values that have been explicitly set, and
+        never write any default values.
+
+        This is not enough, however, as anyone who has used WebKit prior to
+        this change will have the default values sitting in their preferences
+        plist on disk. To remedy this, we perform a one-time removal of any
+        key-value pairs that match a pair in the defaults dictionary.
+
+        Reviewed by Steve, John, Ada, and Darin.
+
+        * WebPreferenceKeysPrivate.h: Added new key to ensure we only remove
+        the defaults once.
+        * WebPreferences.cpp:
+        (WebPreferences::initializeDefaultSettings): Renamed from initialize, and
+        made sure we only set up the defaults dictionary once. Now that the
+        defaults dictionary is never modified after creation, we don't need to
+        check whether the keys are already present.
+        (WebPreferences::setStringValue): Don't modify the defaults dictionary.
+        (WebPreferences::setIntegerValue): Ditto.
+        (WebPreferences::setBoolValue): Ditto.
+        (WebPreferences::save): Write out the user's preferences, not the defaults.
+        (WebPreferences::load):
+           - Removed gotos and early declarations now that we're using
+             RetainPtr everywhere.
+           - Initialize m_privatePrefs with an empty dictionary if we didn't
+             read in a plist.
+           - Call migrateDefaultSettingsFromSafari3Beta after loading.
+        (WebPreferences::migrateDefaultSettingsFromSafari3Beta): Added.
+        (WebPreferences::removeValuesMatchingDefaultSettings): Added.
+        (WebPreferences::initWithIdentifier): Don't initialize m_privatePrefs
+        -- load() does this now.
+        * WebPreferences.h: Updated/added declarations.
+
 2007-08-12  Adam Roben  <aroben@apple.com>
 
         Use RetainPtr to store WebPreferences::m_privatePrefs
index ab39b0f54c6e63252b1faf1f283ad051bbb07f8b..54caa7e05e5526648c4dda4e9a201a1689999b51 100644 (file)
@@ -93,3 +93,6 @@
 #define AllowContinuousSpellCheckingPreferenceKey "AllowContinuousSpellCheckingPreferenceKey" // default: true
 
 #define WebKitDOMPasteAllowedPreferenceKey "WebKitDOMPasteAllowedPreferenceKey" // default: false
+
+// If this key is present and has a value of true, we have already removed the default values from the user's preferences <rdar://problem/5214504>
+#define WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey "WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey"
index 807d440f8054efddb1d9916bb12f368e799aa52e..0110b8bf99cb97726741d99c170874926ef31130 100644 (file)
@@ -122,10 +122,12 @@ void WebPreferences::removeReferenceForIdentifier(BSTR identifier)
         webPreferencesInstances.remove(identifierString);
 }
 
-void WebPreferences::initialize()
+void WebPreferences::initializeDefaultSettings()
 {
-    if (!m_standardUserDefaults)
-        m_standardUserDefaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+    if (m_standardUserDefaults)
+        return;
+
+    m_standardUserDefaults = 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;
@@ -158,179 +160,56 @@ void WebPreferences::initialize()
     else
         objectCacheSize = 23 * 1024 * 1024; 
 
-    CFStringRef key = CFSTR(WebKitStandardFontPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("Times New Roman"));
-
-    key = CFSTR(WebKitFixedFontPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("Courier New"));
-    
-    key = CFSTR(WebKitSerifFontPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("Times New Roman"));
-    
-    key = CFSTR(WebKitSansSerifFontPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("Arial"));
-
-    key = CFSTR(WebKitCursiveFontPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("Comic Sans MS"));
-
-    key = CFSTR(WebKitFantasyFontPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("Comic Sans MS"));
-
-    key = CFSTR(WebKitMinimumFontSizePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("1"));
-
-    key = CFSTR(WebKitMinimumLogicalFontSizePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("9"));
-
-    key = CFSTR(WebKitDefaultFontSizePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("16"));
-
-    key = CFSTR(WebKitDefaultFixedFontSizePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("13"));
-
-    key = CFSTR(WebKitDefaultTextEncodingNamePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("ISO-8859-1"));
-
-    key = CFSTR(WebKitPageCacheSizePreferenceKey);
-    CFStringRef pageCacheSizeString = CFStringCreateWithFormat(0, 0, CFSTR("%d"), pageCacheSize);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               pageCacheSizeString);
-    CFRelease(pageCacheSizeString);
-
-    key = CFSTR(WebKitObjectCacheSizePreferenceKey);
-    CFStringRef objectCacheSizeString = CFStringCreateWithFormat(0, 0, CFSTR("%d"), objectCacheSize);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               objectCacheSizeString);
-    CFRelease(objectCacheSizeString);
-
-    key = CFSTR(WebKitUserStyleSheetEnabledPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(WebKitUserStyleSheetLocationPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR(""));
-
-    key = CFSTR(WebKitShouldPrintBackgroundsPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(WebKitTextAreasAreResizablePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(WebKitJavaEnabledPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitJavaScriptEnabledPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitJavaScriptCanOpenWindowsAutomaticallyPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitPluginsEnabledPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitAllowAnimatedImagesPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitAllowAnimatedImageLoopingPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitDisplayImagesKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitBackForwardCacheExpirationIntervalKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("1800"));
-
-    key = CFSTR(WebKitTabToLinksPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(WebKitPrivateBrowsingEnabledPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(WebKitRespectStandardStyleKeyEquivalentsPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(WebKitShowsURLsInToolTipsPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(WebKitPDFDisplayModePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("1"));
-
-    key = CFSTR(WebKitPDFScaleFactorPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("0"));
-
-    key = CFSTR(WebKitEditableLinkBehaviorPreferenceKey);
-    CFStringRef linkBehaviorStringRef = CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               linkBehaviorStringRef);
-    CFRelease(linkBehaviorStringRef);
-
-    key = CFSTR(WebKitHistoryItemLimitKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("1000"));
-
-    key = CFSTR(WebKitHistoryAgeInDaysLimitKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("7"));
-
-    key = CFSTR(WebKitIconDatabaseLocationKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR(""));
-
-    key = CFSTR(WebKitIconDatabaseEnabledPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitFontSmothingTypePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("2"));
-
-    key = CFSTR(WebKitCookieStorageAcceptPolicyPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               CFSTR("2"));
-
-    key = CFSTR(WebContinuousSpellCheckingEnabledPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(WebGrammarCheckingEnabledPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanFalse);
-
-    key = CFSTR(AllowContinuousSpellCheckingPreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
-
-    key = CFSTR(WebKitUsesPageCachePreferenceKey);
-    if (!CFDictionaryContainsKey(m_standardUserDefaults, key))
-        CFDictionaryAddValue(m_standardUserDefaults, key,                               kCFBooleanTrue);
+    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"));
+
+    RetainPtr<CFStringRef> pageCacheSizeString(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), pageCacheSize));
+    CFDictionaryAddValue(m_standardUserDefaults, 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"));
+
+    RetainPtr<CFStringRef> linkBehaviorStringRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebKitEditableLinkDefaultBehavior));
+    CFDictionaryAddValue(m_standardUserDefaults, 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);
 }
 
 const void* WebPreferences::valueForKey(CFStringRef key)
@@ -426,10 +305,8 @@ void WebPreferences::setStringValue(CFStringRef key, LPCTSTR value)
     RetainPtr<CFStringRef> valueRef(AdoptCF,
         CFStringCreateWithCharactersNoCopy(0, (UniChar*)_wcsdup(value), (CFIndex)_tcslen(value), kCFAllocatorMalloc));
     CFDictionarySetValue(m_privatePrefs.get(), key, valueRef.get());
-    if (m_autoSaves) {
-        CFDictionarySetValue(m_standardUserDefaults, key, valueRef.get());
+    if (m_autoSaves)
         save();
-    }
 
     postPreferencesChangesNotification();
 }
@@ -447,10 +324,8 @@ void WebPreferences::setIntegerValue(CFStringRef key, int value)
 
     RetainPtr<CFNumberRef> valueRef(AdoptCF, CFNumberCreate(0, kCFNumberSInt32Type, &value));
     CFDictionarySetValue(m_privatePrefs.get(), key, valueRef.get());
-    if (m_autoSaves) {
-        CFDictionarySetValue(m_standardUserDefaults, key, valueRef.get());
+    if (m_autoSaves)
         save();
-    }
 
     postPreferencesChangesNotification();
 }
@@ -461,10 +336,8 @@ void WebPreferences::setBoolValue(CFStringRef key, BOOL value)
         return;
 
     CFDictionarySetValue(m_privatePrefs.get(), key, value ? kCFBooleanTrue : kCFBooleanFalse);
-    if (m_autoSaves) {
-        CFDictionarySetValue(m_standardUserDefaults, key, value ? kCFBooleanTrue : kCFBooleanFalse);
+    if (m_autoSaves)
         save();
-    }
 
     postPreferencesChangesNotification();
 }
@@ -483,7 +356,7 @@ void WebPreferences::save()
     if (!CFWriteStreamOpen(stream.get()))
         return;
 
-    if (!CFPropertyListWriteToStream(m_standardUserDefaults, stream.get(), kCFPropertyListXMLFormat_v1_0, 0)) {
+    if (!CFPropertyListWriteToStream(m_privatePrefs.get(), stream.get(), kCFPropertyListXMLFormat_v1_0, 0)) {
         CFWriteStreamClose(stream.get());
         return;
     }
@@ -501,40 +374,85 @@ void WebPreferences::save()
 
 void WebPreferences::load()
 {
-    if (m_standardUserDefaults) // don't need to read in defaults again
-        return;
+    initializeDefaultSettings();
 
     TCHAR appDataPath[MAX_PATH];
-    RetainPtr<CFURLRef> urlRef;
-    CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0;
-    RetainPtr<CFReadStreamRef> stream;
-    OwnPtr<Vector<UInt8> > utf8Path;
-
     if (FAILED(preferencesPath(appDataPath, MAX_PATH)))
-        goto exit;
+        return;
 
     DWORD appDataPathLength = (DWORD) _tcslen(appDataPath)+1;
     int result = WideCharToMultiByte(CP_UTF8, 0, appDataPath, appDataPathLength, 0, 0, 0, 0);
-    utf8Path.set(new Vector<UInt8>(result));
-    if (!WideCharToMultiByte(CP_UTF8, 0, appDataPath, appDataPathLength, (LPSTR)utf8Path->data(), result, 0, 0))
-        goto exit;
+    Vector<UInt8> utf8Path(result);
+    if (!WideCharToMultiByte(CP_UTF8, 0, appDataPath, appDataPathLength, (LPSTR)utf8Path.data(), result, 0, 0))
+        return;
 
-    urlRef.adoptCF(CFURLCreateFromFileSystemRepresentation(0, *utf8Path, result-1, false));
+    RetainPtr<CFURLRef> urlRef(AdoptCF, CFURLCreateFromFileSystemRepresentation(0, utf8Path.data(), result-1, false));
     if (!urlRef)
-        goto exit;
+        return;
 
-    stream.adoptCF(CFReadStreamCreateWithFile(0, urlRef.get()));
+    RetainPtr<CFReadStreamRef> stream(AdoptCF, CFReadStreamCreateWithFile(0, urlRef.get()));
     if (!stream) 
-        goto exit;
+        return;
 
-    if (!CFReadStreamOpen(stream.get()))
-        goto exit;
+    if (CFReadStreamOpen(stream.get())) {
+        CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0 | kCFPropertyListXMLFormat_v1_0;
+        RetainPtr<CFPropertyListRef> plist(AdoptCF, CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0));
+        CFReadStreamClose(stream.get());
+
+        if (CFGetTypeID(plist.get()) == CFDictionaryGetTypeID())
+            m_privatePrefs.adoptCF(const_cast<CFMutableDictionaryRef>(reinterpret_cast<CFDictionaryRef>(plist.releaseRef())));
+    }
 
-    m_standardUserDefaults = (CFMutableDictionaryRef)CFPropertyListCreateFromStream(0, stream.get(), 0, kCFPropertyListMutableContainersAndLeaves, &format, 0);
-    CFReadStreamClose(stream.get());
+    if (!m_privatePrefs)
+        m_privatePrefs.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
 
-exit:
-    initialize();
+    migrateDefaultSettingsFromSafari3Beta();
+}
+
+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);
+    if (!m_privatePrefs)
+        return;
+
+    CFStringRef didMigrateKey = CFSTR(WebKitDidMigrateDefaultSettingsFromSafari3BetaPreferenceKey);
+    if (boolValueForKey(didMigrateKey))
+        return;
+
+    removeValuesMatchingDefaultSettings();
+
+    bool oldValue = m_autoSaves;
+    m_autoSaves = true;
+    setBoolValue(didMigrateKey, TRUE);
+    m_autoSaves = oldValue;
+}
+
+void WebPreferences::removeValuesMatchingDefaultSettings()
+{
+    ASSERT(m_privatePrefs);
+
+    int count = CFDictionaryGetCount(m_privatePrefs.get());
+    if (count <= 0)
+        return;
+
+    Vector<CFTypeRef> keys(count);
+    Vector<CFTypeRef> values(count);
+    CFDictionaryGetKeysAndValues(m_privatePrefs.get(), keys.data(), values.data());
+
+    for (int i = 0; i < count; ++i) {
+        if (!values[i])
+            continue;
+
+        CFTypeRef defaultValue = CFDictionaryGetValue(m_standardUserDefaults, keys[i]);
+        if (!defaultValue)
+            continue;
+
+        if (CFEqual(values[i], defaultValue))
+            CFDictionaryRemoveValue(m_privatePrefs.get(), keys[i]);
+    }
 }
 
 HRESULT WebPreferences::preferencesPath(LPTSTR path, size_t cchPath)
@@ -681,8 +599,6 @@ HRESULT STDMETHODCALLTYPE WebPreferences::initWithIdentifier(
 
     load();
 
-    m_privatePrefs.adoptCF(CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-
     *preferences = this;
     AddRef();
 
index c2ec506e1d6e91f3c454aeec7d4dbbebe34a596b..bf152233c6875f31e9970e69baa3e46969a2f991 100644 (file)
@@ -293,9 +293,11 @@ protected:
     void setIntegerValue(CFStringRef key, int value);
     void setBoolValue(CFStringRef key, BOOL value);
     static WebPreferences* getInstanceForIdentifier(BSTR identifier);
-    static void initialize();
-    static void save();
-    static void load();
+    static void initializeDefaultSettings();
+    void save();
+    void load();
+    void migrateDefaultSettingsFromSafari3Beta();
+    void removeValuesMatchingDefaultSettings();
     static HRESULT preferencesPath(LPTSTR path, size_t cchPath);
     static HRESULT safeCreateFileWithData(LPCTSTR path, void* data, size_t length);