[webkit-changes] cvs commit: WebKit/WebView.subproj WebDataSource.m
WebDataSourcePrivate.h WebFrame.m WebFrameInternal.h
Maciej
mjs at opensource.apple.com
Sun Dec 25 03:05:05 PST 2005
mjs 05/12/25 03:05:05
Modified: . ChangeLog
WebView.subproj WebDataSource.m WebDataSourcePrivate.h
WebFrame.m WebFrameInternal.h
Log:
Reviewed by Geoff.
- rearrange some code in WebDataSource so that more of the frame traversal logic
is in WebFrame, in preparation for moving it down to WebBridge.
http://bugzilla.opendarwin.org/show_bug.cgi?id=6239
* WebView.subproj/WebDataSource.m:
(-[WebDataSource _archiveWithMarkupString:nodes:]): Assert that the
data source is committed, doesn't make sense to archive otherwise.
(-[WebDataSource _subframeArchivesWithCurrentState:]): New helper method.
(-[WebDataSource _archiveWithCurrentState:]): Assert that the data source
is committed. Use the helper.
(-[WebDataSource _setWebView:]): Comment that we won't tell subframes that
defers callback changed.
(-[WebDataSource _startLoading]): Remove stray space.
(-[WebDataSource _stopLoading]): Only handle local _stopLoading business.
Cound on WebFrame to tell subframes to stop loading. Fold in _stopLoadingInternal
and remove _recursiveStopLoading.
(-[WebDataSource _startLoading:]): Clean up an assert slightly.
(-[WebDataSource _setTitle:]): Remove stray spaces.
(-[WebDataSource _defersCallbacksChanged]): Don't call subframes. WebFrame
can do that.
(-[WebDataSource isLoading]): Move checking of subframes down to WebFrame.
(-[WebDataSource webArchive]): Return nil if the data source is not yet
committed. It makes no sense to archive a provisional data source since it
has no data yet.
(-[WebDataSource addSubresource:]): Replace an assert with an early return,
ASSERT is not an appropriate way to flag problems with the argument of a public
method.
* WebView.subproj/WebDataSourcePrivate.h:
* WebView.subproj/WebFrame.m:
(-[WebFrame _setLoadType:]): Remove stray space.
(-[WebFrame _checkLoadCompleteForThisFrame]): Stop loading subframes
manually and add a FIXME about confusingness of stopping loading here.
(-[WebFrame _defersCallbacksChanged]): Tell our subframes.
(-[WebFrame _addChild:]): Remove stray space.
(-[WebFrame _stopLoadingSubframes]): New helper method.
(-[WebFrame _subframeIsLoading]): New helper method, code moved
from WebDataSource.
(-[WebFrame stopLoading]): Tell subframes to stop loading.
(-[WebFrame reload]): Remove extra braces.
* WebView.subproj/WebFrameInternal.h:
Revision Changes Path
1.3427 +45 -0 WebKit/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebKit/ChangeLog,v
retrieving revision 1.3426
retrieving revision 1.3427
diff -u -r1.3426 -r1.3427
--- ChangeLog 24 Dec 2005 00:54:02 -0000 1.3426
+++ ChangeLog 25 Dec 2005 11:04:55 -0000 1.3427
@@ -1,3 +1,48 @@
+2005-12-24 Maciej Stachowiak <mjs at apple.com>
+
+ Reviewed by Geoff.
+
+ - rearrange some code in WebDataSource so that more of the frame traversal logic
+ is in WebFrame, in preparation for moving it down to WebBridge.
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=6239
+
+ * WebView.subproj/WebDataSource.m:
+ (-[WebDataSource _archiveWithMarkupString:nodes:]): Assert that the
+ data source is committed, doesn't make sense to archive otherwise.
+ (-[WebDataSource _subframeArchivesWithCurrentState:]): New helper method.
+ (-[WebDataSource _archiveWithCurrentState:]): Assert that the data source
+ is committed. Use the helper.
+ (-[WebDataSource _setWebView:]): Comment that we won't tell subframes that
+ defers callback changed.
+ (-[WebDataSource _startLoading]): Remove stray space.
+ (-[WebDataSource _stopLoading]): Only handle local _stopLoading business.
+ Cound on WebFrame to tell subframes to stop loading. Fold in _stopLoadingInternal
+ and remove _recursiveStopLoading.
+ (-[WebDataSource _startLoading:]): Clean up an assert slightly.
+ (-[WebDataSource _setTitle:]): Remove stray spaces.
+ (-[WebDataSource _defersCallbacksChanged]): Don't call subframes. WebFrame
+ can do that.
+ (-[WebDataSource isLoading]): Move checking of subframes down to WebFrame.
+ (-[WebDataSource webArchive]): Return nil if the data source is not yet
+ committed. It makes no sense to archive a provisional data source since it
+ has no data yet.
+ (-[WebDataSource addSubresource:]): Replace an assert with an early return,
+ ASSERT is not an appropriate way to flag problems with the argument of a public
+ method.
+ * WebView.subproj/WebDataSourcePrivate.h:
+ * WebView.subproj/WebFrame.m:
+ (-[WebFrame _setLoadType:]): Remove stray space.
+ (-[WebFrame _checkLoadCompleteForThisFrame]): Stop loading subframes
+ manually and add a FIXME about confusingness of stopping loading here.
+ (-[WebFrame _defersCallbacksChanged]): Tell our subframes.
+ (-[WebFrame _addChild:]): Remove stray space.
+ (-[WebFrame _stopLoadingSubframes]): New helper method.
+ (-[WebFrame _subframeIsLoading]): New helper method, code moved
+ from WebDataSource.
+ (-[WebFrame stopLoading]): Tell subframes to stop loading.
+ (-[WebFrame reload]): Remove extra braces.
+ * WebView.subproj/WebFrameInternal.h:
+
2005-12-23 Maciej Stachowiak <mjs at apple.com>
Reviewed by John.
1.217 +68 -97 WebKit/WebView.subproj/WebDataSource.m
Index: WebDataSource.m
===================================================================
RCS file: /cvs/root/WebKit/WebView.subproj/WebDataSource.m,v
retrieving revision 1.216
retrieving revision 1.217
diff -u -r1.216 -r1.217
--- WebDataSource.m 2 Dec 2005 22:53:31 -0000 1.216
+++ WebDataSource.m 25 Dec 2005 11:05:03 -0000 1.217
@@ -133,6 +133,8 @@
- (WebArchive *)_archiveWithMarkupString:(NSString *)markupString nodes:(NSArray *)nodes
{
+ ASSERT(_private->committed);
+
WebFrame *frame = [self webFrame];
NSURLResponse *response = [self response];
WebResource *mainResource = [[WebResource alloc] initWithData:[markupString dataUsingEncoding:NSUTF8StringEncoding]
@@ -174,23 +176,27 @@
return archive;
}
+- (NSArray *)_subframeArchivesWithCurrentState:(BOOL)currentState
+{
+ NSEnumerator *enumerator = [[[self webFrame] childFrames] objectEnumerator];
+ NSMutableArray *subframeArchives = [NSMutableArray array];
+ WebFrame *childFrame;
+ while ((childFrame = [enumerator nextObject])) {
+ [subframeArchives addObject:[[childFrame dataSource] _archiveWithCurrentState:currentState]];
+ }
+ return subframeArchives;
+}
+
- (WebArchive *)_archiveWithCurrentState:(BOOL)currentState
{
- if (currentState && [[self representation] conformsToProtocol:@protocol(WebDocumentDOM)]) {
+ ASSERT(_private->committed);
+
+ if (currentState && [[self representation] conformsToProtocol:@protocol(WebDocumentDOM)])
return [[(id <WebDocumentDOM>)[self representation] DOMDocument] webArchive];
- } else {
- NSEnumerator *enumerator = [[[self webFrame] childFrames] objectEnumerator];
- NSMutableArray *subframeArchives = [[NSMutableArray alloc] init];
- WebFrame *childFrame;
- while ((childFrame = [enumerator nextObject]) != nil) {
- [subframeArchives addObject:[[childFrame dataSource] _archiveWithCurrentState:currentState]];
- }
- WebArchive *archive = [[[WebArchive alloc] initWithMainResource:[self mainResource]
- subresources:[_private->subresources allValues]
- subframeArchives:subframeArchives] autorelease];
- [subframeArchives release];
- return archive;
- }
+ else
+ return [[[WebArchive alloc] initWithMainResource:[self mainResource]
+ subresources:[_private->subresources allValues]
+ subframeArchives:[self _subframeArchivesWithCurrentState:currentState]] autorelease];
}
- (void)_addSubframeArchives:(NSArray *)subframeArchives
@@ -308,7 +314,7 @@
[self _setLoading:_private->mainResourceLoader || [_private->subresourceLoaders count]];
}
-- (void)_setWebView: (WebView *)webView
+- (void)_setWebView:(WebView *)webView
{
if (_private->loading) {
[webView retain];
@@ -317,6 +323,8 @@
_private->webView = webView;
[self _defersCallbacksChanged];
+ // no need to do _defersCallbacksChanged for subframes since they too
+ // will be or have been told of their WebView
}
- (void)_setData:(NSData *)data
@@ -348,25 +356,55 @@
- (void)_startLoading
{
- [self _startLoading: nil];
+ [self _startLoading:nil];
}
// Cancels any pending loads. A data source is conceptually only ever loading
// one document at a time, although one document may have many related
// resources. stopLoading will stop all loads related to the data source. This
-// method will also stop loads that may be loading in child frames.
+// method will not stop loads that may be happening in child frames, that is the
+// WebFrame's job
- (void)_stopLoading
{
- [self _recursiveStopLoading];
-}
+ [self retain];
+ // Always attempt to stop the icon loader because it may still be loading after the data source
+ // is done loading and not stopping it can cause a world leak.
+ [_private->iconLoader stopLoading];
-- (void)_startLoading: (NSDictionary *)pageCache
+ // The same goes for the bridge/part, which may still be parsing.
+ if (_private->committed)
+ [[self _bridge] stopLoading];
+
+ if (!_private->loading)
+ return;
+
+ _private->stopping = YES;
+
+ if (_private->mainResourceLoader) {
+ // Stop the main handle and let it set the cancelled error.
+ [_private->mainResourceLoader cancel];
+ } else {
+ // Main handle is already done. Set the cancelled error.
+ NSError *cancelledError = [NSError _webKitErrorWithDomain:NSURLErrorDomain
+ code:NSURLErrorCancelled
+ URL:[self _URL]];
+ [self _setMainDocumentError:cancelledError];
+ }
+
+ NSArray *loaders = [_private->subresourceLoaders copy];
+ [loaders makeObjectsPerformSelector:@selector(cancel)];
+ [loaders release];
+
+ [self release];
+}
+
+- (void)_startLoading:(NSDictionary *)pageCache
{
- ASSERT([self _isStopping] == NO);
+ ASSERT(![self _isStopping]);
- [self _setPrimaryLoadComplete: NO];
+ [self _setPrimaryLoadComplete:NO];
ASSERT([self webFrame] != nil);
@@ -446,50 +484,6 @@
return _private->stopping;
}
-- (void)_stopLoadingInternal
-{
- // Always attempt to stop the icon loader because it may still be loading after the data source
- // is done loading and not stopping it can cause a world leak.
- [_private->iconLoader stopLoading];
-
- // The same goes for the bridge/part, which may still be parsing.
- if (_private->committed)
- [[self _bridge] stopLoading];
-
- if (!_private->loading) {
- return;
- }
-
- _private->stopping = YES;
-
- if(_private->mainResourceLoader){
- // Stop the main handle and let it set the cancelled error.
- [_private->mainResourceLoader cancel];
- }else{
- // Main handle is already done. Set the cancelled error.
- NSError *cancelledError = [NSError _webKitErrorWithDomain:NSURLErrorDomain
- code:NSURLErrorCancelled
- URL:[self _URL]];
- [self _setMainDocumentError:cancelledError];
- }
-
- NSArray *loaders = [_private->subresourceLoaders copy];
- [loaders makeObjectsPerformSelector:@selector(cancel)];
- [loaders release];
-}
-
-- (void)_recursiveStopLoading
-{
- [self retain];
-
- // We depend on the WebView in the webFrame method and we release it in _stopLoading,
- // so call webFrame first so we don't send a message the released WebView (3129503).
- [[[self webFrame] childFrames] makeObjectsPerformSelector:@selector(stopLoading)];
- [self _stopLoadingInternal];
-
- [self release];
-}
-
- (double)_loadingStartedTime
{
return _private->loadingStartedTime;
@@ -529,10 +523,10 @@
if (!trimmed || [trimmed length] == 0)
return;
- [_private->webView _willChangeValueForKey: _WebMainFrameTitleKey];
+ [_private->webView _willChangeValueForKey:_WebMainFrameTitleKey];
[_private->pageTitle release];
_private->pageTitle = [trimmed copy];
- [_private->webView _didChangeValueForKey: _WebMainFrameTitleKey];
+ [_private->webView _didChangeValueForKey:_WebMainFrameTitleKey];
// The title doesn't get communicated to the WebView until we are committed.
if (_private->committed) {
@@ -906,11 +900,6 @@
while ((loader = [e nextObject])) {
[loader setDefersCallbacks:defers];
}
-
- // It's OK to use the internal version of getting the child
- // frames, since undeferring callbacks will not do any immediate
- // work, and so the set of frames can't change out from under us.
- [[[self webFrame] _internalChildFrames] makeObjectsPerformSelector:@selector(_defersCallbacksChanged)];
}
- (NSURLRequest *)_originalRequest
@@ -930,7 +919,6 @@
return [[_private->triggeringAction retain] autorelease];
}
-
- (NSURLRequest *)_lastCheckedRequest
{
// It's OK not to make a copy here because we know the caller
@@ -1179,27 +1167,9 @@
return YES;
}
- // Put in the auto-release pool because it's common to call this from a run loop source,
- // and then the entire list of frames lasts until the next autorelease.
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
-
- // It's OK to use the internal version of getting the child
- // frames, since nothing we do here can possibly change the set of
- // frames.
- NSEnumerator *e = [[[self webFrame] _internalChildFrames] objectEnumerator];
- WebFrame *childFrame;
- while ((childFrame = [e nextObject])) {
- if ([[childFrame dataSource] isLoading] || [[childFrame provisionalDataSource] isLoading]) {
- break;
- }
- }
-
- [pool drain];
-
- return childFrame != nil;
+ return [[self webFrame] _subframeIsLoading];
}
-
// Returns nil or the page title.
- (NSString *)pageTitle
{
@@ -1213,6 +1183,10 @@
- (WebArchive *)webArchive
{
+ // it makes no sense to grab a WebArchive from an uncommitted document.
+ if (!_private->committed)
+ return nil;
+
return [self _archiveWithCurrentState:NO];
}
@@ -1238,11 +1212,8 @@
- (void)addSubresource:(WebResource *)subresource
{
- if (subresource) {
+ if (subresource)
[_private->subresources setObject:subresource forKey:[[subresource URL] _web_originalDataAsString]];
- } else {
- ASSERT_NOT_REACHED();
- }
}
@end
1.148 +0 -2 WebKit/WebView.subproj/WebDataSourcePrivate.h
Index: WebDataSourcePrivate.h
===================================================================
RCS file: /cvs/root/WebKit/WebView.subproj/WebDataSourcePrivate.h,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -r1.147 -r1.148
--- WebDataSourcePrivate.h 2 Dec 2005 22:53:31 -0000 1.147
+++ WebDataSourcePrivate.h 25 Dec 2005 11:05:03 -0000 1.148
@@ -162,9 +162,7 @@
- (void)_setRepresentation:(id<WebDocumentRepresentation>)representation;
- (void)_setWebView:(WebView *)webView;
- (void)_startLoading:(NSDictionary *)pageCache;
-- (void)_stopLoadingInternal;
- (BOOL)_isStopping;
-- (void)_recursiveStopLoading;
- (void)_addSubresourceLoader:(WebLoader *)loader;
- (void)_removeSubresourceLoader:(WebLoader *)loader;
- (void)_addPlugInStreamLoader:(WebLoader *)loader;
1.263 +49 -8 WebKit/WebView.subproj/WebFrame.m
Index: WebFrame.m
===================================================================
RCS file: /cvs/root/WebKit/WebView.subproj/WebFrame.m,v
retrieving revision 1.262
retrieving revision 1.263
diff -u -r1.262 -r1.263
--- WebFrame.m 24 Dec 2005 00:54:09 -0000 1.262
+++ WebFrame.m 25 Dec 2005 11:05:04 -0000 1.263
@@ -185,6 +185,7 @@
- (WebHistoryItem *)_createItem: (BOOL)useOriginal;
- (WebHistoryItem *)_createItemTreeWithTargetFrame:(WebFrame *)targetFrame clippedAtTarget:(BOOL)doClip;
- (WebHistoryItem *)_currentBackForwardListItemToResetTo;
+- (void)_stopLoadingSubframes;
@end
@interface WebFramePrivate : NSObject
@@ -674,7 +675,7 @@
- (void)_setLoadType: (WebFrameLoadType)t
{
- [_private setLoadType: t];
+ [_private setLoadType:t];
}
- (WebFrameLoadType)_loadType
@@ -1123,14 +1124,21 @@
forFrame:self];
_private->delegateIsHandlingProvisionalLoadError = NO;
[_private->internalLoadDelegate webFrame:self didFinishLoadWithError:error];
-
+
+ // FIXME: can stopping loading here possibly have
+ // any effect, if isLoading is false, which it
+ // must be, to be in this branch of the if? And is it ok to just do
+ // a full-on stopLoading?
+ [self _stopLoadingSubframes];
[pd _stopLoading];
+
+
// Finish resetting the load state, but only if another load hasn't been started by the
// delegate callback.
if (pd == _private->provisionalDataSource) {
[self _setProvisionalDataSource:nil];
- [[self webView] _progressCompleted: self];
+ [[self webView] _progressCompleted:self];
[self _setState:WebFrameStateComplete];
} else {
@@ -2145,6 +2153,11 @@
{
[[self provisionalDataSource] _defersCallbacksChanged];
[[self dataSource] _defersCallbacksChanged];
+
+ // It's OK to use the internal version of getting the child
+ // frames, since undeferring callbacks will not do any immediate
+ // work, and so the set of frames can't change out from under us.
+ [[self _internalChildFrames] makeObjectsPerformSelector:@selector(_defersCallbacksChanged)];
}
- (void)_viewWillMoveToHostWindow:(NSWindow *)hostWindow
@@ -2200,7 +2213,7 @@
// we keep track of sibling pointers to avoid the overhead of a lookup in the children array
if (currentIndex > 0) {
- WebFrame *previousFrame = [[self childFrames] objectAtIndex: currentIndex - 1];
+ WebFrame *previousFrame = [[self childFrames] objectAtIndex:currentIndex - 1];
previousFrame->_private->nextSibling = child;
child->_private->previousSibling = previousFrame;
ASSERT(child->_private->nextSibling == nil);
@@ -2889,6 +2902,34 @@
ASSERT([[[self webView] mainFrame] _atMostOneFrameHasSelection]);
}
+- (void)_stopLoadingSubframes
+{
+ [[self childFrames] makeObjectsPerformSelector:@selector(stopLoading)];
+}
+
+- (BOOL)_subframeIsLoading
+{
+ // Put in the auto-release pool because it's common to call this from a run loop source,
+ // and then the entire list of frames lasts until the next autorelease.
+ // FIXME: is this really still true? we use _internalChildFrames now which does not
+ // make a copy.
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
+ // It's OK to use the internal version of getting the child
+ // frames, since nothing we do here can possibly change the set of
+ // frames.
+ NSEnumerator *e = [[self _internalChildFrames] objectEnumerator];
+ WebFrame *childFrame;
+ while ((childFrame = [e nextObject])) {
+ if ([[childFrame dataSource] isLoading] || [[childFrame provisionalDataSource] isLoading])
+ break;
+ }
+
+ [pool drain];
+
+ return childFrame != nil;
+}
+
@end
@implementation WebFormState : NSObject
@@ -3086,13 +3127,14 @@
- (void)stopLoading
{
// If this method is called from within this method, infinite recursion can occur (3442218). Avoid this.
- if (_private->isStoppingLoad) {
+ if (_private->isStoppingLoad)
return;
- }
+
_private->isStoppingLoad = YES;
[self _invalidatePendingPolicyDecisionCallingDefaultAction:YES];
+ [self _stopLoadingSubframes];
[_private->provisionalDataSource _stopLoading];
[_private->dataSource _stopLoading];
@@ -3106,9 +3148,8 @@
- (void)reload
{
WebDataSource *dataSource = [self dataSource];
- if (dataSource == nil) {
+ if (dataSource == nil)
return;
- }
NSMutableURLRequest *initialRequest = [dataSource request];
1.18 +1 -0 WebKit/WebView.subproj/WebFrameInternal.h
Index: WebFrameInternal.h
===================================================================
RCS file: /cvs/root/WebKit/WebView.subproj/WebFrameInternal.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- WebFrameInternal.h 24 Dec 2005 00:54:09 -0000 1.17
+++ WebFrameInternal.h 25 Dec 2005 11:05:04 -0000 1.18
@@ -57,6 +57,7 @@
- (void)_clearSelection;
- (WebFrame *)_findFrameWithSelection;
- (void)_clearSelectionInOtherFrames;
+- (BOOL)_subframeIsLoading;
@end
More information about the webkit-changes
mailing list