]> git.saurik.com Git - cydia.git/blobdiff - UICaboodle/BrowserView.mm
say thank you, comex :P. animation for editing bar button item for sections.
[cydia.git] / UICaboodle / BrowserView.mm
index bd2c2367b6b1b11c947a21b95077d157ebc38e1e..4523f91b37226c0269db9f31a3605fa95605609f 100644 (file)
@@ -10,8 +10,14 @@ extern NSString * const kCAFilterNearest;
 
 #include "substrate.h"
 
+#define ForSaurik 0
+
+static bool Wildcat_;
+
 static CFArrayRef (*$GSSystemCopyCapability)(CFStringRef);
 static CFArrayRef (*$GSSystemGetCapability)(CFStringRef);
+static Class $UIFormAssistant;
+static Class $UIWebBrowserView;
 
 @interface NSString (UIKit)
 - (NSString *) stringByAddingPercentEscapes;
@@ -142,79 +148,32 @@ static CFArrayRef (*$GSSystemGetCapability)(CFStringRef);
 
 @end
 
-#if 0
-/* Mail Composition {{{ */
-@interface MailToView : PopUpView {
-    MailComposeController *controller_;
+@interface BrowserViewActualView : UIView {
+@private
+    UIWebDocumentView *documentView;
 }
-
-- (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url;
-
+@property (nonatomic, retain) UIWebDocumentView *documentView;
 @end
 
-@implementation MailToView
-
-- (void) dealloc {
-    [controller_ release];
-    [super dealloc];
-}
-
-- (void) mailComposeControllerWillAttemptToSend:(MailComposeController *)controller {
-    NSLog(@"will");
-}
-
-- (void) mailComposeControllerDidAttemptToSend:(MailComposeController *)controller mailDelivery:(id)delivery {
-    NSLog(@"did:%@", delivery);
-// [UIApp setStatusBarShowsProgress:NO];
-if ([controller error]){
-NSArray *buttons = [NSArray arrayWithObjects:UCLocalize("OK"), nil];
-UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self];
-[mailAlertSheet setBodyText:[controller error]];
-[mailAlertSheet popupAlertAnimated:YES];
-}
-}
-
-- (void) showError {
-    NSLog(@"%@", [controller_ error]);
-    NSArray *buttons = [NSArray arrayWithObjects:UCLocalize("OK"), nil];
-    UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self];
-    [mailAlertSheet setBodyText:[controller_ error]];
-    [mailAlertSheet popupAlertAnimated:YES];
-}
+@implementation BrowserViewActualView
 
-- (void) deliverMessage { _pooled
-    setuid(501);
-    setgid(501);
+@synthesize documentView;
 
-    if (![controller_ deliverMessage])
-        [self performSelectorOnMainThread:@selector(showError) withObject:nil waitUntilDone:NO];
+- (void)dealloc {
+    [documentView release];
+    [super dealloc];
 }
 
-- (void) mailComposeControllerCompositionFinished:(MailComposeController *)controller {
-    if ([controller_ needsDelivery])
-        [NSThread detachNewThreadSelector:@selector(deliverMessage) toTarget:self withObject:nil];
-    else
-        [self cancel];
-}
-
-- (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url {
-    if ((self = [super initWithView:view delegate:delegate]) != nil) {
-        controller_ = [[MailComposeController alloc] initForContentSize:[overlay_ bounds].size];
-        [controller_ setDelegate:self];
-        [controller_ initializeUI];
-        [controller_ setupForURL:url];
-
-        UIView *view([controller_ view]);
-        [overlay_ addSubview:view];
-    } return self;
+- (void)layoutSubviews {
+    [super layoutSubviews];
+    if ([documentView respondsToSelector:@selector(setMinimumSize:)])
+        [documentView setMinimumSize:documentView.bounds.size];
 }
 
 @end
-/* }}} */
-#endif
 
 #define ShowInternals 0
-#define LogBrowser 0
+#define LogBrowser 1
 
 #define lprintf(args...) fprintf(stderr, args)
 
@@ -225,7 +184,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 #endif
 
 + (void) _initialize {
-    [WebView enableWebThread];
+    //[WebView enableWebThread];
 
     WebPreferences *preferences([WebPreferences standardPreferences]);
     [preferences setCacheModel:WebCacheModelDocumentBrowser];
@@ -235,6 +194,15 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 
     $GSSystemCopyCapability = reinterpret_cast<CFArrayRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemCopyCapability"));
     $GSSystemGetCapability = reinterpret_cast<CFArrayRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemGetCapability"));
+    $UIFormAssistant = objc_getClass("UIFormAssistant");
+
+    $UIWebBrowserView = objc_getClass("UIWebBrowserView");
+    if ($UIWebBrowserView == nil) {
+        Wildcat_ = false;
+        $UIWebBrowserView = objc_getClass("UIWebDocumentView");
+    } else {
+        Wildcat_ = true;
+    }
 }
 
 - (void) dealloc {
@@ -247,7 +215,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 
     WebThreadLock();
 
-    WebView *webview = [webview_ webView];
+    WebView *webview = [document_ webView];
     [webview setFrameLoadDelegate:nil];
     [webview setResourceLoadDelegate:nil];
     [webview setUIDelegate:nil];
@@ -263,10 +231,13 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     /* XXX: no one sets this, ever
     [webview setWebMailDelegate:nil];*/
 
-    [webview_ setDelegate:nil];
-    [webview_ setGestureDelegate:nil];
-    [webview_ setFormEditingDelegate:nil];
-    [webview_ setInteractionDelegate:nil];
+    [document_ setDelegate:nil];
+    [document_ setGestureDelegate:nil];
+
+    if ([document_ respondsToSelector:@selector(setFormEditingDelegate:)])
+        [document_ setFormEditingDelegate:nil];
+
+    [document_ setInteractionDelegate:nil];
 
     [indirect_ setDelegate:nil];
 
@@ -275,10 +246,10 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     [webview close];
 
 #if RecycleWebViews
-    [webview_ removeFromSuperview];
-    [Documents_ addObject:[webview_ autorelease]];
+    [document_ removeFromSuperview];
+    [Documents_ addObject:[document_ autorelease]];
 #else
-    [webview_ release];
+    [document_ release];
 #endif
 
     [indirect_ release];
@@ -315,7 +286,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     [self loadRequest:[NSURLRequest
         requestWithURL:url
         cachePolicy:policy
-        timeoutInterval:30.0
+        timeoutInterval:120.0
     ]];
 }
 
@@ -328,7 +299,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     error_ = false;
 
     WebThreadLock();
-    [webview_ loadRequest:request];
+    [document_ loadRequest:request];
     WebThreadUnlock();
 }
 
@@ -347,26 +318,29 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
             context:@"submit"
         ] autorelease];
 
+        [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
         [sheet setNumberOfRows:1];
         [sheet popupAlertAnimated:YES];
     }
 }
 
 - (WebView *) webView {
-    return [webview_ webView];
+    return [document_ webView];
 }
 
 - (UIWebDocumentView *) documentView {
-    return webview_;
+    return document_;
 }
 
 /* XXX: WebThreadLock? */
 - (void) _fixScroller:(CGRect)bounds {
-    float extra;
-    if (!editing_)
+       float extra;
+
+    if (!editing_ || $UIFormAssistant == nil)
         extra = 0;
     else {
-        UIFormAssistant *assistant([UIFormAssistant sharedFormAssistant]);
+        UIFormAssistant *assistant([$UIFormAssistant sharedFormAssistant]);
         CGRect peripheral([assistant peripheralFrame]);
 #if LogBrowser
         NSLog(@"per:%f", peripheral.size.height);
@@ -376,20 +350,22 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 
     CGRect subrect([scroller_ frame]);
     subrect.size.height -= extra;
-    [scroller_ setScrollerIndicatorSubrect:subrect];
 
-    NSSize visible(NSMakeSize(subrect.size.width, subrect.size.height));
-    [webview_ setValue:[NSValue valueWithSize:visible] forGestureAttribute:UIGestureAttributeVisibleSize];
+    if ([scroller_ respondsToSelector:@selector(setScrollerIndicatorSubrect:)])
+        [scroller_ setScrollerIndicatorSubrect:subrect];
+
+    [document_ setValue:[NSValue valueWithSize:NSMakeSize(subrect.size.width, subrect.size.height)] forGestureAttribute:UIGestureAttributeVisibleSize];
 
     CGSize size(size_);
     size.height += extra;
     [scroller_ setContentSize:size];
 
-    [scroller_ releaseRubberBandIfNecessary];
+    if ([scroller_ respondsToSelector:@selector(releaseRubberBandIfNecessary)])
+        [scroller_ releaseRubberBandIfNecessary];
 }
 
 - (void) fixScroller {
-    CGRect bounds([webview_ documentBounds]);
+    CGRect bounds([document_ documentBounds]);
 #if TrackResize
     NSLog(@"_fs:(%f,%f+%f,%f)", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
 #endif
@@ -408,10 +384,10 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     [self view:sender didSetFrame:frame];
 }
 
-- (void) pushPage:(RVPage *)page {
+- (void) pushPage:(UCViewController *)page {
     [page setDelegate:delegate_];
-    [self setBackButtonTitle:title_];
-    [book_ pushPage:page];
+    [[self navigationItem] setTitle:title_];
+    [[self navigationController] pushViewController:page animated:YES];
 }
 
 - (void) _pushPage {
@@ -419,15 +395,14 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         return;
     // WTR: [self autorelease];
     pushed_ = true;
-    [book_ pushPage:self];
+    [[self navigationController] pushViewController:self animated:YES];
 }
 
-- (void) swapPage:(RVPage *)page {
+- (void) swapPage:(UCViewController *)page {
     [page setDelegate:delegate_];
-    if (pushed_)
-        [book_ swapPage:page];
-    else
-        [book_ pushPage:page];
+    if (pushed_) [[self navigationController] popViewControllerAnimated:NO];
+               
+       [[self navigationController] pushViewController:page animated:NO];
 }
 
 - (BOOL) getSpecial:(NSURL *)url swap:(BOOL)swap {
@@ -435,7 +410,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     NSLog(@"getSpecial:%@", url);
 #endif
 
-    if (RVPage *page = [delegate_ pageForURL:url hasTag:NULL]) {
+    if (UCViewController *page = [delegate_ pageForURL:url hasTag:NULL]) {
         if (swap)
             [self swapPage:page];
         else
@@ -476,6 +451,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         context:@"sensitive"
     ] autorelease];
 
+    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
     NSString *host(@"XXX");
 
     [sheet setNumberOfRows:1];
@@ -518,6 +495,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         context:@"alert"
     ] autorelease];
 
+    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
     [sheet setBodyText:message];
     [sheet popupAlertAnimated:YES];
 }
@@ -535,6 +514,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         context:@"confirm"
     ] autorelease];
 
+    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
     [sheet setNumberOfRows:1];
     [sheet setBodyText:message];
     [sheet popupAlertAnimated:YES];
@@ -574,7 +555,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
-    [self reloadButtons];
+       [self reloadButtons];
 }
 
 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
@@ -590,7 +571,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
-    [self reloadButtons];
+       [self reloadButtons];
 }
 
 - (void) setFinishHook:(id)function {
@@ -606,12 +587,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 }
 
 - (void) _openMailToURL:(NSURL *)url {
-// XXX: this makes me sad
-#if 0
-    [[[MailToView alloc] initWithView:underlay_ delegate:self url:url] autorelease];
-#else
     [UIApp openURL:url];// asPanel:YES];
-#endif
 }
 
 - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
@@ -628,11 +604,11 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 }
 
 - (void) webViewClose:(WebView *)sender {
-    [book_ close];
+       [self close];
 }
 
 - (void) close {
-    [book_ close];
+    [[self navigationController] dismissModalViewControllerAnimated:YES];
 }
 
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
@@ -662,25 +638,32 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
             if ([scheme isEqualToString:@"mailto"])
                 [self _openMailToURL:url];
             else {
-                RVBook *book([[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
-                [book setHook:indirect_];
+                UCNavigationController *navigation([[[UCNavigationController alloc] init] autorelease]);
+                [navigation setHook:indirect_];
 
-                RVPage *page([delegate_ pageForURL:url hasTag:NULL]);
+                UCViewController *page([delegate_ pageForURL:url hasTag:NULL]);
                 if (page == nil) {
                     /* XXX: call createWebViewWithRequest instead? */
 
-                    [self setBackButtonTitle:title_];
-
-                    BrowserView *browser([[[class_ alloc] initWithBook:book] autorelease]);
+                    BrowserView *browser([[[class_ alloc] init] autorelease]);
                     [browser loadURL:url];
                     page = browser;
                 }
 
-                [book setDelegate:delegate_];
+                [navigation setDelegate:delegate_];
                 [page setDelegate:delegate_];
 
-                [book setPage:page];
-                [book_ pushBook:book];
+                [navigation setViewControllers:[NSArray arrayWithObject:page]];
+                               UIBarButtonItem *closeItem = [[UIBarButtonItem alloc]
+                               initWithTitle:UCLocalize("CLOSE")
+                                       style:UIBarButtonItemStylePlain
+                               target:page
+                               action:@selector(close)
+                           ];
+                           [[page navigationItem] setLeftBarButtonItem:closeItem];
+                           [closeItem release];
+                       
+                [[self navigationController] presentModalViewController:navigation animated:YES];
             }
         } else goto unknown;
 
@@ -696,7 +679,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         // XXX: handle more mime types!
         [listener ignore];
 
-        WebView *webview([webview_ webView]);
+        WebView *webview([document_ webView]);
         if (frame == [webview mainFrame])
             [UIApp openURL:[request URL]];
     }
@@ -723,7 +706,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 
         [listener use];
 
-        WebView *webview([webview_ webView]);
+        WebView *webview([document_ webView]);
         if (frame == [webview mainFrame])
             [self _pushPage];
         return;
@@ -843,8 +826,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
                 [sender cancelAuthenticationChallenge:challenge_];
             break;
 
-            default:
-                _assert(false);
+            _nodefault
         }
 
         [challenge_ release];
@@ -859,13 +841,12 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
             case 2:
                 if (request_ != nil) {
                     WebThreadLock();
-                    [webview_ loadRequest:request_];
+                    [document_ loadRequest:request_];
                     WebThreadUnlock();
                 }
             break;
 
-            default:
-                _assert(false);
+            _nodefault
         }
 
         [sheet dismiss];
@@ -888,6 +869,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         context:@"challenge"
     ] autorelease];
 
+    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
     [sheet setNumberOfRows:1];
 
     [sheet addTextFieldWithValue:@"" label:UCLocalize("USERNAME")];
@@ -928,25 +911,34 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     NSNumber *value([features objectForKey:@"width"]);
     float width(value == nil ? 0 : [value floatValue]);
 
-    RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
+    UCNavigationController *navigation(!popup_ ? [self navigationController] : [[[UCNavigationController alloc] init] autorelease]);
 
     /* XXX: deal with cydia:// pages */
-    BrowserView *browser([[[class_ alloc] initWithBook:book forWidth:width] autorelease]);
+    BrowserView *browser([[[class_ alloc] initWithWidth:width] autorelease]);
 
     if (features != nil && popup_) {
-        [book setDelegate:delegate_];
-        [book setHook:indirect_];
+        [navigation setDelegate:delegate_];
+        [navigation setHook:indirect_];
         [browser setDelegate:delegate_];
 
         [browser loadRequest:request];
 
-        [book setPage:browser];
-        [book_ pushBook:book];
-    } else if (request == nil) {
-        [self setBackButtonTitle:title_];
+        [navigation setViewControllers:[NSArray arrayWithObject:browser]];
+               UIBarButtonItem *closeItem = [[UIBarButtonItem alloc]
+               initWithTitle:UCLocalize("CLOSE")
+                       style:UIBarButtonItemStylePlain
+               target:browser
+               action:@selector(close)
+           ];
+           [[browser navigationItem] setLeftBarButtonItem:closeItem];
+           [closeItem release];
+       
+        [[self navigationController] presentModalViewController:navigation animated:YES];
+    } /*else if (request == nil) {
+        [[self navigationItem] setTitle:title_];
         [browser setDelegate:delegate_];
         [browser retain];
-    } else {
+    }*/ else {
         [self pushPage:browser];
         [browser loadRequest:request];
     }
@@ -964,16 +956,16 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         return;
 
     title_ = [title retain];
-    [book_ reloadTitleForPage:self];
+    [[self navigationItem] setTitle:title_];
 }
 
 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
-    if ([loading_ count] == 0)
-        [self retain];
+    /*if ([loading_ count] == 0)
+        [self retain];*/
     [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
 
     if ([frame parentFrame] == nil) {
-        [webview_ resignFirstResponder];
+        [document_ resignFirstResponder];
 
         reloading_ = false;
 
@@ -1012,9 +1004,18 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
             special_ = nil;
         }
 
-        [book_ reloadTitleForPage:self];
+        [[self navigationItem] setTitle:title_];
 
-        [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
+        if (Wildcat_) {
+            CGRect webrect = [scroller_ bounds];
+            webrect.size.height = 1;
+            [document_ setFrame:webrect];
+        }
+
+        if ([scroller_ respondsToSelector:@selector(scrollPointVisibleAtTopLeft:)])
+            [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
+        else
+            [scroller_ scrollRectToVisible:CGRectZero animated:NO];
 
         if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)])
             [scroller_ setZoomScale:1 duration:0];
@@ -1023,56 +1024,53 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
             [scroller_ setZoomScale:1 animated:NO];*/
 
-        CGRect webrect = [scroller_ bounds];
-        webrect.size.height = 0;
-        [webview_ setFrame:webrect];
+        if (!Wildcat_) {
+            CGRect webrect = [scroller_ bounds];
+            webrect.size.height = 0;
+            [document_ setFrame:webrect];
+        }
     }
 
-    [self reloadButtons];
+       [self reloadButtons];
 }
 
+- (void) didFinishLoading { }
+
 - (void) _finishLoading {
     size_t count([loading_ count]);
-    if (count == 0)
-        [self autorelease];
+    /*if (count == 0)
+        [self autorelease];*/
     if (reloading_ || count != 0)
         return;
     if (finish_ != nil)
         [self callFunction:finish_];
-    [self reloadButtons];
+
+       [self reloadButtons];
 }
 
 - (bool) isLoading {
     return [loading_ count] != 0;
 }
 
-- (void) reloadButtons {
-    if ([self isLoading])
-        [indicator_ startAnimation];
-    else
-        [indicator_ stopAnimation];
-    [super reloadButtons];
-}
-
 - (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
-    return [webview_ webView:sender shouldScrollToPoint:point forFrame:frame];
+    return [document_ webView:sender shouldScrollToPoint:point forFrame:frame];
 }
 
 - (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame {
-    return [webview_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
+    return [document_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
 }
 
 - (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame {
-    return [webview_ webView:sender needsScrollNotifications:notifications forFrame:frame];
+    return [document_ webView:sender needsScrollNotifications:notifications forFrame:frame];
 }
 
 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
     [self _pushPage];
-    return [webview_ webView:sender didCommitLoadForFrame:frame];
+    return [document_ webView:sender didCommitLoadForFrame:frame];
 }
 
 - (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame {
-    return [webview_ webView:sender didReceiveDocTypeForFrame:frame];
+    return [document_ webView:sender didReceiveDocTypeForFrame:frame];
 }
 
 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
@@ -1121,12 +1119,13 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
                 }
     }
 
-    return [webview_ webView:sender didFinishLoadForFrame:frame];
+    return [document_ webView:sender didFinishLoadForFrame:frame];
 }
 
 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
-    if ([frame parentFrame] == nil)
-        [self autorelease];
+    _trace();
+    /*if ([frame parentFrame] == nil)
+        [self autorelease];*/
 
     [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
     [self _finishLoading];
@@ -1146,6 +1145,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 
 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
     [self _didFailWithError:error forFrame:frame];
+    if ([document_ respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)])
+        [document_ webView:sender didFailLoadWithError:error forFrame:frame];
 }
 
 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
@@ -1158,18 +1159,100 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 #endif
 }
 
+- (void) webView:(WebView *)sender didReceiveMessage:(NSDictionary *)dictionary {
+#if LogBrowser || ForSaurik
+    lprintf("Console:%s\n", [[dictionary description] UTF8String]);
+#endif
+    if ([document_ respondsToSelector:@selector(webView:didReceiveMessage:)])
+        [document_ webView:sender didReceiveMessage:dictionary];
+}
+
+- (void) webView:(id)sender willCloseFrame:(id)frame {
+    if ([document_ respondsToSelector:@selector(webView:willCloseFrame:)])
+        [document_ webView:sender willCloseFrame:frame];
+}
+
+- (void) webView:(id)sender didFinishDocumentLoadForFrame:(id)frame {
+    if ([document_ respondsToSelector:@selector(webView:didFinishDocumentLoadForFrame:)])
+        [document_ webView:sender didFinishDocumentLoadForFrame:frame];
+}
+
+- (void) webView:(id)sender didFirstLayoutInFrame:(id)frame {
+    if ([document_ respondsToSelector:@selector(webView:didFirstLayoutInFrame:)])
+        [document_ webView:sender didFirstLayoutInFrame:frame];
+}
+
+- (void) webViewFormEditedStatusHasChanged:(id)changed {
+    if ([document_ respondsToSelector:@selector(webViewFormEditedStatusHasChanged:)])
+        [document_ webViewFormEditedStatusHasChanged:changed];
+}
+
+- (void) webView:(id)sender formStateDidFocusNode:(id)formState {
+    if ([document_ respondsToSelector:@selector(webView:formStateDidFocusNode:)])
+        [document_ webView:sender formStateDidFocusNode:formState];
+}
+
+- (void) webView:(id)sender formStateDidBlurNode:(id)formState {
+    if ([document_ respondsToSelector:@selector(webView:formStateDidBlurNode:)])
+        [document_ webView:sender formStateDidBlurNode:formState];
+}
+
 /* XXX: fix this stupid include file
 - (void) webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)database {
     [origin setQuota:0x500000];
 }*/
 
+- (void) webViewDidLayout:(id)sender {
+    [document_ webViewDidLayout:sender];
+}
+
+- (void) webView:(id)sender didFirstVisuallyNonEmptyLayoutInFrame:(id)frame {
+    [document_ webView:sender didFirstVisuallyNonEmptyLayoutInFrame:frame];
+}
+
+- (void) webView:(id)sender saveStateToHistoryItem:(id)item forFrame:(id)frame {
+    [document_ webView:sender saveStateToHistoryItem:item forFrame:frame];
+}
+
+- (void) webView:(id)sender restoreStateFromHistoryItem:(id)item forFrame:(id)frame force:(BOOL)force {
+    [document_ webView:sender restoreStateFromHistoryItem:item forFrame:frame force:force];
+}
+
+- (void) webView:(id)sender attachRootLayer:(id)layer {
+    [document_ webView:sender attachRootLayer:layer];
+}
+
+- (id) webView:(id)sender plugInViewWithArguments:(id)arguments fromPlugInPackage:(id)package {
+    return [document_ webView:sender plugInViewWithArguments:arguments fromPlugInPackage:package];
+}
+
+- (void) webView:(id)sender willShowFullScreenForPlugInView:(id)view {
+    [document_ webView:sender willShowFullScreenForPlugInView:view];
+}
+
+- (void) webView:(id)sender didHideFullScreenForPlugInView:(id)view {
+    [document_ webView:sender didHideFullScreenForPlugInView:view];
+}
+
+- (void) webView:(id)sender willAddPlugInView:(id)view {
+    [document_ webView:sender willAddPlugInView:view];
+}
+
+- (void) webView:(id)sender didObserveDeferredContentChange:(int)change forFrame:(id)frame {
+    [document_ webView:sender didObserveDeferredContentChange:change forFrame:frame];
+}
+
+- (void) webViewDidPreventDefaultForEvent:(id)sender {
+    [document_ webViewDidPreventDefaultForEvent:sender];
+}
+
 - (void) _setTileDrawingEnabled:(BOOL)enabled {
-    //[webview_ setTileDrawingEnabled:enabled];
+    //[document_ setTileDrawingEnabled:enabled];
 }
 
 - (void) setViewportWidth:(float)width {
-    width_ = width ? width != 0 : [[self class] defaultWidth];
-    [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+    width_ = width != 0 ? width : [[self class] defaultWidth];
+    [document_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
 }
 
 - (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
@@ -1178,7 +1261,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 
 - (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
     [self _setTileDrawingEnabled:YES];
-    [webview_ redrawScaledDocument];
+    [document_ redrawScaledDocument];
 }
 
 - (void) scrollerWillStartDragging:(UIScroller *)scroller {
@@ -1193,34 +1276,53 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     [self _setTileDrawingEnabled:YES];
 }
 
-- (id) initWithBook:(RVBook *)book forWidth:(float)width ofClass:(Class)_class {
-    if ((self = [super initWithBook:book]) != nil) {
+- (id) initWithWidth:(float)width ofClass:(Class)_class {
+    if ((self = [super init]) != nil) {
         class_ = _class;
         loading_ = [[NSMutableSet alloc] initWithCapacity:3];
         popup_ = false;
 
-        struct CGRect bounds = [self bounds];
+        BrowserViewActualView *actualView = [[BrowserViewActualView alloc] initWithFrame:CGRectZero];
+        [self setView:actualView];
+        
+        struct CGRect bounds = [[self view] bounds];
 
-        scroller_ = [[UIScroller alloc] initWithFrame:bounds];
-        [self addSubview:scroller_];
+        scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds];
+        [[self view] addSubview:scroller_];
 
         [scroller_ setFixedBackgroundPattern:YES];
         [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
 
         [scroller_ setScrollingEnabled:YES];
         [scroller_ setClipsSubviews:YES];
-        [scroller_ setAllowsRubberBanding:YES];
+
+        if (!Wildcat_)
+            [scroller_ setAllowsRubberBanding:YES];
 
         [scroller_ setDelegate:self];
         [scroller_ setBounces:YES];
-        [scroller_ setScrollHysteresis:8];
-        [scroller_ setThumbDetectionEnabled:NO];
-        [scroller_ setDirectionalScrolling:YES];
-        [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */
-        [scroller_ setEventMode:YES];
+
+        if (!Wildcat_) {
+            [scroller_ setScrollHysteresis:8];
+            [scroller_ setThumbDetectionEnabled:NO];
+            [scroller_ setDirectionalScrolling:YES];
+            //[scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */
+            [scroller_ setEventMode:YES];
+        }
+
+        if (Wildcat_) {
+            UIScrollView *scroller((UIScrollView *)scroller_);
+            //[scroller setDirectionalLockEnabled:NO];
+            [scroller setDelaysContentTouches:NO];
+            //[scroller setScrollsToTop:NO];
+            //[scroller setCanCancelContentTouches:NO];
+        }
+
         [scroller_ setShowBackgroundShadow:NO]; /* YES */
-        [scroller_ setAllowsRubberBanding:YES]; /* Vertical */
-        [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
+        //[scroller_ setAllowsRubberBanding:YES]; /* Vertical */
+
+        if (!Wildcat_)
+            [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
 
         CGRect webrect = [scroller_ bounds];
         webrect.size.height = 0;
@@ -1230,68 +1332,67 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         WebThreadLock();
 
 #if RecycleWebViews
-        webview_ = [Documents_ lastObject];
-        if (webview_ != nil) {
-            webview_ = [webview_ retain];
-            webview = [webview_ webView];
+        document_ = [Documents_ lastObject];
+        if (document_ != nil) {
+            document_ = [document_ retain];
+            webview = [document_ webView];
             [Documents_ removeLastObject];
-            [webview_ setFrame:webrect];
+            [document_ setFrame:webrect];
         } else {
 #else
         if (true) {
 #endif
-            webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect];
-            webview = [webview_ webView];
+            document_ = [[$UIWebBrowserView alloc] initWithFrame:webrect];
+            webview = [document_ webView];
 
             // XXX: this is terribly (too?) expensive
-            //[webview_ setDrawsBackground:NO];
+            //[document_ setDrawsBackground:NO];
             [webview setPreferencesIdentifier:@"Cydia"];
 
-            [webview_ setTileSize:CGSizeMake(webrect.size.width, 500)];
+            [document_ setTileSize:CGSizeMake(webrect.size.width, 500)];
 
-            if ([webview_ respondsToSelector:@selector(enableReachability)])
-                [webview_ enableReachability];
+            if ([document_ respondsToSelector:@selector(enableReachability)])
+                [document_ enableReachability];
+            if ([document_ respondsToSelector:@selector(setAllowsMessaging:)])
+                [document_ setAllowsMessaging:YES];
+            if ([document_ respondsToSelector:@selector(useSelectionAssistantWithMode:)])
+                [document_ useSelectionAssistantWithMode:0];
 
-            [webview_ setAllowsMessaging:YES];
+            [document_ setTilingEnabled:YES];
+            [document_ setDrawsGrid:NO];
+            [document_ setLogsTilingChanges:NO];
+            [document_ setTileMinificationFilter:kCAFilterNearest];
 
-            if ([webview_ respondsToSelector:@selector(useSelectionAssistantWithMode:)])
-                [webview_ useSelectionAssistantWithMode:0];
-
-            [webview_ setTilingEnabled:YES];
-            [webview_ setDrawsGrid:NO];
-            [webview_ setLogsTilingChanges:NO];
-            [webview_ setTileMinificationFilter:kCAFilterNearest];
-
-            if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
+            if ([document_ respondsToSelector:@selector(setDataDetectorTypes:)])
                 /* XXX: abstractify */
-                [webview_ setDataDetectorTypes:0x80000000];
+                [document_ setDataDetectorTypes:0x80000000];
             else
-                [webview_ setDetectsPhoneNumbers:NO];
+                [document_ setDetectsPhoneNumbers:NO];
 
-            [webview_ setAutoresizes:YES];
+            [document_ setAutoresizes:YES];
 
-            [webview_ setMinimumScale:0.25f forDocumentTypes:0x10];
-            [webview_ setMaximumScale:5.00f forDocumentTypes:0x10];
-            [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
-            //[webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+            [document_ setMinimumScale:0.25f forDocumentTypes:0x10];
+            [document_ setMaximumScale:5.00f forDocumentTypes:0x10];
+            [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
+            //[document_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
 
-            [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
+            [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
 
-            [webview_ setMinimumScale:1.00f forDocumentTypes:0x8];
-            [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
-            [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
+            [document_ setMinimumScale:1.00f forDocumentTypes:0x8];
+            [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
+            [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
 
-            [webview_ _setDocumentType:0x4];
+            [document_ _setDocumentType:0x4];
 
-            if ([webview_ respondsToSelector:@selector(UIWebDocumentView:)])
-                [webview_ setZoomsFocusedFormControl:YES];
-            [webview_ setContentsPosition:7];
-            [webview_ setEnabledGestures:0xa];
-            [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
-            [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
+            if ([document_ respondsToSelector:@selector(setZoomsFocusedFormControl:)])
+                [document_ setZoomsFocusedFormControl:YES];
+            [document_ setContentsPosition:7];
+            [document_ setEnabledGestures:0xa];
+            [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
+            [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
 
-            [webview_ setSmoothsFonts:YES];
-            [webview_ setAllowsImageSheet:YES];
+            [document_ setSmoothsFonts:YES];
+            [document_ setAllowsImageSheet:YES];
             [webview _setUsesLoaderCache:YES];
 
             [webview setGroupName:@"CydiaGroup"];
@@ -1303,15 +1404,21 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
             else
                 [preferences _setLayoutInterval:0];
         }
+        
+        actualView.documentView = document_;
+        [actualView release];
 
         [self setViewportWidth:width];
 
-        [webview_ setDelegate:self];
-        [webview_ setGestureDelegate:self];
-        [webview_ setFormEditingDelegate:self];
-        [webview_ setInteractionDelegate:self];
+        [document_ setDelegate:self];
+        [document_ setGestureDelegate:self];
+
+        if ([document_ respondsToSelector:@selector(setFormEditingDelegate:)])
+            [document_ setFormEditingDelegate:self];
+
+        [document_ setInteractionDelegate:self];
 
-        [scroller_ addSubview:webview_];
+        [scroller_ addSubview:document_];
 
         //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
 
@@ -1328,29 +1435,31 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         WebThreadUnlock();
 
         CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
-        indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
+        indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(15, 5, indsize.width, indsize.height)];
         [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
+               [indicator_ startAnimation];
 
-        [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
-        [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
+        [scroller_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+        [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
+        [document_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
 
-        /*UIWebView *test([[[UIWebView alloc] initWithFrame:[self bounds]] autorelease]);
+        /*UIWebView *test([[[UIWebView alloc] initWithFrame:[[self view] bounds]] autorelease]);
         [test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]];
-        [self addSubview:test];*/
+        [[self view] addSubview:test];*/
     } return self;
 }
 
-- (id) initWithBook:(RVBook *)book forWidth:(float)width {
-    return [self initWithBook:book forWidth:width ofClass:[self class]];
+- (id) initWithWidth:(float)width {
+    return [self initWithWidth:width ofClass:[self class]];
 }
 
-- (id) initWithBook:(RVBook *)book {
-    return [self initWithBook:book forWidth:0];
+- (id) init {
+    return [self initWithWidth:0];
 }
 
 - (NSString *) stringByEvaluatingJavaScriptFromString:(NSString *)script {
     WebThreadLock();
-    WebView *webview([webview_ webView]);
+    WebView *webview([document_ webView]);
     NSString *string([webview stringByEvaluatingJavaScriptFromString:script]);
     WebThreadUnlock();
     return string;
@@ -1359,7 +1468,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
 - (void) callFunction:(WebScriptObject *)function {
     WebThreadLock();
 
-    WebView *webview([webview_ webView]);
+    WebView *webview([document_ webView]);
     WebFrame *frame([webview mainFrame]);
 
     id _private(MSHookIvar<id>(webview, "_private"));
@@ -1374,7 +1483,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         settings->setJavaScriptCanOpenWindowsAutomatically(true);
     }
 
-    if (UIWindow *window = [self window])
+    if (UIWindow *window = [[self view] window])
         if (UIResponder *responder = [window firstResponder])
             [responder resignFirstResponder];
 
@@ -1388,7 +1497,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     WebThreadUnlock();
 }
 
-- (void) didCloseBook:(RVBook *)book {
+- (void) didDismissModalViewController {
     if (closer_ != nil)
         [self callFunction:closer_];
 }
@@ -1407,14 +1516,6 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
         [self __rightButtonClicked];
 }
 
-- (id) _rightButtonTitle {
-    return UCLocalize("RELOAD");
-}
-
-- (id) rightButtonTitle {
-    return [self isLoading] ? @"" : button_ != nil ? button_ : [self _rightButtonTitle];
-}
-
 - (UINavigationButtonStyle) rightButtonStyle {
     if (style_ == nil) normal:
         return UINavigationButtonStyleNormal;
@@ -1429,19 +1530,38 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     else goto normal;
 }
 
-- (NSString *) title {
-    return title_ == nil ? UCLocalize("LOADING") : title_;
-}
-
-- (NSString *) backButtonTitle {
-    return UCLocalize("BROWSER");
+- (void) reloadButtons {
+    if ([self isLoading]) {
+        UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc]
+               initWithTitle:@" "
+               style:UIBarButtonItemStylePlain
+               target:self
+               action:@selector(_rightButtonClicked)
+           ];
+           [[self navigationItem] setRightBarButtonItem:reloadItem];
+               [[reloadItem view] addSubview:indicator_];
+               [[self navigationItem] setTitle:UCLocalize("LOADING")];
+           [reloadItem release];
+    } else {
+        UIBarButtonItem *reloadItem = [[UIBarButtonItem alloc]
+               initWithTitle:button_ ?: UCLocalize("RELOAD")
+                       style:[self rightButtonStyle]
+               target:self
+               action:@selector(_rightButtonClicked)
+           ];
+           [[self navigationItem] setRightBarButtonItem:reloadItem animated:YES];
+               [[self navigationItem] setTitle:title_];
+           [reloadItem release];
+       
+               if (function_ == nil) [self didFinishLoading];
+    }
 }
 
 - (void) setPageActive:(BOOL)active {
     if (!active)
         [indicator_ removeFromSuperview];
     else
-        [[book_ navigationBar] addSubview:indicator_];
+               [[[[self navigationItem] rightBarButtonItem] view] addSubview:indicator_];
 }
 
 - (void) resetViewAnimated:(BOOL)animated {
@@ -1455,4 +1575,4 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize(
     return 980;
 }
 
-@end
+@end
\ No newline at end of file