WebIconDatabase.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2005 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. *
  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.
  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. #import <Cocoa/Cocoa.h>
  29. // Sent whenever a site icon has changed. The object of the notification is the icon database.
  30. // The userInfo contains the site URL whose icon has changed.
  31. // It can be accessed with the key WebIconNotificationUserInfoURLKey.
  32. extern NSString *WebIconDatabaseDidAddIconNotification;
  33. extern NSString *WebIconNotificationUserInfoURLKey;
  34. extern NSString *WebIconDatabaseDirectoryDefaultsKey;
  35. extern NSString *WebIconDatabaseEnabledDefaultsKey;
  36. extern NSSize WebIconSmallSize; // 16 x 16
  37. extern NSSize WebIconMediumSize; // 32 x 32
  38. extern NSSize WebIconLargeSize; // 128 x 128
  39. @class WebIconDatabasePrivate;
  40. /*!
  41. @class WebIconDatabase
  42. @discussion Features:
  43. - memory cache icons at different sizes
  44. - disk storage
  45. - icon update notification
  46. Uses:
  47. - UI elements to retrieve icons that represent site URLs.
  48. - Save icons to disk for later use.
  49. 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.
  50. 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.
  51. Retention methods can be called for icons that are not yet in the database.
  52. */
  53. @interface WebIconDatabase : NSObject {
  54. @private
  55. WebIconDatabasePrivate *_private;
  56. BOOL _isClosing;
  57. }
  58. /*!
  59. @method sharedIconDatabase
  60. @abstract Returns a shared instance of the icon database
  61. */
  62. + (WebIconDatabase *)sharedIconDatabase;
  63. /*!
  64. @method iconForURL:withSize:
  65. @discussion Calls iconForURL:withSize:cache: with YES for cache.
  66. @param URL
  67. @param size
  68. */
  69. - (NSImage *)iconForURL:(NSString *)URL withSize:(NSSize)size;
  70. /*!
  71. @method iconForURL:withSize:cache:
  72. @discussion Returns an icon for a web site URL from memory or disk. nil if none is found.
  73. Usually called by a UI element to determine if a site URL has an associated icon.
  74. Often called by the observer of WebIconChangedNotification after the notification is sent.
  75. @param URL
  76. @param size
  77. @param cache If yes, caches the returned image in memory if not already cached
  78. */
  79. - (NSImage *)iconForURL:(NSString *)URL withSize:(NSSize)size cache:(BOOL)cache;
  80. /*!
  81. @method iconURLForURL:withSize:cache:
  82. @discussion Returns an icon URL for a web site URL from memory or disk. nil if none is found.
  83. @param URL
  84. */
  85. - (NSString *)iconURLForURL:(NSString *)URL;
  86. /*!
  87. @method defaultIconWithSize:
  88. @param size
  89. */
  90. - (NSImage *)defaultIconWithSize:(NSSize)size;
  91. - (NSImage *)defaultIconForURL:(NSString *)URL withSize:(NSSize)size;
  92. /*!
  93. @method retainIconForURL:
  94. @abstract Increments the retain count of the icon.
  95. @param URL
  96. */
  97. - (void)retainIconForURL:(NSString *)URL;
  98. /*!
  99. @method releaseIconForURL:
  100. @abstract Decrements the retain count of the icon.
  101. @param URL
  102. */
  103. - (void)releaseIconForURL:(NSString *)URL;
  104. /*!
  105. @method delayDatabaseCleanup:
  106. @discussion Only effective if called before the database begins removing icons.
  107. delayDatabaseCleanUp increments an internal counter that when 0 begins the database clean-up.
  108. The counter equals 0 at initialization.
  109. */
  110. + (void)delayDatabaseCleanup;
  111. /*!
  112. @method allowDatabaseCleanup:
  113. @discussion Informs the database that it now can begin removing icons.
  114. allowDatabaseCleanup decrements an internal counter that when 0 begins the database clean-up.
  115. The counter equals 0 at initialization.
  116. */
  117. + (void)allowDatabaseCleanup;
  118. - (void)setDelegate:(id)delegate;
  119. - (id)delegate;
  120. @end