2 WebDefaultPolicyDelegate.m
3 Copyright 2002, Apple Computer, Inc.
5 #import <WebKit/WebDataSource.h>
6 #import <WebKit/WebDefaultPolicyDelegate.h>
7 #import <WebKit/WebFrame.h>
8 #import <WebKit/WebPolicyDelegatePrivate.h>
9 #import <WebKit/WebView.h>
10 #import <WebKit/WebViewPrivate.h>
12 #import <Foundation/NSURLConnection.h>
13 #import <Foundation/NSURLRequest.h>
14 #import <Foundation/NSURLResponse.h>
15 #import <WebKit/WebAssertions.h>
18 @implementation WebDefaultPolicyDelegate
20 static WebDefaultPolicyDelegate *sharedDelegate = nil;
22 // Return a object with vanilla implementations of the protocol's methods
23 // Note this feature relies on our default delegate being stateless
24 + (WebDefaultPolicyDelegate *)sharedPolicyDelegate
26 if (!sharedDelegate) {
27 sharedDelegate = [[WebDefaultPolicyDelegate alloc] init];
29 return sharedDelegate;
32 - (void)webView: (WebView *)wv unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame
34 ERROR("called unableToImplementPolicyWithError:%@ inFrame:%@", error, frame);
38 - (void)webView: (WebView *)wv decidePolicyForMIMEType:(NSString *)type
39 request:(NSURLRequest *)request
40 frame:(WebFrame *)frame
41 decisionListener:(WebPolicyDecisionListener *)listener;
43 if ([[request URL] isFileURL]) {
45 [[NSFileManager defaultManager] fileExistsAtPath:[[request URL] path] isDirectory:&isDirectory];
49 } else if([WebView canShowMIMEType:type]) {
54 } else if ([WebView canShowMIMEType:type]) {
61 - (void)webView: (WebView *)wv decidePolicyForNavigationAction:(NSDictionary *)actionInformation
62 request:(NSURLRequest *)request
63 frame:(WebFrame *)frame
64 decisionListener:(WebPolicyDecisionListener *)listener
66 WebNavigationType navType = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue];
68 if ([WebView _canHandleRequest:request]) {
70 } else if (navType == WebNavigationTypePlugInRequest) {
73 // A file URL shouldn't fall through to here, but if it did,
74 // it would be a security risk to open it.
75 if (![[request URL] isFileURL]) {
76 [[NSWorkspace sharedWorkspace] openURL:[request URL]];
82 - (void)webView: (WebView *)wv decidePolicyForNewWindowAction:(NSDictionary *)actionInformation
83 request:(NSURLRequest *)request
84 newFrameName:(NSString *)frameName
85 decisionListener:(WebPolicyDecisionListener *)listener
90 // Temporary SPI needed for <rdar://problem/3951283> can view pages from the back/forward cache that should be disallowed by Parental Controls
91 - (BOOL)webView:(WebView *)webView shouldGoToHistoryItem:(WebHistoryItem *)item