X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/dcc55b8bee7dc7def76c6318f6c2df49cc6eff09..7afcea1c7f36f0c4ee9c4d4b53618df39073d851:/UICaboodle/BrowserView.m?ds=inline diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m index 39599b93..0f95a049 100644 --- a/UICaboodle/BrowserView.m +++ b/UICaboodle/BrowserView.m @@ -71,7 +71,9 @@ } + (NSString *) webScriptNameForSelector:(SEL)selector { - if (selector == @selector(getPackageById:)) + if (selector == @selector(close)) + return @"close"; + else if (selector == @selector(getPackageById:)) return @"getPackageById"; else if (selector == @selector(setAutoPopup:)) return @"setAutoPopup"; @@ -79,6 +81,8 @@ return @"setButtonImage"; else if (selector == @selector(setButtonTitle:withStyle:toFunction:)) return @"setButtonTitle"; + else if (selector == @selector(setPopupHook:)) + return @"setPopupHook"; else if (selector == @selector(setViewportWidth:)) return @"setViewportWidth"; else if (selector == @selector(supports:)) @@ -159,6 +163,10 @@ return value; } +- (void) close { + [indirect_ close]; +} + - (void) setAutoPopup:(BOOL)popup { [indirect_ setAutoPopup:popup]; } @@ -171,6 +179,10 @@ [indirect_ setButtonTitle:button withStyle:style toFunction:function]; } +- (void) setPopupHook:(id)function { + [indirect_ setPopupHook:function]; +} + - (void) setViewportWidth:(float)width { [indirect_ setViewportWidth:width]; } @@ -185,7 +197,7 @@ #endif - (void) dealloc { -#if ForSaurik +#if LogBrowser NSLog(@"[BrowserView dealloc]"); #endif @@ -235,6 +247,8 @@ [style_ release]; if (function_ != nil) [function_ release]; + if (closer_ != nil) + [closer_ release]; [scroller_ release]; [indicator_ release]; @@ -306,13 +320,20 @@ } - (void) _fixScroller { + CGRect bounds([webview_ documentBounds]); +#if LogBrowser + NSLog(@"_fs:(%f,%f+%f,%f)", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); +#endif + float extra; if (!editing_) extra = 0; else { UIFormAssistant *assistant([UIFormAssistant sharedFormAssistant]); CGRect peripheral([assistant peripheralFrame]); +#if LogBrowser NSLog(@"per:%f", peripheral.size.height); +#endif extra = peripheral.size.height; } @@ -320,13 +341,21 @@ subrect.size.height -= extra; [scroller_ setScrollerIndicatorSubrect:subrect]; + NSSize visible(NSMakeSize(subrect.size.width, subrect.size.height)); + [webview_ setValue:[NSValue valueWithSize:visible] forGestureAttribute:UIGestureAttributeVisibleSize]; + CGSize size(size_); size.height += extra; [scroller_ setContentSize:size]; + + [scroller_ releaseRubberBandIfNecessary]; } - (void) view:(UIView *)sender didSetFrame:(CGRect)frame { size_ = frame.size; +#if LogBrowser + NSLog(@"dsf:(%f,%f+%f,%f)", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); +#endif [self _fixScroller]; } @@ -348,8 +377,16 @@ [book_ pushPage:self]; } -- (BOOL) getSpecial:(NSURL *)url { -#if ForSaurik +- (void) swapPage:(RVPage *)page { + [page setDelegate:delegate_]; + if (pushed_) + [book_ swapPage:page]; + else + [book_ pushPage:page]; +} + +- (BOOL) getSpecial:(NSURL *)url swap:(BOOL)swap { +#if LogBrowser NSLog(@"getSpecial:%@", url); #endif @@ -368,7 +405,10 @@ return false; if (page != nil) - [self pushPage:page]; + if (swap) + [self swapPage:page]; + else + [self pushPage:page]; return true; } @@ -428,6 +468,12 @@ popup_ = popup; } +- (void) setPopupHook:(id)function { + if (closer_ != nil) + [closer_ autorelease]; + closer_ = function == nil ? nil : [function retain]; +} + - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { if (button_ != nil) [button_ autorelease]; @@ -440,6 +486,8 @@ if (function_ != nil) [function_ autorelease]; function_ = function == nil ? nil : [function retain]; + + [self reloadButtons]; } - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { @@ -454,6 +502,8 @@ if (function_ != nil) [function_ autorelease]; function_ = function == nil ? nil : [function retain]; + + [self reloadButtons]; } - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element { @@ -473,6 +523,10 @@ [book_ close]; } +- (void) close { + [book_ close]; +} + - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { [window setValue:cydia_ forKey:@"cydia"]; } @@ -482,13 +536,13 @@ } - (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id)listener { -#if ForSaurik +#if LogBrowser NSLog(@"nwa:%@", name); #endif if (NSURL *url = [request URL]) { if (name == nil) unknown: { - if (![self getSpecial:url]) { + if (![self getSpecial:url swap:NO]) { NSString *scheme([[url scheme] lowercaseString]); if ([scheme isEqualToString:@"mailto"]) [delegate_ openMailToURL:url]; @@ -498,6 +552,7 @@ [delegate_ openURL:url]; else if ([name isEqualToString:@"_popup"]) { RVBook *book([[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]); + [book setHook:indirect_]; RVPage *page([delegate_ pageForURL:url hasTag:NULL]); if (page == nil) { @@ -522,13 +577,15 @@ [listener use]; } -- (void) webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { +- (void) webView:(WebView *)sender decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { if ([WebView canShowMIMEType:type]) [listener use]; else { // XXX: handle more mime types! [listener ignore]; - if (frame == [webView mainFrame]) + + WebView *webview([webview_ webView]); + if (frame == [webview mainFrame]) [UIApp openURL:[request URL]]; } } @@ -546,17 +603,19 @@ if (request_ != nil) [request_ autorelease]; request_ = [request retain]; -#if ForSaurik +#if LogBrowser NSLog(@"dpn:%@", request_); #endif } [listener use]; - /* XXX: maybe only the main frame? */ - [self _pushPage]; + + WebView *webview([webview_ webView]); + if (frame == [webview mainFrame]) + [self _pushPage]; return; } -#if ForSaurik +#if LogBrowser else NSLog(@"nav:%@:%@", url, [action description]); #endif @@ -573,7 +632,7 @@ int store(_not(int)); if (NSURL *itms = [url itmsURL:&store]) { -#if ForSaurik +#if LogBrowser NSLog(@"itms#%@#%u#%@", url, store, itms); #endif @@ -598,7 +657,7 @@ goto ignore; } - if ([self getSpecial:url]) + if ([self getSpecial:url swap:YES]) goto ignore; else if ([WebView _canHandleRequest:request]) goto use; @@ -721,13 +780,13 @@ - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features { //- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request userGesture:(BOOL)gesture { -#if ForSaurik +#if LogBrowser NSLog(@"cwv:%@ (%@): %@", request, title_, features == nil ? @"{}" : [features description]); //NSLog(@"cwv:%@ (%@): %@", request, title_, gesture ? @"Yes" : @"No"); #endif NSNumber *value([features objectForKey:@"width"]); - float width(value == nil ? [BrowserView defaultWidth] : [value floatValue]); + float width(value == nil ? 0 : [value floatValue]); RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]); @@ -736,6 +795,7 @@ if (features != nil && popup_) { [book setDelegate:delegate_]; + [book setHook:indirect_]; [browser setDelegate:delegate_]; [browser loadRequest:request]; @@ -771,6 +831,8 @@ if ([frame parentFrame] != nil) return; + [webview_ resignFirstResponder]; + reloading_ = false; loading_ = true; [self reloadButtons]; @@ -795,9 +857,15 @@ function_ = nil; } + if (closer_ != nil) { + [closer_ release]; + closer_ = nil; + } + [book_ reloadTitleForPage:self]; [scroller_ scrollPointVisibleAtTopLeft:CGPointZero]; + [scroller_ setZoomScale:1 duration:0]; CGRect webrect = [scroller_ bounds]; webrect.size.height = 0; @@ -811,12 +879,12 @@ } } -- (bool) _loading { +- (bool) isLoading { return loading_; } - (void) reloadButtons { - if ([self _loading]) + if ([self isLoading]) [indicator_ startAnimation]; else [indicator_ stopAnimation]; @@ -836,6 +904,7 @@ } - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame { + [self _pushPage]; return [webview_ webView:sender didCommitLoadForFrame:frame]; } @@ -907,13 +976,13 @@ } - (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary { -#if ForSaurik +#if LogBrowser || ForSaurik lprintf("Console:%s\n", [[dictionary description] UTF8String]); #endif } - (void) setViewportWidth:(float)width { - width_ = width; + width_ = width ? width != 0 : [[self class] defaultWidth]; [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; } @@ -1049,49 +1118,61 @@ } - (id) initWithBook:(RVBook *)book { - return [self initWithBook:book forWidth:[[self class] defaultWidth]]; + return [self initWithBook:book forWidth:0]; } - (void) didFinishGesturesInView:(UIView *)view forEvent:(id)event { [webview_ redrawScaledDocument]; } -- (void) _rightButtonClicked { - if (function_ == nil) { - reloading_ = true; - [self reloadURL]; - } else { - WebView *webview([webview_ webView]); - WebFrame *frame([webview mainFrame]); - - id _private(MSHookIvar(webview, "_private")); - WebCore::Page *page(_private == nil ? NULL : MSHookIvar(_private, "page")); - WebCore::Settings *settings(page == NULL ? NULL : page->settings()); - - bool no; - if (settings == NULL) - no = 0; - else { - no = settings->JavaScriptCanOpenWindowsAutomatically(); - settings->setJavaScriptCanOpenWindowsAutomatically(true); - } +- (void) callFunction:(WebScriptObject *)function { + WebView *webview([webview_ webView]); + WebFrame *frame([webview mainFrame]); - [delegate_ clearFirstResponder]; - JSObjectRef function([function_ JSObject]); - JSGlobalContextRef context([frame globalContext]); - JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); + id _private(MSHookIvar(webview, "_private")); + WebCore::Page *page(_private == nil ? NULL : MSHookIvar(_private, "page")); + WebCore::Settings *settings(page == NULL ? NULL : page->settings()); - if (settings != NULL) - settings->setJavaScriptCanOpenWindowsAutomatically(no); + bool no; + if (settings == NULL) + no = 0; + else { + no = settings->JavaScriptCanOpenWindowsAutomatically(); + settings->setJavaScriptCanOpenWindowsAutomatically(true); } + + [delegate_ clearFirstResponder]; + JSObjectRef object([function JSObject]); + JSGlobalContextRef context([frame globalContext]); + JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL); + + if (settings != NULL) + settings->setJavaScriptCanOpenWindowsAutomatically(no); +} + +- (void) didCloseBook:(RVBook *)book { + if (closer_ != nil) + [self callFunction:closer_]; +} + +- (void) __rightButtonClicked { + reloading_ = true; + [self reloadURL]; +} + +- (void) _rightButtonClicked { + if (function_ == nil) + [self __rightButtonClicked]; + else + [self callFunction:function_]; } - (id) _rightButtonTitle { - return button_ != nil ? button_ : @"Reload"; + return @"Reload"; } - (id) rightButtonTitle { - return [self _loading] ? @"" : [self _rightButtonTitle]; + return [self isLoading] ? @"" : button_ != nil ? button_ : [self _rightButtonTitle]; } - (UINavigationButtonStyle) rightButtonStyle {