#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;
@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
$GSSystemCopyCapability = reinterpret_cast<CFArrayRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemCopyCapability"));
$GSSystemGetCapability = reinterpret_cast<CFArrayRef (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemGetCapability"));
+ $UIFormAssistant = objc_getClass("UIFormAssistant");
+
+ $UIWebBrowserView = objc_getClass("UIWebBrowserView");
+ if ($UIWebBrowserView == nil) {
+ Wildcat_ = false;
+ $UIWebBrowserView = objc_getClass("UIWebDocumentView");
+ } else {
+ Wildcat_ = true;
+ }
}
- (void) dealloc {
[webview_ setDelegate:nil];
[webview_ setGestureDelegate:nil];
- [webview_ setFormEditingDelegate:nil];
+
+ if ([webview_ respondsToSelector:@selector(setFormEditingDelegate:)])
+ [webview_ setFormEditingDelegate:nil];
+
[webview_ setInteractionDelegate:nil];
[indirect_ setDelegate:nil];
[self loadRequest:[NSURLRequest
requestWithURL:url
cachePolicy:policy
- timeoutInterval:30.0
+ timeoutInterval:120.0
]];
}
context:@"submit"
] autorelease];
+ [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
[sheet setNumberOfRows:1];
[sheet popupAlertAnimated:YES];
}
/* 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);
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 {
context:@"sensitive"
] autorelease];
+ [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
NSString *host(@"XXX");
[sheet setNumberOfRows:1];
context:@"alert"
] autorelease];
+ [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
[sheet setBodyText:message];
[sheet popupAlertAnimated:YES];
}
context:@"confirm"
] autorelease];
+ [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
[sheet setNumberOfRows:1];
[sheet setBodyText:message];
[sheet popupAlertAnimated:YES];
}
- (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 {
[sender cancelAuthenticationChallenge:challenge_];
break;
- default:
- _assert(false);
+ _nodefault
}
[challenge_ release];
}
break;
- default:
- _assert(false);
+ _nodefault
}
[sheet dismiss];
context:@"challenge"
] autorelease];
+ [sheet setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+
[sheet setNumberOfRows:1];
[sheet addTextFieldWithValue:@"" label:UCLocalize("USERNAME")];
}
- (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) {
[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];
/*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];
- (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)
}
- (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];
- (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 {
#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];
}
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];
[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;
#else
if (true) {
#endif
- webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect];
+ webview_ = [[$UIWebBrowserView alloc] initWithFrame:webrect];
webview = [webview_ webView];
// XXX: this is terribly (too?) expensive
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];
[webview_ _setDocumentType:0x4];
- if ([webview_ respondsToSelector:@selector(UIWebDocumentView:)])
+ if ([webview_ respondsToSelector:@selector(setZoomsFocusedFormControl:)])
[webview_ setZoomsFocusedFormControl:YES];
[webview_ setContentsPosition:7];
[webview_ setEnabledGestures:0xa];
[webview_ setDelegate:self];
[webview_ setGestureDelegate:self];
- [webview_ setFormEditingDelegate:self];
+
+ if ([webview_ respondsToSelector:@selector(setFormEditingDelegate:)])
+ [webview_ setFormEditingDelegate:self];
+
[webview_ setInteractionDelegate:self];
[scroller_ addSubview:webview_];
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/"]]];