[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

mjs mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:29:13 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 2713a624716a36fa9a62ca31859eca304cf4a6d2
Author: mjs <mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Mar 12 02:52:44 2003 +0000

    WebKit:
    
            Reviewed by Richard.
    
    	Final policy API changes:
    
    	- changed WebPolicyDecisionListener to protocol in public API
    	- replaced policy enum with separate methods
    	- made content policy handling async
    
            * WebKit.pbproj/project.pbxproj:
            * WebView.subproj/WebControllerPolicyDelegate.h:
            * WebView.subproj/WebControllerPolicyDelegate.m:
            (-[WebPolicyDecisionListener _usePolicy:]):
            (-[WebPolicyDecisionListener use]):
            (-[WebPolicyDecisionListener ignore]):
            (-[WebPolicyDecisionListener download]):
            * WebView.subproj/WebControllerPolicyDelegatePrivate.h:
            * WebView.subproj/WebDefaultPolicyDelegate.m:
            (-[WebDefaultPolicyDelegate unableToImplementPolicyWithError:inFrame:]):
            (-[WebDefaultPolicyDelegate decideNavigationPolicyForAction:andRequest:inFrame:decisionListener:]):
            (-[WebDefaultPolicyDelegate decideNewWindowPolicyForAction:andRequest:newFrameName:decisionListener:]):
            * WebView.subproj/WebFramePrivate.h:
            * WebView.subproj/WebFramePrivate.m:
            (switch):
            * WebView.subproj/WebMainResourceClient.h:
            * WebView.subproj/WebMainResourceClient.m:
            (-[WebMainResourceClient cancelContentPolicy]):
            (-[WebMainResourceClient cancel]):
            (-[WebMainResourceClient cancelQuietly]):
            (-[WebMainResourceClient cancelWithError:]):
            (-[WebMainResourceClient continueAfterContentPolicy:response:]):
            (-[WebMainResourceClient continueAfterContentPolicy:]):
            (-[WebMainResourceClient checkContentPolicyForResponse:]):
            (-[WebMainResourceClient resource:didReceiveResponse:]):
    
    WebBrowser:
    
            Reviewed by Richard.
    
    	- adjusted for WebKit API changes.
    
            * BrowserWebController.m:
            (-[BrowserWebController decideContentPolicyForMIMEType:andRequest:inFrame:decisionListener:]):
            (-[BrowserWebController tellListenerToUseContentPolicyAndRelease:]):
            (-[BrowserWebController confirmSendSheetDidEnd:returnCode:contextInfo:]):
            (-[BrowserWebController decidePolicyForAction:andRequest:inFrame:newFrameName:decisionListener:]):
            (-[BrowserWebController decideNavigationPolicyForAction:andRequest:inFrame:decisionListener:]):
            (-[BrowserWebController decideNewWindowPolicyForAction:andRequest:newFrameName:decisionListener:]):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3804 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 9387a3d..605b6a3 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,39 @@
+2003-03-11  Maciej Stachowiak  <mjs at apple.com>
+
+        Reviewed by Richard.
+
+	Final policy API changes:
+
+	- changed WebPolicyDecisionListener to protocol in public API
+	- replaced policy enum with separate methods
+	- made content policy handling async
+	
+        * WebKit.pbproj/project.pbxproj:
+        * WebView.subproj/WebControllerPolicyDelegate.h:
+        * WebView.subproj/WebControllerPolicyDelegate.m:
+        (-[WebPolicyDecisionListener _usePolicy:]):
+        (-[WebPolicyDecisionListener use]):
+        (-[WebPolicyDecisionListener ignore]):
+        (-[WebPolicyDecisionListener download]):
+        * WebView.subproj/WebControllerPolicyDelegatePrivate.h:
+        * WebView.subproj/WebDefaultPolicyDelegate.m:
+        (-[WebDefaultPolicyDelegate unableToImplementPolicyWithError:inFrame:]):
+        (-[WebDefaultPolicyDelegate decideNavigationPolicyForAction:andRequest:inFrame:decisionListener:]):
+        (-[WebDefaultPolicyDelegate decideNewWindowPolicyForAction:andRequest:newFrameName:decisionListener:]):
+        * WebView.subproj/WebFramePrivate.h:
+        * WebView.subproj/WebFramePrivate.m:
+        (switch):
+        * WebView.subproj/WebMainResourceClient.h:
+        * WebView.subproj/WebMainResourceClient.m:
+        (-[WebMainResourceClient cancelContentPolicy]):
+        (-[WebMainResourceClient cancel]):
+        (-[WebMainResourceClient cancelQuietly]):
+        (-[WebMainResourceClient cancelWithError:]):
+        (-[WebMainResourceClient continueAfterContentPolicy:response:]):
+        (-[WebMainResourceClient continueAfterContentPolicy:]):
+        (-[WebMainResourceClient checkContentPolicyForResponse:]):
+        (-[WebMainResourceClient resource:didReceiveResponse:]):
+
 2003-03-11  Darin Adler  <darin at apple.com>
 
         Reviewed by John.
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index 3295d00..b370fa1 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -1596,6 +1596,9 @@
 			fileRef = 658CF8C003851FB5008C2A4B;
 			isa = PBXBuildFile;
 			settings = {
+				ATTRIBUTES = (
+					Private,
+				);
 			};
 		};
 //650
diff --git a/WebKit/WebView.subproj/WebControllerPolicyDelegate.h b/WebKit/WebView.subproj/WebControllerPolicyDelegate.h
index a4599e1..e08c4d1 100644
--- a/WebKit/WebView.subproj/WebControllerPolicyDelegate.h
+++ b/WebKit/WebView.subproj/WebControllerPolicyDelegate.h
@@ -43,28 +43,53 @@ extern NSString *WebActionOriginalURLKey; // NSURL
 
 
 /*!
-    @enum WebPolicyAction
-    @abstract Potential actions to take when loading a URL
-    @constant WebPolicyUse Have WebKit use the resource.
-    @constant WebPolicySave Save the resource to disk.
-    @constant WebPolicyIgnore Do nothing with the resource.
+    @protocol WebPolicyDecisionListener
+    @discussion This protocol is used to call back with the results of a
+    policy decision. This provides the ability to make these decisions
+    asyncrhonously, which means the decision can be made by prompting
+    with a sheet, for example.
 */
-typedef enum {
-    WebPolicyUse,
-    WebPolicySave,
-    WebPolicyIgnore,
-} WebPolicyAction;
 
+ at protocol WebPolicyDecisionListener <NSObject>
 
- at class WebPolicyDecisionListenerPrivate;
+/*!
+    @method use
+    @abstract Use the resource
+    @discussion If there remain more policy decisions to be made, then
+    the next policy delegate method gets to decide. This will be
+    either the next navigation policy delegate if there is a redirect,
+    or the content policy delegate. If there are no more policy
+    decisions to be made, the resource will be displayed inline if
+    possible. If there is no view available to display the resource
+    inline, then unableToImplementPolicyWithError:inFrame: will be
+    called with an appropriate error. 
+
+    <p>If a new window is going to be created for this navigation as a
+    result of frame targetting, then it will be created once you call
+    this method.
+*/
+-(void)use;
 
- at interface WebPolicyDecisionListener : NSObject
-{
- at private
-    WebPolicyDecisionListenerPrivate *_private;
-}
+/*!
+    @method download
+    @abstract Download the resource instead of displaying it.
+    @discussion This method is more than just a convenience because it
+    allows an in-progress navigation to be converted to a download
+    based on content type, without having to stop and restart the
+    load.
+*/
+-(void)download;
 
--(void)usePolicy:(WebPolicyAction) policy;
+/*!
+    @method ignore
+    @abstract Do nothing (but the client may choose to handle the request itself)
+    @discussion A policy of ignore prevents WebKit from doing anything
+    further with the load, however, the client is still free to handle
+    the request in some other way, such as opening a new window,
+    opening a new window behind the current one, opening the URL in an
+    external app, revealing the location in Finder if a file URL, etc.
+*/
+-(void)ignore;
 
 @end
 
@@ -77,7 +102,7 @@ typedef enum {
 
     decideNewWindowPolicyForAction:andRequest:newFrameName:decisionListener: (at most once)<BR>
     decideNavigationPolicyForAction:inFrame::decisionListener: (one or more times)<BR>
-    contentPolicyForMIMEType:andRequest:inFrame: (at most once)<BR>
+    decideContentPolicyForMIMEType:andRequest:inFrame: (at most once)<BR>
 */
 @interface NSObject (WebPolicyDelegate)
 
@@ -94,7 +119,7 @@ typedef enum {
 - (void)decideNavigationPolicyForAction:(NSDictionary *)actionInformation
                              andRequest:(WebRequest *)request
                                 inFrame:(WebFrame *)frame
-                       decisionListener:(WebPolicyDecisionListener *)listener;
+                       decisionListener:(id<WebPolicyDecisionListener>)listener;
 
 /*!
      @method decideNewWindowPolicyForAction:andRequest:newFrameName:decisionListener:
@@ -115,18 +140,20 @@ typedef enum {
 - (void)decideNewWindowPolicyForAction:(NSDictionary *)actionInformation
                             andRequest:(WebRequest *)request
                           newFrameName:(NSString *)frameName
-                      decisionListener:(WebPolicyDecisionListener *)listener;
+                      decisionListener:(id<WebPolicyDecisionListener>)listener;
 
 /*!
-    @method contentPolicyForMIMEType:andRequest:inFrame:
+    @method decideContentPolicyForMIMEType:andRequest:inFrame:
     @discussion Returns the policy for content which has been partially loaded. Sent after locationChangeStarted. 
     @param type MIME type for the resource.
     @param request A WebResourceRequest for the partially loaded content.
     @param frame The frame which is loading the URL.
+    @param listener The object to call when the decision is made
 */
-- (WebPolicyAction)contentPolicyForMIMEType:(NSString *)type
+- (void)decideContentPolicyForMIMEType:(NSString *)type
                                  andRequest:(WebRequest *)request
-                                    inFrame:(WebFrame *)frame;
+                                    inFrame:(WebFrame *)frame
+                           decisionListener:(id<WebPolicyDecisionListener>)listener;
 
 /*!
     @method unableToImplementPolicy:error:forURL:inFrame:
diff --git a/WebKit/WebView.subproj/WebControllerPolicyDelegate.m b/WebKit/WebView.subproj/WebControllerPolicyDelegate.m
index 9121125..99de024 100644
--- a/WebKit/WebView.subproj/WebControllerPolicyDelegate.m
+++ b/WebKit/WebView.subproj/WebControllerPolicyDelegate.m
@@ -46,17 +46,6 @@ NSString *WebActionOriginalURLKey = @"WebActionOriginalURLKey";
 
 @implementation WebPolicyDecisionListener
 
--(void)usePolicy:(WebPolicyAction)policy
-{
-    if (_private->target != nil) {
-	[_private->target performSelector:_private->action withObject:(id)policy];
-    }
-}
-
- at end
-
- at implementation WebPolicyDecisionListener (WebPrivate)
-
 -(id)_initWithTarget:(id)target action:(SEL)action
 {
     self = [super init];
@@ -72,6 +61,14 @@ NSString *WebActionOriginalURLKey = @"WebActionOriginalURLKey";
     [super dealloc];
 }
 
+
+-(void)_usePolicy:(WebPolicyAction)policy
+{
+    if (_private->target != nil) {
+	[_private->target performSelector:_private->action withObject:(id)policy];
+    }
+}
+
 -(void)_invalidate
 {
     [self retain];
@@ -80,4 +77,19 @@ NSString *WebActionOriginalURLKey = @"WebActionOriginalURLKey";
     [self release];
 }
 
+-(void)use
+{
+    [self _usePolicy:WebPolicyUse];
+}
+
+-(void)ignore
+{
+    [self _usePolicy:WebPolicyIgnore];
+}
+
+-(void)download
+{
+    [self _usePolicy:WebPolicyDownload];
+}   
+
 @end
diff --git a/WebKit/WebView.subproj/WebControllerPolicyDelegatePrivate.h b/WebKit/WebView.subproj/WebControllerPolicyDelegatePrivate.h
index e1a1fe3..43fa768 100644
--- a/WebKit/WebView.subproj/WebControllerPolicyDelegatePrivate.h
+++ b/WebKit/WebView.subproj/WebControllerPolicyDelegatePrivate.h
@@ -6,7 +6,20 @@
 
 #import <WebKit/WebControllerPolicyDelegate.h>
 
- at interface WebPolicyDecisionListener (WebPrivate)
+typedef enum {
+    WebPolicyUse,
+    WebPolicyDownload,
+    WebPolicyIgnore,
+} WebPolicyAction;
+
+
+ at class WebPolicyDecisionListenerPrivate;
+
+ at interface WebPolicyDecisionListener : NSObject <WebPolicyDecisionListener>
+{
+ at private
+    WebPolicyDecisionListenerPrivate *_private;
+}
 
 -(id)_initWithTarget:(id)target action:(SEL)action;
 
diff --git a/WebKit/WebView.subproj/WebDefaultPolicyDelegate.m b/WebKit/WebView.subproj/WebDefaultPolicyDelegate.m
index 7541345..f6421b4 100644
--- a/WebKit/WebView.subproj/WebDefaultPolicyDelegate.m
+++ b/WebKit/WebView.subproj/WebDefaultPolicyDelegate.m
@@ -10,6 +10,7 @@
 #import <WebFoundation/WebResource.h>
 #import <WebFoundation/WebRequest.h>
 #import <WebFoundation/WebResponse.h>
+#import <WebFoundation/WebAssertions.h>
 
 
 @implementation WebDefaultPolicyDelegate
@@ -26,31 +27,32 @@ static WebDefaultPolicyDelegate *sharedDelegate = nil;
     return sharedDelegate;
 }
 
-- (void)unableToImplementPolicy:(WebPolicyAction)policy error:(WebError *)error forURL:(NSURL *)URL inFrame:(WebFrame *)frame
+- (void)unableToImplementPolicyWithError:(WebError *)error inFrame:(WebFrame *)frame
 {
-    NSLog (@"called unableToImplementPolicy:%derror:%@:inFrame:%@", policy, error, frame);
+    ERROR("called unableToImplementPolicyWithError:%@ inFrame:%@", error, frame);
 }
 
 
-- (WebPolicyAction)contentPolicyForMIMEType:(NSString *)type
+- (void)decideContentPolicyForMIMEType:(NSString *)type
 				 andRequest:(WebRequest *)request
-				    inFrame:(WebFrame *)frame;
+				    inFrame:(WebFrame *)frame
+		           decisionListener:(WebPolicyDecisionListener *)listener;
 {
     if ([[request URL] isFileURL]) {
 	BOOL isDirectory;
 	[[NSFileManager defaultManager] fileExistsAtPath:[[request URL] path] isDirectory:&isDirectory];
 	
-	if(isDirectory)
-	    return WebPolicyIgnore;
-	if([WebContentTypes canShowMIMEType:type])
-	    return WebPolicyUse;
-	return WebPolicyIgnore;
-    }
-
-    if ([WebContentTypes canShowMIMEType:type]) {
-        return WebPolicyUse;
+	if (isDirectory) {
+	    [listener ignore];
+	} else if([WebContentTypes canShowMIMEType:type]) {
+	    [listener use];
+	} else{
+	    [listener ignore];
+	}
+    } else if ([WebContentTypes canShowMIMEType:type]) {
+        [listener use];
     } else {
-        return WebPolicyIgnore;
+        [listener ignore];
     }
 }
 
@@ -60,14 +62,14 @@ static WebDefaultPolicyDelegate *sharedDelegate = nil;
 		       decisionListener:(WebPolicyDecisionListener *)listener
 {
     if ([WebResource canInitWithRequest:request]) {
-	[listener usePolicy:WebPolicyUse];
+	[listener use];
     } else {
 	// A file URL shouldn't fall through to here, but if it did,
 	// it would be a security risk to open it.
 	if (![[request URL] isFileURL]) {
 	    [[NSWorkspace sharedWorkspace] openURL:[request URL]];
 	}
-        [listener usePolicy:WebPolicyIgnore];
+        [listener ignore];
     }
 }
 
@@ -76,7 +78,7 @@ static WebDefaultPolicyDelegate *sharedDelegate = nil;
 			   newFrameName:(NSString *)frameName
 		       decisionListener:(WebPolicyDecisionListener *)listener
 {
-    [listener usePolicy:WebPolicyUse];
+    [listener use];
 }
 
 @end
diff --git a/WebKit/WebView.subproj/WebFramePrivate.h b/WebKit/WebView.subproj/WebFramePrivate.h
index bded20f..d0d71b0 100644
--- a/WebKit/WebView.subproj/WebFramePrivate.h
+++ b/WebKit/WebView.subproj/WebFramePrivate.h
@@ -7,7 +7,7 @@
 */
 
 #import <WebKit/WebFrame.h>
-#import <WebKit/WebControllerPolicyDelegate.h>
+#import <WebKit/WebControllerPolicyDelegatePrivate.h>
 
 @class WebBridge;
 @class WebFrameBridge;
@@ -15,6 +15,7 @@
 @class WebView;
 @class WebRequest;
 @class WebFormState;
+ at class WebPolicyDecisionListener;
 @protocol WebDOMElement;
 
 typedef enum {
@@ -149,7 +150,6 @@ typedef enum {
 - (void)_addChild:(WebFrame *)child;
 
 - (NSString *)_generateFrameName;
-
 - (NSDictionary *)_actionInformationForNavigationType:(WebNavigationType)navigationType event:(NSEvent *)event originalURL:(NSURL *)URL;
 
 - (WebHistoryItem *)_itemForSavingDocState;
diff --git a/WebKit/WebView.subproj/WebFramePrivate.m b/WebKit/WebView.subproj/WebFramePrivate.m
index 1a54616..9179319 100644
--- a/WebKit/WebView.subproj/WebFramePrivate.m
+++ b/WebKit/WebView.subproj/WebFramePrivate.m
@@ -1351,7 +1351,7 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
     switch (policy) {
     case WebPolicyIgnore:
         break;
-    case WebPolicySave:
+    case WebPolicyDownload:
 	// FIXME: should download full request
         [[self controller] _downloadURL:[request URL]];
         break;
@@ -1359,8 +1359,7 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
 	shouldContinue = YES;
         break;
     default:
-        [NSException raise:NSInvalidArgumentException
-                    format:@"clickPolicyForElement:button:modifierFlags: returned an invalid WebClickPolicy"];
+	ASSERT_NOT_REACHED();
     }
 
     [target performSelector:selector withObject:(shouldContinue ? request : nil) withObject:frameName withObject:formState];
@@ -1422,7 +1421,7 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
     switch (policy) {
     case WebPolicyIgnore:
         break;
-    case WebPolicySave:
+    case WebPolicyDownload:
 	// FIXME: should download full request
         [[self controller] _downloadURL:[request URL]];
         break;
@@ -1434,8 +1433,7 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
         }
         break;
     default:
-        [NSException raise:NSInvalidArgumentException
-                    format:@"clickPolicyForElement:button:modifierFlags: returned an invalid WebClickPolicy"];
+	ASSERT_NOT_REACHED();
     }
 
     [target performSelector:selector withObject:(shouldContinue ? request : nil) withObject:formState];
diff --git a/WebKit/WebView.subproj/WebMainResourceClient.h b/WebKit/WebView.subproj/WebMainResourceClient.h
index 099decc..1ca574c 100644
--- a/WebKit/WebView.subproj/WebMainResourceClient.h
+++ b/WebKit/WebView.subproj/WebMainResourceClient.h
@@ -10,6 +10,7 @@
 
 #import <WebKit/WebBaseResourceHandleDelegate.h>
 
+ at class WebPolicyDecisionListener;
 @class WebDataSource;
 
 @interface WebResourceDelegateProxy : NSObject <WebResourceDelegate>
@@ -24,6 +25,8 @@
     NSMutableData *resourceData;
     int _contentLength; // for logging only
     int _bytesReceived; // for logging only
+    WebPolicyDecisionListener *listener;
+    WebResponse *policyResponse;
     WebResourceDelegateProxy *proxy;
 }
 
diff --git a/WebKit/WebView.subproj/WebMainResourceClient.m b/WebKit/WebView.subproj/WebMainResourceClient.m
index 1384b94..2cd07c1 100644
--- a/WebKit/WebView.subproj/WebMainResourceClient.m
+++ b/WebKit/WebView.subproj/WebMainResourceClient.m
@@ -20,6 +20,7 @@
 #import <WebKit/WebDataSource.h>
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDefaultPolicyDelegate.h>
+#import <WebKit/WebControllerPolicyDelegatePrivate.h>
 #import <WebKit/WebDocument.h>
 #import <WebKit/WebDownloadPrivate.h>
 #import <WebKit/WebFrame.h>
@@ -73,14 +74,37 @@
     [self release];
 }
 
+- (void)cancelContentPolicy
+{
+    [listener _invalidate];
+    [listener release];
+    listener = nil;
+    [policyResponse release];
+    policyResponse = nil;
+}
+
 - (void)cancel
 {
+    [self cancelContentPolicy];
     LOG(Loading, "URL = %@", [dataSource _URL]);
     
     [resource cancel];
     [self receivedError:[self cancelledError]];
 }
 
+-(void)cancelQuietly
+{
+    [self cancelContentPolicy];
+    [super cancelQuietly];
+}
+
+-(void)cancelWithError:(WebError *)error
+{
+    [self cancelContentPolicy];
+    [super cancelWithError:error];
+}
+
+
 - (void)interruptForPolicyChange
 {
     // Terminate the locationChangeDelegate correctly.
@@ -147,7 +171,7 @@
 	}
         break;
 
-    case WebPolicySave:
+    case WebPolicyDownload:
         [proxy setDelegate:nil];
         [WebDownload _downloadWithLoadingResource:resource
                                           request:request
@@ -165,7 +189,7 @@
         break;
     
     default:
-        ERROR("contentPolicyForMIMEType:andRequest:inFrame: returned an invalid content policy.");
+	ASSERT_NOT_REACHED();
     }
 
     [super resource:resource didReceiveResponse:r];
@@ -175,21 +199,25 @@
     }
 }
 
+-(void)continueAfterContentPolicy:(WebPolicyAction)policy
+{
+    WebResponse *r = [policyResponse retain];
+    [self cancelContentPolicy];
+    [self continueAfterContentPolicy:policy response:r];
+    [r release];
+}
 
--(void)checkContentPolicyForResponse:(WebResponse *)r andCallSelector:(SEL)selector
+-(void)checkContentPolicyForResponse:(WebResponse *)r
 {
-    id pd = [[dataSource _controller] policyDelegate];
-    WebPolicyAction contentPolicy;
-    
-    if ([pd respondsToSelector:@selector(contentPolicyForMIMEType:andRequest:inFrame:)])
-        contentPolicy = [pd contentPolicyForMIMEType:[r contentType]
-                                                                andRequest:[dataSource request]
-                                                                   inFrame:[dataSource webFrame]];
-    else
-        contentPolicy = [[WebDefaultPolicyDelegate sharedPolicyDelegate] contentPolicyForMIMEType:[r contentType]
-                                                                andRequest:[dataSource request]
-                                                                   inFrame:[dataSource webFrame]];
-    [self performSelector:selector withObject:(id)contentPolicy withObject:r];
+    listener = [[WebPolicyDecisionListener alloc]
+		   _initWithTarget:self action:@selector(continueAfterContentPolicy:)];
+    policyResponse = [r retain];
+
+    [[dataSource _controller] setDefersCallbacks:YES];
+    [[[dataSource _controller] _policyDelegateForwarder] decideContentPolicyForMIMEType:[r contentType]
+						                      andRequest:[dataSource request]
+						                         inFrame:[dataSource webFrame]
+						                decisionListener:listener];
 }
 
 
@@ -205,7 +233,7 @@
     [[dataSource _controller] setDefersCallbacks:YES];
 
     // Figure out the content policy.
-    [self checkContentPolicyForResponse:r andCallSelector:@selector(continueAfterContentPolicy:response:)];
+    [self checkContentPolicyForResponse:r];
 
     _contentLength = [r contentLength];
 }
diff --git a/WebKit/WebView.subproj/WebMainResourceLoader.h b/WebKit/WebView.subproj/WebMainResourceLoader.h
index 099decc..1ca574c 100644
--- a/WebKit/WebView.subproj/WebMainResourceLoader.h
+++ b/WebKit/WebView.subproj/WebMainResourceLoader.h
@@ -10,6 +10,7 @@
 
 #import <WebKit/WebBaseResourceHandleDelegate.h>
 
+ at class WebPolicyDecisionListener;
 @class WebDataSource;
 
 @interface WebResourceDelegateProxy : NSObject <WebResourceDelegate>
@@ -24,6 +25,8 @@
     NSMutableData *resourceData;
     int _contentLength; // for logging only
     int _bytesReceived; // for logging only
+    WebPolicyDecisionListener *listener;
+    WebResponse *policyResponse;
     WebResourceDelegateProxy *proxy;
 }
 
diff --git a/WebKit/WebView.subproj/WebMainResourceLoader.m b/WebKit/WebView.subproj/WebMainResourceLoader.m
index 1384b94..2cd07c1 100644
--- a/WebKit/WebView.subproj/WebMainResourceLoader.m
+++ b/WebKit/WebView.subproj/WebMainResourceLoader.m
@@ -20,6 +20,7 @@
 #import <WebKit/WebDataSource.h>
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDefaultPolicyDelegate.h>
+#import <WebKit/WebControllerPolicyDelegatePrivate.h>
 #import <WebKit/WebDocument.h>
 #import <WebKit/WebDownloadPrivate.h>
 #import <WebKit/WebFrame.h>
@@ -73,14 +74,37 @@
     [self release];
 }
 
+- (void)cancelContentPolicy
+{
+    [listener _invalidate];
+    [listener release];
+    listener = nil;
+    [policyResponse release];
+    policyResponse = nil;
+}
+
 - (void)cancel
 {
+    [self cancelContentPolicy];
     LOG(Loading, "URL = %@", [dataSource _URL]);
     
     [resource cancel];
     [self receivedError:[self cancelledError]];
 }
 
+-(void)cancelQuietly
+{
+    [self cancelContentPolicy];
+    [super cancelQuietly];
+}
+
+-(void)cancelWithError:(WebError *)error
+{
+    [self cancelContentPolicy];
+    [super cancelWithError:error];
+}
+
+
 - (void)interruptForPolicyChange
 {
     // Terminate the locationChangeDelegate correctly.
@@ -147,7 +171,7 @@
 	}
         break;
 
-    case WebPolicySave:
+    case WebPolicyDownload:
         [proxy setDelegate:nil];
         [WebDownload _downloadWithLoadingResource:resource
                                           request:request
@@ -165,7 +189,7 @@
         break;
     
     default:
-        ERROR("contentPolicyForMIMEType:andRequest:inFrame: returned an invalid content policy.");
+	ASSERT_NOT_REACHED();
     }
 
     [super resource:resource didReceiveResponse:r];
@@ -175,21 +199,25 @@
     }
 }
 
+-(void)continueAfterContentPolicy:(WebPolicyAction)policy
+{
+    WebResponse *r = [policyResponse retain];
+    [self cancelContentPolicy];
+    [self continueAfterContentPolicy:policy response:r];
+    [r release];
+}
 
--(void)checkContentPolicyForResponse:(WebResponse *)r andCallSelector:(SEL)selector
+-(void)checkContentPolicyForResponse:(WebResponse *)r
 {
-    id pd = [[dataSource _controller] policyDelegate];
-    WebPolicyAction contentPolicy;
-    
-    if ([pd respondsToSelector:@selector(contentPolicyForMIMEType:andRequest:inFrame:)])
-        contentPolicy = [pd contentPolicyForMIMEType:[r contentType]
-                                                                andRequest:[dataSource request]
-                                                                   inFrame:[dataSource webFrame]];
-    else
-        contentPolicy = [[WebDefaultPolicyDelegate sharedPolicyDelegate] contentPolicyForMIMEType:[r contentType]
-                                                                andRequest:[dataSource request]
-                                                                   inFrame:[dataSource webFrame]];
-    [self performSelector:selector withObject:(id)contentPolicy withObject:r];
+    listener = [[WebPolicyDecisionListener alloc]
+		   _initWithTarget:self action:@selector(continueAfterContentPolicy:)];
+    policyResponse = [r retain];
+
+    [[dataSource _controller] setDefersCallbacks:YES];
+    [[[dataSource _controller] _policyDelegateForwarder] decideContentPolicyForMIMEType:[r contentType]
+						                      andRequest:[dataSource request]
+						                         inFrame:[dataSource webFrame]
+						                decisionListener:listener];
 }
 
 
@@ -205,7 +233,7 @@
     [[dataSource _controller] setDefersCallbacks:YES];
 
     // Figure out the content policy.
-    [self checkContentPolicyForResponse:r andCallSelector:@selector(continueAfterContentPolicy:response:)];
+    [self checkContentPolicyForResponse:r];
 
     _contentLength = [r contentLength];
 }
diff --git a/WebKit/WebView.subproj/WebPolicyDelegate.h b/WebKit/WebView.subproj/WebPolicyDelegate.h
index a4599e1..e08c4d1 100644
--- a/WebKit/WebView.subproj/WebPolicyDelegate.h
+++ b/WebKit/WebView.subproj/WebPolicyDelegate.h
@@ -43,28 +43,53 @@ extern NSString *WebActionOriginalURLKey; // NSURL
 
 
 /*!
-    @enum WebPolicyAction
-    @abstract Potential actions to take when loading a URL
-    @constant WebPolicyUse Have WebKit use the resource.
-    @constant WebPolicySave Save the resource to disk.
-    @constant WebPolicyIgnore Do nothing with the resource.
+    @protocol WebPolicyDecisionListener
+    @discussion This protocol is used to call back with the results of a
+    policy decision. This provides the ability to make these decisions
+    asyncrhonously, which means the decision can be made by prompting
+    with a sheet, for example.
 */
-typedef enum {
-    WebPolicyUse,
-    WebPolicySave,
-    WebPolicyIgnore,
-} WebPolicyAction;
 
+ at protocol WebPolicyDecisionListener <NSObject>
 
- at class WebPolicyDecisionListenerPrivate;
+/*!
+    @method use
+    @abstract Use the resource
+    @discussion If there remain more policy decisions to be made, then
+    the next policy delegate method gets to decide. This will be
+    either the next navigation policy delegate if there is a redirect,
+    or the content policy delegate. If there are no more policy
+    decisions to be made, the resource will be displayed inline if
+    possible. If there is no view available to display the resource
+    inline, then unableToImplementPolicyWithError:inFrame: will be
+    called with an appropriate error. 
+
+    <p>If a new window is going to be created for this navigation as a
+    result of frame targetting, then it will be created once you call
+    this method.
+*/
+-(void)use;
 
- at interface WebPolicyDecisionListener : NSObject
-{
- at private
-    WebPolicyDecisionListenerPrivate *_private;
-}
+/*!
+    @method download
+    @abstract Download the resource instead of displaying it.
+    @discussion This method is more than just a convenience because it
+    allows an in-progress navigation to be converted to a download
+    based on content type, without having to stop and restart the
+    load.
+*/
+-(void)download;
 
--(void)usePolicy:(WebPolicyAction) policy;
+/*!
+    @method ignore
+    @abstract Do nothing (but the client may choose to handle the request itself)
+    @discussion A policy of ignore prevents WebKit from doing anything
+    further with the load, however, the client is still free to handle
+    the request in some other way, such as opening a new window,
+    opening a new window behind the current one, opening the URL in an
+    external app, revealing the location in Finder if a file URL, etc.
+*/
+-(void)ignore;
 
 @end
 
@@ -77,7 +102,7 @@ typedef enum {
 
     decideNewWindowPolicyForAction:andRequest:newFrameName:decisionListener: (at most once)<BR>
     decideNavigationPolicyForAction:inFrame::decisionListener: (one or more times)<BR>
-    contentPolicyForMIMEType:andRequest:inFrame: (at most once)<BR>
+    decideContentPolicyForMIMEType:andRequest:inFrame: (at most once)<BR>
 */
 @interface NSObject (WebPolicyDelegate)
 
@@ -94,7 +119,7 @@ typedef enum {
 - (void)decideNavigationPolicyForAction:(NSDictionary *)actionInformation
                              andRequest:(WebRequest *)request
                                 inFrame:(WebFrame *)frame
-                       decisionListener:(WebPolicyDecisionListener *)listener;
+                       decisionListener:(id<WebPolicyDecisionListener>)listener;
 
 /*!
      @method decideNewWindowPolicyForAction:andRequest:newFrameName:decisionListener:
@@ -115,18 +140,20 @@ typedef enum {
 - (void)decideNewWindowPolicyForAction:(NSDictionary *)actionInformation
                             andRequest:(WebRequest *)request
                           newFrameName:(NSString *)frameName
-                      decisionListener:(WebPolicyDecisionListener *)listener;
+                      decisionListener:(id<WebPolicyDecisionListener>)listener;
 
 /*!
-    @method contentPolicyForMIMEType:andRequest:inFrame:
+    @method decideContentPolicyForMIMEType:andRequest:inFrame:
     @discussion Returns the policy for content which has been partially loaded. Sent after locationChangeStarted. 
     @param type MIME type for the resource.
     @param request A WebResourceRequest for the partially loaded content.
     @param frame The frame which is loading the URL.
+    @param listener The object to call when the decision is made
 */
-- (WebPolicyAction)contentPolicyForMIMEType:(NSString *)type
+- (void)decideContentPolicyForMIMEType:(NSString *)type
                                  andRequest:(WebRequest *)request
-                                    inFrame:(WebFrame *)frame;
+                                    inFrame:(WebFrame *)frame
+                           decisionListener:(id<WebPolicyDecisionListener>)listener;
 
 /*!
     @method unableToImplementPolicy:error:forURL:inFrame:
diff --git a/WebKit/WebView.subproj/WebPolicyDelegate.m b/WebKit/WebView.subproj/WebPolicyDelegate.m
index 9121125..99de024 100644
--- a/WebKit/WebView.subproj/WebPolicyDelegate.m
+++ b/WebKit/WebView.subproj/WebPolicyDelegate.m
@@ -46,17 +46,6 @@ NSString *WebActionOriginalURLKey = @"WebActionOriginalURLKey";
 
 @implementation WebPolicyDecisionListener
 
--(void)usePolicy:(WebPolicyAction)policy
-{
-    if (_private->target != nil) {
-	[_private->target performSelector:_private->action withObject:(id)policy];
-    }
-}
-
- at end
-
- at implementation WebPolicyDecisionListener (WebPrivate)
-
 -(id)_initWithTarget:(id)target action:(SEL)action
 {
     self = [super init];
@@ -72,6 +61,14 @@ NSString *WebActionOriginalURLKey = @"WebActionOriginalURLKey";
     [super dealloc];
 }
 
+
+-(void)_usePolicy:(WebPolicyAction)policy
+{
+    if (_private->target != nil) {
+	[_private->target performSelector:_private->action withObject:(id)policy];
+    }
+}
+
 -(void)_invalidate
 {
     [self retain];
@@ -80,4 +77,19 @@ NSString *WebActionOriginalURLKey = @"WebActionOriginalURLKey";
     [self release];
 }
 
+-(void)use
+{
+    [self _usePolicy:WebPolicyUse];
+}
+
+-(void)ignore
+{
+    [self _usePolicy:WebPolicyIgnore];
+}
+
+-(void)download
+{
+    [self _usePolicy:WebPolicyDownload];
+}   
+
 @end
diff --git a/WebKit/WebView.subproj/WebPolicyDelegatePrivate.h b/WebKit/WebView.subproj/WebPolicyDelegatePrivate.h
index e1a1fe3..43fa768 100644
--- a/WebKit/WebView.subproj/WebPolicyDelegatePrivate.h
+++ b/WebKit/WebView.subproj/WebPolicyDelegatePrivate.h
@@ -6,7 +6,20 @@
 
 #import <WebKit/WebControllerPolicyDelegate.h>
 
- at interface WebPolicyDecisionListener (WebPrivate)
+typedef enum {
+    WebPolicyUse,
+    WebPolicyDownload,
+    WebPolicyIgnore,
+} WebPolicyAction;
+
+
+ at class WebPolicyDecisionListenerPrivate;
+
+ at interface WebPolicyDecisionListener : NSObject <WebPolicyDecisionListener>
+{
+ at private
+    WebPolicyDecisionListenerPrivate *_private;
+}
 
 -(id)_initWithTarget:(id)target action:(SEL)action;
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list