From 0291a3a646911ad30480ab925034ab7f765a8acf Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 21 Mar 2011 04:15:24 -0700 Subject: Fix underlying Apple UIWebViewWebViewDelegate on 2.x retain/release bug. --- CyteKit/WebView.mm | 14 ++++++++++++++ iPhonePrivate.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/CyteKit/WebView.mm b/CyteKit/WebView.mm index 1329d4f..0e8ba71 100644 --- a/CyteKit/WebView.mm +++ b/CyteKit/WebView.mm @@ -118,6 +118,15 @@ } - (void) dealloc { + if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) { + UIWebViewInternal *&_internal(MSHookIvar(self, "_internal")); + if (&_internal != NULL) { + UIWebViewWebViewDelegate *&webViewDelegate(MSHookIvar(_internal, "webViewDelegate")); + if (&webViewDelegate != NULL) + [webViewDelegate _clearUIWebView]; + } + } + [super dealloc]; } @@ -353,6 +362,10 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se @end +static void $UIWebViewWebViewDelegate$_clearUIWebView(UIWebViewWebViewDelegate *self, SEL sel) { + MSHookIvar(self, "uiWebView") = nil; +} + __attribute__((__constructor__)) static void $() { if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) { class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12"); @@ -362,5 +375,6 @@ __attribute__((__constructor__)) static void $() { class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didReceiveTitle:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$, "v20@0:4@8@12@16"); class_addMethod($UIWebViewWebViewDelegate, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), (IMP) &$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$, "@28@0:4@8@12@16@20@24"); class_addMethod($UIWebViewWebViewDelegate, @selector(webViewClose:), (IMP) &$UIWebViewWebViewDelegate$webViewClose$, "v12@0:4@8"); + class_addMethod($UIWebViewWebViewDelegate, @selector(_clearUIWebView), (IMP) &$UIWebViewWebViewDelegate$_clearUIWebView, "v8@0:4"); } } diff --git a/iPhonePrivate.h b/iPhonePrivate.h index 8cc997a..cddfe9c 100644 --- a/iPhonePrivate.h +++ b/iPhonePrivate.h @@ -124,6 +124,9 @@ typedef enum { @interface UIWebViewWebViewDelegate : NSObject { @public UIWebView *uiWebView; } + +- (void) _clearUIWebView; + @end // }}} // @interface *Button : * {{{ -- cgit v1.2.3