]> git.saurik.com Git - cydia.git/blobdiff - UICaboodle/BrowserView.mm
Use -[UIColor groupTableViewBackgroundColor] instead of -[UIColor pinStripeColor].
[cydia.git] / UICaboodle / BrowserView.mm
index 207d382e3d44bad4df1a79046f18fd735fad9d9e..e2dee3b5df8d40d02fe8e0ad109bc50e3ef6ce85 100644 (file)
@@ -1,16 +1,32 @@
+#include <UIKit/UIKit.h>
+#include "iPhonePrivate.h"
+
+#include "UCPlatform.h"
+
 #include <UICaboodle/BrowserView.h>
 #include <UICaboodle/UCLocalize.h>
 
 #include <UICaboodle/BrowserView.h>
 #include <UICaboodle/UCLocalize.h>
 
-#import <QuartzCore/CALayer.h>
+//#include <QuartzCore/CALayer.h>
 // XXX: fix the minimum requirement
 extern NSString * const kCAFilterNearest;
 
 #include <WebCore/WebCoreThread.h>
 // XXX: fix the minimum requirement
 extern NSString * const kCAFilterNearest;
 
 #include <WebCore/WebCoreThread.h>
-#include <WebKit/WebPreferences-WebPrivate.h>
+
+#include <WebKit/WebPolicyDelegate.h>
+#include <WebKit/WebPreferences.h>
+
+#include <WebKit/DOMCSSPrimitiveValue.h>
+#include <WebKit/DOMCSSStyleDeclaration.h>
+#include <WebKit/DOMDocument.h>
+#include <WebKit/DOMHTMLBodyElement.h>
+#include <WebKit/DOMRGBColor.h>
+
+//#include <WebCore/Page.h>
+//#include <WebCore/Settings.h>
 
 #include "substrate.h"
 
 
 #include "substrate.h"
 
-#define ForSaurik 1
+#define ForSaurik 0
 
 static bool Wildcat_;
 
 
 static bool Wildcat_;
 
@@ -19,12 +35,10 @@ static CFArrayRef (*$GSSystemGetCapability)(CFStringRef);
 static Class $UIFormAssistant;
 static Class $UIWebBrowserView;
 
 static Class $UIFormAssistant;
 static Class $UIWebBrowserView;
 
-@interface NSString (UIKit)
-- (NSString *) stringByAddingPercentEscapes;
-@end
-
 /* Indirect Delegate {{{ */
 /* Indirect Delegate {{{ */
-@interface IndirectDelegate : NSObject {
+@interface IndirectDelegate : NSObject <
+    HookProtocol
+> {
     _transient volatile id delegate_;
 }
 
     _transient volatile id delegate_;
 }
 
@@ -89,6 +103,11 @@ static Class $UIWebBrowserView;
     return nil;
 }
 
     return nil;
 }
 
+- (void) didDismissModalViewController {
+    if (delegate_ != nil)
+        return [delegate_ didDismissModalViewController];
+}
+
 - (IMP) methodForSelector:(SEL)sel {
     if (IMP method = [super methodForSelector:sel])
         return method;
 - (IMP) methodForSelector:(SEL)sel {
     if (IMP method = [super methodForSelector:sel])
         return method;
@@ -125,16 +144,24 @@ static Class $UIWebBrowserView;
 /* }}} */
 
 @interface WebView (UICaboodle)
 /* }}} */
 
 @interface WebView (UICaboodle)
-- (void) setScriptDebugDelegate:(id)delegate;
++ (BOOL) _canHandleRequest:(NSURLRequest *)request;
 - (void) _setFormDelegate:(id)delegate;
 - (void) _setFormDelegate:(id)delegate;
+- (void) _setLayoutInterval:(float)interval;
+- (void) setScriptDebugDelegate:(id)delegate;
 - (void) _setUIKitDelegate:(id)delegate;
 - (void) _setUIKitDelegate:(id)delegate;
+- (void) _setUsesLoaderCache:(BOOL)uses;
 - (void) setWebMailDelegate:(id)delegate;
 - (void) setWebMailDelegate:(id)delegate;
-- (void) _setLayoutInterval:(float)interval;
+@end
+
+@interface WebPreferences (Apple)
++ (void) _setInitialDefaultTextEncodingToSystemEncoding;
+- (void) _setLayoutInterval:(NSInteger)interval;
+- (void) setOfflineWebApplicationCacheEnabled:(BOOL)enabled;
 @end
 
 @implementation WebScriptObject (UICaboodle)
 
 @end
 
 @implementation WebScriptObject (UICaboodle)
 
-- (unsigned) count {
+- (NSUInteger) count {
     id length([self valueForKey:@"length"]);
     if ([length respondsToSelector:@selector(intValue)])
         return [length intValue];
     id length([self valueForKey:@"length"]);
     if ([length respondsToSelector:@selector(intValue)])
         return [length intValue];
@@ -148,19 +175,43 @@ static Class $UIWebBrowserView;
 
 @end
 
 
 @end
 
-#define ShowInternals 1
-#define LogBrowser 0
+@interface BrowserView : UIView {
+@private
+    UIWebDocumentView *documentView;
+}
+@property (nonatomic, retain) UIWebDocumentView *documentView;
+@end
+
+@implementation BrowserView
+
+@synthesize documentView;
+
+- (void)dealloc {
+    [documentView release];
+    [super dealloc];
+}
+
+- (void)layoutSubviews {
+    [super layoutSubviews];
+    if ([documentView respondsToSelector:@selector(setMinimumSize:)])
+        [documentView setMinimumSize:documentView.bounds.size];
+}
+
+@end
+
+#define ShowInternals 0
+#define LogBrowser 1
 
 #define lprintf(args...) fprintf(stderr, args)
 
 
 #define lprintf(args...) fprintf(stderr, args)
 
-@implementation BrowserView
+@implementation BrowserController
 
 #if ShowInternals
 #include "UICaboodle/UCInternal.h"
 #endif
 
 + (void) _initialize {
 
 #if ShowInternals
 #include "UICaboodle/UCInternal.h"
 #endif
 
 + (void) _initialize {
-    [WebView enableWebThread];
+    //[WebView enableWebThread];
 
     WebPreferences *preferences([WebPreferences standardPreferences]);
     [preferences setCacheModel:WebCacheModelDocumentBrowser];
 
     WebPreferences *preferences([WebPreferences standardPreferences]);
     [preferences setCacheModel:WebCacheModelDocumentBrowser];
@@ -183,7 +234,7 @@ static Class $UIWebBrowserView;
 
 - (void) dealloc {
 #if LogBrowser
 
 - (void) dealloc {
 #if LogBrowser
-    NSLog(@"[BrowserView dealloc]");
+    NSLog(@"[BrowserController dealloc]");
 #endif
 
     if (challenge_ != nil)
 #endif
 
     if (challenge_ != nil)
@@ -191,7 +242,7 @@ static Class $UIWebBrowserView;
 
     WebThreadLock();
 
 
     WebThreadLock();
 
-    WebView *webview = [webview_ webView];
+    WebView *webview = [document_ webView];
     [webview setFrameLoadDelegate:nil];
     [webview setResourceLoadDelegate:nil];
     [webview setUIDelegate:nil];
     [webview setFrameLoadDelegate:nil];
     [webview setResourceLoadDelegate:nil];
     [webview setUIDelegate:nil];
@@ -207,13 +258,13 @@ static Class $UIWebBrowserView;
     /* XXX: no one sets this, ever
     [webview setWebMailDelegate:nil];*/
 
     /* XXX: no one sets this, ever
     [webview setWebMailDelegate:nil];*/
 
-    [webview_ setDelegate:nil];
-    [webview_ setGestureDelegate:nil];
+    [document_ setDelegate:nil];
+    [document_ setGestureDelegate:nil];
 
 
-    if ([webview_ respondsToSelector:@selector(setFormEditingDelegate:)])
-        [webview_ setFormEditingDelegate:nil];
+    if ([document_ respondsToSelector:@selector(setFormEditingDelegate:)])
+        [document_ setFormEditingDelegate:nil];
 
 
-    [webview_ setInteractionDelegate:nil];
+    [document_ setInteractionDelegate:nil];
 
     [indirect_ setDelegate:nil];
 
 
     [indirect_ setDelegate:nil];
 
@@ -222,10 +273,10 @@ static Class $UIWebBrowserView;
     [webview close];
 
 #if RecycleWebViews
     [webview close];
 
 #if RecycleWebViews
-    [webview_ removeFromSuperview];
-    [Documents_ addObject:[webview_ autorelease]];
+    [document_ removeFromSuperview];
+    [Documents_ addObject:[document_ autorelease]];
 #else
 #else
-    [webview_ release];
+    [document_ release];
 #endif
 
     [indirect_ release];
 #endif
 
     [indirect_ release];
@@ -255,6 +306,11 @@ static Class $UIWebBrowserView;
         [sensitive_ release];
     if (title_ != nil)
         [title_ release];
         [sensitive_ release];
     if (title_ != nil)
         [title_ release];
+    if (reloaditem_ != nil)
+        [reloaditem_ release];
+    if (loadingitem_ != nil)
+        [loadingitem_ release];
+
     [super dealloc];
 }
 
     [super dealloc];
 }
 
@@ -262,7 +318,7 @@ static Class $UIWebBrowserView;
     [self loadRequest:[NSURLRequest
         requestWithURL:url
         cachePolicy:policy
     [self loadRequest:[NSURLRequest
         requestWithURL:url
         cachePolicy:policy
-        timeoutInterval:30.0
+        timeoutInterval:120.0
     ]];
 }
 
     ]];
 }
 
@@ -275,7 +331,7 @@ static Class $UIWebBrowserView;
     error_ = false;
 
     WebThreadLock();
     error_ = false;
 
     WebThreadLock();
-    [webview_ loadRequest:request];
+    [document_ loadRequest:request];
     WebThreadUnlock();
 }
 
     WebThreadUnlock();
 }
 
@@ -286,27 +342,24 @@ static Class $UIWebBrowserView;
     if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
         [self loadRequest:request_];
     else {
     if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
         [self loadRequest:request_];
     else {
-        UIActionSheet *sheet = [[[UIActionSheet alloc]
+        UIAlertView *alert = [[[UIAlertView alloc]
             initWithTitle:UCLocalize("RESUBMIT_FORM")
             initWithTitle:UCLocalize("RESUBMIT_FORM")
-            buttons:[NSArray arrayWithObjects:UCLocalize("CANCEL"), UCLocalize("SUBMIT"), nil]
-            defaultButtonIndex:0
+            message:nil
             delegate:self
             delegate:self
-            context:@"submit"
+            cancelButtonTitle:UCLocalize("CANCEL")
+            otherButtonTitles:UCLocalize("SUBMIT"), nil
         ] autorelease];
         ] autorelease];
-
-        [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-        [sheet setNumberOfRows:1];
-        [sheet popupAlertAnimated:YES];
+        [alert setContext:@"submit"];
+        [alert show];
     }
 }
 
 - (WebView *) webView {
     }
 }
 
 - (WebView *) webView {
-    return [webview_ webView];
+    return [document_ webView];
 }
 
 - (UIWebDocumentView *) documentView {
 }
 
 - (UIWebDocumentView *) documentView {
-    return webview_;
+    return document_;
 }
 
 /* XXX: WebThreadLock? */
 }
 
 /* XXX: WebThreadLock? */
@@ -330,7 +383,7 @@ static Class $UIWebBrowserView;
     if ([scroller_ respondsToSelector:@selector(setScrollerIndicatorSubrect:)])
         [scroller_ setScrollerIndicatorSubrect:subrect];
 
     if ([scroller_ respondsToSelector:@selector(setScrollerIndicatorSubrect:)])
         [scroller_ setScrollerIndicatorSubrect:subrect];
 
-    [webview_ setValue:[NSValue valueWithSize:NSMakeSize(subrect.size.width, subrect.size.height)] forGestureAttribute:UIGestureAttributeVisibleSize];
+    [document_ setValue:[NSValue valueWithSize:CGSizeMake(subrect.size.width, subrect.size.height)] forGestureAttribute:UIGestureAttributeVisibleSize];
 
     CGSize size(size_);
     size.height += extra;
 
     CGSize size(size_);
     size.height += extra;
@@ -341,7 +394,7 @@ static Class $UIWebBrowserView;
 }
 
 - (void) fixScroller {
 }
 
 - (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
 #if TrackResize
     NSLog(@"_fs:(%f,%f+%f,%f)", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
 #endif
@@ -360,10 +413,10 @@ static Class $UIWebBrowserView;
     [self view:sender didSetFrame:frame];
 }
 
     [self view:sender didSetFrame:frame];
 }
 
-- (void) pushPage:(RVPage *)page {
+- (void) pushPage:(CYViewController *)page {
     [page setDelegate:delegate_];
     [page setDelegate:delegate_];
-    [self setBackButtonTitle:title_];
-    [book_ pushPage:page];
+    [[self navigationItem] setTitle:title_];
+    [[self navigationController] pushViewController:page animated:YES];
 }
 
 - (void) _pushPage {
 }
 
 - (void) _pushPage {
@@ -371,15 +424,14 @@ static Class $UIWebBrowserView;
         return;
     // WTR: [self autorelease];
     pushed_ = true;
         return;
     // WTR: [self autorelease];
     pushed_ = true;
-    [book_ pushPage:self];
+    [[self navigationController] pushViewController:self animated:YES];
 }
 
 }
 
-- (void) swapPage:(RVPage *)page {
+- (void) swapPage:(CYViewController *)page {
     [page setDelegate:delegate_];
     [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 {
 }
 
 - (BOOL) getSpecial:(NSURL *)url swap:(BOOL)swap {
@@ -387,7 +439,7 @@ static Class $UIWebBrowserView;
     NSLog(@"getSpecial:%@", url);
 #endif
 
     NSLog(@"getSpecial:%@", url);
 #endif
 
-    if (RVPage *page = [delegate_ pageForURL:url hasTag:NULL]) {
+    if (CYViewController *page = [delegate_ pageForURL:url hasTag:NULL]) {
         if (swap)
             [self swapPage:page];
         else
         if (swap)
             [self swapPage:page];
         else
@@ -420,21 +472,19 @@ static Class $UIWebBrowserView;
 - (void) _promptForSensitive:(NSMutableArray *)array {
     NSString *name([array objectAtIndex:0]);
 
 - (void) _promptForSensitive:(NSMutableArray *)array {
     NSString *name([array objectAtIndex:0]);
 
-    UIActionSheet *sheet = [[[UIActionSheet alloc]
+    UIAlertView *alert = [[[UIAlertView alloc]
         initWithTitle:nil
         initWithTitle:nil
-        buttons:[NSArray arrayWithObjects:UCLocalize("YES"), UCLocalize("NO"), nil]
-        defaultButtonIndex:0
+        message:nil
         delegate:indirect_
         delegate:indirect_
-        context:@"sensitive"
+        cancelButtonTitle:UCLocalize("NO")
+        otherButtonTitles:UCLocalize("YES"), nil
     ] autorelease];
 
     ] autorelease];
 
-    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
     NSString *host(@"XXX");
 
     NSString *host(@"XXX");
 
-    [sheet setNumberOfRows:1];
-    [sheet setBodyText:[NSString stringWithFormat:@"The website at %@ is requesting your phone's %@. This is almost certainly for product licensing purposes. Will you allow this?", host, name]];
-    [sheet popupAlertAnimated:YES];
+    [alert setContext:@"sensitive"];
+    [alert setMessage:[NSString stringWithFormat:@"The website at %@ is requesting your phone's %@. This is almost certainly for product licensing purposes. Will you allow this?", host, name]];
+    [alert show];
 
     NSRunLoop *loop([NSRunLoop currentRunLoop]);
     NSDate *future([NSDate distantFuture]);
 
     NSRunLoop *loop([NSRunLoop currentRunLoop]);
     NSDate *future([NSDate distantFuture]);
@@ -464,18 +514,15 @@ static Class $UIWebBrowserView;
         return;
     [self retain];
 
         return;
     [self retain];
 
-    UIActionSheet *sheet = [[[UIActionSheet alloc]
+    UIAlertView *alert = [[[UIAlertView alloc]
         initWithTitle:nil
         initWithTitle:nil
-        buttons:[NSArray arrayWithObjects:UCLocalize("OK"), nil]
-        defaultButtonIndex:0
+        message:message
         delegate:self
         delegate:self
-        context:@"alert"
+        cancelButtonTitle:UCLocalize("OK")
+        otherButtonTitles:nil
     ] autorelease];
     ] autorelease];
-
-    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-    [sheet setBodyText:message];
-    [sheet popupAlertAnimated:YES];
+    [alert setContext:@"alert"];
+    [alert show];
 }
 
 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
 }
 
 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
@@ -483,19 +530,16 @@ static Class $UIWebBrowserView;
         return NO;
     [self retain];
 
         return NO;
     [self retain];
 
-    UIActionSheet *sheet = [[[UIActionSheet alloc]
+    UIAlertView *alert = [[[UIAlertView alloc]
         initWithTitle:nil
         initWithTitle:nil
-        buttons:[NSArray arrayWithObjects:UCLocalize("OK"), UCLocalize("CANCEL"), nil]
-        defaultButtonIndex:0
+        message:message
         delegate:indirect_
         delegate:indirect_
-        context:@"confirm"
+        cancelButtonTitle:UCLocalize("CANCEL")
+        otherButtonTitles:UCLocalize("OK"), nil
     ] autorelease];
 
     ] autorelease];
 
-    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-    [sheet setNumberOfRows:1];
-    [sheet setBodyText:message];
-    [sheet popupAlertAnimated:YES];
+    [alert setContext:@"confirm"];
+    [alert show];
 
     NSRunLoop *loop([NSRunLoop currentRunLoop]);
     NSDate *future([NSDate distantFuture]);
 
     NSRunLoop *loop([NSRunLoop currentRunLoop]);
     NSDate *future([NSDate distantFuture]);
@@ -532,7 +576,7 @@ static Class $UIWebBrowserView;
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
-    [self reloadButtons];
+    [self applyRightButton];
 }
 
 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
 }
 
 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
@@ -548,7 +592,7 @@ static Class $UIWebBrowserView;
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
         [function_ autorelease];
     function_ = function == nil ? nil : [function retain];
 
-    [self reloadButtons];
+    [self applyRightButton];
 }
 
 - (void) setFinishHook:(id)function {
 }
 
 - (void) setFinishHook:(id)function {
@@ -564,7 +608,7 @@ static Class $UIWebBrowserView;
 }
 
 - (void) _openMailToURL:(NSURL *)url {
 }
 
 - (void) _openMailToURL:(NSURL *)url {
-    [UIApp openURL:url];// asPanel:YES];
+    [[UIApplication sharedApplication] openURL:url];// asPanel:YES];
 }
 
 - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
 }
 
 - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
@@ -581,11 +625,11 @@ static Class $UIWebBrowserView;
 }
 
 - (void) webViewClose:(WebView *)sender {
 }
 
 - (void) webViewClose:(WebView *)sender {
-    [book_ close];
+    [self close];
 }
 
 - (void) close {
 }
 
 - (void) close {
-    [book_ close];
+    [[self navigationController] dismissModalViewControllerAnimated:YES];
 }
 
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
 }
 
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
@@ -615,25 +659,32 @@ static Class $UIWebBrowserView;
             if ([scheme isEqualToString:@"mailto"])
                 [self _openMailToURL:url];
             else {
             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]);
+                CYViewController *page([delegate_ pageForURL:url hasTag:NULL]);
                 if (page == nil) {
                     /* XXX: call createWebViewWithRequest instead? */
 
                 if (page == nil) {
                     /* XXX: call createWebViewWithRequest instead? */
 
-                    [self setBackButtonTitle:title_];
-
-                    BrowserView *browser([[[class_ alloc] initWithBook:book] autorelease]);
+                    BrowserController *browser([[[class_ alloc] init] autorelease]);
                     [browser loadURL:url];
                     page = browser;
                 }
 
                     [browser loadURL:url];
                     page = browser;
                 }
 
-                [book setDelegate:delegate_];
+                [navigation setDelegate:delegate_];
                 [page 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;
 
             }
         } else goto unknown;
 
@@ -649,9 +700,9 @@ static Class $UIWebBrowserView;
         // XXX: handle more mime types!
         [listener ignore];
 
         // XXX: handle more mime types!
         [listener ignore];
 
-        WebView *webview([webview_ webView]);
+        WebView *webview([document_ webView]);
         if (frame == [webview mainFrame])
         if (frame == [webview mainFrame])
-            [UIApp openURL:[request URL]];
+            [[UIApplication sharedApplication] openURL:[request URL]];
     }
 }
 
     }
 }
 
@@ -676,7 +727,7 @@ static Class $UIWebBrowserView;
 
         [listener use];
 
 
         [listener use];
 
-        WebView *webview([webview_ webView]);
+        WebView *webview([document_ webView]);
         if (frame == [webview mainFrame])
             [self _pushPage];
         return;
         if (frame == [webview mainFrame])
             [self _pushPage];
         return;
@@ -704,14 +755,14 @@ static Class $UIWebBrowserView;
     )) {
         url = open;
       open:
     )) {
         url = open;
       open:
-        [UIApp openURL:url];
+        [[UIApplication sharedApplication] openURL:url];
         goto ignore;
     }
 
         goto ignore;
     }
 
-    int store(_not(int));
+    NSInteger store(_not(NSInteger));
     if (NSURL *itms = [url itmsURL:&store]) {
 #if LogBrowser
     if (NSURL *itms = [url itmsURL:&store]) {
 #if LogBrowser
-        NSLog(@"itms#%@#%u#%@", url, store, itms);
+        NSLog(@"itms#%@#%d#%@", url, (int) store, itms);
 #endif
 
         if (capability != nil && (
 #endif
 
         if (capability != nil && (
@@ -749,12 +800,12 @@ static Class $UIWebBrowserView;
     //lprintf("Status:%s\n", [text UTF8String]);
 }
 
     //lprintf("Status:%s\n", [text UTF8String]);
 }
 
-- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
-    NSString *context([sheet context]);
+- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
+    NSString *context([alert context]);
 
     if ([context isEqualToString:@"alert"]) {
         [self autorelease];
 
     if ([context isEqualToString:@"alert"]) {
         [self autorelease];
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"confirm"]) {
         switch (button) {
             case 1:
     } else if ([context isEqualToString:@"confirm"]) {
         switch (button) {
             case 1:
@@ -766,7 +817,7 @@ static Class $UIWebBrowserView;
             break;
         }
 
             break;
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"sensitive"]) {
         switch (button) {
             case 1:
     } else if ([context isEqualToString:@"sensitive"]) {
         switch (button) {
             case 1:
@@ -778,14 +829,14 @@ static Class $UIWebBrowserView;
             break;
         }
 
             break;
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"challenge"]) {
         id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
 
         switch (button) {
             case 1: {
     } else if ([context isEqualToString:@"challenge"]) {
         id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
 
         switch (button) {
             case 1: {
-                NSString *username([[sheet textFieldAtIndex:0] text]);
-                NSString *password([[sheet textFieldAtIndex:1] text]);
+                NSString *username([[alert textFieldAtIndex:0] text]);
+                NSString *password([[alert textFieldAtIndex:1] text]);
 
                 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
 
 
                 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
 
@@ -802,7 +853,7 @@ static Class $UIWebBrowserView;
         [challenge_ release];
         challenge_ = nil;
 
         [challenge_ release];
         challenge_ = nil;
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     } else if ([context isEqualToString:@"submit"]) {
         switch (button) {
             case 1:
     } else if ([context isEqualToString:@"submit"]) {
         switch (button) {
             case 1:
@@ -811,7 +862,7 @@ static Class $UIWebBrowserView;
             case 2:
                 if (request_ != nil) {
                     WebThreadLock();
             case 2:
                 if (request_ != nil) {
                     WebThreadLock();
-                    [webview_ loadRequest:request_];
+                    [document_ loadRequest:request_];
                     WebThreadUnlock();
                 }
             break;
                     WebThreadUnlock();
                 }
             break;
@@ -819,7 +870,7 @@ static Class $UIWebBrowserView;
             _nodefault
         }
 
             _nodefault
         }
 
-        [sheet dismiss];
+        [alert dismissWithClickedButtonIndex:-1 animated:YES];
     }
 }
 
     }
 }
 
@@ -831,22 +882,21 @@ static Class $UIWebBrowserView;
     if (realm == nil)
         realm = @"";
 
     if (realm == nil)
         realm = @"";
 
-    UIActionSheet *sheet = [[[UIActionSheet alloc]
+    UIAlertView *alert = [[[UIAlertView alloc]
         initWithTitle:realm
         initWithTitle:realm
-        buttons:[NSArray arrayWithObjects:UCLocalize("LOGIN"), UCLocalize("CANCEL"), nil]
-        defaultButtonIndex:0
+        message:nil
         delegate:self
         delegate:self
-        context:@"challenge"
+        cancelButtonTitle:UCLocalize("CANCEL")
+        otherButtonTitles:UCLocalize("LOGIN"), nil
     ] autorelease];
 
     ] autorelease];
 
-    [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
-
-    [sheet setNumberOfRows:1];
+    [alert setContext:@"challenge"];
+    [alert setNumberOfRows:1];
 
 
-    [sheet addTextFieldWithValue:@"" label:UCLocalize("USERNAME")];
-    [sheet addTextFieldWithValue:@"" label:UCLocalize("PASSWORD")];
+    [alert addTextFieldWithValue:@"" label:UCLocalize("USERNAME")];
+    [alert addTextFieldWithValue:@"" label:UCLocalize("PASSWORD")];
 
 
-    UITextField *username([sheet textFieldAtIndex:0]); {
+    UITextField *username([alert textFieldAtIndex:0]); {
         UITextInputTraits *traits([username textInputTraits]);
         [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
         [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
         UITextInputTraits *traits([username textInputTraits]);
         [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
         [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
@@ -854,7 +904,7 @@ static Class $UIWebBrowserView;
         [traits setReturnKeyType:UIReturnKeyNext];
     }
 
         [traits setReturnKeyType:UIReturnKeyNext];
     }
 
-    UITextField *password([sheet textFieldAtIndex:1]); {
+    UITextField *password([alert textFieldAtIndex:1]); {
         UITextInputTraits *traits([password textInputTraits]);
         [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
         [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
         UITextInputTraits *traits([password textInputTraits]);
         [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
         [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
@@ -864,7 +914,7 @@ static Class $UIWebBrowserView;
         [traits setSecureTextEntry:YES];
     }
 
         [traits setSecureTextEntry:YES];
     }
 
-    [sheet popupAlertAnimated:YES];
+    [alert show];
 }
 
 - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
 }
 
 - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
@@ -881,25 +931,34 @@ static Class $UIWebBrowserView;
     NSNumber *value([features objectForKey:@"width"]);
     float width(value == nil ? 0 : [value floatValue]);
 
     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 */
 
     /* XXX: deal with cydia:// pages */
-    BrowserView *browser([[[class_ alloc] initWithBook:book forWidth:width] autorelease]);
+    BrowserController *browser([[[class_ alloc] initWithWidth:width] autorelease]);
 
     if (features != nil && popup_) {
 
     if (features != nil && popup_) {
-        [book setDelegate:delegate_];
-        [book setHook:indirect_];
+        [navigation setDelegate:delegate_];
+        [navigation setHook:indirect_];
         [browser setDelegate:delegate_];
 
         [browser loadRequest:request];
 
         [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];
         [browser setDelegate:delegate_];
         [browser retain];
-    } else {
+    }*/ else {
         [self pushPage:browser];
         [browser loadRequest:request];
     }
         [self pushPage:browser];
         [browser loadRequest:request];
     }
@@ -917,7 +976,7 @@ static Class $UIWebBrowserView;
         return;
 
     title_ = [title retain];
         return;
 
     title_ = [title retain];
-    [book_ reloadTitleForPage:self];
+    [[self navigationItem] setTitle:title_];
 }
 
 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
 }
 
 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
@@ -926,7 +985,7 @@ static Class $UIWebBrowserView;
     [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
 
     if ([frame parentFrame] == nil) {
     [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
 
     if ([frame parentFrame] == nil) {
-        [webview_ resignFirstResponder];
+        [document_ resignFirstResponder];
 
         reloading_ = false;
 
 
         reloading_ = false;
 
@@ -965,11 +1024,13 @@ static Class $UIWebBrowserView;
             special_ = nil;
         }
 
             special_ = nil;
         }
 
-        [book_ reloadTitleForPage:self];
+        [[self navigationItem] setTitle:title_];
 
 
-        CGRect webrect = [scroller_ bounds];
-        webrect.size.height = 1;
-        [webview_ setFrame:webrect];
+        if (Wildcat_) {
+            CGRect webrect = [scroller_ bounds];
+            webrect.size.height = 1;
+            [document_ setFrame:webrect];
+        }
 
         if ([scroller_ respondsToSelector:@selector(scrollPointVisibleAtTopLeft:)])
             [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
 
         if ([scroller_ respondsToSelector:@selector(scrollPointVisibleAtTopLeft:)])
             [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
@@ -982,9 +1043,60 @@ static Class $UIWebBrowserView;
             [scroller_ _setZoomScale:1 duration:0];
         /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
             [scroller_ setZoomScale:1 animated:NO];*/
             [scroller_ _setZoomScale:1 duration:0];
         /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
             [scroller_ setZoomScale:1 animated:NO];*/
+
+        if (!Wildcat_) {
+            CGRect webrect = [scroller_ bounds];
+            webrect.size.height = 0;
+            [document_ setFrame:webrect];
+        }
     }
 
     }
 
-    [self reloadButtons];
+    [self _startLoading];
+}
+
+- (UIBarButtonItemStyle) rightButtonStyle {
+    if (style_ == nil) normal:
+        return UIBarButtonItemStylePlain;
+    else if ([style_ isEqualToString:@"Normal"])
+        return UIBarButtonItemStylePlain;
+    else if ([style_ isEqualToString:@"Highlighted"])
+        return UIBarButtonItemStyleDone;
+    else goto normal;
+}
+
+- (UIBarButtonItem *) customButton {
+    UIBarButtonItem *customItem = [[UIBarButtonItem alloc]
+        initWithTitle:button_
+        style:[self rightButtonStyle]
+        target:self
+        action:@selector(customButtonClicked)
+    ];
+
+    return [customItem autorelease];
+}
+
+- (UIBarButtonItem *) rightButton {
+    return reloaditem_;
+}
+
+- (void) applyLoadingTitle {
+    [[self navigationItem] setTitle:UCLocalize("LOADING")];
+}
+
+- (void) applyRightButton {
+    if ([self isLoading]) {
+        [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
+        [[loadingitem_ view] addSubview:indicator_];
+        [self applyLoadingTitle];
+    } else if (button_) {
+        [[self navigationItem] setRightBarButtonItem:[self customButton] animated:YES];
+    } else {
+        [[self navigationItem] setRightBarButtonItem:[self rightButton] animated:YES];
+    }
+}
+
+- (void) _startLoading {
+    [self applyRightButton];
 }
 
 - (void) _finishLoading {
 }
 
 - (void) _finishLoading {
@@ -995,40 +1107,34 @@ static Class $UIWebBrowserView;
         return;
     if (finish_ != nil)
         [self callFunction:finish_];
         return;
     if (finish_ != nil)
         [self callFunction:finish_];
-    [self reloadButtons];
+
+    [self applyRightButton];
+    if (![self isLoading]) [[self navigationItem] setTitle:title_];
 }
 
 - (bool) isLoading {
     return [loading_ count] != 0;
 }
 
 }
 
 - (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 {
 - (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 {
 }
 
 - (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 {
 }
 
 - (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];
 }
 
 - (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 {
 }
 
 - (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 {
 }
 
 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
@@ -1038,7 +1144,7 @@ static Class $UIWebBrowserView;
     if ([frame parentFrame] == nil) {
         if (DOMDocument *document = [frame DOMDocument])
             if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"])
     if ([frame parentFrame] == nil) {
         if (DOMDocument *document = [frame DOMDocument])
             if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"])
-                for (DOMHTMLBodyElement *body in bodies) {
+                for (DOMHTMLBodyElement *body in (id) bodies) {
                     DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
 
                     bool colored(false);
                     DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
 
                     bool colored(false);
@@ -1055,7 +1161,7 @@ static Class $UIWebBrowserView;
                             UIColor *uic(nil);
 
                             if (red == 0xc7 && green == 0xce && blue == 0xd5)
                             UIColor *uic(nil);
 
                             if (red == 0xc7 && green == 0xce && blue == 0xd5)
-                                uic = [UIColor pinStripeColor];
+                                uic = [UIColor groupTableViewBackgroundColor];
                             else if (alpha != 0)
                                 uic = [UIColor
                                     colorWithRed:(red / 255)
                             else if (alpha != 0)
                                 uic = [UIColor
                                     colorWithRed:(red / 255)
@@ -1072,12 +1178,12 @@ static Class $UIWebBrowserView;
                     }
 
                     if (!colored)
                     }
 
                     if (!colored)
-                        [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
+                        [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
                     break;
                 }
     }
 
                     break;
                 }
     }
 
-    return [webview_ webView:sender didFinishLoadForFrame:frame];
+    return [document_ webView:sender didFinishLoadForFrame:frame];
 }
 
 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
 }
 
 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
@@ -1103,8 +1209,8 @@ static Class $UIWebBrowserView;
 
 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
     [self _didFailWithError:error forFrame:frame];
 
 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
     [self _didFailWithError:error forFrame:frame];
-    if ([webview_ respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)])
-        [webview_ webView:sender didFailLoadWithError: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 {
 }
 
 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
@@ -1121,38 +1227,38 @@ static Class $UIWebBrowserView;
 #if LogBrowser || ForSaurik
     lprintf("Console:%s\n", [[dictionary description] UTF8String]);
 #endif
 #if LogBrowser || ForSaurik
     lprintf("Console:%s\n", [[dictionary description] UTF8String]);
 #endif
-    if ([webview_ respondsToSelector:@selector(webView:didReceiveMessage:)])
-        [webview_ webView:sender didReceiveMessage:dictionary];
+    if ([document_ respondsToSelector:@selector(webView:didReceiveMessage:)])
+        [document_ webView:sender didReceiveMessage:dictionary];
 }
 
 - (void) webView:(id)sender willCloseFrame:(id)frame {
 }
 
 - (void) webView:(id)sender willCloseFrame:(id)frame {
-    if ([webview_ respondsToSelector:@selector(webView:willCloseFrame:)])
-        [webview_ webView:sender willCloseFrame:frame];
+    if ([document_ respondsToSelector:@selector(webView:willCloseFrame:)])
+        [document_ webView:sender willCloseFrame:frame];
 }
 
 - (void) webView:(id)sender didFinishDocumentLoadForFrame:(id)frame {
 }
 
 - (void) webView:(id)sender didFinishDocumentLoadForFrame:(id)frame {
-    if ([webview_ respondsToSelector:@selector(webView:didFinishDocumentLoadForFrame:)])
-        [webview_ webView:sender didFinishDocumentLoadForFrame:frame];
+    if ([document_ respondsToSelector:@selector(webView:didFinishDocumentLoadForFrame:)])
+        [document_ webView:sender didFinishDocumentLoadForFrame:frame];
 }
 
 - (void) webView:(id)sender didFirstLayoutInFrame:(id)frame {
 }
 
 - (void) webView:(id)sender didFirstLayoutInFrame:(id)frame {
-    if ([webview_ respondsToSelector:@selector(webView:didFirstLayoutInFrame:)])
-        [webview_ webView:sender didFirstLayoutInFrame:frame];
+    if ([document_ respondsToSelector:@selector(webView:didFirstLayoutInFrame:)])
+        [document_ webView:sender didFirstLayoutInFrame:frame];
 }
 
 - (void) webViewFormEditedStatusHasChanged:(id)changed {
 }
 
 - (void) webViewFormEditedStatusHasChanged:(id)changed {
-    if ([webview_ respondsToSelector:@selector(webViewFormEditedStatusHasChanged:)])
-        [webview_ webViewFormEditedStatusHasChanged:changed];
+    if ([document_ respondsToSelector:@selector(webViewFormEditedStatusHasChanged:)])
+        [document_ webViewFormEditedStatusHasChanged:changed];
 }
 
 - (void) webView:(id)sender formStateDidFocusNode:(id)formState {
 }
 
 - (void) webView:(id)sender formStateDidFocusNode:(id)formState {
-    if ([webview_ respondsToSelector:@selector(webView:formStateDidFocusNode:)])
-        [webview_ webView:sender formStateDidFocusNode:formState];
+    if ([document_ respondsToSelector:@selector(webView:formStateDidFocusNode:)])
+        [document_ webView:sender formStateDidFocusNode:formState];
 }
 
 - (void) webView:(id)sender formStateDidBlurNode:(id)formState {
 }
 
 - (void) webView:(id)sender formStateDidBlurNode:(id)formState {
-    if ([webview_ respondsToSelector:@selector(webView:formStateDidBlurNode:)])
-        [webview_ webView:sender formStateDidBlurNode:formState];
+    if ([document_ respondsToSelector:@selector(webView:formStateDidBlurNode:)])
+        [document_ webView:sender formStateDidBlurNode:formState];
 }
 
 /* XXX: fix this stupid include file
 }
 
 /* XXX: fix this stupid include file
@@ -1161,56 +1267,56 @@ static Class $UIWebBrowserView;
 }*/
 
 - (void) webViewDidLayout:(id)sender {
 }*/
 
 - (void) webViewDidLayout:(id)sender {
-    [webview_ webViewDidLayout:sender];
+    [document_ webViewDidLayout:sender];
 }
 
 - (void) webView:(id)sender didFirstVisuallyNonEmptyLayoutInFrame:(id)frame {
 }
 
 - (void) webView:(id)sender didFirstVisuallyNonEmptyLayoutInFrame:(id)frame {
-    [webview_ webView:sender didFirstVisuallyNonEmptyLayoutInFrame:frame];
+    [document_ webView:sender didFirstVisuallyNonEmptyLayoutInFrame:frame];
 }
 
 - (void) webView:(id)sender saveStateToHistoryItem:(id)item forFrame:(id)frame {
 }
 
 - (void) webView:(id)sender saveStateToHistoryItem:(id)item forFrame:(id)frame {
-    [webview_ webView:sender saveStateToHistoryItem:item forFrame:frame];
+    [document_ webView:sender saveStateToHistoryItem:item forFrame:frame];
 }
 
 - (void) webView:(id)sender restoreStateFromHistoryItem:(id)item forFrame:(id)frame force:(BOOL)force {
 }
 
 - (void) webView:(id)sender restoreStateFromHistoryItem:(id)item forFrame:(id)frame force:(BOOL)force {
-    [webview_ webView:sender restoreStateFromHistoryItem:item forFrame:frame force:force];
+    [document_ webView:sender restoreStateFromHistoryItem:item forFrame:frame force:force];
 }
 
 - (void) webView:(id)sender attachRootLayer:(id)layer {
 }
 
 - (void) webView:(id)sender attachRootLayer:(id)layer {
-    [webview_ webView:sender attachRootLayer:layer];
+    [document_ webView:sender attachRootLayer:layer];
 }
 
 - (id) webView:(id)sender plugInViewWithArguments:(id)arguments fromPlugInPackage:(id)package {
 }
 
 - (id) webView:(id)sender plugInViewWithArguments:(id)arguments fromPlugInPackage:(id)package {
-    return [webview_ webView:sender plugInViewWithArguments:arguments fromPlugInPackage:package];
+    return [document_ webView:sender plugInViewWithArguments:arguments fromPlugInPackage:package];
 }
 
 - (void) webView:(id)sender willShowFullScreenForPlugInView:(id)view {
 }
 
 - (void) webView:(id)sender willShowFullScreenForPlugInView:(id)view {
-    [webview_ webView:sender willShowFullScreenForPlugInView:view];
+    [document_ webView:sender willShowFullScreenForPlugInView:view];
 }
 
 - (void) webView:(id)sender didHideFullScreenForPlugInView:(id)view {
 }
 
 - (void) webView:(id)sender didHideFullScreenForPlugInView:(id)view {
-    [webview_ webView:sender didHideFullScreenForPlugInView:view];
+    [document_ webView:sender didHideFullScreenForPlugInView:view];
 }
 
 - (void) webView:(id)sender willAddPlugInView:(id)view {
 }
 
 - (void) webView:(id)sender willAddPlugInView:(id)view {
-    [webview_ webView:sender willAddPlugInView:view];
+    [document_ webView:sender willAddPlugInView:view];
 }
 
 - (void) webView:(id)sender didObserveDeferredContentChange:(int)change forFrame:(id)frame {
 }
 
 - (void) webView:(id)sender didObserveDeferredContentChange:(int)change forFrame:(id)frame {
-    [webview_ webView:sender didObserveDeferredContentChange:change forFrame:frame];
+    [document_ webView:sender didObserveDeferredContentChange:change forFrame:frame];
 }
 
 - (void) webViewDidPreventDefaultForEvent:(id)sender {
 }
 
 - (void) webViewDidPreventDefaultForEvent:(id)sender {
-    [webview_ webViewDidPreventDefaultForEvent:sender];
+    [document_ webViewDidPreventDefaultForEvent:sender];
 }
 
 - (void) _setTileDrawingEnabled:(BOOL)enabled {
 }
 
 - (void) _setTileDrawingEnabled:(BOOL)enabled {
-    //[webview_ setTileDrawingEnabled:enabled];
+    //[document_ setTileDrawingEnabled:enabled];
 }
 
 - (void) setViewportWidth:(float)width {
     width_ = width != 0 ? width : [[self class] defaultWidth];
 }
 
 - (void) setViewportWidth:(float)width {
     width_ = width != 0 ? width : [[self class] defaultWidth];
-    [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+    [document_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
 }
 
 - (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
 }
 
 - (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
@@ -1219,7 +1325,7 @@ static Class $UIWebBrowserView;
 
 - (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
     [self _setTileDrawingEnabled:YES];
 
 - (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
     [self _setTileDrawingEnabled:YES];
-    [webview_ redrawScaledDocument];
+    [document_ redrawScaledDocument];
 }
 
 - (void) scrollerWillStartDragging:(UIScroller *)scroller {
 }
 
 - (void) scrollerWillStartDragging:(UIScroller *)scroller {
@@ -1234,19 +1340,22 @@ static Class $UIWebBrowserView;
     [self _setTileDrawingEnabled:YES];
 }
 
     [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;
 
         class_ = _class;
         loading_ = [[NSMutableSet alloc] initWithCapacity:3];
         popup_ = false;
 
-        struct CGRect bounds = [self bounds];
+        BrowserView *actualView = [[BrowserView alloc] initWithFrame:CGRectZero];
+        [self setView:actualView];
+
+        struct CGRect bounds = [[self view] bounds];
 
         scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds];
 
         scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds];
-        [self addSubview:scroller_];
+        [[self view] addSubview:scroller_];
 
         [scroller_ setFixedBackgroundPattern:YES];
 
         [scroller_ setFixedBackgroundPattern:YES];
-        [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
+        [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
 
         [scroller_ setScrollingEnabled:YES];
         [scroller_ setClipsSubviews:YES];
 
         [scroller_ setScrollingEnabled:YES];
         [scroller_ setClipsSubviews:YES];
@@ -1287,67 +1396,67 @@ static Class $UIWebBrowserView;
         WebThreadLock();
 
 #if RecycleWebViews
         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];
             [Documents_ removeLastObject];
-            [webview_ setFrame:webrect];
+            [document_ setFrame:webrect];
         } else {
 #else
         if (true) {
 #endif
         } else {
 #else
         if (true) {
 #endif
-            webview_ = [[$UIWebBrowserView alloc] initWithFrame:webrect];
-            webview = [webview_ webView];
+            document_ = [[$UIWebBrowserView alloc] initWithFrame:webrect];
+            webview = [document_ webView];
 
             // XXX: this is terribly (too?) expensive
 
             // XXX: this is terribly (too?) expensive
-            //[webview_ setDrawsBackground:NO];
+            //[document_ setDrawsBackground:NO];
             [webview setPreferencesIdentifier:@"Cydia"];
 
             [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 ([webview_ respondsToSelector:@selector(setAllowsMessaging:)])
-                [webview_ setAllowsMessaging:YES];
-            if ([webview_ respondsToSelector:@selector(useSelectionAssistantWithMode:)])
-                [webview_ useSelectionAssistantWithMode:0];
+            if ([document_ respondsToSelector:@selector(enableReachability)])
+                [document_ enableReachability];
+            if ([document_ respondsToSelector:@selector(setAllowsMessaging:)])
+                [document_ setAllowsMessaging:YES];
+            if ([document_ respondsToSelector:@selector(useSelectionAssistantWithMode:)])
+                [document_ useSelectionAssistantWithMode:0];
 
 
-            [webview_ setTilingEnabled:YES];
-            [webview_ setDrawsGrid:NO];
-            [webview_ setLogsTilingChanges:NO];
-            [webview_ setTileMinificationFilter:kCAFilterNearest];
+            [document_ setTilingEnabled:YES];
+            [document_ setDrawsGrid:NO];
+            [document_ setLogsTilingChanges:NO];
+            [document_ setTileMinificationFilter:kCAFilterNearest];
 
 
-            if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
+            if ([document_ respondsToSelector:@selector(setDataDetectorTypes:)])
                 /* XXX: abstractify */
                 /* XXX: abstractify */
-                [webview_ setDataDetectorTypes:0x80000000];
+                [document_ setDataDetectorTypes:0x80000000];
             else
             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(setZoomsFocusedFormControl:)])
-                [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"];
             [webview _setUsesLoaderCache:YES];
 
             [webview setGroupName:@"CydiaGroup"];
@@ -1360,17 +1469,20 @@ static Class $UIWebBrowserView;
                 [preferences _setLayoutInterval:0];
         }
 
                 [preferences _setLayoutInterval:0];
         }
 
+        actualView.documentView = document_;
+        [actualView release];
+
         [self setViewportWidth:width];
 
         [self setViewportWidth:width];
 
-        [webview_ setDelegate:self];
-        [webview_ setGestureDelegate:self];
+        [document_ setDelegate:self];
+        [document_ setGestureDelegate:self];
 
 
-        if ([webview_ respondsToSelector:@selector(setFormEditingDelegate:)])
-            [webview_ setFormEditingDelegate:self];
+        if ([document_ respondsToSelector:@selector(setFormEditingDelegate:)])
+            [document_ setFormEditingDelegate:self];
 
 
-        [webview_ setInteractionDelegate:self];
+        [document_ setInteractionDelegate:self];
 
 
-        [scroller_ addSubview:webview_];
+        [scroller_ addSubview:document_];
 
         //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
 
 
         //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
 
@@ -1387,31 +1499,46 @@ static Class $UIWebBrowserView;
         WebThreadUnlock();
 
         CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
         WebThreadUnlock();
 
         CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
-        indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(bounds.size.width - 39, 12, indsize.width, indsize.height)];
+        indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(15, 5, indsize.width, indsize.height)];
         [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
         [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
+        [indicator_ startAnimation];
+
+        reloaditem_ = [[UIBarButtonItem alloc]
+            initWithTitle:UCLocalize("RELOAD")
+            style:[self rightButtonStyle]
+            target:self
+            action:@selector(reloadButtonClicked)
+        ];
+
+        loadingitem_ = [[UIBarButtonItem alloc]
+            initWithTitle:@" "
+            style:UIBarButtonItemStylePlain
+            target:self
+            action:@selector(reloadButtonClicked)
+        ];
+        [[loadingitem_ view] addSubview:indicator_];
 
 
-        [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
         [scroller_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
         [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
         [scroller_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
         [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
-        [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+        [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/"]]];
         [test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]];
-        [self addSubview:test];*/
+        [[self view] addSubview:test];*/
     } return self;
 }
 
     } 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();
 }
 
 - (NSString *) stringByEvaluatingJavaScriptFromString:(NSString *)script {
     WebThreadLock();
-    WebView *webview([webview_ webView]);
+    WebView *webview([document_ webView]);
     NSString *string([webview stringByEvaluatingJavaScriptFromString:script]);
     WebThreadUnlock();
     return string;
     NSString *string([webview stringByEvaluatingJavaScriptFromString:script]);
     WebThreadUnlock();
     return string;
@@ -1420,10 +1547,14 @@ static Class $UIWebBrowserView;
 - (void) callFunction:(WebScriptObject *)function {
     WebThreadLock();
 
 - (void) callFunction:(WebScriptObject *)function {
     WebThreadLock();
 
-    WebView *webview([webview_ webView]);
+    WebView *webview([document_ webView]);
     WebFrame *frame([webview mainFrame]);
     WebFrame *frame([webview mainFrame]);
+    WebPreferences *preferences([webview preferences]);
 
 
-    id _private(MSHookIvar<id>(webview, "_private"));
+    bool maybe([preferences javaScriptCanOpenWindowsAutomatically]);
+    [preferences setJavaScriptCanOpenWindowsAutomatically:NO];
+
+    /*id _private(MSHookIvar<id>(webview, "_private"));
     WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
     WebCore::Settings *settings(page == NULL ? NULL : page->settings());
 
     WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
     WebCore::Settings *settings(page == NULL ? NULL : page->settings());
 
@@ -1433,9 +1564,9 @@ static Class $UIWebBrowserView;
     else {
         no = settings->JavaScriptCanOpenWindowsAutomatically();
         settings->setJavaScriptCanOpenWindowsAutomatically(true);
     else {
         no = settings->JavaScriptCanOpenWindowsAutomatically();
         settings->setJavaScriptCanOpenWindowsAutomatically(true);
-    }
+    }*/
 
 
-    if (UIWindow *window = [self window])
+    if (UIWindow *window = [[self view] window])
         if (UIResponder *responder = [window firstResponder])
             [responder resignFirstResponder];
 
         if (UIResponder *responder = [window firstResponder])
             [responder resignFirstResponder];
 
@@ -1443,69 +1574,42 @@ static Class $UIWebBrowserView;
     JSGlobalContextRef context([frame globalContext]);
     JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
 
     JSGlobalContextRef context([frame globalContext]);
     JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
 
-    if (settings != NULL)
-        settings->setJavaScriptCanOpenWindowsAutomatically(no);
+    /*if (settings != NULL)
+        settings->setJavaScriptCanOpenWindowsAutomatically(no);*/
+
+    [preferences setJavaScriptCanOpenWindowsAutomatically:maybe];
 
     WebThreadUnlock();
 }
 
 
     WebThreadUnlock();
 }
 
-- (void) didCloseBook:(RVBook *)book {
+- (void) didDismissModalViewController {
     if (closer_ != nil)
         [self callFunction:closer_];
 }
 
     if (closer_ != nil)
         [self callFunction:closer_];
 }
 
-- (void) __rightButtonClicked {
+- (void) reloadButtonClicked {
     reloading_ = true;
     [self reloadURL];
 }
 
     reloading_ = true;
     [self reloadURL];
 }
 
-- (void) _rightButtonClicked {
+- (void) _customButtonClicked {
+    [self reloadButtonClicked];
+}
+
+- (void) customButtonClicked {
 #if !AlwaysReload
     if (function_ != nil)
         [self callFunction:function_];
     else
 #endif
 #if !AlwaysReload
     if (function_ != nil)
         [self callFunction:function_];
     else
 #endif
-        [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;
-    else if ([style_ isEqualToString:@"Normal"])
-        return UINavigationButtonStyleNormal;
-    else if ([style_ isEqualToString:@"Back"])
-        return UINavigationButtonStyleBack;
-    else if ([style_ isEqualToString:@"Highlighted"])
-        return UINavigationButtonStyleHighlighted;
-    else if ([style_ isEqualToString:@"Destructive"])
-        return UINavigationButtonStyleDestructive;
-    else goto normal;
-}
-
-- (NSString *) title {
-    return title_ == nil ? UCLocalize("LOADING") : title_;
-}
-
-- (NSString *) backButtonTitle {
-    return UCLocalize("BROWSER");
+    [self _customButtonClicked];
 }
 
 - (void) setPageActive:(BOOL)active {
     if (!active)
         [indicator_ removeFromSuperview];
     else
 }
 
 - (void) setPageActive:(BOOL)active {
     if (!active)
         [indicator_ removeFromSuperview];
     else
-        [[book_ navigationBar] addSubview:indicator_];
-}
-
-- (void) resetViewAnimated:(BOOL)animated {
+        [[[[self navigationItem] rightBarButtonItem] view] addSubview:indicator_];
 }
 
 - (void) setPushed:(bool)pushed {
 }
 
 - (void) setPushed:(bool)pushed {