[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

sullivan sullivan at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 06:10:48 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 3ae8c46b00b81aee6f99a6ce007e03408f450379
Author: sullivan <sullivan at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri May 3 23:05:33 2002 +0000

    	Along with small corresponding WebBrowser change,
    	fixed 2919172 (Bookmarks aren't saved between sessions).
    
    	* Bookmarks.subproj/IFBookmark_Private.h: Declarations for new private methods.
    	* Bookmarks.subproj/IFBookmark.m:
    	(-[IFBookmark _numberOfDescendants]): New private method, counts deep; used
    	only for debugging messages at this time.
    	(-[IFBookmark _initFromDictionaryRepresentation:withGroup:]):
    	(-[IFBookmark _dictionaryRepresentation]): New private methods used to save/load
    	bookmarks. Stub	implementations; subclasses must implement.
    
    	* Bookmarks.subproj/IFBookmarkLeaf.m:
    	(-[IFBookmarkLeaf _initFromDictionaryRepresentation:withGroup:]):
    	(-[IFBookmarkLeaf _dictionaryRepresentation]): New methods.
    
    	* Bookmarks.subproj/IFBookmarkList.m:
    	(-[IFBookmarkList _initFromDictionaryRepresentation:withGroup:]):
    	(-[IFBookmarkList _dictionaryRepresentation]):
    	(-[IFBookmarkList _numberOfDescendants]):
    	New methods.
    	(-[IFBookmarkList _setGroup:]): Recurse on children.
    
    	* Bookmarks.subproj/IFBookmarkGroup.h: New _loading instance variable.
    
    	* Bookmarks.subproj/IFBookmarkGroup.m:
    	(-[IFBookmarkGroup _setTopBookmark:]): Renamed from _resetTopBookmark,
    	now has potentially non-nil argument.
    	(-[IFBookmarkGroup initWithFile:]),
    	(-[IFBookmarkGroup removeBookmark:]): Updated for name change.
    	(-[IFBookmarkGroup _sendBookmarkGroupChangedNotification]):
    	Don't send notifications while loading bookmarks from disk.
    	(-[IFBookmarkGroup _loadBookmarkGroupGuts]),
    	(-[IFBookmarkGroup loadBookmarkGroup]),
    	(-[IFBookmarkGroup _saveBookmarkGroupGuts]),
    	(-[IFBookmarkGroup saveBookmarkGroup]): New methods, load/save bookmarks
    	and report timings.
    
    	* History.subproj/IFURIEntry.m:
    	(-[IFURIEntry dictionaryRepresentation]),
    	(-[IFURIEntry initFromDictionaryRepresentation:]): Handle nil URL
    	case, which bookmarks run into.
    
    	* WebKit.pbproj/project.pbxproj: version wars
    
    	* AppController.m:
    	(-[AppController applicationWillTerminate:]):
    	Save bookmarks at quit time.
    
    	* WebBrowser.pbproj/project.pbxproj: version wars
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1096 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/Bookmarks.subproj/IFBookmark.m b/WebKit/Bookmarks.subproj/IFBookmark.m
index a9260d8..0c902c8 100644
--- a/WebKit/Bookmarks.subproj/IFBookmark.m
+++ b/WebKit/Bookmarks.subproj/IFBookmark.m
@@ -78,6 +78,14 @@
     return 0;
 }
 
+- (unsigned)_numberOfDescendants
+{
+    if (![self isLeaf]) {
+        NSRequestConcreteImplementation(self, _cmd, [self class]);
+    }
+    return 0;
+}
+
 - (void)insertChild:(IFBookmark *)bookmark atIndex:(unsigned)index
 {
     if (![self isLeaf]) {
@@ -116,4 +124,17 @@
     _group = group;
 }
 
+- (id)_initFromDictionaryRepresentation:(NSDictionary *)dict withGroup:(IFBookmarkGroup *)group
+{
+    NSRequestConcreteImplementation(self, _cmd, [self class]);
+    return nil;
+}
+
+- (NSDictionary *)_dictionaryRepresentation
+{
+    NSRequestConcreteImplementation(self, _cmd, [self class]);
+    return nil;
+}
+
+
 @end
diff --git a/WebKit/Bookmarks.subproj/IFBookmarkGroup.h b/WebKit/Bookmarks.subproj/IFBookmarkGroup.h
index ae43a1d..df55d7c 100644
--- a/WebKit/Bookmarks.subproj/IFBookmarkGroup.h
+++ b/WebKit/Bookmarks.subproj/IFBookmarkGroup.h
@@ -17,6 +17,7 @@
 {
     NSString *_file;
     IFBookmark *_topBookmark;
+    BOOL _loading;
 }
 
 + (IFBookmarkGroup *)bookmarkGroupWithFile: (NSString *)file;
diff --git a/WebKit/Bookmarks.subproj/IFBookmarkGroup.m b/WebKit/Bookmarks.subproj/IFBookmarkGroup.m
index bd4db51..05adb69 100644
--- a/WebKit/Bookmarks.subproj/IFBookmarkGroup.m
+++ b/WebKit/Bookmarks.subproj/IFBookmarkGroup.m
@@ -14,7 +14,7 @@
 #import <WebKit/WebKitDebug.h>
 
 @interface IFBookmarkGroup (IFForwardDeclarations)
-- (void)_resetTopBookmark;
+- (void)_setTopBookmark:(IFBookmark *)newTopBookmark;
 @end
 
 @implementation IFBookmarkGroup
@@ -31,7 +31,7 @@
     }
 
     _file = [file retain];
-    [self _resetTopBookmark];
+    [self _setTopBookmark:nil];
 
     // read history from disk
     [self loadBookmarkGroup];
@@ -53,27 +53,39 @@
 
 - (void)_sendBookmarkGroupChangedNotification
 {
+    if (_loading) {
+        return;
+    }
+    
     [[NSNotificationCenter defaultCenter]
         postNotificationName: IFBookmarkGroupChangedNotification
                       object: self];
 }
 
-- (void)_resetTopBookmark
+- (void)_setTopBookmark:(IFBookmark *)newTopBookmark
 {
-    BOOL hadChildren;
+    BOOL hadChildren, hasChildrenNow;
+
+    WEBKIT_ASSERT_VALID_ARG (newTopBookmark, newTopBookmark == nil || ![newTopBookmark isLeaf]);
 
     hadChildren = [_topBookmark numberOfChildren] > 0;
+    hasChildrenNow = newTopBookmark != nil && [newTopBookmark numberOfChildren] > 0;
     
     // bail out early if nothing needs resetting
-    if (!hadChildren && _topBookmark != nil) {
+    if (!hadChildren && _topBookmark != nil && !hasChildrenNow) {
         return;
     }
 
     [_topBookmark _setGroup:nil];
     [_topBookmark autorelease];
-    _topBookmark = [[[IFBookmarkList alloc] initWithTitle:nil image:nil group:self] retain];
 
-    if (hadChildren) {
+    if (newTopBookmark) {
+        _topBookmark = [newTopBookmark retain];
+    } else {
+        _topBookmark = [[[IFBookmarkList alloc] initWithTitle:nil image:nil group:self] retain];
+    }
+
+    if (hadChildren || hasChildrenNow) {
         [self _sendBookmarkGroupChangedNotification];
     }
 }
@@ -107,7 +119,7 @@
     WEBKIT_ASSERT_VALID_ARG (bookmark, [bookmark _parent] != nil || bookmark == _topBookmark);
 
     if (bookmark == _topBookmark) {
-        [self _resetTopBookmark];
+        [self _setTopBookmark:nil];
     } else {
         [[bookmark _parent] removeChild:bookmark];
         [bookmark _setGroup:nil];
@@ -160,16 +172,90 @@
     return _file;
 }
 
+- (BOOL)_loadBookmarkGroupGuts
+{
+    NSString *path;
+    NSDictionary *dictionary;
+    IFBookmarkList *newTopBookmark;
+
+    path = [self file];
+    if (path == nil) {
+        WEBKITDEBUG("couldn't load bookmarks; couldn't find or create directory to store it in\n");
+        return NO;
+    }
+
+    dictionary = [NSDictionary dictionaryWithContentsOfFile: path];
+    if (dictionary == nil) {
+        if (![[NSFileManager defaultManager] fileExistsAtPath: path]) {
+            WEBKITDEBUG("no bookmarks file found at %s\n",
+                        DEBUG_OBJECT(path));
+        } else {
+            WEBKITDEBUG("attempt to read bookmarks from %s failed; perhaps contents are corrupted\n",
+                        DEBUG_OBJECT(path));
+        }
+        return NO;
+    }
+
+    _loading = YES;
+    newTopBookmark = [[IFBookmarkList alloc] _initFromDictionaryRepresentation:dictionary withGroup:self];
+    [self _setTopBookmark:newTopBookmark];
+    _loading = NO;
+
+    return YES;
+}
+
 - (BOOL)loadBookmarkGroup
 {
-    _logNotYetImplemented();
-    return NO;
+    double start, duration;
+    BOOL result;
+
+    start = CFAbsoluteTimeGetCurrent();
+    result = [self _loadBookmarkGroupGuts];
+
+    if (result == YES) {
+        duration = CFAbsoluteTimeGetCurrent() - start;
+        WEBKITDEBUGLEVEL (WEBKIT_LOG_TIMING, "loading %d bookmarks from %s took %f seconds\n",
+                          [[self topBookmark] _numberOfDescendants], DEBUG_OBJECT([self file]), duration);
+    }
+
+    return result;
+}
+
+- (BOOL)_saveBookmarkGroupGuts
+{
+    NSString *path;
+    NSDictionary *dictionary;
+
+    path = [self file];
+    if (path == nil) {
+        WEBKITDEBUG("couldn't save bookmarks; couldn't find or create directory to store it in\n");
+        return NO;
+    }
+
+    dictionary = [[self topBookmark] _dictionaryRepresentation];
+    if (![dictionary writeToFile:path atomically:YES]) {
+        WEBKITDEBUG("attempt to save %s to %s failed\n", DEBUG_OBJECT(dictionary), DEBUG_OBJECT(path));
+        return NO;
+    }
+
+    return YES;
 }
 
 - (BOOL)saveBookmarkGroup
 {
-    _logNotYetImplemented();
-   return NO;
+    double start, duration;
+    BOOL result;
+
+    start = CFAbsoluteTimeGetCurrent();
+    result = [self _saveBookmarkGroupGuts];
+    
+    if (result == YES) {
+        duration = CFAbsoluteTimeGetCurrent() - start;
+        WEBKITDEBUGLEVEL (WEBKIT_LOG_TIMING, "saving %d bookmarks to %s took %f seconds\n",
+                          [[self topBookmark] _numberOfDescendants], DEBUG_OBJECT([self file]), duration);
+    }
+
+    return result;
 }
 
 @end
diff --git a/WebKit/Bookmarks.subproj/IFBookmarkLeaf.m b/WebKit/Bookmarks.subproj/IFBookmarkLeaf.m
index f879169..c220ea3 100644
--- a/WebKit/Bookmarks.subproj/IFBookmarkLeaf.m
+++ b/WebKit/Bookmarks.subproj/IFBookmarkLeaf.m
@@ -13,6 +13,9 @@
 #import <WebKit/IFURIEntry.h>
 #import <WebKit/WebKitDebug.h>
 
+#define URIDictionaryKey	@"URIDictionary"
+#define URLStringKey		@"URLString"
+
 @implementation IFBookmarkLeaf
 
 - (id)initWithURLString:(NSString *)URLString
@@ -34,6 +37,33 @@
     return self;
 }
 
+- (id)_initFromDictionaryRepresentation:(NSDictionary *)dict withGroup:(IFBookmarkGroup *)group
+{
+    WEBKIT_ASSERT_VALID_ARG (dict, dict != nil);
+
+    [super init];
+
+    [self _setGroup:group];
+    
+    _entry = [[[IFURIEntry alloc] initFromDictionaryRepresentation:
+        [dict objectForKey:URIDictionaryKey]] retain];
+    _URLString = [[dict objectForKey:URLStringKey] retain];
+
+    return self;
+}
+
+- (NSDictionary *)_dictionaryRepresentation
+{
+    NSMutableDictionary *dict;
+
+    dict = [NSMutableDictionary dictionaryWithCapacity: 2];
+
+    [dict setObject:[_entry dictionaryRepresentation] forKey:URIDictionaryKey];
+    [dict setObject:_URLString forKey:URLStringKey];
+
+    return dict;
+}
+
 - (void)dealloc
 {
     [_entry release];
@@ -87,4 +117,5 @@
     [[self _group] _bookmarkDidChange:self];    
 }
 
+
 @end
diff --git a/WebKit/Bookmarks.subproj/IFBookmarkList.m b/WebKit/Bookmarks.subproj/IFBookmarkList.m
index f29fdec..dba42f8 100644
--- a/WebKit/Bookmarks.subproj/IFBookmarkList.m
+++ b/WebKit/Bookmarks.subproj/IFBookmarkList.m
@@ -7,10 +7,15 @@
 //
 
 #import <WebKit/IFBookmarkList.h>
+#import <WebKit/IFBookmarkLeaf.h>
 #import <WebKit/IFBookmark_Private.h>
 #import <WebKit/IFBookmarkGroup_Private.h>
 #import <WebKit/WebKitDebug.h>
 
+#define TitleKey		@"Title"
+#define ListIdentifierKey	@"ListIdentifier"
+#define ChildrenKey		@"Children"
+
 @implementation IFBookmarkList
 
 - (id)initWithTitle:(NSString *)title
@@ -29,6 +34,79 @@
     return self;
 }
 
+- (id)_initFromDictionaryRepresentation:(NSDictionary *)dict withGroup:(IFBookmarkGroup *)group
+{
+    NSArray *storedChildren;
+    NSDictionary *childAsDictionary;
+    IFBookmark *child;
+    unsigned index, count;
+    
+    WEBKIT_ASSERT_VALID_ARG (dict, dict != nil);
+
+    [super init];
+
+    [self _setGroup:group];
+
+    // FIXME: doesn't restore images
+    _title = [[dict objectForKey:TitleKey] retain];
+    _list = [[NSMutableArray alloc] init];
+
+    storedChildren = [dict objectForKey:ChildrenKey];
+    if (storedChildren != nil) {
+        count = [storedChildren count];
+        for (index = 0; index < count; ++index) {
+            childAsDictionary = [storedChildren objectAtIndex:index];
+            
+            // determine whether child is a leaf or a list by looking for the
+            // token that this list class inserts.
+            if ([childAsDictionary objectForKey:ListIdentifierKey] != nil) {
+                child = [[IFBookmarkList alloc] _initFromDictionaryRepresentation:childAsDictionary
+                                                                        withGroup:group];
+            } else {
+                child = [[IFBookmarkLeaf alloc] _initFromDictionaryRepresentation:childAsDictionary
+                                                                        withGroup:group];
+            }
+
+            [self insertChild:child atIndex:index];
+        }
+    }
+
+    return self;
+}
+
+- (NSDictionary *)_dictionaryRepresentation
+{
+    NSMutableDictionary *dict;
+    NSMutableArray *childrenAsDictionaries;
+    unsigned index, childCount;
+
+    dict = [NSMutableDictionary dictionaryWithCapacity: 3];
+
+    // FIXME: doesn't save images
+    if (_title != nil) {
+        [dict setObject:_title forKey:TitleKey];
+    }
+
+    // mark this as a list-type bookmark; used in _initFromDictionaryRepresentation
+    [dict setObject:@"YES" forKey:ListIdentifierKey];
+
+    childCount = [self numberOfChildren];
+    if (childCount > 0) {
+        childrenAsDictionaries = [NSMutableArray arrayWithCapacity:childCount];
+
+        for (index = 0; index < childCount; ++index) {
+            IFBookmark *child;
+
+            child = [_list objectAtIndex:index];
+            [childrenAsDictionaries addObject:[child _dictionaryRepresentation]];
+        }
+
+        [dict setObject:childrenAsDictionaries forKey:ChildrenKey];
+    }
+    
+    return dict;
+}
+
 - (void)dealloc
 {
     [_title release];
@@ -87,6 +165,23 @@
     return [_list count];
 }
 
+- (unsigned)_numberOfDescendants
+{
+    unsigned result;
+    unsigned index, count;
+    IFBookmark *child;
+
+    count = [self numberOfChildren];
+    result = count;
+
+    for (index = 0; index < count; ++index) {
+        child = [_list objectAtIndex:index];
+        result += [child _numberOfDescendants];
+    }
+
+    return result;
+}
+
 - (void)removeChild:(IFBookmark *)bookmark
 {
     WEBKIT_ASSERT_VALID_ARG (bookmark, [bookmark _parent] == self);
@@ -105,4 +200,14 @@
     [[self _group] _bookmarkChildrenDidChange:self]; 
 }
 
+- (void)_setGroup:(IFBookmarkGroup *)group
+{
+    if (group == [self _group]) {
+        return;
+    }
+
+    [super _setGroup:group];
+    [_list makeObjectsPerformSelector:@selector(_setGroup:) withObject:group];
+}
+
 @end
diff --git a/WebKit/Bookmarks.subproj/IFBookmark_Private.h b/WebKit/Bookmarks.subproj/IFBookmark_Private.h
index e450ab2..609b169 100644
--- a/WebKit/Bookmarks.subproj/IFBookmark_Private.h
+++ b/WebKit/Bookmarks.subproj/IFBookmark_Private.h
@@ -11,11 +11,16 @@
 
 @interface IFBookmark(IFPrivate)
 
+- (id)_initFromDictionaryRepresentation:(NSDictionary *)dict withGroup:(IFBookmarkGroup *)group;
+- (NSDictionary *)_dictionaryRepresentation;
+
 - (IFBookmark *)_parent;
 - (void)_setParent:(IFBookmark *)parent;
 
 - (IFBookmarkGroup *)_group;
 - (void)_setGroup:(IFBookmarkGroup *)group;
 
+- (unsigned)_numberOfDescendants;
+
 @end
 
diff --git a/WebKit/Bookmarks.subproj/WebBookmark.m b/WebKit/Bookmarks.subproj/WebBookmark.m
index a9260d8..0c902c8 100644
--- a/WebKit/Bookmarks.subproj/WebBookmark.m
+++ b/WebKit/Bookmarks.subproj/WebBookmark.m
@@ -78,6 +78,14 @@
     return 0;
 }
 
+- (unsigned)_numberOfDescendants
+{
+    if (![self isLeaf]) {
+        NSRequestConcreteImplementation(self, _cmd, [self class]);
+    }
+    return 0;
+}
+
 - (void)insertChild:(IFBookmark *)bookmark atIndex:(unsigned)index
 {
     if (![self isLeaf]) {
@@ -116,4 +124,17 @@
     _group = group;
 }
 
+- (id)_initFromDictionaryRepresentation:(NSDictionary *)dict withGroup:(IFBookmarkGroup *)group
+{
+    NSRequestConcreteImplementation(self, _cmd, [self class]);
+    return nil;
+}
+
+- (NSDictionary *)_dictionaryRepresentation
+{
+    NSRequestConcreteImplementation(self, _cmd, [self class]);
+    return nil;
+}
+
+
 @end
diff --git a/WebKit/Bookmarks.subproj/WebBookmarkGroup.h b/WebKit/Bookmarks.subproj/WebBookmarkGroup.h
index ae43a1d..df55d7c 100644
--- a/WebKit/Bookmarks.subproj/WebBookmarkGroup.h
+++ b/WebKit/Bookmarks.subproj/WebBookmarkGroup.h
@@ -17,6 +17,7 @@
 {
     NSString *_file;
     IFBookmark *_topBookmark;
+    BOOL _loading;
 }
 
 + (IFBookmarkGroup *)bookmarkGroupWithFile: (NSString *)file;
diff --git a/WebKit/Bookmarks.subproj/WebBookmarkGroup.m b/WebKit/Bookmarks.subproj/WebBookmarkGroup.m
index bd4db51..05adb69 100644
--- a/WebKit/Bookmarks.subproj/WebBookmarkGroup.m
+++ b/WebKit/Bookmarks.subproj/WebBookmarkGroup.m
@@ -14,7 +14,7 @@
 #import <WebKit/WebKitDebug.h>
 
 @interface IFBookmarkGroup (IFForwardDeclarations)
-- (void)_resetTopBookmark;
+- (void)_setTopBookmark:(IFBookmark *)newTopBookmark;
 @end
 
 @implementation IFBookmarkGroup
@@ -31,7 +31,7 @@
     }
 
     _file = [file retain];
-    [self _resetTopBookmark];
+    [self _setTopBookmark:nil];
 
     // read history from disk
     [self loadBookmarkGroup];
@@ -53,27 +53,39 @@
 
 - (void)_sendBookmarkGroupChangedNotification
 {
+    if (_loading) {
+        return;
+    }
+    
     [[NSNotificationCenter defaultCenter]
         postNotificationName: IFBookmarkGroupChangedNotification
                       object: self];
 }
 
-- (void)_resetTopBookmark
+- (void)_setTopBookmark:(IFBookmark *)newTopBookmark
 {
-    BOOL hadChildren;
+    BOOL hadChildren, hasChildrenNow;
+
+    WEBKIT_ASSERT_VALID_ARG (newTopBookmark, newTopBookmark == nil || ![newTopBookmark isLeaf]);
 
     hadChildren = [_topBookmark numberOfChildren] > 0;
+    hasChildrenNow = newTopBookmark != nil && [newTopBookmark numberOfChildren] > 0;
     
     // bail out early if nothing needs resetting
-    if (!hadChildren && _topBookmark != nil) {
+    if (!hadChildren && _topBookmark != nil && !hasChildrenNow) {
         return;
     }
 
     [_topBookmark _setGroup:nil];
     [_topBookmark autorelease];
-    _topBookmark = [[[IFBookmarkList alloc] initWithTitle:nil image:nil group:self] retain];
 
-    if (hadChildren) {
+    if (newTopBookmark) {
+        _topBookmark = [newTopBookmark retain];
+    } else {
+        _topBookmark = [[[IFBookmarkList alloc] initWithTitle:nil image:nil group:self] retain];
+    }
+
+    if (hadChildren || hasChildrenNow) {
         [self _sendBookmarkGroupChangedNotification];
     }
 }
@@ -107,7 +119,7 @@
     WEBKIT_ASSERT_VALID_ARG (bookmark, [bookmark _parent] != nil || bookmark == _topBookmark);
 
     if (bookmark == _topBookmark) {
-        [self _resetTopBookmark];
+        [self _setTopBookmark:nil];
     } else {
         [[bookmark _parent] removeChild:bookmark];
         [bookmark _setGroup:nil];
@@ -160,16 +172,90 @@
     return _file;
 }
 
+- (BOOL)_loadBookmarkGroupGuts
+{
+    NSString *path;
+    NSDictionary *dictionary;
+    IFBookmarkList *newTopBookmark;
+
+    path = [self file];
+    if (path == nil) {
+        WEBKITDEBUG("couldn't load bookmarks; couldn't find or create directory to store it in\n");
+        return NO;
+    }
+
+    dictionary = [NSDictionary dictionaryWithContentsOfFile: path];
+    if (dictionary == nil) {
+        if (![[NSFileManager defaultManager] fileExistsAtPath: path]) {
+            WEBKITDEBUG("no bookmarks file found at %s\n",
+                        DEBUG_OBJECT(path));
+        } else {
+            WEBKITDEBUG("attempt to read bookmarks from %s failed; perhaps contents are corrupted\n",
+                        DEBUG_OBJECT(path));
+        }
+        return NO;
+    }
+
+    _loading = YES;
+    newTopBookmark = [[IFBookmarkList alloc] _initFromDictionaryRepresentation:dictionary withGroup:self];
+    [self _setTopBookmark:newTopBookmark];
+    _loading = NO;
+
+    return YES;
+}
+
 - (BOOL)loadBookmarkGroup
 {
-    _logNotYetImplemented();
-    return NO;
+    double start, duration;
+    BOOL result;
+
+    start = CFAbsoluteTimeGetCurrent();
+    result = [self _loadBookmarkGroupGuts];
+
+    if (result == YES) {
+        duration = CFAbsoluteTimeGetCurrent() - start;
+        WEBKITDEBUGLEVEL (WEBKIT_LOG_TIMING, "loading %d bookmarks from %s took %f seconds\n",
+                          [[self topBookmark] _numberOfDescendants], DEBUG_OBJECT([self file]), duration);
+    }
+
+    return result;
+}
+
+- (BOOL)_saveBookmarkGroupGuts
+{
+    NSString *path;
+    NSDictionary *dictionary;
+
+    path = [self file];
+    if (path == nil) {
+        WEBKITDEBUG("couldn't save bookmarks; couldn't find or create directory to store it in\n");
+        return NO;
+    }
+
+    dictionary = [[self topBookmark] _dictionaryRepresentation];
+    if (![dictionary writeToFile:path atomically:YES]) {
+        WEBKITDEBUG("attempt to save %s to %s failed\n", DEBUG_OBJECT(dictionary), DEBUG_OBJECT(path));
+        return NO;
+    }
+
+    return YES;
 }
 
 - (BOOL)saveBookmarkGroup
 {
-    _logNotYetImplemented();
-   return NO;
+    double start, duration;
+    BOOL result;
+
+    start = CFAbsoluteTimeGetCurrent();
+    result = [self _saveBookmarkGroupGuts];
+    
+    if (result == YES) {
+        duration = CFAbsoluteTimeGetCurrent() - start;
+        WEBKITDEBUGLEVEL (WEBKIT_LOG_TIMING, "saving %d bookmarks to %s took %f seconds\n",
+                          [[self topBookmark] _numberOfDescendants], DEBUG_OBJECT([self file]), duration);
+    }
+
+    return result;
 }
 
 @end
diff --git a/WebKit/Bookmarks.subproj/WebBookmarkLeaf.m b/WebKit/Bookmarks.subproj/WebBookmarkLeaf.m
index f879169..c220ea3 100644
--- a/WebKit/Bookmarks.subproj/WebBookmarkLeaf.m
+++ b/WebKit/Bookmarks.subproj/WebBookmarkLeaf.m
@@ -13,6 +13,9 @@
 #import <WebKit/IFURIEntry.h>
 #import <WebKit/WebKitDebug.h>
 
+#define URIDictionaryKey	@"URIDictionary"
+#define URLStringKey		@"URLString"
+
 @implementation IFBookmarkLeaf
 
 - (id)initWithURLString:(NSString *)URLString
@@ -34,6 +37,33 @@
     return self;
 }
 
+- (id)_initFromDictionaryRepresentation:(NSDictionary *)dict withGroup:(IFBookmarkGroup *)group
+{
+    WEBKIT_ASSERT_VALID_ARG (dict, dict != nil);
+
+    [super init];
+
+    [self _setGroup:group];
+    
+    _entry = [[[IFURIEntry alloc] initFromDictionaryRepresentation:
+        [dict objectForKey:URIDictionaryKey]] retain];
+    _URLString = [[dict objectForKey:URLStringKey] retain];
+
+    return self;
+}
+
+- (NSDictionary *)_dictionaryRepresentation
+{
+    NSMutableDictionary *dict;
+
+    dict = [NSMutableDictionary dictionaryWithCapacity: 2];
+
+    [dict setObject:[_entry dictionaryRepresentation] forKey:URIDictionaryKey];
+    [dict setObject:_URLString forKey:URLStringKey];
+
+    return dict;
+}
+
 - (void)dealloc
 {
     [_entry release];
@@ -87,4 +117,5 @@
     [[self _group] _bookmarkDidChange:self];    
 }
 
+
 @end
diff --git a/WebKit/Bookmarks.subproj/WebBookmarkList.m b/WebKit/Bookmarks.subproj/WebBookmarkList.m
index f29fdec..dba42f8 100644
--- a/WebKit/Bookmarks.subproj/WebBookmarkList.m
+++ b/WebKit/Bookmarks.subproj/WebBookmarkList.m
@@ -7,10 +7,15 @@
 //
 
 #import <WebKit/IFBookmarkList.h>
+#import <WebKit/IFBookmarkLeaf.h>
 #import <WebKit/IFBookmark_Private.h>
 #import <WebKit/IFBookmarkGroup_Private.h>
 #import <WebKit/WebKitDebug.h>
 
+#define TitleKey		@"Title"
+#define ListIdentifierKey	@"ListIdentifier"
+#define ChildrenKey		@"Children"
+
 @implementation IFBookmarkList
 
 - (id)initWithTitle:(NSString *)title
@@ -29,6 +34,79 @@
     return self;
 }
 
+- (id)_initFromDictionaryRepresentation:(NSDictionary *)dict withGroup:(IFBookmarkGroup *)group
+{
+    NSArray *storedChildren;
+    NSDictionary *childAsDictionary;
+    IFBookmark *child;
+    unsigned index, count;
+    
+    WEBKIT_ASSERT_VALID_ARG (dict, dict != nil);
+
+    [super init];
+
+    [self _setGroup:group];
+
+    // FIXME: doesn't restore images
+    _title = [[dict objectForKey:TitleKey] retain];
+    _list = [[NSMutableArray alloc] init];
+
+    storedChildren = [dict objectForKey:ChildrenKey];
+    if (storedChildren != nil) {
+        count = [storedChildren count];
+        for (index = 0; index < count; ++index) {
+            childAsDictionary = [storedChildren objectAtIndex:index];
+            
+            // determine whether child is a leaf or a list by looking for the
+            // token that this list class inserts.
+            if ([childAsDictionary objectForKey:ListIdentifierKey] != nil) {
+                child = [[IFBookmarkList alloc] _initFromDictionaryRepresentation:childAsDictionary
+                                                                        withGroup:group];
+            } else {
+                child = [[IFBookmarkLeaf alloc] _initFromDictionaryRepresentation:childAsDictionary
+                                                                        withGroup:group];
+            }
+
+            [self insertChild:child atIndex:index];
+        }
+    }
+
+    return self;
+}
+
+- (NSDictionary *)_dictionaryRepresentation
+{
+    NSMutableDictionary *dict;
+    NSMutableArray *childrenAsDictionaries;
+    unsigned index, childCount;
+
+    dict = [NSMutableDictionary dictionaryWithCapacity: 3];
+
+    // FIXME: doesn't save images
+    if (_title != nil) {
+        [dict setObject:_title forKey:TitleKey];
+    }
+
+    // mark this as a list-type bookmark; used in _initFromDictionaryRepresentation
+    [dict setObject:@"YES" forKey:ListIdentifierKey];
+
+    childCount = [self numberOfChildren];
+    if (childCount > 0) {
+        childrenAsDictionaries = [NSMutableArray arrayWithCapacity:childCount];
+
+        for (index = 0; index < childCount; ++index) {
+            IFBookmark *child;
+
+            child = [_list objectAtIndex:index];
+            [childrenAsDictionaries addObject:[child _dictionaryRepresentation]];
+        }
+
+        [dict setObject:childrenAsDictionaries forKey:ChildrenKey];
+    }
+    
+    return dict;
+}
+
 - (void)dealloc
 {
     [_title release];
@@ -87,6 +165,23 @@
     return [_list count];
 }
 
+- (unsigned)_numberOfDescendants
+{
+    unsigned result;
+    unsigned index, count;
+    IFBookmark *child;
+
+    count = [self numberOfChildren];
+    result = count;
+
+    for (index = 0; index < count; ++index) {
+        child = [_list objectAtIndex:index];
+        result += [child _numberOfDescendants];
+    }
+
+    return result;
+}
+
 - (void)removeChild:(IFBookmark *)bookmark
 {
     WEBKIT_ASSERT_VALID_ARG (bookmark, [bookmark _parent] == self);
@@ -105,4 +200,14 @@
     [[self _group] _bookmarkChildrenDidChange:self]; 
 }
 
+- (void)_setGroup:(IFBookmarkGroup *)group
+{
+    if (group == [self _group]) {
+        return;
+    }
+
+    [super _setGroup:group];
+    [_list makeObjectsPerformSelector:@selector(_setGroup:) withObject:group];
+}
+
 @end
diff --git a/WebKit/Bookmarks.subproj/WebBookmarkPrivate.h b/WebKit/Bookmarks.subproj/WebBookmarkPrivate.h
index e450ab2..609b169 100644
--- a/WebKit/Bookmarks.subproj/WebBookmarkPrivate.h
+++ b/WebKit/Bookmarks.subproj/WebBookmarkPrivate.h
@@ -11,11 +11,16 @@
 
 @interface IFBookmark(IFPrivate)
 
+- (id)_initFromDictionaryRepresentation:(NSDictionary *)dict withGroup:(IFBookmarkGroup *)group;
+- (NSDictionary *)_dictionaryRepresentation;
+
 - (IFBookmark *)_parent;
 - (void)_setParent:(IFBookmark *)parent;
 
 - (IFBookmarkGroup *)_group;
 - (void)_setGroup:(IFBookmarkGroup *)group;
 
+- (unsigned)_numberOfDescendants;
+
 @end
 
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 8364bd5..354861e 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,49 @@
+2002-05-03  John Sullivan  <sullivan at apple.com>
+
+	Along with small corresponding WebBrowser change,	
+	fixed 2919172 (Bookmarks aren't saved between sessions).
+
+	* Bookmarks.subproj/IFBookmark_Private.h: Declarations for new private methods.
+	* Bookmarks.subproj/IFBookmark.m:
+	(-[IFBookmark _numberOfDescendants]): New private method, counts deep; used
+	only for debugging messages at this time.
+	(-[IFBookmark _initFromDictionaryRepresentation:withGroup:]):
+	(-[IFBookmark _dictionaryRepresentation]): New private methods used to save/load
+	bookmarks. Stub	implementations; subclasses must implement.
+
+	* Bookmarks.subproj/IFBookmarkLeaf.m:
+	(-[IFBookmarkLeaf _initFromDictionaryRepresentation:withGroup:]):
+	(-[IFBookmarkLeaf _dictionaryRepresentation]): New methods.
+
+	* Bookmarks.subproj/IFBookmarkList.m:
+	(-[IFBookmarkList _initFromDictionaryRepresentation:withGroup:]):
+	(-[IFBookmarkList _dictionaryRepresentation]):
+	(-[IFBookmarkList _numberOfDescendants]):
+	New methods.
+	(-[IFBookmarkList _setGroup:]): Recurse on children.
+
+	* Bookmarks.subproj/IFBookmarkGroup.h: New _loading instance variable.
+
+	* Bookmarks.subproj/IFBookmarkGroup.m:
+	(-[IFBookmarkGroup _setTopBookmark:]): Renamed from _resetTopBookmark,
+	now has potentially non-nil argument.
+	(-[IFBookmarkGroup initWithFile:]),
+	(-[IFBookmarkGroup removeBookmark:]): Updated for name change.
+	(-[IFBookmarkGroup _sendBookmarkGroupChangedNotification]):
+	Don't send notifications while loading bookmarks from disk.
+	(-[IFBookmarkGroup _loadBookmarkGroupGuts]),
+	(-[IFBookmarkGroup loadBookmarkGroup]),
+	(-[IFBookmarkGroup _saveBookmarkGroupGuts]),
+	(-[IFBookmarkGroup saveBookmarkGroup]): New methods, load/save bookmarks
+	and report timings.
+
+	* History.subproj/IFURIEntry.m:
+	(-[IFURIEntry dictionaryRepresentation]),
+	(-[IFURIEntry initFromDictionaryRepresentation:]): Handle nil URL
+	case, which bookmarks run into.
+
+	* WebKit.pbproj/project.pbxproj: version wars
+
 2002-05-03  Darin Adler  <darin at apple.com>
 
 	* WebCoreSupport.subproj/IFCachedTextRenderer.m: Remove some of the unused code.
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index 8364bd5..354861e 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,49 @@
+2002-05-03  John Sullivan  <sullivan at apple.com>
+
+	Along with small corresponding WebBrowser change,	
+	fixed 2919172 (Bookmarks aren't saved between sessions).
+
+	* Bookmarks.subproj/IFBookmark_Private.h: Declarations for new private methods.
+	* Bookmarks.subproj/IFBookmark.m:
+	(-[IFBookmark _numberOfDescendants]): New private method, counts deep; used
+	only for debugging messages at this time.
+	(-[IFBookmark _initFromDictionaryRepresentation:withGroup:]):
+	(-[IFBookmark _dictionaryRepresentation]): New private methods used to save/load
+	bookmarks. Stub	implementations; subclasses must implement.
+
+	* Bookmarks.subproj/IFBookmarkLeaf.m:
+	(-[IFBookmarkLeaf _initFromDictionaryRepresentation:withGroup:]):
+	(-[IFBookmarkLeaf _dictionaryRepresentation]): New methods.
+
+	* Bookmarks.subproj/IFBookmarkList.m:
+	(-[IFBookmarkList _initFromDictionaryRepresentation:withGroup:]):
+	(-[IFBookmarkList _dictionaryRepresentation]):
+	(-[IFBookmarkList _numberOfDescendants]):
+	New methods.
+	(-[IFBookmarkList _setGroup:]): Recurse on children.
+
+	* Bookmarks.subproj/IFBookmarkGroup.h: New _loading instance variable.
+
+	* Bookmarks.subproj/IFBookmarkGroup.m:
+	(-[IFBookmarkGroup _setTopBookmark:]): Renamed from _resetTopBookmark,
+	now has potentially non-nil argument.
+	(-[IFBookmarkGroup initWithFile:]),
+	(-[IFBookmarkGroup removeBookmark:]): Updated for name change.
+	(-[IFBookmarkGroup _sendBookmarkGroupChangedNotification]):
+	Don't send notifications while loading bookmarks from disk.
+	(-[IFBookmarkGroup _loadBookmarkGroupGuts]),
+	(-[IFBookmarkGroup loadBookmarkGroup]),
+	(-[IFBookmarkGroup _saveBookmarkGroupGuts]),
+	(-[IFBookmarkGroup saveBookmarkGroup]): New methods, load/save bookmarks
+	and report timings.
+
+	* History.subproj/IFURIEntry.m:
+	(-[IFURIEntry dictionaryRepresentation]),
+	(-[IFURIEntry initFromDictionaryRepresentation:]): Handle nil URL
+	case, which bookmarks run into.
+
+	* WebKit.pbproj/project.pbxproj: version wars
+
 2002-05-03  Darin Adler  <darin at apple.com>
 
 	* WebCoreSupport.subproj/IFCachedTextRenderer.m: Remove some of the unused code.
diff --git a/WebKit/History.subproj/IFURIEntry.m b/WebKit/History.subproj/IFURIEntry.m
index 9fc96a3..4c48e7c 100644
--- a/WebKit/History.subproj/IFURIEntry.m
+++ b/WebKit/History.subproj/IFURIEntry.m
@@ -198,7 +198,9 @@
     NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity: 6];
 
     // FIXME: doesn't save/restore images yet
-    [dict setObject: [_url absoluteString] forKey: @"url"];
+    if (_url != nil) {
+        [dict setObject: [_url absoluteString] forKey: @"url"];
+    }
     if (_title != nil) {
         [dict setObject: _title forKey: @"title"];
     }
@@ -226,19 +228,24 @@
 
 - (id)initFromDictionaryRepresentation:(NSDictionary *)dict
 {
+    NSString *storedURLString;
+
+    [super init];
+    
     // FIXME: doesn't save/restore images yet
-    if ((self = [super init]) != nil) {
-        _url = [[NSURL URLWithString: [dict objectForKey: @"url"]] retain];
-        _title = [[dict objectForKey: @"title"] retain];
-        _displayTitle = [[dict objectForKey: @"displayTitle"] retain];
-        _comment = [[dict objectForKey: @"comment"] retain];
-        _creationDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
-            [[dict objectForKey: @"creationDate"] doubleValue]] retain];
-        _modificationDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
-            [[dict objectForKey: @"modificationDate"] doubleValue]] retain];
-        _lastVisitedDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
-            [[dict objectForKey: @"lastVisitedDate"] doubleValue]] retain];
-    }
+    storedURLString = [dict objectForKey: @"url"];
+    if (storedURLString != nil) {
+        _url = [[NSURL URLWithString:storedURLString] retain];
+    }
+    _title = [[dict objectForKey: @"title"] retain];
+    _displayTitle = [[dict objectForKey: @"displayTitle"] retain];
+    _comment = [[dict objectForKey: @"comment"] retain];
+    _creationDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
+        [[dict objectForKey: @"creationDate"] doubleValue]] retain];
+    _modificationDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
+        [[dict objectForKey: @"modificationDate"] doubleValue]] retain];
+    _lastVisitedDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
+        [[dict objectForKey: @"lastVisitedDate"] doubleValue]] retain];
 
     return self;
 }
diff --git a/WebKit/History.subproj/WebHistoryItem.m b/WebKit/History.subproj/WebHistoryItem.m
index 9fc96a3..4c48e7c 100644
--- a/WebKit/History.subproj/WebHistoryItem.m
+++ b/WebKit/History.subproj/WebHistoryItem.m
@@ -198,7 +198,9 @@
     NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity: 6];
 
     // FIXME: doesn't save/restore images yet
-    [dict setObject: [_url absoluteString] forKey: @"url"];
+    if (_url != nil) {
+        [dict setObject: [_url absoluteString] forKey: @"url"];
+    }
     if (_title != nil) {
         [dict setObject: _title forKey: @"title"];
     }
@@ -226,19 +228,24 @@
 
 - (id)initFromDictionaryRepresentation:(NSDictionary *)dict
 {
+    NSString *storedURLString;
+
+    [super init];
+    
     // FIXME: doesn't save/restore images yet
-    if ((self = [super init]) != nil) {
-        _url = [[NSURL URLWithString: [dict objectForKey: @"url"]] retain];
-        _title = [[dict objectForKey: @"title"] retain];
-        _displayTitle = [[dict objectForKey: @"displayTitle"] retain];
-        _comment = [[dict objectForKey: @"comment"] retain];
-        _creationDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
-            [[dict objectForKey: @"creationDate"] doubleValue]] retain];
-        _modificationDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
-            [[dict objectForKey: @"modificationDate"] doubleValue]] retain];
-        _lastVisitedDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
-            [[dict objectForKey: @"lastVisitedDate"] doubleValue]] retain];
-    }
+    storedURLString = [dict objectForKey: @"url"];
+    if (storedURLString != nil) {
+        _url = [[NSURL URLWithString:storedURLString] retain];
+    }
+    _title = [[dict objectForKey: @"title"] retain];
+    _displayTitle = [[dict objectForKey: @"displayTitle"] retain];
+    _comment = [[dict objectForKey: @"comment"] retain];
+    _creationDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
+        [[dict objectForKey: @"creationDate"] doubleValue]] retain];
+    _modificationDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
+        [[dict objectForKey: @"modificationDate"] doubleValue]] retain];
+    _lastVisitedDate = [[[NSCalendarDate alloc] initWithTimeIntervalSinceReferenceDate:
+        [[dict objectForKey: @"lastVisitedDate"] doubleValue]] retain];
 
     return self;
 }
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index 769ea28..6916c05 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -155,8 +155,8 @@
 			productName = WebKit;
 			productReference = 034768E0FF38A50411DB9C8B;
 			productSettingsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
-<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
-<plist version=\"1.0\">
+<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">
+<plist version=\"0.9\">
 <dict>
 	<key>CFBundleDevelopmentRegion</key>
 	<string>English</string>

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list