+2006-10-09 Darin Adler <darin@apple.com>
+
+ Reviewed by Brady.
+
+ - removed almost all direct use of WebView from WebFrameLoader
+
+ * Loader/WebFrameLoader.m:
+ (-[WebFrameLoader defersCallbacksChanged]):
+ (-[WebFrameLoader defersCallbacks]):
+ (-[WebFrameLoader clearProvisionalLoad]):
+ (-[WebFrameLoader _willSendRequest:forResource:redirectResponse:]):
+ (-[WebFrameLoader _didReceiveResponse:forResource:]):
+ (-[WebFrameLoader _didReceiveData:contentLength:forResource:]):
+ (-[WebFrameLoader _didFinishLoadingForResource:]):
+ (-[WebFrameLoader _didFailLoadingWithError:forResource:]):
+ (-[WebFrameLoader closeOldDataSources]):
+ (-[WebFrameLoader _notifyIconChanged:]):
+ (-[WebFrameLoader prepareForLoadStart]):
+ (-[WebFrameLoader willChangeTitleForDocument:]):
+ (-[WebFrameLoader didChangeTitleForDocument:]):
+ (-[WebFrameLoader continueAfterNewWindowPolicy:]):
+ (-[WebFrameLoader continueAfterNavigationPolicy:]):
+ (-[WebFrameLoader continueLoadRequestAfterNavigationPolicy:formState:]):
+ (-[WebFrameLoader didFirstLayout]):
+ (-[WebFrameLoader transitionToCommitted:]):
+ (-[WebFrameLoader checkLoadCompleteForThisFrame]):
+ (-[WebFrameLoader addExtraFieldsToRequest:mainResource:alwaysFromRequest:]):
+ * Loader/WebFrameLoaderClient.h:
+ * WebKit.xcodeproj/project.pbxproj:
+ * WebView/WebFrame.m:
+ (-[WebFrame _currentBackForwardListItemToResetTo]):
+ (-[WebFrame _hasBackForwardList]):
+ (-[WebFrame _resetBackForwardList]):
+ (-[WebFrame _dispatchDidReceiveIcon:]):
+ (-[WebFrame _dispatchDidStartProvisionalLoadForFrame]):
+ (-[WebFrame _dispatchDidCommitLoadForFrame]):
+ (-[WebFrame _dispatchDidFailProvisionalLoadWithError:]):
+ (-[WebFrame _dispatchDidFailLoadWithError:]):
+ (-[WebFrame _dispatchDidFinishLoadForFrame]):
+ (-[WebFrame _progressStarted]):
+ (-[WebFrame _progressCompleted]):
+ (-[WebFrame _incrementProgressForIdentifier:response:]):
+ (-[WebFrame _incrementProgressForIdentifier:data:]):
+ (-[WebFrame _completeProgressForIdentifier:]):
+ (-[WebFrame _setMainFrameDocumentReady:]):
+ (-[WebFrame _willChangeTitleForDocument:]):
+ (-[WebFrame _didChangeTitleForDocument:]):
+ (-[WebFrame _startDownloadWithRequest:]):
+
2006-10-09 Maciej Stachowiak <mjs@apple.com>
Reviewed by Alice.
- (void)defersCallbacksChanged
{
- BOOL defers = [[client webView] defersCallbacks];
+ BOOL defers = [[client _bridge] defersLoading];
for (WebFrame *frame = client; frame; frame = [frame _traverseNextFrameStayWithin:client])
[[frame _frameLoader] setDefersCallbacks:defers];
}
- (BOOL)defersCallbacks
{
- return [[client webView] defersCallbacks];
+ return [[client _bridge] defersLoading];
}
- (void)setDefersCallbacks:(BOOL)defers
- (void)clearProvisionalLoad
{
[self setProvisionalDocumentLoader:nil];
- [[client webView] _progressCompleted:client];
+ [client _progressCompleted];
[self setState:WebFrameStateComplete];
}
- (NSURLRequest *)_willSendRequest:(NSMutableURLRequest *)clientRequest forResource:(id)identifier redirectResponse:(NSURLResponse *)redirectResponse
{
- WebView *webView = [client webView];
- [clientRequest setValue:[webView userAgentForURL:[clientRequest URL]] forHTTPHeaderField:@"User-Agent"];
+ [clientRequest setValue:[[client _bridge] userAgentForURL:[clientRequest URL]] forHTTPHeaderField:@"User-Agent"];
return [client _dispatchResource:identifier willSendRequest:clientRequest redirectResponse:redirectResponse fromDocumentLoader:[self activeDocumentLoader]];
}
{
[[self activeDocumentLoader] addResponse:r];
- [[client webView] _incrementProgressForIdentifier:identifier response:r];
+ [client _incrementProgressForIdentifier:identifier response:r];
[client _dispatchResource:identifier didReceiveResponse:r fromDocumentLoader:[self activeDocumentLoader]];
}
- (void)_didReceiveData:(NSData *)data contentLength:(int)lengthReceived forResource:(id)identifier
{
- WebView *webView = [client webView];
- [webView _incrementProgressForIdentifier:identifier data:data];
-
+ [client _incrementProgressForIdentifier:identifier data:data];
[client _dispatchResource:identifier didReceiveContentLength:lengthReceived fromDocumentLoader:[self activeDocumentLoader]];
}
- (void)_didFinishLoadingForResource:(id)identifier
{
- WebView *webView = [client webView];
- [webView _completeProgressForIdentifier:identifier];
+ [client _completeProgressForIdentifier:identifier];
[client _dispatchResource:identifier didFinishLoadingFromDocumentLoader:[self activeDocumentLoader]];
}
- (void)_didFailLoadingWithError:(NSError *)error forResource:(id)identifier
{
- WebView *webView = [client webView];
-
- [webView _completeProgressForIdentifier:identifier];
-
+ [client _completeProgressForIdentifier:identifier];
if (error)
[client _dispatchResource:identifier didFailLoadingWithError:error fromDocumentLoader:[self activeDocumentLoader]];
}
if (documentLoader)
[client _dispatchWillCloseFrame];
- [[client webView] setMainFrameDocumentReady:NO]; // stop giving out the actual DOMDocument to observers
+ [client _setMainFrameDocumentReady:NO]; // stop giving out the actual DOMDocument to observers
}
// Called after we send an openURL:... down to WebCore.
- (void)_notifyIconChanged:(NSURL *)iconURL
{
ASSERT([[WebIconDatabase sharedIconDatabase] _isEnabled]);
- ASSERT(client == [[client webView] mainFrame]);
-
- [[client webView] _willChangeValueForKey:_WebMainFrameIconKey];
-
NSImage *icon = [[WebIconDatabase sharedIconDatabase] iconForURL:[[[self activeDocumentLoader] URL] _web_originalDataAsString] withSize:WebIconSmallSize];
-
[client _dispatchDidReceiveIcon:icon];
-
- [[client webView] _didChangeValueForKey:_WebMainFrameIconKey];
}
- (NSURL *)_URL
- (void)prepareForLoadStart
{
- [[client webView] _progressStarted:client];
- [[client webView] _didStartProvisionalLoadForFrame:client];
+ [client _progressStarted];
[client _dispatchDidStartProvisionalLoadForFrame];
}
- (void)willChangeTitleForDocument:(WebDocumentLoader *)loader
{
- // FIXME: should do this only in main frame case, right?
- [[client webView] _willChangeValueForKey:_WebMainFrameTitleKey];
+ [client _willChangeTitleForDocument:loader];
}
- (void)didChangeTitleForDocument:(WebDocumentLoader *)loader
{
- // FIXME: should do this only in main frame case, right?
- [[client webView] _didChangeValueForKey:_WebMainFrameTitleKey];
+ [client _didChangeTitleForDocument:loader];
// The title doesn't get communicated to the WebView until we are committed.
if ([loader isCommitted]) {
// Must update the entries in the back-forward list too.
// This must go through the WebFrame because it has the right notion of the current b/f item.
[client _setTitle:[loader title] forURL:URLForHistory];
- [[client webView] setMainFrameDocumentReady:YES]; // update observers with new DOMDocument
-
+ [client _setMainFrameDocumentReady:YES]; // update observers with new DOMDocument
[client _dispatchDidReceiveTitle:[loader title]];
}
}
// will release policy* objects, hence the above retains
[self invalidatePendingPolicyDecisionCallingDefaultAction:NO];
- BOOL shouldContinue = NO;
-
switch (policy) {
- case WebPolicyIgnore:
- break;
- case WebPolicyDownload:
- // FIXME: should download full request
- [[client webView] _downloadURL:[request URL]];
- break;
- case WebPolicyUse:
- shouldContinue = YES;
- break;
- default:
- ASSERT_NOT_REACHED();
+ case WebPolicyIgnore:
+ request = nil;
+ break;
+ case WebPolicyDownload:
+ [client _startDownloadWithRequest:request];
+ request = nil;
+ break;
+ case WebPolicyUse:
+ break;
}
- objc_msgSend(target, selector, shouldContinue ? request : nil, frameName, formState);
+ objc_msgSend(target, selector, request, frameName, formState);
}
- (void)checkNavigationPolicyForRequest:(NSURLRequest *)request
// will release policy* objects, hence the above retains
[self invalidatePendingPolicyDecisionCallingDefaultAction:NO];
- BOOL shouldContinue = NO;
-
switch (policy) {
- case WebPolicyIgnore:
- break;
- case WebPolicyDownload:
- // FIXME: should download full request
- [[client webView] _downloadURL:[request URL]];
- break;
- case WebPolicyUse:
- if (![WebView _canHandleRequest:request]) {
- [self handleUnimplementablePolicyWithErrorCode:WebKitErrorCannotShowURL forURL:[request URL]];
- } else {
- shouldContinue = YES;
- }
- break;
- default:
- ASSERT_NOT_REACHED();
+ case WebPolicyIgnore:
+ request = nil;
+ break;
+ case WebPolicyDownload:
+ [client _startDownloadWithRequest:request];
+ request = nil;
+ break;
+ case WebPolicyUse:
+ if (![WebView _canHandleRequest:request]) {
+ [self handleUnimplementablePolicyWithErrorCode:WebKitErrorCannotShowURL forURL:[request URL]];
+ request = nil;
+ }
+ break;
}
- [target performSelector:selector withObject:(shouldContinue ? request : nil) withObject:formState];
+ [target performSelector:selector withObject:request withObject:formState];
}
// Called after the FormsDelegate is done processing willSubmitForm:
// is the user responding Cancel to the form repost nag sheet.
// 2) User responded Cancel to an alert popped up by the before unload event handler.
// The "before unload" event handler runs only for the main frame.
- BOOL canContinue = request && ([[client webView] mainFrame] != client || [[self bridge] shouldClose]);
+ BOOL canContinue = request && (![self isLoadingMainFrame] || [[self bridge] shouldClose]);
if (!canContinue) {
// If we were waiting for a quick redirect, but the policy delegate decided to ignore it, then we
// If the navigation request came from the back/forward menu, and we punt on it, we have the
// problem that we have optimistically moved the b/f cursor already, so move it back. For sanity,
// we only do this when punting a navigation for the target frame or top-level frame.
- if ((isTargetItem || [[client webView] mainFrame] == client) && isBackForwardLoadType(policyLoadType))
- [(WebFrame <WebFrameLoaderClient> *)[[client webView] mainFrame] _resetBackForwardList];
+ if ((isTargetItem || [self isLoadingMainFrame]) && isBackForwardLoadType(policyLoadType))
+ [client _resetBackForwardList];
return;
}
// mechanism across the willSubmitForm callout.
listener = [[WebPolicyDecisionListener alloc] _initWithTarget:self action:@selector(continueAfterWillSubmitForm:)];
[[[client webView] _formDelegate] frame:client sourceFrame:[(WebFrameBridge *)[formState sourceFrame] webFrame] willSubmitForm:[formState form] withValues:[formState values] submissionListener:listener];
- }
- else {
+ } else
[self continueAfterWillSubmitForm:WebPolicyUse];
- }
}
- (void)loadDocumentLoader:(WebDocumentLoader *)loader withLoadType:(FrameLoadType)type formState:(WebFormState *)formState
- (void)didFirstLayout
{
- if ([[client webView] backForwardList]) {
- if (isBackForwardLoadType(loadType))
- [client _restoreScrollPositionAndViewState];
- }
+ if (isBackForwardLoadType(loadType) && [client _hasBackForwardList])
+ [client _restoreScrollPositionAndViewState];
firstLayoutDone = YES;
[client _dispatchDidFirstLayoutInFrame];
- (void)transitionToCommitted:(NSDictionary *)pageCache
{
ASSERT([client webView] != nil);
-
- switch ([self state]) {
- case WebFrameStateProvisional:
- goto keepGoing;
-
- case WebFrameStateCommittedPage:
- case WebFrameStateComplete:
- break;
- }
+ ASSERT([self state] == WebFrameStateProvisional);
- ASSERT_NOT_REACHED();
- return;
-
-keepGoing:
+ if ([self state] != WebFrameStateProvisional)
+ return;
[client _setCopiesOnScroll];
[client _updateHistoryForCommit];
case WebFrameLoadTypeForward:
case WebFrameLoadTypeBack:
case WebFrameLoadTypeIndexedBackForward:
- if ([[client webView] backForwardList]) {
+ if ([client _hasBackForwardList]) {
[client _updateHistoryForBackForwardNavigation];
// Create a document view for this document, or used the cached view.
// Tell the client we've committed this URL.
ASSERT([[client frameView] documentView] != nil);
- [[client webView] _didCommitLoadForFrame:client];
[client _dispatchDidCommitLoadForFrame];
// If we have a title let the WebView know about it.
LoadErrorResetToken *resetToken = [client _tokenForLoadErrorReset];
BOOL shouldReset = YES;
if (![pdl isLoadingInAPISense]) {
- [[client webView] _didFailProvisionalLoadWithError:error forFrame:client];
delegateIsHandlingProvisionalLoadError = YES;
[client _dispatchDidFailProvisionalLoadWithError:error];
-
delegateIsHandlingProvisionalLoadError = NO;
- [[client _internalLoadDelegate] webFrame:client didFinishLoadWithError:error];
// FIXME: can stopping loading here possibly have
// any effect, if isLoading is false, which it
[client _forceLayoutForNonHTML];
- // If the user had a scroll point scroll to it. This will override
- // the anchor point. After much discussion it was decided by folks
- // that the user scroll point should override the anchor point.
- if ([[client webView] backForwardList]) {
- switch ([self loadType]) {
- case WebFrameLoadTypeForward:
- case WebFrameLoadTypeBack:
- case WebFrameLoadTypeIndexedBackForward:
- case WebFrameLoadTypeReload:
- [client _restoreScrollPositionAndViewState];
- break;
-
- case WebFrameLoadTypeStandard:
- case WebFrameLoadTypeInternal:
- case WebFrameLoadTypeReloadAllowingStaleData:
- case WebFrameLoadTypeSame:
- case WebFrameLoadTypeReplace:
- // Do nothing.
- break;
-
- default:
- ASSERT_NOT_REACHED();
- break;
- }
- }
+ // If the user had a scroll point, scroll to it, overriding the anchor point if any.
+ if ((isBackForwardLoadType([self loadType]) || [self loadType] == WebFrameLoadTypeReload)
+ && [client _hasBackForwardList])
+ [client _restoreScrollPositionAndViewState];
NSError *error = [dl mainDocumentError];
- if (error != nil) {
- [[client webView] _didFailLoadWithError:error forFrame:client];
+ if (error != nil)
[client _dispatchDidFailLoadWithError:error];
- [[client _internalLoadDelegate] webFrame:client didFinishLoadWithError:error];
- } else {
- [[client webView] _didFinishLoadForFrame:client];
+ else
[client _dispatchDidFinishLoadForFrame];
- [[client _internalLoadDelegate] webFrame:client didFinishLoadWithError:nil];
- }
- [[client webView] _progressCompleted:client];
+ [client _progressCompleted];
return;
}
- (void)addExtraFieldsToRequest:(NSMutableURLRequest *)request mainResource:(BOOL)mainResource alwaysFromRequest:(BOOL)f
{
- [request setValue:[[client webView] userAgentForURL:[request URL]] forHTTPHeaderField:@"User-Agent"];
+ [request setValue:[[client _bridge] userAgentForURL:[request URL]] forHTTPHeaderField:@"User-Agent"];
if ([self loadType] == FrameLoadTypeReload)
[request setValue:@"max-age=0" forHTTPHeaderField:@"Cache-Control"];
// Don't set the cookie policy URL if it's already been set.
if ([request mainDocumentURL] == nil) {
- if (mainResource && (client == [[client webView] mainFrame] || f))
+ if (mainResource && ([self isLoadingMainFrame] || f))
[request setMainDocumentURL:[request URL]];
else
[request setMainDocumentURL:[[[[client webView] mainFrame] dataSource] _URL]];
// Return the item that we would reset to, so we can decide later whether to actually reset.
- (WebHistoryItem *)_currentBackForwardListItemToResetTo
{
- if (isBackForwardLoadType([[self _frameLoader] loadType]) && self == [[self webView] mainFrame])
+ if (isBackForwardLoadType([[self _frameLoader] loadType]) && [self _isMainFrame])
return _private->currentItem;
return nil;
}
@implementation WebFrame (WebFrameLoaderClient)
+- (BOOL)_hasBackForwardList
+{
+ return [[self webView] backForwardList] != nil;
+}
+
- (void)_resetBackForwardList
{
// Note this doesn't verify the current load type as a b/f operation because it is called from
// a subframe in the case of a delegate bailing out of the nav before it even gets to provisional state.
- ASSERT(self == [[self webView] mainFrame]);
- WebHistoryItem *resetItem = _private->currentItem;
+ WebFrame *mainFrame = [[self webView] mainFrame];
+ WebHistoryItem *resetItem = mainFrame->_private->currentItem;
if (resetItem)
[[[self webView] backForwardList] goToItem:resetItem];
}
- (void)_dispatchDidReceiveIcon:(NSImage *)icon
{
WebView *webView = [self webView];
+ ASSERT([self _isMainFrame]);
+ [webView _willChangeValueForKey:_WebMainFrameIconKey];
[[webView _frameLoadDelegateForwarder] webView:webView didReceiveIcon:icon forFrame:self];
+ [webView _didChangeValueForKey:_WebMainFrameIconKey];
}
- (void)_dispatchDidStartProvisionalLoadForFrame
{
WebView *webView = [self webView];
+ [webView _didStartProvisionalLoadForFrame:self];
[[webView _frameLoadDelegateForwarder] webView:webView didStartProvisionalLoadForFrame:self];
}
- (void)_dispatchDidCommitLoadForFrame
{
WebView *webView = [self webView];
+ [webView _didCommitLoadForFrame:self];
[[webView _frameLoadDelegateForwarder] webView:webView didCommitLoadForFrame:self];
}
- (void)_dispatchDidFailProvisionalLoadWithError:(NSError *)error
{
WebView *webView = [self webView];
+ [webView _didFailProvisionalLoadWithError:error forFrame:self];
[[webView _frameLoadDelegateForwarder] webView:webView didFailProvisionalLoadWithError:error forFrame:self];
+ [_private->internalLoadDelegate webFrame:self didFinishLoadWithError:error];
}
- (void)_dispatchDidFailLoadWithError:(NSError *)error
{
WebView *webView = [self webView];
+ [webView _didFailLoadWithError:error forFrame:self];
[[webView _frameLoadDelegateForwarder] webView:webView didFailLoadWithError:error forFrame:self];
+ [_private->internalLoadDelegate webFrame:self didFinishLoadWithError:error];
}
- (void)_dispatchDidFinishLoadForFrame
{
WebView *webView = [self webView];
+ [webView _didFinishLoadForFrame:self];
[[webView _frameLoadDelegateForwarder] webView:webView didFinishLoadForFrame:self];
+ [_private->internalLoadDelegate webFrame:self didFinishLoadWithError:nil];
}
- (void)_dispatchDidFirstLayoutInFrame
[dataSource(loader) _makeRepresentation];
}
+- (void)_progressStarted
+{
+ [[self webView] _progressStarted:self];
+}
+
+- (void)_progressCompleted
+{
+ [[self webView] _progressCompleted:self];
+}
+
+- (void)_incrementProgressForIdentifier:(id)identifier response:(NSURLResponse *)response
+{
+ [[self webView] _incrementProgressForIdentifier:identifier response:response];
+}
+
+- (void)_incrementProgressForIdentifier:(id)identifier data:(NSData *)data
+{
+ [[self webView] _incrementProgressForIdentifier:identifier data:data];
+}
+
+- (void)_completeProgressForIdentifier:(id)identifier
+{
+ [[self webView] _completeProgressForIdentifier:identifier];
+}
+
+- (void)_setMainFrameDocumentReady:(BOOL)ready
+{
+ [[self webView] setMainFrameDocumentReady:ready];
+}
+
+- (void)_willChangeTitleForDocument:(WebDocumentLoader *)loader
+{
+ // FIXME: Should do this only in main frame case, right?
+ [[self webView] _willChangeValueForKey:_WebMainFrameTitleKey];
+}
+
+- (void)_didChangeTitleForDocument:(WebDocumentLoader *)loader
+{
+ // FIXME: Should do this only in main frame case, right?
+ [[self webView] _didChangeValueForKey:_WebMainFrameTitleKey];
+}
+
+- (void)_startDownloadWithRequest:(NSURLRequest *)request
+{
+ // FIXME: Should download full request.
+ [[self webView] _downloadURL:[request URL]];
+}
+
@end