1/*
2 * Copyright (C) 2005 Apple 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 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
14 *     its contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#if TARGET_OS_IPHONE
30#import <Foundation/Foundation.h>
31#else
32#import <Cocoa/Cocoa.h>
33#endif
34
35// Sent whenever a site icon has changed. The object of the notification is the icon database.
36// The userInfo contains the site URL whose icon has changed.
37// It can be accessed with the key WebIconNotificationUserInfoURLKey.
38extern NSString *WebIconDatabaseDidAddIconNotification;
39
40extern NSString *WebIconNotificationUserInfoURLKey;
41
42extern NSString *WebIconDatabaseDirectoryDefaultsKey;
43extern NSString *WebIconDatabaseEnabledDefaultsKey;
44
45extern NSSize WebIconSmallSize;  // 16 x 16
46extern NSSize WebIconMediumSize; // 32 x 32
47extern NSSize WebIconLargeSize;  // 128 x 128
48
49@class WebIconDatabasePrivate;
50
51/*!
52    @class WebIconDatabase
53    @discussion Features:
54        - memory cache icons at different sizes
55        - disk storage
56        - icon update notification
57
58        Uses:
59        - UI elements to retrieve icons that represent site URLs.
60        - Save icons to disk for later use.
61
62    Every icon in the database has a retain count.  If an icon has a retain count greater than 0, it will be written to disk for later use. If an icon's retain count equals zero it will be removed from disk.  The retain count is not persistent across launches. If the WebKit client wishes to retain an icon it should retain the icon once for every launch.  This is best done at initialization time before the database begins removing icons.  To make sure that the database does not remove unretained icons prematurely, call delayDatabaseCleanup until all desired icons are retained.  Once all are retained, call allowDatabaseCleanup.
63
64    Note that an icon can be retained after the database clean-up has begun. This just has to be done before the icon is removed. Icons are removed from the database whenever new icons are added to it.
65
66    Retention methods can be called for icons that are not yet in the database.
67*/
68@interface WebIconDatabase : NSObject {
69
70@private
71    WebIconDatabasePrivate *_private;
72    BOOL _isClosing;
73}
74
75
76/*!
77    @method sharedIconDatabase
78    @abstract Returns a shared instance of the icon database
79*/
80+ (WebIconDatabase *)sharedIconDatabase;
81
82#if !TARGET_OS_IPHONE
83/*!
84    @method iconForURL:withSize:
85    @discussion Calls iconForURL:withSize:cache: with YES for cache.
86    @param URL
87    @param size
88*/
89- (NSImage *)iconForURL:(NSString *)URL withSize:(NSSize)size;
90
91/*!
92    @method iconForURL:withSize:cache:
93    @discussion Returns an icon for a web site URL from memory or disk. nil if none is found.
94    Usually called by a UI element to determine if a site URL has an associated icon.
95    Often called by the observer of WebIconChangedNotification after the notification is sent.
96    @param URL
97    @param size
98    @param cache If yes, caches the returned image in memory if not already cached
99*/
100- (NSImage *)iconForURL:(NSString *)URL withSize:(NSSize)size cache:(BOOL)cache;
101#endif
102
103/*!
104    @method iconURLForURL:withSize:cache:
105    @discussion Returns an icon URL for a web site URL from memory or disk. nil if none is found.
106    @param URL
107*/
108- (NSString *)iconURLForURL:(NSString *)URL;
109
110#if !TARGET_OS_IPHONE
111/*!
112    @method defaultIconWithSize:
113    @param size
114*/
115- (NSImage *)defaultIconWithSize:(NSSize)size;
116- (NSImage *)defaultIconForURL:(NSString *)URL withSize:(NSSize)size;
117#endif
118
119/*!
120    @method retainIconForURL:
121    @abstract Increments the retain count of the icon.
122    @param URL
123*/
124- (void)retainIconForURL:(NSString *)URL;
125
126/*!
127    @method releaseIconForURL:
128    @abstract Decrements the retain count of the icon.
129    @param URL
130*/
131- (void)releaseIconForURL:(NSString *)URL;
132
133/*!
134    @method delayDatabaseCleanup:
135    @discussion Only effective if called before the database begins removing icons.
136    delayDatabaseCleanUp increments an internal counter that when 0 begins the database clean-up.
137    The counter equals 0 at initialization.
138*/
139+ (void)delayDatabaseCleanup;
140
141/*!
142    @method allowDatabaseCleanup:
143    @discussion Informs the database that it now can begin removing icons.
144    allowDatabaseCleanup decrements an internal counter that when 0 begins the database clean-up.
145    The counter equals 0 at initialization.
146*/
147+ (void)allowDatabaseCleanup;
148
149- (void)setDelegate:(id)delegate;
150- (id)delegate;
151
152@end
153