Changeset 25430 in webkit


Ignore:
Timestamp:
Sep 7, 2007 5:40:53 PM (17 years ago)
Author:
ggaren
Message:

gtk:

Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.


Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
memory cache, or a very tiny one


Keep the GTK build working with an empty stub.


  • WebCoreSupport/FrameLoaderClientGtk.cpp: (WebKit::FrameLoaderClient::didPerformFirstNavigation):
  • WebCoreSupport/FrameLoaderClientGtk.h:

WebCore:

Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.


Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
memory cache, or a very tiny one

Added a client callback to notify WebKit when the first navigation has
taken place. "Navigation" here means a transition from one page to
another that ends up in the back/forward list.


WebKit Mac uses this notification to grow its cache model under certain
circumstances.


  • loader/FrameLoader.cpp: (WebCore::FrameLoader::addBackForwardItemClippedAtTarget):
  • loader/FrameLoaderClient.h:
  • platform/graphics/svg/SVGImageEmptyClients.h: (WebCore::SVGEmptyFrameLoaderClient::didPerformFirstNavigation): Ah, SVGEmptyFrameLoaderClient, my old friend.

WebKit:

Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.


Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
memory cache, or a very tiny one


High level explanation:

  • Added SPI for specifying a cache model on a per-WebView basis. (Hopefully, this will become API soon.) We balance competing cache models simply by using the largest one that pertains at a given time.
  • Added heuristic for guessing a default cache model in WebViews that don't specify one:

1) Default to DocumentViewer for apps linked on or after this
WebKit. Default to DocumentBrowser otherwise.

2) Assign specific defaults to well-known clients based on
bundle ID.

3) Grow the default to DocumentBrowser if a navigation takes
place.

  • As a part of the DocumentBrowser & PrimaryWebBrowser settings:

1) Make the Foundation disk cache much much bigger than the
default 20MB, if space allows. (This is a hedge against a small
WebCore cache in DocumentBrowser mode, but also an all-around
win for page load speed.)

2) Scaled the Foundation memory cache's capacity with physical
RAM, just like we do with other caches. This is a small win on
low memory systems.

  • Misc/WebKitSystemBits.h:
  • Misc/WebKitSystemBits.m: (WebMemorySize): Renamed from "WebSystemMainMemory." (WebHomeDirectoryFreeSize): Added function to measure the free space on the user's home directory. We use this as a factor in determining the disk cache's cacpacity.
  • Misc/WebKitVersionChecks.h: Support for linked on or after check.


  • WebCoreSupport/WebFrameLoaderClient.h:
  • WebCoreSupport/WebFrameLoaderClient.mm: (WebFrameLoaderClient::didPerformFirstNavigation): Implementation of heuristic rule #3.
  • WebView/WebPreferenceKeysPrivate.h:
  • WebView/WebPreferences.m: (cacheModelForMainBundle): Implementation of heuristic rule #2. (-[NSMutableDictionary _web_checkLastReferenceForIdentifier:]): Added notification for when a WebPreferences instance becomes inert. We use this to shrink the cache model back down if possible. Moved this code into a WebPreferences method, since it's not really a feature of NSDictionary.
  • WebView/WebPreferencesPrivate.h: SPI declarations.


  • WebView/WebView.mm: Replaced manual notification posts with calls to the _postPreferencesChangesNotification convenience method.

(-[WebView _preferencesChangedNotification:]): Merged dispersed code
for updating preferences-related settings into this one function. This
was needed for an earlier version of the patch, even though the
current version could probably do without it.

(+[WebView _preferencesChangedNotification:]): Added a class-level
listener for WebPreferences changes. This listener takes care of
modifying the class-level global cache model setting if necessary.

(+[WebPreferences standardPreferences]): Removed call to
_postPreferencesChangesNotification because the notification already
posts when you create the WebPreferences object. (I noticed this
inefficiency because my new _preferencesChangedNotification: method was
called excessively at startup.)

Also Added explicit tracking of WebPreferences clients, so we know when
a WebPreferences instance becomes inert:


(-[WebPreferences didRemoveFromWebView]):
(-[WebPreferences willAddToWebView]):

(+[WebView _setCacheModel:]): Translates a cache model into actual
settings in various APIs. Caches that have unbounded value grow
linearly relative to available space. Caches that have bounded value
grow inverse-squaredly relative to available space.

WebKitQt:

Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.


Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
memory cache, or a very tiny one


Keep the Qt build working with an empty stub.


  • WebCoreSupport/FrameLoaderClientQt.cpp: (WebCore::FrameLoaderClient::didPerformFirstNavigation):
  • WebCoreSupport/FrameLoaderClientQt.h:

win:

Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.


Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
memory cache, or a very tiny one


Keep the Windows build working with an empty stub.


  • WebFrame.cpp: (FrameLoaderClient::didPerformFirstNavigation):
  • WebFrame.h:
Location:
trunk
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r25429 r25430  
     12007-09-05  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.
     4       
     5        Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
     6        memory cache, or a very tiny one
     7
     8        Added a client callback to notify WebKit when the first navigation has
     9        taken place. "Navigation" here means a transition from one page to
     10        another that ends up in the back/forward list.
     11       
     12        WebKit Mac uses this notification to grow its cache model under certain
     13        circumstances.
     14       
     15        * loader/FrameLoader.cpp:
     16        (WebCore::FrameLoader::addBackForwardItemClippedAtTarget):
     17        * loader/FrameLoaderClient.h:
     18
     19        * platform/graphics/svg/SVGImageEmptyClients.h:
     20        (WebCore::SVGEmptyFrameLoaderClient::didPerformFirstNavigation): Ah,
     21        SVGEmptyFrameLoaderClient, my old friend.
     22
    1232007-09-07  Adele Peterson  <adele@apple.com>
    224
  • trunk/WebCore/loader/FrameLoader.cpp

    r25410 r25430  
    239239    , m_creatingInitialEmptyDocument(false)
    240240    , m_committedFirstRealDocumentLoad(false)
     241    , m_didPerformFirstNavigation(false)
    241242#if USE(LOW_BANDWIDTH_DISPLAY)
    242243    , m_useLowBandwidthDisplay(true)
     
    37583759            Frame* mainFrame = page->mainFrame();
    37593760            ASSERT(mainFrame);
    3760             RefPtr<HistoryItem> item = mainFrame->loader()->createHistoryItemTree(m_frame, doClip);
     3761            FrameLoader* frameLoader = mainFrame->loader();
     3762
     3763            if (!frameLoader->m_didPerformFirstNavigation && page->backForwardList()->entries().size() == 1) {
     3764                frameLoader->m_didPerformFirstNavigation = true;
     3765                m_client->didPerformFirstNavigation();
     3766            }
     3767
     3768            RefPtr<HistoryItem> item = frameLoader->createHistoryItemTree(m_frame, doClip);
    37613769            LOG(BackForward, "WebCoreBackForward - Adding backforward item %p for frame %s", item.get(), documentLoader()->URL().url().ascii());
    37623770            page->backForwardList()->addItem(item);
  • trunk/WebCore/loader/FrameLoader.h

    r25410 r25430  
    643643        RefPtr<HistoryItem> m_previousHistoryItem;
    644644        RefPtr<HistoryItem> m_provisionalHistoryItem;
     645       
     646        bool m_didPerformFirstNavigation;
    645647
    646648#if USE(LOW_BANDWIDTH_DISPLAY)
  • trunk/WebCore/loader/FrameLoaderClient.h

    r25128 r25430  
    208208
    209209        virtual void windowObjectCleared() const = 0;
     210        virtual void didPerformFirstNavigation() const = 0; // "Navigation" here means a transition from one page to another that ends up in the back/forward list.
    210211       
    211212#if PLATFORM(MAC)
  • trunk/WebCore/platform/graphics/svg/SVGImageEmptyClients.h

    r25345 r25430  
    273273    virtual void redirectDataToPlugin(WebCore::Widget*) {}
    274274    virtual void windowObjectCleared() const {}
     275    virtual void didPerformFirstNavigation() const {}
    275276
    276277#if PLATFORM(MAC)
  • trunk/WebKit/ChangeLog

    r25396 r25430  
     12007-09-05  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.
     4       
     5        Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
     6        memory cache, or a very tiny one
     7       
     8        High level explanation:
     9            - Added SPI for specifying a cache model on a per-WebView basis.
     10            (Hopefully, this will become API soon.) We balance competing
     11            cache models simply by using the largest one that pertains at a
     12            given time.
     13
     14            - Added heuristic for guessing a default cache model in WebViews
     15            that don't specify one:
     16                1) Default to DocumentViewer for apps linked on or after this
     17                WebKit. Default to DocumentBrowser otherwise.
     18
     19                2) Assign specific defaults to well-known clients based on
     20                bundle ID.
     21
     22                3) Grow the default to DocumentBrowser if a navigation takes
     23                place.
     24
     25            - As a part of the DocumentBrowser & PrimaryWebBrowser settings:
     26                1) Make the Foundation disk cache much much bigger than the
     27                default 20MB, if space allows. (This is a hedge against a small
     28                WebCore cache in DocumentBrowser mode, but also an all-around
     29                win for page load speed.)
     30
     31                2) Scaled the Foundation memory cache's capacity with physical
     32                RAM, just like we do with other caches. This is a small win on
     33                low memory systems.
     34
     35        * Misc/WebKitSystemBits.h:
     36        * Misc/WebKitSystemBits.m:
     37        (WebMemorySize): Renamed from "WebSystemMainMemory."
     38        (WebHomeDirectoryFreeSize): Added function to measure the free space
     39        on the user's home directory. We use this as a factor in determining
     40        the disk cache's cacpacity.
     41
     42        * Misc/WebKitVersionChecks.h: Support for linked on or after check.
     43       
     44        * WebCoreSupport/WebFrameLoaderClient.h:
     45        * WebCoreSupport/WebFrameLoaderClient.mm:
     46        (WebFrameLoaderClient::didPerformFirstNavigation): Implementation of
     47        heuristic rule #3.
     48
     49        * WebView/WebPreferenceKeysPrivate.h:
     50        * WebView/WebPreferences.m:
     51        (cacheModelForMainBundle): Implementation of heuristic rule #2.
     52        (-[NSMutableDictionary _web_checkLastReferenceForIdentifier:]): Added
     53        notification for when a WebPreferences instance becomes inert. We use
     54        this to shrink the cache model back down if possible. Moved this code
     55        into a WebPreferences method, since it's not really a feature of
     56        NSDictionary.
     57
     58        * WebView/WebPreferencesPrivate.h: SPI declarations.
     59       
     60        * WebView/WebView.mm: Replaced manual notification posts with calls to
     61        the _postPreferencesChangesNotification convenience method.
     62
     63        (-[WebView _preferencesChangedNotification:]): Merged dispersed code
     64        for updating preferences-related settings into this one function. This
     65        was needed for an earlier version of the patch, even though the
     66        current version could probably do without it.
     67
     68        (+[WebView _preferencesChangedNotification:]): Added a class-level
     69        listener for WebPreferences changes. This listener takes care of
     70        modifying the class-level global cache model setting if necessary.
     71
     72        (+[WebPreferences standardPreferences]): Removed call to
     73        _postPreferencesChangesNotification because the notification already
     74        posts when you create the WebPreferences object. (I noticed this
     75        inefficiency because my new _preferencesChangedNotification: method was
     76        called excessively at startup.)
     77
     78        Also Added explicit tracking of WebPreferences clients, so we know when
     79        a WebPreferences instance becomes inert:
     80       
     81        (-[WebPreferences didRemoveFromWebView]):
     82        (-[WebPreferences willAddToWebView]):
     83
     84        (+[WebView _setCacheModel:]): Translates a cache model into actual
     85        settings in various APIs. Caches that have unbounded value grow
     86        linearly relative to available space. Caches that have bounded value
     87        grow inverse-squaredly relative to available space.
     88
    1892007-09-05  Timothy Hatcher  <timothy@apple.com>
    290
  • trunk/WebKit/Misc/WebKitSystemBits.h

    r17000 r25430  
    3333#endif
    3434
    35 vm_size_t WebSystemMainMemory(void);
     35vm_size_t WebMemorySize(void);
     36unsigned long long WebVolumeFreeSize(NSString *path);
    3637int WebNumberOfCPUs(void);
    3738
  • trunk/WebKit/Misc/WebKitSystemBits.m

    r14021 r25430  
    5757}
    5858
    59 vm_size_t WebSystemMainMemory(void)
     59vm_size_t WebMemorySize(void)
    6060{
    6161    pthread_once(&initControl, initCapabilities);
     
    7878    return numCPUs;
    7979}
     80
     81unsigned long long WebVolumeFreeSize(NSString *path)
     82{
     83    NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] fileSystemAttributesAtPath:path];
     84    return [[fileSystemAttributesDictionary objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
     85}
  • trunk/WebKit/Misc/WebKitVersionChecks.h

    r24381 r25430  
    3232   A version of -1 is returned if the main executable did not link against WebKit (should never happen). */
    3333
     34/* Please use the current WebKit version number, available in WebKit/Configurations/Version.xcconfig,
     35   when adding a new version constant. */
     36
    3437#define WEBKIT_FIRST_VERSION_WITH_3_0_CONTEXT_MENU_TAGS 0x020A0000 // 522.0.0
    3538#define WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION 0x020A0000 // 522.0.0
     
    4043#define WEBKIT_FIRST_VERSION_WITHOUT_ADOBE_INSTALLER_QUIRK 0x020A0000 // 522.0.0
    4144#define WEBKIT_FIRST_VERSION_WITH_INSPECT_ELEMENT_MENU_TAG 0x020A0C00 // 522.12.0
     45#define WEBKIT_FIRST_VERSION_WITH_CACHE_MODEL_API 0x020B0500 // 523.5.0
    4246
    4347#ifdef __cplusplus
  • trunk/WebKit/WebCoreSupport/WebFrameLoaderClient.h

    r25128 r25430  
    196196   
    197197    virtual void windowObjectCleared() const;
     198    virtual void didPerformFirstNavigation() const;
    198199
    199200    void deliverArchivedResourcesAfterDelay() const;
  • trunk/WebKit/WebCoreSupport/WebFrameLoaderClient.mm

    r25396 r25430  
    12421242}
    12431243
     1244void WebFrameLoaderClient::didPerformFirstNavigation() const
     1245{
     1246    WebPreferences *preferences = [[m_webFrame.get() webView] preferences];
     1247    if ([preferences automaticallyDetectsCacheModel] && [preferences cacheModel] < WebCacheModelDocumentBrowser)
     1248        [preferences setCacheModel:WebCacheModelDocumentBrowser];
     1249}
     1250
    12441251@implementation WebFramePolicyListener
    12451252
  • trunk/WebKit/WebView/WebPreferenceKeysPrivate.h

    r24289 r25430  
    5454#define WebKitAllowAnimatedImageLoopingPreferenceKey @"WebKitAllowAnimatedImageLoopingPreferenceKey"
    5555#define WebKitDisplayImagesKey @"WebKitDisplayImagesKey"
    56 #define WebKitPageCacheSizePreferenceKey @"WebKitPageCacheSizePreferenceKey"
    57 #define WebKitObjectCacheSizePreferenceKey @"WebKitObjectCacheSizePreferenceKey"
    5856#define WebKitBackForwardCacheExpirationIntervalKey @"WebKitBackForwardCacheExpirationIntervalKey"
    5957#define WebKitTabToLinksPreferenceKey @"WebKitTabToLinksPreferenceKey"
     
    7573#define WebKitUseSiteSpecificSpoofingPreferenceKey @"WebKitUseSiteSpecificSpoofing"
    7674#define WebKitEditableLinkBehaviorPreferenceKey @"WebKitEditableLinkBehavior"
    77 
     75#define WebKitCacheModelPreferenceKey @"WebKitCacheModelPreferenceKey"
    7876
    7977// CoreGraphics deferred updates are disabled if WebKitEnableCoalescedUpdatesPreferenceKey is set
     
    8179// default.
    8280#define WebKitEnableDeferredUpdatesPreferenceKey @"WebKitEnableDeferredUpdates"
     81
     82// For debugging only. Don't use these.
     83#define WebKitPageCacheSizePreferenceKey @"WebKitPageCacheSizePreferenceKey"
     84#define WebKitObjectCacheSizePreferenceKey @"WebKitObjectCacheSizePreferenceKey"
  • trunk/WebKit/WebView/WebPreferences.m

    r25114 r25430  
    3434#import "WebKitNSStringExtras.h"
    3535#import "WebKitSystemBits.h"
     36#import "WebKitSystemInterface.h"
     37#import "WebKitVersionChecks.h"
    3638#import "WebNSDictionaryExtras.h"
    3739#import "WebNSURLExtras.h"
    38 #import "WebKitSystemInterface.h"
    3940
    4041NSString *WebPreferencesChangedNotification = @"WebPreferencesChangedNotification";
     42NSString *WebPreferencesRemovedNotification = @"WebPreferencesRemovedNotification";
    4143
    4244#define KEY(x) (_private->identifier ? [_private->identifier stringByAppendingString:(x)] : (x))
    4345
    4446enum { WebPreferencesVersion = 1 };
     47
     48static WebPreferences *_standardPreferences;
     49static NSMutableDictionary *webPreferencesInstances;
     50
     51static bool contains(const char* const array[], int count, const char* item)
     52{
     53    if (!item)
     54        return false;
     55
     56    for (int i = 0; i < count; i++)
     57        if (!strcasecmp(array[i], item))
     58            return true;
     59    return false;
     60}
     61
     62static WebCacheModel cacheModelForMainBundle(void)
     63{
     64    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     65
     66    // Apps that probably need the small setting
     67    static const char* const documentViewerIDs[] = {
     68        "Microsoft/com.microsoft.Messenger",
     69        "com.adiumX.adiumX",
     70        "com.alientechnology.Proteus",
     71        "com.apple.Dashcode",
     72        "com.apple.iChat",
     73        "com.barebones.bbedit",
     74        "com.barebones.textwrangler",
     75        "com.barebones.yojimbo",
     76        "com.equinux.iSale4",
     77        "com.growl.growlframework",
     78        "com.intrarts.PandoraMan",
     79        "com.karelia.Sandvox",
     80        "com.macromates.textmate",
     81        "com.realmacsoftware.rapidweaverpro",
     82        "com.red-sweater.marsedit",
     83        "com.yahoo.messenger3",
     84        "de.codingmonkeys.SubEthaEdit",
     85        "fi.karppinen.Pyro",
     86        "info.colloquy",
     87        "kungfoo.tv.ecto",
     88    };
     89
     90    // Apps that probably need the medium setting
     91    static const char* const documentBrowserIDs[] = {
     92        "com.apple.Dictionary",
     93        "com.apple.Xcode",
     94        "com.apple.dashboard.client",
     95        "com.apple.helpviewer",
     96        "com.culturedcode.xyle",
     97        "com.macrabbit.CSSEdit",
     98        "com.panic.Coda",
     99        "com.ranchero.NetNewsWire",
     100        "com.thinkmac.NewsLife",
     101        "org.xlife.NewsFire",
     102        "uk.co.opencommunity.vienna2",
     103    };
     104
     105    // Apps that probably need the large setting
     106    static const char* const primaryWebBrowserIDs[] = {
     107        "com.app4mac.KidsBrowser"
     108        "com.freeverse.bumpercar",
     109        "com.omnigroup.OmniWeb5",
     110        "com.sunrisebrowser.Sunrise",
     111        "net.hmdt-web.Shiira",
     112    };
     113
     114    WebCacheModel cacheModel;
     115
     116    const char* bundleID = [[[NSBundle mainBundle] bundleIdentifier] UTF8String];
     117    if (contains(documentViewerIDs, sizeof(documentViewerIDs) / sizeof(documentViewerIDs[0]), bundleID))
     118        cacheModel = WebCacheModelDocumentViewer;
     119    else if (contains(documentBrowserIDs, sizeof(documentBrowserIDs) / sizeof(documentBrowserIDs[0]), bundleID))
     120        cacheModel = WebCacheModelDocumentBrowser;
     121    else if (contains(primaryWebBrowserIDs, sizeof(primaryWebBrowserIDs) / sizeof(primaryWebBrowserIDs[0]), bundleID))
     122        cacheModel = WebCacheModelPrimaryWebBrowser;
     123    else {
     124        bool isLegacyApp = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_CACHE_MODEL_API);
     125        if (isLegacyApp)
     126            cacheModel = WebCacheModelDocumentBrowser; // To avoid regressions in apps that depended on old WebKit's large cache.
     127        else
     128            cacheModel = WebCacheModelDocumentViewer; // To save memory.
     129    }
     130
     131    [pool drain];
     132
     133    return cacheModel;
     134}
    45135
    46136@interface WebPreferencesPrivate : NSObject
     
    51141    NSString *IBCreatorID;
    52142    BOOL autosaves;
     143    BOOL automaticallyDetectsCacheModel;
     144    unsigned numWebViews;
    53145}
    54146@end
     
    97189}
    98190
    99 static WebPreferences *_standardPreferences = nil;
    100 
    101191- (id)initWithIdentifier:(NSString *)anIdentifier
    102192{
     
    116206    _private->values = [[NSMutableDictionary alloc] init];
    117207    _private->identifier = [anIdentifier copy];
    118    
     208    _private->automaticallyDetectsCacheModel = YES;
     209
    119210    [[self class] _setInstance:self forIdentifier:_private->identifier];
    120211
    121     [[NSNotificationCenter defaultCenter]
    122        postNotificationName:WebPreferencesChangedNotification object:self userInfo:nil];
     212    [self _postPreferencesChangesNotification];
    123213
    124214    return self;
     
    135225    _private = [[WebPreferencesPrivate alloc] init];
    136226    _private->IBCreatorID = [[WebPreferences _IBCreatorID] retain];
     227    _private->automaticallyDetectsCacheModel = YES;
    137228   
    138229    if ([decoder allowsKeyedCoding]){
     
    191282        _standardPreferences = [[WebPreferences alloc] initWithIdentifier:nil];
    192283        [_standardPreferences setAutosaves:YES];
    193         [_standardPreferences _postPreferencesChangesNotification];
    194284    }
    195285
     
    200290+ (void)initialize
    201291{
    202     // As a fudge factor, use 1000 instead of 1024, in case the reported memory doesn't align exactly to a megabyte boundary.
    203     vm_size_t memSize = WebSystemMainMemory() / 1024 / 1000;
    204 
    205     // Page cache size (in pages)
    206     int pageCacheSize;
    207     if (memSize >= 1024)
    208         pageCacheSize = 10;
    209     else if (memSize >= 512)
    210         pageCacheSize = 5;
    211     else if (memSize >= 384)
    212         pageCacheSize = 4;
    213     else if (memSize >= 256)
    214         pageCacheSize = 3;
    215     else if (memSize >= 128)
    216         pageCacheSize = 2;
    217     else if (memSize >= 64)
    218         pageCacheSize = 1;
    219     else
    220         pageCacheSize = 0;
    221     NSString *pageCacheSizeString = [NSString stringWithFormat:@"%d", pageCacheSize];
    222 
    223     // Object cache size (in bytes)
    224     int objectCacheSize;
    225     if (memSize >= 2048)
    226         objectCacheSize = 128 * 1024 * 1024;
    227     else if (memSize >= 1024)
    228         objectCacheSize = 64 * 1024 * 1024;
    229     else if (memSize >= 512)
    230         objectCacheSize = 32 * 1024 * 1024;
    231     else
    232         objectCacheSize = 24 * 1024 * 1024;
    233     NSString *objectCacheSizeString = [NSString stringWithFormat:@"%d", objectCacheSize];
    234 
    235292    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
    236293        @"Times",                       WebKitStandardFontPreferenceKey,
     
    245302        @"13",                          WebKitDefaultFixedFontSizePreferenceKey,
    246303        @"ISO-8859-1",                  WebKitDefaultTextEncodingNamePreferenceKey,
    247         pageCacheSizeString,            WebKitPageCacheSizePreferenceKey,
    248         objectCacheSizeString,          WebKitObjectCacheSizePreferenceKey,
    249304        [NSNumber numberWithBool:NO],   WebKitUserStyleSheetEnabledPreferenceKey,
    250305        @"",                            WebKitUserStyleSheetLocationPreferenceKey,
     
    271326        [NSNumber numberWithBool:NO],   WebKitDOMPasteAllowedPreferenceKey,
    272327        [NSNumber numberWithBool:YES],  WebKitUsesPageCachePreferenceKey,
     328        [NSNumber numberWithInt:cacheModelForMainBundle()], WebKitCacheModelPreferenceKey,
    273329        nil];
    274330
     
    677733}
    678734
    679 - (size_t)_pageCacheSize
    680 {
    681     return [[NSUserDefaults standardUserDefaults] integerForKey:WebKitPageCacheSizePreferenceKey];
    682 }
    683 
    684 - (size_t)_objectCacheSize
    685 {
    686     return [[NSUserDefaults standardUserDefaults] integerForKey:WebKitObjectCacheSizePreferenceKey];
     735- (void)setCacheModel:(WebCacheModel)cacheModel
     736{
     737    [self _setIntegerValue:cacheModel forKey:WebKitCacheModelPreferenceKey];
     738    [self setAutomaticallyDetectsCacheModel:NO];
     739}
     740
     741- (WebCacheModel)cacheModel
     742{
     743    return [self _integerValueForKey:WebKitCacheModelPreferenceKey];
     744}
     745
     746- (BOOL)automaticallyDetectsCacheModel
     747{
     748    return _private->automaticallyDetectsCacheModel;
     749}
     750
     751- (void)setAutomaticallyDetectsCacheModel:(BOOL)automaticallyDetectsCacheModel
     752{
     753    _private->automaticallyDetectsCacheModel = automaticallyDetectsCacheModel;
    687754}
    688755
    689756- (NSTimeInterval)_backForwardCacheExpirationInterval
    690757{
     758    // FIXME: There's probably no good reason to read from the standard user defaults instead of self.
    691759    return (NSTimeInterval)[[NSUserDefaults standardUserDefaults] floatForKey:WebKitBackForwardCacheExpirationIntervalKey];
    692760}
     
    757825}
    758826
    759 static NSMutableDictionary *webPreferencesInstances = nil;
    760 
    761827+ (WebPreferences *)_getInstanceForIdentifier:(NSString *)ident
    762828{
    763         LOG (Encoding, "requesting for %@\n", ident);
    764 
    765     if (!ident){
    766         if(_standardPreferences)
    767             return _standardPreferences;
    768         return nil;
    769     }   
     829    LOG(Encoding, "requesting for %@\n", ident);
     830
     831    if (!ident)
     832        return _standardPreferences;
    770833   
    771834    WebPreferences *instance = [webPreferencesInstances objectForKey:[self _concatenateKeyWithIBCreatorID:ident]];
     
    780843    if (ident) {
    781844        [webPreferencesInstances setObject:instance forKey:[self _concatenateKeyWithIBCreatorID:ident]];
    782         LOG (Encoding, "recording %p for %@\n", instance, [self _concatenateKeyWithIBCreatorID:ident]);
    783     }
     845        LOG(Encoding, "recording %p for %@\n", instance, [self _concatenateKeyWithIBCreatorID:ident]);
     846    }
     847}
     848
     849+ (void)_checkLastReferenceForIdentifier:(id)identifier
     850{
     851    // FIXME: This won't work at all under garbage collection because retainCount returns a constant.
     852    // We may need to change WebPreferences API so there's an explicit way to end the lifetime of one.
     853    WebPreferences *instance = [webPreferencesInstances objectForKey:identifier];
     854    if ([instance retainCount] == 1)
     855        [webPreferencesInstances removeObjectForKey:identifier];
    784856}
    785857
    786858+ (void)_removeReferenceForIdentifier:(NSString *)ident
    787859{
    788     if (ident != nil) {
    789         [webPreferencesInstances performSelector:@selector(_web_checkLastReferenceForIdentifier:) withObject: [self _concatenateKeyWithIBCreatorID:ident] afterDelay:.1];
    790     }
     860    if (ident)
     861        [self performSelector:@selector(_checkLastReferenceForIdentifier:) withObject:[self _concatenateKeyWithIBCreatorID:ident] afterDelay:0.1];
    791862}
    792863
     
    847918{
    848919    return [self _boolValueForKey:WebKitForceFTPDirectoryListings];
     920}
     921
     922- (void)didRemoveFromWebView
     923{
     924    ASSERT(_private->numWebViews);
     925    if (--_private->numWebViews == 0)
     926        [[NSNotificationCenter defaultCenter]
     927            postNotificationName:WebPreferencesRemovedNotification
     928                          object:self
     929                        userInfo:nil];
     930}
     931
     932- (void)willAddToWebView
     933{
     934    ++_private->numWebViews;
    849935}
    850936
     
    867953
    868954@end
    869 
    870 @implementation NSMutableDictionary (WebInternal)
    871 
    872 - (void)_web_checkLastReferenceForIdentifier:(NSString *)identifier
    873 {
    874     WebPreferences *instance = [webPreferencesInstances objectForKey:identifier];
    875     if ([instance retainCount] == 1)
    876         [webPreferencesInstances removeObjectForKey:identifier];
    877 }
    878 
    879 @end
  • trunk/WebKit/WebView/WebPreferencesPrivate.h

    r24289 r25430  
    11/*
    2  * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
     2 * Copyright (C) 2005, 2007 Apple Computer, Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828
    2929#import <WebKit/WebPreferences.h>
     30#import <Quartz/Quartz.h>
    3031
    31 #import <Quartz/Quartz.h>
     32#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
     33#define WebNSUInteger unsigned int
     34#else
     35#define WebNSUInteger NSUInteger
     36#endif
    3237
    3338// WebKitEditableLinkBehavior needs to match the EditableLinkBehavior enum in WebCore
     
    3944    WebKitEditableLinkNeverLive
    4045} WebKitEditableLinkBehavior;
     46
     47/*!
     48@enum WebCacheModel
     49
     50@abstract Specifies a usage model for a WebView, which WebKit will use to
     51determine its caching behavior.
     52
     53@constant WebCacheModelDocumentViewer Appropriate for an application displaying
     54fixed documents -- like splash screens, chat documents, or word processing
     55documents -- with no UI for navigation. The WebView will behave like any other
     56view, releasing resources when they are no longer referenced. Remote resources,
     57if any, will be cached to disk. This is the most memory-efficient setting.
     58
     59Examples: iChat, Mail, TextMate, Growl.
     60
     61@constant WebCacheModelDocumentBrowser Appropriate for an application displaying
     62a browsable series of documents with a UI for navigating between them -- for
     63example, a reference materials browser or a website design application. The
     64WebView will cache a reasonable number of resources and previously viewed
     65documents in memory and/or on disk.
     66
     67Examples: Dictionary, Help Viewer, Coda.
     68
     69@constant WebCacheModelPrimaryWebBrowser Appropriate for the application that
     70acts as the user's primary web browser. The WebView will cache a very large
     71number of resources and previously viewed documents in memory and/or on disk.
     72
     73Examples: Safari, OmniWeb, Shiira.
     74*/
     75enum {
     76    WebCacheModelDocumentViewer = 0,
     77    WebCacheModelDocumentBrowser = 1,
     78    WebCacheModelPrimaryWebBrowser = 2
     79};
     80typedef WebNSUInteger WebCacheModel;
     81
     82extern NSString *WebPreferencesChangedNotification;
     83extern NSString *WebPreferencesRemovedNotification;
    4184
    4285@interface WebPreferences (WebPrivate)
     
    57100- (BOOL)shrinksStandaloneImagesToFit;
    58101- (void)setShrinksStandaloneImagesToFit:(BOOL)flag;
     102
     103/*!
     104@method setCacheModel:
     105
     106@abstract Specifies a usage model for a WebView, which WebKit will use to
     107determine its caching behavior.
     108
     109@param cacheModel The application's usage model for WebKit. If necessary,
     110WebKit will prune its caches to match cacheModel.
     111
     112@discussion Research indicates that users tend to browse within clusters of
     113documents that hold resources in common, and to revisit previously visited
     114documents. WebKit and the frameworks below it include built-in caches that take
     115advantage of these patterns, substantially improving document load speed in
     116browsing situations. The WebKit cache model controls the behaviors of all of
     117these caches, including NSURLCache and the various WebCore caches.
     118
     119Applications with a browsing interface can improve document load speed
     120substantially by specifying WebCacheModelDocumentBrowser. Applications without
     121a browsing interface can reduce memory usage substantially by specifying
     122WebCacheModelDocumentViewer.
     123
     124If setCacheModel: is not called, WebKit will select a cache model automatically.
     125*/
     126- (void)setCacheModel:(WebCacheModel)cacheModel;
     127
     128/*!
     129@method cacheModel:
     130
     131@abstract Returns the usage model according to which WebKit determines its
     132caching behavior.
     133
     134@result The usage model.
     135*/
     136- (WebCacheModel)cacheModel;
     137
     138- (BOOL)automaticallyDetectsCacheModel;
     139- (void)setAutomaticallyDetectsCacheModel:(BOOL)automaticallyDetectsCacheModel;
    59140
    60141// zero means do AutoScale
     
    85166
    86167// Other private methods
    87 - (size_t)_pageCacheSize;
    88 - (size_t)_objectCacheSize;
    89168- (void)_postPreferencesChangesNotification;
    90169+ (WebPreferences *)_getInstanceForIdentifier:(NSString *)identifier;
     
    96175+ (void)_setIBCreatorID:(NSString *)string;
    97176
     177// For WebView's use only.
     178- (void)willAddToWebView;
     179- (void)didRemoveFromWebView;
     180
    98181@end
     182
     183#undef WebNSUInteger
  • trunk/WebKit/WebView/WebView.mm

    r25396 r25430  
    6464#import "WebKitNSStringExtras.h"
    6565#import "WebKitStatisticsPrivate.h"
     66#import "WebKitSystemBits.h"
    6667#import "WebKitVersionChecks.h"
    6768#import "WebLocalizableStrings.h"
     
    121122#import <WebKit/DOMPrivate.h>
    122123#import <WebKitSystemInterface.h>
     124#import <mach-o/dyld.h>
    123125#import <objc/objc-runtime.h>
    124126#import <wtf/RefPtr.h>
     
    239241#define WebKitOriginalBottomPrintingMarginKey @"WebKitOriginalBottomMargin"
    240242
     243static BOOL s_didSetCacheModel;
     244static WebCacheModel s_cacheModel = WebCacheModelDocumentViewer;
     245
    241246static BOOL applicationIsTerminating;
    242247static int pluginDatabaseClientCount = 0;
     
    344349
    345350@interface WebView (WebFileInternal)
     351+ (void)_setCacheModel:(WebCacheModel)cacheModel;
     352+ (WebCacheModel)_cacheModel;
    346353- (WebFrame *)_selectedOrMainFrame;
    347354- (WebFrameBridge *)_bridgeForSelectedOrMainFrame;
     
    452459{
    453460    ASSERT(!page);
     461    ASSERT(!preferences);
    454462
    455463    delete userAgent;
     
    459467    [backgroundColor release];
    460468   
    461     [preferences release];
    462469    [hostWindow release];
    463470
     
    707714   
    708715    [[NSNotificationCenter defaultCenter] removeObserver:self];
    709     [WebPreferences _removeReferenceForIdentifier: [self preferencesIdentifier]];
     716
     717    [WebPreferences _removeReferenceForIdentifier:[self preferencesIdentifier]];
     718
     719    WebPreferences *preferences = _private->preferences;
     720    _private->preferences = nil;
     721    [preferences didRemoveFromWebView];
     722    [preferences release];
     723
    710724    pluginDatabaseClientCount--;
    711725   
     
    881895}
    882896
    883 - (void)_updateWebCoreSettingsFromPreferences:(WebPreferences *)preferences
    884 {
     897- (void)_preferencesChangedNotification:(NSNotification *)notification
     898{
     899    WebPreferences *preferences = (WebPreferences *)[notification object];
     900    ASSERT(preferences == [self preferences]);
     901
     902    if (!_private->userAgentOverridden)
     903        *_private->userAgent = String();
     904
     905    // Cache this value so we don't have to read NSUserDefaults on each page load
     906    _private->useSiteSpecificSpoofing = [preferences _useSiteSpecificSpoofing];
     907
     908    // Update corresponding WebCore Settings object.
    885909    if (!_private->page)
    886910        return;
     
    921945        settings->setUserStyleSheetLocation([NSURL URLWithString:@""]);
    922946    settings->setNeedsAdobeFrameReloadingQuirk([self _needsAdobeFrameReloadingQuirk]);
    923 }
    924 
    925 - (void)_preferencesChangedNotification: (NSNotification *)notification
    926 {
    927     WebPreferences *preferences = (WebPreferences *)[notification object];
    928    
    929     ASSERT(preferences == [self preferences]);
    930     if (!_private->userAgentOverridden)
    931         *_private->userAgent = String();
    932     // Cache this value so we don't have to read NSUserDefaults on each page load
    933     _private->useSiteSpecificSpoofing = [preferences _useSiteSpecificSpoofing];
    934     [self _updateWebCoreSettingsFromPreferences: preferences];
    935947}
    936948
     
    15701582{
    15711583    _private->usesPageCache = usesPageCache;
    1572     [self _updateWebCoreSettingsFromPreferences:[self preferences]];
     1584
     1585    // Post a notification so the WebCore settings update.
     1586    [[self preferences] _postPreferencesChangesNotification];
    15731587}
    15741588
     
    16571671
    16581672    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate) name:NSApplicationWillTerminateNotification object:NSApp];
     1673    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:) name:WebPreferencesChangedNotification object:nil];
     1674    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesRemovedNotification:) name:WebPreferencesRemovedNotification object:nil];
    16591675
    16601676    // Older versions of Safari use the pasteboard types without initializing them.
     
    17941810- (void)_commonInitializationWithFrameName:(NSString *)frameName groupName:(NSString *)groupName
    17951811{
     1812    WebPreferences *standardPreferences = [WebPreferences standardPreferences];
     1813    [standardPreferences willAddToWebView];
     1814
     1815    _private->preferences = [standardPreferences retain];
    17961816    _private->catchesDelegateExceptions = YES;
    17971817    _private->mainFrameDocumentReady = NO;
     
    17991819    _private->smartInsertDeleteEnabled = YES;
    18001820    _private->backgroundColor = [[NSColor whiteColor] retain];
    1801    
     1821
    18021822    NSRect f = [self frame];
    18031823    WebFrameView *frameView = [[WebFrameView alloc] initWithFrame: NSMakeRect(0,0,f.size.width,f.size.height)];
     
    18091829    WebCore::InitializeLoggingChannelsIfNecessary();
    18101830    [WebHistoryItem initWindowWatcherIfNecessary];
    1811     [WebView _initializeCacheSizesIfNecessary];
    18121831
    18131832    _private->page = new Page(new WebChromeClient(self), new WebContextMenuClient(self), new WebEditorClient(self), new WebDragClient(self), new WebInspectorClient(self));
     
    18361855
    18371856    WebPreferences *prefs = [self preferences];
    1838    
    1839     // Update WebCore with preferences.  These values will either come from an archived WebPreferences,
    1840     // or from the standard preferences, depending on whether this method was called from initWithCoder:
    1841     // or initWithFrame, respectively.
    1842     [self _updateWebCoreSettingsFromPreferences:prefs];
    1843 
    1844     // Initialize this cached value for the common case where we're using [WebPreferences standardPreferences],
    1845     // since neither setPreferences: nor _preferencesChangedNotification: will be called.
    1846     _private->useSiteSpecificSpoofing = [prefs _useSiteSpecificSpoofing];
    1847    
    1848     // Register to receive notifications whenever preference values change.
    18491857    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:)
    18501858                                                 name:WebPreferencesChangedNotification object:prefs];
     1859
     1860    // Post a notification so the WebCore settings update.
     1861    [[self preferences] _postPreferencesChangesNotification];
    18511862
    18521863    if (WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_LOCAL_RESOURCE_SECURITY_RESTRICTION))
     
    19811992- (void)dealloc
    19821993{
    1983     // call close to ensure we tear-down completly
     1994    // call close to ensure we tear-down completely
    19841995    // this maintains our old behavior for existing applications
    19851996    [self _close];
     
    20452056- (void)setPreferences:(WebPreferences *)prefs
    20462057{
    2047     if (_private->preferences != prefs) {
    2048         [[NSNotificationCenter defaultCenter] removeObserver:self name:WebPreferencesChangedNotification object:[self preferences]];
    2049         [WebPreferences _removeReferenceForIdentifier:[_private->preferences identifier]];
    2050         [_private->preferences release];
    2051         _private->preferences = [prefs retain];
    2052         // Cache this value so we don't have to read NSUserDefaults on each page load
    2053         _private->useSiteSpecificSpoofing = [prefs _useSiteSpecificSpoofing];
    2054         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:)
    2055             name:WebPreferencesChangedNotification object:[self preferences]];
    2056         [[NSNotificationCenter defaultCenter]
    2057             postNotificationName:WebPreferencesChangedNotification object:prefs userInfo:nil];
    2058     }
     2058    if (!prefs)
     2059        prefs = [WebPreferences standardPreferences];
     2060
     2061    if (_private->preferences == prefs)
     2062        return;
     2063
     2064    [prefs willAddToWebView];
     2065
     2066    WebPreferences *oldPrefs = _private->preferences;
     2067
     2068    [[NSNotificationCenter defaultCenter] removeObserver:self name:WebPreferencesChangedNotification object:[self preferences]];
     2069    [WebPreferences _removeReferenceForIdentifier:[oldPrefs identifier]];
     2070
     2071    _private->preferences = [prefs retain];
     2072
     2073    // After registering for the notification, post it so the WebCore settings update.
     2074    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_preferencesChangedNotification:)
     2075        name:WebPreferencesChangedNotification object:[self preferences]];
     2076    [[self preferences] _postPreferencesChangesNotification];
     2077
     2078    [oldPrefs didRemoveFromWebView];
     2079    [oldPrefs release];
    20592080}
    20602081
    20612082- (WebPreferences *)preferences
    20622083{
    2063     return _private->preferences ? _private->preferences : [WebPreferences standardPreferences];
     2084    return _private->preferences;
    20642085}
    20652086
     
    35623583@implementation WebView (WebFileInternal)
    35633584
     3585+ (void)_setCacheModel:(WebCacheModel)cacheModel
     3586{
     3587    if (s_didSetCacheModel && cacheModel == s_cacheModel)
     3588        return;
     3589
     3590    // As a fudge factor, use 1000 instead of 1024, in case the reported byte
     3591    // count doesn't align exactly to a megabyte boundary.
     3592    vm_size_t memSize = WebMemorySize() / 1024 / 1000;
     3593    unsigned long long diskFreeSize = WebVolumeFreeSize(NSHomeDirectory()) / 1024 / 1000;
     3594    NSURLCache *nsurlCache = [NSURLCache sharedURLCache];
     3595
     3596    unsigned cacheTotalCapacity = 0;
     3597    unsigned cacheMinDeadCapacity = 0;
     3598    unsigned cacheMaxDeadCapacity = 0;
     3599
     3600    unsigned pageCacheCapacity = 0;
     3601
     3602    unsigned nsurlCacheMemoryCapacity = 0;
     3603    unsigned nsurlCacheDiskCapacity = 0;
     3604
     3605    switch (cacheModel) {
     3606    case WebCacheModelDocumentViewer: {
     3607        // Page cache capacity (in pages)
     3608        pageCacheCapacity = 0;
     3609
     3610        // Object cache capacities (in bytes)
     3611        if (memSize >= 4096)
     3612            cacheTotalCapacity = 256 * 1024 * 1024;
     3613        else if (memSize >= 3072)
     3614            cacheTotalCapacity = 192 * 1024 * 1024;
     3615        else if (memSize >= 2048)
     3616            cacheTotalCapacity = 128 * 1024 * 1024;
     3617        else if (memSize >= 1536)
     3618            cacheTotalCapacity = 86 * 1024 * 1024;
     3619        else if (memSize >= 1024)
     3620            cacheTotalCapacity = 64 * 1024 * 1024;
     3621        else if (memSize >= 512)
     3622            cacheTotalCapacity = 32 * 1024 * 1024;
     3623        else if (memSize >= 256)
     3624            cacheTotalCapacity = 16 * 1024 * 1024;
     3625
     3626        cacheMinDeadCapacity = 0;
     3627        cacheMaxDeadCapacity = 0;
     3628
     3629        // Foundation memory cache capacity (in bytes)
     3630        nsurlCacheMemoryCapacity = 0;
     3631
     3632        // Foundation disk cache capacity (in bytes)
     3633        nsurlCacheDiskCapacity = [nsurlCache diskCapacity];
     3634
     3635        break;
     3636    }
     3637    case WebCacheModelDocumentBrowser: {
     3638        // Page cache capacity (in pages)
     3639        if (memSize >= 1024)
     3640            pageCacheCapacity = 3;
     3641        else if (memSize >= 512)
     3642            pageCacheCapacity = 2;
     3643        else if (memSize >= 256)
     3644            pageCacheCapacity = 1;
     3645        else
     3646            pageCacheCapacity = 0;
     3647
     3648        // Object cache capacities (in bytes)
     3649        if (memSize >= 4096)
     3650            cacheTotalCapacity = 256 * 1024 * 1024;
     3651        else if (memSize >= 3072)
     3652            cacheTotalCapacity = 192 * 1024 * 1024;
     3653        else if (memSize >= 2048)
     3654            cacheTotalCapacity = 128 * 1024 * 1024;
     3655        else if (memSize >= 1536)
     3656            cacheTotalCapacity = 86 * 1024 * 1024;
     3657        else if (memSize >= 1024)
     3658            cacheTotalCapacity = 64 * 1024 * 1024;
     3659        else if (memSize >= 512)
     3660            cacheTotalCapacity = 32 * 1024 * 1024;
     3661        else if (memSize >= 256)
     3662            cacheTotalCapacity = 16 * 1024 * 1024;
     3663
     3664        cacheMinDeadCapacity = cacheTotalCapacity * 0.125f;
     3665        cacheMaxDeadCapacity = cacheTotalCapacity * 0.25f;
     3666
     3667        // Foundation memory cache capacity (in bytes)
     3668        if (memSize >= 2048)
     3669            nsurlCacheMemoryCapacity = 4 * 1024 * 1024;
     3670        else if (memSize >= 1024)
     3671            nsurlCacheMemoryCapacity = 2 * 1024 * 1024;
     3672        else if (memSize >= 512)
     3673            nsurlCacheMemoryCapacity = 1 * 1024 * 1024;
     3674        else
     3675            nsurlCacheMemoryCapacity =      512 * 1024;
     3676
     3677        // Foundation disk cache capacity (in bytes)
     3678        if (diskFreeSize >= 16384)
     3679            nsurlCacheDiskCapacity = 50 * 1024 * 1024;
     3680        else if (diskFreeSize >= 8192)
     3681            nsurlCacheDiskCapacity = 40 * 1024 * 1024;
     3682        else if (diskFreeSize >= 4096)
     3683            nsurlCacheDiskCapacity = 30 * 1024 * 1024;
     3684        else
     3685            nsurlCacheDiskCapacity = 20 * 1024 * 1024;
     3686
     3687        break;
     3688    }
     3689    case WebCacheModelPrimaryWebBrowser: {
     3690        // Page cache capacity (in pages)
     3691        // (Research indicates that value / page drops substantially after 3 pages.)
     3692        if (memSize >= 8192)
     3693            pageCacheCapacity = 7;
     3694        if (memSize >= 4096)
     3695            pageCacheCapacity = 6;
     3696        else if (memSize >= 2048)
     3697            pageCacheCapacity = 5;
     3698        else if (memSize >= 1024)
     3699            pageCacheCapacity = 4;
     3700        else if (memSize >= 512)
     3701            pageCacheCapacity = 3;
     3702        else if (memSize >= 256)
     3703            pageCacheCapacity = 2;
     3704        else
     3705            pageCacheCapacity = 1;
     3706
     3707        // Object cache capacities (in bytes)
     3708        // (Testing indicates that value / MB depends heavily on content and
     3709        // browsing pattern. Even growth above 128MB can have substantial
     3710        // value / MB for some content / browsing patterns.)
     3711        if (memSize >= 4096)
     3712            cacheTotalCapacity = 512 * 1024 * 1024;
     3713        else if (memSize >= 3072)
     3714            cacheTotalCapacity = 384 * 1024 * 1024;
     3715        else if (memSize >= 2048)
     3716            cacheTotalCapacity = 256 * 1024 * 1024;
     3717        else if (memSize >= 1536)
     3718            cacheTotalCapacity = 172 * 1024 * 1024;
     3719        else if (memSize >= 1024)
     3720            cacheTotalCapacity = 128 * 1024 * 1024;
     3721        else if (memSize >= 512)
     3722            cacheTotalCapacity = 64 * 1024 * 1024;
     3723        else if (memSize >= 256)
     3724            cacheTotalCapacity = 32 * 1024 * 1024;
     3725
     3726        cacheMinDeadCapacity = cacheTotalCapacity * 0.25f;
     3727        cacheMaxDeadCapacity = cacheTotalCapacity * 0.50f;
     3728
     3729        // This code is here to avoid a PLT regression. We can remove it if we
     3730        // can prove that the overall system gain would justify the regression.
     3731        cacheMaxDeadCapacity = max(24u, cacheMaxDeadCapacity);
     3732
     3733        // Foundation memory cache capacity (in bytes)
     3734        // (These values are small because WebCore does most caching itself.)
     3735        if (memSize >= 1024)
     3736            nsurlCacheMemoryCapacity = 4 * 1024 * 1024;
     3737        else if (memSize >= 512)
     3738            nsurlCacheMemoryCapacity = 2 * 1024 * 1024;
     3739        else if (memSize >= 256)
     3740            nsurlCacheMemoryCapacity = 1 * 1024 * 1024;
     3741        else
     3742            nsurlCacheMemoryCapacity =      512 * 1024;
     3743
     3744        // Foundation disk cache capacity (in bytes)
     3745        if (diskFreeSize >= 16384)
     3746            nsurlCacheDiskCapacity = 175 * 1024 * 1024;
     3747        else if (diskFreeSize >= 8192)
     3748            nsurlCacheDiskCapacity = 150 * 1024 * 1024;
     3749        else if (diskFreeSize >= 4096)
     3750            nsurlCacheDiskCapacity = 125 * 1024 * 1024;
     3751        else if (diskFreeSize >= 2048)
     3752            nsurlCacheDiskCapacity = 100 * 1024 * 1024;
     3753        else if (diskFreeSize >= 1024)
     3754            nsurlCacheDiskCapacity = 75 * 1024 * 1024;
     3755        else
     3756            nsurlCacheDiskCapacity = 50 * 1024 * 1024;
     3757
     3758        break;
     3759    }
     3760    default:
     3761        ASSERT_NOT_REACHED();
     3762    };
     3763
     3764#ifdef BUILDING_ON_TIGER
     3765    // Don't use a big Foundation disk cache on Tiger because, according to the
     3766    // PLT, the Foundation disk cache on Tiger is slower than the network.
     3767    nsurlCacheDiskCapacity = [[NSURLCache sharedURLCache] diskCapacity];
     3768#else
     3769    // Don't use a big Foundation disk cache on older versions of Leopard because
     3770    // doing so causes a SPOD on launch (<rdar://problem/5465260>).
     3771    if (NSVersionOfLinkTimeLibrary("CFNetwork") < 211)
     3772        nsurlCacheDiskCapacity = [[NSURLCache sharedURLCache] diskCapacity];
     3773#endif
     3774
     3775    // Don't shrink a big disk cache, since that would cause churn.
     3776    nsurlCacheDiskCapacity = max(nsurlCacheDiskCapacity, [nsurlCache diskCapacity]);
     3777
     3778    cache()->setCapacities(cacheMinDeadCapacity, cacheMaxDeadCapacity, cacheTotalCapacity);
     3779    pageCache()->setCapacity(pageCacheCapacity);
     3780    [nsurlCache setMemoryCapacity:nsurlCacheMemoryCapacity];
     3781    [nsurlCache setDiskCapacity:nsurlCacheDiskCapacity];
     3782
     3783    s_cacheModel = cacheModel;
     3784    s_didSetCacheModel = YES;
     3785}
     3786
     3787+ (WebCacheModel)_cacheModel
     3788{
     3789    return s_cacheModel;
     3790}
     3791
     3792+ (WebCacheModel)_didSetCacheModel
     3793{
     3794    return s_didSetCacheModel;
     3795}
     3796
     3797+ (WebCacheModel)_maxCacheModelInAnyInstance
     3798{
     3799    WebCacheModel cacheModel = WebCacheModelDocumentViewer;
     3800    NSEnumerator *enumerator = [(NSMutableSet *)allWebViewsSet objectEnumerator];
     3801    while (WebPreferences *preferences = [[enumerator nextObject] preferences])
     3802        cacheModel = max(cacheModel, [preferences cacheModel]);
     3803    return cacheModel;
     3804}
     3805
     3806+ (void)_preferencesChangedNotification:(NSNotification *)notification
     3807{
     3808    WebPreferences *preferences = (WebPreferences *)[notification object];
     3809    ASSERT([preferences isKindOfClass:[WebPreferences class]]);
     3810
     3811    WebCacheModel cacheModel = [preferences cacheModel];
     3812    if (![self _didSetCacheModel] || cacheModel > [self _cacheModel])
     3813        [self _setCacheModel:cacheModel];
     3814    else if (cacheModel < [self _cacheModel])
     3815        [self _setCacheModel:max([[WebPreferences standardPreferences] cacheModel], [self _maxCacheModelInAnyInstance])];
     3816}
     3817
     3818+ (void)_preferencesRemovedNotification:(NSNotification *)notification
     3819{
     3820    WebPreferences *preferences = (WebPreferences *)[notification object];
     3821    ASSERT([preferences isKindOfClass:[WebPreferences class]]);
     3822
     3823    if ([preferences cacheModel] == [self _cacheModel])
     3824        [self _setCacheModel:max([[WebPreferences standardPreferences] cacheModel], [self _maxCacheModelInAnyInstance])];
     3825}
     3826
    35643827- (WebFrame *)_focusedFrame
    35653828{
     
    37694032@implementation WebView (WebViewInternal)
    37704033
    3771 + (void)_initializeCacheSizesIfNecessary
    3772 {
    3773     static bool didInitialize;
    3774     if (didInitialize)
    3775         return;
    3776 
    3777     WebPreferences *standardPreferences = [WebPreferences standardPreferences];
    3778     pageCache()->setCapacity([standardPreferences _pageCacheSize]);
    3779     cache()->setCapacities(0, [standardPreferences _objectCacheSize], [standardPreferences _objectCacheSize]);
    3780     didInitialize = true;
    3781 
    3782 #ifndef NDEBUG
    3783     LOG(CacheSizes, "Object cache size set to %d bytes.", [standardPreferences _objectCacheSize]);
    3784     LOG(CacheSizes, "Page cache size set to %d pages.", [standardPreferences _pageCacheSize]);
    3785 #endif
    3786 }
    3787 
    37884034- (BOOL)_becomingFirstResponderFromOutside
    37894035{
  • trunk/WebKit/WebView/WebViewInternal.h

    r25396 r25430  
    6868@interface WebView (WebViewMiscInternal)
    6969
    70 + (void)_initializeCacheSizesIfNecessary;
     70+ (void)_setCacheModelIfNecessary;
    7171- (WebCorePage*)page;
    7272- (NSMenu *)_menuForElement:(NSDictionary *)element defaultItems:(NSArray *)items;
  • trunk/WebKit/gtk/ChangeLog

    r25345 r25430  
     12007-09-05  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.
     4       
     5        Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
     6        memory cache, or a very tiny one
     7       
     8        Keep the GTK build working with an empty stub.
     9       
     10        * WebCoreSupport/FrameLoaderClientGtk.cpp:
     11        (WebKit::FrameLoaderClient::didPerformFirstNavigation):
     12        * WebCoreSupport/FrameLoaderClientGtk.h:
     13
    1142007-09-01  Oliver Hunt  <oliver@apple.com>
    215
  • trunk/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp

    r25143 r25430  
    250250}
    251251
     252void FrameLoaderClient::didPerformFirstNavigation() const
     253{
     254}
     255
    252256void FrameLoaderClient::setMainFrameDocumentReady(bool)
    253257{
  • trunk/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.h

    r25136 r25430  
    120120        virtual WebCore::String overrideMediaType() const;
    121121        virtual void windowObjectCleared() const;
     122        virtual void didPerformFirstNavigation() const;
    122123
    123124        virtual WebCore::ObjectContentType objectContentType(const WebCore::KURL& url, const WebCore::String& mimeType);
  • trunk/WebKit/win/ChangeLog

    r25428 r25430  
     12007-09-05  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.
     4       
     5        Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
     6        memory cache, or a very tiny one
     7       
     8        Keep the Windows build working with an empty stub.
     9       
     10        * WebFrame.cpp:
     11        (FrameLoaderClient::didPerformFirstNavigation):
     12        * WebFrame.h:
     13
    1142007-09-07  Ada Chan  <adachan@apple.com>
    215
  • trunk/WebKit/win/WebFrame.cpp

    r25427 r25430  
    23422342}
    23432343
     2344void FrameLoaderClient::didPerformFirstNavigation() const
     2345{
     2346}
     2347
    23442348static IntRect printerRect(HDC printDC)
    23452349{
  • trunk/WebKit/win/WebFrame.h

    r25288 r25430  
    314314
    315315    virtual void windowObjectCleared() const;
     316    virtual void didPerformFirstNavigation() const;
    316317
    317318    // WebFrame
  • trunk/WebKitQt/ChangeLog

    r25412 r25430  
     12007-09-05  Geoffrey Garen  <ggaren@apple.com>
     2
     3        Reviewed by Darin Adler, Maciej Stachowiak, Mark Rowe, Tim Hatcher.
     4       
     5        Fixed <rdar://problem/5326009> Make non-browser WebKit clients have no
     6        memory cache, or a very tiny one
     7       
     8        Keep the Qt build working with an empty stub.
     9       
     10        * WebCoreSupport/FrameLoaderClientQt.cpp:
     11        (WebCore::FrameLoaderClient::didPerformFirstNavigation):
     12        * WebCoreSupport/FrameLoaderClientQt.h:
     13
    1142007-09-07  George Staikos  <staikos@kde.org>
    215
  • trunk/WebKitQt/WebCoreSupport/FrameLoaderClientQt.cpp

    r25389 r25430  
    581581}
    582582
     583void FrameLoaderClient::didPerformFirstNavigation() const
     584{
     585}
     586
    583587void FrameLoaderClientQt::setDocumentViewFromCachedPage(CachedPage*)
    584588{
  • trunk/WebKitQt/WebCoreSupport/FrameLoaderClientQt.h

    r25144 r25430  
    213213       
    214214        virtual void windowObjectCleared() const;
     215        virtual void didPerformFirstNavigation() const;
    215216
    216217        QString chooseFile(const QString& oldFile);
Note: See TracChangeset for help on using the changeset viewer.