diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2008-12-04 07:17:49 +0000 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2010-09-30 07:09:00 +0000 |
commit | 22f8bed9669aee2b33cbc4da49eea3106e91c338 (patch) | |
tree | 6fee9ee08b04bf3d7a3f0997a97d49e8d861f4e7 | |
parent | 03c0f7a9657ad201acfa37b0f94bc080014a4516 (diff) |
Reorganized code and mostly finished ratings indicator.
-rw-r--r-- | Cydia.app/Sections/Widgets.png | bin | 0 -> 9943 bytes | |||
-rw-r--r-- | Cydia.app/loading.html | 15 | ||||
-rw-r--r-- | Cydia.app/menes/indicator-c7ced5-4d4d70.gif | bin | 0 -> 1849 bytes | |||
-rw-r--r-- | Cydia.app/menes/menes.js | 12 | ||||
-rw-r--r-- | Cydia.app/package.html | 1 | ||||
-rw-r--r-- | Cydia.app/package.js | 9 | ||||
-rw-r--r-- | Cydia.mm | 873 | ||||
-rw-r--r-- | UICaboodle/BrowserView.h | 21 | ||||
-rw-r--r-- | UICaboodle/BrowserView.m | 824 | ||||
-rw-r--r-- | UICaboodle/Internals.h | 5 | ||||
-rw-r--r-- | UICaboodle/RVBook.h | 7 | ||||
-rw-r--r-- | UICaboodle/RVBook.mm | 43 | ||||
-rw-r--r-- | UICaboodle/RVPage.h | 4 | ||||
-rw-r--r-- | UICaboodle/RVPage.mm | 6 | ||||
-rw-r--r-- | internals.h | 10 | ||||
-rw-r--r-- | makefile | 2 |
16 files changed, 964 insertions, 868 deletions
diff --git a/Cydia.app/Sections/Widgets.png b/Cydia.app/Sections/Widgets.png Binary files differnew file mode 100644 index 0000000..ca8c1ef --- /dev/null +++ b/Cydia.app/Sections/Widgets.png diff --git a/Cydia.app/loading.html b/Cydia.app/loading.html new file mode 100644 index 0000000..85cc4c5 --- /dev/null +++ b/Cydia.app/loading.html @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-16"?> +<html><head> + <title>Loading</title> + <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"/> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + <link rel="stylesheet" type="text/css" href="menes/style.css"/> + <base target="_blank"/> +</head><body> + <div style="padding: 5px 7px"> + <span style="color: #4d4d70; font-weight: normal; font-size: 16px"/> + <div style="display: inline-block; background-image: url(menes/indicator-c7ced5-4d4d70.gif); width: 16px; height: 16px; margin: 2px 0 -2px 0"></div> + <span style="margin: 0 4px">Loading...</span> + </span> + </div> +</body></html> diff --git a/Cydia.app/menes/indicator-c7ced5-4d4d70.gif b/Cydia.app/menes/indicator-c7ced5-4d4d70.gif Binary files differnew file mode 100644 index 0000000..e41bb96 --- /dev/null +++ b/Cydia.app/menes/indicator-c7ced5-4d4d70.gif diff --git a/Cydia.app/menes/menes.js b/Cydia.app/menes/menes.js index 8148d8d..70c5c47 100644 --- a/Cydia.app/menes/menes.js +++ b/Cydia.app/menes/menes.js @@ -439,9 +439,15 @@ $.xhr = function (url, method, headers, data, events) { events = {}; xhr.onreadystatechange = function () { - if (xhr.readyState == 4) - if (events.complete != null) - events.complete(xhr.responseText); + if (xhr.readyState == 4) { + var status = xhr.status; + var text = xhr.responseText; + if (events.response != null) + events.response(status, text); + if (events.success != null) + if (status == 200) + events.success(text); + } }; xhr.send(data); diff --git a/Cydia.app/package.html b/Cydia.app/package.html index faba915..2b1aca9 100644 --- a/Cydia.app/package.html +++ b/Cydia.app/package.html @@ -164,6 +164,7 @@ frameborder="0" height="0" target="_top" + src="loading.html" ></iframe> </div> </div> diff --git a/Cydia.app/package.js b/Cydia.app/package.js index fc8e218..bab0b2f 100644 --- a/Cydia.app/package.js +++ b/Cydia.app/package.js @@ -49,8 +49,13 @@ $(function () { var rating = package.rating; if (rating == null) $(".rating").remove(); - else - $("#rating").src(rating); + else { + $.xhr(rating, 'GET', {}, null, { + success: function (value) { + document.getElementById("rating").contentWindow.document.write(value); + } + }); + } $("#settings").href("cydia://package-settings/" + idc); @@ -52,26 +52,6 @@ // XXX: remove #import <MessageUI/MailComposeController.h> -#include <WebKit/DOMCSSPrimitiveValue.h> -#include <WebKit/DOMCSSStyleDeclaration.h> -#include <WebKit/DOMDocument.h> -#include <WebKit/DOMHTMLBodyElement.h> -#include <WebKit/DOMNodeList.h> -#include <WebKit/DOMRGBColor.h> - -#include <WebKit/WebFrame.h> -#include <WebKit/WebPolicyDelegate.h> -#include <WebKit/WebPreferences.h> -#include <WebKit/WebScriptObject.h> - -#import <WebKit/WebView.h> -#import <WebKit/WebView-WebPrivate.h> - -#include <WebCore/Page.h> -#include <WebCore/Settings.h> - -#import <JavaScriptCore/JavaScriptCore.h> - #include <sstream> #include <string> @@ -277,7 +257,7 @@ extern NSString * const kCAFilterNearest; #define lprintf(args...) fprintf(stderr, args) -#define ForRelease 1 +#define ForRelease 0 #define ForSaurik (1 && !ForRelease) #define RecycleWebViews 0 #define AlwaysReload (1 && !ForRelease) @@ -617,6 +597,7 @@ static const float KeyboardTime_ = 0.3f; #define SpringBoard_ "/System/Library/LaunchDaemons/com.apple.SpringBoard.plist" #define SandboxTemplate_ "/usr/share/sandbox/SandboxTemplate.sb" +#define NotifyConfig_ "/etc/notify.conf" static CGColor Blue_; static CGColor Blueish_; @@ -2948,6 +2929,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { id delegate_; BOOL running_; SHA1SumValue springlist_; + SHA1SumValue notifyconf_; SHA1SumValue sandplate_; size_t received_; NSTimeInterval last_; @@ -3167,6 +3149,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { Finish_ = 4; } + if (Finish_ < 4) { + FileFd file(NotifyConfig_, FileFd::ReadOnly); + MMap mmap(file, MMap::ReadOnly); + SHA1Summation sha1; + sha1.Add(reinterpret_cast<uint8_t *>(mmap.Data()), mmap.Size()); + if (!(notifyconf_ == sha1.Result())) + Finish_ = 4; + } + if (Finish_ < 3) { FileFd file(SpringBoard_, FileFd::ReadOnly); MMap mmap(file, MMap::ReadOnly); @@ -3268,6 +3259,14 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { } { + FileFd file(NotifyConfig_, FileFd::ReadOnly); + MMap mmap(file, MMap::ReadOnly); + SHA1Summation sha1; + sha1.Add(reinterpret_cast<uint8_t *>(mmap.Data()), mmap.Size()); + notifyconf_ = sha1.Result(); + } + + { FileFd file(SpringBoard_, FileFd::ReadOnly); MMap mmap(file, MMap::ReadOnly); SHA1Summation sha1; @@ -4776,14 +4775,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -@interface WebView (Cydia) -- (void) setScriptDebugDelegate:(id)delegate; -- (void) _setFormDelegate:(id)delegate; -- (void) _setUIKitDelegate:(id)delegate; -- (void) setWebMailDelegate:(id)delegate; -- (void) _setLayoutInterval:(float)interval; -@end - /* Indirect Delegate {{{ */ @interface IndirectDelegate : NSProxy { _transient volatile id delegate_; @@ -4820,822 +4811,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @end /* }}} */ -/* Browser Implementation {{{ */ -@implementation BrowserView - -#if ForSaurik -#include "internals.h" -#endif - -- (void) dealloc { - if (challenge_ != nil) - [challenge_ release]; - - WebView *webview = [webview_ webView]; - [webview setFrameLoadDelegate:nil]; - [webview setResourceLoadDelegate:nil]; - [webview setUIDelegate:nil]; - [webview setScriptDebugDelegate:nil]; - [webview setPolicyDelegate:nil]; - - [webview setDownloadDelegate:nil]; - - [webview _setFormDelegate:nil]; - [webview _setUIKitDelegate:nil]; - [webview setWebMailDelegate:nil]; - [webview setEditingDelegate:nil]; - - [webview_ setDelegate:nil]; - [webview_ setGestureDelegate:nil]; - - //NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; - - [webview close]; - -#if RecycleWebViews - [webview_ removeFromSuperview]; - [Documents_ addObject:[webview_ autorelease]]; -#else - [webview_ release]; -#endif - - [indirect_ setDelegate:nil]; - [indirect_ release]; - - [scroller_ setDelegate:nil]; - - if (button_ != nil) - [button_ release]; - if (style_ != nil) - [style_ release]; - if (function_ != nil) - [function_ release]; - - [scroller_ release]; - [indicator_ release]; - if (confirm_ != nil) - [confirm_ release]; - if (title_ != nil) - [title_ release]; - [super dealloc]; -} - -- (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy { - [self loadRequest:[NSURLRequest - requestWithURL:url - cachePolicy:policy - timeoutInterval:30.0 - ]]; -} - -- (void) loadURL:(NSURL *)url { - [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy]; -} - -- (NSMutableURLRequest *) _addHeadersToRequest:(NSURLRequest *)request { - NSMutableURLRequest *copy = [request mutableCopy]; - - if (Machine_ != NULL) - [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"]; - if (UniqueID_ != nil) - [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"]; - - if (Role_ != nil) - [copy setValue:Role_ forHTTPHeaderField:@"X-Role"]; - - return copy; -} - -- (void) loadRequest:(NSURLRequest *)request { - pushed_ = true; - [webview_ loadRequest:request]; -} - -- (void) reloadURL { - NSLog(@"rlu:%@", request_); - if (request_ == nil) - return; - - if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil) - [webview_ loadRequest:request_]; - else { - UIActionSheet *sheet = [[[UIActionSheet alloc] - initWithTitle:@"Are you sure you want to submit this form again?" - buttons:[NSArray arrayWithObjects:@"Cancel", @"Submit", nil] - defaultButtonIndex:0 - delegate:self - context:@"submit" - ] autorelease]; - - [sheet setNumberOfRows:1]; - [sheet popupAlertAnimated:YES]; - } -} - -- (WebView *) webView { - return [webview_ webView]; -} - -- (void) view:(UIView *)sender didSetFrame:(CGRect)frame { - [scroller_ setContentSize:frame.size]; -} - -- (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old { - [self view:sender didSetFrame:frame]; -} - -- (void) pushPage:(RVPage *)page { - [self setBackButtonTitle:title_]; - [page setDelegate:delegate_]; - [book_ pushPage:page]; -} - -- (BOOL) getSpecial:(NSURL *)url { - NSString *href([url absoluteString]); - NSString *scheme([[url scheme] lowercaseString]); - - RVPage *page = nil; - - if ([href hasPrefix:@"apptapp://package/"]) - page = [delegate_ pageForPackage:[href substringFromIndex:18]]; - else if ([scheme isEqualToString:@"cydia"]) { - page = [delegate_ pageForURL:url hasTag:NULL]; - if (page == nil) - return false; - } else if (![scheme isEqualToString:@"apptapp"]) - return false; - - if (page != nil) - [self pushPage:page]; - return true; -} - -- (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { - UIActionSheet *sheet = [[[UIActionSheet alloc] - initWithTitle:nil - buttons:[NSArray arrayWithObjects:@"OK", nil] - defaultButtonIndex:0 - delegate:self - context:@"alert" - ] autorelease]; - - [sheet setBodyText:message]; - [sheet popupAlertAnimated:YES]; -} - -- (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { - UIActionSheet *sheet = [[[UIActionSheet alloc] - initWithTitle:nil - buttons:[NSArray arrayWithObjects:@"OK", @"Cancel", nil] - defaultButtonIndex:0 - delegate:self - context:@"confirm" - ] autorelease]; - - [sheet setNumberOfRows:1]; - [sheet setBodyText:message]; - [sheet popupAlertAnimated:YES]; - - NSRunLoop *loop([NSRunLoop currentRunLoop]); - NSDate *future([NSDate distantFuture]); - - while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]); - - NSNumber *confirm([confirm_ autorelease]); - confirm_ = nil; - return [confirm boolValue]; -} - -/* Web Scripting {{{ */ -+ (NSString *) webScriptNameForSelector:(SEL)selector { - if (selector == @selector(getPackageById:)) - return @"getPackageById"; - else if (selector == @selector(setButtonImage:withStyle:toFunction:)) - return @"setButtonImage"; - else if (selector == @selector(setButtonTitle:withStyle:toFunction:)) - return @"setButtonTitle"; - else if (selector == @selector(supports:)) - return @"supports"; - else - return nil; -} - -+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector { - return [self webScriptNameForSelector:selector] == nil; -} - -- (BOOL) supports:(NSString *)feature { - return [feature isEqualToString:@"window.open"]; -} - -- (Package *) getPackageById:(NSString *)id { - return [[Database sharedInstance] packageWithName:id]; -} - -- (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { - if (button_ != nil) - [button_ autorelease]; - button_ = button == nil ? nil : [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:button]]] retain]; - - if (style_ != nil) - [style_ autorelease]; - style_ = style == nil ? nil : [style retain]; - - if (function_ != nil) - [function_ autorelease]; - function_ = function == nil ? nil : [function retain]; -} - -- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { - if (button_ != nil) - [button_ autorelease]; - button_ = button == nil ? nil : [button retain]; - - if (style_ != nil) - [style_ autorelease]; - style_ = style == nil ? nil : [style retain]; - - if (function_ != nil) - [function_ autorelease]; - function_ = function == nil ? nil : [function retain]; -} -/* }}} */ - -- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { - [window setValue:self forKey:@"cydia"]; -} - -- (void) webView:(WebView *)sender unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame { - NSLog(@"err:%@", error); -} - -- (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener { - if (NSURL *url = [request URL]) { - if (name != nil && [name isEqualToString:@"_open"]) - [delegate_ openURL:url]; - - NSLog(@"win:%@:%@", url, [action description]); - if (![self getSpecial:url]) { - NSString *scheme([[url scheme] lowercaseString]); - if ([scheme isEqualToString:@"mailto"]) - [delegate_ openMailToURL:url]; - else goto use; - } - - [listener ignore]; - } else use: - [listener use]; -} - -- (void) webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { - if ([WebView canShowMIMEType:type]) - [listener use]; - else { - // XXX: handle more mime types! - [listener ignore]; - if (frame == [webView mainFrame]) - [UIApp openURL:[request URL]]; - } -} - -- (void) webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { - if (request == nil) ignore: { - [listener ignore]; - return; - } - - NSURL *url([request URL]); - - if (url == nil) use: { - if ([frame parentFrame] == nil) { - if (request_ != nil) - [request_ autorelease]; - request_ = [request retain]; - NSLog(@"dpn:%@", request_); - } - - [listener use]; - return; - } -#if ForSaurik - else NSLog(@"nav:%@:%@", url, [action description]); -#endif - - const NSArray *capability(reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability))); - - if ( - [capability containsObject:@"com.apple.Maps"] && [url mapsURL] || - [capability containsObject:@"com.apple.youtube"] && [url youTubeURL] - ) { - open: - [UIApp openURL:url]; - goto ignore; - } - - int store(_not(int)); - if (NSURL *itms = [url itmsURL:&store]) { - NSLog(@"itms#%@#%u#%@", url, store, itms); - if ( - store == 1 && [capability containsObject:@"com.apple.MobileStore"] || - store == 2 && [capability containsObject:@"com.apple.AppStore"] - ) { - url = itms; - goto open; - } - } - - NSString *scheme([[url scheme] lowercaseString]); - - if ([scheme isEqualToString:@"tel"]) { - // XXX: intelligence - goto open; - } - - if ([scheme isEqualToString:@"mailto"]) { - [delegate_ openMailToURL:url]; - goto ignore; - } - - if ([self getSpecial:url]) - goto ignore; - else if ([WebView _canHandleRequest:request]) - goto use; - else if ([url isSpringboardHandledURL]) - goto open; - else - goto use; -} - -- (void) webView:(WebView *)sender setStatusText:(NSString *)text { - //lprintf("Status:%s\n", [text UTF8String]); -} - -- (void) _pushPage { - if (pushed_) - return; - pushed_ = true; - [book_ pushPage:self]; -} - -- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button { - NSString *context([sheet context]); - - if ([context isEqualToString:@"alert"]) - [sheet dismiss]; - else if ([context isEqualToString:@"confirm"]) { - switch (button) { - case 1: - confirm_ = [NSNumber numberWithBool:YES]; - break; - - case 2: - confirm_ = [NSNumber numberWithBool:NO]; - break; - } - - [sheet dismiss]; - } else if ([context isEqualToString:@"challenge"]) { - id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]); - - switch (button) { - case 1: { - NSString *username([[sheet textFieldAtIndex:0] text]); - NSString *password([[sheet textFieldAtIndex:1] text]); - - NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]); - - [sender useCredential:credential forAuthenticationChallenge:challenge_]; - } break; - - case 2: - [sender cancelAuthenticationChallenge:challenge_]; - break; - - default: - _assert(false); - } - - [challenge_ release]; - challenge_ = nil; - - [sheet dismiss]; - } else if ([context isEqualToString:@"submit"]) { - switch (button) { - case 1: - break; - - case 2: - if (request_ != nil) - [webview_ loadRequest:request_]; - break; - - default: - _assert(false); - } - - [sheet dismiss]; - } -} - -- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source { - challenge_ = [challenge retain]; - - NSURLProtectionSpace *space([challenge protectionSpace]); - NSString *realm([space realm]); - if (realm == nil) - realm = @""; - - UIActionSheet *sheet = [[[UIActionSheet alloc] - initWithTitle:realm - buttons:[NSArray arrayWithObjects:@"Login", @"Cancel", nil] - defaultButtonIndex:0 - delegate:self - context:@"challenge" - ] autorelease]; - - [sheet setNumberOfRows:1]; - - [sheet addTextFieldWithValue:@"" label:@"username"]; - [sheet addTextFieldWithValue:@"" label:@"password"]; - - UITextField *username([sheet textFieldAtIndex:0]); { - UITextInputTraits *traits([username textInputTraits]); - [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; - [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; - [traits setKeyboardType:UIKeyboardTypeASCIICapable]; - [traits setReturnKeyType:UIReturnKeyNext]; - } - - UITextField *password([sheet textFieldAtIndex:1]); { - UITextInputTraits *traits([password textInputTraits]); - [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; - [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; - [traits setKeyboardType:UIKeyboardTypeASCIICapable]; - // XXX: UIReturnKeyDone - [traits setReturnKeyType:UIReturnKeyNext]; - [traits setSecureTextEntry:YES]; - } - - [sheet popupAlertAnimated:YES]; -} - -- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source { - NSURL *url = [request URL]; - if ([self getSpecial:url]) - return nil; - [self _pushPage]; - return [self _addHeadersToRequest:request]; -} - -- (WebView *) _createWebViewWithRequest:(NSURLRequest *)request pushed:(BOOL)pushed { - [self setBackButtonTitle:title_]; - - BrowserView *browser = [[[BrowserView alloc] initWithBook:book_] autorelease]; - [browser setDelegate:delegate_]; - - if (pushed) { - [browser loadRequest:request]; - [book_ pushPage:browser]; - } - - return [browser webView]; -} - -- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request { - return [self _createWebViewWithRequest:request pushed:(request != nil)]; -} - -- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features { - return [self _createWebViewWithRequest:request pushed:YES]; -} - -- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { - if ([frame parentFrame] != nil) - return; - - title_ = [title retain]; - [book_ reloadTitleForPage:self]; -} - -- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { - if ([frame parentFrame] != nil) - return; - - reloading_ = false; - loading_ = true; - [self reloadButtons]; - - if (title_ != nil) { - [title_ release]; - title_ = nil; - } - - if (button_ != nil) { - [button_ release]; - button_ = nil; - } - - if (style_ != nil) { - [style_ release]; - style_ = nil; - } - - if (function_ != nil) { - [function_ release]; - function_ = nil; - } - - [book_ reloadTitleForPage:self]; - - [scroller_ scrollPointVisibleAtTopLeft:CGPointZero]; - - CGRect webrect = [scroller_ bounds]; - webrect.size.height = 0; - [webview_ setFrame:webrect]; -} - -- (void) _finishLoading { - if (!reloading_) { - loading_ = false; - [self reloadButtons]; - } -} - -- (bool) _loading { - return loading_; -} - -- (void) reloadButtons { - if ([self _loading]) - [indicator_ startAnimation]; - else - [indicator_ stopAnimation]; - [super reloadButtons]; -} - -- (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame { - return [webview_ webView:sender shouldScrollToPoint:point forFrame:frame]; -} - -- (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame { - return [webview_ webView:sender didReceiveViewportArguments:arguments forFrame:frame]; -} - -- (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame { - return [webview_ webView:sender needsScrollNotifications:notifications forFrame:frame]; -} - -- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame { - return [webview_ webView:sender didCommitLoadForFrame:frame]; -} - -- (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame { - return [webview_ webView:sender didReceiveDocTypeForFrame:frame]; -} - -- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { - if ([frame parentFrame] == nil) { - [self _finishLoading]; - if (DOMDocument *document = [frame DOMDocument]) - if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"]) - for (DOMHTMLBodyElement *body in bodies) { - DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]); - - bool colored(false); - - if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) { - DOMRGBColor *rgb([color getRGBColorValue]); - - float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]); - NSLog(@"alpha:%g", alpha); - - if (alpha != 0) { - colored = true; - - [scroller_ setBackgroundColor:[UIColor - colorWithRed:([[rgb red] getFloatValue:DOM_CSS_NUMBER] / 255) - green:([[rgb green] getFloatValue:DOM_CSS_NUMBER] / 255) - blue:([[rgb blue] getFloatValue:DOM_CSS_NUMBER] / 255) - alpha:alpha - ]]; - } - } - - if (!colored) - [scroller_ setBackgroundColor:[UIColor pinStripeColor]]; - break; - } - } - - return [webview_ webView:sender didFinishLoadForFrame:frame]; -} - -- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { - if ([frame parentFrame] != nil) - return; - [self _finishLoading]; - - [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", - [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString], - [[error localizedDescription] stringByAddingPercentEscapes] - ]]]; -} - -- (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary { -#if ForSaurik - lprintf("Console:%s\n", [[dictionary description] UTF8String]); -#endif -} - -- (id) initWithBook:(RVBook *)book { - if ((self = [super initWithBook:book]) != nil) { - loading_ = false; - - struct CGRect bounds = [self bounds]; - - scroller_ = [[UIScroller alloc] initWithFrame:bounds]; - [self addSubview:scroller_]; - - [scroller_ setShowBackgroundShadow:NO]; - [scroller_ setFixedBackgroundPattern:YES]; - [scroller_ setBackgroundColor:[UIColor pinStripeColor]]; - - [scroller_ setScrollingEnabled:YES]; - [scroller_ setAdjustForContentSizeChange:YES]; - [scroller_ setClipsSubviews:YES]; - [scroller_ setAllowsRubberBanding:YES]; - [scroller_ setScrollDecelerationFactor:0.99]; - [scroller_ setDelegate:self]; - - CGRect webrect = [scroller_ bounds]; - webrect.size.height = 0; - - WebView *webview; - -#if RecycleWebViews - webview_ = [Documents_ lastObject]; - if (webview_ != nil) { - webview_ = [webview_ retain]; - webview = [webview_ webView]; - [Documents_ removeLastObject]; - [webview_ setFrame:webrect]; - } else { -#else - if (true) { -#endif - webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect]; - webview = [webview_ webView]; - - // XXX: this is terribly (too?) expensive - //[webview_ setDrawsBackground:NO]; - [webview setPreferencesIdentifier:@"Cydia"]; - - [webview_ setTileSize:CGSizeMake(webrect.size.width, 500)]; - - [webview_ setAllowsMessaging:YES]; - - [webview_ setTilingEnabled:YES]; - [webview_ setDrawsGrid:NO]; - [webview_ setLogsTilingChanges:NO]; - [webview_ setTileMinificationFilter:kCAFilterNearest]; - [webview_ setDetectsPhoneNumbers:NO]; - [webview_ setAutoresizes:YES]; - - [webview_ setMinimumScale:0.25f forDocumentTypes:0x10]; - [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10]; - [webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; - - [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2]; - - [webview_ setMinimumScale:1.0f forDocumentTypes:0x8]; - [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8]; - [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8]; - - [webview_ _setDocumentType:0x4]; - - [webview_ setZoomsFocusedFormControl:YES]; - [webview_ setContentsPosition:7]; - [webview_ setEnabledGestures:0xa]; - [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled]; - [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller]; - - [webview_ setSmoothsFonts:YES]; - - [webview _setUsesLoaderCache:YES]; - [webview setGroupName:@"Cydia"]; - [webview _setLayoutInterval:0]; - } - - [webview_ setDelegate:self]; - [webview_ setGestureDelegate:self]; - [scroller_ addSubview:webview_]; - - //NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; - - CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]; - indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)]; - [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite]; - - Package *package([[Database sharedInstance] packageWithName:@"cydia"]); - NSString *application = package == nil ? @"Cydia" : [NSString - stringWithFormat:@"Cydia/%@", - [package installed] - ]; [webview setApplicationNameForUserAgent:application]; - - indirect_ = [[IndirectDelegate alloc] initWithDelegate:self]; - - [webview setFrameLoadDelegate:self]; - [webview setResourceLoadDelegate:indirect_]; - [webview setUIDelegate:self]; - [webview setScriptDebugDelegate:self]; - [webview setPolicyDelegate:self]; - - [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; - [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; - } return self; -} - -- (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<id>(webview, "_private")); - WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page")); - WebCore::Settings *settings(page == NULL ? NULL : page->settings()); - - bool no; - if (settings == NULL) - no = 0; - else { - no = settings->JavaScriptCanOpenWindowsAutomatically(); - settings->setJavaScriptCanOpenWindowsAutomatically(true); - } - - [delegate_ clearFirstResponder]; - JSObjectRef function([function_ JSObject]); - JSGlobalContextRef context([frame globalContext]); - JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); - - if (settings != NULL) - settings->setJavaScriptCanOpenWindowsAutomatically(no); - } -} - -- (id) _rightButtonTitle { - return button_ != nil ? button_ : @"Reload"; -} - -- (id) rightButtonTitle { - return [self _loading] ? @"" : [self _rightButtonTitle]; -} - -- (UINavigationButtonStyle) rightButtonStyle { - if (style_ == nil) normal: - return UINavigationButtonStyleNormal; - else if ([style_ isEqualToString:@"Normal"]) - return UINavigationButtonStyleNormal; - else if ([style_ isEqualToString:@"Back"]) - return UINavigationButtonStyleBack; - else if ([style_ isEqualToString:@"Highlighted"]) - return UINavigationButtonStyleHighlighted; - else if ([style_ isEqualToString:@"Destructive"]) - return UINavigationButtonStyleDestructive; - else goto normal; -} - -- (NSString *) title { - return title_ == nil ? @"Loading" : title_; -} - -- (NSString *) backButtonTitle { - return @"Browser"; -} - -- (void) setPageActive:(BOOL)active { - if (!active) - [indicator_ removeFromSuperview]; - else - [[book_ navigationBar] addSubview:indicator_]; -} - -- (void) resetViewAnimated:(BOOL)animated { -} - -- (void) setPushed:(bool)pushed { - pushed_ = pushed; -} - -@end -/* }}} */ +#include <BrowserView.m> /* Cydia Book {{{ */ @interface CYBook : RVBook < @@ -7810,8 +6987,12 @@ int main(int argc, char *argv[]) { _pooled /*AddPreferences(@"/Applications/Preferences.app/Settings-iPhone.plist"); AddPreferences(@"/Applications/Preferences.app/Settings-iPod.plist");*/ - if ((Indices_ = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/indices.plist"]) == NULL) - Indices_ = [[NSMutableDictionary alloc] init]; + /*if ((Indices_ = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/indices.plist"]) == NULL) + Indices_ = [[NSMutableDictionary alloc] init];*/ + + Indices_ = [NSMutableDictionary dictionaryWithObjectsAndKeys: + @"http://"/*"cache.saurik.com/"*/"cydia.saurik.com/server/rating/@P", @"Rating", + nil]; if ((Metadata_ = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"]) == NULL) Metadata_ = [[NSMutableDictionary alloc] initWithCapacity:2]; diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index 88434a0..3dcdb93 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -1,5 +1,26 @@ #import "ResetView.h" + +#include <WebKit/DOMCSSPrimitiveValue.h> +#include <WebKit/DOMCSSStyleDeclaration.h> +#include <WebKit/DOMDocument.h> +#include <WebKit/DOMHTMLBodyElement.h> +#include <WebKit/DOMNodeList.h> +#include <WebKit/DOMRGBColor.h> + +#include <WebKit/WebFrame.h> +#include <WebKit/WebPolicyDelegate.h> +#include <WebKit/WebPreferences.h> +#include <WebKit/WebScriptObject.h> + +#import <WebKit/WebView.h> +#import <WebKit/WebView-WebPrivate.h> + +#include <WebCore/Page.h> +#include <WebCore/Settings.h> + +#import <JavaScriptCore/JavaScriptCore.h> + @class NSMutableArray; @class NSString; @class NSURL; diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m new file mode 100644 index 0000000..edaa2f2 --- /dev/null +++ b/UICaboodle/BrowserView.m @@ -0,0 +1,824 @@ +#include <BrowserView.h> + +@interface WebView (Cydia) +- (void) setScriptDebugDelegate:(id)delegate; +- (void) _setFormDelegate:(id)delegate; +- (void) _setUIKitDelegate:(id)delegate; +- (void) setWebMailDelegate:(id)delegate; +- (void) _setLayoutInterval:(float)interval; +@end + +@implementation BrowserView + +#if ForSaurik +#include "Internals.h" +#endif + +- (void) dealloc { + if (challenge_ != nil) + [challenge_ release]; + + WebView *webview = [webview_ webView]; + [webview setFrameLoadDelegate:nil]; + [webview setResourceLoadDelegate:nil]; + [webview setUIDelegate:nil]; + [webview setScriptDebugDelegate:nil]; + [webview setPolicyDelegate:nil]; + + [webview setDownloadDelegate:nil]; + + [webview _setFormDelegate:nil]; + [webview _setUIKitDelegate:nil]; + [webview setWebMailDelegate:nil]; + [webview setEditingDelegate:nil]; + + [webview_ setDelegate:nil]; + [webview_ setGestureDelegate:nil]; + + //NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + + [webview close]; + +#if RecycleWebViews + [webview_ removeFromSuperview]; + [Documents_ addObject:[webview_ autorelease]]; +#else + [webview_ release]; +#endif + + [indirect_ setDelegate:nil]; + [indirect_ release]; + + [scroller_ setDelegate:nil]; + + if (button_ != nil) + [button_ release]; + if (style_ != nil) + [style_ release]; + if (function_ != nil) + [function_ release]; + + [scroller_ release]; + [indicator_ release]; + if (confirm_ != nil) + [confirm_ release]; + if (title_ != nil) + [title_ release]; + [super dealloc]; +} + +- (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy { + [self loadRequest:[NSURLRequest + requestWithURL:url + cachePolicy:policy + timeoutInterval:30.0 + ]]; +} + +- (void) loadURL:(NSURL *)url { + [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy]; +} + +- (NSMutableURLRequest *) _addHeadersToRequest:(NSURLRequest *)request { + NSMutableURLRequest *copy = [request mutableCopy]; + + if (Machine_ != NULL) + [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"]; + if (UniqueID_ != nil) + [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"]; + + if (Role_ != nil) + [copy setValue:Role_ forHTTPHeaderField:@"X-Role"]; + + return copy; +} + +- (void) loadRequest:(NSURLRequest *)request { + pushed_ = true; + [webview_ loadRequest:request]; +} + +- (void) reloadURL { + NSLog(@"rlu:%@", request_); + if (request_ == nil) + return; + + if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil) + [webview_ loadRequest:request_]; + else { + UIActionSheet *sheet = [[[UIActionSheet alloc] + initWithTitle:@"Are you sure you want to submit this form again?" + buttons:[NSArray arrayWithObjects:@"Cancel", @"Submit", nil] + defaultButtonIndex:0 + delegate:self + context:@"submit" + ] autorelease]; + + [sheet setNumberOfRows:1]; + [sheet popupAlertAnimated:YES]; + } +} + +- (WebView *) webView { + return [webview_ webView]; +} + +- (void) view:(UIView *)sender didSetFrame:(CGRect)frame { + [scroller_ setContentSize:frame.size]; +} + +- (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old { + [self view:sender didSetFrame:frame]; +} + +- (void) pushPage:(RVPage *)page { + [self setBackButtonTitle:title_]; + [page setDelegate:delegate_]; + [book_ pushPage:page]; +} + +- (BOOL) getSpecial:(NSURL *)url { + NSString *href([url absoluteString]); + NSString *scheme([[url scheme] lowercaseString]); + + RVPage *page = nil; + + if ([href hasPrefix:@"apptapp://package/"]) + page = [delegate_ pageForPackage:[href substringFromIndex:18]]; + else if ([scheme isEqualToString:@"cydia"]) { + page = [delegate_ pageForURL:url hasTag:NULL]; + if (page == nil) + return false; + } else if (![scheme isEqualToString:@"apptapp"]) + return false; + + if (page != nil) + [self pushPage:page]; + return true; +} + +- (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { + UIActionSheet *sheet = [[[UIActionSheet alloc] + initWithTitle:nil + buttons:[NSArray arrayWithObjects:@"OK", nil] + defaultButtonIndex:0 + delegate:self + context:@"alert" + ] autorelease]; + + [sheet setBodyText:message]; + [sheet popupAlertAnimated:YES]; +} + +- (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { + UIActionSheet *sheet = [[[UIActionSheet alloc] + initWithTitle:nil + buttons:[NSArray arrayWithObjects:@"OK", @"Cancel", nil] + defaultButtonIndex:0 + delegate:self + context:@"confirm" + ] autorelease]; + + [sheet setNumberOfRows:1]; + [sheet setBodyText:message]; + [sheet popupAlertAnimated:YES]; + + NSRunLoop *loop([NSRunLoop currentRunLoop]); + NSDate *future([NSDate distantFuture]); + + while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]); + + NSNumber *confirm([confirm_ autorelease]); + confirm_ = nil; + return [confirm boolValue]; +} + +/* Web Scripting {{{ */ ++ (NSString *) webScriptNameForSelector:(SEL)selector { + if (selector == @selector(getPackageById:)) + return @"getPackageById"; + else if (selector == @selector(setButtonImage:withStyle:toFunction:)) + return @"setButtonImage"; + else if (selector == @selector(setButtonTitle:withStyle:toFunction:)) + return @"setButtonTitle"; + else if (selector == @selector(supports:)) + return @"supports"; + else + return nil; +} + ++ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector { + return [self webScriptNameForSelector:selector] == nil; +} + +- (BOOL) supports:(NSString *)feature { + return [feature isEqualToString:@"window.open"]; +} + +- (Package *) getPackageById:(NSString *)id { + return [[Database sharedInstance] packageWithName:id]; +} + +- (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { + if (button_ != nil) + [button_ autorelease]; + button_ = button == nil ? nil : [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:button]]] retain]; + + if (style_ != nil) + [style_ autorelease]; + style_ = style == nil ? nil : [style retain]; + + if (function_ != nil) + [function_ autorelease]; + function_ = function == nil ? nil : [function retain]; +} + +- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function { + if (button_ != nil) + [button_ autorelease]; + button_ = button == nil ? nil : [button retain]; + + if (style_ != nil) + [style_ autorelease]; + style_ = style == nil ? nil : [style retain]; + + if (function_ != nil) + [function_ autorelease]; + function_ = function == nil ? nil : [function retain]; +} +/* }}} */ + +- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { + [window setValue:self forKey:@"cydia"]; +} + +- (void) webView:(WebView *)sender unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame { + NSLog(@"err:%@", error); +} + +- (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener { + if (NSURL *url = [request URL]) { + if (name != nil && [name isEqualToString:@"_open"]) + [delegate_ openURL:url]; + + NSLog(@"win:%@:%@", url, [action description]); + if (![self getSpecial:url]) { + NSString *scheme([[url scheme] lowercaseString]); + if ([scheme isEqualToString:@"mailto"]) + [delegate_ openMailToURL:url]; + else goto use; + } + + [listener ignore]; + } else use: + [listener use]; +} + +- (void) webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { + if ([WebView canShowMIMEType:type]) + [listener use]; + else { + // XXX: handle more mime types! + [listener ignore]; + if (frame == [webView mainFrame]) + [UIApp openURL:[request URL]]; + } +} + +- (void) webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { + if (request == nil) ignore: { + [listener ignore]; + return; + } + + NSURL *url([request URL]); + + if (url == nil) use: { + if ([frame parentFrame] == nil) { + if (request_ != nil) + [request_ autorelease]; + request_ = [request retain]; + NSLog(@"dpn:%@", request_); + } + + [listener use]; + return; + } +#if ForSaurik + else NSLog(@"nav:%@:%@", url, [action description]); +#endif + + const NSArray *capability(reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability))); + + if ( + [capability containsObject:@"com.apple.Maps"] && [url mapsURL] || + [capability containsObject:@"com.apple.youtube"] && [url youTubeURL] + ) { + open: + [UIApp openURL:url]; + goto ignore; + } + + int store(_not(int)); + if (NSURL *itms = [url itmsURL:&store]) { + NSLog(@"itms#%@#%u#%@", url, store, itms); + if ( + store == 1 && [capability containsObject:@"com.apple.MobileStore"] || + store == 2 && [capability containsObject:@"com.apple.AppStore"] + ) { + url = itms; + goto open; + } + } + + NSString *scheme([[url scheme] lowercaseString]); + + if ([scheme isEqualToString:@"tel"]) { + // XXX: intelligence + goto open; + } + + if ([scheme isEqualToString:@"mailto"]) { + [delegate_ openMailToURL:url]; + goto ignore; + } + + if ([self getSpecial:url]) + goto ignore; + else if ([WebView _canHandleRequest:request]) + goto use; + else if ([url isSpringboardHandledURL]) + goto open; + else + goto use; +} + +- (void) webView:(WebView *)sender setStatusText:(NSString *)text { + //lprintf("Status:%s\n", [text UTF8String]); +} + +- (void) _pushPage { + if (pushed_) + return; + pushed_ = true; + [book_ pushPage:self]; +} + +- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button { + NSString *context([sheet context]); + + if ([context isEqualToString:@"alert"]) + [sheet dismiss]; + else if ([context isEqualToString:@"confirm"]) { + switch (button) { + case 1: + confirm_ = [NSNumber numberWithBool:YES]; + break; + + case 2: + confirm_ = [NSNumber numberWithBool:NO]; + break; + } + + [sheet dismiss]; + } else if ([context isEqualToString:@"challenge"]) { + id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]); + + switch (button) { + case 1: { + NSString *username([[sheet textFieldAtIndex:0] text]); + NSString *password([[sheet textFieldAtIndex:1] text]); + + NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]); + + [sender useCredential:credential forAuthenticationChallenge:challenge_]; + } break; + + case 2: + [sender cancelAuthenticationChallenge:challenge_]; + break; + + default: + _assert(false); + } + + [challenge_ release]; + challenge_ = nil; + + [sheet dismiss]; + } else if ([context isEqualToString:@"submit"]) { + switch (button) { + case 1: + break; + + case 2: + if (request_ != nil) + [webview_ loadRequest:request_]; + break; + + default: + _assert(false); + } + + [sheet dismiss]; + } +} + +- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source { + challenge_ = [challenge retain]; + + NSURLProtectionSpace *space([challenge protectionSpace]); + NSString *realm([space realm]); + if (realm == nil) + realm = @""; + + UIActionSheet *sheet = [[[UIActionSheet alloc] + initWithTitle:realm + buttons:[NSArray arrayWithObjects:@"Login", @"Cancel", nil] + defaultButtonIndex:0 + delegate:self + context:@"challenge" + ] autorelease]; + + [sheet setNumberOfRows:1]; + + [sheet addTextFieldWithValue:@"" label:@"username"]; + [sheet addTextFieldWithValue:@"" label:@"password"]; + + UITextField *username([sheet textFieldAtIndex:0]); { + UITextInputTraits *traits([username textInputTraits]); + [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; + [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; + [traits setKeyboardType:UIKeyboardTypeASCIICapable]; + [traits setReturnKeyType:UIReturnKeyNext]; + } + + UITextField *password([sheet textFieldAtIndex:1]); { + UITextInputTraits *traits([password textInputTraits]); + [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; + [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; + [traits setKeyboardType:UIKeyboardTypeASCIICapable]; + // XXX: UIReturnKeyDone + [traits setReturnKeyType:UIReturnKeyNext]; + [traits setSecureTextEntry:YES]; + } + + [sheet popupAlertAnimated:YES]; +} + +- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source { + NSURL *url = [request URL]; + if ([self getSpecial:url]) + return nil; + [self _pushPage]; + return [self _addHeadersToRequest:request]; +} + +- (WebView *) _createWebViewWithRequest:(NSURLRequest *)request pushed:(BOOL)pushed { + [self setBackButtonTitle:title_]; + + BrowserView *browser = [[[BrowserView alloc] initWithBook:book_] autorelease]; + [browser setDelegate:delegate_]; + + if (pushed) { + [browser loadRequest:request]; + [book_ pushPage:browser]; + } + + return [browser webView]; +} + +- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request { + return [self _createWebViewWithRequest:request pushed:(request != nil)]; +} + +- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features { + return [self _createWebViewWithRequest:request pushed:YES]; +} + +- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { + if ([frame parentFrame] != nil) + return; + + title_ = [title retain]; + [book_ reloadTitleForPage:self]; +} + +- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { + if ([frame parentFrame] != nil) + return; + + reloading_ = false; + loading_ = true; + [self reloadButtons]; + + if (title_ != nil) { + [title_ release]; + title_ = nil; + } + + if (button_ != nil) { + [button_ release]; + button_ = nil; + } + + if (style_ != nil) { + [style_ release]; + style_ = nil; + } + + if (function_ != nil) { + [function_ release]; + function_ = nil; + } + + [book_ reloadTitleForPage:self]; + + [scroller_ scrollPointVisibleAtTopLeft:CGPointZero]; + + CGRect webrect = [scroller_ bounds]; + webrect.size.height = 0; + [webview_ setFrame:webrect]; +} + +- (void) _finishLoading { + if (!reloading_) { + loading_ = false; + [self reloadButtons]; + } +} + +- (bool) _loading { + return loading_; +} + +- (void) reloadButtons { + if ([self _loading]) + [indicator_ startAnimation]; + else + [indicator_ stopAnimation]; + [super reloadButtons]; +} + +- (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame { + return [webview_ webView:sender shouldScrollToPoint:point forFrame:frame]; +} + +- (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame { + return [webview_ webView:sender didReceiveViewportArguments:arguments forFrame:frame]; +} + +- (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame { + return [webview_ webView:sender needsScrollNotifications:notifications forFrame:frame]; +} + +- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame { + return [webview_ webView:sender didCommitLoadForFrame:frame]; +} + +- (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame { + return [webview_ webView:sender didReceiveDocTypeForFrame:frame]; +} + +- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { + if ([frame parentFrame] == nil) { + [self _finishLoading]; + + if (DOMDocument *document = [frame DOMDocument]) + if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"]) + for (DOMHTMLBodyElement *body in bodies) { + DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]); + + bool colored(false); + + if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) { + DOMRGBColor *rgb([color getRGBColorValue]); + + float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]); + NSLog(@"alpha:%g", alpha); + + if (alpha != 0) { + colored = true; + + [scroller_ setBackgroundColor:[UIColor + colorWithRed:([[rgb red] getFloatValue:DOM_CSS_NUMBER] / 255) + green:([[rgb green] getFloatValue:DOM_CSS_NUMBER] / 255) + blue:([[rgb blue] getFloatValue:DOM_CSS_NUMBER] / 255) + alpha:alpha + ]]; + } + } + + if (!colored) + [scroller_ setBackgroundColor:[UIColor pinStripeColor]]; + break; + } + } + + return [webview_ webView:sender didFinishLoadForFrame:frame]; +} + +- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { + if ([frame parentFrame] != nil) + return; + [self _finishLoading]; + + [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", + [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString], + [[error localizedDescription] stringByAddingPercentEscapes] + ]]]; +} + +- (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary { +#if ForSaurik + lprintf("Console:%s\n", [[dictionary description] UTF8String]); +#endif +} + +- (id) initWithBook:(RVBook *)book { + if ((self = [super initWithBook:book]) != nil) { + loading_ = false; + + struct CGRect bounds = [self bounds]; + + scroller_ = [[UIScroller alloc] initWithFrame:bounds]; + [self addSubview:scroller_]; + + [scroller_ setShowBackgroundShadow:NO]; + [scroller_ setFixedBackgroundPattern:YES]; + [scroller_ setBackgroundColor:[UIColor pinStripeColor]]; + + [scroller_ setScrollingEnabled:YES]; + [scroller_ setAdjustForContentSizeChange:YES]; + [scroller_ setClipsSubviews:YES]; + [scroller_ setAllowsRubberBanding:YES]; + [scroller_ setScrollDecelerationFactor:0.99]; + [scroller_ setDelegate:self]; + + CGRect webrect = [scroller_ bounds]; + webrect.size.height = 0; + + WebView *webview; + +#if RecycleWebViews + webview_ = [Documents_ lastObject]; + if (webview_ != nil) { + webview_ = [webview_ retain]; + webview = [webview_ webView]; + [Documents_ removeLastObject]; + [webview_ setFrame:webrect]; + } else { +#else + if (true) { +#endif + webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect]; + webview = [webview_ webView]; + + // XXX: this is terribly (too?) expensive + //[webview_ setDrawsBackground:NO]; + [webview setPreferencesIdentifier:@"Cydia"]; + + [webview_ setTileSize:CGSizeMake(webrect.size.width, 500)]; + + [webview_ setAllowsMessaging:YES]; + + [webview_ setTilingEnabled:YES]; + [webview_ setDrawsGrid:NO]; + [webview_ setLogsTilingChanges:NO]; + [webview_ setTileMinificationFilter:kCAFilterNearest]; + [webview_ setDetectsPhoneNumbers:NO]; + [webview_ setAutoresizes:YES]; + + [webview_ setMinimumScale:0.25f forDocumentTypes:0x10]; + [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10]; + [webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10]; + + [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2]; + + [webview_ setMinimumScale:1.0f forDocumentTypes:0x8]; + [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8]; + [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8]; + + [webview_ _setDocumentType:0x4]; + + [webview_ setZoomsFocusedFormControl:YES]; + [webview_ setContentsPosition:7]; + [webview_ setEnabledGestures:0xa]; + [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled]; + [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller]; + + [webview_ setSmoothsFonts:YES]; + + [webview _setUsesLoaderCache:YES]; + [webview setGroupName:@"Cydia"]; + [webview _setLayoutInterval:0]; + } + + [webview_ setDelegate:self]; + [webview_ setGestureDelegate:self]; + [scroller_ addSubview:webview_]; + + //NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + + CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]; + indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)]; + [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite]; + + Package *package([[Database sharedInstance] packageWithName:@"cydia"]); + NSString *application = package == nil ? @"Cydia" : [NSString + stringWithFormat:@"Cydia/%@", + [package installed] + ]; [webview setApplicationNameForUserAgent:application]; + + indirect_ = [[IndirectDelegate alloc] initWithDelegate:self]; + + [webview setFrameLoadDelegate:self]; + [webview setResourceLoadDelegate:indirect_]; + [webview setUIDelegate:self]; + [webview setScriptDebugDelegate:self]; + [webview setPolicyDelegate:self]; + + [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; + [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight]; + } return self; +} + +- (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<id>(webview, "_private")); + WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page")); + WebCore::Settings *settings(page == NULL ? NULL : page->settings()); + + bool no; + if (settings == NULL) + no = 0; + else { + no = settings->JavaScriptCanOpenWindowsAutomatically(); + settings->setJavaScriptCanOpenWindowsAutomatically(true); + } + + [delegate_ clearFirstResponder]; + JSObjectRef function([function_ JSObject]); + JSGlobalContextRef context([frame globalContext]); + JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL); + + if (settings != NULL) + settings->setJavaScriptCanOpenWindowsAutomatically(no); + } +} + +- (id) _rightButtonTitle { + return button_ != nil ? button_ : @"Reload"; +} + +- (id) rightButtonTitle { + return [self _loading] ? @"" : [self _rightButtonTitle]; +} + +- (UINavigationButtonStyle) rightButtonStyle { + if (style_ == nil) normal: + return UINavigationButtonStyleNormal; + else if ([style_ isEqualToString:@"Normal"]) + return UINavigationButtonStyleNormal; + else if ([style_ isEqualToString:@"Back"]) + return UINavigationButtonStyleBack; + else if ([style_ isEqualToString:@"Highlighted"]) + return UINavigationButtonStyleHighlighted; + else if ([style_ isEqualToString:@"Destructive"]) + return UINavigationButtonStyleDestructive; + else goto normal; +} + +- (NSString *) title { + return title_ == nil ? @"Loading" : title_; +} + +- (NSString *) backButtonTitle { + return @"Browser"; +} + +- (void) setPageActive:(BOOL)active { + if (!active) + [indicator_ removeFromSuperview]; + else + [[book_ navigationBar] addSubview:indicator_]; +} + +- (void) resetViewAnimated:(BOOL)animated { +} + +- (void) setPushed:(bool)pushed { + pushed_ = pushed; +} + +@end diff --git a/UICaboodle/Internals.h b/UICaboodle/Internals.h index a34c29f..62b46e2 100644 --- a/UICaboodle/Internals.h +++ b/UICaboodle/Internals.h @@ -4,6 +4,7 @@ } - (BOOL) respondsToSelector:(SEL)selector { - fprintf(stderr, "[%s]R-%s\n", class_getName(self->isa), sel_getName(selector)); - return [super respondsToSelector:selector]; + BOOL responds = [super respondsToSelector:selector]; + fprintf(stderr, "[%s]R%c%s\n", class_getName(self->isa), (responds ? '+' : '-'), sel_getName(selector)); + return responds; } diff --git a/UICaboodle/RVBook.h b/UICaboodle/RVBook.h index d1037b2..88a5191 100644 --- a/UICaboodle/RVBook.h +++ b/UICaboodle/RVBook.h @@ -7,13 +7,18 @@ @class UINavigationBar; @class UITransitionView; +@protocol RVNavigationBarDelegate +@end + @protocol RVDelegate - (void) setPageActive:(BOOL)active with:(id)object; - (void) resetViewAnimated:(BOOL)animated with:(id)object; - (void) reloadDataWith:(id)object; @end -@interface RVBook : UIView { +@interface RVBook : UIView < + RVNavigationBarDelegate +> { NSMutableArray *pages_; UINavigationBar *navbar_; UITransitionView *transition_; diff --git a/UICaboodle/RVBook.mm b/UICaboodle/RVBook.mm index 708e66f..a6f5318 100644 --- a/UICaboodle/RVBook.mm +++ b/UICaboodle/RVBook.mm @@ -18,6 +18,47 @@ #import "RVPage.h" +@interface NSObject (UICaboodleRVBook) +- (float) widthForButtonContents:(float)width; +@end + +@implementation NSObject (UICaboodleRVBook) + +- (float) widthForButtonContents:(float)width { + return width; +} + +@end + +@interface UIImage (UICaboodleRVBook) +- (float) widthForButtonContents:(float)width; +@end + +@implementation UIImage (UICaboodleRVBook) + +- (float) widthForButtonContents:(float)width { + return [self size].width + 8; +} + +@end + +@interface RVNavigationBar : UINavigationBar { +} + +- (id) createButtonWithContents:(id)contents width:(float)width barStyle:(int)barStyle buttonStyle:(int)style isRight:(BOOL)right; +@end + +@implementation RVNavigationBar + +- (id) createButtonWithContents:(id)contents width:(float)width barStyle:(int)barStyle buttonStyle:(int)style isRight:(BOOL)right { + float adjust = [contents widthForButtonContents:width]; + NSLog(@"cc:%@:%g:%g", contents, width, adjust); + width = adjust; + return [super createButtonWithContents:contents width:width barStyle:barStyle buttonStyle:style isRight:right]; +} + +@end + @implementation RVBook - (void) dealloc { @@ -59,7 +100,7 @@ CGSize navsize = [UINavigationBar defaultSize]; CGRect navrect = {{0, 0}, navsize}; - navbar_ = [[UINavigationBar alloc] initWithFrame:navrect]; + navbar_ = [[RVNavigationBar alloc] initWithFrame:navrect]; [self addSubview:navbar_]; [navbar_ setBarStyle:0]; diff --git a/UICaboodle/RVPage.h b/UICaboodle/RVPage.h index fa77df3..fffc4c4 100644 --- a/UICaboodle/RVPage.h +++ b/UICaboodle/RVPage.h @@ -12,10 +12,12 @@ - (NSString *) title; - (NSString *) backButtonTitle; -- (NSString *) rightButtonTitle; +- (id) rightButtonTitle; - (NSString *) leftButtonTitle; - (UIView *) accessoryView; +- (UIImage *) rightButtonImage; + - (UINavigationButtonStyle) leftButtonStyle; - (UINavigationButtonStyle) rightButtonStyle; diff --git a/UICaboodle/RVPage.mm b/UICaboodle/RVPage.mm index 02135c1..7700755 100644 --- a/UICaboodle/RVPage.mm +++ b/UICaboodle/RVPage.mm @@ -20,7 +20,7 @@ return nil; } -- (NSString *) rightButtonTitle { +- (id) rightButtonTitle { return nil; } @@ -44,6 +44,10 @@ return nil; } +- (UIImage *) rightButtonImage { + return nil; +} + - (void) setPageActive:(BOOL)active { } diff --git a/internals.h b/internals.h deleted file mode 100644 index 62b46e2..0000000 --- a/internals.h +++ /dev/null @@ -1,10 +0,0 @@ -- (NSMethodSignature *) methodSignatureForSelector:(SEL)selector { - fprintf(stderr, "[%s]S-%s\n", class_getName(self->isa), sel_getName(selector)); - return [super methodSignatureForSelector:selector]; -} - -- (BOOL) respondsToSelector:(SEL)selector { - BOOL responds = [super respondsToSelector:selector]; - fprintf(stderr, "[%s]R%c%s\n", class_getName(self->isa), (responds ? '+' : '-'), sel_getName(selector)); - return responds; -} @@ -9,7 +9,7 @@ all: Cydia clean: rm -f Cydia -Cydia: Cydia.mm ../uicaboodle.m/*.mm ../mobilesubstrate/*.h *.h #makefile +Cydia: Cydia.mm ../uicaboodle.m/*.m ../uicaboodle.m/*.mm ../mobilesubstrate/*.h #makefile $(target)g++ -march=armv6 -mcpu=arm1176jzf-s -I../uicaboodle.m -I../mobilesubstrate -fobjc-call-cxx-cdtors -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework IOKit -framework CoreFoundation -framework Foundation -framework CoreGraphics -framework GraphicsServices -framework MessageUI -framework QuartzCore -framework JavaScriptCore -framework WebCore -framework WebKit -lobjc -lapt-pkg -lpcre -fobjc-exceptions -F"$${PKG_ROOT}"/System/Library/PrivateFrameworks -multiply_defined suppress sign: Cydia |