"NEW" = "New";
"NEW_AT" = "New at %@";
"NEW_INSTALL" = "New Install";
+"NO" = "No";
"NO_SECTION" = "(No Section)";
"NOT_RATED" = "Not Rated";
"NODE" = "Note";
"VERSION" = "Version";
"WELCOME_TO_CYDIA" = "Welcome to Cydiaâ„¢";
"WHO_ARE_YOU" = "Who Are You?";
+"YES" = "Yes";
/* #include Directives {{{ */
#import "UICaboodle.h"
+#import "UCLocalize.h"
#include <objc/message.h>
#include <objc/objc.h>
#include <CoreFoundation/CFPriv.h>
#include <CoreFoundation/CFUniChar.h>
-#import <QuartzCore/CALayer.h>
#import <UIKit/UIKit.h>
#include <WebCore/WebCoreThread.h>
#endif
/* }}} */
-extern NSString * const kCAFilterNearest;
-
/* Information Dictionaries {{{ */
@interface NSMutableArray (Cydia)
- (void) addInfoDictionary:(NSDictionary *)info;
@end
-static inline NSString *CYLocalizeEx(NSString *key, NSString *value = nil) {
- return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil];
-}
-
-#define CYLocalize(key) CYLocalizeEx(@ key)
-
class CYString {
private:
char *data_;
NSDate *update = [Metadata_ objectForKey:@"LastUpdate"];
if (update == nil)
- return CYLocalize("NEVER_OR_UNKNOWN");
+ return UCLocalize("NEVER_OR_UNKNOWN");
CFDateFormatterRef formatter = CFDateFormatterCreate(NULL, Locale_, kCFDateFormatterMediumStyle, kCFDateFormatterMediumStyle);
CFStringRef formatted = CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) update);
NSString *parent(title_r[1]);
NSString *child(title_r[2]);
- return [NSString stringWithFormat:CYLocalize("PARENTHETICAL"),
+ return [NSString stringWithFormat:UCLocalize("PARENTHETICAL"),
LocalizeSection(parent),
LocalizeSection(child)
];
- (void) askForSettings;
- (UIProgressHUD *) addProgressHUD;
- (void) removeProgressHUD:(UIProgressHUD *)hud;
-- (RVPage *) pageForURL:(NSURL *)url hasTag:(int *)tag;
- (RVPage *) pageForPackage:(NSString *)name;
-- (void) openMailToURL:(NSURL *)url;
-- (void) clearFirstResponder;
- (PackageView *) packageView;
@end
/* }}} */
size_t length(strlen(name));
if (length < 2) invalid:
- [warnings addObject:CYLocalize("ILLEGAL_PACKAGE_IDENTIFIER")];
+ [warnings addObject:UCLocalize("ILLEGAL_PACKAGE_IDENTIFIER")];
else for (size_t i(0); i != length; ++i)
if (
/* XXX: technically this is not allowed */
/* XXX: this is not sensitive enough. only some folders are valid. */
if (cydia && !repository)
- [warnings addObject:[NSString stringWithFormat:CYLocalize("FILES_INSTALLED_TO"), @"Cydia.app"]];
+ [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"Cydia.app"]];
if (_private)
- [warnings addObject:[NSString stringWithFormat:CYLocalize("FILES_INSTALLED_TO"), @"/private"]];
+ [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/private"]];
if (stash)
- [warnings addObject:[NSString stringWithFormat:CYLocalize("FILES_INSTALLED_TO"), @"/var/stash"]];
+ [warnings addObject:[NSString stringWithFormat:UCLocalize("FILES_INSTALLED_TO"), @"/var/stash"]];
}
return [warnings count] == 0 ? nil : warnings;
@end
/* }}} */
-#if 0
-/* Mail Composition {{{ */
-@interface MailToView : PopUpView {
- MailComposeController *controller_;
+/* Confirmation View {{{ */
+bool DepSubstrate(const pkgCache::VerIterator &iterator) {
+ if (!iterator.end())
+ for (pkgCache::DepIterator dep(iterator.DependsList()); !dep.end(); ++dep) {
+ if (dep->Type != pkgCache::Dep::Depends && dep->Type != pkgCache::Dep::PreDepends)
+ continue;
+ pkgCache::PkgIterator package(dep.TargetPkg());
+ if (package.end())
+ continue;
+ if (strcmp(package.Name(), "mobilesubstrate") == 0)
+ return true;
+ }
+
+ return false;
}
-- (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url;
+/* Web Scripting {{{ */
+@interface CydiaObject : NSObject {
+ id indirect_;
+}
+- (id) initWithDelegate:(IndirectDelegate *)indirect;
@end
-@implementation MailToView
+@implementation CydiaObject
- (void) dealloc {
- [controller_ release];
+ [indirect_ release];
[super dealloc];
}
-- (void) mailComposeControllerWillAttemptToSend:(MailComposeController *)controller {
- NSLog(@"will");
+- (id) initWithDelegate:(IndirectDelegate *)indirect {
+ if ((self = [super init]) != nil) {
+ indirect_ = [indirect retain];
+ } return self;
+}
+
++ (NSArray *) _attributeKeys {
+ return [NSArray arrayWithObjects:@"device", @"firewire", @"imei", @"mac", @"serial", nil];
+}
+
+- (NSArray *) attributeKeys {
+ return [[self class] _attributeKeys];
}
-- (void) mailComposeControllerDidAttemptToSend:(MailComposeController *)controller mailDelivery:(id)delivery {
- NSLog(@"did:%@", delivery);
-// [UIApp setStatusBarShowsProgress:NO];
-if ([controller error]){
-NSArray *buttons = [NSArray arrayWithObjects:CYLocalize("OK"), nil];
-UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:CYLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self];
-[mailAlertSheet setBodyText:[controller error]];
-[mailAlertSheet popupAlertAnimated:YES];
++ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
+ return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
}
+
+- (NSString *) device {
+ return [[UIDevice currentDevice] uniqueIdentifier];
}
-- (void) showError {
- NSLog(@"%@", [controller_ error]);
- NSArray *buttons = [NSArray arrayWithObjects:CYLocalize("OK"), nil];
- UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:CYLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self];
- [mailAlertSheet setBodyText:[controller_ error]];
- [mailAlertSheet popupAlertAnimated:YES];
+#if 0 // XXX: implement!
+- (NSString *) mac {
+ if (![indirect_ promptForSensitive:@"Mac Address"])
+ return nil;
}
-- (void) deliverMessage { _pooled
- setuid(501);
- setgid(501);
+- (NSString *) serial {
+ if (![indirect_ promptForSensitive:@"Serial #"])
+ return nil;
+}
- if (![controller_ deliverMessage])
- [self performSelectorOnMainThread:@selector(showError) withObject:nil waitUntilDone:NO];
+- (NSString *) firewire {
+ if (![indirect_ promptForSensitive:@"Firewire GUID"])
+ return nil;
}
-- (void) mailComposeControllerCompositionFinished:(MailComposeController *)controller {
- if ([controller_ needsDelivery])
- [NSThread detachNewThreadSelector:@selector(deliverMessage) toTarget:self withObject:nil];
+- (NSString *) imei {
+ if (![indirect_ promptForSensitive:@"IMEI"])
+ return nil;
+}
+#endif
+
++ (NSString *) webScriptNameForSelector:(SEL)selector {
+ if (selector == @selector(close))
+ return @"close";
+ else if (selector == @selector(getPackageById:))
+ return @"getPackageById";
+ else if (selector == @selector(setAutoPopup:))
+ return @"setAutoPopup";
+ else if (selector == @selector(setButtonImage:withStyle:toFunction:))
+ return @"setButtonImage";
+ else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
+ return @"setButtonTitle";
+ else if (selector == @selector(setFinishHook:))
+ return @"setFinishHook";
+ else if (selector == @selector(setPopupHook:))
+ return @"setPopupHook";
+ else if (selector == @selector(setSpecial:))
+ return @"setSpecial";
+ else if (selector == @selector(setViewportWidth:))
+ return @"setViewportWidth";
+ else if (selector == @selector(supports:))
+ return @"supports";
+ else if (selector == @selector(stringWithFormat:arguments:))
+ return @"format";
+ else if (selector == @selector(localizedStringForKey:value:table:))
+ return @"localize";
+ else if (selector == @selector(du:))
+ return @"du";
+ else if (selector == @selector(statfs:))
+ return @"statfs";
else
- [self cancel];
+ return nil;
+}
+
++ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector {
+ return [self webScriptNameForSelector:selector] == nil;
}
-- (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url {
- if ((self = [super initWithView:view delegate:delegate]) != nil) {
- controller_ = [[MailComposeController alloc] initForContentSize:[overlay_ bounds].size];
- [controller_ setDelegate:self];
- [controller_ initializeUI];
- [controller_ setupForURL:url];
+- (BOOL) supports:(NSString *)feature {
+ return [feature isEqualToString:@"window.open"];
+}
- UIView *view([controller_ view]);
- [overlay_ addSubview:view];
- } return self;
+- (Package *) getPackageById:(NSString *)id {
+ return [[Database sharedInstance] packageWithName:id];
+}
+
+- (NSArray *) statfs:(NSString *)path {
+ struct statfs stat;
+
+ if (path == nil || statfs([path UTF8String], &stat) == -1)
+ return nil;
+
+ return [NSArray arrayWithObjects:
+ [NSNumber numberWithUnsignedLong:stat.f_bsize],
+ [NSNumber numberWithUnsignedLong:stat.f_blocks],
+ [NSNumber numberWithUnsignedLong:stat.f_bfree],
+ nil];
+}
+
+- (NSNumber *) du:(NSString *)path {
+ NSNumber *value(nil);
+
+ int fds[2];
+ _assert(pipe(fds) != -1);
+
+ pid_t pid(ExecFork());
+ if (pid == 0) {
+ _assert(dup2(fds[1], 1) != -1);
+ _assert(close(fds[0]) != -1);
+ _assert(close(fds[1]) != -1);
+ /* XXX: this should probably not use du */
+ execl("/usr/libexec/cydia/du", "du", "-s", [path UTF8String], NULL);
+ exit(1);
+ _assert(false);
+ }
+
+ _assert(close(fds[1]) != -1);
+
+ if (FILE *du = fdopen(fds[0], "r")) {
+ char line[1024];
+ while (fgets(line, sizeof(line), du) != NULL) {
+ size_t length(strlen(line));
+ while (length != 0 && line[length - 1] == '\n')
+ line[--length] = '\0';
+ if (char *tab = strchr(line, '\t')) {
+ *tab = '\0';
+ value = [NSNumber numberWithUnsignedLong:strtoul(line, NULL, 0)];
+ }
+ }
+
+ fclose(du);
+ } else _assert(close(fds[0]));
+
+ int status;
+ wait:
+ if (waitpid(pid, &status, 0) == -1)
+ if (errno == EINTR)
+ goto wait;
+ else _assert(false);
+
+ return value;
+}
+
+- (void) close {
+ [indirect_ close];
+}
+
+- (void) setAutoPopup:(BOOL)popup {
+ [indirect_ setAutoPopup:popup];
+}
+
+- (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
+ [indirect_ setButtonImage:button withStyle:style toFunction:function];
+}
+
+- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
+ [indirect_ setButtonTitle:button withStyle:style toFunction:function];
+}
+
+- (void) setSpecial:(id)function {
+ [indirect_ setSpecial:function];
+}
+
+- (void) setFinishHook:(id)function {
+ [indirect_ setFinishHook:function];
+}
+
+- (void) setPopupHook:(id)function {
+ [indirect_ setPopupHook:function];
+}
+
+- (void) setViewportWidth:(float)width {
+ [indirect_ setViewportWidth:width];
+}
+
+- (NSString *) stringWithFormat:(NSString *)format arguments:(WebScriptObject *)arguments {
+ //NSLog(@"SWF:\"%@\" A:%@", format, [arguments description]);
+ unsigned count([arguments count]);
+ id values[count];
+ for (unsigned i(0); i != count; ++i)
+ values[i] = [arguments objectAtIndex:i];
+ return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast<va_list>(values)] autorelease];
+}
+
+- (NSString *) localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table {
+ if (reinterpret_cast<id>(table) == [WebUndefined undefined])
+ table = nil;
+ return [[NSBundle mainBundle] localizedStringForKey:key value:value table:table];
}
@end
/* }}} */
-#endif
-/* Confirmation View {{{ */
-bool DepSubstrate(const pkgCache::VerIterator &iterator) {
- if (!iterator.end())
- for (pkgCache::DepIterator dep(iterator.DependsList()); !dep.end(); ++dep) {
- if (dep->Type != pkgCache::Dep::Depends && dep->Type != pkgCache::Dep::PreDepends)
- continue;
- pkgCache::PkgIterator package(dep.TargetPkg());
- if (package.end())
- continue;
- if (strcmp(package.Name(), "mobilesubstrate") == 0)
- return true;
- }
+@interface CydiaBrowserView : BrowserView {
+ CydiaObject *cydia_;
+}
- return false;
+@end
+
+@implementation CydiaBrowserView
+
+- (void) dealloc {
+ [cydia_ release];
+ [super dealloc];
+}
+
+- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+ [super webView:sender didClearWindowObject:window forFrame:frame];
+ [window setValue:cydia_ forKey:@"cydia"];
+}
+
+- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
+ 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;
}
+- (id) initWithBook:(RVBook *)book forWidth:(float)width {
+ if ((self = [super initWithBook:book]) != nil) {
+ cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_];
+
+ WebView *webview([webview_ webView]);
+
+ Package *package([[Database sharedInstance] packageWithName:@"cydia"]);
+ NSString *application = package == nil ? @"Cydia" : [NSString
+ stringWithFormat:@"Cydia/%@",
+ [package installed]
+ ];
+
+ if (Product_ != nil)
+ application = [NSString stringWithFormat:@"%@ Version/%@", application, Product_];
+ if (Build_ != nil)
+ application = [NSString stringWithFormat:@"%@ Mobile/%@", application, Build_];
+ if (Safari_ != nil)
+ application = [NSString stringWithFormat:@"%@ Safari/%@", application, Safari_];
+
+ [webview setApplicationNameForUserAgent:application];
+ } return self;
+}
+
+@end
+
@protocol ConfirmationViewDelegate
- (void) cancel;
- (void) confirm;
- (void) queue;
@end
-@interface ConfirmationView : BrowserView {
+@interface ConfirmationView : CydiaBrowserView {
_transient Database *database_;
UIActionSheet *essential_;
NSArray *changes_;
if (!remove)
essential_ = nil;
else if (Advanced_ || true) {
- NSString *parenthetical(CYLocalize("PARENTHETICAL"));
+ NSString *parenthetical(UCLocalize("PARENTHETICAL"));
essential_ = [[UIActionSheet alloc]
- initWithTitle:CYLocalize("REMOVING_ESSENTIALS")
+ initWithTitle:UCLocalize("REMOVING_ESSENTIALS")
buttons:[NSArray arrayWithObjects:
- [NSString stringWithFormat:parenthetical, CYLocalize("CANCEL_OPERATION"), CYLocalize("SAFE")],
- [NSString stringWithFormat:parenthetical, CYLocalize("FORCE_REMOVAL"), CYLocalize("UNSAFE")],
+ [NSString stringWithFormat:parenthetical, UCLocalize("CANCEL_OPERATION"), UCLocalize("SAFE")],
+ [NSString stringWithFormat:parenthetical, UCLocalize("FORCE_REMOVAL"), UCLocalize("UNSAFE")],
nil]
defaultButtonIndex:0
delegate:self
#ifndef __OBJC2__
[essential_ setDestructiveButton:[[essential_ buttons] objectAtIndex:0]];
#endif
- [essential_ setBodyText:CYLocalize("REMOVING_ESSENTIALS_EX")];
+ [essential_ setBodyText:UCLocalize("REMOVING_ESSENTIALS_EX")];
} else {
essential_ = [[UIActionSheet alloc]
- initWithTitle:CYLocalize("UNABLE_TO_COMPLY")
- buttons:[NSArray arrayWithObjects:CYLocalize("OKAY"), nil]
+ initWithTitle:UCLocalize("UNABLE_TO_COMPLY")
+ buttons:[NSArray arrayWithObjects:UCLocalize("OKAY"), nil]
defaultButtonIndex:0
delegate:self
context:@"unable"
];
- [essential_ setBodyText:CYLocalize("UNABLE_TO_COMPLY_EX")];
+ [essential_ setBodyText:UCLocalize("UNABLE_TO_COMPLY_EX")];
}
changes_ = [[NSArray alloc] initWithObjects:
}
- (NSString *) backButtonTitle {
- return CYLocalize("CONFIRM");
+ return UCLocalize("CONFIRM");
}
- (NSString *) leftButtonTitle {
- return [NSString stringWithFormat:CYLocalize("SLASH_DELIMITED"), CYLocalize("CANCEL"), CYLocalize("QUEUE")];
+ return [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("CANCEL"), UCLocalize("QUEUE")];
}
- (id) rightButtonTitle {
#if AlwaysReload || IgnoreInstall
return [super _rightButtonTitle];
#else
- return CYLocalize("CONFIRM");
+ return UCLocalize("CONFIRM");
#endif
}
_assert(false);
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("ERROR")
- buttons:[NSArray arrayWithObjects:CYLocalize("OKAY"), nil]
+ initWithTitle:UCLocalize("ERROR")
+ buttons:[NSArray arrayWithObjects:UCLocalize("OKAY"), nil]
defaultButtonIndex:0
delegate:self
context:@"_error"
}
switch (Finish_) {
- case 0: [close_ setTitle:CYLocalize("RETURN_TO_CYDIA")]; break;
- case 1: [close_ setTitle:CYLocalize("CLOSE_CYDIA")]; break;
- case 2: [close_ setTitle:CYLocalize("RESTART_SPRINGBOARD")]; break;
- case 3: [close_ setTitle:CYLocalize("RELOAD_SPRINGBOARD")]; break;
- case 4: [close_ setTitle:CYLocalize("REBOOT_DEVICE")]; break;
+ case 0: [close_ setTitle:UCLocalize("RETURN_TO_CYDIA")]; break;
+ case 1: [close_ setTitle:UCLocalize("CLOSE_CYDIA")]; break;
+ case 2: [close_ setTitle:UCLocalize("RESTART_SPRINGBOARD")]; break;
+ case 3: [close_ setTitle:UCLocalize("RELOAD_SPRINGBOARD")]; break;
+ case 4: [close_ setTitle:UCLocalize("REBOOT_DEVICE")]; break;
}
#define Cache_ "/User/Library/Caches/com.apple.mobile.installation.plist"
- (void) _retachThread {
UINavigationItem *item = [navbar_ topItem];
- [item setTitle:CYLocalize("COMPLETE")];
+ [item setTitle:UCLocalize("COMPLETE")];
[overlay_ addSubview:close_];
[progress_ removeFromSuperview];
detachNewThreadSelector:selector
toTarget:database_
withObject:nil
- title:CYLocalize("REPAIRING")
+ title:UCLocalize("REPAIRING")
];
}
UIActionSheet *sheet = [[[UIActionSheet alloc]
initWithTitle:(package == nil ? id : [package name])
- buttons:[NSArray arrayWithObjects:CYLocalize("OKAY"), nil]
+ buttons:[NSArray arrayWithObjects:UCLocalize("OKAY"), nil]
defaultButtonIndex:0
delegate:self
context:@"error"
//NSString *nfile = conffile_r[2];
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("CONFIGURATION_UPGRADE")
+ initWithTitle:UCLocalize("CONFIGURATION_UPGRADE")
buttons:[NSArray arrayWithObjects:
- CYLocalize("KEEP_OLD_COPY"),
- CYLocalize("ACCEPT_NEW_COPY"),
- // XXX: CYLocalize("SEE_WHAT_CHANGED"),
+ UCLocalize("KEEP_OLD_COPY"),
+ UCLocalize("ACCEPT_NEW_COPY"),
+ // XXX: UCLocalize("SEE_WHAT_CHANGED"),
nil]
defaultButtonIndex:0
delegate:self
context:@"conffile"
] autorelease];
- [sheet setBodyText:[NSString stringWithFormat:@"%@\n\n%@", CYLocalize("CONFIGURATION_UPGRADE_EX"), ofile]];
+ [sheet setBodyText:[NSString stringWithFormat:@"%@\n\n%@", UCLocalize("CONFIGURATION_UPGRADE_EX"), ofile]];
[sheet popupAlertAnimated:YES];
}
label = [source label];
trusted = [source trusted];
} else if ([[package id] isEqualToString:@"firmware"])
- label = CYLocalize("APPLE");
+ label = UCLocalize("APPLE");
else
- label = [NSString stringWithFormat:CYLocalize("SLASH_DELIMITED"), CYLocalize("UNKNOWN"), CYLocalize("LOCAL")];
+ label = [NSString stringWithFormat:UCLocalize("SLASH_DELIMITED"), UCLocalize("UNKNOWN"), UCLocalize("LOCAL")];
NSString *from(label);
NSString *section = [package simpleSection];
if (section != nil && ![section isEqualToString:label]) {
section = [[NSBundle mainBundle] localizedStringForKey:section value:nil table:@"Sections"];
- from = [NSString stringWithFormat:CYLocalize("PARENTHETICAL"), from, section];
+ from = [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), from, section];
}
- from = [NSString stringWithFormat:CYLocalize("FROM"), from];
+ from = [NSString stringWithFormat:UCLocalize("FROM"), from];
source_ = [from retain];
if (NSString *purpose = [package primaryPurpose])
[mode isEqualToString:@"REMOVE"] || [mode isEqualToString:@"PURGE"] ? @"removing.png" : @"installing.png"
]];
- [status_ setText:[NSString stringWithFormat:CYLocalize("QUEUED_FOR"), CYLocalize(mode)]];
+ [status_ setText:[NSString stringWithFormat:UCLocalize("QUEUED_FOR"), UCLocalize(mode)]];
[status_ setColor:[UIColor colorWithCGColor:Blueish_]];
} else if ([package half]) {
[badge_ setImage:[UIImage applicationImageNamed:@"damaged.png"]];
- [status_ setText:CYLocalize("PACKAGE_DAMAGED")];
+ [status_ setText:UCLocalize("PACKAGE_DAMAGED")];
[status_ setColor:[UIColor redColor]];
} else {
[badge_ setImage:nil];
[self clearSection];
if (section == nil) {
- name_ = [CYLocalize("ALL_PACKAGES") retain];
+ name_ = [UCLocalize("ALL_PACKAGES") retain];
count_ = nil;
} else {
section_ = [section localized];
if (section_ != nil)
section_ = [section_ retain];
- name_ = [(section_ == nil || [section_ length] == 0 ? CYLocalize("NO_SECTION") : section_) retain];
+ name_ = [(section_ == nil || [section_ length] == 0 ? UCLocalize("NO_SECTION") : section_) retain];
count_ = [[NSString stringWithFormat:@"%d", [section count]] retain];
if (editing_)
[self addSubview:list_];
UITableColumn *column = [[[UITableColumn alloc]
- initWithTitle:CYLocalize("NAME")
+ initWithTitle:UCLocalize("NAME")
identifier:@"name"
width:[self frame].size.width
] autorelease];
}
- (NSString *) title {
- return CYLocalize("INSTALLED_FILES");
+ return UCLocalize("INSTALLED_FILES");
}
- (NSString *) backButtonTitle {
- return CYLocalize("FILES");
+ return UCLocalize("FILES");
}
@end
/* }}} */
/* Package View {{{ */
-@interface PackageView : BrowserView {
+@interface PackageView : CydiaBrowserView {
_transient Database *database_;
Package *package_;
NSString *name_;
/* XXX: this is not safe at all... localization of /fail/ */
- (void) _clickButtonWithName:(NSString *)name {
- if ([name isEqualToString:CYLocalize("CLEAR")])
+ if ([name isEqualToString:UCLocalize("CLEAR")])
[delegate_ clearPackage:package_];
- else if ([name isEqualToString:CYLocalize("INSTALL")])
+ else if ([name isEqualToString:UCLocalize("INSTALL")])
[delegate_ installPackage:package_];
- else if ([name isEqualToString:CYLocalize("REINSTALL")])
+ else if ([name isEqualToString:UCLocalize("REINSTALL")])
[delegate_ installPackage:package_];
- else if ([name isEqualToString:CYLocalize("REMOVE")])
+ else if ([name isEqualToString:UCLocalize("REMOVE")])
[delegate_ removePackage:package_];
- else if ([name isEqualToString:CYLocalize("UPGRADE")])
+ else if ([name isEqualToString:UCLocalize("UPGRADE")])
[delegate_ installPackage:package_];
else _assert(false);
}
else {
NSMutableArray *buttons = [NSMutableArray arrayWithCapacity:(count + 1)];
[buttons addObjectsFromArray:buttons_];
- [buttons addObject:CYLocalize("CANCEL")];
+ [buttons addObject:UCLocalize("CANCEL")];
[delegate_ slideUp:[[[UIActionSheet alloc]
initWithTitle:nil
- (id) _rightButtonTitle {
int count = [buttons_ count];
- return count == 0 ? nil : count != 1 ? CYLocalize("MODIFY") : [buttons_ objectAtIndex:0];
+ return count == 0 ? nil : count != 1 ? UCLocalize("MODIFY") : [buttons_ objectAtIndex:0];
}
- (NSString *) backButtonTitle {
commercial_ = [package isCommercial];
if ([package_ mode] != nil)
- [buttons_ addObject:CYLocalize("CLEAR")];
+ [buttons_ addObject:UCLocalize("CLEAR")];
if ([package_ source] == nil);
else if ([package_ upgradableAndEssential:NO])
- [buttons_ addObject:CYLocalize("UPGRADE")];
+ [buttons_ addObject:UCLocalize("UPGRADE")];
else if ([package_ uninstalled])
- [buttons_ addObject:CYLocalize("INSTALL")];
+ [buttons_ addObject:UCLocalize("INSTALL")];
else
- [buttons_ addObject:CYLocalize("REINSTALL")];
+ [buttons_ addObject:UCLocalize("REINSTALL")];
if (![package_ uninstalled])
- [buttons_ addObject:CYLocalize("REMOVE")];
+ [buttons_ addObject:UCLocalize("REMOVE")];
if (special_ != NULL) {
CGRect frame([webview_ frame]);
[list_ setDataSource:self];
UITableColumn *column = [[[UITableColumn alloc]
- initWithTitle:CYLocalize("NAME")
+ initWithTitle:UCLocalize("NAME")
identifier:@"name"
width:[self frame].size.width
] autorelease];
- (NSString *) sectionList:(UISectionList *)list titleForSection:(int)section {
switch (section + (offset_ == 0 ? 1 : 0)) {
- case 0: return CYLocalize("ENTERED_BY_USER");
- case 1: return CYLocalize("INSTALLED_BY_PACKAGE");
+ case 0: return UCLocalize("ENTERED_BY_USER");
+ case 1: return UCLocalize("INSTALLED_BY_PACKAGE");
default:
_assert(false);
defer = true;
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("SOURCE_WARNING")
- buttons:[NSArray arrayWithObjects:CYLocalize("ADD_ANYWAY"), CYLocalize("CANCEL"), nil]
+ initWithTitle:UCLocalize("SOURCE_WARNING")
+ buttons:[NSArray arrayWithObjects:UCLocalize("ADD_ANYWAY"), UCLocalize("CANCEL"), nil]
defaultButtonIndex:0
delegate:self
context:@"warning"
[self complete];
} else if (error_ != nil) {
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("VERIFICATION_ERROR")
- buttons:[NSArray arrayWithObjects:CYLocalize("OK"), nil]
+ initWithTitle:UCLocalize("VERIFICATION_ERROR")
+ buttons:[NSArray arrayWithObjects:UCLocalize("OK"), nil]
defaultButtonIndex:0
delegate:self
context:@"urlerror"
[sheet popupAlertAnimated:YES];
} else {
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("NOT_REPOSITORY")
- buttons:[NSArray arrayWithObjects:CYLocalize("OK"), nil]
+ initWithTitle:UCLocalize("NOT_REPOSITORY")
+ buttons:[NSArray arrayWithObjects:UCLocalize("OK"), nil]
defaultButtonIndex:0
delegate:self
context:@"trivial"
] autorelease];
- [sheet setBodyText:CYLocalize("NOT_REPOSITORY_EX")];
+ [sheet setBodyText:UCLocalize("NOT_REPOSITORY_EX")];
[sheet popupAlertAnimated:YES];
}
trivial_ = false;
hud_ = [[delegate_ addProgressHUD] retain];
- [hud_ setText:CYLocalize("VERIFYING_URL")];
+ [hud_ setText:UCLocalize("VERIFYING_URL")];
} break;
case 2:
[list_ setDataSource:self];
UITableColumn *column = [[UITableColumn alloc]
- initWithTitle:CYLocalize("NAME")
+ initWithTitle:UCLocalize("NAME")
identifier:@"name"
width:[self frame].size.width
];
] autorelease]];*/
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("ENTER_APT_URL")
- buttons:[NSArray arrayWithObjects:CYLocalize("ADD_SOURCE"), CYLocalize("CANCEL"), nil]
+ initWithTitle:UCLocalize("ENTER_APT_URL")
+ buttons:[NSArray arrayWithObjects:UCLocalize("ADD_SOURCE"), UCLocalize("CANCEL"), nil]
defaultButtonIndex:0
delegate:self
context:@"source"
}
- (NSString *) title {
- return CYLocalize("SOURCES");
+ return UCLocalize("SOURCES");
}
- (NSString *) leftButtonTitle {
- return [[list_ table] isRowDeletionEnabled] ? CYLocalize("ADD") : nil;
+ return [[list_ table] isRowDeletionEnabled] ? UCLocalize("ADD") : nil;
}
- (id) rightButtonTitle {
- return [[list_ table] isRowDeletionEnabled] ? CYLocalize("DONE") : CYLocalize("EDIT");
+ return [[list_ table] isRowDeletionEnabled] ? UCLocalize("DONE") : UCLocalize("EDIT");
}
- (UINavigationButtonStyle) rightButtonStyle {
}
- (NSString *) title {
- return CYLocalize("INSTALLED");
+ return UCLocalize("INSTALLED");
}
- (NSString *) backButtonTitle {
- return CYLocalize("PACKAGES");
+ return UCLocalize("PACKAGES");
}
- (id) rightButtonTitle {
- return Role_ != nil && [Role_ isEqualToString:@"Developer"] ? nil : expert_ ? CYLocalize("EXPERT") : CYLocalize("SIMPLE");
+ return Role_ != nil && [Role_ isEqualToString:@"Developer"] ? nil : expert_ ? UCLocalize("EXPERT") : UCLocalize("SIMPLE");
}
- (UINavigationButtonStyle) rightButtonStyle {
/* }}} */
/* Home View {{{ */
-@interface HomeView : BrowserView {
+@interface HomeView : CydiaBrowserView {
}
@end
- (void) _leftButtonClicked {
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("ABOUT_CYDIA")
- buttons:[NSArray arrayWithObjects:CYLocalize("CLOSE"), nil]
+ initWithTitle:UCLocalize("ABOUT_CYDIA")
+ buttons:[NSArray arrayWithObjects:UCLocalize("CLOSE"), nil]
defaultButtonIndex:0
delegate:self
context:@"about"
}
- (NSString *) leftButtonTitle {
- return CYLocalize("ABOUT");
+ return UCLocalize("ABOUT");
}
@end
/* }}} */
/* Manage View {{{ */
-@interface ManageView : BrowserView {
+@interface ManageView : CydiaBrowserView {
}
@end
@implementation ManageView
- (NSString *) title {
- return CYLocalize("MANAGE");
+ return UCLocalize("MANAGE");
}
- (void) _leftButtonClicked {
}
- (NSString *) leftButtonTitle {
- return CYLocalize("SETTINGS");
+ return UCLocalize("SETTINGS");
}
#if !AlwaysReload
- (id) _rightButtonTitle {
- return Queuing_ ? CYLocalize("QUEUE") : nil;
+ return Queuing_ ? UCLocalize("QUEUE") : nil;
}
- (UINavigationButtonStyle) rightButtonStyle {
@end
/* }}} */
-#include <BrowserView.m>
-
/* Cydia Book {{{ */
@interface CYBook : RVBook <
ProgressDelegate
[UIView endAnimations];
[indicator_ startAnimation];
- [prompt_ setText:CYLocalize("UPDATING_DATABASE")];
+ [prompt_ setText:UCLocalize("UPDATING_DATABASE")];
[progress_ setProgress:0];
updating_ = true;
[delegate_ performSelector:@selector(reloadData) withObject:nil afterDelay:0];
else {
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:[NSString stringWithFormat:CYLocalize("COLON_DELIMITED"), CYLocalize("ERROR"), CYLocalize("REFRESH")]
+ initWithTitle:[NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), UCLocalize("ERROR"), UCLocalize("REFRESH")]
buttons:[NSArray arrayWithObjects:
- CYLocalize("OK"),
+ UCLocalize("OK"),
nil]
defaultButtonIndex:0
delegate:self
[progress_ setStyle:0];
[overlay_ addSubview:progress_];
- cancel_ = [[UINavigationButton alloc] initWithTitle:CYLocalize("CANCEL") style:UINavigationButtonStyleHighlighted];
+ cancel_ = [[UINavigationButton alloc] initWithTitle:UCLocalize("CANCEL") style:UINavigationButtonStyleHighlighted];
[cancel_ addTarget:self action:@selector(_onCancel) forControlEvents:UIControlEventTouchUpInside];
CGRect frame = [cancel_ frame];
}
- (void) setProgressError:(NSString *)error forPackage:(NSString *)id {
- [prompt_ setText:[NSString stringWithFormat:CYLocalize("COLON_DELIMITED"), CYLocalize("ERROR"), error]];
+ [prompt_ setText:[NSString stringWithFormat:UCLocalize("COLON_DELIMITED"), UCLocalize("ERROR"), error]];
}
- (void) setProgressTitle:(NSString *)title {
if (row == 0) {
section = nil;
name = nil;
- title = CYLocalize("ALL_PACKAGES");
+ title = UCLocalize("ALL_PACKAGES");
} else {
section = [filtered_ objectAtIndex:(row - 1)];
name = [section name];
title = [[NSBundle mainBundle] localizedStringForKey:Simplify(name) value:nil table:@"Sections"];
else {
name = @"";
- title = CYLocalize("NO_SECTION");
+ title = UCLocalize("NO_SECTION");
}
}
[transition_ transition:0 toView:list_];
UITableColumn *column = [[[UITableColumn alloc]
- initWithTitle:CYLocalize("NAME")
+ initWithTitle:UCLocalize("NAME")
identifier:@"name"
width:[self frame].size.width
] autorelease];
}
- (NSString *) title {
- return editing_ ? CYLocalize("SECTION_VISIBILITY") : CYLocalize("INSTALL_BY_SECTION");
+ return editing_ ? UCLocalize("SECTION_VISIBILITY") : UCLocalize("INSTALL_BY_SECTION");
}
- (NSString *) backButtonTitle {
- return CYLocalize("SECTIONS");
+ return UCLocalize("SECTIONS");
}
- (id) rightButtonTitle {
- return [sections_ count] == 0 ? nil : editing_ ? CYLocalize("DONE") : CYLocalize("EDIT");
+ return [sections_ count] == 0 ? nil : editing_ ? UCLocalize("DONE") : UCLocalize("EDIT");
}
- (UINavigationButtonStyle) rightButtonStyle {
//[list_ setSectionListStyle:1];
UITableColumn *column = [[[UITableColumn alloc]
- initWithTitle:CYLocalize("NAME")
+ initWithTitle:UCLocalize("NAME")
identifier:@"name"
width:[self frame].size.width
] autorelease];
[packages_ radixSortUsingFunction:reinterpret_cast<SKRadixFunction>(&PackageChangesRadix) withContext:NULL];
_trace();
- Section *upgradable = [[[Section alloc] initWithName:CYLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
- Section *ignored = [[[Section alloc] initWithName:CYLocalize("IGNORED_UPGRADES") localize:NO] autorelease];
+ Section *upgradable = [[[Section alloc] initWithName:UCLocalize("AVAILABLE_UPGRADES") localize:NO] autorelease];
+ Section *ignored = [[[Section alloc] initWithName:UCLocalize("IGNORED_UPGRADES") localize:NO] autorelease];
Section *section = nil;
NSDate *last = nil;
NSString *name;
if (seen == nil)
- name = CYLocalize("UNKNOWN");
+ name = UCLocalize("UNKNOWN");
else {
name = (NSString *) CFDateFormatterCreateStringWithDate(NULL, formatter, (CFDateRef) seen);
[name autorelease];
}
_profile(ChangesView$reloadData$Allocate)
- name = [NSString stringWithFormat:CYLocalize("NEW_AT"), name];
+ name = [NSString stringWithFormat:UCLocalize("NEW_AT"), name];
section = [[[Section alloc] initWithName:name row:offset localize:NO] autorelease];
[sections_ addObject:section];
_end
}
- (NSString *) leftButtonTitle {
- return [(CYBook *)book_ updating] ? nil : CYLocalize("REFRESH");
+ return [(CYBook *)book_ updating] ? nil : UCLocalize("REFRESH");
}
- (id) rightButtonTitle {
- return upgrades_ == 0 ? nil : [NSString stringWithFormat:CYLocalize("PARENTHETICAL"), CYLocalize("UPGRADE"), [NSString stringWithFormat:@"%u", upgrades_]];
+ return upgrades_ == 0 ? nil : [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), UCLocalize("UPGRADE"), [NSString stringWithFormat:@"%u", upgrades_]];
}
- (NSString *) title {
- return CYLocalize("CHANGES");
+ return UCLocalize("CHANGES");
}
@end
- (NSString *) preferencesTable:(UIPreferencesTable *)table titleForGroup:(int)group {
switch (group) {
- case 0: return [NSString stringWithFormat:CYLocalize("PARENTHETICAL"), CYLocalize("ADVANCED_SEARCH"), CYLocalize("COMING_SOON")];
+ case 0: return [NSString stringWithFormat:UCLocalize("PARENTHETICAL"), UCLocalize("ADVANCED_SEARCH"), UCLocalize("COMING_SOON")];
default: _assert(false);
}
UIFont *font = [UIFont systemFontOfSize:16];
[field_ setFont:font];
- [field_ setPlaceholder:CYLocalize("SEARCH_EX")];
+ [field_ setPlaceholder:UCLocalize("SEARCH_EX")];
[field_ setDelegate:self];
[field_ setPaddingTop:5];
}
- (NSString *) backButtonTitle {
- return CYLocalize("SEARCH");
+ return UCLocalize("SEARCH");
}
- (void) setDelegate:(id)delegate {
case 0: {
UIPreferencesControlTableCell *cell([[[UIPreferencesControlTableCell alloc] init] autorelease]);
[cell setShowSelection:NO];
- [cell setTitle:CYLocalize("SHOW_ALL_CHANGES_EX")];
+ [cell setTitle:UCLocalize("SHOW_ALL_CHANGES_EX")];
return cell;
}
subscribedCell_ = [[UIPreferencesControlTableCell alloc] init];
[subscribedCell_ setShowSelection:NO];
- [subscribedCell_ setTitle:CYLocalize("SHOW_ALL_CHANGES")];
+ [subscribedCell_ setTitle:UCLocalize("SHOW_ALL_CHANGES")];
[subscribedCell_ setControl:subscribedSwitch_];
ignoredCell_ = [[UIPreferencesControlTableCell alloc] init];
[ignoredCell_ setShowSelection:NO];
- [ignoredCell_ setTitle:CYLocalize("IGNORE_UPGRADES")];
+ [ignoredCell_ setTitle:UCLocalize("IGNORE_UPGRADES")];
[ignoredCell_ setControl:ignoredSwitch_];
[table_ setDataSource:self];
}
- (NSString *) title {
- return CYLocalize("SETTINGS");
+ return UCLocalize("SETTINGS");
}
@end
/* Signature View {{{ */
-@interface SignatureView : BrowserView {
+@interface SignatureView : CydiaBrowserView {
_transient Database *database_;
NSString *package_;
}
int count = [broken_ count];
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:(count == 1 ? CYLocalize("HALFINSTALLED_PACKAGE") : [NSString stringWithFormat:CYLocalize("HALFINSTALLED_PACKAGES"), count])
+ initWithTitle:(count == 1 ? UCLocalize("HALFINSTALLED_PACKAGE") : [NSString stringWithFormat:UCLocalize("HALFINSTALLED_PACKAGES"), count])
buttons:[NSArray arrayWithObjects:
- CYLocalize("FORCIBLY_CLEAR"),
- CYLocalize("TEMPORARY_IGNORE"),
+ UCLocalize("FORCIBLY_CLEAR"),
+ UCLocalize("TEMPORARY_IGNORE"),
nil]
defaultButtonIndex:0
delegate:self
context:@"fixhalf"
] autorelease];
- [sheet setBodyText:CYLocalize("HALFINSTALLED_PACKAGE_EX")];
+ [sheet setBodyText:UCLocalize("HALFINSTALLED_PACKAGE_EX")];
[sheet popupAlertAnimated:YES];
} else if (!Ignored_ && [essential_ count] != 0) {
int count = [essential_ count];
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:(count == 1 ? CYLocalize("ESSENTIAL_UPGRADE") : [NSString stringWithFormat:CYLocalize("ESSENTIAL_UPGRADES"), count])
+ initWithTitle:(count == 1 ? UCLocalize("ESSENTIAL_UPGRADE") : [NSString stringWithFormat:UCLocalize("ESSENTIAL_UPGRADES"), count])
buttons:[NSArray arrayWithObjects:
- CYLocalize("UPGRADE_ESSENTIAL"),
- CYLocalize("COMPLETE_UPGRADE"),
- CYLocalize("TEMPORARY_IGNORE"),
+ UCLocalize("UPGRADE_ESSENTIAL"),
+ UCLocalize("COMPLETE_UPGRADE"),
+ UCLocalize("TEMPORARY_IGNORE"),
nil]
defaultButtonIndex:0
delegate:self
context:@"upgrade"
] autorelease];
- [sheet setBodyText:CYLocalize("ESSENTIAL_UPGRADE_EX")];
+ [sheet setBodyText:UCLocalize("ESSENTIAL_UPGRADE_EX")];
[sheet popupAlertAnimated:YES];
}
}
static bool loaded(false);
UIProgressHUD *hud([self addProgressHUD]);
- [hud setText:(loaded ? CYLocalize("RELOADING_DATA") : CYLocalize("LOADING_DATA"))];
+ [hud setText:(loaded ? UCLocalize("RELOADING_DATA") : UCLocalize("LOADING_DATA"))];
loaded = true;
[database_ yieldToSelector:@selector(reloadData) withObject:nil];
detachNewThreadSelector:@selector(update_)
toTarget:self
withObject:nil
- title:CYLocalize("UPDATING_SOURCES")
+ title:UCLocalize("UPDATING_SOURCES")
];
}
- (void) cancel {
[self slideUp:[[[UIActionSheet alloc]
initWithTitle:nil
- buttons:[NSArray arrayWithObjects:CYLocalize("CONTINUE_QUEUING"), CYLocalize("CANCEL_CLEAR"), nil]
+ buttons:[NSArray arrayWithObjects:UCLocalize("CONTINUE_QUEUING"), UCLocalize("CANCEL_CLEAR"), nil]
defaultButtonIndex:1
delegate:self
context:@"cancel"
detachNewThreadSelector:@selector(perform)
toTarget:database_
withObject:nil
- title:CYLocalize("RUNNING")
+ title:UCLocalize("RUNNING")
];
}
}
- (RVPage *) _pageForURL:(NSURL *)url withClass:(Class)_class {
- BrowserView *browser = [[[_class alloc] initWithBook:book_] autorelease];
+ CydiaBrowserView *browser = [[[_class alloc] initWithBook:book_] autorelease];
[browser loadURL:url];
return browser;
}
}
- (void) askForSettings {
- NSString *parenthetical(CYLocalize("PARENTHETICAL"));
+ NSString *parenthetical(UCLocalize("PARENTHETICAL"));
UIActionSheet *role = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("WHO_ARE_YOU")
+ initWithTitle:UCLocalize("WHO_ARE_YOU")
buttons:[NSArray arrayWithObjects:
- [NSString stringWithFormat:parenthetical, CYLocalize("USER"), CYLocalize("USER_EX")],
- [NSString stringWithFormat:parenthetical, CYLocalize("HACKER"), CYLocalize("HACKER_EX")],
- [NSString stringWithFormat:parenthetical, CYLocalize("DEVELOPER"), CYLocalize("DEVELOPER_EX")],
+ [NSString stringWithFormat:parenthetical, UCLocalize("USER"), UCLocalize("USER_EX")],
+ [NSString stringWithFormat:parenthetical, UCLocalize("HACKER"), UCLocalize("HACKER_EX")],
+ [NSString stringWithFormat:parenthetical, UCLocalize("DEVELOPER"), UCLocalize("DEVELOPER_EX")],
nil]
defaultButtonIndex:-1
delegate:self
context:@"role"
] autorelease];
- [role setBodyText:CYLocalize("ROLE_EX")];
+ [role setBodyText:UCLocalize("ROLE_EX")];
[role popupAlertAnimated:YES];
}
@"install-dn.png", kUIButtonBarButtonSelectedInfo,
[NSNumber numberWithInt:2], kUIButtonBarButtonTag,
self, kUIButtonBarButtonTarget,
- CYLocalize("SECTIONS"), kUIButtonBarButtonTitle,
+ UCLocalize("SECTIONS"), kUIButtonBarButtonTitle,
@"0", kUIButtonBarButtonType,
nil],
@"changes-dn.png", kUIButtonBarButtonSelectedInfo,
[NSNumber numberWithInt:3], kUIButtonBarButtonTag,
self, kUIButtonBarButtonTarget,
- CYLocalize("CHANGES"), kUIButtonBarButtonTitle,
+ UCLocalize("CHANGES"), kUIButtonBarButtonTitle,
@"0", kUIButtonBarButtonType,
nil],
@"manage-dn.png", kUIButtonBarButtonSelectedInfo,
[NSNumber numberWithInt:4], kUIButtonBarButtonTag,
self, kUIButtonBarButtonTarget,
- CYLocalize("MANAGE"), kUIButtonBarButtonTitle,
+ UCLocalize("MANAGE"), kUIButtonBarButtonTitle,
@"0", kUIButtonBarButtonType,
nil],
@"search-dn.png", kUIButtonBarButtonSelectedInfo,
[NSNumber numberWithInt:5], kUIButtonBarButtonTag,
self, kUIButtonBarButtonTarget,
- CYLocalize("SEARCH"), kUIButtonBarButtonTitle,
+ UCLocalize("SEARCH"), kUIButtonBarButtonTitle,
@"0", kUIButtonBarButtonType,
nil],
nil];
[self _reloadData];
else {
Queuing_ = true;
- [buttonbar_ setBadgeValue:CYLocalize("Q_D") forButton:4];
+ [buttonbar_ setBadgeValue:UCLocalize("Q_D") forButton:4];
[book_ reloadData];
}
[window_ setUserInteractionEnabled:YES];
}
-- (void) openMailToURL:(NSURL *)url {
-// XXX: this makes me sad
-#if 0
- [[[MailToView alloc] initWithView:underlay_ delegate:self url:url] autorelease];
-#else
- [UIApp openURL:url];// asPanel:YES];
-#endif
-}
-
-- (void) clearFirstResponder {
- if (id responder = [window_ firstResponder])
- [responder resignFirstResponder];
-}
-
- (RVPage *) pageForPackage:(NSString *)name {
if (Package *package = [database_ packageWithName:name]) {
PackageView *view([self packageView]);
return view;
} else {
UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("CANNOT_LOCATE_PACKAGE")
- buttons:[NSArray arrayWithObjects:CYLocalize("CLOSE"), nil]
+ initWithTitle:UCLocalize("CANNOT_LOCATE_PACKAGE")
+ buttons:[NSArray arrayWithObjects:UCLocalize("CLOSE"), nil]
defaultButtonIndex:0
delegate:self
context:@"missing"
] autorelease];
- [sheet setBodyText:[NSString stringWithFormat:CYLocalize("PACKAGE_CANNOT_BE_FOUND"), name]];
+ [sheet setBodyText:[NSString stringWithFormat:UCLocalize("PACKAGE_CANNOT_BE_FOUND"), name]];
[sheet popupAlertAnimated:YES];
return nil;
if (tag != NULL)
tag = 0;
+ NSString *href([url absoluteString]);
+ if ([href hasPrefix:@"apptapp://package/"])
+ return [self pageForPackage:[href substringFromIndex:18]];
+
NSString *scheme([[url scheme] lowercaseString]);
if (![scheme isEqualToString:@"cydia"])
return nil;
if ([path isEqualToString:@"/add-source"])
return [[[AddSourceView alloc] initWithBook:book_ database:database_] autorelease];
else if ([path isEqualToString:@"/storage"])
- return [self _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]] withClass:[BrowserView class]];
+ return [self _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]] withClass:[CydiaBrowserView class]];
else if ([path isEqualToString:@"/sources"])
return [[[SourceTable alloc] initWithBook:book_ database:database_] autorelease];
else if ([path isEqualToString:@"/packages"])
return [[[InstalledView alloc] initWithBook:book_ database:database_] autorelease];
else if ([path hasPrefix:@"/url/"])
- return [self _pageForURL:[NSURL URLWithString:[path substringFromIndex:5]] withClass:[BrowserView class]];
+ return [self _pageForURL:[NSURL URLWithString:[path substringFromIndex:5]] withClass:[CydiaBrowserView class]];
else if ([path hasPrefix:@"/launch/"])
[self launchApplicationWithIdentifier:[path substringFromIndex:8] suspended:NO];
else if ([path hasPrefix:@"/package-settings/"])
#import "ResetView.h"
-
#include <WebKit/DOMCSSPrimitiveValue.h>
#include <WebKit/DOMCSSStyleDeclaration.h>
#include <WebKit/DOMDocument.h>
@class Database;
@class IndirectDelegate;
-@class CydiaObject;
+
+@interface WebScriptObject (UICaboodle)
+- (unsigned) count;
+- (id) objectAtIndex:(unsigned)index;
+@end
+
+@protocol BrowserViewDelegate
+- (RVPage *) pageForURL:(NSURL *)url hasTag:(int *)tag;
+@end
@interface BrowserView : RVPage <
RVBookHook
UIWebDocumentView *webview_;
UIProgressIndicator *indicator_;
IndirectDelegate *indirect_;
- CydiaObject *cydia_;
NSURLAuthenticationChallenge *challenge_;
bool error_;
- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;
- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
+- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source;
+
+ (float) defaultWidth;
- (void) setViewportWidth:(float)width;
+++ /dev/null
-#include <BrowserView.h>
-
-#include <WebCore/WebCoreThread.h>
-
-/* Indirect Delegate {{{ */
-@interface IndirectDelegate : NSObject {
- _transient volatile id delegate_;
-}
-
-- (void) setDelegate:(id)delegate;
-- (id) initWithDelegate:(id)delegate;
-@end
-
-@implementation IndirectDelegate
-
-- (void) setDelegate:(id)delegate {
- delegate_ = delegate;
-}
-
-- (id) initWithDelegate:(id)delegate {
- delegate_ = delegate;
- return self;
-}
-
-- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
- if (delegate_ != nil)
- return [delegate_ webView:sender didClearWindowObject:window forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
- if (delegate_ != nil)
- return [delegate_ webView:sender didCommitLoadForFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
- if (delegate_ != nil)
- return [delegate_ webView:sender didFailLoadWithError:error forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
- if (delegate_ != nil)
- return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
- if (delegate_ != nil)
- return [delegate_ webView:sender didFinishLoadForFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
- if (delegate_ != nil)
- return [delegate_ webView:sender didReceiveTitle:title forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
- if (delegate_ != nil)
- return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame];
-}
-
-- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
- if (delegate_ != nil)
- return [delegate_ webView:sender resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source];
-}
-
-- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
- if (delegate_ != nil)
- return [delegate_ webView:sender resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:source];
- return nil;
-}
-
-- (IMP) methodForSelector:(SEL)sel {
- if (IMP method = [super methodForSelector:sel])
- return method;
- fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
- return NULL;
-}
-
-- (BOOL) respondsToSelector:(SEL)sel {
- if ([super respondsToSelector:sel])
- return YES;
- // XXX: WebThreadCreateNSInvocation returns nil
- //fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
- return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
-}
-
-- (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
- if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
- return method;
- //fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
- if (delegate_ != nil)
- if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
- return sig;
- // XXX: I fucking hate Apple so very very bad
- return [NSMethodSignature signatureWithObjCTypes:"v@:"];
-}
-
-- (void) forwardInvocation:(NSInvocation *)inv {
- SEL sel = [inv selector];
- if (delegate_ != nil && [delegate_ respondsToSelector:sel])
- [inv invokeWithTarget:delegate_];
-}
-
-@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
-
-@interface WebScriptObject (Cydia)
-
-- (unsigned) count;
-- (id) objectAtIndex:(unsigned)index;
-
-@end
-
-@implementation WebScriptObject (Cydia)
-
-- (unsigned) count {
- id length([self valueForKey:@"length"]);
- if ([length respondsToSelector:@selector(intValue)])
- return [length intValue];
- else
- return 0;
-}
-
-- (id) objectAtIndex:(unsigned)index {
- return [self webScriptValueAtIndex:index];
-}
-
-@end
-
-/* Web Scripting {{{ */
-@interface CydiaObject : NSObject {
- id indirect_;
-}
-
-- (id) initWithDelegate:(IndirectDelegate *)indirect;
-@end
-
-@implementation CydiaObject
-
-- (void) dealloc {
- [indirect_ release];
- [super dealloc];
-}
-
-- (id) initWithDelegate:(IndirectDelegate *)indirect {
- if ((self = [super init]) != nil) {
- indirect_ = [indirect retain];
- } return self;
-}
-
-+ (NSArray *) _attributeKeys {
- return [NSArray arrayWithObjects:@"device", @"firewire", @"imei", @"mac", @"serial", nil];
-}
-
-- (NSArray *) attributeKeys {
- return [[self class] _attributeKeys];
-}
-
-+ (BOOL) isKeyExcludedFromWebScript:(const char *)name {
- return ![[self _attributeKeys] containsObject:[NSString stringWithUTF8String:name]] && [super isKeyExcludedFromWebScript:name];
-}
-
-- (NSString *) device {
- return [[UIDevice currentDevice] uniqueIdentifier];
-}
-
-- (NSString *) mac {
- if (![indirect_ promptForSensitive:@"Mac Address"])
- return nil;
-}
-
-- (NSString *) serial {
- if (![indirect_ promptForSensitive:@"Serial #"])
- return nil;
-}
-
-- (NSString *) firewire {
- if (![indirect_ promptForSensitive:@"Firewire GUID"])
- return nil;
-}
-
-- (NSString *) imei {
- if (![indirect_ promptForSensitive:@"IMEI"])
- return nil;
-}
-
-+ (NSString *) webScriptNameForSelector:(SEL)selector {
- if (selector == @selector(close))
- return @"close";
- else if (selector == @selector(getPackageById:))
- return @"getPackageById";
- else if (selector == @selector(setAutoPopup:))
- return @"setAutoPopup";
- else if (selector == @selector(setButtonImage:withStyle:toFunction:))
- return @"setButtonImage";
- else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
- return @"setButtonTitle";
- else if (selector == @selector(setFinishHook:))
- return @"setFinishHook";
- else if (selector == @selector(setPopupHook:))
- return @"setPopupHook";
- else if (selector == @selector(setSpecial:))
- return @"setSpecial";
- else if (selector == @selector(setViewportWidth:))
- return @"setViewportWidth";
- else if (selector == @selector(supports:))
- return @"supports";
- else if (selector == @selector(stringWithFormat:arguments:))
- return @"format";
- else if (selector == @selector(localizedStringForKey:value:table:))
- return @"localize";
- else if (selector == @selector(du:))
- return @"du";
- else if (selector == @selector(statfs:))
- return @"statfs";
- 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];
-}
-
-- (NSArray *) statfs:(NSString *)path {
- struct statfs stat;
-
- if (path == nil || statfs([path UTF8String], &stat) == -1)
- return nil;
-
- return [NSArray arrayWithObjects:
- [NSNumber numberWithUnsignedLong:stat.f_bsize],
- [NSNumber numberWithUnsignedLong:stat.f_blocks],
- [NSNumber numberWithUnsignedLong:stat.f_bfree],
- nil];
-}
-
-- (NSNumber *) du:(NSString *)path {
- NSNumber *value(nil);
-
- int fds[2];
- _assert(pipe(fds) != -1);
-
- pid_t pid(ExecFork());
- if (pid == 0) {
- _assert(dup2(fds[1], 1) != -1);
- _assert(close(fds[0]) != -1);
- _assert(close(fds[1]) != -1);
- /* XXX: this should probably not use du */
- execl("/usr/libexec/cydia/du", "du", "-s", [path UTF8String], NULL);
- exit(1);
- _assert(false);
- }
-
- _assert(close(fds[1]) != -1);
-
- if (FILE *du = fdopen(fds[0], "r")) {
- char line[1024];
- while (fgets(line, sizeof(line), du) != NULL) {
- size_t length(strlen(line));
- while (length != 0 && line[length - 1] == '\n')
- line[--length] = '\0';
- if (char *tab = strchr(line, '\t')) {
- *tab = '\0';
- value = [NSNumber numberWithUnsignedLong:strtoul(line, NULL, 0)];
- }
- }
-
- fclose(du);
- } else _assert(close(fds[0]));
-
- int status;
- wait:
- if (waitpid(pid, &status, 0) == -1)
- if (errno == EINTR)
- goto wait;
- else _assert(false);
-
- return value;
-}
-
-- (void) close {
- [indirect_ close];
-}
-
-- (void) setAutoPopup:(BOOL)popup {
- [indirect_ setAutoPopup:popup];
-}
-
-- (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
- [indirect_ setButtonImage:button withStyle:style toFunction:function];
-}
-
-- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
- [indirect_ setButtonTitle:button withStyle:style toFunction:function];
-}
-
-- (void) setSpecial:(id)function {
- [indirect_ setSpecial:function];
-}
-
-- (void) setFinishHook:(id)function {
- [indirect_ setFinishHook:function];
-}
-
-- (void) setPopupHook:(id)function {
- [indirect_ setPopupHook:function];
-}
-
-- (void) setViewportWidth:(float)width {
- [indirect_ setViewportWidth:width];
-}
-
-- (NSString *) stringWithFormat:(NSString *)format arguments:(WebScriptObject *)arguments {
- //NSLog(@"SWF:\"%@\" A:%@", format, [arguments description]);
- unsigned count([arguments count]);
- id values[count];
- for (unsigned i(0); i != count; ++i)
- values[i] = [arguments objectAtIndex:i];
- return [[[NSString alloc] initWithFormat:format arguments:reinterpret_cast<va_list>(values)] autorelease];
-}
-
-- (NSString *) localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table {
- if (reinterpret_cast<id>(table) == [WebUndefined undefined])
- table = nil;
- return [[NSBundle mainBundle] localizedStringForKey:key value:value table:table];
-}
-
-@end
-/* }}} */
-
-@implementation BrowserView
-
-#if ShowInternals
-#include "Internals.h"
-#endif
-
-- (void) dealloc {
-#if LogBrowser
- NSLog(@"[BrowserView dealloc]");
-#endif
-
- if (challenge_ != nil)
- [challenge_ release];
-
- WebThreadLock();
-
- WebView *webview = [webview_ webView];
- [webview setFrameLoadDelegate:nil];
- [webview setResourceLoadDelegate:nil];
- [webview setUIDelegate:nil];
- [webview setScriptDebugDelegate:nil];
- [webview setPolicyDelegate:nil];
-
- [webview setDownloadDelegate:nil];
-
- /* XXX: these are set by UIWebDocumentView
- [webview _setFormDelegate:nil];
- [webview _setUIKitDelegate:nil];
- [webview setEditingDelegate:nil];*/
-
- /* XXX: no one sets this, ever
- [webview setWebMailDelegate:nil];*/
-
- [webview_ setDelegate:nil];
- [webview_ setGestureDelegate:nil];
- [webview_ setFormEditingDelegate:nil];
- [webview_ setInteractionDelegate:nil];
-
- [indirect_ setDelegate:nil];
-
- //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
- [webview close];
-
-#if RecycleWebViews
- [webview_ removeFromSuperview];
- [Documents_ addObject:[webview_ autorelease]];
-#else
- [webview_ release];
-#endif
-
- [indirect_ release];
-
- WebThreadUnlock();
-
- [cydia_ release];
-
- [scroller_ setDelegate:nil];
-
- if (button_ != nil)
- [button_ release];
- if (style_ != nil)
- [style_ release];
- if (function_ != nil)
- [function_ release];
- if (finish_ != nil)
- [finish_ release];
- if (closer_ != nil)
- [closer_ release];
- if (special_ != nil)
- [special_ release];
-
- [scroller_ release];
- [indicator_ release];
- if (confirm_ != nil)
- [confirm_ release];
- if (sensitive_ != nil)
- [sensitive_ 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;
- error_ = false;
-
- WebThreadLock();
- [webview_ loadRequest:request];
- WebThreadUnlock();
-}
-
-- (void) reloadURL {
- if (request_ == nil)
- return;
-
- if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
- [self loadRequest:request_];
- else {
- UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:CYLocalize("RESUBMIT_FORM")
- buttons:[NSArray arrayWithObjects:CYLocalize("CANCEL"), CYLocalize("SUBMIT"), nil]
- defaultButtonIndex:0
- delegate:self
- context:@"submit"
- ] autorelease];
-
- [sheet setNumberOfRows:1];
- [sheet popupAlertAnimated:YES];
- }
-}
-
-- (WebView *) webView {
- return [webview_ webView];
-}
-
-- (UIWebDocumentView *) documentView {
- return webview_;
-}
-
-/* XXX: WebThreadLock? */
-- (void) _fixScroller:(CGRect)bounds {
- 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;
- }
-
- CGRect subrect([scroller_ frame]);
- 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) fixScroller {
- CGRect bounds([webview_ documentBounds]);
-#if TrackResize
- NSLog(@"_fs:(%f,%f+%f,%f)", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
-#endif
- [self _fixScroller:bounds];
-}
-
-- (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
- size_ = frame.size;
-#if TrackResize
- NSLog(@"dsf:(%f,%f+%f,%f)", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
-#endif
- [self _fixScroller:frame];
-}
-
-- (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
- [self view:sender didSetFrame:frame];
-}
-
-- (void) pushPage:(RVPage *)page {
- [page setDelegate:delegate_];
- [self setBackButtonTitle:title_];
- [book_ pushPage:page];
-}
-
-- (void) _pushPage {
- if (pushed_)
- return;
- // WTR: [self autorelease];
- pushed_ = true;
- [book_ pushPage:self];
-}
-
-- (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
-
- 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)
- if (swap)
- [self swapPage:page];
- else
- [self pushPage:page];
- return true;
-}
-
-- (void) webViewShow:(WebView *)sender {
- /* XXX: this is where I cry myself to sleep */
-}
-
-- (bool) _allowJavaScriptPanel {
- return true;
-}
-
-- (bool) allowSensitiveRequests {
- [self _allowJavaScriptPanel];
-}
-
-- (void) _promptForSensitive:(NSMutableArray *)array {
- NSString *name([array objectAtIndex:0]);
-
- UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:nil
- buttons:[NSArray arrayWithObjects:CYLocalize("YES"), CYLocalize("NO"), nil]
- defaultButtonIndex:0
- delegate:indirect_
- context:@"sensitive"
- ] autorelease];
-
- NSString *host(@"XXX");
-
- [sheet setNumberOfRows:1];
- [sheet setBodyText:[NSString stringWithFormat:@"The website at %@ is requesting your phone's %@. This is almost certainly for product licensing purposes. Will you allow this?", host, name]];
- [sheet popupAlertAnimated:YES];
-
- NSRunLoop *loop([NSRunLoop currentRunLoop]);
- NSDate *future([NSDate distantFuture]);
-
- while (sensitive_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
-
- NSNumber *sensitive([sensitive_ autorelease]);
- sensitive_ = nil;
-
- [self autorelease];
- [array replaceObjectAtIndex:0 withObject:sensitive];
-}
-
-- (bool) promptForSensitive:(NSString *)name {
- if (![self allowSensitiveRequests])
- return false;
-
- NSMutableArray *array([NSMutableArray arrayWithCapacity:1]);
- [array addObject:name];
-
- [self performSelectorOnMainThread:@selector(_promptForSensitive:) withObject:array waitUntilDone:YES];
- return [[array lastObject] boolValue];
-}
-
-- (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
- if (![self _allowJavaScriptPanel])
- return;
- [self retain];
-
- UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:nil
- buttons:[NSArray arrayWithObjects:CYLocalize("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 {
- if (![self _allowJavaScriptPanel])
- return NO;
- [self retain];
-
- UIActionSheet *sheet = [[[UIActionSheet alloc]
- initWithTitle:nil
- buttons:[NSArray arrayWithObjects:CYLocalize("OK"), CYLocalize("CANCEL"), nil]
- defaultButtonIndex:0
- delegate:indirect_
- 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;
-
- [self autorelease];
- return [confirm boolValue];
-}
-
-- (void) setAutoPopup:(BOOL)popup {
- popup_ = popup;
-}
-
-- (void) setSpecial:(id)function {
- if (special_ != nil)
- [special_ autorelease];
- special_ = function == nil ? nil : [function retain];
-}
-
-- (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];
-
- [self reloadButtons];
-}
-
-- (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];
-
- [self reloadButtons];
-}
-
-- (void) setFinishHook:(id)function {
- if (finish_ != nil)
- [finish_ autorelease];
- finish_ = function == nil ? nil : [function retain];
-}
-
-- (void) setPopupHook:(id)function {
- if (closer_ != nil)
- [closer_ autorelease];
- closer_ = function == nil ? nil : [function retain];
-}
-
-- (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
- editing_ = true;
-}
-
-- (void) webView:(WebView *)sender didBeginEditingFormElement:(id)element {
- [self fixScroller];
-}
-
-- (void) webViewDidEndEditingFormElements:(WebView *)sender {
- editing_ = false;
- [self fixScroller];
-}
-
-- (void) webViewClose:(WebView *)sender {
- [book_ close];
-}
-
-- (void) close {
- [book_ close];
-}
-
-- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
- [window setValue:cydia_ 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 LogBrowser
- NSLog(@"nwa:%@", name);
-#endif
-
- if (NSURL *url = [request URL]) {
- if (name == nil) unknown: {
- if (![self getSpecial:url swap:NO]) {
- NSString *scheme([[url scheme] lowercaseString]);
- if ([scheme isEqualToString:@"mailto"])
- [delegate_ openMailToURL:url];
- else goto use;
- }
- } else if ([name isEqualToString:@"_open"])
- [delegate_ openURL:url];
- else if ([name isEqualToString:@"_popup"]) {
- NSString *scheme([[url scheme] lowercaseString]);
- if ([scheme isEqualToString:@"mailto"])
- [delegate_ openMailToURL:url];
- else {
- RVBook *book([[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
- [book setHook:indirect_];
-
- RVPage *page([delegate_ pageForURL:url hasTag:NULL]);
- if (page == nil) {
- /* XXX: call createWebViewWithRequest instead? */
-
- [self setBackButtonTitle:title_];
-
- BrowserView *browser([[[BrowserView alloc] initWithBook:book] autorelease]);
- [browser loadURL:url];
- page = browser;
- }
-
- [book setDelegate:delegate_];
- [page setDelegate:delegate_];
-
- [book setPage:page];
- [book_ pushBook:book];
- }
- } else goto unknown;
-
- [listener ignore];
- } else use:
- [listener use];
-}
-
-- (void) webView:(WebView *)sender 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];
-
- WebView *webview([webview_ webView]);
- 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 (!error_ && [frame parentFrame] == nil) {
- if (request_ != nil)
- [request_ autorelease];
- request_ = [request retain];
-#if LogBrowser
- NSLog(@"dpn:%@", request_);
-#endif
- }
-
- [listener use];
-
- WebView *webview([webview_ webView]);
- if (frame == [webview mainFrame])
- [self _pushPage];
- return;
- }
-#if LogBrowser
- else NSLog(@"nav:%@:%@", url, [action description]);
-#endif
-
- const NSArray *capability;
-
-#if 0 // XXX:3:GSSystemCopyCapability
- capability = reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability));
-#else
- capability = nil;
-#endif
-
- if (capability != nil && (
- [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]) {
-#if LogBrowser
- NSLog(@"itms#%@#%u#%@", url, store, itms);
-#endif
-
- if (capability != nil && (
- 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 swap:YES])
- 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) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
- NSString *context([sheet context]);
-
- if ([context isEqualToString:@"alert"]) {
- [self autorelease];
- [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:@"sensitive"]) {
- switch (button) {
- case 1:
- sensitive_ = [NSNumber numberWithBool:YES];
- break;
-
- case 2:
- sensitive_ = [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) {
- WebThreadLock();
- [webview_ loadRequest:request_];
- WebThreadUnlock();
- }
- 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:CYLocalize("LOGIN"), CYLocalize("CANCEL"), nil]
- defaultButtonIndex:0
- delegate:self
- context:@"challenge"
- ] autorelease];
-
- [sheet setNumberOfRows:1];
-
- [sheet addTextFieldWithValue:@"" label:CYLocalize("USERNAME")];
- [sheet addTextFieldWithValue:@"" label:CYLocalize("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 {
- return [self _addHeadersToRequest:request];
-}
-
-- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features {
-//- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request userGesture:(BOOL)gesture {
-#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 ? 0 : [value floatValue]);
-
- RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
-
- /* XXX: deal with cydia:// pages */
- BrowserView *browser([[[BrowserView alloc] initWithBook:book forWidth:width] autorelease]);
-
- if (features != nil && popup_) {
- [book setDelegate:delegate_];
- [book setHook:indirect_];
- [browser setDelegate:delegate_];
-
- [browser loadRequest:request];
-
- [book setPage:browser];
- [book_ pushBook:book];
- } else if (request == nil) {
- [self setBackButtonTitle:title_];
- [browser setDelegate:delegate_];
- [browser retain];
- } else {
- [self pushPage:browser];
- [browser loadRequest:request];
- }
-
- return [browser webView];
-}
-
-- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {
- return [self webView:sender createWebViewWithRequest:request windowFeatures:nil];
- //return [self webView:sender createWebViewWithRequest:request userGesture: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 ([loading_ count] == 0)
- [self retain];
- [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
-
- if ([frame parentFrame] == nil) {
- [webview_ resignFirstResponder];
-
- reloading_ = false;
-
- 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;
- }
-
- if (finish_ != nil) {
- [finish_ release];
- finish_ = nil;
- }
-
- if (closer_ != nil) {
- [closer_ release];
- closer_ = nil;
- }
-
- if (special_ != nil) {
- [special_ release];
- special_ = nil;
- }
-
- [book_ reloadTitleForPage:self];
-
- [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
-
- if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)])
- [scroller_ setZoomScale:1 duration:0];
- else if ([scroller_ respondsToSelector:@selector(_setZoomScale:duration:)])
- [scroller_ _setZoomScale:1 duration:0];
- /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
- [scroller_ setZoomScale:1 animated:NO];*/
-
- CGRect webrect = [scroller_ bounds];
- webrect.size.height = 0;
- [webview_ setFrame:webrect];
- }
-
- [self reloadButtons];
-}
-
-- (void) _finishLoading {
- size_t count([loading_ count]);
- if (count == 0)
- [self autorelease];
- if (reloading_ || count != 0)
- return;
- if (finish_ != nil)
- [self callFunction:finish_];
- [self reloadButtons];
-}
-
-- (bool) isLoading {
- return [loading_ count] != 0;
-}
-
-- (void) reloadButtons {
- if ([self isLoading])
- [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 {
- [self _pushPage];
- 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 {
- [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
- [self _finishLoading];
-
- if ([frame parentFrame] == nil) {
- 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"])) {
- if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
- DOMRGBColor *rgb([color getRGBColorValue]);
-
- float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
- float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
- float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
- float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
-
- UIColor *uic(nil);
-
- if (red == 0xc7 && green == 0xce && blue == 0xd5)
- uic = [UIColor pinStripeColor];
- else if (alpha != 0)
- uic = [UIColor
- colorWithRed:(red / 255)
- green:(green / 255)
- blue:(blue / 255)
- alpha:alpha
- ];
-
- if (uic != nil) {
- colored = true;
- [scroller_ setBackgroundColor:uic];
- }
- }
- }
-
- if (!colored)
- [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
- break;
- }
- }
-
- return [webview_ webView:sender didFinishLoadForFrame:frame];
-}
-
-- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
- if ([frame parentFrame] == nil)
- [self autorelease];
-
- [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
- [self _finishLoading];
-
- if (reloading_)
- return;
-
- if ([frame parentFrame] == nil) {
- [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
- [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
- [[error localizedDescription] stringByAddingPercentEscapes]
- ]]];
-
- error_ = true;
- }
-}
-
-- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
- [self _didFailWithError:error forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
- [self _didFailWithError:error forFrame:frame];
-}
-
-- (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
-#if LogBrowser || ForSaurik
- lprintf("Console:%s\n", [[dictionary description] UTF8String]);
-#endif
-}
-
-/* XXX: fix this stupid include file
-- (void) webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)database {
- [origin setQuota:0x500000];
-}*/
-
-- (void) _setTileDrawingEnabled:(BOOL)enabled {
- //[webview_ setTileDrawingEnabled:enabled];
-}
-
-- (void) setViewportWidth:(float)width {
- width_ = width ? width != 0 : [[self class] defaultWidth];
- [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
-}
-
-- (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
- [self _setTileDrawingEnabled:NO];
-}
-
-- (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
- [self _setTileDrawingEnabled:YES];
- [webview_ redrawScaledDocument];
-}
-
-- (void) scrollerWillStartDragging:(UIScroller *)scroller {
- [self _setTileDrawingEnabled:NO];
-}
-
-- (void) scrollerDidEndDragging:(UIScroller *)scroller willSmoothScroll:(BOOL)smooth {
- [self _setTileDrawingEnabled:YES];
-}
-
-- (void) scrollerDidEndDragging:(UIScroller *)scroller {
- [self _setTileDrawingEnabled:YES];
-}
-
-- (id) initWithBook:(RVBook *)book forWidth:(float)width {
- if ((self = [super initWithBook:book]) != nil) {
- loading_ = [[NSMutableSet alloc] initWithCapacity:3];
- popup_ = false;
-
- struct CGRect bounds = [self bounds];
-
- scroller_ = [[UIScroller alloc] initWithFrame:bounds];
- [self addSubview:scroller_];
-
- [scroller_ setFixedBackgroundPattern:YES];
- [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
-
- [scroller_ setScrollingEnabled:YES];
- [scroller_ setClipsSubviews:YES];
- [scroller_ setAllowsRubberBanding:YES];
-
- [scroller_ setDelegate:self];
- [scroller_ setBounces:YES];
- [scroller_ setScrollHysteresis:8];
- [scroller_ setThumbDetectionEnabled:NO];
- [scroller_ setDirectionalScrolling:YES];
- [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */
- [scroller_ setEventMode:YES];
- [scroller_ setShowBackgroundShadow:NO]; /* YES */
- [scroller_ setAllowsRubberBanding:YES]; /* Vertical */
- [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
-
- CGRect webrect = [scroller_ bounds];
- webrect.size.height = 0;
-
- WebView *webview;
-
- WebThreadLock();
-
-#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];
- if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
- /* XXX: abstractify */
- [webview_ setDataDetectorTypes:0x80000000];
- else
- [webview_ setDetectsPhoneNumbers:NO];
- [webview_ setAutoresizes:YES];
-
- [webview_ setMinimumScale:0.25f forDocumentTypes:0x10];
- [webview_ setMaximumScale:5.00f forDocumentTypes:0x10];
- [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
- //[webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
-
- [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
-
- [webview_ setMinimumScale:1.00f forDocumentTypes:0x8];
- [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
- [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
-
- [webview_ _setDocumentType:0x4];
-
- if ([webview_ respondsToSelector:@selector(UIWebDocumentView:)])
- [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_ setAllowsImageSheet:YES];
- [webview _setUsesLoaderCache:YES];
-
- [webview setGroupName:@"CydiaGroup"];
- if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
- [webview _setLayoutInterval:0];
- }
-
- [self setViewportWidth:width];
-
- [webview_ setDelegate:self];
- [webview_ setGestureDelegate:self];
- [webview_ setFormEditingDelegate:self];
- [webview_ setInteractionDelegate:self];
-
- [scroller_ addSubview:webview_];
-
- //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
-
- Package *package([[Database sharedInstance] packageWithName:@"cydia"]);
- NSString *application = package == nil ? @"Cydia" : [NSString
- stringWithFormat:@"Cydia/%@",
- [package installed]
- ];
-
- if (Product_ != nil)
- application = [NSString stringWithFormat:@"%@ Version/%@", application, Product_];
- if (Build_ != nil)
- application = [NSString stringWithFormat:@"%@ Mobile/%@", application, Build_];
- if (Safari_ != nil)
- application = [NSString stringWithFormat:@"%@ Safari/%@", application, Safari_];
-
- [webview setApplicationNameForUserAgent:application];
-
- indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
- cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_];
-
- [webview setFrameLoadDelegate:indirect_];
- [webview setResourceLoadDelegate:indirect_];
- [webview setUIDelegate:indirect_];
- [webview setScriptDebugDelegate:indirect_];
- [webview setPolicyDelegate:indirect_];
-
- WebThreadUnlock();
-
- CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
- indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
- [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
-
- [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
- [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
-
- /*UIWebView *test([[[UIWebView alloc] initWithFrame:[self bounds]] autorelease]);
- [test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]];
- [self addSubview:test];*/
- } return self;
-}
-
-- (id) initWithBook:(RVBook *)book {
- return [self initWithBook:book forWidth:0];
-}
-
-- (NSString *) stringByEvaluatingJavaScriptFromString:(NSString *)script {
- WebThreadLock();
- WebView *webview([webview_ webView]);
- NSString *string([webview stringByEvaluatingJavaScriptFromString:script]);
- WebThreadUnlock();
- return string;
-}
-
-- (void) callFunction:(WebScriptObject *)function {
- WebThreadLock();
-
- 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 object([function JSObject]);
- JSGlobalContextRef context([frame globalContext]);
- JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
-
- if (settings != NULL)
- settings->setJavaScriptCanOpenWindowsAutomatically(no);
-
- WebThreadUnlock();
-}
-
-- (void) didCloseBook:(RVBook *)book {
- if (closer_ != nil)
- [self callFunction:closer_];
-}
-
-- (void) __rightButtonClicked {
- reloading_ = true;
- [self reloadURL];
-}
-
-- (void) _rightButtonClicked {
-#if !AlwaysReload
- if (function_ != nil)
- [self callFunction:function_];
- else
-#endif
- [self __rightButtonClicked];
-}
-
-- (id) _rightButtonTitle {
- return CYLocalize("RELOAD");
-}
-
-- (id) rightButtonTitle {
- return [self isLoading] ? @"" : button_ != nil ? button_ : [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 ? CYLocalize("LOADING") : title_;
-}
-
-- (NSString *) backButtonTitle {
- return CYLocalize("BROWSER");
-}
-
-- (void) setPageActive:(BOOL)active {
- if (!active)
- [indicator_ removeFromSuperview];
- else
- [[book_ navigationBar] addSubview:indicator_];
-}
-
-- (void) resetViewAnimated:(BOOL)animated {
-}
-
-- (void) setPushed:(bool)pushed {
- pushed_ = pushed;
-}
-
-+ (float) defaultWidth {
- return 980;
-}
-
-@end
--- /dev/null
+#include <BrowserView.h>
+#include <UCLocalize.h>
+
+#import <QuartzCore/CALayer.h>
+// XXX: fix the minimum requirement
+extern NSString * const kCAFilterNearest;
+
+#include <WebCore/WebCoreThread.h>
+
+#include "substrate.h"
+
+@interface NSString (UIKit)
+- (NSString *) stringByAddingPercentEscapes;
+@end
+
+/* Indirect Delegate {{{ */
+@interface IndirectDelegate : NSObject {
+ _transient volatile id delegate_;
+}
+
+- (void) setDelegate:(id)delegate;
+- (id) initWithDelegate:(id)delegate;
+@end
+
+@implementation IndirectDelegate
+
+- (void) setDelegate:(id)delegate {
+ delegate_ = delegate;
+}
+
+- (id) initWithDelegate:(id)delegate {
+ delegate_ = delegate;
+ return self;
+}
+
+- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender didClearWindowObject:window forFrame:frame];
+}
+
+- (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender didCommitLoadForFrame:frame];
+}
+
+- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender didFailLoadWithError:error forFrame:frame];
+}
+
+- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame];
+}
+
+- (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender didFinishLoadForFrame:frame];
+}
+
+- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender didReceiveTitle:title forFrame:frame];
+}
+
+- (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame];
+}
+
+- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source];
+}
+
+- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
+ if (delegate_ != nil)
+ return [delegate_ webView:sender resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:source];
+ return nil;
+}
+
+- (IMP) methodForSelector:(SEL)sel {
+ if (IMP method = [super methodForSelector:sel])
+ return method;
+ fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
+ return NULL;
+}
+
+- (BOOL) respondsToSelector:(SEL)sel {
+ if ([super respondsToSelector:sel])
+ return YES;
+ // XXX: WebThreadCreateNSInvocation returns nil
+ //fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
+ return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
+}
+
+- (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
+ if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
+ return method;
+ //fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
+ if (delegate_ != nil)
+ if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
+ return sig;
+ // XXX: I fucking hate Apple so very very bad
+ return [NSMethodSignature signatureWithObjCTypes:"v@:"];
+}
+
+- (void) forwardInvocation:(NSInvocation *)inv {
+ SEL sel = [inv selector];
+ if (delegate_ != nil && [delegate_ respondsToSelector:sel])
+ [inv invokeWithTarget:delegate_];
+}
+
+@end
+/* }}} */
+
+@interface WebView (UICaboodle)
+- (void) setScriptDebugDelegate:(id)delegate;
+- (void) _setFormDelegate:(id)delegate;
+- (void) _setUIKitDelegate:(id)delegate;
+- (void) setWebMailDelegate:(id)delegate;
+- (void) _setLayoutInterval:(float)interval;
+@end
+
+@implementation WebScriptObject (UICaboodle)
+
+- (unsigned) count {
+ id length([self valueForKey:@"length"]);
+ if ([length respondsToSelector:@selector(intValue)])
+ return [length intValue];
+ else
+ return 0;
+}
+
+- (id) objectAtIndex:(unsigned)index {
+ return [self webScriptValueAtIndex:index];
+}
+
+@end
+
+#if 0
+/* Mail Composition {{{ */
+@interface MailToView : PopUpView {
+ MailComposeController *controller_;
+}
+
+- (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url;
+
+@end
+
+@implementation MailToView
+
+- (void) dealloc {
+ [controller_ release];
+ [super dealloc];
+}
+
+- (void) mailComposeControllerWillAttemptToSend:(MailComposeController *)controller {
+ NSLog(@"will");
+}
+
+- (void) mailComposeControllerDidAttemptToSend:(MailComposeController *)controller mailDelivery:(id)delivery {
+ NSLog(@"did:%@", delivery);
+// [UIApp setStatusBarShowsProgress:NO];
+if ([controller error]){
+NSArray *buttons = [NSArray arrayWithObjects:UCLocalize("OK"), nil];
+UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self];
+[mailAlertSheet setBodyText:[controller error]];
+[mailAlertSheet popupAlertAnimated:YES];
+}
+}
+
+- (void) showError {
+ NSLog(@"%@", [controller_ error]);
+ NSArray *buttons = [NSArray arrayWithObjects:UCLocalize("OK"), nil];
+ UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self];
+ [mailAlertSheet setBodyText:[controller_ error]];
+ [mailAlertSheet popupAlertAnimated:YES];
+}
+
+- (void) deliverMessage { _pooled
+ setuid(501);
+ setgid(501);
+
+ if (![controller_ deliverMessage])
+ [self performSelectorOnMainThread:@selector(showError) withObject:nil waitUntilDone:NO];
+}
+
+- (void) mailComposeControllerCompositionFinished:(MailComposeController *)controller {
+ if ([controller_ needsDelivery])
+ [NSThread detachNewThreadSelector:@selector(deliverMessage) toTarget:self withObject:nil];
+ else
+ [self cancel];
+}
+
+- (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url {
+ if ((self = [super initWithView:view delegate:delegate]) != nil) {
+ controller_ = [[MailComposeController alloc] initForContentSize:[overlay_ bounds].size];
+ [controller_ setDelegate:self];
+ [controller_ initializeUI];
+ [controller_ setupForURL:url];
+
+ UIView *view([controller_ view]);
+ [overlay_ addSubview:view];
+ } return self;
+}
+
+@end
+/* }}} */
+#endif
+
+@implementation BrowserView
+
+#if ShowInternals
+#include "Internals.h"
+#endif
+
+- (void) dealloc {
+#if LogBrowser
+ NSLog(@"[BrowserView dealloc]");
+#endif
+
+ if (challenge_ != nil)
+ [challenge_ release];
+
+ WebThreadLock();
+
+ WebView *webview = [webview_ webView];
+ [webview setFrameLoadDelegate:nil];
+ [webview setResourceLoadDelegate:nil];
+ [webview setUIDelegate:nil];
+ [webview setScriptDebugDelegate:nil];
+ [webview setPolicyDelegate:nil];
+
+ [webview setDownloadDelegate:nil];
+
+ /* XXX: these are set by UIWebDocumentView
+ [webview _setFormDelegate:nil];
+ [webview _setUIKitDelegate:nil];
+ [webview setEditingDelegate:nil];*/
+
+ /* XXX: no one sets this, ever
+ [webview setWebMailDelegate:nil];*/
+
+ [webview_ setDelegate:nil];
+ [webview_ setGestureDelegate:nil];
+ [webview_ setFormEditingDelegate:nil];
+ [webview_ setInteractionDelegate:nil];
+
+ [indirect_ setDelegate:nil];
+
+ //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ [webview close];
+
+#if RecycleWebViews
+ [webview_ removeFromSuperview];
+ [Documents_ addObject:[webview_ autorelease]];
+#else
+ [webview_ release];
+#endif
+
+ [indirect_ release];
+
+ WebThreadUnlock();
+
+ [scroller_ setDelegate:nil];
+
+ if (button_ != nil)
+ [button_ release];
+ if (style_ != nil)
+ [style_ release];
+ if (function_ != nil)
+ [function_ release];
+ if (finish_ != nil)
+ [finish_ release];
+ if (closer_ != nil)
+ [closer_ release];
+ if (special_ != nil)
+ [special_ release];
+
+ [scroller_ release];
+ [indicator_ release];
+ if (confirm_ != nil)
+ [confirm_ release];
+ if (sensitive_ != nil)
+ [sensitive_ 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];
+}
+
+- (void) loadRequest:(NSURLRequest *)request {
+ pushed_ = true;
+ error_ = false;
+
+ WebThreadLock();
+ [webview_ loadRequest:request];
+ WebThreadUnlock();
+}
+
+- (void) reloadURL {
+ if (request_ == nil)
+ return;
+
+ if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
+ [self loadRequest:request_];
+ else {
+ UIActionSheet *sheet = [[[UIActionSheet alloc]
+ initWithTitle:UCLocalize("RESUBMIT_FORM")
+ buttons:[NSArray arrayWithObjects:UCLocalize("CANCEL"), UCLocalize("SUBMIT"), nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:@"submit"
+ ] autorelease];
+
+ [sheet setNumberOfRows:1];
+ [sheet popupAlertAnimated:YES];
+ }
+}
+
+- (WebView *) webView {
+ return [webview_ webView];
+}
+
+- (UIWebDocumentView *) documentView {
+ return webview_;
+}
+
+/* XXX: WebThreadLock? */
+- (void) _fixScroller:(CGRect)bounds {
+ 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;
+ }
+
+ CGRect subrect([scroller_ frame]);
+ 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) fixScroller {
+ CGRect bounds([webview_ documentBounds]);
+#if TrackResize
+ NSLog(@"_fs:(%f,%f+%f,%f)", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
+#endif
+ [self _fixScroller:bounds];
+}
+
+- (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
+ size_ = frame.size;
+#if TrackResize
+ NSLog(@"dsf:(%f,%f+%f,%f)", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
+#endif
+ [self _fixScroller:frame];
+}
+
+- (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
+ [self view:sender didSetFrame:frame];
+}
+
+- (void) pushPage:(RVPage *)page {
+ [page setDelegate:delegate_];
+ [self setBackButtonTitle:title_];
+ [book_ pushPage:page];
+}
+
+- (void) _pushPage {
+ if (pushed_)
+ return;
+ // WTR: [self autorelease];
+ pushed_ = true;
+ [book_ pushPage:self];
+}
+
+- (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
+
+ if (RVPage *page = [delegate_ pageForURL:url hasTag:NULL]) {
+ if (swap)
+ [self swapPage:page];
+ else
+ [self pushPage:page];
+
+ return true;
+ } else
+ return false;
+}
+
+- (void) webViewShow:(WebView *)sender {
+ /* XXX: this is where I cry myself to sleep */
+}
+
+- (bool) _allowJavaScriptPanel {
+ return true;
+}
+
+- (bool) allowSensitiveRequests {
+ return [self _allowJavaScriptPanel];
+}
+
+- (void) _promptForSensitive:(NSMutableArray *)array {
+ NSString *name([array objectAtIndex:0]);
+
+ UIActionSheet *sheet = [[[UIActionSheet alloc]
+ initWithTitle:nil
+ buttons:[NSArray arrayWithObjects:UCLocalize("YES"), UCLocalize("NO"), nil]
+ defaultButtonIndex:0
+ delegate:indirect_
+ context:@"sensitive"
+ ] autorelease];
+
+ NSString *host(@"XXX");
+
+ [sheet setNumberOfRows:1];
+ [sheet setBodyText:[NSString stringWithFormat:@"The website at %@ is requesting your phone's %@. This is almost certainly for product licensing purposes. Will you allow this?", host, name]];
+ [sheet popupAlertAnimated:YES];
+
+ NSRunLoop *loop([NSRunLoop currentRunLoop]);
+ NSDate *future([NSDate distantFuture]);
+
+ while (sensitive_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
+
+ NSNumber *sensitive([sensitive_ autorelease]);
+ sensitive_ = nil;
+
+ [self autorelease];
+ [array replaceObjectAtIndex:0 withObject:sensitive];
+}
+
+- (bool) promptForSensitive:(NSString *)name {
+ if (![self allowSensitiveRequests])
+ return false;
+
+ NSMutableArray *array([NSMutableArray arrayWithCapacity:1]);
+ [array addObject:name];
+
+ [self performSelectorOnMainThread:@selector(_promptForSensitive:) withObject:array waitUntilDone:YES];
+ return [[array lastObject] boolValue];
+}
+
+- (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
+ if (![self _allowJavaScriptPanel])
+ return;
+ [self retain];
+
+ UIActionSheet *sheet = [[[UIActionSheet alloc]
+ initWithTitle:nil
+ buttons:[NSArray arrayWithObjects:UCLocalize("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 {
+ if (![self _allowJavaScriptPanel])
+ return NO;
+ [self retain];
+
+ UIActionSheet *sheet = [[[UIActionSheet alloc]
+ initWithTitle:nil
+ buttons:[NSArray arrayWithObjects:UCLocalize("OK"), UCLocalize("CANCEL"), nil]
+ defaultButtonIndex:0
+ delegate:indirect_
+ 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;
+
+ [self autorelease];
+ return [confirm boolValue];
+}
+
+- (void) setAutoPopup:(BOOL)popup {
+ popup_ = popup;
+}
+
+- (void) setSpecial:(id)function {
+ if (special_ != nil)
+ [special_ autorelease];
+ special_ = function == nil ? nil : [function retain];
+}
+
+- (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];
+
+ [self reloadButtons];
+}
+
+- (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];
+
+ [self reloadButtons];
+}
+
+- (void) setFinishHook:(id)function {
+ if (finish_ != nil)
+ [finish_ autorelease];
+ finish_ = function == nil ? nil : [function retain];
+}
+
+- (void) setPopupHook:(id)function {
+ if (closer_ != nil)
+ [closer_ autorelease];
+ closer_ = function == nil ? nil : [function retain];
+}
+
+- (void) _openMailToURL:(NSURL *)url {
+// XXX: this makes me sad
+#if 0
+ [[[MailToView alloc] initWithView:underlay_ delegate:self url:url] autorelease];
+#else
+ [UIApp openURL:url];// asPanel:YES];
+#endif
+}
+
+- (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
+ editing_ = true;
+}
+
+- (void) webView:(WebView *)sender didBeginEditingFormElement:(id)element {
+ [self fixScroller];
+}
+
+- (void) webViewDidEndEditingFormElements:(WebView *)sender {
+ editing_ = false;
+ [self fixScroller];
+}
+
+- (void) webViewClose:(WebView *)sender {
+ [book_ close];
+}
+
+- (void) close {
+ [book_ close];
+}
+
+- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+}
+
+- (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 LogBrowser
+ NSLog(@"nwa:%@", name);
+#endif
+
+ if (NSURL *url = [request URL]) {
+ if (name == nil) unknown: {
+ if (![self getSpecial:url swap:NO]) {
+ NSString *scheme([[url scheme] lowercaseString]);
+ if ([scheme isEqualToString:@"mailto"])
+ [self _openMailToURL:url];
+ else goto use;
+ }
+ } else if ([name isEqualToString:@"_open"])
+ [delegate_ openURL:url];
+ else if ([name isEqualToString:@"_popup"]) {
+ NSString *scheme([[url scheme] lowercaseString]);
+ if ([scheme isEqualToString:@"mailto"])
+ [self _openMailToURL:url];
+ else {
+ RVBook *book([[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
+ [book setHook:indirect_];
+
+ RVPage *page([delegate_ pageForURL:url hasTag:NULL]);
+ if (page == nil) {
+ /* XXX: call createWebViewWithRequest instead? */
+
+ [self setBackButtonTitle:title_];
+
+ BrowserView *browser([[[BrowserView alloc] initWithBook:book] autorelease]);
+ [browser loadURL:url];
+ page = browser;
+ }
+
+ [book setDelegate:delegate_];
+ [page setDelegate:delegate_];
+
+ [book setPage:page];
+ [book_ pushBook:book];
+ }
+ } else goto unknown;
+
+ [listener ignore];
+ } else use:
+ [listener use];
+}
+
+- (void) webView:(WebView *)sender 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];
+
+ WebView *webview([webview_ webView]);
+ 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 (!error_ && [frame parentFrame] == nil) {
+ if (request_ != nil)
+ [request_ autorelease];
+ request_ = [request retain];
+#if LogBrowser
+ NSLog(@"dpn:%@", request_);
+#endif
+ }
+
+ [listener use];
+
+ WebView *webview([webview_ webView]);
+ if (frame == [webview mainFrame])
+ [self _pushPage];
+ return;
+ }
+#if LogBrowser
+ else NSLog(@"nav:%@:%@", url, [action description]);
+#endif
+
+ const NSArray *capability;
+
+#if 0 // XXX:3:GSSystemCopyCapability
+ capability = reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability));
+#else
+ capability = nil;
+#endif
+
+ if (capability != nil && (
+ [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]) {
+#if LogBrowser
+ NSLog(@"itms#%@#%u#%@", url, store, itms);
+#endif
+
+ if (capability != nil && (
+ 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"]) {
+ [self _openMailToURL:url];
+ goto ignore;
+ }
+
+ if ([self getSpecial:url swap:YES])
+ 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) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
+ NSString *context([sheet context]);
+
+ if ([context isEqualToString:@"alert"]) {
+ [self autorelease];
+ [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:@"sensitive"]) {
+ switch (button) {
+ case 1:
+ sensitive_ = [NSNumber numberWithBool:YES];
+ break;
+
+ case 2:
+ sensitive_ = [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) {
+ WebThreadLock();
+ [webview_ loadRequest:request_];
+ WebThreadUnlock();
+ }
+ 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:UCLocalize("LOGIN"), UCLocalize("CANCEL"), nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:@"challenge"
+ ] autorelease];
+
+ [sheet setNumberOfRows:1];
+
+ [sheet addTextFieldWithValue:@"" label:UCLocalize("USERNAME")];
+ [sheet addTextFieldWithValue:@"" label:UCLocalize("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 {
+ return request;
+}
+
+- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features {
+//- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request userGesture:(BOOL)gesture {
+#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 ? 0 : [value floatValue]);
+
+ RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
+
+ /* XXX: deal with cydia:// pages */
+ BrowserView *browser([[[BrowserView alloc] initWithBook:book forWidth:width] autorelease]);
+
+ if (features != nil && popup_) {
+ [book setDelegate:delegate_];
+ [book setHook:indirect_];
+ [browser setDelegate:delegate_];
+
+ [browser loadRequest:request];
+
+ [book setPage:browser];
+ [book_ pushBook:book];
+ } else if (request == nil) {
+ [self setBackButtonTitle:title_];
+ [browser setDelegate:delegate_];
+ [browser retain];
+ } else {
+ [self pushPage:browser];
+ [browser loadRequest:request];
+ }
+
+ return [browser webView];
+}
+
+- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {
+ return [self webView:sender createWebViewWithRequest:request windowFeatures:nil];
+ //return [self webView:sender createWebViewWithRequest:request userGesture: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 ([loading_ count] == 0)
+ [self retain];
+ [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
+
+ if ([frame parentFrame] == nil) {
+ [webview_ resignFirstResponder];
+
+ reloading_ = false;
+
+ 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;
+ }
+
+ if (finish_ != nil) {
+ [finish_ release];
+ finish_ = nil;
+ }
+
+ if (closer_ != nil) {
+ [closer_ release];
+ closer_ = nil;
+ }
+
+ if (special_ != nil) {
+ [special_ release];
+ special_ = nil;
+ }
+
+ [book_ reloadTitleForPage:self];
+
+ [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
+
+ if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)])
+ [scroller_ setZoomScale:1 duration:0];
+ else if ([scroller_ respondsToSelector:@selector(_setZoomScale:duration:)])
+ [scroller_ _setZoomScale:1 duration:0];
+ /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
+ [scroller_ setZoomScale:1 animated:NO];*/
+
+ CGRect webrect = [scroller_ bounds];
+ webrect.size.height = 0;
+ [webview_ setFrame:webrect];
+ }
+
+ [self reloadButtons];
+}
+
+- (void) _finishLoading {
+ size_t count([loading_ count]);
+ if (count == 0)
+ [self autorelease];
+ if (reloading_ || count != 0)
+ return;
+ if (finish_ != nil)
+ [self callFunction:finish_];
+ [self reloadButtons];
+}
+
+- (bool) isLoading {
+ return [loading_ count] != 0;
+}
+
+- (void) reloadButtons {
+ if ([self isLoading])
+ [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 {
+ [self _pushPage];
+ 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 {
+ [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
+ [self _finishLoading];
+
+ if ([frame parentFrame] == nil) {
+ 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"])) {
+ if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
+ DOMRGBColor *rgb([color getRGBColorValue]);
+
+ float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
+ float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
+ float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
+ float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
+
+ UIColor *uic(nil);
+
+ if (red == 0xc7 && green == 0xce && blue == 0xd5)
+ uic = [UIColor pinStripeColor];
+ else if (alpha != 0)
+ uic = [UIColor
+ colorWithRed:(red / 255)
+ green:(green / 255)
+ blue:(blue / 255)
+ alpha:alpha
+ ];
+
+ if (uic != nil) {
+ colored = true;
+ [scroller_ setBackgroundColor:uic];
+ }
+ }
+ }
+
+ if (!colored)
+ [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
+ break;
+ }
+ }
+
+ return [webview_ webView:sender didFinishLoadForFrame:frame];
+}
+
+- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
+ if ([frame parentFrame] == nil)
+ [self autorelease];
+
+ [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
+ [self _finishLoading];
+
+ if (reloading_)
+ return;
+
+ if ([frame parentFrame] == nil) {
+ [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
+ [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
+ [[error localizedDescription] stringByAddingPercentEscapes]
+ ]]];
+
+ error_ = true;
+ }
+}
+
+- (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
+ [self _didFailWithError:error forFrame:frame];
+}
+
+- (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
+ [self _didFailWithError:error forFrame:frame];
+}
+
+- (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
+#if LogBrowser || ForSaurik
+ lprintf("Console:%s\n", [[dictionary description] UTF8String]);
+#endif
+}
+
+/* XXX: fix this stupid include file
+- (void) webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)database {
+ [origin setQuota:0x500000];
+}*/
+
+- (void) _setTileDrawingEnabled:(BOOL)enabled {
+ //[webview_ setTileDrawingEnabled:enabled];
+}
+
+- (void) setViewportWidth:(float)width {
+ width_ = width ? width != 0 : [[self class] defaultWidth];
+ [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+}
+
+- (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
+ [self _setTileDrawingEnabled:NO];
+}
+
+- (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
+ [self _setTileDrawingEnabled:YES];
+ [webview_ redrawScaledDocument];
+}
+
+- (void) scrollerWillStartDragging:(UIScroller *)scroller {
+ [self _setTileDrawingEnabled:NO];
+}
+
+- (void) scrollerDidEndDragging:(UIScroller *)scroller willSmoothScroll:(BOOL)smooth {
+ [self _setTileDrawingEnabled:YES];
+}
+
+- (void) scrollerDidEndDragging:(UIScroller *)scroller {
+ [self _setTileDrawingEnabled:YES];
+}
+
+- (id) initWithBook:(RVBook *)book forWidth:(float)width {
+ if ((self = [super initWithBook:book]) != nil) {
+ loading_ = [[NSMutableSet alloc] initWithCapacity:3];
+ popup_ = false;
+
+ struct CGRect bounds = [self bounds];
+
+ scroller_ = [[UIScroller alloc] initWithFrame:bounds];
+ [self addSubview:scroller_];
+
+ [scroller_ setFixedBackgroundPattern:YES];
+ [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
+
+ [scroller_ setScrollingEnabled:YES];
+ [scroller_ setClipsSubviews:YES];
+ [scroller_ setAllowsRubberBanding:YES];
+
+ [scroller_ setDelegate:self];
+ [scroller_ setBounces:YES];
+ [scroller_ setScrollHysteresis:8];
+ [scroller_ setThumbDetectionEnabled:NO];
+ [scroller_ setDirectionalScrolling:YES];
+ [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */
+ [scroller_ setEventMode:YES];
+ [scroller_ setShowBackgroundShadow:NO]; /* YES */
+ [scroller_ setAllowsRubberBanding:YES]; /* Vertical */
+ [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
+
+ CGRect webrect = [scroller_ bounds];
+ webrect.size.height = 0;
+
+ WebView *webview;
+
+ WebThreadLock();
+
+#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];
+ if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
+ /* XXX: abstractify */
+ [webview_ setDataDetectorTypes:0x80000000];
+ else
+ [webview_ setDetectsPhoneNumbers:NO];
+ [webview_ setAutoresizes:YES];
+
+ [webview_ setMinimumScale:0.25f forDocumentTypes:0x10];
+ [webview_ setMaximumScale:5.00f forDocumentTypes:0x10];
+ [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
+ //[webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+
+ [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
+
+ [webview_ setMinimumScale:1.00f forDocumentTypes:0x8];
+ [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
+ [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
+
+ [webview_ _setDocumentType:0x4];
+
+ if ([webview_ respondsToSelector:@selector(UIWebDocumentView:)])
+ [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_ setAllowsImageSheet:YES];
+ [webview _setUsesLoaderCache:YES];
+
+ [webview setGroupName:@"CydiaGroup"];
+ if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
+ [webview _setLayoutInterval:0];
+ }
+
+ [self setViewportWidth:width];
+
+ [webview_ setDelegate:self];
+ [webview_ setGestureDelegate:self];
+ [webview_ setFormEditingDelegate:self];
+ [webview_ setInteractionDelegate:self];
+
+ [scroller_ addSubview:webview_];
+
+ //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+
+ indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
+
+ [webview setFrameLoadDelegate:indirect_];
+ [webview setResourceLoadDelegate:indirect_];
+ [webview setUIDelegate:indirect_];
+ [webview setScriptDebugDelegate:indirect_];
+ [webview setPolicyDelegate:indirect_];
+
+ WebThreadUnlock();
+
+ CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
+ indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
+ [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
+
+ [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
+ [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
+
+ /*UIWebView *test([[[UIWebView alloc] initWithFrame:[self bounds]] autorelease]);
+ [test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]];
+ [self addSubview:test];*/
+ } return self;
+}
+
+- (id) initWithBook:(RVBook *)book {
+ return [self initWithBook:book forWidth:0];
+}
+
+- (NSString *) stringByEvaluatingJavaScriptFromString:(NSString *)script {
+ WebThreadLock();
+ WebView *webview([webview_ webView]);
+ NSString *string([webview stringByEvaluatingJavaScriptFromString:script]);
+ WebThreadUnlock();
+ return string;
+}
+
+- (void) callFunction:(WebScriptObject *)function {
+ WebThreadLock();
+
+ 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);
+ }
+
+ if (UIWindow *window = [self window])
+ if (UIResponder *responder = [window firstResponder])
+ [responder resignFirstResponder];
+
+ JSObjectRef object([function JSObject]);
+ JSGlobalContextRef context([frame globalContext]);
+ JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
+
+ if (settings != NULL)
+ settings->setJavaScriptCanOpenWindowsAutomatically(no);
+
+ WebThreadUnlock();
+}
+
+- (void) didCloseBook:(RVBook *)book {
+ if (closer_ != nil)
+ [self callFunction:closer_];
+}
+
+- (void) __rightButtonClicked {
+ reloading_ = true;
+ [self reloadURL];
+}
+
+- (void) _rightButtonClicked {
+#if !AlwaysReload
+ if (function_ != nil)
+ [self callFunction:function_];
+ else
+#endif
+ [self __rightButtonClicked];
+}
+
+- (id) _rightButtonTitle {
+ return UCLocalize("RELOAD");
+}
+
+- (id) rightButtonTitle {
+ return [self isLoading] ? @"" : button_ != nil ? button_ : [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 ? UCLocalize("LOADING") : title_;
+}
+
+- (NSString *) backButtonTitle {
+ return UCLocalize("BROWSER");
+}
+
+- (void) setPageActive:(BOOL)active {
+ if (!active)
+ [indicator_ removeFromSuperview];
+ else
+ [[book_ navigationBar] addSubview:indicator_];
+}
+
+- (void) resetViewAnimated:(BOOL)animated {
+}
+
+- (void) setPushed:(bool)pushed {
+ pushed_ = pushed;
+}
+
++ (float) defaultWidth {
+ return 980;
+}
+
+@end
--- /dev/null
+#ifndef UICABOODLE_UCLOCALIZE_H
+#define UICABOODLE_UCLOCALIZE_H
+
+#import <Foundation/Foundation.h>
+
+static inline NSString *UCLocalizeEx(NSString *key, NSString *value = nil) {
+ return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil];
+}
+
+#define UCLocalize(key) UCLocalizeEx(@ key)
+
+#endif/*UICABOODLE_UCLOCALIZE_H*/
Architecture: iphoneos-arm
Version: 1.0.2913-1
Replaces: com.sosiphone.addcydia
-Depends: apr-lib, apt7-lib, apt-key, darwintools, pcre, shell-cmds, system-cmds
+Depends: apr-lib, apt7-lib, apt7-key, darwintools, pcre, shell-cmds, system-cmds
Pre-Depends: dpkg (>= 1.14.25-8)
Conflicts: com.sosiphone.addcydia
Description: graphical iPhone front-end for APT
clean:
rm -f Cydia
-Cydia: Cydia.mm ../uicaboodle.m/*.m ../uicaboodle.m/*.mm ../mobilesubstrate/*.h #makefile
+Cydia: Cydia.mm ../uicaboodle.m/*.mm ../mobilesubstrate/*.h #makefile
$(target)g++ -march=armv6 -mcpu=arm1176jzf-s -mthumb -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 QuartzCore -framework JavaScriptCore -framework WebCore -framework WebKit -lobjc -lapt-pkg -lpcre -fobjc-exceptions -F"$${PKG_ROOT}"/System/Library/PrivateFrameworks -multiply_defined suppress -lapr-1
sign: Cydia