WebCore:
authorbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2006 23:32:07 +0000 (23:32 +0000)
committerbeidson <beidson@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Aug 2006 23:32:07 +0000 (23:32 +0000)
        Reviewed by John

        <rdar://problem/4707718> - Instead of faking the user out with an in-memory icon database if their
        ~/Library/Safari/Icons is unwritable, we'll actually fail to open the icon database and the app will
        run as if it was disabled via a preference.
        Also took the opportunity to change some ASSERTS() to reasonable behavior

        * bridge/mac/WebCoreIconDatabaseBridge.mm:
        (-[WebCoreIconDatabaseBridge openSharedDatabaseWithPath:]): NSLog on failure so the user has a chance to figure
          out there's a problem.
        (-[WebCoreIconDatabaseBridge closeSharedDatabase]):
        (-[WebCoreIconDatabaseBridge iconForPageURL:withSize:]): From here on, just replaced ASSERTS() with reasonable behavior
        (-[WebCoreIconDatabaseBridge iconURLForPageURL:]):
        (-[WebCoreIconDatabaseBridge defaultIconWithSize:]):
        (-[WebCoreIconDatabaseBridge retainIconForURL:]):
        (-[WebCoreIconDatabaseBridge releaseIconForURL:]):
        (-[WebCoreIconDatabaseBridge _setIconData:forIconURL:]):
        (-[WebCoreIconDatabaseBridge _setHaveNoIconForIconURL:]):
        (-[WebCoreIconDatabaseBridge _setIconURL:forPageURL:]):
        (-[WebCoreIconDatabaseBridge _hasEntryForIconURL:]):
        * loader/icon/IconDatabase.cpp:
        (WebCore::IconDatabase::open): If we fail to open, return false
        (WebCore::IconDatabase::~IconDatabase): cleanup better
        * loader/icon/IconDatabase.h:

WebKit:

        Reviewed by John

        <rdar://problem/4707718> Change behavior so if the WebCore::IconDatabase can't open, WebKit releases the bridge and
        continues on as if the IconDatabase is disabled.

        * Misc/WebIconDatabase.m:
        (-[WebIconDatabase init]): Release the bridge on failure to open
        * WebCoreSupport/WebIconDatabaseBridge.m:
        (+[WebIconDatabaseBridge sharedBridgeInstance]): Moved static shared instance out as a global
        (-[WebIconDatabaseBridge dealloc]): Clear pointer to the shared instance

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

WebCore/ChangeLog
WebCore/bridge/mac/WebCoreIconDatabaseBridge.mm
WebCore/loader/icon/IconDatabase.cpp
WebCore/loader/icon/IconDatabase.h
WebKit/ChangeLog
WebKit/Misc/WebIconDatabase.m
WebKit/WebCoreSupport/WebIconDatabaseBridge.m

index 896f91595cdefa24c117bcd2cdac110613d1d548..8064cb94c27f49e82e42bf702ccbaeafd5b49ab3 100644 (file)
@@ -1,3 +1,30 @@
+2006-08-30  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by John
+
+        <rdar://problem/4707718> - Instead of faking the user out with an in-memory icon database if their 
+        ~/Library/Safari/Icons is unwritable, we'll actually fail to open the icon database and the app will
+        run as if it was disabled via a preference.
+        Also took the opportunity to change some ASSERTS() to reasonable behavior
+
+        * bridge/mac/WebCoreIconDatabaseBridge.mm:
+        (-[WebCoreIconDatabaseBridge openSharedDatabaseWithPath:]): NSLog on failure so the user has a chance to figure 
+          out there's a problem.
+        (-[WebCoreIconDatabaseBridge closeSharedDatabase]):
+        (-[WebCoreIconDatabaseBridge iconForPageURL:withSize:]): From here on, just replaced ASSERTS() with reasonable behavior
+        (-[WebCoreIconDatabaseBridge iconURLForPageURL:]):
+        (-[WebCoreIconDatabaseBridge defaultIconWithSize:]):
+        (-[WebCoreIconDatabaseBridge retainIconForURL:]):
+        (-[WebCoreIconDatabaseBridge releaseIconForURL:]):
+        (-[WebCoreIconDatabaseBridge _setIconData:forIconURL:]):
+        (-[WebCoreIconDatabaseBridge _setHaveNoIconForIconURL:]):
+        (-[WebCoreIconDatabaseBridge _setIconURL:forPageURL:]):
+        (-[WebCoreIconDatabaseBridge _hasEntryForIconURL:]):
+        * loader/icon/IconDatabase.cpp:
+        (WebCore::IconDatabase::open): If we fail to open, return false 
+        (WebCore::IconDatabase::~IconDatabase): cleanup better
+        * loader/icon/IconDatabase.h:
+
 2006-08-30  David Harrison  <harrison@apple.com>
 
         Reviewed by John Sullivan.
index 047eb25d341942a9ad8bef4190ccf68e1128b4dd..54eba6d2059311d0360bbdedfd7c95421747d0fb 100644 (file)
@@ -50,17 +50,20 @@ void WebCore::IconDatabase::loadIconFromURL(const String& url)
     _iconDB = IconDatabase::sharedIconDatabase();
     if (_iconDB) {
         _iconDB->open((String([path stringByStandardizingPath])));
-        return _iconDB->isOpen() ? YES : NO;
+        if (!_iconDB->isOpen()) {
+            [self closeSharedDatabase];
+            NSLog(@"Unable to open icon database at %@ - Check your write permissions at that path.  Icon database will be disabled for this browsing session", path);
+            return NO;
+        }
+        return YES;
     }
     return NO;
 }
 
 - (void)closeSharedDatabase
 {
-    if (_iconDB) {
-        _iconDB->close();
-        _iconDB = 0;
-    }
+    delete _iconDB;
+    _iconDB = 0;
 }
 
 - (BOOL)isOpen
@@ -99,7 +102,9 @@ void WebCore::IconDatabase::loadIconFromURL(const String& url)
 
 - (NSImage *)iconForPageURL:(NSString *)url withSize:(NSSize)size
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return nil;
+        
     ASSERT(url);
     ASSERT(size.width);
     ASSERT(size.height);
@@ -127,7 +132,8 @@ void WebCore::IconDatabase::loadIconFromURL(const String& url)
 
 - (NSString *)iconURLForPageURL:(NSString *)url
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return nil;
     ASSERT(url);
     
     String iconURL = _iconDB->iconURLForPageURL(String(url));
@@ -136,7 +142,8 @@ void WebCore::IconDatabase::loadIconFromURL(const String& url)
 
 - (NSImage *)defaultIconWithSize:(NSSize)size
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return nil;
     ASSERT(size.width);
     ASSERT(size.height);
     
@@ -148,21 +155,24 @@ void WebCore::IconDatabase::loadIconFromURL(const String& url)
 
 - (void)retainIconForURL:(NSString *)url
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return;
     ASSERT(url);
     _iconDB->retainIconForPageURL(String(url));
 }
 
 - (void)releaseIconForURL:(NSString *)url
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return;
     ASSERT(url);
     _iconDB->releaseIconForPageURL(String(url));
 }
 
 - (void)_setIconData:(NSData *)data forIconURL:(NSString *)iconURL
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return;
     ASSERT(data);
     ASSERT(iconURL);
     
@@ -171,7 +181,8 @@ void WebCore::IconDatabase::loadIconFromURL(const String& url)
 
 - (void)_setHaveNoIconForIconURL:(NSString *)iconURL
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return;
     ASSERT(iconURL);
     
     _iconDB->setHaveNoIconForIconURL(String(iconURL));
@@ -179,7 +190,8 @@ void WebCore::IconDatabase::loadIconFromURL(const String& url)
 
 - (BOOL)_setIconURL:(NSString *)iconURL forPageURL:(NSString *)pageURL
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return NO;
     ASSERT(iconURL);
     ASSERT(pageURL);
     
@@ -188,7 +200,8 @@ void WebCore::IconDatabase::loadIconFromURL(const String& url)
 
 - (BOOL)_hasEntryForIconURL:(NSString *)iconURL
 {
-    ASSERT(_iconDB);
+    if (!_iconDB)
+        return NO;
     ASSERT(iconURL);
     
     return _iconDB->hasEntryForIconURL(iconURL);
index 74c68999b089f55302a6335b2dca2330e14f6da6..a2d16fad2ac8ddd58d3a566515b5b3b455b7af39 100644 (file)
@@ -105,13 +105,11 @@ bool IconDatabase::open(const String& databasePath)
         dbFilename = databasePath + "/" + defaultDatabaseFilename();
 
     // <rdar://problem/4707718> - If user's Icon directory is unwritable, Safari will crash at startup
-    // Now, we'll see if we can open the on-disk database.  If we can't, we'll log the error and open it as
-    // an in-memory database so the user will have icons during their current browsing session
-    
+    // Now, we'll see if we can open the on-disk database.  And, if we can't, we'll return false.  
+    // WebKit will then ignore us and act as if the database is disabled
     if (!m_mainDB.open(dbFilename)) {
         LOG_ERROR("Unable to open icon database at path %s - %s", dbFilename.ascii().data(), m_mainDB.lastErrorMsg());
-        if (!m_mainDB.open(":memory:"))
-            LOG_ERROR("Unable to open in-memory database for browsing - %s", m_mainDB.lastErrorMsg());
+        return false;
     }
     
     if (!isValidDatabase(m_mainDB)) {
@@ -829,6 +827,10 @@ bool IconDatabase::hasEntryForIconURL(const String& iconURL)
 IconDatabase::~IconDatabase()
 {
     close();
+    m_startupTimer.stop();
+    m_updateTimer.stop();
+    if (m_sharedInstance == this)
+        m_sharedInstance = 0;
 }
 
 // readySQLStatement() handles two things
index 0ab7758e19bda786a5db4935ddb5c8149e52755a..29452a6de92cf2684d9d6a97db7482f07b073083 100644 (file)
@@ -60,7 +60,8 @@ class IconDatabase
 friend class SiteIcon;
 public:
     static IconDatabase* sharedIconDatabase();
-    
+    ~IconDatabase();
+
     bool open(const String& path);
     bool isOpen() { return m_mainDB.isOpen() && m_privateBrowsingDB.isOpen(); }
     void close();
@@ -98,7 +99,6 @@ public:
     static const int updateTimerDelay;
 private:
     IconDatabase();
-    ~IconDatabase();
     
     // This tries to get the iconID for the IconURL and, if it doesn't exist and createIfNecessary is true,
     // it will create the entry and return the new iconID
index 903cd28a6bff0c06229d621e2b2bf96cd44d2621..1da3258135e0fb1005aaae2536e2eab13c057b10 100644 (file)
@@ -1,3 +1,16 @@
+2006-08-30  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by John
+
+        <rdar://problem/4707718> Change behavior so if the WebCore::IconDatabase can't open, WebKit releases the bridge and 
+        continues on as if the IconDatabase is disabled.
+        * Misc/WebIconDatabase.m:
+        (-[WebIconDatabase init]): Release the bridge on failure to open
+        * WebCoreSupport/WebIconDatabaseBridge.m:
+        (+[WebIconDatabaseBridge sharedBridgeInstance]): Moved static shared instance out as a global
+        (-[WebIconDatabaseBridge dealloc]): Clear pointer to the shared instance
+
 2006-08-30  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Darin.
index 432de26c73867885c2c7814c0e2879409e3c93c4..5f7d3cfd4040d85c1f8c8617b60cef7cc218ea49 100644 (file)
@@ -107,7 +107,12 @@ NSSize WebIconLargeSize = {128, 128};
     databaseDirectory = [databaseDirectory stringByExpandingTildeInPath];
     
     // Open the WebCore icon database
-    [_private->databaseBridge openSharedDatabaseWithPath:databaseDirectory];
+    if (![_private->databaseBridge openSharedDatabaseWithPath:databaseDirectory]) {
+        LOG_ERROR("Unable to open IconDatabaseBridge");
+        [_private->databaseBridge release];
+        _private->databaseBridge = nil;
+        return self;
+    }
     [_private->databaseBridge setPrivateBrowsingEnabled:[[WebPreferences standardPreferences] privateBrowsingEnabled]];
     
     // <rdar://problem/4674552> New IconDB: New Safari icon database needs to convert from the old icons on first load 
index ff52e587068d7647056e4b4cd36247bd75ce5a4d..f4efb2595ffb21f1f6a0301a142da5f8fc548f17 100644 (file)
     return self;
 }
 
-- (void)dealloc
-{
-    [cachedLoaders release];
-    [super dealloc];
-}
-
 - (void)loadIconFromURL:(NSString *)iconURL
 {
     if ([cachedLoaders valueForKey:iconURL])
     }
 }
 
+static WebCoreIconDatabaseBridge* g_sharedBridgeInstance = nil;
 + (WebCoreIconDatabaseBridge *)sharedBridgeInstance
 {
-    static WebCoreIconDatabaseBridge* sharedBridgeInstance = nil;
-    if (!sharedBridgeInstance)
-        sharedBridgeInstance = [[WebIconDatabaseBridge alloc] init];
-    return sharedBridgeInstance;
+    if (!g_sharedBridgeInstance)
+        g_sharedBridgeInstance = [[WebIconDatabaseBridge alloc] init];
+    return g_sharedBridgeInstance;
+}
+
+- (void)dealloc
+{
+    ASSERT(self == g_sharedBridgeInstance);
+    g_sharedBridgeInstance = nil;
+    [cachedLoaders release];
+    [super dealloc];
 }
 
 @end