[webkit-changes] cvs commit: WebKit/WebView.subproj WebFrame.m

John sullivan at opensource.apple.com
Tue Nov 1 11:24:52 PST 2005


sullivan    05/11/01 11:24:51

  Modified:    .        ChangeLog
               History.subproj WebHistory.m WebHistoryItem.m
                        WebHistoryItemPrivate.h WebHistoryPrivate.h
               WebView.subproj WebFrame.m
  Log:
          Reviewed by Tim Omernick.
  
          - fixed <rdar://problem/4324104> Assertion failure (foundDate) in WebHistory
  
          WebFrame was updating the last visited date on a WebHistoryItem behind WebHistory's
          back, causing WebHistory's caches of items by date to get out of sync with reality.
          Changed to set the date through WebHistory rather than directly.
  
          * History.subproj/WebHistory.m:
          (-[WebHistoryPrivate _removeItemFromDateCaches:]):
          New method, extracted from removeItemForURLString.
          (-[WebHistoryPrivate removeItemForURLString:]):
          Now calls extracted method. Cleaned up white space a little.
          (-[WebHistoryPrivate _addItemToDateCaches:]):
          New method, extracted from addItem:
          (-[WebHistoryPrivate addItem:]):
          Now calls extracted method. Cleaned up white space a little.
          (-[WebHistoryPrivate setLastVisitedTimeInterval:forItem:]):
          New method, removes item from date caches, changes date, then adds item back to
          date caches and sends notification.
          (-[WebHistory setLastVisitedTimeInterval:forItem:]):
          New method, cover for WebHistoryPrivate version.
  
          * History.subproj/WebHistoryItem.m:
          (-[WebHistoryItem _setLastVisitedTimeInterval:]):
          Don't send notification here; send from new WebHistory method instead.
  
          * History.subproj/WebHistoryItemPrivate.h:
          Added comment about avoiding incorrect use of _setLastVisitedTimeInterval:
          * History.subproj/WebHistoryPrivate.h:
          Added declarations for WebHistory and WebHistoryPrivate versions of
          setLastVisitedTimeInterval:forItem:
  
          * WebView.subproj/WebFrame.m:
          (-[WebFrame _transitionToCommitted:]):
          change history item's date via new WebHistory method rather than directly
  
  Revision  Changes    Path
  1.3364    +39 -0     WebKit/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebKit/ChangeLog,v
  retrieving revision 1.3363
  retrieving revision 1.3364
  diff -u -r1.3363 -r1.3364
  --- ChangeLog	25 Oct 2005 19:32:27 -0000	1.3363
  +++ ChangeLog	1 Nov 2005 19:24:45 -0000	1.3364
  @@ -1,3 +1,42 @@
  +2005-11-01  John Sullivan  <sullivan at apple.com>
  +
  +        Reviewed by Tim Omernick.
  +        
  +        - fixed <rdar://problem/4324104> Assertion failure (foundDate) in WebHistory
  +        
  +        WebFrame was updating the last visited date on a WebHistoryItem behind WebHistory's
  +        back, causing WebHistory's caches of items by date to get out of sync with reality.
  +        Changed to set the date through WebHistory rather than directly.
  +
  +        * History.subproj/WebHistory.m:
  +        (-[WebHistoryPrivate _removeItemFromDateCaches:]):
  +        New method, extracted from removeItemForURLString.
  +        (-[WebHistoryPrivate removeItemForURLString:]):
  +        Now calls extracted method. Cleaned up white space a little.
  +        (-[WebHistoryPrivate _addItemToDateCaches:]):
  +        New method, extracted from addItem:
  +        (-[WebHistoryPrivate addItem:]):
  +        Now calls extracted method. Cleaned up white space a little.
  +        (-[WebHistoryPrivate setLastVisitedTimeInterval:forItem:]):
  +        New method, removes item from date caches, changes date, then adds item back to
  +        date caches and sends notification.
  +        (-[WebHistory setLastVisitedTimeInterval:forItem:]):
  +        New method, cover for WebHistoryPrivate version.
  +        
  +        * History.subproj/WebHistoryItem.m:
  +        (-[WebHistoryItem _setLastVisitedTimeInterval:]):
  +        Don't send notification here; send from new WebHistory method instead.
  +        
  +        * History.subproj/WebHistoryItemPrivate.h:
  +        Added comment about avoiding incorrect use of _setLastVisitedTimeInterval:
  +        * History.subproj/WebHistoryPrivate.h:
  +        Added declarations for WebHistory and WebHistoryPrivate versions of 
  +        setLastVisitedTimeInterval:forItem:
  +        
  +        * WebView.subproj/WebFrame.m:
  +        (-[WebFrame _transitionToCommitted:]):
  +        change history item's date via new WebHistory method rather than directly
  +
   2005-10-25  Timothy Hatcher  <timothy at apple.com>
   
           Reviewed by Darin.
  
  
  
  1.40      +58 -33    WebKit/History.subproj/WebHistory.m
  
  Index: WebHistory.m
  ===================================================================
  RCS file: /cvs/root/WebKit/History.subproj/WebHistory.m,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- WebHistory.m	5 Jun 2005 17:54:23 -0000	1.39
  +++ WebHistory.m	1 Nov 2005 19:24:49 -0000	1.40
  @@ -138,66 +138,86 @@
       [entriesForDate insertObject: entry atIndex: index];
   }
   
  -- (BOOL)removeItemForURLString: (NSString *)URLString
  +- (BOOL)_removeItemFromDateCaches:(WebHistoryItem *)entry
   {
  -    NSMutableArray *entriesForDate;
  -    WebHistoryItem *entry;
       int dateIndex;
  -    BOOL foundDate;
  -
  -    entry = [_entriesByURL objectForKey: URLString];
  -    if (entry == nil) {
  +    BOOL foundDate = [self findIndex: &dateIndex forDay: [entry _lastVisitedDate]];
  + 
  +    if (!foundDate)
           return NO;
  -    }
  -
  -    [_entriesByURL removeObjectForKey: URLString];
  -
  -    foundDate = [self findIndex: &dateIndex forDay: [entry _lastVisitedDate]];
  -
  -    ASSERT(foundDate);
       
  -    entriesForDate = [_entriesByDate objectAtIndex: dateIndex];
  +    NSMutableArray *entriesForDate = [_entriesByDate objectAtIndex: dateIndex];
       [entriesForDate removeObjectIdenticalTo: entry];
  -
  +    
       // remove this date entirely if there are no other entries on it
       if ([entriesForDate count] == 0) {
           [_entriesByDate removeObjectAtIndex: dateIndex];
           [_datesWithEntries removeObjectAtIndex: dateIndex];
       }
  -
  +    
       return YES;
   }
   
  +- (BOOL)removeItemForURLString: (NSString *)URLString
  +{
  +    WebHistoryItem *entry = [_entriesByURL objectForKey: URLString];
  +    if (entry == nil) {
  +        return NO;
  +    }
   
  -- (void)addItem: (WebHistoryItem *)entry
  +    [_entriesByURL removeObjectForKey: URLString];
  +    
  +    BOOL itemWasInDateCaches = [self _removeItemFromDateCaches:entry];
  +    ASSERT(itemWasInDateCaches);
  +
  +    return YES;
  +}
  +
  +- (void)_addItemToDateCaches:(WebHistoryItem *)entry
   {
       int dateIndex;
  -    NSString *URLString;
  +    if ([self findIndex:&dateIndex forDay:[entry _lastVisitedDate]]) {
  +        // other entries already exist for this date
  +        [self insertItem:entry atDateIndex:dateIndex];
  +    } else {
  +        // no other entries exist for this date
  +        [_datesWithEntries insertObject:[entry _lastVisitedDate] atIndex:dateIndex];
  +        [_entriesByDate insertObject:[NSMutableArray arrayWithObject:entry] atIndex:dateIndex];
  +    }
  +}
   
  +- (void)addItem:(WebHistoryItem *)entry
  +{
       ASSERT_ARG(entry, entry);
       ASSERT_ARG(entry, [entry lastVisitedTimeInterval] != 0);
   
  -    URLString = [entry URLString];
  +    NSString *URLString = [entry URLString];
   
  -    // If we already have an item with this URL, we need to merge info that drives the
  -    // URL autocomplete heuristics from that item into the new one.
  -    WebHistoryItem *oldEntry = [_entriesByURL objectForKey: URLString];
  +    WebHistoryItem *oldEntry = [_entriesByURL objectForKey:URLString];
       if (oldEntry) {
  +        [self removeItemForURLString:URLString];
  +
  +        // If we already have an item with this URL, we need to merge info that drives the
  +        // URL autocomplete heuristics from that item into the new one.
           [entry _mergeAutoCompleteHints:oldEntry];
       }
   
  -    [self removeItemForURLString: URLString];
  +    [self _addItemToDateCaches:entry];
  +    [_entriesByURL setObject:entry forKey:URLString];
  +}
   
  -    if ([self findIndex: &dateIndex forDay: [entry _lastVisitedDate]]) {
  -        // other entries already exist for this date
  -        [self insertItem: entry atDateIndex: dateIndex];
  -    } else {
  -        // no other entries exist for this date
  -        [_datesWithEntries insertObject: [entry _lastVisitedDate] atIndex: dateIndex];
  -        [_entriesByDate insertObject: [NSMutableArray arrayWithObject:entry] atIndex: dateIndex];
  -    }
  +- (void)setLastVisitedTimeInterval:(NSTimeInterval)time forItem:(WebHistoryItem *)entry
  +{
  +    BOOL entryWasPresent = [self _removeItemFromDateCaches:entry];
  +    ASSERT(entryWasPresent);
  +    
  +    [entry _setLastVisitedTimeInterval:time];
  +    [self _addItemToDateCaches:entry];
   
  -    [_entriesByURL setObject: entry forKey: URLString];
  +    // Don't send notification until entry is back in the right place in the date caches,
  +    // since observers might fetch history by date when they receive the notification.
  +    [[NSNotificationCenter defaultCenter]
  +        postNotificationName:WebHistoryItemChangedNotification object:entry userInfo:nil];
   }
   
   - (BOOL)removeItem: (WebHistoryItem *)entry
  @@ -760,6 +780,11 @@
                       entries: newEntries];
   }
   
  +- (void)setLastVisitedTimeInterval:(NSTimeInterval)time forItem:(WebHistoryItem *)entry
  +{
  +    [_historyPrivate setLastVisitedTimeInterval:time forItem:entry];
  +}
  +
   #pragma mark DATE-BASED RETRIEVAL
   
   - (NSArray *)orderedLastVisitedDays
  
  
  
  1.93      +0 -3      WebKit/History.subproj/WebHistoryItem.m
  
  Index: WebHistoryItem.m
  ===================================================================
  RCS file: /cvs/root/WebKit/History.subproj/WebHistoryItem.m,v
  retrieving revision 1.92
  retrieving revision 1.93
  diff -u -r1.92 -r1.93
  --- WebHistoryItem.m	27 Jul 2005 21:36:43 -0000	1.92
  +++ WebHistoryItem.m	1 Nov 2005 19:24:49 -0000	1.93
  @@ -384,9 +384,6 @@
           _private->lastVisitedDate = nil;
           _private->visitCount++;
       }
  -
  -    [[NSNotificationCenter defaultCenter]
  -        postNotificationName: WebHistoryItemChangedNotification object: self userInfo: nil];
   }
   
   // FIXME:  Remove this accessor and related ivar.
  
  
  
  1.16      +3 -0      WebKit/History.subproj/WebHistoryItemPrivate.h
  
  Index: WebHistoryItemPrivate.h
  ===================================================================
  RCS file: /cvs/root/WebKit/History.subproj/WebHistoryItemPrivate.h,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- WebHistoryItemPrivate.h	27 Jul 2005 21:36:43 -0000	1.15
  +++ WebHistoryItemPrivate.h	1 Nov 2005 19:24:50 -0000	1.16
  @@ -84,6 +84,9 @@
   - (BOOL)alwaysAttemptToUsePageCache;
   
   - (NSCalendarDate *)_lastVisitedDate;
  +
  +// This should not be called directly for WebHistoryItems that are already included
  +// in WebHistory. Use -[WebHistory setLastVisitedTimeInterval:forItem:] instead.
   - (void)_setLastVisitedTimeInterval:(NSTimeInterval)time;
   
   @end
  
  
  
  1.24      +3 -0      WebKit/History.subproj/WebHistoryPrivate.h
  
  Index: WebHistoryPrivate.h
  ===================================================================
  RCS file: /cvs/root/WebKit/History.subproj/WebHistoryPrivate.h,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- WebHistoryPrivate.h	5 Jun 2005 17:54:23 -0000	1.23
  +++ WebHistoryPrivate.h	1 Nov 2005 19:24:50 -0000	1.24
  @@ -49,6 +49,7 @@
   - (BOOL)removeItem:(WebHistoryItem *)entry;
   - (BOOL)removeItems:(NSArray *)entries;
   - (BOOL)removeAllItems;
  +- (void)setLastVisitedTimeInterval:(NSTimeInterval)time forItem:(WebHistoryItem *)item;
   
   - (NSArray *)orderedLastVisitedDays;
   - (NSArray *)orderedItemsLastVisitedOnDay:(NSCalendarDate *)calendarDate;
  @@ -72,6 +73,8 @@
   @interface WebHistory (WebPrivate)
   - (void)removeItem:(WebHistoryItem *)entry;
   - (void)addItem:(WebHistoryItem *)entry;
  +// Change date on existing item
  +- (void)setLastVisitedTimeInterval:(NSTimeInterval)time forItem:(WebHistoryItem *)item;
   
   - (BOOL)loadHistory;
   - initWithFile:(NSString *)file;
  
  
  
  1.254     +5 -4      WebKit/WebView.subproj/WebFrame.m
  
  Index: WebFrame.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebFrame.m,v
  retrieving revision 1.253
  retrieving revision 1.254
  diff -u -r1.253 -r1.254
  --- WebFrame.m	13 Oct 2005 01:08:23 -0000	1.253
  +++ WebFrame.m	1 Nov 2005 19:24:50 -0000	1.254
  @@ -816,10 +816,11 @@
                   // Update the last visited time.  Mostly interesting for URL autocompletion
                   // statistics.
                   NSURL *URL = [[[ds _originalRequest] URL] _webkit_canonicalize];
  -                WebHistoryItem *oldItem = [[WebHistory optionalSharedHistory] itemForURL:URL];
  -                if (oldItem) {
  -                    [oldItem _setLastVisitedTimeInterval:[NSDate timeIntervalSinceReferenceDate]];
  -                }
  +                WebHistory *sharedHistory = [WebHistory optionalSharedHistory];
  +                WebHistoryItem *oldItem = [sharedHistory itemForURL:URL];
  +                if (oldItem)
  +                    [sharedHistory setLastVisitedTimeInterval:[NSDate timeIntervalSinceReferenceDate] forItem:oldItem];
  +                
                   [self _makeDocumentView];
                   break;
               }
  
  
  



More information about the webkit-changes mailing list