summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2017-02-16 01:30:53 -0800
committerJay Freeman (saurik) <saurik@saurik.com>2017-02-16 01:30:53 -0800
commita3d01a768f0e7f9d5a36b4bcea04458634818863 (patch)
treea3e62c81f8cf286cabe0bdf382c95caaf0722d0d
parent68df8c0b7bacec286d4798408b5a110bdac88986 (diff)
Move a bunch of clearly shared logic into CyteKit.
-rw-r--r--CyteKit/Application.mm7
-rw-r--r--CyteKit/CyteKit.h38
-rw-r--r--CyteKit/WebView.mm26
-rw-r--r--CyteKit/WebViewController.mm28
-rw-r--r--CyteKit/countByEnumeratingWithState.h (renamed from CyteKit/WebScriptObject-Cyte.h)12
-rw-r--r--CyteKit/countByEnumeratingWithState.mm (renamed from CyteKit/WebScriptObject-Cyte.mm)21
-rw-r--r--CyteKit/webScriptObjectInContext.h31
-rw-r--r--CyteKit/webScriptObjectInContext.mm56
-rw-r--r--MobileCydia.mm127
9 files changed, 216 insertions, 130 deletions
diff --git a/CyteKit/Application.mm b/CyteKit/Application.mm
index 9bd42ff..77b1260 100644
--- a/CyteKit/Application.mm
+++ b/CyteKit/Application.mm
@@ -25,6 +25,7 @@
#include <UIKit/UIKit.h>
#include "CyteKit/Application.h"
+#include "CyteKit/URLCache.h"
#include "iPhonePrivate.h"
#include <Menes/ObjectHandle.h>
@@ -57,6 +58,12 @@
if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)])
[self setApplicationSupportsShakeToEdit:NO];
+
+ [NSURLCache setSharedURLCache:[[[CyteURLCache alloc]
+ initWithMemoryCapacity:524288
+ diskCapacity:10485760
+ diskPath:[NSString stringWithFormat:@"%@/%@/%@", NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject, NSBundle.mainBundle.bundleIdentifier, @"SDURLCache"]
+ ] autorelease]];
}
@end
diff --git a/CyteKit/CyteKit.h b/CyteKit/CyteKit.h
new file mode 100644
index 0000000..3edcc88
--- /dev/null
+++ b/CyteKit/CyteKit.h
@@ -0,0 +1,38 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2015 Jay Freeman (saurik)
+*/
+
+/* GNU General Public License, Version 3 {{{ */
+/*
+ * Cydia is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Cydia is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
+**/
+/* }}} */
+
+#ifndef CyteKit_CyteKit_H
+#define CyteKit_CyteKit_H
+
+#include "CyteKit/Application.h"
+#include "CyteKit/NavigationController.h"
+#include "CyteKit/RegEx.hpp"
+#include "CyteKit/TableViewCell.h"
+#include "CyteKit/TabBarController.h"
+#include "CyteKit/URLCache.h"
+#include "CyteKit/WebViewController.h"
+#include "CyteKit/WebViewTableViewCell.h"
+
+#include "CyteKit/countByEnumeratingWithState.h"
+#include "CyteKit/stringWithUTF8Bytes.h"
+#include "CyteKit/webScriptObjectInContext.h"
+
+#endif//CyteKit_CyteKit_H
diff --git a/CyteKit/WebView.mm b/CyteKit/WebView.mm
index 3711587..9e0cbea 100644
--- a/CyteKit/WebView.mm
+++ b/CyteKit/WebView.mm
@@ -417,3 +417,29 @@ __attribute__((__constructor__)) static void $() {
class_addMethod($UIWebViewWebViewDelegate, @selector(_clearUIWebView), (IMP) &$UIWebViewWebViewDelegate$_clearUIWebView, "v8@0:4");
}
}
+
+@implementation UIWebDocumentView (Cydia)
+
+- (void) _setScrollerOffset:(CGPoint)offset {
+ UIScroller *scroller([self _scroller]);
+
+ CGSize size([scroller contentSize]);
+ CGSize bounds([scroller bounds].size);
+
+ CGPoint max;
+ max.x = size.width - bounds.width;
+ max.y = size.height - bounds.height;
+
+ // wtf Apple?!
+ if (max.x < 0)
+ max.x = 0;
+ if (max.y < 0)
+ max.y = 0;
+
+ offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x;
+ offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y;
+
+ [scroller setOffset:offset];
+}
+
+@end
diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm
index 20838bf..40b1200 100644
--- a/CyteKit/WebViewController.mm
+++ b/CyteKit/WebViewController.mm
@@ -19,6 +19,8 @@ extern NSString * const kCAFilterNearest;
#include <dlfcn.h>
#include <objc/runtime.h>
+#include "Substrate.hpp"
+
#define ForSaurik 0
#define DefaultTimeout_ 120.0
@@ -1297,3 +1299,29 @@ float CYScrollViewDecelerationRateNormal;
}
@end
+
+MSClassHook(WAKWindow)
+
+static CGSize $WAKWindow$screenSize(WAKWindow *self, SEL _cmd) {
+ CGSize size([[UIScreen mainScreen] bounds].size);
+ /*if ([$WAKWindow respondsToSelector:@selector(hasLandscapeOrientation)])
+ if ([$WAKWindow hasLandscapeOrientation])
+ std::swap(size.width, size.height);*/
+ return size;
+}
+
+static struct WAKWindow$screenSize { WAKWindow$screenSize() {
+ if ($WAKWindow != NULL)
+ if (Method method = class_getInstanceMethod($WAKWindow, @selector(screenSize)))
+ method_setImplementation(method, (IMP) &$WAKWindow$screenSize);
+} } WAKWindow$screenSize;;
+
+MSClassHook(NSUserDefaults)
+
+MSHook(id, NSUserDefaults$objectForKey$, NSUserDefaults *self, SEL _cmd, NSString *key) {
+ if ([key respondsToSelector:@selector(isEqualToString:)] && [key isEqualToString:@"WebKitLocalStorageDatabasePathPreferenceKey"])
+ return [NSString stringWithFormat:@"%@/%@/%@", NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject, NSBundle.mainBundle.bundleIdentifier, @"LocalStorage"];
+ return _NSUserDefaults$objectForKey$(self, _cmd, key);
+}
+
+CYHook(NSUserDefaults, objectForKey$, objectForKey:)
diff --git a/CyteKit/WebScriptObject-Cyte.h b/CyteKit/countByEnumeratingWithState.h
index 6a394bc..32106fa 100644
--- a/CyteKit/WebScriptObject-Cyte.h
+++ b/CyteKit/countByEnumeratingWithState.h
@@ -19,15 +19,21 @@
**/
/* }}} */
-#ifndef CyteKit_WebScriptObject_Cyte_H
-#define CyteKit_WebScriptObject_Cyte_H
+#ifndef CyteKit_countByEnumeratingWithState_H
+#define CyteKit_countByEnumeratingWithState_H
#include "iPhonePrivate.h"
+@interface DOMNodeList (Cyte)
+// XXX? - (NSUInteger) count;
+- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)objects count:(NSUInteger)count;
+// XXX? - (id) objectAtIndex:(unsigned)index;
+@end
+
@interface WebScriptObject (Cyte)
- (NSUInteger) count;
- (NSUInteger) countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)objects count:(NSUInteger)count;
- (id) objectAtIndex:(unsigned)index;
@end
-#endif//CyteKit_WebScriptObject_Cyte_H
+#endif//CyteKit_countByEnumeratingWithState_H
diff --git a/CyteKit/WebScriptObject-Cyte.mm b/CyteKit/countByEnumeratingWithState.mm
index 7fa851d..ca5e577 100644
--- a/CyteKit/WebScriptObject-Cyte.mm
+++ b/CyteKit/countByEnumeratingWithState.mm
@@ -21,10 +21,29 @@
#include "CyteKit/UCPlatform.h"
-#include "CyteKit/WebScriptObject-Cyte.h"
+#include "CyteKit/countByEnumeratingWithState.h"
+
+#include <objc/runtime.h>
#include "iPhonePrivate.h"
+static NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) {
+ size_t length([self length] - state->state);
+ if (length <= 0)
+ return 0;
+ else if (length > count)
+ length = count;
+ for (size_t i(0); i != length; ++i)
+ objects[i] = [self item:state->state++];
+ state->itemsPtr = objects;
+ state->mutationsPtr = (unsigned long *) self;
+ return length;
+}
+
+static struct DOMNodeList$countByEnumeratingWithState { DOMNodeList$countByEnumeratingWithState() {
+ class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
+} } DOMNodeList$countByEnumeratingWithState;
+
@implementation WebScriptObject (Cyte)
- (NSUInteger) count {
diff --git a/CyteKit/webScriptObjectInContext.h b/CyteKit/webScriptObjectInContext.h
new file mode 100644
index 0000000..a73c8ce
--- /dev/null
+++ b/CyteKit/webScriptObjectInContext.h
@@ -0,0 +1,31 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2015 Jay Freeman (saurik)
+*/
+
+/* GNU General Public License, Version 3 {{{ */
+/*
+ * Cydia is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Cydia is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
+**/
+/* }}} */
+
+#ifndef CyteKit_webScriptObjectInContext_H
+#define CyteKit_webScriptObjectInContext_H
+
+#include "iPhonePrivate.h"
+
+@interface NSObject (CydiaScript)
+- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context;
+@end
+
+#endif//CyteKit_webScriptObjectInContext_H
diff --git a/CyteKit/webScriptObjectInContext.mm b/CyteKit/webScriptObjectInContext.mm
new file mode 100644
index 0000000..6f05336
--- /dev/null
+++ b/CyteKit/webScriptObjectInContext.mm
@@ -0,0 +1,56 @@
+/* Cydia - iPhone UIKit Front-End for Debian APT
+ * Copyright (C) 2008-2015 Jay Freeman (saurik)
+*/
+
+/* GNU General Public License, Version 3 {{{ */
+/*
+ * Cydia is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * Cydia is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
+**/
+/* }}} */
+
+#include "CyteKit/UCPlatform.h"
+
+#include "CyteKit/webScriptObjectInContext.h"
+
+#include "iPhonePrivate.h"
+
+@implementation NSObject (CydiaScript)
+
+- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context {
+ return self;
+}
+
+@end
+
+@implementation NSArray (CydiaScript)
+
+- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context {
+ WebScriptObject *object([context evaluateWebScript:@"[]"]);
+ for (size_t i(0), e([self count]); i != e; ++i)
+ [object setWebScriptValueAtIndex:i value:[[self objectAtIndex:i] Cydia$webScriptObjectInContext:context]];
+ return object;
+}
+
+@end
+
+@implementation NSDictionary (CydiaScript)
+
+- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context {
+ WebScriptObject *object([context evaluateWebScript:@"({})"]);
+ for (id i in self)
+ [object setValue:[[self objectForKey:i] Cydia$webScriptObjectInContext:context] forKey:i];
+ return object;
+}
+
+@end
diff --git a/MobileCydia.mm b/MobileCydia.mm
index d52a38e..64bc7ab 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -112,16 +112,7 @@ extern "C" {
#include "Substrate.hpp"
#include "Menes/Menes.h"
-#include "CyteKit/Application.h"
-#include "CyteKit/NavigationController.h"
-#include "CyteKit/RegEx.hpp"
-#include "CyteKit/TableViewCell.h"
-#include "CyteKit/TabBarController.h"
-#include "CyteKit/URLCache.h"
-#include "CyteKit/WebScriptObject-Cyte.h"
-#include "CyteKit/WebViewController.h"
-#include "CyteKit/WebViewTableViewCell.h"
-#include "CyteKit/stringWithUTF8Bytes.h"
+#include "CyteKit/CyteKit.h"
#include "Cydia/MIMEAddress.h"
#include "Cydia/LoadingViewController.h"
@@ -389,47 +380,6 @@ void CYArrayInsertionSortValues(Type_ *values, size_t length, CFComparisonResult
/* }}} */
-/* Apple Bug Fixes {{{ */
-@implementation UIWebDocumentView (Cydia)
-
-- (void) _setScrollerOffset:(CGPoint)offset {
- UIScroller *scroller([self _scroller]);
-
- CGSize size([scroller contentSize]);
- CGSize bounds([scroller bounds].size);
-
- CGPoint max;
- max.x = size.width - bounds.width;
- max.y = size.height - bounds.height;
-
- // wtf Apple?!
- if (max.x < 0)
- max.x = 0;
- if (max.y < 0)
- max.y = 0;
-
- offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x;
- offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y;
-
- [scroller setOffset:offset];
-}
-
-@end
-/* }}} */
-
-NSUInteger DOMNodeList$countByEnumeratingWithState$objects$count$(DOMNodeList *self, SEL sel, NSFastEnumerationState *state, id *objects, NSUInteger count) {
- size_t length([self length] - state->state);
- if (length <= 0)
- return 0;
- else if (length > count)
- length = count;
- for (size_t i(0); i != length; ++i)
- objects[i] = [self item:state->state++];
- state->itemsPtr = objects;
- state->mutationsPtr = (unsigned long *) self;
- return length;
-}
-
/* Cydia NSString Additions {{{ */
@interface NSString (Cydia)
- (NSComparisonResult) compareByPath:(NSString *)other;
@@ -5127,42 +5077,6 @@ static _H<NSMutableSet> Diversions_;
@end
/* }}} */
-// CydiaScript {{{
-@interface NSObject (CydiaScript)
-- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context;
-@end
-
-@implementation NSObject (CydiaScript)
-
-- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context {
- return self;
-}
-
-@end
-
-@implementation NSArray (CydiaScript)
-
-- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context {
- WebScriptObject *object([context evaluateWebScript:@"[]"]);
- for (size_t i(0), e([self count]); i != e; ++i)
- [object setWebScriptValueAtIndex:i value:[[self objectAtIndex:i] Cydia$webScriptObjectInContext:context]];
- return object;
-}
-
-@end
-
-@implementation NSDictionary (CydiaScript)
-
-- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context {
- WebScriptObject *object([context evaluateWebScript:@"({})"]);
- for (id i in self)
- [object setValue:[[self objectForKey:i] Cydia$webScriptObjectInContext:context] forKey:i];
- return object;
-}
-
-@end
-// }}}
-
/* Confirmation Controller {{{ */
bool DepSubstrate(const pkgCache::VerIterator &iterator) {
if (!iterator.end())
@@ -9811,12 +9725,6 @@ _trace();
[BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]];
}
- [NSURLCache setSharedURLCache:[[[CyteURLCache alloc]
- initWithMemoryCapacity:524288
- diskCapacity:10485760
- diskPath:Cache("SDURLCache")
- ] autorelease]];
-
[CydiaWebViewController _initialize];
[NSURLProtocol registerClass:[CydiaURLProtocol class]];
@@ -10038,24 +9946,6 @@ id Dealloc_(id self, SEL selector) {
return object;
}*/
-Class $WAKWindow;
-
-static CGSize $WAKWindow$screenSize(WAKWindow *self, SEL _cmd) {
- CGSize size([[UIScreen mainScreen] bounds].size);
- /*if ([$WAKWindow respondsToSelector:@selector(hasLandscapeOrientation)])
- if ([$WAKWindow hasLandscapeOrientation])
- std::swap(size.width, size.height);*/
- return size;
-}
-
-Class $NSUserDefaults;
-
-MSHook(id, NSUserDefaults$objectForKey$, NSUserDefaults *self, SEL _cmd, NSString *key) {
- if ([key respondsToSelector:@selector(isEqualToString:)] && [key isEqualToString:@"WebKitLocalStorageDatabasePathPreferenceKey"])
- return Cache("LocalStorage");
- return _NSUserDefaults$objectForKey$(self, _cmd, key);
-}
-
static NSMutableDictionary *AutoreleaseDeepMutableCopyOfDictionary(CFTypeRef type) {
if (type == NULL)
return nil;
@@ -10126,21 +10016,6 @@ int main(int argc, char *argv[]) {
PackageName = reinterpret_cast<CYString &(*)(Package *, SEL)>(method_getImplementation(class_getInstanceMethod([Package class], @selector(cyname))));
- /* Library Hacks {{{ */
- class_addMethod(objc_getClass("DOMNodeList"), @selector(countByEnumeratingWithState:objects:count:), (IMP) &DOMNodeList$countByEnumeratingWithState$objects$count$, "I20@0:4^{NSFastEnumerationState}8^@12I16");
-
- $WAKWindow = objc_getClass("WAKWindow");
- if ($WAKWindow != NULL)
- if (Method method = class_getInstanceMethod($WAKWindow, @selector(screenSize)))
- method_setImplementation(method, (IMP) &$WAKWindow$screenSize);
-
- $NSUserDefaults = objc_getClass("NSUserDefaults");
- Method NSUserDefaults$objectForKey$(class_getInstanceMethod($NSUserDefaults, @selector(objectForKey:)));
- if (NSUserDefaults$objectForKey$ != NULL) {
- _NSUserDefaults$objectForKey$ = reinterpret_cast<id (*)(NSUserDefaults *, SEL, NSString *)>(method_getImplementation(NSUserDefaults$objectForKey$));
- method_setImplementation(NSUserDefaults$objectForKey$, reinterpret_cast<IMP>(&$NSUserDefaults$objectForKey$));
- }
- /* }}} */
/* Set Locale {{{ */
Locale_ = CFLocaleCopyCurrent();
Languages_ = [NSLocale preferredLanguages];