~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/mac/Misc/WebCache.mm

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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. 
 
24
 */
 
25
 
 
26
#import "WebCache.h"
 
27
 
 
28
#import "WebNSObjectExtras.h"
 
29
#import "WebPreferences.h"
 
30
#import "WebSystemInterface.h"
 
31
#import "WebView.h"
 
32
#import "WebViewInternal.h"
 
33
#import <WebCore/ApplicationCacheStorage.h>
 
34
#import <WebCore/MemoryCache.h>
 
35
#import <WebCore/CrossOriginPreflightResultCache.h>
 
36
 
 
37
@implementation WebCache
 
38
 
 
39
+ (void)initialize
 
40
{
 
41
    InitWebCoreSystemInterface();   
 
42
}
 
43
 
 
44
+ (NSArray *)statistics
 
45
{
 
46
    WebCore::MemoryCache::Statistics s = WebCore::memoryCache()->getStatistics();
 
47
 
 
48
    return [NSArray arrayWithObjects:
 
49
        [NSDictionary dictionaryWithObjectsAndKeys:
 
50
            [NSNumber numberWithInt:s.images.count], @"Images",
 
51
            [NSNumber numberWithInt:s.cssStyleSheets.count], @"CSS",
 
52
#if ENABLE(XSLT)
 
53
            [NSNumber numberWithInt:s.xslStyleSheets.count], @"XSL",
 
54
#else
 
55
            [NSNumber numberWithInt:0], @"XSL",
 
56
#endif
 
57
            [NSNumber numberWithInt:s.scripts.count], @"JavaScript",
 
58
            nil],
 
59
        [NSDictionary dictionaryWithObjectsAndKeys:
 
60
            [NSNumber numberWithInt:s.images.size], @"Images",
 
61
            [NSNumber numberWithInt:s.cssStyleSheets.size] ,@"CSS",
 
62
#if ENABLE(XSLT)
 
63
            [NSNumber numberWithInt:s.xslStyleSheets.size], @"XSL",
 
64
#else
 
65
            [NSNumber numberWithInt:0], @"XSL",
 
66
#endif
 
67
            [NSNumber numberWithInt:s.scripts.size], @"JavaScript",
 
68
            nil],
 
69
        [NSDictionary dictionaryWithObjectsAndKeys:
 
70
            [NSNumber numberWithInt:s.images.liveSize], @"Images",
 
71
            [NSNumber numberWithInt:s.cssStyleSheets.liveSize] ,@"CSS",
 
72
#if ENABLE(XSLT)
 
73
            [NSNumber numberWithInt:s.xslStyleSheets.liveSize], @"XSL",
 
74
#else
 
75
            [NSNumber numberWithInt:0], @"XSL",
 
76
#endif
 
77
            [NSNumber numberWithInt:s.scripts.liveSize], @"JavaScript",
 
78
            nil],
 
79
        [NSDictionary dictionaryWithObjectsAndKeys:
 
80
            [NSNumber numberWithInt:s.images.decodedSize], @"Images",
 
81
            [NSNumber numberWithInt:s.cssStyleSheets.decodedSize] ,@"CSS",
 
82
#if ENABLE(XSLT)
 
83
            [NSNumber numberWithInt:s.xslStyleSheets.decodedSize], @"XSL",
 
84
#else
 
85
            [NSNumber numberWithInt:0], @"XSL",
 
86
#endif
 
87
            [NSNumber numberWithInt:s.scripts.decodedSize], @"JavaScript",
 
88
            nil],
 
89
        [NSDictionary dictionaryWithObjectsAndKeys:
 
90
            [NSNumber numberWithInt:s.images.purgeableSize], @"Images",
 
91
            [NSNumber numberWithInt:s.cssStyleSheets.purgeableSize] ,@"CSS",
 
92
#if ENABLE(XSLT)
 
93
            [NSNumber numberWithInt:s.xslStyleSheets.purgeableSize], @"XSL",
 
94
#else
 
95
            [NSNumber numberWithInt:0], @"XSL",
 
96
#endif
 
97
            [NSNumber numberWithInt:s.scripts.purgeableSize], @"JavaScript",
 
98
            nil],
 
99
        [NSDictionary dictionaryWithObjectsAndKeys:
 
100
            [NSNumber numberWithInt:s.images.purgedSize], @"Images",
 
101
            [NSNumber numberWithInt:s.cssStyleSheets.purgedSize] ,@"CSS",
 
102
#if ENABLE(XSLT)
 
103
            [NSNumber numberWithInt:s.xslStyleSheets.purgedSize], @"XSL",
 
104
#else
 
105
            [NSNumber numberWithInt:0], @"XSL",
 
106
#endif
 
107
            [NSNumber numberWithInt:s.scripts.purgedSize], @"JavaScript",
 
108
            nil],
 
109
        nil];
 
110
}
 
111
 
 
112
+ (void)empty
 
113
{
 
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];
 
118
 
 
119
    // Empty the application cache.
 
120
    WebCore::cacheStorage().empty();
 
121
 
 
122
    // Empty the Cross-Origin Preflight cache
 
123
    WebCore::CrossOriginPreflightResultCache::shared().empty();
 
124
}
 
125
 
 
126
+ (void)setDisabled:(BOOL)disabled
 
127
{
 
128
    if (!pthread_main_np())
 
129
        return [[self _webkit_invokeOnMainThread] setDisabled:disabled];
 
130
 
 
131
    WebCore::memoryCache()->setDisabled(disabled);
 
132
}
 
133
 
 
134
+ (BOOL)isDisabled
 
135
{
 
136
    return WebCore::memoryCache()->disabled();
 
137
}
 
138
 
 
139
@end