Commit 604b1965 authored by mjs's avatar mjs
Browse files

Refactor so that all invocations of navigation policy are set up

	to be asynchronous. However, the actually delegate method is not
	async yet.

        * WebView.subproj/WebFramePrivate.h:
        * WebView.subproj/WebFramePrivate.m:
        (-[WebFrame _checkNavigationPolicyForRequest:dataSource:andCall:withSelector:]):
        (-[WebFrame _continueFragmentScrollAfterNavigationPolicy:request:]):
        (-[WebFrame _loadURL:loadType:triggeringEvent:isFormSubmission:]):
        (-[WebFrame _continueLoadRequestAfterNavigationPolicy:request:]):
        (-[WebFrame _loadDataSource:withLoadType:]):
        * WebView.subproj/WebMainResourceClient.h:
        * WebView.subproj/WebMainResourceClient.m:
        (-[WebMainResourceClient stopLoadingForPolicyChange]):
        (-[WebMainResourceClient continueAfterNavigationPolicy:request:]):
        (-[WebMainResourceClient handle:willSendRequest:]):
        (-[WebMainResourceClient handle:didReceiveResponse:]):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2686 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bd6a1fde
2002-11-15 Maciej Stachowiak <mjs@apple.com>
Refactor so that all invocations of navigation policy are set up
to be asynchronous. However, the actually delegate method is not
async yet.
* WebView.subproj/WebFramePrivate.h:
* WebView.subproj/WebFramePrivate.m:
(-[WebFrame _checkNavigationPolicyForRequest:dataSource:andCall:withSelector:]):
(-[WebFrame _continueFragmentScrollAfterNavigationPolicy:request:]):
(-[WebFrame _loadURL:loadType:triggeringEvent:isFormSubmission:]):
(-[WebFrame _continueLoadRequestAfterNavigationPolicy:request:]):
(-[WebFrame _loadDataSource:withLoadType:]):
* WebView.subproj/WebMainResourceClient.h:
* WebView.subproj/WebMainResourceClient.m:
(-[WebMainResourceClient stopLoadingForPolicyChange]):
(-[WebMainResourceClient continueAfterNavigationPolicy:request:]):
(-[WebMainResourceClient handle:willSendRequest:]):
(-[WebMainResourceClient handle:didReceiveResponse:]):
2002-11-14 Maciej Stachowiak <mjs@apple.com>
 
Refactor things a bit so all loads bottleneck through a single
......
2002-11-15 Maciej Stachowiak <mjs@apple.com>
Refactor so that all invocations of navigation policy are set up
to be asynchronous. However, the actually delegate method is not
async yet.
* WebView.subproj/WebFramePrivate.h:
* WebView.subproj/WebFramePrivate.m:
(-[WebFrame _checkNavigationPolicyForRequest:dataSource:andCall:withSelector:]):
(-[WebFrame _continueFragmentScrollAfterNavigationPolicy:request:]):
(-[WebFrame _loadURL:loadType:triggeringEvent:isFormSubmission:]):
(-[WebFrame _continueLoadRequestAfterNavigationPolicy:request:]):
(-[WebFrame _loadDataSource:withLoadType:]):
* WebView.subproj/WebMainResourceClient.h:
* WebView.subproj/WebMainResourceClient.m:
(-[WebMainResourceClient stopLoadingForPolicyChange]):
(-[WebMainResourceClient continueAfterNavigationPolicy:request:]):
(-[WebMainResourceClient handle:willSendRequest:]):
(-[WebMainResourceClient handle:didReceiveResponse:]):
2002-11-14 Maciej Stachowiak <mjs@apple.com>
 
Refactor things a bit so all loads bottleneck through a single
......
......@@ -103,11 +103,12 @@ typedef enum {
- (void)_checkLoadComplete;
- (void)_timedLayout: userInfo;
- (WebBridge *)_bridge;
- (BOOL)_shouldShowRequest:(WebResourceRequest *)request;
- (void)_clearProvisionalDataSource;
- (void)_setLoadType: (WebFrameLoadType)loadType;
- (WebFrameLoadType)_loadType;
- (void)_checkNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource andCall:(id)target withSelector:(SEL)selector;
- (NSDictionary *)_actionInformationForNavigationType:(WebNavigationType)navigationType event:(NSEvent *)event;
- (BOOL)_continueAfterNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource;
- (void)_goToItem: (WebHistoryItem *)item withLoadType: (WebFrameLoadType)type;
......
......@@ -731,11 +731,6 @@ - (void)_handleUnimplementablePolicy:(WebPolicyAction)policy errorCode:(int)code
[[[self controller] policyDelegate] unableToImplementPolicy:policy error:error forURL:URL inFrame:self];
}
- (BOOL)_shouldShowRequest:(WebResourceRequest *)request
{
return [self _continueAfterNavigationPolicyForRequest:request dataSource:[self provisionalDataSource]];
}
- (void)_clearProvisionalDataSource
{
[_private setProvisionalDataSource:nil];
......@@ -920,6 +915,12 @@ -(NSDictionary *)_actionInformationForNavigationType:(WebNavigationType)navigati
forKey:WebActionNavigationTypeKey];
}
- (void)_checkNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource andCall:(id)target withSelector:(SEL)selector
{
BOOL shouldContinue = [self _continueAfterNavigationPolicyForRequest:request dataSource:dataSource];
[target performSelector:selector withObject:(id)(unsigned)shouldContinue withObject:request];
}
-(BOOL)_continueAfterNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource
{
NSDictionary *action = [dataSource _triggeringAction];
......@@ -984,6 +985,35 @@ -(BOOL)_continueAfterNavigationPolicyForRequest:(WebResourceRequest *)request da
return NO;
}
-(void)_continueFragmentScrollAfterNavigationPolicy:(BOOL)shouldContinue request:(WebResourceRequest *)request
{
if (!shouldContinue) {
return;
}
NSURL *URL = [request URL];
WebDataSource *dataSrc = [self dataSource];
// save scroll position before we open URL, which will jump to anchor
[self _saveScrollPositionToItem:[_private currentItem]];
// ???Might need to save scroll-state, form-state for all other frames
ASSERT(![_private previousItem]);
// will save form state to current item, since prevItem not set
[_private->bridge openURL:URL reload:NO headers:nil];
[dataSrc _setURL:URL];
// NB: must happen after _setURL, since we add based on the current request
[self _addBackForwardItemClippedAtTarget:NO];
// This will clear previousItem from the rest of the frame tree tree that didn't
// doing any loading. We need to make a pass on this now, since for anchor nav
// we'll not go through a real load and reach Completed state
[self _checkLoadComplete];
[[[self controller] locationChangeDelegate] locationChangedWithinPageForDataSource:dataSrc];
}
// main funnel for navigating via callback from WebCore (e.g., clicking a link, redirect)
- (void)_loadURL:(NSURL *)URL loadType:(WebFrameLoadType)loadType triggeringEvent:(NSEvent *)event isFormSubmission:(BOOL)isFormSubmission
{
......@@ -1013,26 +1043,7 @@ - (void)_loadURL:(NSURL *)URL loadType:(WebFrameLoadType)loadType triggeringEven
WebDataSource *dataSrc = [self dataSource];
[dataSrc _setTriggeringAction:action];
if (![self _continueAfterNavigationPolicyForRequest:request dataSource:dataSrc]) {
return;
}
// save scroll position before we open URL, which will jump to anchor
[self _saveScrollPositionToItem:[_private currentItem]];
// ???Might need to save scroll-state, form-state for all other frames
ASSERT(![_private previousItem]);
// will save form state to current item, since prevItem not set
[_private->bridge openURL:URL reload:NO headers:nil];
[dataSrc _setURL:URL];
// NB: must happen after _setURL, since we add based on the current request
[self _addBackForwardItemClippedAtTarget:NO];
// This will clear previousItem from the rest of the frame tree tree that didn't
// doing any loading. We need to make a pass on this now, since for anchor nav
// we'll not go through a real load and reach Completed state
[self _checkLoadComplete];
[[[self controller] locationChangeDelegate] locationChangedWithinPageForDataSource:dataSrc];
[self _checkNavigationPolicyForRequest:request dataSource:dataSrc andCall:self withSelector:@selector(_continueFragmentScrollAfterNavigationPolicy:request:)];
} else {
WebFrameLoadType previousLoadType = [self _loadType];
WebDataSource *oldDataSource = [[self dataSource] retain];
......@@ -1259,6 +1270,25 @@ - (WebHistoryItem *)_itemForRestoringDocState
return [_private currentItem];
}
-(void)_continueLoadRequestAfterNavigationPolicy:(BOOL)shouldContinue request:(WebResourceRequest *)request
{
if (!shouldContinue) {
[self _setLoadType: WebFrameLoadTypeStandard];
[_private setProvisionalDataSource:nil];
return;
}
// We tell the documentView provisionalDataSourceChanged:
// once it has been created by the controller.
[self _setState: WebFrameStateProvisional];
if (self == [[self controller] mainFrame])
LOG(DocumentLoad, "loading %@", [[[self provisionalDataSource] request] URL]);
[_private->provisionalDataSource startLoading];
}
- (void)_loadDataSource:(WebDataSource *)newDataSource withLoadType: (WebFrameLoadType)loadType
{
ASSERT([self controller] != nil);
......@@ -1272,16 +1302,8 @@ - (void)_loadDataSource:(WebDataSource *)newDataSource withLoadType: (WebFrameLo
[self stopLoading];
}
[self _setLoadType: WebFrameLoadTypeStandard];
// _continueAfterNavigationPolicyForRequest:dataSource: asks the
// client for the URL policies and reports errors if there are any
// returns YES if we should show the data source
[self _setLoadType:loadType];
if (![self _continueAfterNavigationPolicyForRequest:[newDataSource request] dataSource:newDataSource]) {
return;
}
if ([self parent]) {
[newDataSource _setOverrideEncoding:[[[self parent] dataSource] _overrideEncoding]];
}
......@@ -1289,18 +1311,8 @@ - (void)_loadDataSource:(WebDataSource *)newDataSource withLoadType: (WebFrameLo
[_private setProvisionalDataSource:newDataSource];
ASSERT([newDataSource webFrame] == self);
// We tell the documentView provisionalDataSourceChanged:
// once it has been created by the controller.
[self _setState: WebFrameStateProvisional];
[self _setLoadType:loadType];
if (self == [[self controller] mainFrame])
LOG(DocumentLoad, "loading %@", [[[self provisionalDataSource] request] URL]);
[_private->provisionalDataSource startLoading];
[self _checkNavigationPolicyForRequest:[newDataSource request] dataSource:newDataSource andCall:self withSelector:@selector(_continueLoadRequestAfterNavigationPolicy:request:)];
}
- (void)_downloadRequest:(WebResourceRequest *)request toPath:(NSString *)path
......
......@@ -26,6 +26,7 @@
NSMutableData *resourceData;
int _contentLength; // for logging only
int _bytesReceived; // for logging only
BOOL defersBeforeCheckingPolicy;
}
- initWithDataSource:(WebDataSource *)dataSource;
......
......@@ -91,6 +91,25 @@ - (void)cancel
[self release];
}
-(void)stopLoadingForPolicyChange
{
[[dataSource webFrame] _clearProvisionalDataSource];
[self notifyDelegatesOfInterruptionByPolicyChange];
[self cancelQuietly];
}
-(void)continueAfterNavigationPolicy:(BOOL)shouldContinue request:(WebResourceRequest *)request
{
if (!defersBeforeCheckingPolicy) {
[[dataSource controller] _setDefersCallbacks:NO];
}
if (!shouldContinue) {
[self stopLoadingForPolicyChange];
}
}
-(WebResourceRequest *)handle:(WebResourceHandle *)h willSendRequest:(WebResourceRequest *)newRequest
{
newRequest = [super handle:h willSendRequest:newRequest];
......@@ -99,16 +118,6 @@ -(WebResourceRequest *)handle:(WebResourceHandle *)h willSendRequest:(WebResourc
NSURL *URL = [newRequest URL];
if (![[dataSource webFrame] _shouldShowRequest:newRequest]) {
[self cancelQuietly];
[[dataSource webFrame] _clearProvisionalDataSource];
[[[dataSource controller] locationChangeDelegate] locationChangeDone:
[WebError errorWithCode:WebErrorLocationChangeInterruptedByPolicyChange inDomain:WebErrorDomainWebKit failingURL:nil]
forDataSource:dataSource];
return nil;
}
LOG(Redirect, "URL = %@", URL);
// Update cookie policy base URL as URL changes, except for subframes, which use the
......@@ -120,7 +129,14 @@ -(WebResourceRequest *)handle:(WebResourceHandle *)h willSendRequest:(WebResourc
// Don't set this on the first request. It is set
// when the main load was started.
[dataSource _setRequest:newRequest];
defersBeforeCheckingPolicy = [[dataSource controller] _defersCallbacks];
if (!defersBeforeCheckingPolicy) {
[[dataSource controller] _setDefersCallbacks:YES];
}
[[dataSource webFrame] _checkNavigationPolicyForRequest:newRequest dataSource:dataSource andCall:self withSelector:@selector(continueAfterNavigationPolicy:request:)];
return newRequest;
}
......@@ -133,14 +149,6 @@ - (void)notifyDelegatesOfInterruptionByPolicyChange
[super notifyDelegatesOfInterruptionByPolicyChange];
}
-(void)stopLoadingAfterContentPolicy
{
[[dataSource webFrame] _clearProvisionalDataSource];
[self notifyDelegatesOfInterruptionByPolicyChange];
[self cancelQuietly];
}
-(void)handle:(WebResourceHandle *)h didReceiveResponse:(WebResourceResponse *)r
{
[dataSource _setResponse:r];
......@@ -165,7 +173,7 @@ -(void)handle:(WebResourceHandle *)h didReceiveResponse:(WebResourceResponse *)r
case WebPolicyShow:
if (![WebController canShowMIMEType:[r contentType]]) {
[[dataSource webFrame] _handleUnimplementablePolicy:contentPolicy errorCode:WebErrorCannotShowMIMEType forURL:[req URL]];
[self stopLoadingAfterContentPolicy];
[self stopLoadingForPolicyChange];
return;
}
break;
......@@ -198,7 +206,7 @@ -(void)handle:(WebResourceHandle *)h didReceiveResponse:(WebResourceResponse *)r
}
}
[self stopLoadingAfterContentPolicy];
[self stopLoadingForPolicyChange];
return;
break;
......@@ -209,12 +217,12 @@ -(void)handle:(WebResourceHandle *)h didReceiveResponse:(WebResourceResponse *)r
[[dataSource webFrame] _handleUnimplementablePolicy:contentPolicy errorCode:WebErrorFinderCannotOpenDirectory forURL:[req URL]];
}
[self stopLoadingAfterContentPolicy];
[self stopLoadingForPolicyChange];
return;
break;
case WebPolicyIgnore:
[self stopLoadingAfterContentPolicy];
[self stopLoadingForPolicyChange];
return;
break;
......
......@@ -26,6 +26,7 @@
NSMutableData *resourceData;
int _contentLength; // for logging only
int _bytesReceived; // for logging only
BOOL defersBeforeCheckingPolicy;
}
- initWithDataSource:(WebDataSource *)dataSource;
......
......@@ -91,6 +91,25 @@ - (void)cancel
[self release];
}
-(void)stopLoadingForPolicyChange
{
[[dataSource webFrame] _clearProvisionalDataSource];
[self notifyDelegatesOfInterruptionByPolicyChange];
[self cancelQuietly];
}
-(void)continueAfterNavigationPolicy:(BOOL)shouldContinue request:(WebResourceRequest *)request
{
if (!defersBeforeCheckingPolicy) {
[[dataSource controller] _setDefersCallbacks:NO];
}
if (!shouldContinue) {
[self stopLoadingForPolicyChange];
}
}
-(WebResourceRequest *)handle:(WebResourceHandle *)h willSendRequest:(WebResourceRequest *)newRequest
{
newRequest = [super handle:h willSendRequest:newRequest];
......@@ -99,16 +118,6 @@ -(WebResourceRequest *)handle:(WebResourceHandle *)h willSendRequest:(WebResourc
NSURL *URL = [newRequest URL];
if (![[dataSource webFrame] _shouldShowRequest:newRequest]) {
[self cancelQuietly];
[[dataSource webFrame] _clearProvisionalDataSource];
[[[dataSource controller] locationChangeDelegate] locationChangeDone:
[WebError errorWithCode:WebErrorLocationChangeInterruptedByPolicyChange inDomain:WebErrorDomainWebKit failingURL:nil]
forDataSource:dataSource];
return nil;
}
LOG(Redirect, "URL = %@", URL);
// Update cookie policy base URL as URL changes, except for subframes, which use the
......@@ -120,7 +129,14 @@ -(WebResourceRequest *)handle:(WebResourceHandle *)h willSendRequest:(WebResourc
// Don't set this on the first request. It is set
// when the main load was started.
[dataSource _setRequest:newRequest];
defersBeforeCheckingPolicy = [[dataSource controller] _defersCallbacks];
if (!defersBeforeCheckingPolicy) {
[[dataSource controller] _setDefersCallbacks:YES];
}
[[dataSource webFrame] _checkNavigationPolicyForRequest:newRequest dataSource:dataSource andCall:self withSelector:@selector(continueAfterNavigationPolicy:request:)];
return newRequest;
}
......@@ -133,14 +149,6 @@ - (void)notifyDelegatesOfInterruptionByPolicyChange
[super notifyDelegatesOfInterruptionByPolicyChange];
}
-(void)stopLoadingAfterContentPolicy
{
[[dataSource webFrame] _clearProvisionalDataSource];
[self notifyDelegatesOfInterruptionByPolicyChange];
[self cancelQuietly];
}
-(void)handle:(WebResourceHandle *)h didReceiveResponse:(WebResourceResponse *)r
{
[dataSource _setResponse:r];
......@@ -165,7 +173,7 @@ -(void)handle:(WebResourceHandle *)h didReceiveResponse:(WebResourceResponse *)r
case WebPolicyShow:
if (![WebController canShowMIMEType:[r contentType]]) {
[[dataSource webFrame] _handleUnimplementablePolicy:contentPolicy errorCode:WebErrorCannotShowMIMEType forURL:[req URL]];
[self stopLoadingAfterContentPolicy];
[self stopLoadingForPolicyChange];
return;
}
break;
......@@ -198,7 +206,7 @@ -(void)handle:(WebResourceHandle *)h didReceiveResponse:(WebResourceResponse *)r
}
}
[self stopLoadingAfterContentPolicy];
[self stopLoadingForPolicyChange];
return;
break;
......@@ -209,12 +217,12 @@ -(void)handle:(WebResourceHandle *)h didReceiveResponse:(WebResourceResponse *)r
[[dataSource webFrame] _handleUnimplementablePolicy:contentPolicy errorCode:WebErrorFinderCannotOpenDirectory forURL:[req URL]];
}
[self stopLoadingAfterContentPolicy];
[self stopLoadingForPolicyChange];
return;
break;
case WebPolicyIgnore:
[self stopLoadingAfterContentPolicy];
[self stopLoadingForPolicyChange];
return;
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment