+@implementation WebViewCustomProtocol
+
++ (BOOL)canInitWithRequest:(NSURLRequest *)request
+{
+ NSString *scheme = [[request URL] scheme];
+
+ wxStringToWebHandlerMap::const_iterator it;
+ for( it = g_stringHandlerMap.begin(); it != g_stringHandlerMap.end(); ++it )
+ {
+ if(it->first.IsSameAs(wxStringWithNSString(scheme)))
+ {
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
++ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
+{
+ //We don't do any processing here as the wxWebViewHandler classes do it
+ return request;
+}
+
+- (void)startLoading
+{
+ NSURLRequest *request = [self request];
+ NSString* path = [[request URL] absoluteString];
+
+ id<NSURLProtocolClient> client = [self client];
+
+ wxString wxpath = wxStringWithNSString(path);
+ wxString scheme = wxStringWithNSString([[request URL] scheme]);
+ wxFSFile* file = g_stringHandlerMap[scheme]->GetFile(wxpath);
+
+ if (!file)
+ {
+ NSError *error = [[NSError alloc] initWithDomain:NSURLErrorDomain
+ code:NSURLErrorFileDoesNotExist
+ userInfo:nil];
+
+ [client URLProtocol:self didFailWithError:error];
+
+ return;
+ }
+
+ size_t length = file->GetStream()->GetLength();
+
+
+ NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[request URL]
+ MIMEType:wxNSStringWithWxString(file->GetMimeType())
+ expectedContentLength:length
+ textEncodingName:nil];
+
+ //Load the data, we malloc it so it is tidied up properly
+ void* buffer = malloc(length);
+ file->GetStream()->Read(buffer, length);
+ NSData *data = [[NSData alloc] initWithBytesNoCopy:buffer length:length];
+
+ //We do not support caching anything yet
+ [client URLProtocol:self didReceiveResponse:response
+ cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+
+ //Set the data
+ [client URLProtocol:self didLoadData:data];
+
+ //Notify that we have finished
+ [client URLProtocolDidFinishLoading:self];
+
+ [response release];
+}
+
+- (void)stopLoading
+{
+
+}
+
+@end
+
+
+@implementation WebViewUIDelegate
+
+- initWithWxWindow: (wxWebViewWebKit*)inWindow
+{
+ [super init];
+ webKitWindow = inWindow; // non retained
+ return self;
+}
+
+- (void)webView:(WebView *)sender printFrameView:(WebFrameView *)frameView
+{
+ wxUnusedVar(sender);
+ wxUnusedVar(frameView);
+
+ webKitWindow->Print();
+}
+
+- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element
+ defaultMenuItems:(NSArray *) defaultMenuItems
+{
+ if(webKitWindow->IsContextMenuEnabled())
+ return defaultMenuItems;
+ else
+ return nil;
+}
+@end
+
+#endif //wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT