WebCore:
authorbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Jun 2006 01:29:57 +0000 (01:29 +0000)
committerbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Jun 2006 01:29:57 +0000 (01:29 +0000)
        Reviewed by Maciej.

        More changes/additions setting the stage for the major IconDatabase hookup.

        * WebCore.xcodeproj/project.pbxproj:  Added SQLTransaction.cpp

        * bridge/mac/WebCoreIconDatabaseBridge.h: Added call-throughs and translations to pass WebKit DB to WebCore DB
        * bridge/mac/WebCoreIconDatabaseBridge.mm:
        (+[WebCoreIconDatabaseBridge sharedBridgeInstance]):
        (-[WebCoreIconDatabaseBridge setPrivateBrowsingEnabled:]):
        (-[WebCoreIconDatabaseBridge iconForURL:withSize:]):
        (-[WebCoreIconDatabaseBridge iconURLForURL:]):
        (-[WebCoreIconDatabaseBridge defaultIconWithSize:]):
        (-[WebCoreIconDatabaseBridge retainIconForURL:]):
        (-[WebCoreIconDatabaseBridge releaseIconForURL:]):
        (-[WebCoreIconDatabaseBridge _setIconData:forIconURL:]):
        (-[WebCoreIconDatabaseBridge _setHaveNoIconForIconURL:]):
        (-[WebCoreIconDatabaseBridge _setIconURL:forURL:]):
        (-[WebCoreIconDatabaseBridge _hasIconForIconURL:]):

        * bridge/mac/WebCorePageBridge.mm: Added WebCore's IconDatabase logging channel to the user-prefs check
        (initializeLoggingChannelsIfNecessary):

        * icon/IconDatabase.cpp:  Added stubs and basic SQL usage to create the sqlite DB and respond to WebKit calls
        (WebCore::IconDatabase::IconDatabase):
        (WebCore::IconDatabase::open):
        (WebCore::IconDatabase::close):
        (WebCore::IconDatabase::isValidDatabase):
        (WebCore::IconDatabase::recreateDatabase):
        (WebCore::IconDatabase::setPrivateBrowsingEnabled):
        (WebCore::IconDatabase::iconForURL):
        (WebCore::IconDatabase::iconURLForURL):
        (WebCore::IconDatabase::defaultIcon):
        (WebCore::IconDatabase::retainIconForURL):
        (WebCore::IconDatabase::releaseIconForURL):
        (WebCore::IconDatabase::setIconForIconURL):
        (WebCore::IconDatabase::setHaveNoIconForIconURL):
        (WebCore::IconDatabase::setIconURLForPageURL):
        (WebCore::IconDatabase::hasIconForIconURL):

        * icon/IconDatabase.h:  WebIcon will be an internal class used in IconDatabase but is not complete yet
        (WebCore::WebIcon::getExpiration):
        (WebCore::WebIcon::getTouch):

        * icon/SQLDatabase.cpp:  Added more SQLite convenience methods
        (SQLDatabase::setFullsync):
        (SQLDatabase::setBusyTimeout):
        (SQLDatabase::setBusyHandler):
        * icon/SQLDatabase.h:
        * icon/SQLStatement.cpp:
        (WebCore::SQLStatement::returnsAtLeastOneResult):

        * icon/SQLTransaction.cpp: Added basic commit/rollback support with this simple class
        (SQLTransaction::SQLTransaction):
        (SQLTransaction::~SQLTransaction):
        (SQLTransaction::begin):
        (SQLTransaction::commit):
        (SQLTransaction::rollback):

WebKit:

        Reviewed by Maciej

        Added calls through to the WebCoreIconDatabaseBridge for all the major WebIconDatabase API.  For now these calls
        are wrapped with #ifdef's and are for debugging only.

        * Misc/WebIconDatabase.h:
        * Misc/WebIconDatabase.m:
        (-[NSMutableDictionary _scaleIcon:toSize:]):
        (-[NSMutableDictionary init]):
        (-[NSMutableDictionary iconForURL:withSize:cache:]):
        (-[NSMutableDictionary iconURLForURL:]):
        (-[NSMutableDictionary retainIconForURL:]):
        (-[NSMutableDictionary releaseIconForURL:]):
        (-[WebIconDatabase _setHaveNoIconForIconURL:]):
        (-[WebIconDatabase _setIconURL:forURL:]):
        (-[WebIconDatabase _hasIconForIconURL:]):
        * Misc/WebIconLoader.m:
        (-[WebIconLoader didFinishLoading]):

        * Misc/WebKitLogging.h:  Added a logging channel for WebIconDatabase debugging
        * Misc/WebKitLogging.m:
        (WebKitInitializeLoggingChannelsIfNecessary):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14933 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bridge/mac/WebCoreIconDatabaseBridge.h
WebCore/bridge/mac/WebCoreIconDatabaseBridge.mm
WebCore/bridge/mac/WebCorePageBridge.mm
WebCore/icon/IconDatabase.cpp
WebCore/icon/IconDatabase.h
WebCore/icon/SQLDatabase.cpp
WebCore/icon/SQLDatabase.h
WebCore/icon/SQLStatement.cpp
WebCore/icon/SQLTransaction.cpp [new file with mode: 0644]
WebKit/ChangeLog
WebKit/Misc/WebIconDatabase.h
WebKit/Misc/WebIconDatabase.m
WebKit/Misc/WebIconLoader.m
WebKit/Misc/WebKitLogging.h
WebKit/Misc/WebKitLogging.m

index 0cd97084265c15b6ee3e7c396c3550996379d4a1..53006a089e1f7ef12b4179ea2f61cd4848fd0e90 100644 (file)
@@ -1,3 +1,64 @@
+2006-06-20  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Maciej.
+
+        More changes/additions setting the stage for the major IconDatabase hookup.
+
+        * WebCore.xcodeproj/project.pbxproj:  Added SQLTransaction.cpp
+
+        * bridge/mac/WebCoreIconDatabaseBridge.h: Added call-throughs and translations to pass WebKit DB to WebCore DB
+        * bridge/mac/WebCoreIconDatabaseBridge.mm:
+        (+[WebCoreIconDatabaseBridge sharedBridgeInstance]):
+        (-[WebCoreIconDatabaseBridge setPrivateBrowsingEnabled:]):
+        (-[WebCoreIconDatabaseBridge iconForURL:withSize:]):
+        (-[WebCoreIconDatabaseBridge iconURLForURL:]):
+        (-[WebCoreIconDatabaseBridge defaultIconWithSize:]):
+        (-[WebCoreIconDatabaseBridge retainIconForURL:]):
+        (-[WebCoreIconDatabaseBridge releaseIconForURL:]):
+        (-[WebCoreIconDatabaseBridge _setIconData:forIconURL:]):
+        (-[WebCoreIconDatabaseBridge _setHaveNoIconForIconURL:]):
+        (-[WebCoreIconDatabaseBridge _setIconURL:forURL:]):
+        (-[WebCoreIconDatabaseBridge _hasIconForIconURL:]):
+
+        * bridge/mac/WebCorePageBridge.mm: Added WebCore's IconDatabase logging channel to the user-prefs check
+        (initializeLoggingChannelsIfNecessary):
+
+        * icon/IconDatabase.cpp:  Added stubs and basic SQL usage to create the sqlite DB and respond to WebKit calls
+        (WebCore::IconDatabase::IconDatabase):
+        (WebCore::IconDatabase::open):
+        (WebCore::IconDatabase::close):
+        (WebCore::IconDatabase::isValidDatabase):
+        (WebCore::IconDatabase::recreateDatabase):
+        (WebCore::IconDatabase::setPrivateBrowsingEnabled):
+        (WebCore::IconDatabase::iconForURL):
+        (WebCore::IconDatabase::iconURLForURL):
+        (WebCore::IconDatabase::defaultIcon):
+        (WebCore::IconDatabase::retainIconForURL):
+        (WebCore::IconDatabase::releaseIconForURL):
+        (WebCore::IconDatabase::setIconForIconURL):
+        (WebCore::IconDatabase::setHaveNoIconForIconURL):
+        (WebCore::IconDatabase::setIconURLForPageURL):
+        (WebCore::IconDatabase::hasIconForIconURL):
+
+        * icon/IconDatabase.h:  WebIcon will be an internal class used in IconDatabase but is not complete yet
+        (WebCore::WebIcon::getExpiration):
+        (WebCore::WebIcon::getTouch):
+
+        * icon/SQLDatabase.cpp:  Added more SQLite convenience methods
+        (SQLDatabase::setFullsync):
+        (SQLDatabase::setBusyTimeout):
+        (SQLDatabase::setBusyHandler):
+        * icon/SQLDatabase.h:
+        * icon/SQLStatement.cpp:
+        (WebCore::SQLStatement::returnsAtLeastOneResult):
+
+        * icon/SQLTransaction.cpp: Added basic commit/rollback support with this simple class
+        (SQLTransaction::SQLTransaction):
+        (SQLTransaction::~SQLTransaction):
+        (SQLTransaction::begin):
+        (SQLTransaction::commit):
+        (SQLTransaction::rollback):
+
 2006-06-20  Adele Peterson  <adele@apple.com>
 
         Reviewed by Maciej.
index 25a069f910402d0d56f12cd7a0d3869e96b5f7c0..fc9785c9d66a1de5a8930356ff13681e54eae064 100644 (file)
                51D3EA160A3D24D300BADA35 /* SQLDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D3EA130A3D24D300BADA35 /* SQLDatabase.cpp */; };
                51D3EA170A3D24D300BADA35 /* SQLDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D3EA140A3D24D300BADA35 /* SQLDatabase.h */; };
                51D3EA180A3D24D300BADA35 /* SQLStatement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D3EA150A3D24D300BADA35 /* SQLStatement.cpp */; };
+               51F11E150A48C2920034A24E /* SQLTransaction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51F11E140A48C2920034A24E /* SQLTransaction.cpp */; };
                550A0BC9085F6039007353D6 /* QualifiedName.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 550A0BC7085F6039007353D6 /* QualifiedName.cpp */; };
                550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */ = {isa = PBXBuildFile; fileRef = 550A0BC8085F6039007353D6 /* QualifiedName.h */; };
                650F53DC09D15DDA00C9B0C8 /* CSSGrammar.h in Headers */ = {isa = PBXBuildFile; fileRef = 650F53DB09D15DDA00C9B0C8 /* CSSGrammar.h */; };
                FAE04190097596C9000540BE /* SVGImageLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE0418E097596C9000540BE /* SVGImageLoader.h */; };
 /* End PBXBuildFile section */
 
-/* Begin PBXBuildStyle section */
-               BCC3C56B0A44C45A00370EAD /* Development */ = {
-                       isa = PBXBuildStyle;
-                       buildSettings = {
-                               COPY_PHASE_STRIP = NO;
-                       };
-                       name = Development;
-               };
-               BCC3C56C0A44C45A00370EAD /* Deployment */ = {
-                       isa = PBXBuildStyle;
-                       buildSettings = {
-                               COPY_PHASE_STRIP = YES;
-                       };
-                       name = Deployment;
-               };
-/* End PBXBuildStyle section */
-
 /* Begin PBXContainerItemProxy section */
                DD041FF009D9E3250010AF2A /* PBXContainerItemProxy */ = {
                        isa = PBXContainerItemProxy;
                51D3EA130A3D24D300BADA35 /* SQLDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SQLDatabase.cpp; sourceTree = "<group>"; };
                51D3EA140A3D24D300BADA35 /* SQLDatabase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SQLDatabase.h; sourceTree = "<group>"; };
                51D3EA150A3D24D300BADA35 /* SQLStatement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SQLStatement.cpp; sourceTree = "<group>"; };
+               51F11E140A48C2920034A24E /* SQLTransaction.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SQLTransaction.cpp; sourceTree = "<group>"; };
                51F6A3D50663BF04004D2919 /* HTMLCanvasElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLCanvasElement.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                51F6A3D60663BF04004D2919 /* HTMLCanvasElement.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = HTMLCanvasElement.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                550A0BC7085F6039007353D6 /* QualifiedName.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = QualifiedName.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                                51D3EA130A3D24D300BADA35 /* SQLDatabase.cpp */,
                                51D3EA140A3D24D300BADA35 /* SQLDatabase.h */,
                                51D3EA150A3D24D300BADA35 /* SQLStatement.cpp */,
+                               51F11E140A48C2920034A24E /* SQLTransaction.cpp */,
                        );
                        path = icon;
                        sourceTree = "<group>";
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
-                       buildSettings = {
-                       };
-                       buildStyles = (
-                               BCC3C56B0A44C45A00370EAD /* Development */,
-                               BCC3C56C0A44C45A00370EAD /* Deployment */,
-                       );
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                                85031B4D0A44EFC700F992E0 /* UIEvent.cpp in Sources */,
                                85031B500A44EFC700F992E0 /* WheelEvent.cpp in Sources */,
                                ABE7B5230A489F830031881C /* DeprecatedRenderSelect.cpp in Sources */,
+                               51F11E150A48C2920034A24E /* SQLTransaction.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 8c815278b5658a4b408681db7732fd4ef1b44dc6..4def5614e331229df4a3e024f62d4051f64dab5f 100644 (file)
  */
 
 #ifdef __cplusplus
-namespace WebCore { class IconDatabase; }
+namespace WebCore { 
+class IconDatabase; 
+class Image;
+} 
 typedef WebCore::IconDatabase WebCoreIconDatabase;
 #else
 @class WebCoreIconDatabase;
@@ -34,9 +37,26 @@ typedef WebCore::IconDatabase WebCoreIconDatabase;
 {
     WebCoreIconDatabase *_iconDB;
 }
++ (WebCoreIconDatabaseBridge *)sharedBridgeInstance;
+
 - (BOOL)openSharedDatabaseWithPath:(NSString *)path;
 - (void)closeSharedDatabase;
 - (BOOL)isOpen;
+
+- (NSImage *)iconForURL:(NSString *)url withSize:(NSSize)size;
+- (NSString *)iconURLForURL:(NSString *)url;
+- (NSImage *)defaultIconWithSize:(NSSize)size;
+- (void)retainIconForURL:(NSString *)url;
+- (void)releaseIconForURL:(NSString *)url;
+- (void)setPrivateBrowsingEnabled:(BOOL)flag;
+
+
+- (void)_setIconData:(NSData *)data forIconURL:(NSString *)iconURL;
+- (void)_setHaveNoIconForIconURL:(NSString *)iconURL;
+- (void)_setIconURL:(NSString *)iconURL forURL:(NSString *)url;
+- (BOOL)_hasIconForIconURL:(NSString *)iconURL;
+
+
 @end
 
 
index dd564e611f1c1bbfd89b4d7baf70ea4f2952439c..7a25a73155fe35e55993e01702b5091938344df6 100644 (file)
 
 #import "Logging.h"
 #import "IconDatabase.h"
+#import "Image.h"
 #import "PlatformString.h"
 
 using WebCore::IconDatabase;
 using WebCore::String;
+using WebCore::Image;
+
+static WebCoreIconDatabaseBridge *_sharedBridgeInstance = nil;
 
 @implementation WebCoreIconDatabaseBridge
 
+
++ (WebCoreIconDatabaseBridge *)sharedBridgeInstance;
+{
+    if (_sharedBridgeInstance) 
+        return _sharedBridgeInstance;
+        
+    return _sharedBridgeInstance = [[WebCoreIconDatabaseBridge alloc] init];
+}
+
 - (BOOL)openSharedDatabaseWithPath:(NSString *)path;
 {
     assert(path);
@@ -59,4 +72,95 @@ using WebCore::String;
 {
     return _iconDB != 0;
 }
+
+- (void)setPrivateBrowsingEnabled:(BOOL)flag;
+{
+    if (_iconDB)
+        _iconDB->setPrivateBrowsingEnabled(flag);
+}
+
+- (NSImage *)iconForURL:(NSString *)url withSize:(NSSize)size;
+{
+    ASSERT(_iconDB);
+    ASSERT(url);
+    ASSERT(size.width);
+    ASSERT(size.height);
+    
+    Image* image = _iconDB->iconForURL(String(url), IntSize(size));
+    if (image) 
+        return image->getNSImage();
+    return nil;
+}
+
+- (NSString *)iconURLForURL:(NSString *)url;
+{
+    ASSERT(_iconDB);
+    ASSERT(url);
+    
+    String iconURL = _iconDB->iconURLForURL(String(url));
+    return (NSString*)iconURL;
+}
+
+- (NSImage *)defaultIconWithSize:(NSSize)size;
+{
+    ASSERT(_iconDB);
+    ASSERT(size.width);
+    ASSERT(size.height);
+    
+    Image* image = _iconDB->defaultIcon(IntSize(size));
+    if (image)
+        return image->getNSImage();
+    return nil;
+}
+
+- (void)retainIconForURL:(NSString *)url;
+{
+    ASSERT(_iconDB);
+    ASSERT(url);
+    _iconDB->retainIconForURL(String(url));
+}
+
+- (void)releaseIconForURL:(NSString *)url;
+{
+    ASSERT(_iconDB);
+    ASSERT(url);
+    _iconDB->releaseIconForURL(String(url));
+}
+
+- (void)_setIconData:(NSData *)data forIconURL:(NSString *)iconURL;
+{
+    ASSERT(_iconDB);
+    ASSERT(data);
+    ASSERT(iconURL);
+    
+    Image* image = new Image();
+    image->setNativeData((CFDataRef)data, true);
+    _iconDB->setIconForIconURL(image, String(iconURL));
+}
+
+- (void)_setHaveNoIconForIconURL:(NSString *)iconURL;
+{
+    ASSERT(_iconDB);
+    ASSERT(iconURL);
+    
+    _iconDB->setHaveNoIconForIconURL(String(iconURL));
+}
+
+- (void)_setIconURL:(NSString *)iconURL forURL:(NSString *)url;
+{
+    ASSERT(_iconDB);
+    ASSERT(iconURL);
+    ASSERT(url);
+    
+    _iconDB->setIconURLForPageURL(String(iconURL), String(url));
+}
+
+- (BOOL)_hasIconForIconURL:(NSString *)iconURL;
+{
+    ASSERT(_iconDB);
+    ASSERT(iconURL);
+    
+    return _iconDB->hasIconForIconURL(String(iconURL));
+}
+
 @end
index 444d7dc6de7d5c79443b05a57bdd1f945d9aab8a..2ea73feb479e291170b39fdddf7f6c8a0095c8c7 100644 (file)
@@ -62,6 +62,7 @@ static void initializeLoggingChannelsIfNecessary()
     initializeLogChannel(LogEvents);
     initializeLogChannel(LogEditing);
     initializeLogChannel(LogTextConversion);
+    initializeLogChannel(LogIconDatabase);
 }
 
 - (id)init
index 10cebb5e3341102e5e7de770dba5011421cb081b..5cdf5fb63ff847aa9290afc8a7d26b0b46419189 100644 (file)
@@ -47,8 +47,9 @@ IconDatabase* IconDatabase::sharedIconDatabase()
 }
 
 IconDatabase::IconDatabase()
+    : m_privateBrowsingEnabled(false)
 {
-
+    close();
 }
 
 bool IconDatabase::open(const String& databasePath)
@@ -61,28 +62,30 @@ bool IconDatabase::open(const String& databasePath)
     }
     
     if (!isValidDatabase()) {
-        LOG(IconDatabase, "%s is in an invalid state - reconstructing", dbFilename.ascii().data());
+        LOG(IconDatabase, "%s is missing or in an invalid state - reconstructing", dbFilename.ascii().data());
         clearDatabase();
         recreateDatabase();
     }
     
+    m_db.setFullsync(false);
     return isOpen();
 }
 
 void IconDatabase::close()
 {
-    //TODO - sync any cached info before close();
+    //TODO - sync any cached info before m_db.close();
     m_db.close();
 }
 
 
 bool IconDatabase::isValidDatabase()
 {
-    if (!m_db.tableExists("IconDatabaseInfo")) {
+    if (!m_db.tableExists("Icon") || !m_db.tableExists("PageURL") || !m_db.tableExists("IconResource") || !m_db.tableExists("IconDatabaseInfo")) {
         return false;
     }
     
     String query = "SELECT value FROM IconDatabaseInfo WHERE key = 'Version';";
+    
     SQLStatement sql(m_db, query);
     sql.prepare();
     sql.step();
@@ -90,10 +93,7 @@ bool IconDatabase::isValidDatabase()
         LOG(IconDatabase, "DB version is not found or below expected valid version");
         return false;
     }
-    
-    if (!m_db.tableExists("Icon") || !m_db.tableExists("PageURL") || !m_db.tableExists("IconResource")) {
-        return false;
-    }
+
     return true;
 }
 
@@ -115,7 +115,7 @@ void IconDatabase::clearDatabase()
 
 void IconDatabase::recreateDatabase()
 {
-    if (!m_db.executeCommand("CREATE TABLE IconDatabaseInfo (key varchar NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value integer NOT NULL ON CONFLICT FAIL);")) {
+    if (!m_db.executeCommand("CREATE TABLE IconDatabaseInfo (key varchar NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value NOT NULL ON CONFLICT FAIL);")) {
         LOG_ERROR("Could not create IconDatabaseInfo table in icon.db (%i)\n%s", m_db.lastError(), m_db.lastErrorMsg());
         m_db.close();
         return;
@@ -130,7 +130,7 @@ void IconDatabase::recreateDatabase()
         m_db.close();
         return;
     }
-    if (!m_db.executeCommand("CREATE TABLE Icon (id integer PRIMARY KEY ON CONFLICT FAIL,url varchar NOT NULL UNIQUE ON CONFLICT FAIL);")) {
+    if (!m_db.executeCommand("CREATE TABLE Icon (iconid INTEGER PRIMARY KEY AUTOINCREMENT, url varchar NOT NULL UNIQUE ON CONFLICT FAIL);")) {
         LOG_ERROR("Could not create Icon table in icon.db (%i)\n%s", m_db.lastError(), m_db.lastErrorMsg());
         m_db.close();
         return;
@@ -140,14 +140,62 @@ void IconDatabase::recreateDatabase()
         m_db.close();
         return;
     }
-    
-    
 }    
 
+void IconDatabase::setPrivateBrowsingEnabled(bool flag)
+{
+    //FIXME - set/clear private browsing caches
+    m_privateBrowsingEnabled = flag;   
+}
+
+Image* IconDatabase::iconForURL(const String& url, const IntSize& size, bool cache)
+{
+    return 0;
+}
+
+String IconDatabase::iconURLForURL(const String& url)
+{
+    return "(null)";
+}
+
+Image* IconDatabase::defaultIcon(const IntSize& size)
+{
+    return 0;
+}
+
+void IconDatabase::retainIconForURL(const String& url)
+{
+
+}
+
+void IconDatabase::releaseIconForURL(const String& url)
+{
+
+}
+
+void IconDatabase::setIconForIconURL(Image* icon, const String& url)
+{
+
+}
+
+void IconDatabase::setHaveNoIconForIconURL(const String& iconURL)
+{
+
+}
+
+void IconDatabase::setIconURLForPageURL(const String& iconURL, const String& pageURL)
+{
+
+}
+
+bool IconDatabase::hasIconForIconURL(const String& url)
+{
+    return false;
+}
+
 IconDatabase::~IconDatabase()
 {
     m_db.close();
 }
 
-} //namespace WebCore
-
+} //namespace WebCore
\ No newline at end of file
index 96a9e22ea08438a5b512cbdaccd1e30189307058..dbb2be1424d4ea31001b8a03c1a5a260e82e2918 100644 (file)
 
 #include "config.h"
 
+#include "IntSize.h"
 #include "PlatformString.h"
 #include "SQLDatabase.h"
 
+#include <wtf/HashMap.h>
+
 namespace WebCore { 
 
+class Image;
+
+class WebIcon {
+public:
+    WebIcon();
+    ~WebIcon();
+    
+    void resetExpiration(time_t newExpiration = 0);
+    time_t getExpiration() { return m_expire; }
+    
+    //getImage() inherently touch()es the icon
+    Image* getImage();
+    
+    //incase a user wants to manually touch() the icon
+    void touch();
+    time_t getTouch() { return m_touch; }
+        
+private:
+    time_t m_touch;
+    time_t m_expire;
+    Image* m_image;
+};
+
+
 class IconDatabase
 {
+//TODO - WebIcon is never to be used outside of IconDatabase
+friend class WebIcon;
 public:
     static IconDatabase* sharedIconDatabase();
     
     bool open(const String& path);
     bool isOpen() { return m_db.isOpen(); }
     void close();
+
+    Image* iconForURL(const String&, const IntSize&, bool cache = true);
+    String iconURLForURL(const String&);
+    Image* defaultIcon(const IntSize&);
+
+    void retainIconForURL(const String&);
+    void releaseIconForURL(const String&);
+    
+    void setPrivateBrowsingEnabled(bool flag);
+
+    bool hasIconForIconURL(const String&);
     
-    static const int currentDatabaseVersion;
+    //TODO - The following 3 methods were considered private in WebKit - analyze the impact of making them
+    //public here in WebCore - I don't see any real badness with doing that...  afterall if Chuck Norris wants to muck
+    //around with the icons in his database, he's going to anyway
+    void setIconForIconURL(Image*, const String&);
+    void setHaveNoIconForIconURL(const String&);
+    void setIconURLForPageURL(const String& iconURL, const String& pageURL);
+
+    static const int currentDatabaseVersion;    
 private:
     IconDatabase();
     ~IconDatabase();
     
+    void removeAllIcons();
+    bool isEnabled();
+    
     bool isValidDatabase();
     void clearDatabase();
     void recreateDatabase();
     
     static IconDatabase* m_sharedInstance;
+    static const int DefaultCachedPageCount;
     
     SQLDatabase m_db;
+    bool m_privateBrowsingEnabled;
+    
+    typedef WTF::HashMap<String, WebIcon*> WebIconMap;
+    WebIconMap m_webIcons;
 };
 
 } //namespace WebCore
index c8190b2c759b4728d31580f2f1275067da422caf..27aa6e07b9b21f36c5e46e35f7934e97cc6692c4 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "SQLDatabase.h"
+#include "Logging.h"
 
 using namespace WebCore;
 
@@ -60,6 +61,30 @@ void SQLDatabase::close()
     }
 }
 
+void SQLDatabase::setFullsync(bool fsync) 
+{
+    if (fsync) 
+        SQLStatement(*this,"PRAGMA fullfsync = 1;").executeCommand();
+    else
+        SQLStatement(*this,"PRAGMA fullfsync = 0;").executeCommand();
+}
+
+void SQLDatabase::setBusyTimeout(int ms)
+{
+    if (m_db)
+        sqlite3_busy_timeout(m_db, ms);
+    else
+        LOG(IconDatabase, "BusyTimeout set on non-open database");
+}
+
+void SQLDatabase::setBusyHandler(int(*handler)(void*, int))
+{
+    if (m_db)
+        sqlite3_busy_handler(m_db, handler, NULL);
+    else
+        LOG(IconDatabase, "Busy handler set on non-open database");
+}
+
 bool SQLDatabase::executeCommand(const String& sql)
 {
     return SQLStatement(*this,sql).executeCommand();
index b75e1297efb13c9979a7daa32fa8e86ec0f2ab5a..f25f339324678d8e96b81ff5bfd067051d25ed86 100644 (file)
@@ -50,8 +50,12 @@ public:
 
     bool executeCommand(const String&);
     bool tableExists(const String&);
+
+    void setBusyTimeout(int ms);
+    void setBusyHandler(int(*)(void*, int));
     
     //TODO - add pragma and sqlite_master accessors here
+    void setFullsync(bool);
     
     int lastError() { return m_db ? sqlite3_errcode(m_db) : SQLITE_ERROR; }
     const char* lastErrorMsg() { return sqlite3_errmsg(m_db); }
@@ -63,6 +67,21 @@ private:
     
 }; //class SQLDatabase
 
+class SQLTransaction : public Noncopyable
+{
+public:
+    SQLTransaction(SQLDatabase& db, bool start = false);
+    ~SQLTransaction();
+    
+    void begin();
+    void commit();
+    void rollback();
+    
+private:
+    SQLDatabase& m_db;
+    bool m_began;
+
+};
 
 class SQLStatement : public Noncopyable
 {
@@ -80,10 +99,15 @@ public:
     int reset();
     
     //prepares, steps, and finalizes the query.
-    //returns true if all 3 steps succeed with step() returnsing SQLITE_DONE
+    //returns true if all 3 steps succeed with step() returning SQLITE_DONE
     //returns false otherwise  
     bool executeCommand();
     
+    //prepares, steps, and finalizes.  
+    //returns true is step() returns SQLITE_ROW
+    //returns false otherwise
+    bool returnsAtLeastOneResult();
+    
     //Returns -1 on last-step failing.  Otherwise, returns number of rows
     //returned in the last step()
     int columnCount();
index d50912436f76c5ffdbd7f595cc8ebdef688877e6..ee2b02082f40acc80b090500e299fa899ab83b4a 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "SQLDatabase.h"
 
-#include <wtf/Assertions.h>
+#include <wtf/assertions.h>
 #include "Logging.h"
 
 namespace WebCore {
@@ -97,6 +97,20 @@ bool SQLStatement::executeCommand()
     return true;
 }
 
+bool SQLStatement::returnsAtLeastOneResult()
+{
+    if (!isPrepared())
+        if (prepare() != SQLITE_OK)
+            return false;
+    if (step() != SQLITE_ROW) {
+        finalize();
+        return false;
+    }
+    finalize();
+    return true;
+
+}
+
 int SQLStatement::bindBlob(int index, const void* blob, int size, bool copy)
 {
     ASSERT(blob);
diff --git a/WebCore/icon/SQLTransaction.cpp b/WebCore/icon/SQLTransaction.cpp
new file mode 100644 (file)
index 0000000..d57df83
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "SQLDatabase.h"
+
+using namespace WebCore;
+
+
+SQLTransaction::SQLTransaction(SQLDatabase& db, bool start)
+    : m_db(db)
+    , m_began(false)
+{
+    if (start)
+        begin();
+}
+
+SQLTransaction::~SQLTransaction()
+{
+    if (m_began) 
+        rollback();
+}
+    
+void SQLTransaction::begin()
+{
+    if (!m_began)
+        m_began = m_db.executeCommand("BEGIN;");
+}
+
+void SQLTransaction::commit()
+{
+    if (m_began) {
+        if (m_db.executeCommand("COMMIT;"))
+            m_began = false;
+    }
+}
+
+void SQLTransaction::rollback()
+{
+    if (m_began)
+        m_db.executeCommand("ROLLBACK;");
+}
+    
+
+
+
index 735cffc5b5cffdfc20c475643db92a9f36fbaebc..425e3b1663da4df38edf29f028d6d3a32798b44b 100644 (file)
@@ -1,3 +1,28 @@
+2006-06-20  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Maciej
+
+        Added calls through to the WebCoreIconDatabaseBridge for all the major WebIconDatabase API.  For now these calls
+        are wrapped with #ifdef's and are for debugging only.
+
+        * Misc/WebIconDatabase.h:
+        * Misc/WebIconDatabase.m:
+        (-[NSMutableDictionary _scaleIcon:toSize:]):
+        (-[NSMutableDictionary init]):
+        (-[NSMutableDictionary iconForURL:withSize:cache:]):
+        (-[NSMutableDictionary iconURLForURL:]):
+        (-[NSMutableDictionary retainIconForURL:]):
+        (-[NSMutableDictionary releaseIconForURL:]):
+        (-[WebIconDatabase _setHaveNoIconForIconURL:]):
+        (-[WebIconDatabase _setIconURL:forURL:]):
+        (-[WebIconDatabase _hasIconForIconURL:]):
+        * Misc/WebIconLoader.m:
+        (-[WebIconLoader didFinishLoading]):
+
+        * Misc/WebKitLogging.h:  Added a logging channel for WebIconDatabase debugging
+        * Misc/WebKitLogging.m:
+        (WebKitInitializeLoggingChannelsIfNecessary):
+
 2006-06-20  Adele Peterson  <adele@apple.com>
 
         Reviewed by Tim Hatcher.
index fcd76c98ca48cab9df8a56c2c30519edd41fbdfb..8c9f8ca74331816839c2bad9793644c459f8c1a0 100644 (file)
@@ -138,3 +138,5 @@ extern NSSize WebIconLargeSize;  // 128 x 128
 - (void)allowDatabaseCleanup;
 
 @end
+
+
index 5241cdc974aede15e87fab265123b2fb96f35414..4cb550bc380d17267133bab246bba4f7f843e588 100644 (file)
@@ -25,7 +25,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 #import <WebKit/WebIconDatabase.h>
 
 #import <WebKit/WebIconDatabasePrivate.h>
@@ -85,7 +84,6 @@ NSSize WebIconLargeSize = {128, 128};
 - (void)_scaleIcon:(NSImage *)icon toSize:(NSSize)size;
 @end
 
-
 @implementation WebIconDatabase
 
 + (WebIconDatabase *)sharedIconDatabase
@@ -105,6 +103,7 @@ NSSize WebIconLargeSize = {128, 128};
     return database;
 }
 
+
 - init
 {
     [super init];
@@ -122,7 +121,7 @@ NSSize WebIconLargeSize = {128, 128};
     [self _createFileDatabase];
     [self _loadIconDictionaries];
 
-    _private->databaseBridge = [[WebCoreIconDatabaseBridge alloc] init];
+    _private->databaseBridge = [WebCoreIconDatabaseBridge sharedBridgeInstance];
     if (_private->databaseBridge) {
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         NSString *databaseDirectory = [defaults objectForKey:WebIconDatabaseDirectoryDefaultsKey];
@@ -166,7 +165,7 @@ NSSize WebIconLargeSize = {128, 128};
 {
     ASSERT(size.width);
     ASSERT(size.height);
-    
+
     if (!URL || ![self _isEnabled])
         return [self defaultIconWithSize:size];
 
@@ -179,6 +178,18 @@ NSSize WebIconLargeSize = {128, 128};
         return [self defaultIconWithSize:size];
 
     NSMutableDictionary *icons = [self _iconsForIconURLString:iconURLString];
+#ifdef ICONDEBUG
+    NSImage* image = [_private->databaseBridge iconForURL:URL withSize:size];
+    if (image)
+        LOG(IconDatabase, "NewDB has image for %@", URL);
+    else
+        LOG(IconDatabase, "NewDB has no image for %@", URL);
+    if (icons)
+        LOG(IconDatabase, "OldDB has at least 1 image for %@", URL);
+    else
+        LOG(IconDatabase, "OldDB has no image for %@", URL);
+#endif
+
     if (!icons) {
        if (![_private->iconURLsWithNoIcons containsObject:iconURLString]) {
            // We used to have this icon, but don't have it anymore for some reason. (Bug? Deleted from
@@ -201,6 +212,11 @@ NSSize WebIconLargeSize = {128, 128};
 {
     if (![self _isEnabled])
         return nil;
+#ifdef ICONDEBUG
+    NSString* iconurl = [_private->databaseBridge iconURLForURL:URL];
+    LOG(IconDatabase, "NewDB has IconURL %@ for PageURL %@", iconurl, URL);
+    LOG(IconDatabase, "OldDB has IconURL %@ for PageURL %@", [_private->pageURLToIconURL objectForKey:URL], URL);
+#endif
     return URL ? [_private->pageURLToIconURL objectForKey:URL] : nil;
 }
 
@@ -225,21 +241,27 @@ NSSize WebIconLargeSize = {128, 128};
 - (void)retainIconForURL:(NSString *)URL
 {
     ASSERT(URL);
-    
     if (![self _isEnabled])
         return;
     
     WebNSUInteger retainCount = (WebNSUInteger)(void *)CFDictionaryGetValue(_private->pageURLToRetainCount, URL);
     CFDictionarySetValue(_private->pageURLToRetainCount, URL, (void *)(retainCount + 1));
+#ifdef ICONDEBUG
+    [_private->databaseBridge retainIconForURL:URL];
+    LOG(IconDatabase, "NewDB - Icon retained for URL %@", URL);
+#endif
 }
 
 - (void)releaseIconForURL:(NSString *)pageURL
 {
     ASSERT(pageURL);
-    
     if (![self _isEnabled])
         return;
-    
+#ifdef ICONDEBUG
+    [_private->databaseBridge releaseIconForURL:pageURL];
+    LOG(IconDatabase, "NewDB - Icon released for URL %@", pageURL);
+#endif
+
     WebNSUInteger retainCount = (WebNSUInteger)(void *)CFDictionaryGetValue(_private->pageURLToRetainCount, pageURL);
     
     if (retainCount <= 0) {
@@ -389,6 +411,11 @@ NSSize WebIconLargeSize = {128, 128};
     ASSERT(iconURL);
     ASSERT([self _isEnabled]);
 
+#ifdef ICONDEBUG
+    [_private->databaseBridge _setHaveNoIconForIconURL:iconURL];
+    LOG(IconDatabase, "NewDB - Set haveNoIcon for IconURL %@", iconURL);
+#endif
+
     [_private->iconURLsWithNoIcons addObject:iconURL];
     
     // Don't update any icon information on disk during private browsing. Remember which icons have been
@@ -412,6 +439,11 @@ NSSize WebIconLargeSize = {128, 128};
     ASSERT([self _isEnabled]);
     ASSERT([self _hasIconForIconURL:iconURL]);
     ASSERT(_private->pageURLToIconURL);
+    
+#ifdef ICONDEBUG
+    [_private->databaseBridge _setIconURL:iconURL forURL:URL];
+    LOG(IconDatabase, "NewDB - Icon URL %@ set for URL %@", iconURL, URL);
+#endif
 
     if ([[_private->pageURLToIconURL objectForKey:URL] isEqualToString:iconURL]) {
         // Don't do any work if the icon URL is already bound to the site URL
@@ -440,7 +472,22 @@ NSSize WebIconLargeSize = {128, 128};
 - (BOOL)_hasIconForIconURL:(NSString *)iconURL;
 {
     ASSERT([self _isEnabled]);
-    
+
+#ifdef ICONDEBUG
+    BOOL result = [_private->databaseBridge _hasIconForIconURL:iconURL];
+    if (result)
+        LOG(IconDatabase, "NewDB - Has icon for IconURL %@", iconURL);
+    else
+        LOG(IconDatabase, "NewDB - Does NOT have icon for IconURL %@", iconURL);
+    if (([_private->iconURLToIcons objectForKey:iconURL] ||
+         [_private->iconURLsWithNoIcons containsObject:iconURL] ||
+         [_private->iconsOnDiskWithURLs containsObject:iconURL]) &&
+         [self _totalRetainCountForIconURLString:iconURL] > 0)
+        LOG(IconDatabase, "OldDB - Has icon for IconURL %@", iconURL);
+    else
+        LOG(IconDatabase, "NewDB - Does NOT have icon for IconURL %@", iconURL);
+#endif
+
     return (([_private->iconURLToIcons objectForKey:iconURL] ||
             [_private->iconURLsWithNoIcons containsObject:iconURL] ||
              [_private->iconsOnDiskWithURLs containsObject:iconURL]) &&
index 105604f0271db2a75f3a74c2f0653994811b12ca..a66d858e9d1ac2739b42c87a519c9e76b6a4d53d 100644 (file)
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 #import <WebKit/WebIconLoader.h>
 
 #import <JavaScriptCore/Assertions.h>
+#import <WebCore/WebCoreIconDatabaseBridge.h>
 #import <WebKit/WebIconDatabase.h>
 #import <WebKit/WebIconDatabasePrivate.h>
+#import <WebKit/WebKitLogging.h>
+
 #import <WebKit/WebNSURLExtras.h>
 
 @interface WebIconLoaderPrivate : NSObject
 - (void)didFinishLoading
 {
     NSImage *icon;
+    
+    #ifdef ICONDEBUG
+    NSData *_data = [self resourceData];
+    if (_data) {
+        [[WebCoreIconDatabaseBridge sharedBridgeInstance] _setIconData:_data forIconURL:[[self URL] _web_originalDataAsString]];
+        LOG(IconDatabase, "NewDB - Icon data set for URL %@", [[self URL] _web_originalDataAsString]);
+    }
+    #endif
+    
     NS_DURING
         NSData *data = [self resourceData];
         icon = [data length] > 0 ? [[NSImage alloc] initWithData:data] : nil;
index 4f51d28a1e191979c67dab0e0dd7c5bb7d165bc7..6868e460211f66336f96b527736bf93576abebda 100644 (file)
@@ -54,5 +54,6 @@ extern WTFLogChannel WebKitLogLiveConnect;
 extern WTFLogChannel WebKitLogBackForward;
 extern WTFLogChannel WebKitLogProgress;
 extern WTFLogChannel WebKitLogPluginEvents;
+extern WTFLogChannel WebKitLogIconDatabase;
 
 void WebKitInitializeLoggingChannelsIfNecessary(void);
index 05bac1cc306c7ea439d26077136693738b593a69..dc09c9d18c6b46bda62c575e38d47b477c668eb9 100644 (file)
@@ -50,6 +50,7 @@ WTFLogChannel WebKitLogLiveConnect =            { 0x08000000, "WebKitLogLevel",
 WTFLogChannel WebKitLogBackForward =            { 0x10000000, "WebKitLogLevel", WTFLogChannelOff };
 WTFLogChannel WebKitLogProgress =               { 0x20000000, "WebKitLogLevel", WTFLogChannelOff };
 WTFLogChannel WebKitLogPluginEvents =           { 0x40000000, "WebKitLogLevel", WTFLogChannelOff };
+WTFLogChannel WebKitLogIconDatabase =           { 0x80000000, "WebKitLogLevel", WTFLogChannelOff };
 
 static void initializeLogChannel(WTFLogChannel *channel)
 {
@@ -93,5 +94,6 @@ void WebKitInitializeLoggingChannelsIfNecessary()
     initializeLogChannel(&WebKitLogBackForward);
     initializeLogChannel(&WebKitLogProgress);
     initializeLogChannel(&WebKitLogPluginEvents);
+    initializeLogChannel(&WebKitLogIconDatabase);
 }