X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/7be3eb3270fb2a03788c01abf3a5f270eda54531..2d5f3bfcb480536bdc9ecca29ce50267078d3f73:/CyteKit/WebViewController.mm diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm index d5d4967f..d347a396 100644 --- a/CyteKit/WebViewController.mm +++ b/CyteKit/WebViewController.mm @@ -53,6 +53,14 @@ float CYScrollViewDecelerationRateNormal; - (void) setOfflineWebApplicationCacheEnabled:(BOOL)enabled; @end +@implementation WebFrame (Cydia) + +- (NSString *) description { + return [NSString stringWithFormat:@"<%s: %p, %@>", class_getName([self class]), self, [[[([self provisionalDataSource] ?: [self dataSource]) request] URL] absoluteString]]; +} + +@end + /* Indirect Delegate {{{ */ @interface IndirectDelegate : NSObject { _transient volatile id delegate_; @@ -147,6 +155,10 @@ float CYScrollViewDecelerationRateNormal; [super dealloc]; } +- (NSString *) description { + return [NSString stringWithFormat:@"<%s: %p, %@>", class_getName([self class]), self, [[request_ URL] absoluteString]]; +} + - (CyteWebView *) webView { return (CyteWebView *) [self view]; } @@ -163,9 +175,13 @@ float CYScrollViewDecelerationRateNormal; ]; } -- (void) setURL:(NSURL *)url { +- (void) setRequest:(NSURLRequest *)request { _assert(request_ == nil); - request_ = [self requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy]; + request_ = request; +} + +- (void) setURL:(NSURL *)url { + [self setRequest:[self requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy]]; } - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy { @@ -338,9 +354,7 @@ float CYScrollViewDecelerationRateNormal; return; if ([[error domain] isEqualToString:WebKitErrorDomain] && [error code] == WebKitErrorFrameLoadInterruptedByPolicyChange) { - request_ = stage2_; - stage1_ = nil; - stage2_ = nil; + request_ = nil; return; } @@ -362,7 +376,7 @@ float CYScrollViewDecelerationRateNormal; if (page == nil) { CyteWebViewController *browser([[[class_ alloc] init] autorelease]); - [browser loadRequest:request]; + [browser setRequest:request]; page = browser; } @@ -425,10 +439,8 @@ float CYScrollViewDecelerationRateNormal; - (void) webView:(WebView *)view didDecidePolicy:(CYWebPolicyDecision)decision forNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame { if ([frame parentFrame] == nil) if (decision == CYWebPolicyDecisionUse) - if (!error_) { - stage1_ = request_; + if (!error_) request_ = request; - } } - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id)listener { @@ -456,6 +468,16 @@ float CYScrollViewDecelerationRateNormal; - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { } +- (void) webView:(WebView *)view didCommitLoadForFrame:(WebFrame *)frame { +#if LogBrowser + NSLog(@"didCommitLoadForFrame:%@", frame); +#endif + + if ([frame parentFrame] == nil) { + loaded_ = true; + } +} + - (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { #if LogBrowser NSLog(@"didFailLoadWithError:%@ forFrame:%@", error, frame); @@ -476,9 +498,6 @@ float CYScrollViewDecelerationRateNormal; [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]]; if ([frame parentFrame] == nil) { - stage1_ = nil; - stage2_ = nil; - if (DOMDocument *document = [frame DOMDocument]) if (DOMNodeList *bodies = [document getElementsByTagName:@"body"]) for (DOMHTMLBodyElement *body in (id) bodies) { @@ -539,9 +558,6 @@ float CYScrollViewDecelerationRateNormal; allowsNavigationAction_ = true; - stage2_ = stage1_; - stage1_ = nil; - [self setHidesNavigationBar:NO]; // XXX: do we still need to do this? @@ -577,7 +593,7 @@ float CYScrollViewDecelerationRateNormal; // }}} - (void) close { - [[self navigationController] dismissModalViewControllerAnimated:YES]; + [[[self navigationController] parentViewController] dismissModalViewControllerAnimated:YES]; } - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button { @@ -775,6 +791,10 @@ float CYScrollViewDecelerationRateNormal; } return self; } +- (NSString *) applicationNameForUserAgent { + return nil; +} + - (void) loadView { CGRect bounds([[UIScreen mainScreen] applicationFrame]); @@ -812,6 +832,9 @@ float CYScrollViewDecelerationRateNormal; [preferences setJavaScriptCanOpenWindowsAutomatically:YES]; [preferences setOfflineWebApplicationCacheEnabled:YES]; + if (NSString *agent = [self applicationNameForUserAgent]) + [webview setApplicationNameForUserAgent:agent]; + if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)]) [webview setShouldUpdateWhileOffscreen:NO]; @@ -859,10 +882,13 @@ float CYScrollViewDecelerationRateNormal; [self setViewportWidth:width_]; UITableView *table([[[UITableView alloc] initWithFrame:[webview_ bounds] style:UITableViewStyleGrouped] autorelease]); + [table setScrollsToTop:NO]; [webview_ insertSubview:table atIndex:0]; [table setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)]; + + ready_ = false; } - (void) releaseSubviews {