// XXX: remove
#import <MessageUI/MailComposeController.h>
-#import <WebCore/WebScriptObject.h>
-//#include <WebCore/DOMHTML.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/WebView.h>
+#include <WebKit/WebScriptObject.h>
+#import <WebKit/WebView.h>
#import <WebKit/WebView-WebPrivate.h>
#include <sstream>
#define lprintf(args...) fprintf(stderr, args)
#define ForRelease 0
-#define ForSaurik 1 && !ForRelease
+#define ForSaurik (1 && !ForRelease)
#define RecycleWebViews 0
-#define AlwaysReload 0 && !ForRelease
+#define AlwaysReload (1 && !ForRelease)
/* Radix Sort {{{ */
@interface NSMutableArray (Radix)
kUIControlAllEvents = (kUIControlEventMouseDown | kUIControlEventMouseMovedInside | kUIControlEventMouseMovedOutside | kUIControlEventMouseUpInside | kUIControlEventMouseUpOutside)
} UIControlEventMasks;
+NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) {
+ size_t length([self length] - state->state);
+ if (length <= 0)
+ return 0;
+ else if (length > count)
+ length = count;
+ for (size_t i(0); i != length; ++i)
+ objects[i] = [self item:state->state++];
+ state->itemsPtr = objects;
+ state->mutationsPtr = (unsigned long *) self;
+ return length;
+}
+
@interface NSString (UIKit)
- (NSString *) stringByAddingPercentEscapes;
- (NSString *) stringByReplacingCharacter:(unsigned short)arg0 withCharacter:(unsigned short)arg1;
static NSDictionary *SectionMap_;
static NSMutableDictionary *Metadata_;
+static NSMutableDictionary *Indices_;
static _transient NSMutableDictionary *Settings_;
static _transient NSString *Role_;
static _transient NSMutableDictionary *Packages_;
- (Source *) source;
- (NSString *) role;
+- (NSString *) rating;
- (BOOL) matches:(NSString *)text;
}
+ (NSArray *) _attributeKeys {
- return [NSArray arrayWithObjects:@"applications", @"author", @"depiction", @"description", @"essential", @"homepage", @"icon", @"id", @"installed", @"latest", @"maintainer", @"name", @"purposes", @"section", @"size", @"source", @"sponsor", @"tagline", @"warnings", nil];
+ return [NSArray arrayWithObjects:@"applications", @"author", @"depiction", @"description", @"essential", @"homepage", @"icon", @"id", @"installed", @"latest", @"maintainer", @"name", @"purposes", @"rating", @"section", @"size", @"source", @"sponsor", @"tagline", @"warnings", nil];
}
- (NSArray *) attributeKeys {
return role_;
}
+- (NSString *) rating {
+ if (NSString *pattern = [Indices_ objectForKey:@"Rating"])
+ return [pattern stringByReplacingOccurrencesOfString:@"%@" withString:[id_ stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+ else
+ return nil;
+}
+
- (BOOL) matches:(NSString *)text {
if (text == nil)
return NO;
}
- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
- [[frame windowObject] evaluateWebScript:@"document.base.target = '_top'"];
return [super webView:sender didFinishLoadForFrame:frame];
}
}
[sheet dismiss];
- }
+ } else if ([context isEqualToString:@"trivial"])
+ [sheet dismiss];
+ else if ([context isEqualToString:@"urlerror"])
+ [sheet dismiss];
}
- (id) initWithBook:(RVBook *)book database:(Database *)database {
[sheet addTextFieldWithValue:@"http://" label:@""];
UITextInputTraits *traits = [[sheet textField] textInputTraits];
- [traits setAutocapitalizationType:0];
+ [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
+ [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
[traits setKeyboardType:UIKeyboardTypeURL];
- [traits setAutocorrectionType:1];
+ // XXX: UIReturnKeyDone
+ [traits setReturnKeyType:UIReturnKeyNext];
[sheet popupAlertAnimated:YES];
}
/* }}} */
/* Browser Implementation {{{ */
@implementation BrowserView
+#include "internals.h"
- (void) dealloc {
if (challenge_ != nil)
[scroller_ setDelegate:nil];
+ [background_ release];
[scroller_ release];
[urls_ release];
[indicator_ release];
return true;
}
+- (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
+ UIActionSheet *sheet = [[[UIActionSheet alloc]
+ initWithTitle:@"JavaScript Alert"
+ buttons:[NSArray arrayWithObjects:@"OK", nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:@"alert"
+ ] autorelease];
+
+ [sheet setBodyText:message];
+ [sheet popupAlertAnimated:YES];
+}
+
- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
[window setValue:delegate_ forKey:@"cydia"];
}
-- (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)dictionary request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
+- (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
if (NSURL *url = [request URL]) {
+ NSLog(@"win:%@:%@", url, [action description]);
if (![self getSpecial:url]) {
NSString *scheme([[url scheme] lowercaseString]);
if ([scheme isEqualToString:@"mailto"])
[listener use];
return;
}
+ else NSLog(@"nav:%@:%@", url, [action description]);
const NSArray *capability(reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability)));
- (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
NSString *context([sheet context]);
- if ([context isEqualToString:@"challenge"]) {
+ if ([context isEqualToString:@"alert"])
+ [sheet dismiss];
+ else if ([context isEqualToString:@"challenge"]) {
id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
switch (button) {
UITextField *username([sheet textFieldAtIndex:0]); {
UITextInputTraits *traits([username textInputTraits]);
- [traits setAutocapitalizationType:0];
- [traits setAutocorrectionType:1];
+ [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
+ [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
+ [traits setKeyboardType:UIKeyboardTypeASCIICapable];
+ [traits setReturnKeyType:UIReturnKeyNext];
}
UITextField *password([sheet textFieldAtIndex:1]); {
UITextInputTraits *traits([password textInputTraits]);
- [traits setAutocapitalizationType:0];
- [traits setAutocorrectionType:1];
+ [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
+ [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
+ [traits setKeyboardType:UIKeyboardTypeASCIICapable];
+ // XXX: UIReturnKeyDone
+ [traits setReturnKeyType:UIReturnKeyNext];
+ [traits setSecureTextEntry:YES];
}
[sheet popupAlertAnimated:YES];
return [webview_ webView:sender didReceiveDocTypeForFrame:frame];
}
+- (void) _clearBackground {
+ [background_ setBackgroundColor:[UIColor pinStripeColor]];
+ [background_ setImage:[UIImage applicationImageNamed:@"pinstripe.png"]];
+ [scroller_ setShowBackgroundShadow:NO];
+}
+
- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
- if ([frame parentFrame] == nil)
+ if ([frame parentFrame] == nil) {
[self _finishLoading];
+
+ [self _clearBackground];
+
+ 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]);
+ if (alpha != 0) {
+ colored = true;
+
+ [background_ 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 (DOMCSSPrimitiveValue *image = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-image"])) {
+ NSString *src([image getStringValue]);
+ if ([src isEqualToString:@"none"])
+ goto none;
+ NSLog(@"img:%@", [image getStringValue]);
+ } else none: if (colored)
+ [background_ setImage:nil];
+
+ break;
+ }
+ }
+
return [webview_ webView:sender didFinishLoadForFrame:frame];
}
struct CGRect bounds = [self bounds];
- UIImageView *pinstripe = [[[UIImageView alloc] initWithFrame:bounds] autorelease];
- [pinstripe setImage:[UIImage applicationImageNamed:@"pinstripe.png"]];
- [self addSubview:pinstripe];
+ background_ = [[UIImageView alloc] initWithFrame:bounds];
+ [self _clearBackground];
+ [self addSubview:background_];
scroller_ = [[UIScroller alloc] initWithFrame:bounds];
[self addSubview:scroller_];
#endif
webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect];
webview = [webview_ webView];
+ [webview_ setDrawsBackground:NO];
[webview_ setTileSize:CGSizeMake(webrect.size.width, 500)];
urls_ = [[NSMutableArray alloc] initWithCapacity:16];
[self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
+ [background_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
- [pinstripe setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
} return self;
}
NSData *data(UIImagePNGRepresentation(icon));
+ NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
+ [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+ [client URLProtocol:self didLoadData:data];
+ [client URLProtocolDidFinishLoading:self];
+ } else if ([command isEqualToString:@"source-icon"]) {
+ if (path == nil)
+ goto fail;
+ path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+ NSString *source(Simplify(path));
+
+ UIImage *icon([UIImage imageAtPath:[NSString stringWithFormat:@"%@/Sources/%@.png", App_, source]]);
+ if (icon == nil)
+ icon = [UIImage applicationImageNamed:@"unknown.png"];
+
+ NSData *data(UIImagePNGRepresentation(icon));
+
NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
[client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
[client URLProtocol:self didLoadData:data];
[field_ setPaddingTop:5];
- UITextInputTraits *traits = [field_ textInputTraits];
- [traits setAutocapitalizationType:0];
- [traits setAutocorrectionType:1];
- [traits setReturnKeyType:6];
+ UITextInputTraits *traits([field_ textInputTraits]);
+ [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
+ [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
+ [traits setReturnKeyType:UIReturnKeySearch];
CGRect accrect = {{0, 6}, {6 + cnfrect.size.width + 6 + area.size.width + 6, area.size.height}};
}*/
int main(int argc, char *argv[]) { _pooled
+ class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
+
bool substrate(false);
if (argc != 0) {
/*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 ((Metadata_ = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/lib/cydia/metadata.plist"]) == NULL)
Metadata_ = [[NSMutableDictionary alloc] initWithCapacity:2];
else {