Commit 62074c91 authored by mjs's avatar mjs

WebKit:

	Make navigation policy asynchronous for real.

        * WebKit.pbproj/project.pbxproj:
        * WebView.subproj/WebControllerPolicyDelegate.h:
        * WebView.subproj/WebControllerPolicyDelegate.m:
        (-[WebPolicyDecisionListenerPrivate initWithTarget:action:]):
        (-[WebPolicyDecisionListenerPrivate dealloc]):
        (-[WebPolicyDecisionListener usePolicy:]):
        (-[WebPolicyDecisionListener _initWithTarget:action:]):
        (-[WebPolicyDecisionListener dealloc]):
        (-[WebPolicyDecisionListener _invalidate]):
        * WebView.subproj/WebControllerPolicyDelegatePrivate.h: Added.
        * WebView.subproj/WebDefaultPolicyDelegate.m:
        (-[WebDefaultPolicyDelegate decideNavigationPolicyForAction:andRequest:inFrame:decisionListener:]):
        * WebView.subproj/WebFrame.m:
        (-[WebFrame stopLoading]):
        * WebView.subproj/WebFramePrivate.h:
        * WebView.subproj/WebFramePrivate.m:
        (-[WebFramePrivate dealloc]):
        (-[WebFrame _invalidatePendingPolicyDecisionCallingDefaultAction:]):
        (-[WebFrame _checkNavigationPolicyForRequest:dataSource:andCall:withSelector:]):
        (-[WebFrame _continueAfterNavigationPolicy:]):
        (-[WebFrame _loadURL:loadType:triggeringEvent:isFormSubmission:]):
        (-[WebFrame _loadDataSource:withLoadType:]):

WebBrowser:

	Make navigation policy asynchronous.

        * BrowserWebController.m:
        (-[BrowserWebController decideNavigationPolicyForAction:andRequest:inFrame:decisionListener:]):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 252d3fe7
2002-11-15 Maciej Stachowiak <mjs@apple.com>
Make navigation policy asynchronous for real.
* WebKit.pbproj/project.pbxproj:
* WebView.subproj/WebControllerPolicyDelegate.h:
* WebView.subproj/WebControllerPolicyDelegate.m:
(-[WebPolicyDecisionListenerPrivate initWithTarget:action:]):
(-[WebPolicyDecisionListenerPrivate dealloc]):
(-[WebPolicyDecisionListener usePolicy:]):
(-[WebPolicyDecisionListener _initWithTarget:action:]):
(-[WebPolicyDecisionListener dealloc]):
(-[WebPolicyDecisionListener _invalidate]):
* WebView.subproj/WebControllerPolicyDelegatePrivate.h: Added.
* WebView.subproj/WebDefaultPolicyDelegate.m:
(-[WebDefaultPolicyDelegate decideNavigationPolicyForAction:andRequest:inFrame:decisionListener:]):
* WebView.subproj/WebFrame.m:
(-[WebFrame stopLoading]):
* WebView.subproj/WebFramePrivate.h:
* WebView.subproj/WebFramePrivate.m:
(-[WebFramePrivate dealloc]):
(-[WebFrame _invalidatePendingPolicyDecisionCallingDefaultAction:]):
(-[WebFrame _checkNavigationPolicyForRequest:dataSource:andCall:withSelector:]):
(-[WebFrame _continueAfterNavigationPolicy:]):
(-[WebFrame _loadURL:loadType:triggeringEvent:isFormSubmission:]):
(-[WebFrame _loadDataSource:withLoadType:]):
2002-11-15 Maciej Stachowiak <mjs@apple.com>
Wrap content policy invocation to look asynchronous.
......
2002-11-15 Maciej Stachowiak <mjs@apple.com>
Make navigation policy asynchronous for real.
* WebKit.pbproj/project.pbxproj:
* WebView.subproj/WebControllerPolicyDelegate.h:
* WebView.subproj/WebControllerPolicyDelegate.m:
(-[WebPolicyDecisionListenerPrivate initWithTarget:action:]):
(-[WebPolicyDecisionListenerPrivate dealloc]):
(-[WebPolicyDecisionListener usePolicy:]):
(-[WebPolicyDecisionListener _initWithTarget:action:]):
(-[WebPolicyDecisionListener dealloc]):
(-[WebPolicyDecisionListener _invalidate]):
* WebView.subproj/WebControllerPolicyDelegatePrivate.h: Added.
* WebView.subproj/WebDefaultPolicyDelegate.m:
(-[WebDefaultPolicyDelegate decideNavigationPolicyForAction:andRequest:inFrame:decisionListener:]):
* WebView.subproj/WebFrame.m:
(-[WebFrame stopLoading]):
* WebView.subproj/WebFramePrivate.h:
* WebView.subproj/WebFramePrivate.m:
(-[WebFramePrivate dealloc]):
(-[WebFrame _invalidatePendingPolicyDecisionCallingDefaultAction:]):
(-[WebFrame _checkNavigationPolicyForRequest:dataSource:andCall:withSelector:]):
(-[WebFrame _continueAfterNavigationPolicy:]):
(-[WebFrame _loadURL:loadType:triggeringEvent:isFormSubmission:]):
(-[WebFrame _loadDataSource:withLoadType:]):
2002-11-15 Maciej Stachowiak <mjs@apple.com>
Wrap content policy invocation to look asynchronous.
......
......@@ -301,6 +301,7 @@
83413E8E0375BCD3004719BE,
83413E8F0375BCD3004719BE,
9316400E0379832D008635CE,
658CF8C103851FB5008C2A4B,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
......@@ -1476,6 +1477,18 @@
settings = {
};
};
658CF8C003851FB5008C2A4B = {
fileEncoding = 30;
isa = PBXFileReference;
path = WebControllerPolicyDelegatePrivate.h;
refType = 4;
};
658CF8C103851FB5008C2A4B = {
fileRef = 658CF8C003851FB5008C2A4B;
isa = PBXBuildFile;
settings = {
};
};
//650
//651
//652
......@@ -2120,6 +2133,7 @@
6523FAD0032DA06B005EFCFF,
5152FAD7033FC44A00CA2ACD,
5152FAD8033FC44A00CA2ACD,
658CF8C003851FB5008C2A4B,
5152FADD033FC50400CA2ACD,
5152FADE033FC50400CA2ACD,
5152FADF033FC50400CA2ACD,
......
......@@ -67,6 +67,8 @@ typedef enum {
WebPolicyDecisionListenerPrivate *_private;
}
-(void)usePolicy:(WebPolicyAction) policy;
@end
......@@ -82,16 +84,17 @@ typedef enum {
@protocol WebControllerPolicyDelegate <NSObject>
/*!
@method navigationPolicyForAction:andRequest:inFrame:
@method decideNavigationPolicyForAction:andRequest:inFrame:
@discussion Called right after the user clicks on a link.
@param actionInformation Dictionary that describes the action that triggered this navigation.
@param andRequest The request for the proposed navigation
@param frame The frame in which the navigation is taking place
@result The WebPolicyAction for WebKit to implement
@param listener The object to call when the decision is made
*/
- (WebPolicyAction)navigationPolicyForAction:(NSDictionary *)actionInformation
andRequest:(WebResourceRequest *)request
inFrame:(WebFrame *)frame;
- (void)decideNavigationPolicyForAction:(NSDictionary *)actionInformation
andRequest:(WebResourceRequest *)request
inFrame:(WebFrame *)frame
decisionListener:(WebPolicyDecisionListener *)listener;
/*!
......
......@@ -4,9 +4,80 @@
*/
#import <WebKit/WebControllerPolicyDelegate.h>
#import <WebKit/WebControllerPolicyDelegatePrivate.h>
NSString *WebActionNavigationTypeKey = @"WebActionNavigationTypeKey";
NSString *WebActionElementKey = @"WebActionNavigationTypeKey";
NSString *WebActionButtonKey = @"WebActionButtonKey";
NSString *WebActionModifierFlagsKey = @"WebActionModifierFlagsKey";
@interface WebPolicyDecisionListenerPrivate : NSObject
{
@public
id target;
SEL action;
}
-(id)initWithTarget:(id)target action:(SEL)action;
@end
@implementation WebPolicyDecisionListenerPrivate
-(id)initWithTarget:(id)t action:(SEL)a
{
self = [super init];
if (self != nil) {
target = [t retain];
action = a;
}
return self;
}
-(void)dealloc
{
[target release];
[super dealloc];
}
@end
@implementation WebPolicyDecisionListener
-(void)usePolicy:(WebPolicyAction)policy
{
if (_private->target != nil) {
[_private->target performSelector:_private->action withObject:(id)policy];
}
}
@end
@implementation WebPolicyDecisionListener (WebPrivate)
-(id)_initWithTarget:(id)target action:(SEL)action
{
self = [super init];
if (self != nil) {
_private = [[WebPolicyDecisionListenerPrivate alloc] initWithTarget:target action:action];
}
return self;
}
-(void)dealloc
{
[_private release];
[super dealloc];
}
-(void)_invalidate
{
[self retain];
[_private->target release];
_private->target = nil;
[self release];
}
@end
/*
WebControllerPolicyDelegatePrivate.h
Copyright 2002, Apple, Inc. All rights reserved.
*/
#import <WebKit/WebControllerPolicyDelegate.h>
@interface WebPolicyDecisionListener (WebPrivate)
-(id)_initWithTarget:(id)target action:(SEL)action;
-(void)_invalidate;
@end
......@@ -55,14 +55,15 @@ - (NSString *)saveFilenameForResponse:(WebResourceResponse *)response
return nil;
}
- (WebPolicyAction)navigationPolicyForAction:(NSDictionary *)actionInformation
andRequest:(WebResourceRequest *)request
inFrame:(WebFrame *)frame
- (void)decideNavigationPolicyForAction:(NSDictionary *)actionInformation
andRequest:(WebResourceRequest *)request
inFrame:(WebFrame *)frame
decisionListener:(WebPolicyDecisionListener *)listener
{
if([WebResourceHandle canInitWithRequest:request]){
return WebPolicyUse;
if ([WebResourceHandle canInitWithRequest:request]) {
[listener usePolicy:WebPolicyUse];
}else{
return WebPolicyOpenURL;
[listener usePolicy:WebPolicyOpenURL];
}
}
......
......@@ -112,6 +112,8 @@ - (void)loadRequest:(WebResourceRequest *)request
- (void)stopLoading
{
[self _invalidatePendingPolicyDecisionCallingDefaultAction:YES];
if (_private->state != WebFrameStateComplete) {
[_private->provisionalDataSource stopLoading];
[_private->dataSource stopLoading];
......
......@@ -64,6 +64,11 @@ typedef enum {
// (only known when navigating to a pre-existing BF item)
WebHistoryItem *previousItem; // BF item for previous content, see _itemForSavingDocState
BOOL instantRedirectComing;
WebPolicyDecisionListener *listener;
WebResourceRequest *policyRequest;
id policyTarget;
SEL policySelector;
}
- (void)setName:(NSString *)name;
......@@ -109,8 +114,9 @@ typedef enum {
- (void)_checkNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource andCall:(id)target withSelector:(SEL)selector;
- (void)_invalidatePendingPolicyDecisionCallingDefaultAction:(BOOL)call;
- (NSDictionary *)_actionInformationForNavigationType:(WebNavigationType)navigationType event:(NSEvent *)event;
- (BOOL)_continueAfterNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource;
- (void)_goToItem: (WebHistoryItem *)item withLoadType: (WebFrameLoadType)type;
- (void)_loadURL:(NSURL *)URL loadType:(WebFrameLoadType)loadType triggeringEvent:(NSEvent *)event isFormSubmission:(BOOL)isFormSubmission;
- (void)_loadURL:(NSURL *)URL intoChild:(WebFrame *)childFrame;
......
......@@ -10,6 +10,7 @@
#import <WebKit/WebBridge.h>
#import <WebKit/WebController.h>
#import <WebKit/WebControllerPolicyDelegate.h>
#import <WebKit/WebControllerPolicyDelegatePrivate.h>
#import <WebKit/WebControllerPrivate.h>
#import <WebKit/WebDataSource.h>
#import <WebKit/WebDataSourcePrivate.h>
......@@ -74,6 +75,10 @@ - (void)dealloc
[provisionalItem release];
[previousItem release];
ASSERT(listener == nil);
ASSERT(policyRequest == nil);
ASSERT(policyTarget == nil);
[super dealloc];
}
......@@ -915,13 +920,29 @@ -(NSDictionary *)_actionInformationForNavigationType:(WebNavigationType)navigati
forKey:WebActionNavigationTypeKey];
}
- (void)_checkNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource andCall:(id)target withSelector:(SEL)selector
- (void) _invalidatePendingPolicyDecisionCallingDefaultAction:(BOOL)call
{
BOOL shouldContinue = [self _continueAfterNavigationPolicyForRequest:request dataSource:dataSource];
[target performSelector:selector withObject:(id)(unsigned)shouldContinue withObject:request];
[_private->listener _invalidate];
[_private->listener release];
_private->listener = nil;
WebResourceRequest *request = _private->policyRequest;
id target = _private->policyTarget;
SEL selector = _private->policySelector;
_private->policyRequest = nil;
_private->policyTarget = nil;
_private->policySelector = nil;
if (call) {
[target performSelector:selector withObject:(id)NO withObject:request];
}
[_private->policyRequest release];
[_private->policyTarget release];
}
-(BOOL)_continueAfterNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource
- (void)_checkNavigationPolicyForRequest:(WebResourceRequest *)request dataSource:(WebDataSource *)dataSource andCall:(id)target withSelector:(SEL)selector
{
NSDictionary *action = [dataSource _triggeringAction];
if (action == nil) {
......@@ -931,14 +952,31 @@ -(BOOL)_continueAfterNavigationPolicyForRequest:(WebResourceRequest *)request da
// Don't ask more than once for the same request
if ([request isEqual:[dataSource _lastCheckedRequest]]) {
return YES;
[target performSelector:selector withObject:(id)YES withObject:request];
}
[dataSource _setLastCheckedRequest:request];
WebPolicyAction policy = [[[self controller] policyDelegate] navigationPolicyForAction:action
andRequest:request
inFrame:self];
_private->policyRequest = [request retain];
_private->policyTarget = [target retain];
_private->policySelector = selector;
_private->listener = [[WebPolicyDecisionListener alloc] _initWithTarget:self action:@selector(_continueAfterNavigationPolicy:)];
[[[self controller] policyDelegate] decideNavigationPolicyForAction:action
andRequest:request
inFrame:self
decisionListener:_private->listener];
}
-(void)_continueAfterNavigationPolicy:(WebPolicyAction)policy
{
WebResourceRequest *request = [[_private->policyRequest retain] autorelease];
id target = [[_private->policyTarget retain] autorelease];
SEL selector = _private->policySelector;
[self _invalidatePendingPolicyDecisionCallingDefaultAction:NO];
BOOL shouldContinue = NO;
switch (policy) {
case WebPolicyIgnore:
......@@ -946,11 +984,11 @@ -(BOOL)_continueAfterNavigationPolicyForRequest:(WebResourceRequest *)request da
case WebPolicyOpenURL:
if ([[request URL] isFileURL]) {
if(![[NSWorkspace sharedWorkspace] openFile:[[request URL] path]]){
[[dataSource webFrame] _handleUnimplementablePolicy:policy errorCode:WebErrorCannotFindApplicationForFile forURL:[request URL]];
[self _handleUnimplementablePolicy:policy errorCode:WebErrorCannotFindApplicationForFile forURL:[request URL]];
}
} else {
if(![[NSWorkspace sharedWorkspace] openURL:[request URL]]){
[[dataSource webFrame] _handleUnimplementablePolicy:policy errorCode:WebErrorCannotNotFindApplicationForURL forURL:[request URL]];
[self _handleUnimplementablePolicy:policy errorCode:WebErrorCannotNotFindApplicationForURL forURL:[request URL]];
}
}
break;
......@@ -974,19 +1012,18 @@ -(BOOL)_continueAfterNavigationPolicyForRequest:(WebResourceRequest *)request da
case WebPolicyUse:
if (![WebResourceHandle canInitWithRequest:request]) {
[self _handleUnimplementablePolicy:policy errorCode:WebErrorCannotShowURL forURL:[request URL]];
} else {
shouldContinue = YES;
}
return YES;
break;
default:
[NSException raise:NSInvalidArgumentException
format:@"clickPolicyForElement:button:modifierFlags: returned an invalid WebClickPolicy"];
}
return NO;
[target performSelector:selector withObject:(id)(unsigned)shouldContinue withObject:request];
}
-(void)_continueFragmentScrollAfterNavigationPolicy:(BOOL)shouldContinue request:(WebResourceRequest *)request
{
if (!shouldContinue) {
......@@ -1043,6 +1080,9 @@ - (void)_loadURL:(NSURL *)URL loadType:(WebFrameLoadType)loadType triggeringEven
WebDataSource *dataSrc = [self dataSource];
[dataSrc _setTriggeringAction:action];
[self _invalidatePendingPolicyDecisionCallingDefaultAction:YES];
[self _checkNavigationPolicyForRequest:request dataSource:dataSrc andCall:self withSelector:@selector(_continueFragmentScrollAfterNavigationPolicy:request:)];
} else {
WebFrameLoadType previousLoadType = [self _loadType];
......@@ -1298,9 +1338,7 @@ - (void)_loadDataSource:(WebDataSource *)newDataSource withLoadType: (WebFrameLo
// KDE drop we should fix this dependency.
ASSERT([self webView] != nil);
if ([self _state] != WebFrameStateComplete) {
[self stopLoading];
}
[self stopLoading];
[self _setLoadType:loadType];
......
......@@ -67,6 +67,8 @@ typedef enum {
WebPolicyDecisionListenerPrivate *_private;
}
-(void)usePolicy:(WebPolicyAction) policy;
@end
......@@ -82,16 +84,17 @@ typedef enum {
@protocol WebControllerPolicyDelegate <NSObject>
/*!
@method navigationPolicyForAction:andRequest:inFrame:
@method decideNavigationPolicyForAction:andRequest:inFrame:
@discussion Called right after the user clicks on a link.
@param actionInformation Dictionary that describes the action that triggered this navigation.
@param andRequest The request for the proposed navigation
@param frame The frame in which the navigation is taking place
@result The WebPolicyAction for WebKit to implement
@param listener The object to call when the decision is made
*/
- (WebPolicyAction)navigationPolicyForAction:(NSDictionary *)actionInformation
andRequest:(WebResourceRequest *)request
inFrame:(WebFrame *)frame;
- (void)decideNavigationPolicyForAction:(NSDictionary *)actionInformation
andRequest:(WebResourceRequest *)request
inFrame:(WebFrame *)frame
decisionListener:(WebPolicyDecisionListener *)listener;
/*!
......
......@@ -4,9 +4,80 @@
*/
#import <WebKit/WebControllerPolicyDelegate.h>
#import <WebKit/WebControllerPolicyDelegatePrivate.h>
NSString *WebActionNavigationTypeKey = @"WebActionNavigationTypeKey";
NSString *WebActionElementKey = @"WebActionNavigationTypeKey";
NSString *WebActionButtonKey = @"WebActionButtonKey";
NSString *WebActionModifierFlagsKey = @"WebActionModifierFlagsKey";
@interface WebPolicyDecisionListenerPrivate : NSObject
{
@public
id target;
SEL action;
}
-(id)initWithTarget:(id)target action:(SEL)action;
@end
@implementation WebPolicyDecisionListenerPrivate
-(id)initWithTarget:(id)t action:(SEL)a
{
self = [super init];
if (self != nil) {
target = [t retain];
action = a;
}
return self;
}
-(void)dealloc
{
[target release];
[super dealloc];
}
@end
@implementation WebPolicyDecisionListener
-(void)usePolicy:(WebPolicyAction)policy
{
if (_private->target != nil) {
[_private->target performSelector:_private->action withObject:(id)policy];
}
}
@end
@implementation WebPolicyDecisionListener (WebPrivate)
-(id)_initWithTarget:(id)target action:(SEL)action
{
self = [super init];
if (self != nil) {
_private = [[WebPolicyDecisionListenerPrivate alloc] initWithTarget:target action:action];
}
return self;
}
-(void)dealloc
{
[_private release];
[super dealloc];
}
-(void)_invalidate
{
[self retain];
[_private->target release];
_private->target = nil;
[self release];
}
@end
/*
WebControllerPolicyDelegatePrivate.h
Copyright 2002, Apple, Inc. All rights reserved.
*/
#import <WebKit/WebControllerPolicyDelegate.h>
@interface WebPolicyDecisionListener (WebPrivate)
-(id)_initWithTarget:(id)target action:(SEL)action;
-(void)_invalidate;
@end
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