From 99c17c099ece8b09b6bc9a7442fd802ad8f04177 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 1 Apr 2011 00:11:25 +0000 Subject: [PATCH] Support application URL schemes. --- LockScreen.mm | 31 ++++++++++++-- makefile | 2 +- yieldToSelector.h | 50 ++++++++++++++++++++++ yieldToSelector.mm | 104 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 yieldToSelector.h create mode 100644 yieldToSelector.mm diff --git a/LockScreen.mm b/LockScreen.mm index 3ad5020..5fccd84 100644 --- a/LockScreen.mm +++ b/LockScreen.mm @@ -75,6 +75,8 @@ extern NSString * const kCAFilterNearest; #include "SourceCode.h" +#include "yieldToSelector.h" + #include #include @@ -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)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 *delegate([self delegate]); if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)]) diff --git a/makefile b/makefile index bbf925b..4b3c652 100644 --- 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 index 0000000..859488f --- /dev/null +++ b/yieldToSelector.h @@ -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 + +@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 index 0000000..d1cff3e --- /dev/null +++ b/yieldToSelector.mm @@ -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([[context objectAtIndex:0] pointerValue])); + id object([[context objectAtIndex:1] nonretainedObjectValue]); + volatile bool &stopped(*reinterpret_cast([[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(&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 + -- 2.45.2