WebViews inside OS X screen savers have large caches, but should not
authoraroben@webkit.org <aroben@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Oct 2013 04:05:49 +0000 (04:05 +0000)
committeraroben@webkit.org <aroben@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Oct 2013 04:05:49 +0000 (04:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122604

We use WebCacheModelDocumentViewer by default for apps linked against
modern WebKit, and WebCacheModelDocumentBrowser for apps linked
against legacy WebKit. ScreenSaverEngine.app doesn't link against
WebKit at all, and thus falls into the legacy case by accident because
NSVersionOfLinkTimeLibrary("WebKit") returns -1.

But WebViews inside screen savers are almost certainly not being used
as browsers, so this large-ish cache specified by
WebCacheModelDocumentBrowser is wasteful. This is likely true for all
apps that don't directly link against WebKit, so now we use
WebCacheModelDocumentViewer by default for those apps.

Reviewed by Darin Adler.

* WebView/WebPreferences.mm:
(cacheModelForMainBundle): Use WebCacheModelDocumentViewer by default
for apps that don't link against WebKit directly. Also converted to
use @autoreleasepool {} and early returns while I was in here.

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

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebPreferences.mm

index e744b5e..38e4d4c 100644 (file)
@@ -1,3 +1,27 @@
+2013-10-12  Adam Roben  <aroben@webkit.org>
+
+        WebViews inside OS X screen savers have large caches, but should not
+        https://bugs.webkit.org/show_bug.cgi?id=122604
+
+        We use WebCacheModelDocumentViewer by default for apps linked against
+        modern WebKit, and WebCacheModelDocumentBrowser for apps linked
+        against legacy WebKit. ScreenSaverEngine.app doesn't link against
+        WebKit at all, and thus falls into the legacy case by accident because
+        NSVersionOfLinkTimeLibrary("WebKit") returns -1.
+
+        But WebViews inside screen savers are almost certainly not being used
+        as browsers, so this large-ish cache specified by
+        WebCacheModelDocumentBrowser is wasteful. This is likely true for all
+        apps that don't directly link against WebKit, so now we use
+        WebCacheModelDocumentViewer by default for those apps.
+
+        Reviewed by Darin Adler.
+
+        * WebView/WebPreferences.mm:
+        (cacheModelForMainBundle): Use WebCacheModelDocumentViewer by default
+        for apps that don't link against WebKit directly. Also converted to
+        use @autoreleasepool {} and early returns while I was in here.
+
 2013-10-12  Alexey Proskuryakov  <ap@apple.com>
 
         Add a feature define for SubtleCrypto
index 0c79bbe..5c0bef5 100644 (file)
@@ -75,77 +75,74 @@ static bool contains(const char* const array[], int count, const char* item)
 
 static WebCacheModel cacheModelForMainBundle(void)
 {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-    // Apps that probably need the small setting
-    static const char* const documentViewerIDs[] = {
-        "Microsoft/com.microsoft.Messenger",
-        "com.adiumX.adiumX", 
-        "com.alientechnology.Proteus",
-        "com.apple.Dashcode",
-        "com.apple.iChat", 
-        "com.barebones.bbedit", 
-        "com.barebones.textwrangler",
-        "com.barebones.yojimbo",
-        "com.equinux.iSale4",
-        "com.growl.growlframework",
-        "com.intrarts.PandoraMan",
-        "com.karelia.Sandvox",
-        "com.macromates.textmate",
-        "com.realmacsoftware.rapidweaverpro",
-        "com.red-sweater.marsedit",
-        "com.yahoo.messenger3",
-        "de.codingmonkeys.SubEthaEdit",
-        "fi.karppinen.Pyro",
-        "info.colloquy", 
-        "kungfoo.tv.ecto",
-    };
-
-    // Apps that probably need the medium setting
-    static const char* const documentBrowserIDs[] = {
-        "com.apple.Dictionary",
-        "com.apple.Xcode",
-        "com.apple.dashboard.client", 
-        "com.apple.helpviewer",
-        "com.culturedcode.xyle",
-        "com.macrabbit.CSSEdit",
-        "com.panic.Coda",
-        "com.ranchero.NetNewsWire",
-        "com.thinkmac.NewsLife",
-        "org.xlife.NewsFire",
-        "uk.co.opencommunity.vienna2",
-    };
-
-    // Apps that probably need the large setting
-    static const char* const primaryWebBrowserIDs[] = {
-        "com.app4mac.KidsBrowser"
-        "com.app4mac.wKiosk",
-        "com.freeverse.bumpercar",
-        "com.omnigroup.OmniWeb5",
-        "com.sunrisebrowser.Sunrise",
-        "net.hmdt-web.Shiira",
-    };
-
-    WebCacheModel cacheModel;
-
-    const char* bundleID = [[[NSBundle mainBundle] bundleIdentifier] UTF8String];
-    if (contains(documentViewerIDs, sizeof(documentViewerIDs) / sizeof(documentViewerIDs[0]), bundleID))
-        cacheModel = WebCacheModelDocumentViewer;
-    else if (contains(documentBrowserIDs, sizeof(documentBrowserIDs) / sizeof(documentBrowserIDs[0]), bundleID))
-        cacheModel = WebCacheModelDocumentBrowser;
-    else if (contains(primaryWebBrowserIDs, sizeof(primaryWebBrowserIDs) / sizeof(primaryWebBrowserIDs[0]), bundleID))
-        cacheModel = WebCacheModelPrimaryWebBrowser;
-    else {
+    @autoreleasepool {
+        // Apps that probably need the small setting
+        static const char* const documentViewerIDs[] = {
+            "Microsoft/com.microsoft.Messenger",
+            "com.adiumX.adiumX", 
+            "com.alientechnology.Proteus",
+            "com.apple.Dashcode",
+            "com.apple.iChat", 
+            "com.barebones.bbedit",
+            "com.barebones.textwrangler",
+            "com.barebones.yojimbo",
+            "com.equinux.iSale4",
+            "com.growl.growlframework",
+            "com.intrarts.PandoraMan",
+            "com.karelia.Sandvox",
+            "com.macromates.textmate",
+            "com.realmacsoftware.rapidweaverpro",
+            "com.red-sweater.marsedit",
+            "com.yahoo.messenger3",
+            "de.codingmonkeys.SubEthaEdit",
+            "fi.karppinen.Pyro",
+            "info.colloquy", 
+            "kungfoo.tv.ecto",
+        };
+
+        // Apps that probably need the medium setting
+        static const char* const documentBrowserIDs[] = {
+            "com.apple.Dictionary",
+            "com.apple.Xcode",
+            "com.apple.dashboard.client", 
+            "com.apple.helpviewer",
+            "com.culturedcode.xyle",
+            "com.macrabbit.CSSEdit",
+            "com.panic.Coda",
+            "com.ranchero.NetNewsWire",
+            "com.thinkmac.NewsLife",
+            "org.xlife.NewsFire",
+            "uk.co.opencommunity.vienna2",
+        };
+
+        // Apps that probably need the large setting
+        static const char* const primaryWebBrowserIDs[] = {
+            "com.app4mac.KidsBrowser"
+            "com.app4mac.wKiosk",
+            "com.freeverse.bumpercar",
+            "com.omnigroup.OmniWeb5",
+            "com.sunrisebrowser.Sunrise",
+            "net.hmdt-web.Shiira",
+        };
+
+        const char* bundleID = [[[NSBundle mainBundle] bundleIdentifier] UTF8String];
+        if (contains(documentViewerIDs, sizeof(documentViewerIDs) / sizeof(documentViewerIDs[0]), bundleID))
+            return WebCacheModelDocumentViewer;
+        if (contains(documentBrowserIDs, sizeof(documentBrowserIDs) / sizeof(documentBrowserIDs[0]), bundleID))
+            return WebCacheModelDocumentBrowser;
+        if (contains(primaryWebBrowserIDs, sizeof(primaryWebBrowserIDs) / sizeof(primaryWebBrowserIDs[0]), bundleID))
+            return WebCacheModelPrimaryWebBrowser;
+
+        bool isLinkedAgainstWebKit = WebKitLinkedOnOrAfter(0);
+        if (!isLinkedAgainstWebKit)
+            return WebCacheModelDocumentViewer; // Apps that don't link against WebKit probably aren't meant to be browsers.
+
         bool isLegacyApp = !WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_CACHE_MODEL_API);
         if (isLegacyApp)
-            cacheModel = WebCacheModelDocumentBrowser; // To avoid regressions in apps that depended on old WebKit's large cache.
-        else
-            cacheModel = WebCacheModelDocumentViewer; // To save memory.
-    }
+            return WebCacheModelDocumentBrowser; // To avoid regressions in apps that depended on old WebKit's large cache.
 
-    [pool drain];
-
-    return cacheModel;
+        return WebCacheModelDocumentViewer; // To save memory.
+    }
 }
 
 @interface WebPreferences ()