Permalink
Browse files

Create a PolicyDelegate for NavigationAction

Have links clicked by the user be opened in the user's default
browser.
  • Loading branch information...
1 parent bc13d12 commit 366b2ab85c360e0379150b7e07f5a8b0ba2b9c20 @sc68cal sc68cal committed Dec 31, 2012
Showing with 17 additions and 0 deletions.
  1. +2 −0 ViewDown/Document.h
  2. +15 −0 ViewDown/Document.m
View
@@ -52,6 +52,8 @@
-(void)webView:(WebView *)webView willPerformDragDestinationAction:(WebDragDestinationAction)action forDraggingInfo:(id <NSDraggingInfo>)draggingInfo;
-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;
+
+-(void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener;
/////////////////////////////////////////////////
@end
View
@@ -121,6 +121,8 @@ -(void)awakeFromNib
[self setCurrent:NULL];
}
+ [web setPolicyDelegate:self];
+
}
@@ -573,6 +575,19 @@ -(NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings er
}
+- (void)webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation
+ request:(NSURLRequest *)request frame:(WebFrame *)frame
+ decisionListener:(id <WebPolicyDecisionListener>)listener
+{
+ NSURL *url = [request URL];
+ if(url.isFileURL)
+ [listener use];
+ else{
+ [listener ignore];
+ [[NSWorkspace sharedWorkspace] openURL:url];
+ }
+}
+
+ (BOOL)autosavesInPlace
{
return YES;

0 comments on commit 366b2ab

Please sign in to comment.