Port Cydget to UIWebView.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 28 Mar 2011 10:21:49 +0000 (10:21 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 28 Mar 2011 10:21:49 +0000 (10:21 +0000)
LockScreen.mm
PhotoExample.cydget/index.html
Welcome.html

index 57c7dfc204a5971d92b0eb6d17b5e4ac4ef7cd48..2b6c8610e99a02b1970551ea79f5a7881c0d8ad6 100644 (file)
@@ -78,14 +78,6 @@ extern NSString * const kCAFilterNearest;
 #include <apr-1/apr_pools.h>
 #include <pcre.h>
 
-@interface WebView (UICaboodle)
-- (void) setScriptDebugDelegate:(id)delegate;
-- (void) _setFormDelegate:(id)delegate;
-- (void) _setUIKitDelegate:(id)delegate;
-- (void) setWebMailDelegate:(id)delegate;
-- (void) _setLayoutInterval:(float)interval;
-@end
-
 #define _transient
 #define _forever for (;;)
 
@@ -119,8 +111,6 @@ while (false)
 @end
 
 static Class $CydgetController(objc_getClass("CydgetController"));
-static Class $UIFormAssistant(objc_getClass("UIFormAssistant"));
-//static Class $SBStatusBarController(objc_getClass("SBStatusBarController"));
 
 static Class $UIWebBrowserView;
 static bool Wildcat_, iOS4;
@@ -199,127 +189,58 @@ class Pcre {
     }
 };
 /* }}} */
-/* WebCycript Delegate {{{ */
-@interface WebCycriptDelegate : NSObject {
-    _transient volatile id delegate_;
-}
-
-- (void) setDelegate:(id)delegate;
-- (id) initWithDelegate:(id)delegate;
-@end
-
-@implementation WebCycriptDelegate
 
-- (void) setDelegate:(id)delegate {
-    delegate_ = delegate;
-}
-
-- (id) initWithDelegate:(id)delegate {
-    delegate_ = delegate;
-    return self;
-}
+static float CYScrollViewDecelerationRateNormal;
 
-- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender didClearWindowObject:window forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender didCommitLoadForFrame:frame];
-}
+@interface UIScrollView (Apple)
+- (void) setDecelerationRate:(float)value;
+- (void) setScrollingEnabled:(BOOL)enabled;
+@end
 
-- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender didFailLoadWithError:error forFrame:frame];
-}
+@interface UIWebView (Apple)
+- (void) setDataDetectorTypes:(int)types;
+- (UIScrollView *) _scrollView;
+- (UIScroller *) _scroller;
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
+@end
 
-- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame];
-}
+@interface WebView (Apple)
+- (void) _setLayoutInterval:(float)interval;
+- (void) _setAllowsMessaging:(BOOL)allows;
+- (void) setShouldUpdateWhileOffscreen:(BOOL)update;
+@end
 
-- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender didFinishLoadForFrame:frame];
-}
+@protocol CydgetWebViewDelegate //<UIWebViewDelegate>
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
+@end
 
-/*- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender didReceiveTitle:title forFrame:frame];
-}*/
+@class UIWebViewWebViewDelegate;
 
-- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame];
+@interface CydgetWebView : UIWebView {
 }
 
-/*- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source];
-}*/
-
-/*- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
-    if (delegate_ != nil)
-        return [delegate_ webView:sender resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:source];
-    return nil;
-}*/
-
-- (IMP) methodForSelector:(SEL)sel {
-    if (IMP method = [super methodForSelector:sel])
-        return method;
-    fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
-    return NULL;
-}
+@end
 
-- (BOOL) respondsToSelector:(SEL)sel {
-    if ([super respondsToSelector:sel])
-        return YES;
-    // XXX: WebThreadCreateNSInvocation returns nil
-    //fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
-    return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
-}
+@implementation CydgetWebView
 
-- (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
-    if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
-        return method;
-    //fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
-    if (delegate_ != nil)
-        if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
-            return sig;
-    // XXX: I fucking hate Apple so very very bad
-    return [NSMethodSignature signatureWithObjCTypes:"v@:"];
+- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+    [listener use];
 }
 
-- (void) forwardInvocation:(NSInvocation *)inv {
-    SEL sel = [inv selector];
-    if (delegate_ != nil && [delegate_ respondsToSelector:sel])
-        [inv invokeWithTarget:delegate_];
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+    NSObject<CydgetWebViewDelegate> *delegate([self delegate]);
+    if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
+        [delegate webView:view didClearWindowObject:window forFrame:frame];
+    if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)])
+        [super webView:view didClearWindowObject:window forFrame:frame];
 }
 
 @end
-/* }}} */
 
 @interface WebCydgetLockScreenView : UIView {
-    WebCycriptDelegate *indirect_;
-    UIProgressIndicator *indicator_;
-    UIScroller *scroller_;
-    UIWebDocumentView *document_;
-
+    CydgetWebView *webview_;
+    UIScrollView *scroller_;
     NSString *cycript_;
-    bool scrollable_;
-
-    float width_;
-    CGSize size_;
-    bool editing_;
-
-    NSNumber *confirm_;
-
-    NSMutableSet *loading_;
-    bool error_;
-    bool reloading_;
-
-    //UIKeyboard *keyboard_;
 }
 
 @end
@@ -329,176 +250,13 @@ class Pcre {
 //#include "UICaboodle/UCInternal.h"
 
 - (void) dealloc {
-    WebThreadLock();
-
-    WebView *webview([document_ webView]);
-    [webview setFrameLoadDelegate:nil];
-    [webview setResourceLoadDelegate:nil];
-    [webview setUIDelegate:nil];
-    [webview setScriptDebugDelegate:nil];
-    [webview setPolicyDelegate:nil];
-
-    /* XXX: these are set by UIWebDocumentView
-    [webview setDownloadDelegate:nil];
-    [webview _setFormDelegate:nil];
-    [webview _setUIKitDelegate:nil];
-    [webview setEditingDelegate:nil];*/
-
-    /* XXX: no one sets this, ever
-    [webview setWebMailDelegate:nil];*/
-
-    [document_ setDelegate:nil];
-    [document_ setGestureDelegate:nil];
-
-    if ([document_ respondsToSelector:@selector(setFormEditingDelegate:)])
-        [document_ setFormEditingDelegate:nil];
-
-    [document_ setInteractionDelegate:nil];
-
-    [indirect_ setDelegate:nil];
-
-    [webview close];
-    [document_ release];
-
-    [indirect_ release];
-
-    WebThreadUnlock();
-
-    [scroller_ setDelegate:nil];
-
-    if (confirm_ != nil)
-        [confirm_ release];
-
-    //[keyboard_ release];
-
-    [scroller_ release];
-    [indicator_ release];
-    [loading_ release];
+    [webview_ setDelegate:nil];
+    [webview_ release];
     [super dealloc];
 }
 
-+ (float) defaultWidth {
-    return 980;
-}
-
-- (void) webView:(WebView *)sender didReceiveMessage:(NSDictionary *)dictionary {
-#if LogBrowser || ForSaurik
-    NSLog(@"Console:%@\n", [dictionary description]);
-#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];
-}
-
-- (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 {
-    //[document_ setTileDrawingEnabled:enabled];
-}
-
-- (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
-    [self _setTileDrawingEnabled:NO];
-}
-
-- (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
-    [self _setTileDrawingEnabled:YES];
-    [document_ redrawScaledDocument];
-}
-
-- (void) setViewportWidth:(float)width {
-    width_ = width != 0 ? width : [[self class] defaultWidth];
-    [document_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
-}
-
-- (void) scrollerWillStartDragging:(UIScroller *)scroller {
-    [self _setTileDrawingEnabled:NO];
-}
-
-- (void) scrollerDidEndDragging:(UIScroller *)scroller willSmoothScroll:(BOOL)smooth {
-    [self _setTileDrawingEnabled:YES];
-}
-
-- (void) scrollerDidEndDragging:(UIScroller *)scroller {
-    [self _setTileDrawingEnabled:YES];
-}
-
 - (void) loadRequest:(NSURLRequest *)request {
-    error_ = false;
-
-    WebThreadLock();
-    [document_ loadRequest:request];
-    WebThreadUnlock();
+    [webview_ loadRequest:request];
 }
 
 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
@@ -518,410 +276,100 @@ class Pcre {
     frame.size.height -= 20; //[[[$SBStatusBarController sharedStatusBarController] statusBarView] frame].size.height;
 
     if ((self = [super initWithFrame:frame]) != nil) {
-        loading_ = [[NSMutableSet alloc] initWithCapacity:3];
+        CGRect bounds([self bounds]);
+        bounds.size.height -= [TPBottomLockBar defaultHeight];
 
-        struct CGRect bounds([self bounds]);
-
-        scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds];
-        [self addSubview:scroller_];
-
-        [scroller_ setFixedBackgroundPattern:YES];
-        [scroller_ setBackgroundColor:[UIColor blackColor]];
-
-        [scroller_ setScrollingEnabled:YES];
-        [scroller_ setClipsSubviews:YES];
-
-        if (!Wildcat_)
-            [scroller_ setAllowsRubberBanding:YES];
-
-        [scroller_ setDelegate:self];
-        [scroller_ setBounces: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 */
+        webview_ = [[CydgetWebView alloc] initWithFrame:bounds];
+        [webview_ setDelegate:self];
+        [self addSubview:webview_];
 
-        if (!Wildcat_)
-            [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
-
-        CGRect rect([scroller_ bounds]);
-        //rect.size.height = 0;
-
-        WebThreadLock();
-
-        document_ = [[$UIWebBrowserView alloc] initWithFrame:rect];
-        WebView *webview([document_ webView]);
-
-        [document_ setBackgroundColor:[UIColor blackColor]];
-        if ([document_ respondsToSelector:@selector(setDrawsBackground:)])
-            [document_ setDrawsBackground:NO];
-        [webview setDrawsBackground:NO];
-
-        [webview setPreferencesIdentifier:@"WebCycript"];
-
-        [document_ setTileSize:CGSizeMake(rect.size.width, 500)];
-
-        if ([document_ respondsToSelector:@selector(enableReachability)])
-            [document_ enableReachability];
-        if ([document_ respondsToSelector:@selector(setAllowsMessaging:)])
-            [document_ setAllowsMessaging:YES];
-        if ([document_ respondsToSelector:@selector(useSelectionAssistantWithMode:)])
-            [document_ useSelectionAssistantWithMode:0];
-
-        [document_ setTilingEnabled:YES];
-        [document_ setDrawsGrid:NO];
-        [document_ setLogsTilingChanges:NO];
-        [document_ setTileMinificationFilter:kCAFilterNearest];
-
-        if ([document_ respondsToSelector:@selector(setDataDetectorTypes:)])
-            /* XXX: abstractify */
-            [document_ setDataDetectorTypes:0x80000000];
+        if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
+            [webview_ setDataDetectorTypes:0x80000000];
         else
-            [document_ setDetectsPhoneNumbers:NO];
-
-        [document_ setAutoresizes:YES];
-
-        [document_ setMinimumScale:0.25f forDocumentTypes:0x10];
-        [document_ setMaximumScale:5.00f forDocumentTypes:0x10];
-        [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
-        //[document_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
-
-        [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
-
-        [document_ setMinimumScale:1.00f forDocumentTypes:0x8];
-        [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
-        [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
+            [webview_ setDetectsPhoneNumbers:NO];
 
-        [document_ _setDocumentType:0x4];
+        [webview_ setScalesPageToFit:YES];
 
-        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];
+        UIWebDocumentView *document([webview_ _documentView]);
+        WebView *webview([document webView]);
+        WebPreferences *preferences([webview preferences]);
 
-        [document_ setSmoothsFonts:YES];
-        [document_ setAllowsImageSheet:YES];
-        [webview _setUsesLoaderCache:YES];
+        [document setTileSize:CGSizeMake(bounds.size.width, 500)];
 
-        [webview setGroupName:@"CydgetGroup"];
+        [document setBackgroundColor:[UIColor blackColor]];
+        [document setDrawsBackground:NO];
 
-        WebPreferences *preferences([webview preferences]);
+        [webview setPreferencesIdentifier:@"WebCycript"];
 
         if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
             [webview _setLayoutInterval:0];
         else
             [preferences _setLayoutInterval:0];
 
-        [self setViewportWidth:0];
+        [preferences setCacheModel:WebCacheModelDocumentViewer];
+        [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+        [preferences setOfflineWebApplicationCacheEnabled:YES];
 
-        [document_ setDelegate:self];
-        [document_ setGestureDelegate:self];
+        if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)])
+            [webview setShouldUpdateWhileOffscreen:NO];
 
-        if ([document_ respondsToSelector:@selector(setFormEditingDelegate:)])
-            [document_ setFormEditingDelegate:self];
-        [document_ setInteractionDelegate:self];
+        if ([document respondsToSelector:@selector(setAllowsMessaging:)])
+            [document setAllowsMessaging:YES];
+        if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
+            [webview _setAllowsMessaging:YES];
 
-        [scroller_ addSubview:document_];
+        if ([webview_ respondsToSelector:@selector(_scrollView)]) {
+            scroller_ = [webview_ _scrollView];
 
-        //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+            [scroller_ setDirectionalLockEnabled:YES];
+            [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
+            [scroller_ setDelaysContentTouches:NO];
 
-        indirect_ = [[WebCycriptDelegate alloc] initWithDelegate:self];
+            [scroller_ setCanCancelContentTouches:YES];
+        } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
+            UIScroller *scroller([webview_ _scroller]);
+            scroller_ = (UIScrollView *) scroller;
 
-        [webview setFrameLoadDelegate:indirect_];
-        [webview setPolicyDelegate:indirect_];
-        [webview setResourceLoadDelegate:indirect_];
-        [webview setUIDelegate:indirect_];
+            [scroller setDirectionalScrolling:YES];
+            [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
+            [scroller setScrollHysteresis:0]; /* 8 */
 
-        /* XXX: do not turn this on under penalty of extreme pain */
-        [webview setScriptDebugDelegate:nil];
+            [scroller setThumbDetectionEnabled:NO];
+        }
 
-        WebThreadUnlock();
+        [scroller_ setFixedBackgroundPattern:YES];
+        [scroller_ setBackgroundColor:[UIColor blackColor]];
+        [scroller_ setClipsSubviews:NO];
 
-        CGSize indsize([UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]);
-        indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
-        [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
+        [scroller_ setBounces:YES];
+        [scroller_ setShowBackgroundShadow:NO]; /* YES */
 
-        [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
-        [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
+        [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+        [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
 
         NSDictionary *configuration([$CydgetController currentConfiguration]);
 
         cycript_ = [configuration objectForKey:@"CycriptURLs"];
 
-        scrollable_ = [[configuration objectForKey:@"Scrollable"] boolValue];
-        [scroller_ setScrollingEnabled:scrollable_];
+        [scroller_ setScrollingEnabled:[[configuration objectForKey:@"Scrollable"] boolValue]];
 
         NSString *homepage([configuration objectForKey:@"Homepage"]);
         [self loadURL:[NSURL URLWithString:homepage]];
-
-        /*[UIKeyboard initImplementationNow];
-        CGSize keysize = [UIKeyboard defaultSize];
-        CGRect keyrect = {{0, [self bounds].size.height - 100}, keysize};
-        keyboard_ = [[UIKeyboard alloc] initWithFrame:keyrect];
-        [self addSubview:keyboard_];
-
-        [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 0, 100, 100)]];
-        [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 150, 100, 100)]];
-        [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 300, 100, 100)]];*/
     } return self;
 }
 
-- (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
-    [self retain];
-
-    UIActionSheet *sheet = [[[UIActionSheet alloc]
-        initWithTitle:nil
-        buttons:[NSArray arrayWithObjects:@"OK", nil]
-        defaultButtonIndex:0
-        delegate:self
-        context:@"alert"
-    ] autorelease];
-
-    [sheet setBodyText:message];
-    [sheet popupAlertAnimated:YES];
-}
-
-- (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
-    [self retain];
-
-    UIActionSheet *sheet = [[[UIActionSheet alloc]
-        initWithTitle:nil
-        buttons:[NSArray arrayWithObjects:@"OK", @"CANCEL", nil]
-        defaultButtonIndex:0
-        delegate:indirect_
-        context:@"confirm"
-    ] autorelease];
-
-    [sheet setNumberOfRows:1];
-    [sheet setBodyText:message];
-    [sheet popupAlertAnimated:YES];
-
-    NSRunLoop *loop([NSRunLoop currentRunLoop]);
-    NSDate *future([NSDate distantFuture]);
-
-    while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
-
-    NSNumber *confirm([confirm_ autorelease]);
-    confirm_ = nil;
-
-    [self autorelease];
-    return [confirm boolValue];
-}
-
-/* XXX: WebThreadLock? */
-- (void) _fixScroller:(CGRect)bounds {
-    float extra;
-    if (!editing_ || $UIFormAssistant == nil)
-        extra = 0;
-    else {
-        UIFormAssistant *assistant([$UIFormAssistant sharedFormAssistant]);
-        CGRect peripheral([assistant peripheralFrame]);
-        extra = peripheral.size.height;
-    }
-
-    CGRect subrect([scroller_ frame]);
-    subrect.size.height -= [TPBottomLockBar defaultHeight];
-    subrect.size.height -= extra;
-
-    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;
-    size.height += [TPBottomLockBar defaultHeight];
-    [scroller_ setContentSize:size];
-
-    if ([scroller_ respondsToSelector:@selector(releaseRubberBandIfNecessary)])
-        [scroller_ releaseRubberBandIfNecessary];
-}
-
-- (void) fixScroller {
-    CGRect bounds([document_ documentBounds]);
-    [self _fixScroller:bounds];
-}
-
-- (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
-    size_ = frame.size;
-    [self _fixScroller:frame];
-}
-
-- (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
-    [self view:sender didSetFrame:frame];
-}
-
-- (void) formAssistant:(id)sender didBeginEditingFormNode:(id)node {
-}
-
-- (void) formAssistant:(id)sender didEndEditingFormNode:(id)node {
-    [self fixScroller];
-}
-
-- (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
-    editing_ = true;
-}
-
-- (void) webView:(WebView *)sender didBeginEditingFormElement:(id)element {
-    [self fixScroller];
-}
-
-- (void) webViewDidEndEditingFormElements:(WebView *)sender {
-    editing_ = false;
-    [self fixScroller];
-}
-
-- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+- (void) webView:(WebView *)webview didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
     if (cycript_ != nil)
         if (NSString *href = [[[[frame dataSource] request] URL] absoluteString])
             if (Pcre([cycript_ UTF8String], 0 /*XXX:PCRE_UTF8*/)(href))
                 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
                     if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CydgetSetupContext"))) {
-                        WebView *webview([document_ webView]);
                         WebFrame *frame([webview mainFrame]);
                         JSGlobalContextRef context([frame globalContext]);
                         CYSetupContext(context);
                     }
 }
 
-- (bool) isLoading {
-    return [loading_ count] != 0;
-}
-
-- (void) reloadButtons {
-    if ([self isLoading]) {
-        [UIApp setNetworkActivityIndicatorVisible:YES];
-        [indicator_ startAnimation];
-    } else {
-        [UIApp setNetworkActivityIndicatorVisible:NO];
-        [indicator_ stopAnimation];
-    }
-}
-
-- (void) _finishLoading {
-    size_t count([loading_ count]);
-    /*if (count == 0)
-        [self autorelease];*/
-    if (reloading_ || count != 0)
-        return;
-    [self reloadButtons];
-}
-
-- (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
-    return [document_ webView:sender shouldScrollToPoint:point forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame {
-    return [document_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame {
-    return [document_ webView:sender needsScrollNotifications:notifications forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
-    return [document_ webView:sender didCommitLoadForFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame {
-    return [document_ webView:sender didReceiveDocTypeForFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
-    [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
-    [self _finishLoading];
-    return [document_ webView:sender didFinishLoadForFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
-    /*if ([loading_ count] == 0)
-        [self retain];*/
-    [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
-
-    if ([frame parentFrame] == nil) {
-        [document_ resignFirstResponder];
-
-        reloading_ = false;
-
-        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];
-        else if ([scroller_ respondsToSelector:@selector(_setZoomScale:duration:)])
-            [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 = 1;
-            [document_ setFrame:webrect];
-        }
-    }
-
-    [self reloadButtons];
-}
-
-- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
-    /*if ([frame parentFrame] == nil)
-        [self autorelease];*/
-
-    [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
-    [self _finishLoading];
-
-    if (reloading_)
-        return;
-
-    if ([frame parentFrame] == nil) {
-        [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
-            [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
-            [[error localizedDescription] stringByAddingPercentEscapes]
-        ]]];
-
-        error_ = true;
-    }
-}
-
-- (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 {
-    [self _didFailWithError:error forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
-    NSLog(@"Console:%@\n", [dictionary description]);
-}
-
 @end
 
 @interface WebCycriptLockScreenController : SBAwayViewPluginController {
@@ -1392,7 +840,21 @@ static void msset_(Type_ &function, const char *name, MSImageRef handle) {
 
 @implementation WebCycriptLockScreenController
 
+static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) {
+    UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
+    if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
+        [uiWebView webView:view didClearWindowObject:window forFrame:frame];
+}
+
 + (void) initialize {
+    if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate"))
+        class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16");
+
+    if (float *_UIScrollViewDecelerationRateNormal = reinterpret_cast<float *>(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal")))
+        CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
+    else // XXX: this actually might be fast on some older systems: we should look into this
+        CYScrollViewDecelerationRateNormal = 0.998;
+
     iOS4 = kCFCoreFoundationVersionNumber >= 550.32;
 
     $UIWebBrowserView = objc_getClass("UIWebBrowserView");
index d16c35319decfa9163f76a29143812f26b65ddcb..3c2b6f7d000c3742453afeb1797f9aab74736d16 100644 (file)
@@ -38,6 +38,7 @@
         text-align: center;
         text-shadow: -0.5px -1px 1px black;
         top: -6px;
+        width: 319px;
     }
 
     #lcd h2 {
index 4ba17343da29805346e6a390f0344d452595effb..ec7b0e7648f9664c12e4b44e9920721fa01c4d71 100644 (file)
@@ -38,6 +38,7 @@
         text-align: center;
         text-shadow: -0.5px -1px 1px black;
         top: -6px;
+        width: 319px;
     }
 
     #lcd h2 {