2 * Copyright (C) 2005 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
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 Computer, 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.
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.
29 #import <Cocoa/Cocoa.h>
31 // Sent whenever a site icon has changed. The object of the notification is the icon database.
32 // The userInfo contains the site URL whose icon has changed.
33 // It can be accessed with the key WebIconNotificationUserInfoURLKey.
34 extern NSString *WebIconDatabaseDidAddIconNotification;
36 extern NSString *WebIconNotificationUserInfoURLKey;
38 extern NSString *WebIconDatabaseDirectoryDefaultsKey;
39 extern NSString *WebIconDatabaseEnabledDefaultsKey;
41 extern NSSize WebIconSmallSize; // 16 x 16
42 extern NSSize WebIconMediumSize; // 32 x 32
43 extern NSSize WebIconLargeSize; // 128 x 128
45 @class WebIconDatabasePrivate;
48 @class WebIconDatabase
50 - memory cache icons at different sizes
52 - icon update notification
55 - UI elements to retrieve icons that represent site URLs.
56 - Save icons to disk for later use.
58 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.
60 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.
62 Retention methods can be called for icons that are not yet in the database.
64 @interface WebIconDatabase : NSObject {
67 WebIconDatabasePrivate *_private;
73 @method sharedIconDatabase
74 @abstract Returns a shared instance of the icon database
76 + (WebIconDatabase *)sharedIconDatabase;
79 @method iconForURL:withSize:
80 @discussion Calls iconForURL:withSize:cache: with YES for cache.
84 - (NSImage *)iconForURL:(NSString *)URL withSize:(NSSize)size;
87 @method iconForURL:withSize:cache:
88 @discussion Returns an icon for a web site URL from memory or disk. nil if none is found.
89 Usually called by a UI element to determine if a site URL has an associated icon.
90 Often called by the observer of WebIconChangedNotification after the notification is sent.
93 @param cache If yes, caches the returned image in memory if not already cached
95 - (NSImage *)iconForURL:(NSString *)URL withSize:(NSSize)size cache:(BOOL)cache;
98 @method iconURLForURL:withSize:cache:
99 @discussion Returns an icon URL for a web site URL from memory or disk. nil if none is found.
102 - (NSString *)iconURLForURL:(NSString *)URL;
105 @method defaultIconWithSize:
108 - (NSImage *)defaultIconWithSize:(NSSize)size;
109 - (NSImage *)defaultIconForURL:(NSString *)URL withSize:(NSSize)size;
112 @method retainIconForURL:
113 @abstract Increments the retain count of the icon.
116 - (void)retainIconForURL:(NSString *)URL;
119 @method releaseIconForURL:
120 @abstract Decrements the retain count of the icon.
123 - (void)releaseIconForURL:(NSString *)URL;
126 @method delayDatabaseCleanup:
127 @discussion Only effective if called before the database begins removing icons.
128 delayDatabaseCleanUp increments an internal counter that when 0 begins the database clean-up.
129 The counter equals 0 at initialization.
131 + (void)delayDatabaseCleanup;
134 @method allowDatabaseCleanup:
135 @discussion Informs the database that it now can begin removing icons.
136 allowDatabaseCleanup decrements an internal counter that when 0 begins the database clean-up.
137 The counter equals 0 at initialization.
139 + (void)allowDatabaseCleanup;
141 - (void)setDelegate:(id)delegate;