X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/5d8f1006c6bbb69d65d7b2f9eab9cde3bda32e6a..172b238d6f66f6b1a0298ef9ebbcfbe9477a2221:/UICaboodle/BrowserView.mm diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index bd2c2367..13e6b08c 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -10,8 +10,14 @@ extern NSString * const kCAFilterNearest; #include "substrate.h" +#define ForSaurik 0 + +static bool Wildcat_; + static CFArrayRef (*$GSSystemCopyCapability)(CFStringRef); static CFArrayRef (*$GSSystemGetCapability)(CFStringRef); +static Class $UIFormAssistant; +static Class $UIWebBrowserView; @interface NSString (UIKit) - (NSString *) stringByAddingPercentEscapes; @@ -142,77 +148,6 @@ static CFArrayRef (*$GSSystemGetCapability)(CFStringRef); @end -#if 0 -/* Mail Composition {{{ */ -@interface MailToView : PopUpView { - MailComposeController *controller_; -} - -- (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url; - -@end - -@implementation MailToView - -- (void) dealloc { - [controller_ release]; - [super dealloc]; -} - -- (void) mailComposeControllerWillAttemptToSend:(MailComposeController *)controller { - NSLog(@"will"); -} - -- (void) mailComposeControllerDidAttemptToSend:(MailComposeController *)controller mailDelivery:(id)delivery { - NSLog(@"did:%@", delivery); -// [UIApp setStatusBarShowsProgress:NO]; -if ([controller error]){ -NSArray *buttons = [NSArray arrayWithObjects:UCLocalize("OK"), nil]; -UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self]; -[mailAlertSheet setBodyText:[controller error]]; -[mailAlertSheet popupAlertAnimated:YES]; -} -} - -- (void) showError { - NSLog(@"%@", [controller_ error]); - NSArray *buttons = [NSArray arrayWithObjects:UCLocalize("OK"), nil]; - UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self]; - [mailAlertSheet setBodyText:[controller_ error]]; - [mailAlertSheet popupAlertAnimated:YES]; -} - -- (void) deliverMessage { _pooled - setuid(501); - setgid(501); - - if (![controller_ deliverMessage]) - [self performSelectorOnMainThread:@selector(showError) withObject:nil waitUntilDone:NO]; -} - -- (void) mailComposeControllerCompositionFinished:(MailComposeController *)controller { - if ([controller_ needsDelivery]) - [NSThread detachNewThreadSelector:@selector(deliverMessage) toTarget:self withObject:nil]; - else - [self cancel]; -} - -- (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url { - if ((self = [super initWithView:view delegate:delegate]) != nil) { - controller_ = [[MailComposeController alloc] initForContentSize:[overlay_ bounds].size]; - [controller_ setDelegate:self]; - [controller_ initializeUI]; - [controller_ setupForURL:url]; - - UIView *view([controller_ view]); - [overlay_ addSubview:view]; - } return self; -} - -@end -/* }}} */ -#endif - #define ShowInternals 0 #define LogBrowser 0 @@ -235,6 +170,15 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( $GSSystemCopyCapability = reinterpret_cast(dlsym(RTLD_DEFAULT, "GSSystemCopyCapability")); $GSSystemGetCapability = reinterpret_cast(dlsym(RTLD_DEFAULT, "GSSystemGetCapability")); + $UIFormAssistant = objc_getClass("UIFormAssistant"); + + $UIWebBrowserView = objc_getClass("UIWebBrowserView"); + if ($UIWebBrowserView == nil) { + Wildcat_ = false; + $UIWebBrowserView = objc_getClass("UIWebDocumentView"); + } else { + Wildcat_ = true; + } } - (void) dealloc { @@ -265,7 +209,10 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( [webview_ setDelegate:nil]; [webview_ setGestureDelegate:nil]; - [webview_ setFormEditingDelegate:nil]; + + if ([webview_ respondsToSelector:@selector(setFormEditingDelegate:)]) + [webview_ setFormEditingDelegate:nil]; + [webview_ setInteractionDelegate:nil]; [indirect_ setDelegate:nil]; @@ -315,7 +262,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( [self loadRequest:[NSURLRequest requestWithURL:url cachePolicy:policy - timeoutInterval:30.0 + timeoutInterval:120.0 ]]; } @@ -347,6 +294,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( context:@"submit" ] autorelease]; + [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + [sheet setNumberOfRows:1]; [sheet popupAlertAnimated:YES]; } @@ -363,10 +312,11 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( /* XXX: WebThreadLock? */ - (void) _fixScroller:(CGRect)bounds { float extra; - if (!editing_) + + if (!editing_ || $UIFormAssistant == nil) extra = 0; else { - UIFormAssistant *assistant([UIFormAssistant sharedFormAssistant]); + UIFormAssistant *assistant([$UIFormAssistant sharedFormAssistant]); CGRect peripheral([assistant peripheralFrame]); #if LogBrowser NSLog(@"per:%f", peripheral.size.height); @@ -376,16 +326,18 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( CGRect subrect([scroller_ frame]); subrect.size.height -= extra; - [scroller_ setScrollerIndicatorSubrect:subrect]; - NSSize visible(NSMakeSize(subrect.size.width, subrect.size.height)); - [webview_ setValue:[NSValue valueWithSize:visible] forGestureAttribute:UIGestureAttributeVisibleSize]; + if ([scroller_ respondsToSelector:@selector(setScrollerIndicatorSubrect:)]) + [scroller_ setScrollerIndicatorSubrect:subrect]; + + [webview_ setValue:[NSValue valueWithSize:NSMakeSize(subrect.size.width, subrect.size.height)] forGestureAttribute:UIGestureAttributeVisibleSize]; CGSize size(size_); size.height += extra; [scroller_ setContentSize:size]; - [scroller_ releaseRubberBandIfNecessary]; + if ([scroller_ respondsToSelector:@selector(releaseRubberBandIfNecessary)]) + [scroller_ releaseRubberBandIfNecessary]; } - (void) fixScroller { @@ -476,6 +428,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( context:@"sensitive" ] autorelease]; + [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + NSString *host(@"XXX"); [sheet setNumberOfRows:1]; @@ -518,6 +472,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( context:@"alert" ] autorelease]; + [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + [sheet setBodyText:message]; [sheet popupAlertAnimated:YES]; } @@ -535,6 +491,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( context:@"confirm" ] autorelease]; + [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + [sheet setNumberOfRows:1]; [sheet setBodyText:message]; [sheet popupAlertAnimated:YES]; @@ -606,12 +564,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( } - (void) _openMailToURL:(NSURL *)url { -// XXX: this makes me sad -#if 0 - [[[MailToView alloc] initWithView:underlay_ delegate:self url:url] autorelease]; -#else [UIApp openURL:url];// asPanel:YES]; -#endif } - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element { @@ -843,8 +796,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( [sender cancelAuthenticationChallenge:challenge_]; break; - default: - _assert(false); + _nodefault } [challenge_ release]; @@ -864,8 +816,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( } break; - default: - _assert(false); + _nodefault } [sheet dismiss]; @@ -888,6 +839,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( context:@"challenge" ] autorelease]; + [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + [sheet setNumberOfRows:1]; [sheet addTextFieldWithValue:@"" label:UCLocalize("USERNAME")]; @@ -968,8 +921,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( } - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { - if ([loading_ count] == 0) - [self retain]; + /*if ([loading_ count] == 0) + [self retain];*/ [loading_ addObject:[NSValue valueWithNonretainedObject:frame]]; if ([frame parentFrame] == nil) { @@ -1014,7 +967,16 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( [book_ reloadTitleForPage:self]; - [scroller_ scrollPointVisibleAtTopLeft:CGPointZero]; + if (Wildcat_) { + CGRect webrect = [scroller_ bounds]; + webrect.size.height = 1; + [webview_ setFrame:webrect]; + } + + if ([scroller_ respondsToSelector:@selector(scrollPointVisibleAtTopLeft:)]) + [scroller_ scrollPointVisibleAtTopLeft:CGPointZero]; + else + [scroller_ scrollRectToVisible:CGRectZero animated:NO]; if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)]) [scroller_ setZoomScale:1 duration:0]; @@ -1023,9 +985,11 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)]) [scroller_ setZoomScale:1 animated:NO];*/ - CGRect webrect = [scroller_ bounds]; - webrect.size.height = 0; - [webview_ setFrame:webrect]; + if (!Wildcat_) { + CGRect webrect = [scroller_ bounds]; + webrect.size.height = 0; + [webview_ setFrame:webrect]; + } } [self reloadButtons]; @@ -1033,8 +997,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( - (void) _finishLoading { size_t count([loading_ count]); - if (count == 0) - [self autorelease]; + /*if (count == 0) + [self autorelease];*/ if (reloading_ || count != 0) return; if (finish_ != nil) @@ -1125,8 +1089,9 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( } - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame { - if ([frame parentFrame] == nil) - [self autorelease]; + _trace(); + /*if ([frame parentFrame] == nil) + [self autorelease];*/ [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]]; [self _finishLoading]; @@ -1146,6 +1111,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( - (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]; } - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { @@ -1158,17 +1125,99 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( #endif } +- (void) webView:(WebView *)sender didReceiveMessage:(NSDictionary *)dictionary { +#if LogBrowser || ForSaurik + lprintf("Console:%s\n", [[dictionary description] UTF8String]); +#endif + if ([webview_ respondsToSelector:@selector(webView:didReceiveMessage:)]) + [webview_ webView:sender didReceiveMessage:dictionary]; +} + +- (void) webView:(id)sender willCloseFrame:(id)frame { + if ([webview_ respondsToSelector:@selector(webView:willCloseFrame:)]) + [webview_ webView:sender willCloseFrame:frame]; +} + +- (void) webView:(id)sender didFinishDocumentLoadForFrame:(id)frame { + if ([webview_ respondsToSelector:@selector(webView:didFinishDocumentLoadForFrame:)]) + [webview_ webView:sender didFinishDocumentLoadForFrame:frame]; +} + +- (void) webView:(id)sender didFirstLayoutInFrame:(id)frame { + if ([webview_ respondsToSelector:@selector(webView:didFirstLayoutInFrame:)]) + [webview_ webView:sender didFirstLayoutInFrame:frame]; +} + +- (void) webViewFormEditedStatusHasChanged:(id)changed { + if ([webview_ respondsToSelector:@selector(webViewFormEditedStatusHasChanged:)]) + [webview_ webViewFormEditedStatusHasChanged:changed]; +} + +- (void) webView:(id)sender formStateDidFocusNode:(id)formState { + if ([webview_ respondsToSelector:@selector(webView:formStateDidFocusNode:)]) + [webview_ webView:sender formStateDidFocusNode:formState]; +} + +- (void) webView:(id)sender formStateDidBlurNode:(id)formState { + if ([webview_ respondsToSelector:@selector(webView:formStateDidBlurNode:)]) + [webview_ webView:sender formStateDidBlurNode:formState]; +} + /* XXX: fix this stupid include file - (void) webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)database { [origin setQuota:0x500000]; }*/ +- (void) webViewDidLayout:(id)sender { + [webview_ webViewDidLayout:sender]; +} + +- (void) webView:(id)sender didFirstVisuallyNonEmptyLayoutInFrame:(id)frame { + [webview_ webView:sender didFirstVisuallyNonEmptyLayoutInFrame:frame]; +} + +- (void) webView:(id)sender saveStateToHistoryItem:(id)item forFrame:(id)frame { + [webview_ webView:sender saveStateToHistoryItem:item forFrame:frame]; +} + +- (void) webView:(id)sender restoreStateFromHistoryItem:(id)item forFrame:(id)frame force:(BOOL)force { + [webview_ webView:sender restoreStateFromHistoryItem:item forFrame:frame force:force]; +} + +- (void) webView:(id)sender attachRootLayer:(id)layer { + [webview_ webView:sender attachRootLayer:layer]; +} + +- (id) webView:(id)sender plugInViewWithArguments:(id)arguments fromPlugInPackage:(id)package { + return [webview_ webView:sender plugInViewWithArguments:arguments fromPlugInPackage:package]; +} + +- (void) webView:(id)sender willShowFullScreenForPlugInView:(id)view { + [webview_ webView:sender willShowFullScreenForPlugInView:view]; +} + +- (void) webView:(id)sender didHideFullScreenForPlugInView:(id)view { + [webview_ webView:sender didHideFullScreenForPlugInView:view]; +} + +- (void) webView:(id)sender willAddPlugInView:(id)view { + [webview_ webView:sender willAddPlugInView:view]; +} + +- (void) webView:(id)sender didObserveDeferredContentChange:(int)change forFrame:(id)frame { + [webview_ webView:sender didObserveDeferredContentChange:change forFrame:frame]; +} + +- (void) webViewDidPreventDefaultForEvent:(id)sender { + [webview_ webViewDidPreventDefaultForEvent:sender]; +} + - (void) _setTileDrawingEnabled:(BOOL)enabled { //[webview_ setTileDrawingEnabled:enabled]; } - (void) setViewportWidth:(float)width { - width_ = width ? width != 0 : [[self class] defaultWidth]; + width_ = width != 0 ? width : [[self class] defaultWidth]; [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; } @@ -1201,7 +1250,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( struct CGRect bounds = [self bounds]; - scroller_ = [[UIScroller alloc] initWithFrame:bounds]; + scroller_ = [[objc_getClass(Wildcat_ ? "UIScrollView" : "UIScroller") alloc] initWithFrame:bounds]; [self addSubview:scroller_]; [scroller_ setFixedBackgroundPattern:YES]; @@ -1209,18 +1258,34 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( [scroller_ setScrollingEnabled:YES]; [scroller_ setClipsSubviews:YES]; - [scroller_ setAllowsRubberBanding:YES]; + + if (!Wildcat_) + [scroller_ setAllowsRubberBanding:YES]; [scroller_ setDelegate:self]; [scroller_ setBounces:YES]; - [scroller_ setScrollHysteresis:8]; - [scroller_ setThumbDetectionEnabled:NO]; - [scroller_ setDirectionalScrolling:YES]; - [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */ - [scroller_ setEventMode:YES]; + + if (!Wildcat_) { + [scroller_ setScrollHysteresis:8]; + [scroller_ setThumbDetectionEnabled:NO]; + [scroller_ setDirectionalScrolling:YES]; + //[scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */ + [scroller_ setEventMode:YES]; + } + + if (Wildcat_) { + UIScrollView *scroller((UIScrollView *)scroller_); + //[scroller setDirectionalLockEnabled:NO]; + [scroller setDelaysContentTouches:NO]; + //[scroller setScrollsToTop:NO]; + //[scroller setCanCancelContentTouches:NO]; + } + [scroller_ setShowBackgroundShadow:NO]; /* YES */ - [scroller_ setAllowsRubberBanding:YES]; /* Vertical */ - [scroller_ setAdjustForContentSizeChange:YES]; /* NO */ + //[scroller_ setAllowsRubberBanding:YES]; /* Vertical */ + + if (!Wildcat_) + [scroller_ setAdjustForContentSizeChange:YES]; /* NO */ CGRect webrect = [scroller_ bounds]; webrect.size.height = 0; @@ -1240,7 +1305,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( #else if (true) { #endif - webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect]; + webview_ = [[$UIWebBrowserView alloc] initWithFrame:webrect]; webview = [webview_ webView]; // XXX: this is terribly (too?) expensive @@ -1251,9 +1316,8 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( if ([webview_ respondsToSelector:@selector(enableReachability)]) [webview_ enableReachability]; - - [webview_ setAllowsMessaging:YES]; - + if ([webview_ respondsToSelector:@selector(setAllowsMessaging:)]) + [webview_ setAllowsMessaging:YES]; if ([webview_ respondsToSelector:@selector(useSelectionAssistantWithMode:)]) [webview_ useSelectionAssistantWithMode:0]; @@ -1283,7 +1347,7 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( [webview_ _setDocumentType:0x4]; - if ([webview_ respondsToSelector:@selector(UIWebDocumentView:)]) + if ([webview_ respondsToSelector:@selector(setZoomsFocusedFormControl:)]) [webview_ setZoomsFocusedFormControl:YES]; [webview_ setContentsPosition:7]; [webview_ setEnabledGestures:0xa]; @@ -1308,7 +1372,10 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( [webview_ setDelegate:self]; [webview_ setGestureDelegate:self]; - [webview_ setFormEditingDelegate:self]; + + if ([webview_ respondsToSelector:@selector(setFormEditingDelegate:)]) + [webview_ setFormEditingDelegate:self]; + [webview_ setInteractionDelegate:self]; [scroller_ addSubview:webview_]; @@ -1328,11 +1395,13 @@ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize( WebThreadUnlock(); CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]; - indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)]; + indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(bounds.size.width - 39, 12, indsize.width, indsize.height)]; [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite]; - [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; - [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; + [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + [scroller_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; + [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; /*UIWebView *test([[[UIWebView alloc] initWithFrame:[self bounds]] autorelease]); [test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]];