1 #include <BrowserView.h>
3 /* Indirect Delegate {{{ */
4 @interface IndirectDelegate : NSProxy {
5 _transient volatile id delegate_;
8 - (void) setDelegate:(id)delegate;
9 - (id) initWithDelegate:(id)delegate;
12 @implementation IndirectDelegate
14 - (void) setDelegate:(id)delegate {
18 - (id) initWithDelegate:(id)delegate {
23 - (BOOL) respondsToSelector:(SEL)sel {
24 return delegate_ == nil ? FALSE : [delegate_ respondsToSelector:sel];
27 - (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
29 if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
31 // XXX: I fucking hate Apple so very very bad
32 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
35 - (void) forwardInvocation:(NSInvocation *)inv {
36 SEL sel = [inv selector];
37 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
38 [inv invokeWithTarget:delegate_];
44 @interface WebView (Cydia)
45 - (void) setScriptDebugDelegate:(id)delegate;
46 - (void) _setFormDelegate:(id)delegate;
47 - (void) _setUIKitDelegate:(id)delegate;
48 - (void) setWebMailDelegate:(id)delegate;
49 - (void) _setLayoutInterval:(float)interval;
52 /* Web Scripting {{{ */
53 @interface CydiaObject : NSObject {
57 - (id) initWithDelegate:(IndirectDelegate *)indirect;
60 @implementation CydiaObject
67 - (id) initWithDelegate:(IndirectDelegate *)indirect {
68 if ((self = [super init]) != nil) {
69 indirect_ = [indirect retain];
73 + (NSString *) webScriptNameForSelector:(SEL)selector {
74 if (selector == @selector(getPackageById:))
75 return @"getPackageById";
76 else if (selector == @selector(setAutoPopup:))
77 return @"setAutoPopup";
78 else if (selector == @selector(setButtonImage:withStyle:toFunction:))
79 return @"setButtonImage";
80 else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
81 return @"setButtonTitle";
82 else if (selector == @selector(supports:))
84 else if (selector == @selector(du:))
86 else if (selector == @selector(statfs:))
92 + (BOOL) isSelectorExcludedFromWebScript:(SEL)selector {
93 return [self webScriptNameForSelector:selector] == nil;
96 - (BOOL) supports:(NSString *)feature {
97 return [feature isEqualToString:@"window.open"];
100 - (Package *) getPackageById:(NSString *)id {
101 return [[Database sharedInstance] packageWithName:id];
104 - (NSArray *) statfs:(NSString *)path {
107 if (path == nil || statfs([path UTF8String], &stat) == -1)
110 return [NSArray arrayWithObjects:
111 [NSNumber numberWithUnsignedLong:stat.f_bsize],
112 [NSNumber numberWithUnsignedLong:stat.f_blocks],
113 [NSNumber numberWithUnsignedLong:stat.f_bfree],
117 - (NSNumber *) du:(NSString *)path {
118 NSNumber *value(nil);
121 _assert(pipe(fds) != -1);
123 pid_t pid(ExecFork());
125 _assert(dup2(fds[1], 1) != -1);
126 _assert(close(fds[0]) != -1);
127 _assert(close(fds[1]) != -1);
128 execlp("du", "du", "-s", [path UTF8String], NULL);
133 _assert(close(fds[1]) != -1);
135 if (FILE *du = fdopen(fds[0], "r")) {
137 while (fgets(line, sizeof(line), du) != NULL) {
138 size_t length(strlen(line));
139 while (length != 0 && line[length - 1] == '\n')
140 line[--length] = '\0';
141 if (char *tab = strchr(line, '\t')) {
143 value = [NSNumber numberWithUnsignedLong:strtoul(line, NULL, 0)];
148 } else _assert(close(fds[0]));
152 if (waitpid(pid, &status, 0) == -1)
160 - (void) setAutoPopup:(BOOL)popup {
161 [indirect_ setAutoPopup:popup];
164 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
165 [indirect_ setButtonImage:button withStyle:style toFunction:function];
168 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
169 [indirect_ setButtonTitle:button withStyle:style toFunction:function];
175 @implementation BrowserView
178 #include "Internals.h"
183 NSLog(@"[BrowserView dealloc]");
186 if (challenge_ != nil)
187 [challenge_ release];
189 WebView *webview = [webview_ webView];
190 [webview setFrameLoadDelegate:nil];
191 [webview setResourceLoadDelegate:nil];
192 [webview setUIDelegate:nil];
193 [webview setScriptDebugDelegate:nil];
194 [webview setPolicyDelegate:nil];
196 [webview setDownloadDelegate:nil];
198 [webview _setFormDelegate:nil];
199 [webview _setUIKitDelegate:nil];
200 [webview setWebMailDelegate:nil];
201 [webview setEditingDelegate:nil];
203 [webview_ setDelegate:nil];
204 [webview_ setGestureDelegate:nil];
206 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
211 [webview_ removeFromSuperview];
212 [Documents_ addObject:[webview_ autorelease]];
217 [indirect_ setDelegate:nil];
222 [scroller_ setDelegate:nil];
228 if (function_ != nil)
232 [indicator_ release];
240 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
241 [self loadRequest:[NSURLRequest
248 - (void) loadURL:(NSURL *)url {
249 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
252 - (NSMutableURLRequest *) _addHeadersToRequest:(NSURLRequest *)request {
253 NSMutableURLRequest *copy = [request mutableCopy];
255 if (Machine_ != NULL)
256 [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
257 if (UniqueID_ != nil)
258 [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
261 [copy setValue:Role_ forHTTPHeaderField:@"X-Role"];
266 - (void) loadRequest:(NSURLRequest *)request {
269 [webview_ loadRequest:request];
276 if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
277 [self loadRequest:request_];
279 UIActionSheet *sheet = [[[UIActionSheet alloc]
280 initWithTitle:@"Are you sure you want to submit this form again?"
281 buttons:[NSArray arrayWithObjects:@"Cancel", @"Submit", nil]
287 [sheet setNumberOfRows:1];
288 [sheet popupAlertAnimated:YES];
292 - (WebView *) webView {
293 return [webview_ webView];
296 - (UIWebDocumentView *) documentView {
300 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
301 [scroller_ setContentSize:frame.size];
304 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
305 [self view:sender didSetFrame:frame];
308 - (void) pushPage:(RVPage *)page {
309 [page setDelegate:delegate_];
310 [self setBackButtonTitle:title_];
311 [book_ pushPage:page];
319 [book_ pushPage:self];
322 - (BOOL) getSpecial:(NSURL *)url {
324 NSLog(@"getSpecial:%@", url);
327 NSString *href([url absoluteString]);
328 NSString *scheme([[url scheme] lowercaseString]);
332 if ([href hasPrefix:@"apptapp://package/"])
333 page = [delegate_ pageForPackage:[href substringFromIndex:18]];
334 else if ([scheme isEqualToString:@"cydia"]) {
335 page = [delegate_ pageForURL:url hasTag:NULL];
338 } else if (![scheme isEqualToString:@"apptapp"])
342 [self pushPage:page];
346 - (void) webViewShow:(WebView *)sender {
347 /* XXX: this is where I cry myself to sleep */
350 - (bool) _allowJavaScriptPanel {
354 - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
355 if ([self _allowJavaScriptPanel])
358 UIActionSheet *sheet = [[[UIActionSheet alloc]
360 buttons:[NSArray arrayWithObjects:@"OK", nil]
366 [sheet setBodyText:message];
367 [sheet popupAlertAnimated:YES];
370 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
371 if (![self _allowJavaScriptPanel])
374 UIActionSheet *sheet = [[[UIActionSheet alloc]
376 buttons:[NSArray arrayWithObjects:@"OK", @"Cancel", nil]
382 [sheet setNumberOfRows:1];
383 [sheet setBodyText:message];
384 [sheet popupAlertAnimated:YES];
386 NSRunLoop *loop([NSRunLoop currentRunLoop]);
387 NSDate *future([NSDate distantFuture]);
389 while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
391 NSNumber *confirm([confirm_ autorelease]);
393 return [confirm boolValue];
396 - (void) setAutoPopup:(BOOL)popup {
400 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
402 [button_ autorelease];
403 button_ = button == nil ? nil : [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:button]]] retain];
406 [style_ autorelease];
407 style_ = style == nil ? nil : [style retain];
409 if (function_ != nil)
410 [function_ autorelease];
411 function_ = function == nil ? nil : [function retain];
414 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
416 [button_ autorelease];
417 button_ = button == nil ? nil : [button retain];
420 [style_ autorelease];
421 style_ = style == nil ? nil : [style retain];
423 if (function_ != nil)
424 [function_ autorelease];
425 function_ = function == nil ? nil : [function retain];
428 - (void) webViewClose:(WebView *)sender {
432 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
433 [window setValue:cydia_ forKey:@"cydia"];
436 - (void) webView:(WebView *)sender unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame {
437 NSLog(@"err:%@", error);
440 - (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
442 NSLog(@"nwa:%@", name);
445 if (NSURL *url = [request URL]) {
446 if (name == nil) unknown: {
447 if (![self getSpecial:url]) {
448 NSString *scheme([[url scheme] lowercaseString]);
449 if ([scheme isEqualToString:@"mailto"])
450 [delegate_ openMailToURL:url];
453 } else if ([name isEqualToString:@"_open"])
454 [delegate_ openURL:url];
455 else if ([name isEqualToString:@"_popup"]) {
456 RVBook *book([[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
458 RVPage *page([delegate_ pageForURL:url hasTag:NULL]);
460 /* XXX: call createWebViewWithRequest instead? */
462 [self setBackButtonTitle:title_];
464 BrowserView *browser([[[BrowserView alloc] initWithBook:book] autorelease]);
465 [browser loadURL:url];
469 [book setDelegate:delegate_];
470 [page setDelegate:delegate_];
473 [book_ pushBook:book];
481 - (void) webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
482 if ([WebView canShowMIMEType:type])
485 // XXX: handle more mime types!
487 if (frame == [webView mainFrame])
488 [UIApp openURL:[request URL]];
492 - (void) webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
493 if (request == nil) ignore: {
498 NSURL *url([request URL]);
500 if (url == nil) use: {
501 if (!error_ && [frame parentFrame] == nil) {
503 [request_ autorelease];
504 request_ = [request retain];
506 NSLog(@"dpn:%@", request_);
511 /* XXX: maybe only the main frame? */
516 else NSLog(@"nav:%@:%@", url, [action description]);
519 const NSArray *capability(reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability)));
522 [capability containsObject:@"com.apple.Maps"] && [url mapsURL] ||
523 [capability containsObject:@"com.apple.youtube"] && [url youTubeURL]
530 int store(_not(int));
531 if (NSURL *itms = [url itmsURL:&store]) {
533 NSLog(@"itms#%@#%u#%@", url, store, itms);
537 store == 1 && [capability containsObject:@"com.apple.MobileStore"] ||
538 store == 2 && [capability containsObject:@"com.apple.AppStore"]
545 NSString *scheme([[url scheme] lowercaseString]);
547 if ([scheme isEqualToString:@"tel"]) {
552 if ([scheme isEqualToString:@"mailto"]) {
553 [delegate_ openMailToURL:url];
557 if ([self getSpecial:url])
559 else if ([WebView _canHandleRequest:request])
561 else if ([url isSpringboardHandledURL])
567 - (void) webView:(WebView *)sender setStatusText:(NSString *)text {
568 //lprintf("Status:%s\n", [text UTF8String]);
571 - (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
572 NSString *context([sheet context]);
574 if ([context isEqualToString:@"alert"])
576 else if ([context isEqualToString:@"confirm"]) {
579 confirm_ = [NSNumber numberWithBool:YES];
583 confirm_ = [NSNumber numberWithBool:NO];
588 } else if ([context isEqualToString:@"challenge"]) {
589 id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
593 NSString *username([[sheet textFieldAtIndex:0] text]);
594 NSString *password([[sheet textFieldAtIndex:1] text]);
596 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
598 [sender useCredential:credential forAuthenticationChallenge:challenge_];
602 [sender cancelAuthenticationChallenge:challenge_];
609 [challenge_ release];
613 } else if ([context isEqualToString:@"submit"]) {
620 [webview_ loadRequest:request_];
631 - (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
632 challenge_ = [challenge retain];
634 NSURLProtectionSpace *space([challenge protectionSpace]);
635 NSString *realm([space realm]);
639 UIActionSheet *sheet = [[[UIActionSheet alloc]
641 buttons:[NSArray arrayWithObjects:@"Login", @"Cancel", nil]
647 [sheet setNumberOfRows:1];
649 [sheet addTextFieldWithValue:@"" label:@"username"];
650 [sheet addTextFieldWithValue:@"" label:@"password"];
652 UITextField *username([sheet textFieldAtIndex:0]); {
653 UITextInputTraits *traits([username textInputTraits]);
654 [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
655 [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
656 [traits setKeyboardType:UIKeyboardTypeASCIICapable];
657 [traits setReturnKeyType:UIReturnKeyNext];
660 UITextField *password([sheet textFieldAtIndex:1]); {
661 UITextInputTraits *traits([password textInputTraits]);
662 [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
663 [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
664 [traits setKeyboardType:UIKeyboardTypeASCIICapable];
665 // XXX: UIReturnKeyDone
666 [traits setReturnKeyType:UIReturnKeyNext];
667 [traits setSecureTextEntry:YES];
670 [sheet popupAlertAnimated:YES];
673 - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
674 return [self _addHeadersToRequest:request];
677 - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features {
678 //- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request userGesture:(BOOL)gesture {
680 NSLog(@"cwv:%@ (%@): %@", request, title_, features == nil ? @"{}" : [features description]);
681 //NSLog(@"cwv:%@ (%@): %@", request, title_, gesture ? @"Yes" : @"No");
684 NSNumber *value([features objectForKey:@"width"]);
685 float width(value == nil ? [BrowserView defaultWidth] : [value floatValue]);
687 RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
689 /* XXX: deal with cydia:// pages */
690 BrowserView *browser([[[BrowserView alloc] initWithBook:book forWidth:width] autorelease]);
692 if (features == nil && popup_) {
693 [book setDelegate:delegate_];
694 [browser setDelegate:delegate_];
696 [browser loadRequest:request];
698 [book setPage:browser];
699 [book_ pushBook:book];
700 } else if (request == nil) {
701 [self setBackButtonTitle:title_];
702 [browser setDelegate:delegate_];
705 [self pushPage:browser];
706 [browser loadRequest:request];
709 return [browser webView];
712 - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {
713 return [self webView:sender createWebViewWithRequest:request windowFeatures:nil];
714 //return [self webView:sender createWebViewWithRequest:request userGesture:YES];
717 - (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
718 if ([frame parentFrame] != nil)
721 title_ = [title retain];
722 [book_ reloadTitleForPage:self];
725 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
726 if ([frame parentFrame] != nil)
731 [self reloadButtons];
738 if (button_ != nil) {
748 if (function_ != nil) {
753 [book_ reloadTitleForPage:self];
755 [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
757 CGRect webrect = [scroller_ bounds];
758 webrect.size.height = 0;
759 [webview_ setFrame:webrect];
762 - (void) _finishLoading {
765 [self reloadButtons];
773 - (void) reloadButtons {
775 [indicator_ startAnimation];
777 [indicator_ stopAnimation];
778 [super reloadButtons];
781 - (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
782 return [webview_ webView:sender shouldScrollToPoint:point forFrame:frame];
785 - (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame {
786 return [webview_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
789 - (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame {
790 return [webview_ webView:sender needsScrollNotifications:notifications forFrame:frame];
793 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
794 return [webview_ webView:sender didCommitLoadForFrame:frame];
797 - (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame {
798 return [webview_ webView:sender didReceiveDocTypeForFrame:frame];
801 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
802 if ([frame parentFrame] == nil) {
803 [self _finishLoading];
805 if (DOMDocument *document = [frame DOMDocument])
806 if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"])
807 for (DOMHTMLBodyElement *body in bodies) {
808 DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
812 if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) {
813 if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
814 DOMRGBColor *rgb([color getRGBColorValue]);
816 float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
817 float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
818 float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
819 float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
823 if (red == 0xc7 && green == 0xce && blue == 0xd5)
824 uic = [UIColor pinStripeColor];
827 colorWithRed:(red / 255)
835 [scroller_ setBackgroundColor:uic];
841 [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
846 return [webview_ webView:sender didFinishLoadForFrame:frame];
849 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
850 if ([frame parentFrame] != nil)
854 [self _finishLoading];
856 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
857 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
858 [[error localizedDescription] stringByAddingPercentEscapes]
864 - (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
866 lprintf("Console:%s\n", [[dictionary description] UTF8String]);
870 - (id) initWithBook:(RVBook *)book forWidth:(float)width {
871 if ((self = [super initWithBook:book]) != nil) {
876 struct CGRect bounds = [self bounds];
878 scroller_ = [[UIScroller alloc] initWithFrame:bounds];
879 [self addSubview:scroller_];
881 [scroller_ setShowBackgroundShadow:NO];
882 [scroller_ setFixedBackgroundPattern:YES];
883 [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
885 [scroller_ setScrollingEnabled:YES];
886 [scroller_ setAdjustForContentSizeChange:YES];
887 [scroller_ setClipsSubviews:YES];
888 [scroller_ setAllowsRubberBanding:YES];
889 [scroller_ setScrollDecelerationFactor:0.99];
890 [scroller_ setDelegate:self];
892 CGRect webrect = [scroller_ bounds];
893 webrect.size.height = 0;
898 webview_ = [Documents_ lastObject];
899 if (webview_ != nil) {
900 webview_ = [webview_ retain];
901 webview = [webview_ webView];
902 [Documents_ removeLastObject];
903 [webview_ setFrame:webrect];
908 webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect];
909 webview = [webview_ webView];
911 // XXX: this is terribly (too?) expensive
912 //[webview_ setDrawsBackground:NO];
913 [webview setPreferencesIdentifier:@"Cydia"];
915 [webview_ setTileSize:CGSizeMake(webrect.size.width, 500)];
917 [webview_ setAllowsMessaging:YES];
919 [webview_ setTilingEnabled:YES];
920 [webview_ setDrawsGrid:NO];
921 [webview_ setLogsTilingChanges:NO];
922 [webview_ setTileMinificationFilter:kCAFilterNearest];
923 [webview_ setDetectsPhoneNumbers:NO];
924 [webview_ setAutoresizes:YES];
926 [webview_ setMinimumScale:0.25f forDocumentTypes:0x10];
927 [webview_ setMaximumScale:5.00f forDocumentTypes:0x10];
928 [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
929 //[webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
931 [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
933 [webview_ setMinimumScale:1.00f forDocumentTypes:0x8];
934 [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
935 [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
937 [webview_ _setDocumentType:0x4];
939 [webview_ setZoomsFocusedFormControl:YES];
940 [webview_ setContentsPosition:7];
941 [webview_ setEnabledGestures:0xa];
942 [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
943 [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
945 [webview_ setSmoothsFonts:YES];
946 [webview_ setAllowsImageSheet:YES];
947 [webview _setUsesLoaderCache:YES];
949 [webview setGroupName:@"CydiaGroup"];
950 [webview _setLayoutInterval:0];
953 [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
955 [webview_ setDelegate:self];
956 [webview_ setGestureDelegate:self];
957 [scroller_ addSubview:webview_];
959 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
961 CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
962 indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
963 [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
965 Package *package([[Database sharedInstance] packageWithName:@"cydia"]);
966 NSString *application = package == nil ? @"Cydia" : [NSString
967 stringWithFormat:@"Cydia/%@",
972 application = [NSString stringWithFormat:@"%@ Version/%@", application, Product_];
974 application = [NSString stringWithFormat:@"%@ Mobile/%@", application, Build_];
976 application = [NSString stringWithFormat:@"%@ Safari/%@", application, Safari_];
978 /* XXX: lookup application directory? */
979 /*if (NSDictionary *safari = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"])
980 if (NSString *version = [safari objectForKey:@"SafariProductVersion"])
981 application = [NSString stringWithFormat:@"Version/%@ %@", version, application];*/
983 [webview setApplicationNameForUserAgent:application];
985 indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
986 cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_];
988 [webview setFrameLoadDelegate:self];
989 [webview setResourceLoadDelegate:indirect_];
990 [webview setUIDelegate:self];
991 [webview setScriptDebugDelegate:self];
992 [webview setPolicyDelegate:self];
994 [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
995 [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
999 - (id) initWithBook:(RVBook *)book {
1000 return [self initWithBook:book forWidth:[[self class] defaultWidth]];
1003 - (void) didFinishGesturesInView:(UIView *)view forEvent:(id)event {
1004 [webview_ redrawScaledDocument];
1007 - (void) _rightButtonClicked {
1008 if (function_ == nil) {
1012 WebView *webview([webview_ webView]);
1013 WebFrame *frame([webview mainFrame]);
1015 id _private(MSHookIvar<id>(webview, "_private"));
1016 WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
1017 WebCore::Settings *settings(page == NULL ? NULL : page->settings());
1020 if (settings == NULL)
1023 no = settings->JavaScriptCanOpenWindowsAutomatically();
1024 settings->setJavaScriptCanOpenWindowsAutomatically(true);
1027 [delegate_ clearFirstResponder];
1028 JSObjectRef function([function_ JSObject]);
1029 JSGlobalContextRef context([frame globalContext]);
1030 JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
1032 if (settings != NULL)
1033 settings->setJavaScriptCanOpenWindowsAutomatically(no);
1037 - (id) _rightButtonTitle {
1038 return button_ != nil ? button_ : @"Reload";
1041 - (id) rightButtonTitle {
1042 return [self _loading] ? @"" : [self _rightButtonTitle];
1045 - (UINavigationButtonStyle) rightButtonStyle {
1046 if (style_ == nil) normal:
1047 return UINavigationButtonStyleNormal;
1048 else if ([style_ isEqualToString:@"Normal"])
1049 return UINavigationButtonStyleNormal;
1050 else if ([style_ isEqualToString:@"Back"])
1051 return UINavigationButtonStyleBack;
1052 else if ([style_ isEqualToString:@"Highlighted"])
1053 return UINavigationButtonStyleHighlighted;
1054 else if ([style_ isEqualToString:@"Destructive"])
1055 return UINavigationButtonStyleDestructive;
1059 - (NSString *) title {
1060 return title_ == nil ? @"Loading" : title_;
1063 - (NSString *) backButtonTitle {
1067 - (void) setPageActive:(BOOL)active {
1069 [indicator_ removeFromSuperview];
1071 [[book_ navigationBar] addSubview:indicator_];
1074 - (void) resetViewAnimated:(BOOL)animated {
1077 - (void) setPushed:(bool)pushed {
1081 + (float) defaultWidth {