Making Policy Decisions
You can make decisions about what web content to display in a WebView by implementing a policy delegate that conforms to the WebPolicyDelegate protocol.
The protocol is very flexible, allowing you to make a wide range of policy decisions. For example, you can implement a policy delegate to log URL requests, check for patterns you might not permit, block certain websites, block types of files, and even block IP addresses. The protocol provides the hooks for you to intercept requests—you implement the actual policy decisions.
For example, follow these steps to modify the MiniBrowser application located in /Developer/Examples/WebKit
to ignore selected URLs:
Open
MyDocument.nib
using Interface Builder and set the WebView’spolicyDelegate
outlet toFile’s Owner
(the MyDocument instance).Implement
webView:decidePolicyForNavigationAction:request:frame:decisionListener:
to filter the URL requests. In this example, URL requests with host names ending incompany.com
are ignored.- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation
request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener {
NSString *host = [[request URL] host];
if ([host hasSuffix:@"company.com"])
[listener ignore];
else
[listener use];
}
Copyright © 2003, 2012 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2012-11-09