]> git.saurik.com Git - cydget.git/commitdiff
Support application URL schemes.
authorJay Freeman (saurik) <saurik@saurik.com>
Fri, 1 Apr 2011 00:11:25 +0000 (00:11 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Fri, 1 Apr 2011 00:11:25 +0000 (00:11 +0000)
LockScreen.mm
makefile
yieldToSelector.h [new file with mode: 0644]
yieldToSelector.mm [new file with mode: 0644]

index 3ad5020ab09f40a59015dde3f9f7c9b1834e625d..5fccd842a2b35a0665202dcc564c80e5f1fc9569 100644 (file)
@@ -75,6 +75,8 @@ extern NSString * const kCAFilterNearest;
 
 #include "SourceCode.h"
 
+#include "yieldToSelector.h"
+
 #include <apr-1/apr_pools.h>
 #include <pcre.h>
 
@@ -191,6 +193,10 @@ class Pcre {
 
 static float CYScrollViewDecelerationRateNormal;
 
+@interface NSURL (Apple)
+- (BOOL) isSpringboardHandledURL;
+@end
+
 @interface UIScrollView (Apple)
 - (void) setDecelerationRate:(float)value;
 - (void) setScrollingEnabled:(BOOL)enabled;
@@ -221,12 +227,31 @@ static float CYScrollViewDecelerationRateNormal;
 
 @end
 
-@implementation CydgetWebView
+MSClassHook(UIApplication)
 
-- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
-    [listener use];
+MSInstanceMessageHook1(void, UIApplication, openURL, NSURL *, url) {
+    [self applicationOpenURL:url];
 }
 
+@implementation NSURL (Cydget)
+
+- (NSNumber *) cydget$isSpringboardHandledURL {
+    return [NSNumber numberWithBool:[self isSpringboardHandledURL]];
+}
+
+@end
+
+MSClassHook(NSURL)
+
+MSInstanceMessageHook0(BOOL, NSURL, isSpringboardHandledURL) {
+    if (![NSThread isMainThread])
+        return MSOldCall();
+
+    return [[self cydget$yieldToSelector:@selector(cydget$isSpringboardHandledURL)] boolValue];
+}
+
+@implementation CydgetWebView
+
 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
     NSObject<CydgetWebViewDelegate> *delegate([self delegate]);
     if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
index bbf925b0482450f86172362c718d5bf81c7a0a41..4b3c652057dc3efcf00956b4b8baa2956ef8eb54 100644 (file)
--- a/makefile
+++ b/makefile
@@ -15,7 +15,7 @@ CydgetSettings: CydgetSettings.mm makefile
        ldid -S $@
 
 WebCycriptLockScreen: LockScreen.mm makefile $(base)/../mobilesubstrate/substrate.h
-       $(target)g++ -F. -bundle -mthumb -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -lobjc -I$(base)/../mobilesubstrate $(link) $(flags) -framework CoreGraphics -framework QuartzCore -framework SpringBoardUI -framework WebCore -framework GraphicsServices -framework TelephonyUI -I$(jscore) -iquote$(webcore)/{bindings/js,dom,loader,platform{,/animation,/cf,/network{,/cf},/text},/rendering/style} -iquote$(jscore)/{bytecode,debugger,interpreter,jit,parser,runtime} -lapr-1 -weak_reference_mismatches weak -framework JavaScriptCore -lpcre -DNDEBUG -framework CFNetwork -framework WebKit
+       $(target)g++ -F. -bundle -mthumb -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -lobjc -I$(base)/../mobilesubstrate $(link) $(flags) -framework CoreGraphics -framework QuartzCore -framework SpringBoardUI -framework WebCore -framework GraphicsServices -framework TelephonyUI -I$(jscore) -iquote$(webcore)/{bindings/js,dom,loader,platform{,/animation,/cf,/network{,/cf},/text},/rendering/style} -iquote$(jscore)/{bytecode,debugger,interpreter,jit,parser,runtime} -lapr-1 -weak_reference_mismatches weak -framework JavaScriptCore -lpcre -DNDEBUG -framework CFNetwork -framework WebKit yieldToSelector.mm
        ldid -S $@
 
 extra:
diff --git a/yieldToSelector.h b/yieldToSelector.h
new file mode 100644 (file)
index 0000000..859488f
--- /dev/null
@@ -0,0 +1,50 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2011  Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ *        Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer in the documentation
+ *    and/or other materials provided with the
+ *    distribution.
+ * 3. The name of the author may not be used to endorse
+ *    or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
+#ifndef Cydget_yieldToSelector_H
+#define Cydget_yieldToSelector_H
+
+#include <Foundation/Foundation.h>
+
+@interface NSObject (MenesYieldToSelector)
+- (id) cydget$yieldToSelector:(SEL)selector withObject:(id)object;
+- (id) cydget$yieldToSelector:(SEL)selector;
+@end
+
+#endif//Cydget_yieldToSelector_H
diff --git a/yieldToSelector.mm b/yieldToSelector.mm
new file mode 100644 (file)
index 0000000..d1cff3e
--- /dev/null
@@ -0,0 +1,104 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2011  Jay Freeman (saurik)
+*/
+
+/* Modified BSD License {{{ */
+/*
+ *        Redistribution and use in source and binary
+ * forms, with or without modification, are permitted
+ * provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions
+ *    and the following disclaimer in the documentation
+ *    and/or other materials provided with the
+ *    distribution.
+ * 3. The name of the author may not be used to endorse
+ *    or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+ * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+/* }}} */
+
+#include "yieldToSelector.h"
+
+@implementation NSObject (CydgetYieldToSelector)
+
+- (void) cydget$doNothing {
+}
+
+- (void) cydget$yieldToContext:(NSMutableArray *)context {
+    NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
+    SEL selector(reinterpret_cast<SEL>([[context objectAtIndex:0] pointerValue]));
+    id object([[context objectAtIndex:1] nonretainedObjectValue]);
+    volatile bool &stopped(*reinterpret_cast<bool *>([[context objectAtIndex:2] pointerValue]));
+
+    /* XXX: deal with exceptions */
+    id value([self performSelector:selector withObject:object]);
+
+    NSMethodSignature *signature([self methodSignatureForSelector:selector]);
+    [context removeAllObjects];
+    if ([signature methodReturnLength] != 0 && value != nil)
+        [context addObject:value];
+
+    stopped = true;
+
+    [self
+        performSelectorOnMainThread:@selector(cydget$doNothing)
+        withObject:nil
+        waitUntilDone:NO
+    ];
+
+    [pool release];
+}
+
+- (id) cydget$yieldToSelector:(SEL)selector withObject:(id)object {
+    volatile bool stopped(false);
+
+    NSMutableArray *context([NSMutableArray arrayWithObjects:
+        [NSValue valueWithPointer:selector],
+        [NSValue valueWithNonretainedObject:object],
+        [NSValue valueWithPointer:const_cast<bool *>(&stopped)],
+    nil]);
+
+    NSThread *thread([[[NSThread alloc]
+        initWithTarget:self
+        selector:@selector(cydget$yieldToContext:)
+        object:context
+    ] autorelease]);
+
+    [thread start];
+
+    NSRunLoop *loop([NSRunLoop currentRunLoop]);
+    NSDate *future([NSDate distantFuture]);
+    NSString *mode([loop currentMode] ?: NSDefaultRunLoopMode);
+
+    while (!stopped && [loop runMode:mode beforeDate:future]);
+
+    return [context count] == 0 ? nil : [context objectAtIndex:0];
+}
+
+- (id) cydget$yieldToSelector:(SEL)selector {
+    return [self cydget$yieldToSelector:selector withObject:nil];
+}
+
+@end
+