#include "SourceCode.h"
+#include "yieldToSelector.h"
+
#include <apr-1/apr_pools.h>
#include <pcre.h>
static float CYScrollViewDecelerationRateNormal;
+@interface NSURL (Apple)
+- (BOOL) isSpringboardHandledURL;
+@end
+
@interface UIScrollView (Apple)
- (void) setDecelerationRate:(float)value;
- (void) setScrollingEnabled:(BOOL)enabled;
@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:)])
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:
--- /dev/null
+/* 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
--- /dev/null
+/* 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
+