Reviewed by Steve Falkenburg.
authorweinig <weinig@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Oct 2007 00:10:07 +0000 (00:10 +0000)
committerweinig <weinig@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Oct 2007 00:10:07 +0000 (00:10 +0000)
        Fix for <rdar://problem/5463608>
        Port WebKit cache model code (Windows needs a big disk cache, smarter memory cache)

        * Interfaces/IWebPreferences.idl:
        Deprecate pageCacheSize and objectCacheSize and add cacheModel/setCacheModel.

        * Interfaces/IWebPreferencesPrivate.idl:
        Add automaticallyDetectsCacheModel/setAutomaticallyDetectsCacheModel

        * WebFrame.cpp:
        (WebFrame::didPerformFirstNavigation):
        Implement based on the mac version.

        * WebKit.vcproj/WebKit.vcproj:
        * WebKitSystemBits.cpp: Added.
        (WebMemorySize): Moved and renamed from WebPreferences.cpp
        (WebVolumeFreeSize): Added.
        * WebKitSystemBits.h: Added.
        * WebPreferenceKeysPrivate.h: Added WebKitCacheModelPreferenceKey.

        * WebPreferences.cpp:
        (WebPreferences::sharedStandardPreferences):
        (WebPreferences::WebPreferences):
        (WebPreferences::initializeDefaultSettings): Added default for cacheModel.
        (WebPreferences::webPreferencesChangedNotification):
        (WebPreferences::webPreferencesRemovedNotification):
        (WebPreferences::initWithIdentifier): Post a preferences change notification.
        (WebPreferences::pageCacheSize): Deprecated.
        (WebPreferences::objectCacheSize): Deprecated.
        (WebPreferences::cacheModel): Added.
        (WebPreferences::setCacheModel): Added.
        (WebPreferences::setAutomaticallyDetectsCacheModel): Added.
        (WebPreferences::automaticallyDetectsCacheModel): Added.
        (WebPreferences::willAddToWebView): Added.
        (WebPreferences::didRemoveFromWebView): Added.
        * WebPreferences.h:

        * WebView.cpp:
        (PreferencesChangedOrRemovedObserver::PreferencesChangedOrRemovedObserver):
        (PreferencesChangedOrRemovedObserver::~PreferencesChangedOrRemovedObserver):
        (PreferencesChangedOrRemovedObserver::QueryInterface):
        (PreferencesChangedOrRemovedObserver::AddRef):
        (PreferencesChangedOrRemovedObserver::Release):
        (PreferencesChangedOrRemovedObserver::sharedInstance):
        (PreferencesChangedOrRemovedObserver::onNotify):
        (PreferencesChangedOrRemovedObserver::notifyPreferencesChanged):
        (PreferencesChangedOrRemovedObserver::notifyPreferencesRemoved):
        This singleton class updates static properties for all webviews when
        preferenceChange or preferenceRemoved notifications are fired for
        any WebPreference.
        (WebView::WebView):
        (WebView::~WebView):
        (initializeStaticObservers):
        (allWebViewsSet):
        (WebView::addToAllWebViewsSet):
        (WebView::removeFromAllWebViewsSet):
        (WebView::setCacheModel):
        (WebView::cacheModel):
        (WebView::didSetCacheModel):
        (WebView::maxCacheModelInAnyInstance):
        (WebView::close):
        (WebViewWndProc):
        (WebView::developerExtrasEnabled):
        (WebView::initWithFrame):
        (WebView::setPreferences):
        (WebView::preferences):
        (WebView::onNotify):
        (WebView::notifyPreferencesChanged):
        (updateSharedSettingsFromPreferencesIfNeeded):
        * WebView.h:
        Match the macs behavior by using explicit postings of notifications to
        update the preferences.

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

12 files changed:
WebKit/win/ChangeLog
WebKit/win/Interfaces/IWebPreferences.idl
WebKit/win/Interfaces/IWebPreferencesPrivate.idl
WebKit/win/WebFrame.cpp
WebKit/win/WebKit.vcproj/WebKit.vcproj
WebKit/win/WebKitSystemBits.cpp [new file with mode: 0644]
WebKit/win/WebKitSystemBits.h [new file with mode: 0644]
WebKit/win/WebPreferenceKeysPrivate.h
WebKit/win/WebPreferences.cpp
WebKit/win/WebPreferences.h
WebKit/win/WebView.cpp
WebKit/win/WebView.h

index d84e8ada14d3d79e5a32420c1a7ce874fac6761b..7796089718d48da506e057e360a202a8072e3a3e 100644 (file)
@@ -1,3 +1,80 @@
+2007-10-25  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Steve Falkenburg.
+
+        Fix for <rdar://problem/5463608>
+        Port WebKit cache model code (Windows needs a big disk cache, smarter memory cache) 
+
+        * Interfaces/IWebPreferences.idl: 
+        Deprecate pageCacheSize and objectCacheSize and add cacheModel/setCacheModel.
+
+        * Interfaces/IWebPreferencesPrivate.idl:
+        Add automaticallyDetectsCacheModel/setAutomaticallyDetectsCacheModel
+     
+        * WebFrame.cpp:
+        (WebFrame::didPerformFirstNavigation):
+        Implement based on the mac version.
+
+        * WebKit.vcproj/WebKit.vcproj:
+        * WebKitSystemBits.cpp: Added.
+        (WebMemorySize): Moved and renamed from WebPreferences.cpp
+        (WebVolumeFreeSize): Added.
+        * WebKitSystemBits.h: Added.
+        * WebPreferenceKeysPrivate.h: Added WebKitCacheModelPreferenceKey.
+
+        * WebPreferences.cpp:
+        (WebPreferences::sharedStandardPreferences):
+        (WebPreferences::WebPreferences):
+        (WebPreferences::initializeDefaultSettings): Added default for cacheModel.
+        (WebPreferences::webPreferencesChangedNotification):
+        (WebPreferences::webPreferencesRemovedNotification):
+        (WebPreferences::initWithIdentifier): Post a preferences change notification.
+        (WebPreferences::pageCacheSize): Deprecated.
+        (WebPreferences::objectCacheSize): Deprecated.
+        (WebPreferences::cacheModel): Added.
+        (WebPreferences::setCacheModel): Added.
+        (WebPreferences::setAutomaticallyDetectsCacheModel): Added.
+        (WebPreferences::automaticallyDetectsCacheModel): Added.
+        (WebPreferences::willAddToWebView): Added.
+        (WebPreferences::didRemoveFromWebView): Added.
+        * WebPreferences.h:
+
+        * WebView.cpp:
+        (PreferencesChangedOrRemovedObserver::PreferencesChangedOrRemovedObserver):
+        (PreferencesChangedOrRemovedObserver::~PreferencesChangedOrRemovedObserver):
+        (PreferencesChangedOrRemovedObserver::QueryInterface):
+        (PreferencesChangedOrRemovedObserver::AddRef):
+        (PreferencesChangedOrRemovedObserver::Release):
+        (PreferencesChangedOrRemovedObserver::sharedInstance):
+        (PreferencesChangedOrRemovedObserver::onNotify):
+        (PreferencesChangedOrRemovedObserver::notifyPreferencesChanged):
+        (PreferencesChangedOrRemovedObserver::notifyPreferencesRemoved):
+        This singleton class updates static properties for all webviews when
+        preferenceChange or preferenceRemoved notifications are fired for
+        any WebPreference.
+        (WebView::WebView):
+        (WebView::~WebView):
+        (initializeStaticObservers):
+        (allWebViewsSet):
+        (WebView::addToAllWebViewsSet):
+        (WebView::removeFromAllWebViewsSet):
+        (WebView::setCacheModel):
+        (WebView::cacheModel):
+        (WebView::didSetCacheModel):
+        (WebView::maxCacheModelInAnyInstance):
+        (WebView::close):
+        (WebViewWndProc):
+        (WebView::developerExtrasEnabled):
+        (WebView::initWithFrame):
+        (WebView::setPreferences):
+        (WebView::preferences):
+        (WebView::onNotify):
+        (WebView::notifyPreferencesChanged):
+        (updateSharedSettingsFromPreferencesIfNeeded):
+        * WebView.h:
+        Match the macs behavior by using explicit postings of notifications to
+        update the preferences.
+
 2007-10-25  Adam Roben  <aroben@apple.com>
 
         Update WebKit.sln for the removal of Release dftables
index 56fb54529a6fc3fd9cb53855e9a18bb0aa6e1af9..9bc0dc86d06d8f09a4c8fb7017842648e468ade0 100644 (file)
@@ -49,6 +49,7 @@ cpp_quote(" * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAG
 cpp_quote(" */")
 
 cpp_quote("#define WebPreferencesChangedNotification TEXT(\"WebPreferencesChangedNotification\")")
+cpp_quote("#define WebPreferencesRemovedNotification TEXT(\"WebPreferencesRemovedNotification\")")
 
 import "oaidl.idl";
 import "ocidl.idl";
@@ -168,8 +169,8 @@ interface IWebPreferences : IUnknown
     HRESULT textAreasAreResizable([out, retval] BOOL* enabled);
     HRESULT setTextAreasAreResizable([in] BOOL enabled);
 
-    HRESULT pageCacheSize([out, retval] unsigned int* enabled);
-    HRESULT objectCacheSize([out, retval] unsigned int* enabled);
+    HRESULT unused1();
+    HRESULT unused2();
 
     HRESULT iconDatabaseLocation([out, retval] BSTR* location);
     HRESULT setIconDatabaseLocation([in] BSTR location);
@@ -198,4 +199,7 @@ interface IWebPreferences : IUnknown
 
     HRESULT usesPageCache([out, retval] BOOL* usesPageCache);
     HRESULT setUsesPageCache([in] BOOL usesPageCache);
+
+    HRESULT cacheModel([out, retval] WebCacheModel* cacheModel);
+    HRESULT setCacheModel([in] WebCacheModel cacheModel);
 }
index 676011a53e0df9845b651ced510a315ad8ef1495..e52402466c3fc910d7fddb73356f86c342ea1140 100644 (file)
@@ -68,4 +68,7 @@ interface IWebPreferencesPrivate : IUnknown
 {
     HRESULT setDeveloperExtrasEnabled([in] BOOL enabled);
     HRESULT developerExtrasEnabled([out, retval] BOOL* enabled);
+
+    HRESULT setAutomaticallyDetectsCacheModel([in] BOOL automaticallyDetectsCacheModel);
+    HRESULT automaticallyDetectsCacheModel([out, retval] BOOL* automaticallyDetectsCacheModel);
 }
index 9d88cfc2374485afd876c5d4c44ae8b673f1a59c..5368c5c16ee40d11b6299f63f6adc2d06e5c9307 100644 (file)
@@ -2398,6 +2398,23 @@ void WebFrame::windowObjectCleared() const
 
 void WebFrame::didPerformFirstNavigation() const
 {
+    COMPtr<IWebPreferences> preferences;
+    if (FAILED(d->webView->preferences(&preferences)))
+        return;
+
+    COMPtr<IWebPreferencesPrivate> preferencesPrivate(Query, preferences);
+    if (!preferencesPrivate)
+        return;
+    BOOL automaticallyDetectsCacheModel;
+    if (FAILED(preferencesPrivate->automaticallyDetectsCacheModel(&automaticallyDetectsCacheModel)))
+        return;
+
+    WebCacheModel cacheModel;
+    if (FAILED(preferences->cacheModel(&cacheModel)))
+        return;
+
+    if (automaticallyDetectsCacheModel && cacheModel < WebCacheModelDocumentBrowser)
+        preferences->setCacheModel(WebCacheModelDocumentBrowser);
 }
 
 void WebFrame::registerForIconNotification(bool listen)
index 20b6c4864a37dd774ecf8da998dd25a18502670e..dbcbb303643678913328dd7a99aa8e3d247d15ab 100644 (file)
                                RelativePath="..\WebKitDLL.cpp"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\WebKitSystemBits.cpp"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\WebNodeHighlight.cpp"\r
                                >\r
                                RelativePath="..\WebKitStatisticsPrivate.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\WebKitSystemBits.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\WebLocalizableStrings.h"\r
                                >\r
diff --git a/WebKit/win/WebKitSystemBits.cpp b/WebKit/win/WebKitSystemBits.cpp
new file mode 100644 (file)
index 0000000..e8ee0e9
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebKitSystemBits.h"
+
+#pragma warning(push, 0)
+#include <WebCore/PlatformString.h>
+#pragma warning(pop)
+
+#include <windows.h>
+#include <CoreFoundation/CoreFoundation.h>
+
+unsigned long long WebMemorySize()
+{
+    MEMORYSTATUSEX statex;
+    statex.dwLength = sizeof(statex);
+    GlobalMemoryStatusEx(&statex);
+    return statex.ullTotalPhys;
+}
+
+unsigned long long WebVolumeFreeSize(CFStringRef cfstringPath)
+{
+    WebCore::String path(cfstringPath);
+    ULARGE_INTEGER freeBytesToCaller;
+    BOOL result = GetDiskFreeSpaceExW((LPCWSTR)path.charactersWithNullTermination(), &freeBytesToCaller, 0, 0);
+    if (!result)
+        return 0;
+
+    return freeBytesToCaller.QuadPart;
+}
diff --git a/WebKit/win/WebKitSystemBits.h b/WebKit/win/WebKitSystemBits.h
new file mode 100644 (file)
index 0000000..7461696
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2007 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebKitSystemBits_h
+#define WebKitSystemBits_h
+
+typedef const struct __CFString* CFStringRef;
+
+unsigned long long WebMemorySize();
+unsigned long long WebVolumeFreeSize(CFStringRef path);
+
+#endif // WebKitSystemBits_h
index 44d2789315781beb53666d2185ce5db89741fb23..4e91f46c762d034fa2cbc89a0ad6c7386ac6a842 100644 (file)
 #define WebKitAllowAnimatedImagesPreferenceKey "WebKitAllowAnimatedImagesPreferenceKey"
 #define WebKitAllowAnimatedImageLoopingPreferenceKey "WebKitAllowAnimatedImageLoopingPreferenceKey"
 #define WebKitDisplayImagesKey "WebKitDisplayImagesKey"
-#define WebKitPageCacheSizePreferenceKey "WebKitPageCacheSizePreferenceKey"
-#define WebKitObjectCacheSizePreferenceKey "WebKitObjectCacheSizePreferenceKey"
 #define WebKitBackForwardCacheExpirationIntervalKey "WebKitBackForwardCacheExpirationIntervalKey"
 #define WebKitTabToLinksPreferenceKey "WebKitTabToLinksPreferenceKey"
 #define WebKitPrivateBrowsingEnabledPreferenceKey "WebKitPrivateBrowsingEnabled"
 #define WebKitIconDatabaseLocationKey "WebKitIconDatabaseLocation"
 #define WebKitIconDatabaseEnabledPreferenceKey "WebKitIconDatabaseEnabled"
 #define WebKitUsesPageCachePreferenceKey "WebKitUsesPageCachePreferenceKey"
+#define WebKitCacheModelPreferenceKey "WebKitCacheModelPreferenceKey"
 
 // These are private both because callers should be using the cover methods and because the
 // cover methods themselves are private.
 // default.
 #define WebKitEnableDeferredUpdatesPreferenceKey "WebKitEnableDeferredUpdates"
 
+// For debugging only.  Don't use these.
+#define WebKitPageCacheSizePreferenceKey "WebKitPageCacheSizePreferenceKey"
+#define WebKitObjectCacheSizePreferenceKey "WebKitObjectCacheSizePreferenceKey"
+
 // From WebHistory.h
 #define WebKitHistoryItemLimitKey "WebKitHistoryItemLimit" // default: "1000"
 #define WebKitHistoryAgeInDaysLimitKey "WebKitHistoryAgeInDaysLimit" // default: "7"
index 43d1f51f18135e06b1b3470ba45ded6608b85be9..6cfcb1d830095456c48223aff949fe44384828d0 100644 (file)
@@ -27,6 +27,7 @@
 #include "WebKit.h"
 #include "WebKitDLL.h"
 #include "WebPreferences.h"
+#include "WebKit.h"
 
 #include "WebNotificationCenter.h"
 #include "WebPreferenceKeysPrivate.h"
 
 using namespace WebCore;
 
-static unsigned long long WebSystemMainMemory()
-{
-    MEMORYSTATUSEX statex;
-    
-    statex.dwLength = sizeof(statex);
-    GlobalMemoryStatusEx(&statex);
-    return statex.ullTotalPhys;
-}
-
 static String preferencesPath()
 {
     static String path = pathByAppendingComponent(roamingUserSpecificStorageDirectory(), "WebKitPreferences.plist");
@@ -80,15 +72,16 @@ WebPreferences* WebPreferences::sharedStandardPreferences()
         standardPreferences = WebPreferences::createInstance();
         standardPreferences->load();
         standardPreferences->setAutosaves(TRUE);
-        standardPreferences->postPreferencesChangesNotification();
     }
 
     return standardPreferences;
 }
 
 WebPreferences::WebPreferences()
-: m_refCount(0)
-, m_autoSaves(0)
+    : m_refCount(0)
+    , m_autoSaves(0)
+    , m_automaticallyDetectsCacheModel(true)
+    , m_numWebViews(0)
 {
     gClassCount++;
 }
@@ -150,37 +143,6 @@ void WebPreferences::initializeDefaultSettings()
 
     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;
-
-    // Page cache size (in pages)
-    int pageCacheSize;
-    if (memSize >= 1024)
-        pageCacheSize = 10;
-    else if (memSize >= 512)
-        pageCacheSize = 5;
-    else if (memSize >= 384)
-        pageCacheSize = 4;
-    else if (memSize >= 256)
-        pageCacheSize = 3;
-    else if (memSize >= 128)
-        pageCacheSize = 2;
-    else if (memSize >= 64)
-        pageCacheSize = 1;
-    else
-        pageCacheSize = 0;
-
-    // Object cache size (in bytes)
-    int objectCacheSize;
-    if (memSize >= 2048)
-        objectCacheSize = 128 * 1024 * 1024;
-    else if (memSize >= 1024)
-        objectCacheSize = 64 * 1024 * 1024;
-    else if (memSize >= 512)
-        objectCacheSize = 32 * 1024 * 1024;
-    else
-        objectCacheSize = 24 * 1024 * 1024; 
-
     CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman"));
     CFDictionaryAddValue(defaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New"));
     CFDictionaryAddValue(defaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman"));
@@ -194,12 +156,6 @@ void WebPreferences::initializeDefaultSettings()
     WebCore::String defaultDefaultEncoding(LPCTSTR_UI_STRING("ISO-8859-1", "The default, default character encoding"));
     CFDictionaryAddValue(defaults, CFSTR(WebKitDefaultTextEncodingNamePreferenceKey), defaultDefaultEncoding.createCFString());
 
-    RetainPtr<CFStringRef> pageCacheSizeString(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), pageCacheSize));
-    CFDictionaryAddValue(defaults, CFSTR(WebKitPageCacheSizePreferenceKey), pageCacheSizeString.get());
-
-    RetainPtr<CFStringRef> objectCacheSizeString(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), objectCacheSize));
-    CFDictionaryAddValue(defaults, CFSTR(WebKitObjectCacheSizePreferenceKey), objectCacheSizeString.get());
-
     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetEnabledPreferenceKey), kCFBooleanFalse);
     CFDictionaryAddValue(defaults, CFSTR(WebKitUserStyleSheetLocationPreferenceKey), CFSTR(""));
     CFDictionaryAddValue(defaults, CFSTR(WebKitShouldPrintBackgroundsPreferenceKey), kCFBooleanFalse);
@@ -233,6 +189,9 @@ void WebPreferences::initializeDefaultSettings()
     CFDictionaryAddValue(defaults, CFSTR(AllowContinuousSpellCheckingPreferenceKey), kCFBooleanTrue);
     CFDictionaryAddValue(defaults, CFSTR(WebKitUsesPageCachePreferenceKey), kCFBooleanTrue);
 
+    RetainPtr<CFStringRef> cacheModelRef(AdoptCF, CFStringCreateWithFormat(0, 0, CFSTR("%d"), WebCacheModelDocumentViewer));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitCacheModelPreferenceKey), cacheModelRef.get());
+
     s_defaultSettings = defaults;
 }
 
@@ -335,12 +294,6 @@ void WebPreferences::setStringValue(CFStringRef key, LPCTSTR value)
     postPreferencesChangesNotification();
 }
 
-BSTR WebPreferences::webPreferencesChangedNotification()
-{
-    static BSTR webPreferencesChangedNotification = SysAllocString(WebPreferencesChangedNotification);
-    return webPreferencesChangedNotification;
-}
-
 void WebPreferences::setIntegerValue(CFStringRef key, int value)
 {
     if (integerValueForKey(key) == value)
@@ -366,6 +319,17 @@ void WebPreferences::setBoolValue(CFStringRef key, BOOL value)
     postPreferencesChangesNotification();
 }
 
+BSTR WebPreferences::webPreferencesChangedNotification()
+{
+    static BSTR webPreferencesChangedNotification = SysAllocString(WebPreferencesChangedNotification);
+    return webPreferencesChangedNotification;
+}
+
+BSTR WebPreferences::webPreferencesRemovedNotification()
+{
+    static BSTR webPreferencesRemovedNotification = SysAllocString(WebPreferencesRemovedNotification);
+    return webPreferencesRemovedNotification;
+}
 void WebPreferences::save()
 {
     RetainPtr<CFWriteStreamRef> stream(AdoptCF,
@@ -532,6 +496,8 @@ HRESULT STDMETHODCALLTYPE WebPreferences::initWithIdentifier(
         setInstance(this, m_identifier);
     }
 
+    this->postPreferencesChangesNotification();
+
     return S_OK;
 }
 
@@ -932,16 +898,16 @@ HRESULT WebPreferences::setHistoryAgeInDaysLimit(int limit)
     return S_OK;
 }
 
-HRESULT WebPreferences::pageCacheSize(unsigned int* limit)
+HRESULT WebPreferences::unused1()
 {
-    *limit = integerValueForKey(CFSTR(WebKitPageCacheSizePreferenceKey));
-    return S_OK;
+    ASSERT_NOT_REACHED();
+    return E_FAIL;
 }
 
-HRESULT WebPreferences::objectCacheSize(unsigned int* limit)
+HRESULT WebPreferences::unused2()
 {
-    *limit = integerValueForKey(CFSTR(WebKitObjectCacheSizePreferenceKey));
-    return S_OK;
+    ASSERT_NOT_REACHED();
+    return E_FAIL;
 }
 
 HRESULT WebPreferences::iconDatabaseLocation(
@@ -1077,6 +1043,21 @@ HRESULT WebPreferences::setDOMPasteAllowed(BOOL enabled)
     return S_OK;
 }
 
+HRESULT WebPreferences::cacheModel(WebCacheModel* cacheModel)
+{
+    if (!cacheModel)
+        return E_POINTER;
+
+    *cacheModel = (WebCacheModel)integerValueForKey(CFSTR(WebKitCacheModelPreferenceKey));
+    return S_OK;
+}
+
+HRESULT WebPreferences::setCacheModel(WebCacheModel cacheModel)
+{
+    setIntegerValue(CFSTR(WebKitCacheModelPreferenceKey), cacheModel);
+    return S_OK;
+}
+
 HRESULT WebPreferences::setDeveloperExtrasEnabled(BOOL enabled)
 {
     setBoolValue(CFSTR(WebKitDeveloperExtrasEnabledPreferenceKey), enabled);
@@ -1096,3 +1077,32 @@ bool WebPreferences::developerExtrasDisabledByOverride()
 {
     return !!boolValueForKey(CFSTR(DisableWebKitDeveloperExtrasPreferenceKey));
 }
+
+HRESULT WebPreferences::setAutomaticallyDetectsCacheModel(BOOL automaticallyDetectsCacheModel)
+{
+    m_automaticallyDetectsCacheModel = !!automaticallyDetectsCacheModel;
+    return S_OK;
+}
+
+HRESULT WebPreferences::automaticallyDetectsCacheModel(BOOL* automaticallyDetectsCacheModel)
+{
+    if (!automaticallyDetectsCacheModel)
+        return E_POINTER;
+
+    *automaticallyDetectsCacheModel = m_automaticallyDetectsCacheModel;
+    return S_OK;
+}
+
+void WebPreferences::willAddToWebView()
+{
+    ++m_numWebViews;
+}
+
+void WebPreferences::didRemoveFromWebView()
+{
+    ASSERT(m_numWebViews);
+    if (--m_numWebViews == 0) {
+        IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
+        nc->postNotificationName(webPreferencesRemovedNotification(), static_cast<IWebPreferences*>(this), 0);
+    }
+}
index 34309ae1fdb4f4299c8ddf60f21d7ed88b39c3da..5a81f8ca54198008f84d81dee0d85fd2f6a132e0 100644 (file)
@@ -212,12 +212,9 @@ public:
     virtual HRESULT STDMETHODCALLTYPE setUsesPageCache( 
         /* [in] */ BOOL usesPageCache);
 
-    virtual HRESULT STDMETHODCALLTYPE pageCacheSize( 
-        /* [retval][out] */ unsigned int *limit);
+    virtual HRESULT STDMETHODCALLTYPE unused1();
+    virtual HRESULT STDMETHODCALLTYPE unused2();
 
-    virtual HRESULT STDMETHODCALLTYPE objectCacheSize( 
-        /* [retval][out] */ unsigned int *limit);
-    
     virtual HRESULT STDMETHODCALLTYPE iconDatabaseLocation(
         /* [retval][out] */ BSTR* location);
 
@@ -272,6 +269,12 @@ public:
     virtual HRESULT STDMETHODCALLTYPE setDOMPasteAllowed( 
         /* [in] */ BOOL enabled);
 
+     virtual HRESULT STDMETHODCALLTYPE cacheModel(
+         /* [retval][out] */ WebCacheModel* cacheModel);
+
+     virtual HRESULT STDMETHODCALLTYPE setCacheModel(
+         /* [in] */ WebCacheModel cacheModel);
+
     // IWebPreferencesPrivate
     virtual HRESULT STDMETHODCALLTYPE setDeveloperExtrasEnabled(
         /* [in] */ BOOL);
@@ -279,6 +282,11 @@ public:
     virtual HRESULT STDMETHODCALLTYPE developerExtrasEnabled(
         /* [retval][out] */ BOOL*);
 
+     virtual HRESULT STDMETHODCALLTYPE setAutomaticallyDetectsCacheModel(
+         /* [in] */ BOOL automaticallyDetectsCacheModel);
+
+     virtual HRESULT STDMETHODCALLTYPE automaticallyDetectsCacheModel(
+         /* [out, retval] */ BOOL* automaticallyDetectsCacheModel);
 
     // WebPreferences
 
@@ -287,6 +295,8 @@ public:
     bool developerExtrasDisabledByOverride();
 
     static BSTR webPreferencesChangedNotification();
+    static BSTR webPreferencesRemovedNotification();
+
     static void setInstance(WebPreferences* instance, BSTR identifier);
     static void removeReferenceForIdentifier(BSTR identifier);
     static WebPreferences* sharedStandardPreferences();
@@ -297,8 +307,12 @@ public:
     HRESULT historyAgeInDaysLimit(int* limit);
     HRESULT setHistoryAgeInDaysLimit(int limit);
 
-protected:
+     void willAddToWebView();
+     void didRemoveFromWebView();
+
     HRESULT postPreferencesChangesNotification();
+
+protected:
     const void* valueForKey(CFStringRef key);
     BSTR stringValueForKey(CFStringRef key);
     int integerValueForKey(CFStringRef key);
@@ -317,8 +331,11 @@ protected:
 protected:
     ULONG m_refCount;
     RetainPtr<CFMutableDictionaryRef> m_privatePrefs;
-    bool m_autoSaves;
     WebCore::BString m_identifier;
+    bool m_autoSaves;
+    bool m_automaticallyDetectsCacheModel;
+    unsigned m_numWebViews;
+
     static CFDictionaryRef s_defaultSettings;
     static WebPreferences* s_standardPreferences;
 };
index ffbcacccc2b4a89e9ac8dfc7268e6a21fd8a47eb..0a4381b6a802e9f200f5ea05f795c3f802c2da4a 100644 (file)
@@ -43,6 +43,7 @@
 #include "WebInspectorClient.h"
 #include "WebKit.h"
 #include "WebKitStatisticsPrivate.h"
+#include "WebKitSystemBits.h"
 #include "WebMutableURLRequest.h"
 #include "WebNotificationCenter.h"
 #include "WebPreferences.h"
@@ -60,6 +61,7 @@
 #include <WebCore/DragData.h>
 #include <WebCore/Editor.h>
 #include <WebCore/EventHandler.h>
+#include <WebCore/FileSystem.h>
 #include <WebCore/FocusController.h>
 #include <WebCore/FrameLoader.h>
 #include <WebCore/FrameTree.h>
 #pragma warning(pop)
 #include <JavaScriptCore/collector.h>
 #include <JavaScriptCore/value.h>
+#include <CFNetwork/CFURLCachePriv.h>
 #include <CFNetwork/CFURLProtocolPriv.h>
+#include <CoreFoundation/CoreFoundation.h>
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
+#include <wtf/HashSet.h>
 #include <tchar.h>
 #include <dimm.h>
 #include <windowsx.h>
 using namespace WebCore;
 using KJS::JSLock;
 using std::min;
+using std::max;
+
+class PreferencesChangedOrRemovedObserver : public IWebNotificationObserver {
+public:
+    static PreferencesChangedOrRemovedObserver* sharedInstance();
+
+private:
+    PreferencesChangedOrRemovedObserver() {}
+    ~PreferencesChangedOrRemovedObserver() {}
+
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**) { return E_FAIL; }
+    virtual ULONG STDMETHODCALLTYPE AddRef(void) { return 0; }
+    virtual ULONG STDMETHODCALLTYPE Release(void) { return 0; }
+
+public:
+    // IWebNotificationObserver
+    virtual HRESULT STDMETHODCALLTYPE onNotify( 
+        /* [in] */ IWebNotification* notification);
+
+private:
+    HRESULT notifyPreferencesChanged(WebCacheModel);
+    HRESULT notifyPreferencesRemoved(WebCacheModel);
+};
+
+PreferencesChangedOrRemovedObserver* PreferencesChangedOrRemovedObserver::sharedInstance()
+{
+    static PreferencesChangedOrRemovedObserver* shared = new PreferencesChangedOrRemovedObserver;
+    return shared;
+}
+
+HRESULT PreferencesChangedOrRemovedObserver::onNotify(IWebNotification* notification)
+{
+    HRESULT hr = S_OK;
+
+    COMPtr<IUnknown> unkPrefs;
+    hr = notification->getObject(&unkPrefs);
+    if (FAILED(hr))
+        return hr;
+
+    COMPtr<IWebPreferences> preferences(Query, unkPrefs);
+    if (preferences)
+        return E_NOINTERFACE;
+
+    WebCacheModel cacheModel;
+    hr = preferences->cacheModel(&cacheModel);
+    if (FAILED(hr))
+        return hr;
+
+    BSTR nameBSTR;
+    hr = notification->name(&nameBSTR);
+    if (FAILED(hr))
+        return hr;
+    BString name;
+    name.adoptBSTR(nameBSTR);
+
+    if (wcscmp(name, WebPreferences::webPreferencesChangedNotification()) == 0)
+        return notifyPreferencesChanged(cacheModel);
+
+    if (wcscmp(name, WebPreferences::webPreferencesRemovedNotification()) == 0)
+        return notifyPreferencesRemoved(cacheModel);
+
+    ASSERT_NOT_REACHED();
+    return E_FAIL;
+}
+
+HRESULT PreferencesChangedOrRemovedObserver::notifyPreferencesChanged(WebCacheModel cacheModel)
+{
+    HRESULT hr = S_OK;
+
+    if (WebView::didSetCacheModel() || cacheModel > WebView::cacheModel())
+        WebView::setCacheModel(cacheModel);
+    else if (cacheModel < WebView::cacheModel()) {
+        WebCacheModel sharedPreferencesCacheModel;
+        hr = WebPreferences::sharedStandardPreferences()->cacheModel(&sharedPreferencesCacheModel);
+        if (FAILED(hr))
+            return hr;
+        WebView::setCacheModel(max(sharedPreferencesCacheModel, WebView::maxCacheModelInAnyInstance()));
+    }
+
+    return hr;
+}
+
+HRESULT PreferencesChangedOrRemovedObserver::notifyPreferencesRemoved(WebCacheModel cacheModel)
+{
+    HRESULT hr = S_OK;
+
+    if (cacheModel == WebView::cacheModel()) {
+        WebCacheModel sharedPreferencesCacheModel;
+        hr = WebPreferences::sharedStandardPreferences()->cacheModel(&sharedPreferencesCacheModel);
+        if (FAILED(hr))
+            return hr;
+        WebView::setCacheModel(max(sharedPreferencesCacheModel, WebView::maxCacheModelInAnyInstance()));
+    }
+
+    return hr;
+}
+
 
 const LPCWSTR kWebViewWindowClassName = L"WebViewWindowClass";
 
@@ -111,11 +213,18 @@ static const int maxToolTipWidth = 250;
 static ATOM registerWebView();
 static LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
 
+static void initializeStaticObservers();
+
+static HRESULT updateSharedSettingsFromPreferencesIfNeeded(IWebPreferences*);
+
 HRESULT createMatchEnumerator(Vector<IntRect>* rects, IEnumTextMatches** matches);
 
 static bool continuousSpellCheckingEnabled;
 static bool grammarCheckingEnabled;
 
+static bool s_didSetCacheModel;
+static WebCacheModel s_cacheModel = WebCacheModelDocumentViewer;
+
 // WebView ----------------------------------------------------------------
 
 bool WebView::s_allowSiteSpecificHacks = false;
@@ -148,16 +257,17 @@ WebView::WebView()
 
     CoCreateInstance(CLSID_DragDropHelper, 0, CLSCTX_INPROC_SERVER, IID_IDropTargetHelper,(void**)&m_dropTargetHelper);
 
-    COMPtr<IWebPreferences> prefs;
-    if (SUCCEEDED(preferences(&prefs))) {
-        BOOL enabled;
-        if (SUCCEEDED(prefs->continuousSpellCheckingEnabled(&enabled)))
-            continuousSpellCheckingEnabled = !!enabled;
-        if (SUCCEEDED(prefs->grammarCheckingEnabled(&enabled)))
-            grammarCheckingEnabled = !!enabled;
-    }
+    initializeStaticObservers();
+
+    WebPreferences* sharedPreferences = WebPreferences::sharedStandardPreferences();
+    BOOL enabled;
+    if (SUCCEEDED(sharedPreferences->continuousSpellCheckingEnabled(&enabled)))
+        continuousSpellCheckingEnabled = !!enabled;
+    if (SUCCEEDED(sharedPreferences->grammarCheckingEnabled(&enabled)))
+        grammarCheckingEnabled = !!enabled;
 
     WebScriptDebugServer::viewAdded(this);
+
     WebViewCount++;
     gClassCount++;
 }
@@ -172,7 +282,8 @@ WebView::~WebView()
     if (::IsWindow(m_viewWindow))
         ::DestroyWindow(m_viewWindow);
 
-    delete m_page;
+    ASSERT(!m_page);
+    ASSERT(!m_preferences);
 
     WebScriptDebugServer::viewRemoved(this);
     WebViewCount--;
@@ -186,6 +297,262 @@ WebView* WebView::createInstance()
     return instance;
 }
 
+void initializeStaticObservers()
+{
+    static bool initialized;
+    if (initialized)
+        return;
+    initialized = true;
+
+    IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
+    notifyCenter->addObserver(PreferencesChangedOrRemovedObserver::sharedInstance(), WebPreferences::webPreferencesChangedNotification(), 0);
+    notifyCenter->addObserver(PreferencesChangedOrRemovedObserver::sharedInstance(), WebPreferences::webPreferencesRemovedNotification(), 0);
+}
+
+static HashSet<WebView*>& allWebViewsSet()
+{
+    static HashSet<WebView*> allWebViewsSet;
+    return allWebViewsSet;
+}
+
+void WebView::addToAllWebViewsSet()
+{
+    allWebViewsSet().add(this);
+}
+
+void WebView::removeFromAllWebViewsSet()
+{
+    allWebViewsSet().remove(this);
+}
+
+void WebView::setCacheModel(WebCacheModel cacheModel)
+{
+    if (s_didSetCacheModel && cacheModel == s_cacheModel)
+        return;
+
+    RetainPtr<CFStringRef> cfurlCacheDirectory(AdoptCF, wkCopyFoundationCacheDirectory());
+    if (!cfurlCacheDirectory)
+        cfurlCacheDirectory.adoptCF(WebCore::localUserSpecificStorageDirectory().createCFString());
+
+
+    CFURLCacheRef cfurlSharedCache = CFURLCacheSharedURLCache();
+
+    // As a fudge factor, use 1000 instead of 1024, in case the reported byte 
+    // count doesn't align exactly to a megabyte boundary.
+    unsigned long long memSize = WebMemorySize() / 1024 / 1000;
+    unsigned long long diskFreeSize = WebVolumeFreeSize(cfurlCacheDirectory.get()) / 1024 / 1000;
+
+    unsigned cacheTotalCapacity = 0;
+    unsigned cacheMinDeadCapacity = 0;
+    unsigned cacheMaxDeadCapacity = 0;
+
+    unsigned pageCacheCapacity = 0;
+
+    CFIndex cfurlCacheMemoryCapacity = 0;
+    CFIndex cfurlCacheDiskCapacity = 0;
+
+    switch (cacheModel) {
+    case WebCacheModelDocumentViewer: {
+        // Page cache capacity (in pages)
+        pageCacheCapacity = 0;
+
+        // Object cache capacities (in bytes)
+        if (memSize >= 4096)
+            cacheTotalCapacity = 256 * 1024 * 1024;
+        else if (memSize >= 3072)
+            cacheTotalCapacity = 192 * 1024 * 1024;
+        else if (memSize >= 2048)
+            cacheTotalCapacity = 128 * 1024 * 1024;
+        else if (memSize >= 1536)
+            cacheTotalCapacity = 86 * 1024 * 1024;
+        else if (memSize >= 1024)
+            cacheTotalCapacity = 64 * 1024 * 1024;
+        else if (memSize >= 512)
+            cacheTotalCapacity = 32 * 1024 * 1024;
+        else if (memSize >= 256)
+            cacheTotalCapacity = 16 * 1024 * 1024; 
+
+        cacheMinDeadCapacity = 0;
+        cacheMaxDeadCapacity = 0;
+
+        // Foundation memory cache capacity (in bytes)
+        cfurlCacheMemoryCapacity = 0;
+
+        // Foundation disk cache capacity (in bytes)
+        cfurlCacheDiskCapacity = CFURLCacheDiskCapacity(cfurlSharedCache);
+
+        break;
+    }
+    case WebCacheModelDocumentBrowser: {
+        // Page cache capacity (in pages)
+        if (memSize >= 1024)
+            pageCacheCapacity = 3;
+        else if (memSize >= 512)
+            pageCacheCapacity = 2;
+        else if (memSize >= 256)
+            pageCacheCapacity = 1;
+        else
+            pageCacheCapacity = 0;
+
+        // Object cache capacities (in bytes)
+        if (memSize >= 4096)
+            cacheTotalCapacity = 256 * 1024 * 1024;
+        else if (memSize >= 3072)
+            cacheTotalCapacity = 192 * 1024 * 1024;
+        else if (memSize >= 2048)
+            cacheTotalCapacity = 128 * 1024 * 1024;
+        else if (memSize >= 1536)
+            cacheTotalCapacity = 86 * 1024 * 1024;
+        else if (memSize >= 1024)
+            cacheTotalCapacity = 64 * 1024 * 1024;
+        else if (memSize >= 512)
+            cacheTotalCapacity = 32 * 1024 * 1024;
+        else if (memSize >= 256)
+            cacheTotalCapacity = 16 * 1024 * 1024; 
+
+        cacheMinDeadCapacity = cacheTotalCapacity / 8;
+        cacheMaxDeadCapacity = cacheTotalCapacity / 4;
+
+        // Foundation memory cache capacity (in bytes)
+        if (memSize >= 2048)
+            cfurlCacheMemoryCapacity = 4 * 1024 * 1024;
+        else if (memSize >= 1024)
+            cfurlCacheMemoryCapacity = 2 * 1024 * 1024;
+        else if (memSize >= 512)
+            cfurlCacheMemoryCapacity = 1 * 1024 * 1024;
+        else
+            cfurlCacheMemoryCapacity =      512 * 1024; 
+
+        // Foundation disk cache capacity (in bytes)
+        if (diskFreeSize >= 16384)
+            cfurlCacheDiskCapacity = 50 * 1024 * 1024;
+        else if (diskFreeSize >= 8192)
+            cfurlCacheDiskCapacity = 40 * 1024 * 1024;
+        else if (diskFreeSize >= 4096)
+            cfurlCacheDiskCapacity = 30 * 1024 * 1024;
+        else
+            cfurlCacheDiskCapacity = 20 * 1024 * 1024;
+
+        break;
+    }
+    case WebCacheModelPrimaryWebBrowser: {
+        // Page cache capacity (in pages)
+        // (Research indicates that value / page drops substantially after 3 pages.)
+        if (memSize >= 8192)
+            pageCacheCapacity = 7;
+        if (memSize >= 4096)
+            pageCacheCapacity = 6;
+        else if (memSize >= 2048)
+            pageCacheCapacity = 5;
+        else if (memSize >= 1024)
+            pageCacheCapacity = 4;
+        else if (memSize >= 512)
+            pageCacheCapacity = 3;
+        else if (memSize >= 256)
+            pageCacheCapacity = 2;
+        else
+            pageCacheCapacity = 1;
+
+        // Object cache capacities (in bytes)
+        // (Testing indicates that value / MB depends heavily on content and
+        // browsing pattern. Even growth above 128MB can have substantial 
+        // value / MB for some content / browsing patterns.)
+        if (memSize >= 4096)
+            cacheTotalCapacity = 512 * 1024 * 1024;
+        else if (memSize >= 3072)
+            cacheTotalCapacity = 384 * 1024 * 1024;
+        else if (memSize >= 2048)
+            cacheTotalCapacity = 256 * 1024 * 1024;
+        else if (memSize >= 1536)
+            cacheTotalCapacity = 172 * 1024 * 1024;
+        else if (memSize >= 1024)
+            cacheTotalCapacity = 128 * 1024 * 1024;
+        else if (memSize >= 512)
+            cacheTotalCapacity = 64 * 1024 * 1024;
+        else if (memSize >= 256)
+            cacheTotalCapacity = 32 * 1024 * 1024; 
+
+        cacheMinDeadCapacity = cacheTotalCapacity / 4;
+        cacheMaxDeadCapacity = cacheTotalCapacity / 2;
+
+        // This code is here to avoid a PLT regression. We can remove it if we
+        // can prove that the overall system gain would justify the regression.
+        cacheMaxDeadCapacity = max(24u, cacheMaxDeadCapacity);
+
+        // Foundation memory cache capacity (in bytes)
+        // (These values are small because WebCore does most caching itself.)
+        if (memSize >= 1024)
+            cfurlCacheMemoryCapacity = 4 * 1024 * 1024;
+        else if (memSize >= 512)
+            cfurlCacheMemoryCapacity = 2 * 1024 * 1024;
+        else if (memSize >= 256)
+            cfurlCacheMemoryCapacity = 1 * 1024 * 1024;
+        else
+            cfurlCacheMemoryCapacity =      512 * 1024; 
+
+        // Foundation disk cache capacity (in bytes)
+        if (diskFreeSize >= 16384)
+            cfurlCacheDiskCapacity = 175 * 1024 * 1024;
+        else if (diskFreeSize >= 8192)
+            cfurlCacheDiskCapacity = 150 * 1024 * 1024;
+        else if (diskFreeSize >= 4096)
+            cfurlCacheDiskCapacity = 125 * 1024 * 1024;
+        else if (diskFreeSize >= 2048)
+            cfurlCacheDiskCapacity = 100 * 1024 * 1024;
+        else if (diskFreeSize >= 1024)
+            cfurlCacheDiskCapacity = 75 * 1024 * 1024;
+        else
+            cfurlCacheDiskCapacity = 50 * 1024 * 1024;
+
+        break;
+    }
+    default:
+        ASSERT_NOT_REACHED();
+    };
+
+    // Don't shrink a big disk cache, since that would cause churn.
+    cfurlCacheDiskCapacity = max(cfurlCacheDiskCapacity, CFURLCacheDiskCapacity(cfurlSharedCache));
+
+    cache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
+    pageCache()->setCapacity(pageCacheCapacity);
+
+    CFURLCacheSetMemoryCapacity(cfurlSharedCache, cfurlCacheMemoryCapacity);
+    CFURLCacheSetDiskCapacity(cfurlSharedCache, cfurlCacheDiskCapacity);
+
+    s_didSetCacheModel = true;
+    s_cacheModel = cacheModel;
+    return;
+}
+
+WebCacheModel WebView::cacheModel()
+{
+    return s_cacheModel;
+}
+
+bool WebView::didSetCacheModel()
+{
+    return s_didSetCacheModel;
+}
+
+WebCacheModel WebView::maxCacheModelInAnyInstance()
+{
+    WebCacheModel cacheModel = WebCacheModelDocumentViewer;
+
+    HashSet<WebView*>::iterator end = allWebViewsSet().end();
+    for (HashSet<WebView*>::iterator it = allWebViewsSet().begin(); it != end; ++it) {
+        COMPtr<IWebPreferences> pref;
+        if (FAILED((*it)->preferences(&pref)))
+            continue;
+        WebCacheModel prefCacheModel = WebCacheModelDocumentViewer;
+        if (FAILED(pref->cacheModel(&prefCacheModel)))
+            continue;
+
+        cacheModel = max(cacheModel, prefCacheModel);
+    }
+
+    return cacheModel;
+}
+
 void WebView::close()
 {
     if (m_didClose)
@@ -193,6 +560,8 @@ void WebView::close()
 
     m_didClose = true;
 
+    removeFromAllWebViewsSet();
+
     Frame* frame = m_page->mainFrame();
     if (frame)
         frame->loader()->detachFromParent();
@@ -214,18 +583,17 @@ void WebView::close()
 
     registerForIconNotification(false);
     IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
-    COMPtr<IWebPreferences> prefs;
-    if (SUCCEEDED(preferences(&prefs)))
-        notifyCenter->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), prefs.get());
-    prefs = 0;  // make sure we release the reference, since WebPreferences::removeReferenceForIdentifier will check for last reference to WebPreferences
-    if (m_preferences) {
-        BSTR identifier = 0;
-        if (SUCCEEDED(m_preferences->identifier(&identifier)))
-            WebPreferences::removeReferenceForIdentifier(identifier);
-        if (identifier)
-            SysFreeString(identifier);
-        m_preferences = 0;
-    }
+    notifyCenter->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
+
+    BSTR identifier = 0;
+    if (SUCCEEDED(m_preferences->identifier(&identifier)))
+        WebPreferences::removeReferenceForIdentifier(identifier);
+    if (identifier)
+        SysFreeString(identifier);
+
+    COMPtr<WebPreferences> preferences = m_preferences;
+    m_preferences = 0;
+    preferences->didRemoveFromWebView();
 
     deleteBackingStore();
 }
@@ -1112,27 +1480,6 @@ bool WebView::inResizer(LPARAM lParam)
     return !!PtInRect(&r, pt);
 }
 
-void WebView::initializeCacheSizesIfNecessary()
-{
-    static bool didInitialize;
-    if (didInitialize)
-        return;
-
-    COMPtr<IWebPreferences> prefs;
-    if (FAILED(preferences(&prefs)))
-        return;
-
-   UINT pageCacheSize;
-   if (SUCCEEDED(prefs->pageCacheSize(&pageCacheSize)))
-        pageCache()->setCapacity(pageCacheSize);
-
-   UINT objectCacheSize;
-   if (SUCCEEDED(prefs->objectCacheSize(&objectCacheSize)))
-        cache()->setCapacities(0, objectCacheSize, objectCacheSize);
-
-    didInitialize = true;
-}
-
 static ATOM registerWebViewWindowClass()
 {
     static bool haveRegisteredWindowClass = false;
@@ -1355,260 +1702,62 @@ static LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, L
                     keyCode = (UINT) lpMsg->wParam;
             }
             if (SUCCEEDED(webView->uiDelegate(&uiDelegate)) && uiDelegate &&
-                SUCCEEDED(uiDelegate->QueryInterface(IID_IWebUIDelegatePrivate, (void**) &uiDelegatePrivate)) && uiDelegatePrivate &&
-                SUCCEEDED(uiDelegatePrivate->webViewGetDlgCode(webView, keyCode, &dlgCode)))
-                return dlgCode;
-            handled = false;
-            break;
-        }
-
-        case WM_IME_STARTCOMPOSITION:
-            handled = webView->onIMEStartComposition();
-            break;
-        case WM_IME_REQUEST:
-            webView->onIMERequest(wParam, lParam, &lResult);
-            break;
-        case WM_IME_COMPOSITION:
-            handled = webView->onIMEComposition(lParam);
-            break;
-        case WM_IME_ENDCOMPOSITION:
-            handled = webView->onIMEEndComposition();
-            break;
-        case WM_IME_CHAR:
-            handled = webView->onIMEChar(wParam, lParam);
-            break;
-        case WM_IME_NOTIFY:
-            handled = webView->onIMENotify(wParam, lParam, &lResult);
-            break;
-        case WM_IME_SELECT:
-            handled = webView->onIMESelect(wParam, lParam);
-            break;
-        case WM_IME_SETCONTEXT:
-            handled = webView->onIMESetContext(wParam, lParam);
-            break;
-        case WM_SETCURSOR:
-            if (lastSetCursor) {
-                SetCursor(lastSetCursor);
-                break;
-            }
-            __fallthrough;
-        default:
-            handled = false;
-            break;
-    }
-
-    if (!handled)
-        lResult = DefWindowProc(hWnd, message, wParam, lParam);
-    
-    return lResult;
-}
-
-HRESULT WebView::updateWebCoreSettingsFromPreferences(IWebPreferences* preferences)
-{
-    HRESULT hr;
-    BSTR str;
-    int size;
-    BOOL enabled;
-    
-    Settings* settings = m_page->settings();
-
-    hr = preferences->cursiveFontFamily(&str);
-    if (FAILED(hr))
-        return hr;
-    settings->setCursiveFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
-
-    hr = preferences->defaultFixedFontSize(&size);
-    if (FAILED(hr))
-        return hr;
-    settings->setDefaultFixedFontSize(size);
-
-    hr = preferences->defaultFontSize(&size);
-    if (FAILED(hr))
-        return hr;
-    settings->setDefaultFontSize(size);
-    
-    hr = preferences->defaultTextEncodingName(&str);
-    if (FAILED(hr))
-        return hr;
-    settings->setDefaultTextEncodingName(String(str, SysStringLen(str)));
-    SysFreeString(str);
-
-    hr = preferences->fantasyFontFamily(&str);
-    if (FAILED(hr))
-        return hr;
-    settings->setFantasyFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
-
-    hr = preferences->fixedFontFamily(&str);
-    if (FAILED(hr))
-        return hr;
-    settings->setFixedFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
-
-    hr = preferences->isJavaEnabled(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setJavaEnabled(!!enabled);
-
-    hr = preferences->isJavaScriptEnabled(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setJavaScriptEnabled(!!enabled);
-
-    hr = preferences->javaScriptCanOpenWindowsAutomatically(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setJavaScriptCanOpenWindowsAutomatically(!!enabled);
-
-    hr = preferences->minimumFontSize(&size);
-    if (FAILED(hr))
-        return hr;
-    settings->setMinimumFontSize(size);
-
-    hr = preferences->minimumLogicalFontSize(&size);
-    if (FAILED(hr))
-        return hr;
-    settings->setMinimumLogicalFontSize(size);
-
-    hr = preferences->arePlugInsEnabled(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setPluginsEnabled(!!enabled);
-
-    hr = preferences->privateBrowsingEnabled(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setPrivateBrowsingEnabled(!!enabled);
-
-    hr = preferences->sansSerifFontFamily(&str);
-    if (FAILED(hr))
-        return hr;
-    settings->setSansSerifFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
-
-    hr = preferences->serifFontFamily(&str);
-    if (FAILED(hr))
-        return hr;
-    settings->setSerifFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
-
-    hr = preferences->standardFontFamily(&str);
-    if (FAILED(hr))
-        return hr;
-    settings->setStandardFontFamily(AtomicString(str, SysStringLen(str)));
-    SysFreeString(str);
-
-    hr = preferences->loadsImagesAutomatically(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setLoadsImagesAutomatically(!!enabled);
-
-    hr = preferences->userStyleSheetEnabled(&enabled);
-    if (FAILED(hr))
-        return hr;
-    if (enabled) {
-        hr = preferences->userStyleSheetLocation(&str);
-        if (FAILED(hr))
-            return hr;
-
-        RetainPtr<CFStringRef> urlString(AdoptCF, String(str, SysStringLen(str)).createCFString());
-        RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithString(kCFAllocatorDefault, urlString.get(), 0));
-
-        // Check if the passed in string is a path and convert it to a URL.
-        // FIXME: This is a workaround for nightly builds until we can get Safari to pass 
-        // in an URL here. See <rdar://problem/5478378>
-        if (!url) {
-            DWORD len = SysStringLen(str) + 1;
-
-            int result = WideCharToMultiByte(CP_UTF8, 0, str, len, 0, 0, 0, 0);
-            Vector<UInt8> utf8Path(result);
-            if (!WideCharToMultiByte(CP_UTF8, 0, str, len, (LPSTR)utf8Path.data(), result, 0, 0))
-                return E_FAIL;
-
-            url.adoptCF(CFURLCreateFromFileSystemRepresentation(0, utf8Path.data(), result - 1, false));
-        }
-
-        settings->setUserStyleSheetLocation(url.get());
-        SysFreeString(str);
-    } else {
-        settings->setUserStyleSheetLocation(KURL(DeprecatedString("")));
-    }
-
-    hr = preferences->shouldPrintBackgrounds(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setShouldPrintBackgrounds(!!enabled);
-
-    hr = preferences->textAreasAreResizable(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setTextAreasAreResizable(!!enabled);
-
-    WebKitEditableLinkBehavior behavior;
-    hr = preferences->editableLinkBehavior(&behavior);
-    if (FAILED(hr))
-        return hr;
-    settings->setEditableLinkBehavior((EditableLinkBehavior)behavior);
-
-    hr = preferences->usesPageCache(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setUsesPageCache(!!enabled);
-
-    hr = preferences->isDOMPasteAllowed(&enabled);
-    if (FAILED(hr))
-        return hr;
-    settings->setDOMPasteAllowed(!!enabled);
-
-    settings->setShowsURLsInToolTips(false);
-
-    settings->setForceFTPDirectoryListings(true);
-
-    settings->setDeveloperExtrasEnabled(developerExtrasEnabled());
-
-    m_mainFrame->invalidate(); // FIXME
-
-    return S_OK;
-}
-
-HRESULT WebView::updateGlobalSettingsFromPreferences(IWebPreferences* preferences)
-{
-    WebKitCookieStorageAcceptPolicy acceptPolicy;
-    HRESULT hr = preferences->cookieStorageAcceptPolicy(&acceptPolicy);
-    if (FAILED(hr))
-        return hr;
-
-    // set cookie storage accept policy
-    if (CFHTTPCookieStorageRef defaultCookieStorage = wkGetDefaultHTTPCookieStorage())
-        CFHTTPCookieStorageSetCookieAcceptPolicy(defaultCookieStorage, acceptPolicy);
-
-    return S_OK;
-}
-
-HRESULT WebView::updateSettingsFromPreferences(IWebPreferences* preferences)
-{
-    HRESULT hr = updateWebCoreSettingsFromPreferences(preferences);
-    if (FAILED(hr))
-        return hr;
+                SUCCEEDED(uiDelegate->QueryInterface(IID_IWebUIDelegatePrivate, (void**) &uiDelegatePrivate)) && uiDelegatePrivate &&
+                SUCCEEDED(uiDelegatePrivate->webViewGetDlgCode(webView, keyCode, &dlgCode)))
+                return dlgCode;
+            handled = false;
+            break;
+        }
 
-    COMPtr<WebPreferences> webPreferences(Query, preferences);
-    if (webPreferences && webPreferences == WebPreferences::sharedStandardPreferences())
-        hr = updateGlobalSettingsFromPreferences(preferences);
+        case WM_IME_STARTCOMPOSITION:
+            handled = webView->onIMEStartComposition();
+            break;
+        case WM_IME_REQUEST:
+            webView->onIMERequest(wParam, lParam, &lResult);
+            break;
+        case WM_IME_COMPOSITION:
+            handled = webView->onIMEComposition(lParam);
+            break;
+        case WM_IME_ENDCOMPOSITION:
+            handled = webView->onIMEEndComposition();
+            break;
+        case WM_IME_CHAR:
+            handled = webView->onIMEChar(wParam, lParam);
+            break;
+        case WM_IME_NOTIFY:
+            handled = webView->onIMENotify(wParam, lParam, &lResult);
+            break;
+        case WM_IME_SELECT:
+            handled = webView->onIMESelect(wParam, lParam);
+            break;
+        case WM_IME_SETCONTEXT:
+            handled = webView->onIMESetContext(wParam, lParam);
+            break;
+        case WM_SETCURSOR:
+            if (lastSetCursor) {
+                SetCursor(lastSetCursor);
+                break;
+            }
+            __fallthrough;
+        default:
+            handled = false;
+            break;
+    }
 
-    return hr;
+    if (!handled)
+        lResult = DefWindowProc(hWnd, message, wParam, lParam);
+    
+    return lResult;
 }
 
 bool WebView::developerExtrasEnabled() const
 {
-    COMPtr<WebPreferences> webPrefs(Query, m_preferences);
-    if (webPrefs && webPrefs->developerExtrasDisabledByOverride())
+    if (m_preferences->developerExtrasDisabledByOverride())
         return false;
 
 #ifdef NDEBUG
-    BOOL enabled = FALSE;
-    COMPtr<IWebPreferencesPrivate> prefsPrivate;
-    return SUCCEEDED(m_preferences->QueryInterface(&prefsPrivate)) && SUCCEEDED(prefsPrivate->developerExtrasEnabled(&enabled)) && enabled;
+    BOOL enabled;
+    return SUCCEEDED(m_preferences->developerExtrasEnabled(&enabled)) && enabled;
 #else
     return true;
 #endif
@@ -1818,6 +1967,10 @@ HRESULT STDMETHODCALLTYPE WebView::initWithFrame(
     if (FAILED(hr))
         return hr;
 
+    WebPreferences* sharedPreferences = WebPreferences::sharedStandardPreferences();
+    sharedPreferences->willAddToWebView();
+    m_preferences = sharedPreferences;
+
     m_groupName = String(groupName, SysStringLen(groupName));
 
     WebKitSetWebDatabasesPathIfNecessary();
@@ -1852,31 +2005,17 @@ HRESULT STDMETHODCALLTYPE WebView::initWithFrame(
     m_page->mainFrame()->init();
     m_page->setGroupName(m_groupName);
 
+    addToAllWebViewsSet();
+
     #pragma warning(suppress: 4244)
     SetWindowLongPtr(m_viewWindow, 0, (LONG_PTR)this);
     ShowWindow(m_viewWindow, SW_SHOW);
 
-    initializeCacheSizesIfNecessary();
     initializeToolTipWindow();
 
-    // Update WebCore with preferences.  These values will either come from an archived WebPreferences,
-    // or from the standard preferences, depending on whether this method was called from initWithCoder:
-    // or initWithFrame, respectively.
-    //[self _updateWebCoreSettingsFromPreferences: [self preferences]];
-    COMPtr<IWebPreferences> prefs;
-    if (FAILED(preferences(&prefs)))
-        return hr;
-    hr = updateSettingsFromPreferences(prefs.get());
-    if (FAILED(hr))
-        return hr;
-
-    // Register to receive notifications whenever preference values change.
-    //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:)
-    //                                             name:WebPreferencesChangedNotification object:[self preferences]];
     IWebNotificationCenter* notifyCenter = WebNotificationCenter::defaultCenterInternal();
-    if (!WebPreferences::webPreferencesChangedNotification())
-        return E_OUTOFMEMORY;
-    notifyCenter->addObserver(this, WebPreferences::webPreferencesChangedNotification(), prefs.get());
+    notifyCenter->addObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
+    m_preferences->postPreferencesChangesNotification();
 
     setSmartInsertDeleteEnabled(TRUE);
     return hr;
@@ -2343,28 +2482,37 @@ HRESULT STDMETHODCALLTYPE WebView::windowScriptObject(
 HRESULT STDMETHODCALLTYPE WebView::setPreferences( 
     /* [in] */ IWebPreferences* prefs)
 {
+    if (!prefs)
+        prefs = WebPreferences::sharedStandardPreferences();
+
     if (m_preferences == prefs)
         return S_OK;
 
+    COMPtr<WebPreferences> webPrefs(Query, prefs);
+    if (!webPrefs)
+        return E_NOINTERFACE;
+    webPrefs->willAddToWebView();
+
+    COMPtr<WebPreferences> oldPrefs = m_preferences;
+
     IWebNotificationCenter* nc = WebNotificationCenter::defaultCenterInternal();
-    COMPtr<IWebPreferences> oldPrefs;
-    if (SUCCEEDED(preferences(&oldPrefs)) && oldPrefs) {
-        nc->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), oldPrefs.get());
-        BSTR identifier = 0;
-        HRESULT hr = oldPrefs->identifier(&identifier);
-        oldPrefs = 0;   // make sure we release the reference, since WebPreferences::removeReferenceForIdentifier will check for last reference to WebPreferences
-        if (SUCCEEDED(hr))
-            WebPreferences::removeReferenceForIdentifier(identifier);
-        if (identifier)
-            SysFreeString(identifier);
+    nc->removeObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
+
+    BSTR identifierBSTR = 0;
+    HRESULT hr = oldPrefs->identifier(&identifierBSTR);
+    oldPrefs->didRemoveFromWebView();
+    oldPrefs = 0; // Make sure we release the reference, since WebPreferences::removeReferenceForIdentifier will check for last reference to WebPreferences
+    if (SUCCEEDED(hr)) {
+        BString identifier;
+        identifier.adoptBSTR(identifierBSTR);
+        WebPreferences::removeReferenceForIdentifier(identifier);
     }
-    m_preferences = prefs;
-    COMPtr<IWebPreferences> newPrefs;
-    if (SUCCEEDED(preferences(&newPrefs)))
-        nc->addObserver(this, WebPreferences::webPreferencesChangedNotification(), newPrefs.get());
-    HRESULT hr = nc->postNotificationName(WebPreferences::webPreferencesChangedNotification(), newPrefs.get(), 0);
-    if (FAILED(hr))
-        return hr;
+
+    m_preferences = webPrefs;
+
+    nc->addObserver(this, WebPreferences::webPreferencesChangedNotification(), static_cast<IWebPreferences*>(m_preferences.get()));
+
+    m_preferences->postPreferencesChangesNotification();
 
     return S_OK;
 }
@@ -2372,13 +2520,12 @@ HRESULT STDMETHODCALLTYPE WebView::setPreferences(
 HRESULT STDMETHODCALLTYPE WebView::preferences( 
     /* [retval][out] */ IWebPreferences** prefs)
 {
-    HRESULT hr = S_OK;
-
-    if (!m_preferences)
-        m_preferences = WebPreferences::sharedStandardPreferences();
-
-    m_preferences.copyRefTo(prefs);
-    return hr;
+    if (!prefs)
+        return E_POINTER;
+    *prefs = m_preferences.get();
+    if (m_preferences)
+        m_preferences->AddRef();
+    return S_OK;
 }
 
 HRESULT STDMETHODCALLTYPE WebView::setPreferencesIdentifier( 
@@ -3459,22 +3606,213 @@ HRESULT STDMETHODCALLTYPE WebView::onNotify(
     BString name;
     name.adoptBSTR(nameBSTR);
 
-    if (!_tcscmp(name, WebIconDatabase::iconDatabaseDidAddIconNotification()))
+    if (!wcscmp(name, WebIconDatabase::iconDatabaseDidAddIconNotification()))
         return notifyDidAddIcon(notification);
 
+    if (!wcscmp(name, WebPreferences::webPreferencesChangedNotification()))
+        return notifyPreferencesChanged(notification);
+
+    return hr;
+}
+
+HRESULT WebView::notifyPreferencesChanged(IWebNotification* notification)
+{
+    HRESULT hr;
+
     COMPtr<IUnknown> unkPrefs;
     hr = notification->getObject(&unkPrefs);
     if (FAILED(hr))
         return hr;
 
-    COMPtr<IWebPreferences> preferences;
-    hr = unkPrefs->QueryInterface(IID_IWebPreferences, (void**)&preferences);
+    COMPtr<IWebPreferences> preferences(Query, unkPrefs);
+    if (!preferences)
+        return E_NOINTERFACE;
+
+    ASSERT(preferences != m_preferences);
+
+    BSTR str;
+    int size;
+    BOOL enabled;
+
+    Settings* settings = m_page->settings();
+
+    hr = preferences->cursiveFontFamily(&str);
     if (FAILED(hr))
         return hr;
+    settings->setCursiveFontFamily(AtomicString(str, SysStringLen(str)));
+    SysFreeString(str);
 
-    hr = updateSettingsFromPreferences(preferences.get());
+    hr = preferences->defaultFixedFontSize(&size);
+    if (FAILED(hr))
+        return hr;
+    settings->setDefaultFixedFontSize(size);
 
-    return hr;
+    hr = preferences->defaultFontSize(&size);
+    if (FAILED(hr))
+        return hr;
+    settings->setDefaultFontSize(size);
+    
+    hr = preferences->defaultTextEncodingName(&str);
+    if (FAILED(hr))
+        return hr;
+    settings->setDefaultTextEncodingName(String(str, SysStringLen(str)));
+    SysFreeString(str);
+
+    hr = preferences->fantasyFontFamily(&str);
+    if (FAILED(hr))
+        return hr;
+    settings->setFantasyFontFamily(AtomicString(str, SysStringLen(str)));
+    SysFreeString(str);
+
+    hr = preferences->fixedFontFamily(&str);
+    if (FAILED(hr))
+        return hr;
+    settings->setFixedFontFamily(AtomicString(str, SysStringLen(str)));
+    SysFreeString(str);
+
+    hr = preferences->isJavaEnabled(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setJavaEnabled(!!enabled);
+
+    hr = preferences->isJavaScriptEnabled(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setJavaScriptEnabled(!!enabled);
+
+    hr = preferences->javaScriptCanOpenWindowsAutomatically(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setJavaScriptCanOpenWindowsAutomatically(!!enabled);
+
+    hr = preferences->minimumFontSize(&size);
+    if (FAILED(hr))
+        return hr;
+    settings->setMinimumFontSize(size);
+
+    hr = preferences->minimumLogicalFontSize(&size);
+    if (FAILED(hr))
+        return hr;
+    settings->setMinimumLogicalFontSize(size);
+
+    hr = preferences->arePlugInsEnabled(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setPluginsEnabled(!!enabled);
+
+    hr = preferences->privateBrowsingEnabled(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setPrivateBrowsingEnabled(!!enabled);
+
+    hr = preferences->sansSerifFontFamily(&str);
+    if (FAILED(hr))
+        return hr;
+    settings->setSansSerifFontFamily(AtomicString(str, SysStringLen(str)));
+    SysFreeString(str);
+
+    hr = preferences->serifFontFamily(&str);
+    if (FAILED(hr))
+        return hr;
+    settings->setSerifFontFamily(AtomicString(str, SysStringLen(str)));
+    SysFreeString(str);
+
+    hr = preferences->standardFontFamily(&str);
+    if (FAILED(hr))
+        return hr;
+    settings->setStandardFontFamily(AtomicString(str, SysStringLen(str)));
+    SysFreeString(str);
+
+    hr = preferences->loadsImagesAutomatically(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setLoadsImagesAutomatically(!!enabled);
+
+    hr = preferences->userStyleSheetEnabled(&enabled);
+    if (FAILED(hr))
+        return hr;
+    if (enabled) {
+        hr = preferences->userStyleSheetLocation(&str);
+        if (FAILED(hr))
+            return hr;
+
+        RetainPtr<CFStringRef> urlString(AdoptCF, String(str, SysStringLen(str)).createCFString());
+        RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithString(kCFAllocatorDefault, urlString.get(), 0));
+
+        // Check if the passed in string is a path and convert it to a URL.
+        // FIXME: This is a workaround for nightly builds until we can get Safari to pass 
+        // in an URL here. See <rdar://problem/5478378>
+        if (!url) {
+            DWORD len = SysStringLen(str) + 1;
+
+            int result = WideCharToMultiByte(CP_UTF8, 0, str, len, 0, 0, 0, 0);
+            Vector<UInt8> utf8Path(result);
+            if (!WideCharToMultiByte(CP_UTF8, 0, str, len, (LPSTR)utf8Path.data(), result, 0, 0))
+                return E_FAIL;
+
+            url.adoptCF(CFURLCreateFromFileSystemRepresentation(0, utf8Path.data(), result - 1, false));
+        }
+
+        settings->setUserStyleSheetLocation(url.get());
+        SysFreeString(str);
+    } else {
+        settings->setUserStyleSheetLocation(KURL(DeprecatedString("")));
+    }
+
+    hr = preferences->shouldPrintBackgrounds(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setShouldPrintBackgrounds(!!enabled);
+
+    hr = preferences->textAreasAreResizable(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setTextAreasAreResizable(!!enabled);
+
+    WebKitEditableLinkBehavior behavior;
+    hr = preferences->editableLinkBehavior(&behavior);
+    if (FAILED(hr))
+        return hr;
+    settings->setEditableLinkBehavior((EditableLinkBehavior)behavior);
+
+    hr = preferences->usesPageCache(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setUsesPageCache(!!enabled);
+
+    hr = preferences->isDOMPasteAllowed(&enabled);
+    if (FAILED(hr))
+        return hr;
+    settings->setDOMPasteAllowed(!!enabled);
+
+    settings->setShowsURLsInToolTips(false);
+    settings->setForceFTPDirectoryListings(true);
+    settings->setDeveloperExtrasEnabled(developerExtrasEnabled());
+
+    m_mainFrame->invalidate(); // FIXME
+
+    hr = updateSharedSettingsFromPreferencesIfNeeded(preferences.get());
+    if (FAILED(hr))
+        return hr;
+
+    return S_OK;
+}
+
+HRESULT updateSharedSettingsFromPreferencesIfNeeded(IWebPreferences* preferences)
+{
+    if (preferences != WebPreferences::sharedStandardPreferences())
+        return S_OK;
+
+    WebKitCookieStorageAcceptPolicy acceptPolicy;
+    HRESULT hr = preferences->cookieStorageAcceptPolicy(&acceptPolicy);
+    if (FAILED(hr))
+        return hr;
+
+    // Set cookie storage accept policy
+    if (CFHTTPCookieStorageRef defaultCookieStorage = wkGetDefaultHTTPCookieStorage())
+        CFHTTPCookieStorageSetCookieAcceptPolicy(defaultCookieStorage, acceptPolicy);
+
+    return S_OK;
 }
 
 // IWebViewPrivate ------------------------------------------------------------
index beaf89aa5034a0ad4f05724611d4410e67cb7852..ac4a4b0cf968b00f6839e9f9c7a7c70f93d7401f 100644 (file)
@@ -32,6 +32,7 @@
 #include "IWebView.h"
 #include "IWebViewPrivate.h"
 #include "WebFrame.h"
+#include "WebPreferences.h"
 
 #include <WebCore/IntRect.h>
 #include <WebCore/Timer.h>
@@ -627,9 +628,6 @@ public:
     bool execCommand(WPARAM wParam, LPARAM lParam);
     bool keyDown(WPARAM, LPARAM, bool systemKeyDown = false);
     bool keyUp(WPARAM, LPARAM);
-    HRESULT updateWebCoreSettingsFromPreferences(IWebPreferences* preferences);
-    static HRESULT updateGlobalSettingsFromPreferences(IWebPreferences*);
-    HRESULT updateSettingsFromPreferences(IWebPreferences*);
     bool inResizer(LPARAM lParam);
     void paint(HDC, LPARAM);
     void paintIntoBackingStore(WebCore::FrameView*, HDC bitmapDC, LPRECT dirtyRect);
@@ -680,16 +678,22 @@ public:
     void setToolTip(const WebCore::String&);
 
     void registerForIconNotification(bool listen);
-    HRESULT notifyDidAddIcon(IWebNotification*);
     void dispatchDidReceiveIconFromWebFrame(WebFrame*);
 
+    HRESULT notifyDidAddIcon(IWebNotification*);
+    HRESULT notifyPreferencesChanged(IWebNotification*);
+
+    static void setCacheModel(WebCacheModel);
+    static WebCacheModel cacheModel();
+    static bool didSetCacheModel();
+    static WebCacheModel maxCacheModelInAnyInstance();
+
 protected:
     HIMC getIMMContext();
     void releaseIMMContext(HIMC);
     static bool allowSiteSpecificHacks() { return s_allowSiteSpecificHacks; } 
     void preflightSpellChecker();
     bool continuousCheckingAllowed();
-    void initializeCacheSizesIfNecessary();
     void initializeToolTipWindow();
     void closeWindowTimerFired(WebCore::Timer<WebView>*);
     void prepareCandidateWindow(WebCore::Frame*, HIMC);
@@ -698,6 +702,10 @@ protected:
     bool onIMERequestReconvertString(WebCore::Frame*, RECONVERTSTRING*, LRESULT*);
     bool developerExtrasEnabled() const;
 
+    // AllWebViewSet functions
+    void addToAllWebViewsSet();
+    void removeFromAllWebViewsSet();
+
     ULONG m_refCount;
     WebCore::String m_groupName;
     HWND m_hostWindow;
@@ -716,9 +724,9 @@ protected:
     COMPtr<IWebUIDelegatePrivate> m_uiDelegatePrivate;
     COMPtr<IWebFormDelegate> m_formDelegate;
     COMPtr<IWebPolicyDelegate> m_policyDelegate;
-    COMPtr<IWebPreferences> m_preferences;
     COMPtr<IWebResourceLoadDelegate> m_resourceLoadDelegate;
     COMPtr<IWebDownloadDelegate> m_downloadDelegate;
+    COMPtr<WebPreferences> m_preferences;
     bool m_userAgentOverridden;
     bool m_useBackForwardList;
     WebCore::String m_userAgentCustom;