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(setButtonImage:withStyle:toFunction:))
77 return @"setButtonImage";
78 else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
79 return @"setButtonTitle";
80 else if (selector == @selector(supports:))
82 else if (selector == @selector(du:))
84 else if (selector == @selector(statfs:))
90 + (BOOL) isSelectorExcludedFromWebScript:(SEL)selector {
91 return [self webScriptNameForSelector:selector] == nil;
94 - (BOOL) supports:(NSString *)feature {
95 return [feature isEqualToString:@"window.open"];
98 - (Package *) getPackageById:(NSString *)id {
99 return [[Database sharedInstance] packageWithName:id];
102 - (NSArray *) statfs:(NSString *)path {
105 if (path == nil || statfs([path UTF8String], &stat) == -1)
108 return [NSArray arrayWithObjects:
109 [NSNumber numberWithUnsignedLong:stat.f_bsize],
110 [NSNumber numberWithUnsignedLong:stat.f_blocks],
111 [NSNumber numberWithUnsignedLong:stat.f_bfree],
115 - (NSNumber *) du:(NSString *)path {
116 NSNumber *value(nil);
119 _assert(pipe(fds) != -1);
121 pid_t pid(ExecFork());
123 _assert(dup2(fds[1], 1) != -1);
124 _assert(close(fds[0]) != -1);
125 _assert(close(fds[1]) != -1);
126 execlp("du", "du", "-s", [path UTF8String], NULL);
131 _assert(close(fds[1]) != -1);
133 if (FILE *du = fdopen(fds[0], "r")) {
135 while (fgets(line, sizeof(line), du) != NULL) {
136 size_t length(strlen(line));
137 while (length != 0 && line[length - 1] == '\n')
138 line[--length] = '\0';
139 if (char *tab = strchr(line, '\t')) {
141 value = [NSNumber numberWithUnsignedLong:strtoul(line, NULL, 0)];
146 } else _assert(close(fds[0]));
150 if (waitpid(pid, &status, 0) == -1)
158 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
159 [indirect_ setButtonImage:button withStyle:style toFunction:function];
162 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
163 [indirect_ setButtonTitle:button withStyle:style toFunction:function];
169 @implementation BrowserView
172 #include "Internals.h"
176 if (challenge_ != nil)
177 [challenge_ release];
179 WebView *webview = [webview_ webView];
180 [webview setFrameLoadDelegate:nil];
181 [webview setResourceLoadDelegate:nil];
182 [webview setUIDelegate:nil];
183 [webview setScriptDebugDelegate:nil];
184 [webview setPolicyDelegate:nil];
186 [webview setDownloadDelegate:nil];
188 [webview _setFormDelegate:nil];
189 [webview _setUIKitDelegate:nil];
190 [webview setWebMailDelegate:nil];
191 [webview setEditingDelegate:nil];
193 [webview_ setDelegate:nil];
194 [webview_ setGestureDelegate:nil];
196 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
201 [webview_ removeFromSuperview];
202 [Documents_ addObject:[webview_ autorelease]];
207 [indirect_ setDelegate:nil];
212 [scroller_ setDelegate:nil];
218 if (function_ != nil)
222 [indicator_ release];
230 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
231 [self loadRequest:[NSURLRequest
238 - (void) loadURL:(NSURL *)url {
239 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
242 - (NSMutableURLRequest *) _addHeadersToRequest:(NSURLRequest *)request {
243 NSMutableURLRequest *copy = [request mutableCopy];
245 if (Machine_ != NULL)
246 [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
247 if (UniqueID_ != nil)
248 [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
251 [copy setValue:Role_ forHTTPHeaderField:@"X-Role"];
256 - (void) loadRequest:(NSURLRequest *)request {
259 [webview_ loadRequest:request];
263 NSLog(@"rlu:%@", request_);
267 if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
268 [self loadRequest:request_];
270 UIActionSheet *sheet = [[[UIActionSheet alloc]
271 initWithTitle:@"Are you sure you want to submit this form again?"
272 buttons:[NSArray arrayWithObjects:@"Cancel", @"Submit", nil]
278 [sheet setNumberOfRows:1];
279 [sheet popupAlertAnimated:YES];
283 - (WebView *) webView {
284 return [webview_ webView];
287 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
288 [scroller_ setContentSize:frame.size];
291 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
292 [self view:sender didSetFrame:frame];
295 - (void) pushPage:(RVPage *)page {
296 [self setBackButtonTitle:title_];
297 [page setDelegate:delegate_];
298 [book_ pushPage:page];
301 - (BOOL) getSpecial:(NSURL *)url {
302 NSString *href([url absoluteString]);
303 NSString *scheme([[url scheme] lowercaseString]);
307 if ([href hasPrefix:@"apptapp://package/"])
308 page = [delegate_ pageForPackage:[href substringFromIndex:18]];
309 else if ([scheme isEqualToString:@"cydia"]) {
310 page = [delegate_ pageForURL:url hasTag:NULL];
313 } else if (![scheme isEqualToString:@"apptapp"])
317 [self pushPage:page];
321 - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
322 UIActionSheet *sheet = [[[UIActionSheet alloc]
324 buttons:[NSArray arrayWithObjects:@"OK", nil]
330 [sheet setBodyText:message];
331 [sheet popupAlertAnimated:YES];
334 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
335 UIActionSheet *sheet = [[[UIActionSheet alloc]
337 buttons:[NSArray arrayWithObjects:@"OK", @"Cancel", nil]
343 [sheet setNumberOfRows:1];
344 [sheet setBodyText:message];
345 [sheet popupAlertAnimated:YES];
347 NSRunLoop *loop([NSRunLoop currentRunLoop]);
348 NSDate *future([NSDate distantFuture]);
350 while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
352 NSNumber *confirm([confirm_ autorelease]);
354 return [confirm boolValue];
357 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
359 [button_ autorelease];
360 button_ = button == nil ? nil : [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:button]]] retain];
363 [style_ autorelease];
364 style_ = style == nil ? nil : [style retain];
366 if (function_ != nil)
367 [function_ autorelease];
368 function_ = function == nil ? nil : [function retain];
371 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
373 [button_ autorelease];
374 button_ = button == nil ? nil : [button retain];
377 [style_ autorelease];
378 style_ = style == nil ? nil : [style retain];
380 if (function_ != nil)
381 [function_ autorelease];
382 function_ = function == nil ? nil : [function retain];
385 - (void) webViewClose:(WebView *)sender {
389 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
390 [window setValue:cydia_ forKey:@"cydia"];
393 - (void) webView:(WebView *)sender unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame {
394 NSLog(@"err:%@", error);
397 - (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
398 if (NSURL *url = [request URL]) {
399 if (name == nil) unknown: {
400 NSLog(@"win:%@:%@", url, [action description]);
401 if (![self getSpecial:url]) {
402 NSString *scheme([[url scheme] lowercaseString]);
403 if ([scheme isEqualToString:@"mailto"])
404 [delegate_ openMailToURL:url];
407 } else if ([name isEqualToString:@"_open"])
408 [delegate_ openURL:url];
409 else if ([name isEqualToString:@"_popup"]) {
410 RVBook *book([[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
412 RVPage *page([delegate_ pageForURL:url hasTag:NULL]);
414 BrowserView *browser([[[BrowserView alloc] initWithBook:book] autorelease]);
415 [browser loadURL:url];
419 [book setDelegate:delegate_];
420 [page setDelegate:delegate_];
423 [book_ pushBook:book];
431 - (void) webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
432 if ([WebView canShowMIMEType:type])
435 // XXX: handle more mime types!
437 if (frame == [webView mainFrame])
438 [UIApp openURL:[request URL]];
442 - (void) webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
443 if (request == nil) ignore: {
448 NSURL *url([request URL]);
450 if (url == nil) use: {
451 if (!error_ && [frame parentFrame] == nil) {
453 [request_ autorelease];
454 request_ = [request retain];
456 NSLog(@"dpn:%@", request_);
464 else NSLog(@"nav:%@:%@", url, [action description]);
467 const NSArray *capability(reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability)));
470 [capability containsObject:@"com.apple.Maps"] && [url mapsURL] ||
471 [capability containsObject:@"com.apple.youtube"] && [url youTubeURL]
478 int store(_not(int));
479 if (NSURL *itms = [url itmsURL:&store]) {
480 NSLog(@"itms#%@#%u#%@", url, store, itms);
482 store == 1 && [capability containsObject:@"com.apple.MobileStore"] ||
483 store == 2 && [capability containsObject:@"com.apple.AppStore"]
490 NSString *scheme([[url scheme] lowercaseString]);
492 if ([scheme isEqualToString:@"tel"]) {
497 if ([scheme isEqualToString:@"mailto"]) {
498 [delegate_ openMailToURL:url];
502 if ([self getSpecial:url])
504 else if ([WebView _canHandleRequest:request])
506 else if ([url isSpringboardHandledURL])
512 - (void) webView:(WebView *)sender setStatusText:(NSString *)text {
513 //lprintf("Status:%s\n", [text UTF8String]);
520 [book_ pushPage:self];
523 - (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
524 NSString *context([sheet context]);
526 if ([context isEqualToString:@"alert"])
528 else if ([context isEqualToString:@"confirm"]) {
531 confirm_ = [NSNumber numberWithBool:YES];
535 confirm_ = [NSNumber numberWithBool:NO];
540 } else if ([context isEqualToString:@"challenge"]) {
541 id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
545 NSString *username([[sheet textFieldAtIndex:0] text]);
546 NSString *password([[sheet textFieldAtIndex:1] text]);
548 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
550 [sender useCredential:credential forAuthenticationChallenge:challenge_];
554 [sender cancelAuthenticationChallenge:challenge_];
561 [challenge_ release];
565 } else if ([context isEqualToString:@"submit"]) {
572 [webview_ loadRequest:request_];
583 - (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
584 challenge_ = [challenge retain];
586 NSURLProtectionSpace *space([challenge protectionSpace]);
587 NSString *realm([space realm]);
591 UIActionSheet *sheet = [[[UIActionSheet alloc]
593 buttons:[NSArray arrayWithObjects:@"Login", @"Cancel", nil]
599 [sheet setNumberOfRows:1];
601 [sheet addTextFieldWithValue:@"" label:@"username"];
602 [sheet addTextFieldWithValue:@"" label:@"password"];
604 UITextField *username([sheet textFieldAtIndex:0]); {
605 UITextInputTraits *traits([username textInputTraits]);
606 [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
607 [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
608 [traits setKeyboardType:UIKeyboardTypeASCIICapable];
609 [traits setReturnKeyType:UIReturnKeyNext];
612 UITextField *password([sheet textFieldAtIndex:1]); {
613 UITextInputTraits *traits([password textInputTraits]);
614 [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
615 [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
616 [traits setKeyboardType:UIKeyboardTypeASCIICapable];
617 // XXX: UIReturnKeyDone
618 [traits setReturnKeyType:UIReturnKeyNext];
619 [traits setSecureTextEntry:YES];
622 [sheet popupAlertAnimated:YES];
625 - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
626 NSURL *url = [request URL];
627 if ([self getSpecial:url])
630 return [self _addHeadersToRequest:request];
633 - (WebView *) _createWebViewWithRequest:(NSURLRequest *)request pushed:(BOOL)pushed {
634 [self setBackButtonTitle:title_];
636 BrowserView *browser = [[[BrowserView alloc] initWithBook:book_] autorelease];
637 [browser setDelegate:delegate_];
640 [browser loadRequest:request];
641 [book_ pushPage:browser];
644 return [browser webView];
647 - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {
648 return [self _createWebViewWithRequest:request pushed:(request != nil)];
651 - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features {
652 return [self _createWebViewWithRequest:request pushed:YES];
655 - (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
656 if ([frame parentFrame] != nil)
659 title_ = [title retain];
660 [book_ reloadTitleForPage:self];
663 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
664 if ([frame parentFrame] != nil)
669 [self reloadButtons];
676 if (button_ != nil) {
686 if (function_ != nil) {
691 [book_ reloadTitleForPage:self];
693 [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
695 CGRect webrect = [scroller_ bounds];
696 webrect.size.height = 0;
697 [webview_ setFrame:webrect];
700 - (void) _finishLoading {
703 [self reloadButtons];
711 - (void) reloadButtons {
713 [indicator_ startAnimation];
715 [indicator_ stopAnimation];
716 [super reloadButtons];
719 - (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
720 return [webview_ webView:sender shouldScrollToPoint:point forFrame:frame];
723 - (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame {
724 return [webview_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
727 - (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame {
728 return [webview_ webView:sender needsScrollNotifications:notifications forFrame:frame];
731 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
732 return [webview_ webView:sender didCommitLoadForFrame:frame];
735 - (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame {
736 return [webview_ webView:sender didReceiveDocTypeForFrame:frame];
739 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
740 if ([frame parentFrame] == nil) {
741 [self _finishLoading];
743 if (DOMDocument *document = [frame DOMDocument])
744 if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"])
745 for (DOMHTMLBodyElement *body in bodies) {
746 DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
750 if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) {
751 if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
752 DOMRGBColor *rgb([color getRGBColorValue]);
754 float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
755 float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
756 float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
757 float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
761 if (red == 0xc7 && green == 0xce && blue == 0xd5)
762 uic = [UIColor pinStripeColor];
765 colorWithRed:(red / 255)
773 [scroller_ setBackgroundColor:uic];
779 [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
784 return [webview_ webView:sender didFinishLoadForFrame:frame];
787 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
788 if ([frame parentFrame] != nil)
790 [self _finishLoading];
792 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
793 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
794 [[error localizedDescription] stringByAddingPercentEscapes]
800 - (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
802 lprintf("Console:%s\n", [[dictionary description] UTF8String]);
806 - (id) initWithBook:(RVBook *)book {
807 if ((self = [super initWithBook:book]) != nil) {
810 struct CGRect bounds = [self bounds];
812 scroller_ = [[UIScroller alloc] initWithFrame:bounds];
813 [self addSubview:scroller_];
815 [scroller_ setShowBackgroundShadow:NO];
816 [scroller_ setFixedBackgroundPattern:YES];
817 [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
819 [scroller_ setScrollingEnabled:YES];
820 [scroller_ setAdjustForContentSizeChange:YES];
821 [scroller_ setClipsSubviews:YES];
822 [scroller_ setAllowsRubberBanding:YES];
823 [scroller_ setScrollDecelerationFactor:0.99];
824 [scroller_ setDelegate:self];
826 CGRect webrect = [scroller_ bounds];
827 webrect.size.height = 0;
832 webview_ = [Documents_ lastObject];
833 if (webview_ != nil) {
834 webview_ = [webview_ retain];
835 webview = [webview_ webView];
836 [Documents_ removeLastObject];
837 [webview_ setFrame:webrect];
842 webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect];
843 webview = [webview_ webView];
845 // XXX: this is terribly (too?) expensive
846 //[webview_ setDrawsBackground:NO];
847 [webview setPreferencesIdentifier:@"Cydia"];
849 [webview_ setTileSize:CGSizeMake(webrect.size.width, 500)];
851 [webview_ setAllowsMessaging:YES];
853 [webview_ setTilingEnabled:YES];
854 [webview_ setDrawsGrid:NO];
855 [webview_ setLogsTilingChanges:NO];
856 [webview_ setTileMinificationFilter:kCAFilterNearest];
857 [webview_ setDetectsPhoneNumbers:NO];
858 [webview_ setAutoresizes:YES];
860 [webview_ setMinimumScale:0.25f forDocumentTypes:0x10];
861 [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
862 [webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
864 [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
866 [webview_ setMinimumScale:1.0f forDocumentTypes:0x8];
867 [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
868 [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
870 [webview_ _setDocumentType:0x4];
872 [webview_ setZoomsFocusedFormControl:YES];
873 [webview_ setContentsPosition:7];
874 [webview_ setEnabledGestures:0xa];
875 [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
876 [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
878 [webview_ setSmoothsFonts:YES];
880 [webview _setUsesLoaderCache:YES];
881 [webview setGroupName:@"Cydia"];
882 [webview _setLayoutInterval:0];
885 [webview_ setDelegate:self];
886 [webview_ setGestureDelegate:self];
887 [scroller_ addSubview:webview_];
889 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
891 CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
892 indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
893 [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
895 Package *package([[Database sharedInstance] packageWithName:@"cydia"]);
896 NSString *application = package == nil ? @"Cydia" : [NSString
897 stringWithFormat:@"Cydia/%@",
902 application = [NSString stringWithFormat:@"Mobile/%@ %@", Build_, application];
904 /* XXX: lookup application directory? */
905 /*if (NSDictionary *safari = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"])
906 if (NSString *version = [safari objectForKey:@"SafariProductVersion"])
907 application = [NSString stringWithFormat:@"Version/%@ %@", version, application];*/
909 [webview setApplicationNameForUserAgent:application];
911 indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
912 cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_];
914 [webview setFrameLoadDelegate:self];
915 [webview setResourceLoadDelegate:indirect_];
916 [webview setUIDelegate:self];
917 [webview setScriptDebugDelegate:self];
918 [webview setPolicyDelegate:self];
920 [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
921 [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
925 - (void) didFinishGesturesInView:(UIView *)view forEvent:(id)event {
926 [webview_ redrawScaledDocument];
929 - (void) _rightButtonClicked {
930 if (function_ == nil) {
934 WebView *webview([webview_ webView]);
935 WebFrame *frame([webview mainFrame]);
937 id _private(MSHookIvar<id>(webview, "_private"));
938 WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
939 WebCore::Settings *settings(page == NULL ? NULL : page->settings());
942 if (settings == NULL)
945 no = settings->JavaScriptCanOpenWindowsAutomatically();
946 settings->setJavaScriptCanOpenWindowsAutomatically(true);
949 [delegate_ clearFirstResponder];
950 JSObjectRef function([function_ JSObject]);
951 JSGlobalContextRef context([frame globalContext]);
952 JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
954 if (settings != NULL)
955 settings->setJavaScriptCanOpenWindowsAutomatically(no);
959 - (id) _rightButtonTitle {
960 return button_ != nil ? button_ : @"Reload";
963 - (id) rightButtonTitle {
964 return [self _loading] ? @"" : [self _rightButtonTitle];
967 - (UINavigationButtonStyle) rightButtonStyle {
968 if (style_ == nil) normal:
969 return UINavigationButtonStyleNormal;
970 else if ([style_ isEqualToString:@"Normal"])
971 return UINavigationButtonStyleNormal;
972 else if ([style_ isEqualToString:@"Back"])
973 return UINavigationButtonStyleBack;
974 else if ([style_ isEqualToString:@"Highlighted"])
975 return UINavigationButtonStyleHighlighted;
976 else if ([style_ isEqualToString:@"Destructive"])
977 return UINavigationButtonStyleDestructive;
981 - (NSString *) title {
982 return title_ == nil ? @"Loading" : title_;
985 - (NSString *) backButtonTitle {
989 - (void) setPageActive:(BOOL)active {
991 [indicator_ removeFromSuperview];
993 [[book_ navigationBar] addSubview:indicator_];
996 - (void) resetViewAnimated:(BOOL)animated {
999 - (void) setPushed:(bool)pushed {