2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #import "WebNSObjectExtras.h"
29 #import "WebPreferences.h"
30 #import "WebSystemInterface.h"
32 #import "WebViewInternal.h"
33 #import <WebCore/ApplicationCacheStorage.h>
34 #import <WebCore/MemoryCache.h>
35 #import <WebCore/CrossOriginPreflightResultCache.h>
37 @implementation WebCache
41 InitWebCoreSystemInterface();
44 + (NSArray *)statistics
46 WebCore::MemoryCache::Statistics s = WebCore::memoryCache()->getStatistics();
48 return [NSArray arrayWithObjects:
49 [NSDictionary dictionaryWithObjectsAndKeys:
50 [NSNumber numberWithInt:s.images.count], @"Images",
51 [NSNumber numberWithInt:s.cssStyleSheets.count], @"CSS",
53 [NSNumber numberWithInt:s.xslStyleSheets.count], @"XSL",
55 [NSNumber numberWithInt:0], @"XSL",
57 [NSNumber numberWithInt:s.scripts.count], @"JavaScript",
59 [NSDictionary dictionaryWithObjectsAndKeys:
60 [NSNumber numberWithInt:s.images.size], @"Images",
61 [NSNumber numberWithInt:s.cssStyleSheets.size] ,@"CSS",
63 [NSNumber numberWithInt:s.xslStyleSheets.size], @"XSL",
65 [NSNumber numberWithInt:0], @"XSL",
67 [NSNumber numberWithInt:s.scripts.size], @"JavaScript",
69 [NSDictionary dictionaryWithObjectsAndKeys:
70 [NSNumber numberWithInt:s.images.liveSize], @"Images",
71 [NSNumber numberWithInt:s.cssStyleSheets.liveSize] ,@"CSS",
73 [NSNumber numberWithInt:s.xslStyleSheets.liveSize], @"XSL",
75 [NSNumber numberWithInt:0], @"XSL",
77 [NSNumber numberWithInt:s.scripts.liveSize], @"JavaScript",
79 [NSDictionary dictionaryWithObjectsAndKeys:
80 [NSNumber numberWithInt:s.images.decodedSize], @"Images",
81 [NSNumber numberWithInt:s.cssStyleSheets.decodedSize] ,@"CSS",
83 [NSNumber numberWithInt:s.xslStyleSheets.decodedSize], @"XSL",
85 [NSNumber numberWithInt:0], @"XSL",
87 [NSNumber numberWithInt:s.scripts.decodedSize], @"JavaScript",
89 [NSDictionary dictionaryWithObjectsAndKeys:
90 [NSNumber numberWithInt:s.images.purgeableSize], @"Images",
91 [NSNumber numberWithInt:s.cssStyleSheets.purgeableSize] ,@"CSS",
93 [NSNumber numberWithInt:s.xslStyleSheets.purgeableSize], @"XSL",
95 [NSNumber numberWithInt:0], @"XSL",
97 [NSNumber numberWithInt:s.scripts.purgeableSize], @"JavaScript",
99 [NSDictionary dictionaryWithObjectsAndKeys:
100 [NSNumber numberWithInt:s.images.purgedSize], @"Images",
101 [NSNumber numberWithInt:s.cssStyleSheets.purgedSize] ,@"CSS",
103 [NSNumber numberWithInt:s.xslStyleSheets.purgedSize], @"XSL",
105 [NSNumber numberWithInt:0], @"XSL",
107 [NSNumber numberWithInt:s.scripts.purgedSize], @"JavaScript",
114 // Toggling the cache model like this forces the cache to evict all its in-memory resources.
115 WebCacheModel cacheModel = [WebView _cacheModel];
116 [WebView _setCacheModel:WebCacheModelDocumentViewer];
117 [WebView _setCacheModel:cacheModel];
119 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
120 // Empty the application cache.
121 WebCore::cacheStorage().empty();
124 // Empty the Cross-Origin Preflight cache
125 WebCore::CrossOriginPreflightResultCache::shared().empty();
128 + (void)setDisabled:(BOOL)disabled
130 if (!pthread_main_np())
131 return [[self _webkit_invokeOnMainThread] setDisabled:disabled];
133 WebCore::memoryCache()->setDisabled(disabled);
138 return WebCore::memoryCache()->disabled();