summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2008-12-28 19:30:17 +0000
committerJay Freeman (saurik) <saurik@saurik.com>2010-09-30 07:09:28 +0000
commit374f3d18f0a8adefbb9eca5292ebef10935c09a5 (patch)
tree0f23d32bac8995d83674901e29a70986e1f5218c
parent00e2109e804e55567a7682c902047d532da63033 (diff)
Fixed window.cydia.
-rw-r--r--UICaboodle/BrowserView.h2
-rw-r--r--UICaboodle/BrowserView.m209
-rw-r--r--control2
3 files changed, 124 insertions, 89 deletions
diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h
index a37d326..632528d 100644
--- a/UICaboodle/BrowserView.h
+++ b/UICaboodle/BrowserView.h
@@ -34,12 +34,14 @@
@class Database;
@class IndirectDelegate;
+@class CydiaObject;
@interface BrowserView : RVPage {
UIScroller *scroller_;
UIWebDocumentView *webview_;
UIProgressIndicator *indicator_;
IndirectDelegate *indirect_;
+ CydiaObject *cydia_;
NSURLAuthenticationChallenge *challenge_;
bool error_;
diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m
index 6fe74f4..5cf07c8 100644
--- a/UICaboodle/BrowserView.m
+++ b/UICaboodle/BrowserView.m
@@ -49,6 +49,123 @@
- (void) _setLayoutInterval:(float)interval;
@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;
+}
+
++ (NSString *) webScriptNameForSelector:(SEL)selector {
+ if (selector == @selector(getPackageById:))
+ return @"getPackageById";
+ else if (selector == @selector(setButtonImage:withStyle:toFunction:))
+ return @"setButtonImage";
+ else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
+ return @"setButtonTitle";
+ else if (selector == @selector(supports:))
+ return @"supports";
+ else 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);
+ execlp("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) 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];
+}
+
+@end
+/* }}} */
+
@implementation BrowserView
#if ForSaurik
@@ -90,6 +207,8 @@
[indirect_ setDelegate:nil];
[indirect_ release];
+ [cydia_ release];
+
[scroller_ setDelegate:nil];
if (button_ != nil)
@@ -235,92 +354,6 @@
return [confirm boolValue];
}
-/* Web Scripting {{{ */
-+ (NSString *) webScriptNameForSelector:(SEL)selector {
- if (selector == @selector(getPackageById:))
- return @"getPackageById";
- else if (selector == @selector(setButtonImage:withStyle:toFunction:))
- return @"setButtonImage";
- else if (selector == @selector(setButtonTitle:withStyle:toFunction:))
- return @"setButtonTitle";
- else if (selector == @selector(supports:))
- return @"supports";
- else 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);
- execlp("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) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
if (button_ != nil)
[button_ autorelease];
@@ -348,14 +381,13 @@
[function_ autorelease];
function_ = function == nil ? nil : [function retain];
}
-/* }}} */
- (void) webViewClose:(WebView *)sender {
[book_ close];
}
- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
- [window setValue:indirect_ forKey:@"cydia"];
+ [window setValue:cydia_ forKey:@"cydia"];
}
- (void) webView:(WebView *)sender unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame {
@@ -877,6 +909,7 @@
[webview setApplicationNameForUserAgent:application];
indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
+ cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_];
[webview setFrameLoadDelegate:self];
[webview setResourceLoadDelegate:indirect_];
diff --git a/control b/control
index 7999793..6c73b1c 100644
--- a/control
+++ b/control
@@ -4,7 +4,7 @@ Priority: required
Section: Packaging
Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
Architecture: iphoneos-arm
-Version: 1.0.2676-38
+Version: 1.0.2677-38
Replaces: com.sosiphone.addcydia
Depends: apt, darwintools, pcre, shell-cmds
Conflicts: com.sosiphone.addcydia