Show an error when WebKit fails to load the requested resource

WebKit will e.g. fail to load resources identified as application/octet-stream.
This commit is contained in:
Allan Odgaard
2014-04-28 17:37:42 +07:00
parent cb22cc0228
commit 7698ce2783
2 changed files with 26 additions and 0 deletions

View File

@@ -85,12 +85,14 @@ extern NSString* const kCommandRunnerURLScheme; // from HTMLOutput.h
{
self.runningCommand = NO;
self.autoScrollHelper = nil;
[super webView:sender didFailProvisionalLoadWithError:error forFrame:frame];
}
- (void)webView:(WebView*)sender didFailLoadWithError:(NSError*)error forFrame:(WebFrame*)frame
{
self.runningCommand = NO;
self.autoScrollHelper = nil;
[super webView:sender didFailLoadWithError:error forFrame:frame];
}
// =========================================

View File

@@ -4,6 +4,18 @@
#import <OakAppKit/OakUIConstructionFunctions.h>
#import <OakAppKit/NSColor Additions.h>
static NSString* EscapeHTML (NSString* str)
{
return [[[str stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"] stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"] stringByReplacingOccurrencesOfString:@"\"" withString:@"&quot;"];
}
static void ShowLoadErrorForURL (WebFrame* frame, NSURL* url, NSError* error)
{
NSString* options = [[url scheme] isEqualToString:@"file"] ? @" -R" : @"";
NSString* errorMsg = [NSString stringWithFormat:@"<title>Load Error</title><h1>Load Error</h1><p>WebKit reported <em>%@</em> while loading <tt><a href=\"#\" onClick=\"javascript:TextMate.system('/usr/bin/open%@ &quot;%@&quot;', null)\">%@</a></tt>.</p>", EscapeHTML([error localizedDescription]), options, EscapeHTML([url absoluteString]), EscapeHTML([url absoluteString])];
[frame loadHTMLString:errorMsg baseURL:[NSURL fileURLWithPath:NSTemporaryDirectory()]];
}
@interface HOBrowserView ()
@property (nonatomic, readwrite) WebView* webView;
@property (nonatomic, readwrite) HOStatusBar* statusBar;
@@ -143,6 +155,18 @@
[self setUpdatesProgress:YES];
}
- (void)webView:(WebView*)sender didFailProvisionalLoadWithError:(NSError*)error forFrame:(WebFrame*)frame
{
ShowLoadErrorForURL(frame, [[[frame provisionalDataSource] request] URL], error);
[self webView:sender didFinishLoadForFrame:frame];
}
- (void)webView:(WebView*)sender didFailLoadWithError:(NSError*)error forFrame:(WebFrame*)frame
{
ShowLoadErrorForURL(frame, [[[frame provisionalDataSource] request] URL], error);
[self webView:sender didFinishLoadForFrame:frame];
}
- (void)webView:(WebView*)sender didFinishLoadForFrame:(WebFrame*)frame
{
_statusBar.canGoBack = _webView.canGoBack;