X-Git-Url: https://git.saurik.com/cydia.git/blobdiff_plain/c623466b01da346cafe5cdd1039ed608326d9a5c..a3d01a768f0e7f9d5a36b4bcea04458634818863:/CyteKit/WebViewController.mm diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm index 33524f39..40b12001 100644 --- a/CyteKit/WebViewController.mm +++ b/CyteKit/WebViewController.mm @@ -1,15 +1,14 @@ #include "CyteKit/UCPlatform.h" -#include "CyteKit/WebViewController.h" - -#include "CyteKit/MFMailComposeViewController-MailToURL.h" - -#include "iPhonePrivate.h" #include "CyteKit/IndirectDelegate.h" #include "CyteKit/Localize.h" -#include "CyteKit/WebViewController.h" -#include "CyteKit/PerlCompatibleRegEx.hpp" +#include "CyteKit/MFMailComposeViewController-MailToURL.h" +#include "CyteKit/RegEx.hpp" #include "CyteKit/WebThreadLocked.hpp" +#include "CyteKit/WebViewController.h" + +#include "iPhonePrivate.h" +#include //#include // XXX: fix the minimum requirement @@ -17,18 +16,11 @@ extern NSString * const kCAFilterNearest; #include -#import -#import - -#include -#include -#include -#include -#include - #include #include +#include "Substrate.hpp" + #define ForSaurik 0 #define DefaultTimeout_ 120.0 @@ -95,7 +87,7 @@ float CYScrollViewDecelerationRateNormal; // XXX: WebThreadCreateNSInvocation returns nil #if ShowInternals - fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel)); + fprintf(stderr, "[%s]R?%s\n", class_getName(object_getClass(self)), sel_getName(sel)); #endif return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel]; @@ -106,7 +98,7 @@ float CYScrollViewDecelerationRateNormal; return method; #if ShowInternals - fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel)); + fprintf(stderr, "[%s]S?%s\n", class_getName(object_getClass(self)), sel_getName(sel)); #endif if (delegate_ != nil) @@ -126,7 +118,43 @@ float CYScrollViewDecelerationRateNormal; @end /* }}} */ -@implementation CyteWebViewController +@implementation CyteWebViewController { + _H webview_; + _transient UIScrollView *scroller_; + + _H indicator_; + _H indirect_; + _H challenge_; + + bool error_; + _H request_; + bool ready_; + + _transient NSNumber *sensitive_; + _H appstore_; + + _H title_; + _H loading_; + + _H registered_; + _H timer_; + + // XXX: NSString * or UIImage * + _H custom_; + _H style_; + + _H function_; + + float width_; + Class class_; + + _H reloaditem_; + _H loadingitem_; + + bool visible_; + bool hidesNavigationBar_; + bool allowsNavigationAction_; +} #if ShowInternals #include "CyteKit/UCInternal.h" @@ -146,7 +174,7 @@ float CYScrollViewDecelerationRateNormal; dlopen("/System/Library/Frameworks/MessageUI.framework/MessageUI", RTLD_GLOBAL | RTLD_LAZY); $MFMailComposeViewController = objc_getClass("MFMailComposeViewController"); - if (float *_UIScrollViewDecelerationRateNormal = reinterpret_cast(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal"))) + if (CGFloat *_UIScrollViewDecelerationRateNormal = reinterpret_cast(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal"))) CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal; else // XXX: this actually might be fast on some older systems: we should look into this CYScrollViewDecelerationRateNormal = 0.998; @@ -161,7 +189,7 @@ float CYScrollViewDecelerationRateNormal; [loading_ removeAllObjects]; if ([self retainsNetworkActivityIndicator]) - [delegate_ releaseNetworkActivityIndicator]; + [self.delegate releaseNetworkActivityIndicator]; } } @@ -183,6 +211,10 @@ float CYScrollViewDecelerationRateNormal; return (CyteWebView *) [self view]; } +- (CyteWebViewController *) indirect { + return (CyteWebViewController *) (IndirectDelegate *) indirect_; +} + - (NSURL *) URLWithURL:(NSURL *)url { return url; } @@ -204,6 +236,10 @@ float CYScrollViewDecelerationRateNormal; request_ = request; } +- (NSURLRequest *) request { + return request_; +} + - (void) setURL:(NSURL *)url { [self setURL:url withReferrer:nil]; } @@ -409,7 +445,7 @@ float CYScrollViewDecelerationRateNormal; NSURL *url([request URL]); // XXX: filter to internal usage? - CyteViewController *page([delegate_ pageForURL:url forExternal:NO withReferrer:referrer]); + CyteViewController *page([self.delegate pageForURL:url forExternal:NO withReferrer:referrer]); if (page == nil) { CyteWebViewController *browser([[[class_ alloc] init] autorelease]); @@ -417,8 +453,8 @@ float CYScrollViewDecelerationRateNormal; page = browser; } - [page setDelegate:delegate_]; - [page setPageColor:color_]; + [page setDelegate:self.delegate]; + [page setPageColor:self.pageColor]; if (!pop) { [[self navigationItem] setTitle:title_]; @@ -427,7 +463,7 @@ float CYScrollViewDecelerationRateNormal; } else { UINavigationController *navigation([[[UINavigationController alloc] initWithRootViewController:page] autorelease]); - [navigation setDelegate:delegate_]; + [navigation setDelegate:self.delegate]; [[page navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:UCLocalize("CLOSE") @@ -443,10 +479,10 @@ float CYScrollViewDecelerationRateNormal; // CyteWebViewDelegate {{{ - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message { #if LogMessages - static Pcre irritating("^(?" + static RegEx irritating("(?" ":" "The page at .* displayed insecure content from .*\\." "|" "Unsafe JavaScript attempt to access frame with URL .* from frame with URL .*\\. Domains, protocols and ports must match\\." - ")\\n$"); + ")\\n"); if (NSString *data = [message objectForKey:@"message"]) if (irritating(data)) @@ -505,7 +541,7 @@ float CYScrollViewDecelerationRateNormal; - (void) webView:(WebView *)view didDecidePolicy:(CYWebPolicyDecision)decision forNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame { #if LogBrowser - NSLog(@"didDecidePolicy:%u forNavigationAction:%@ request:%@ frame:%@", decision, action, request, [request allHTTPHeaderFields], frame); + NSLog(@"didDecidePolicy:%u forNavigationAction:%@ request:%@ %@ frame:%@", decision, action, request, [request allHTTPHeaderFields], frame); #endif if ([frame parentFrame] == nil) { @@ -536,7 +572,7 @@ float CYScrollViewDecelerationRateNormal; return; if ([name isEqualToString:@"_open"]) - [delegate_ openURL:url]; + [self.delegate openURL:url]; else { NSString *scheme([[url scheme] lowercaseString]); if ([scheme isEqualToString:@"mailto"]) @@ -560,7 +596,6 @@ float CYScrollViewDecelerationRateNormal; #endif if ([frame parentFrame] == nil) { - loaded_ = true; } } @@ -614,7 +649,7 @@ float CYScrollViewDecelerationRateNormal; } [super setPageColor:uic]; - [scroller_ setBackgroundColor:color_]; + [scroller_ setBackgroundColor:self.pageColor]; break; } } @@ -683,7 +718,7 @@ float CYScrollViewDecelerationRateNormal; [alert addTextFieldWithValue:@"" label:UCLocalize("PASSWORD")]; UITextField *username([alert textFieldAtIndex:0]); { - UITextInputTraits *traits([username textInputTraits]); + NSObject *traits([username textInputTraits]); [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; [traits setKeyboardType:UIKeyboardTypeASCIICapable]; @@ -691,7 +726,7 @@ float CYScrollViewDecelerationRateNormal; } UITextField *password([alert textFieldAtIndex:1]); { - UITextInputTraits *traits([password textInputTraits]); + NSObject *traits([password textInputTraits]); [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone]; [traits setAutocorrectionType:UITextAutocorrectionTypeNo]; [traits setKeyboardType:UIKeyboardTypeASCIICapable]; @@ -711,6 +746,14 @@ float CYScrollViewDecelerationRateNormal; return request; } +- (NSURLRequest *) webThreadWebView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { +#if LogBrowser + NSLog(@"resource:%@ willSendRequest:%@ redirectResponse:%@ fromDataSource:%@", identifier, request, response, source); +#endif + + return request; +} + - (bool) webView:(WebView *)view shouldRunJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { return [self _allowJavaScriptPanel]; } @@ -767,7 +810,7 @@ float CYScrollViewDecelerationRateNormal; } else if ([context isEqualToString:@"itmsappss"]) { if (button == [alert cancelButtonIndex]) { } else if (button == [alert firstOtherButtonIndex]) { - [delegate_ openURL:appstore_]; + [self.delegate openURL:appstore_]; } [alert dismissWithClickedButtonIndex:-1 animated:YES]; @@ -796,9 +839,9 @@ float CYScrollViewDecelerationRateNormal; - (UIBarButtonItem *) customButton { if (custom_ == nil) - return nil; + return [self rightButton]; else if ((/*clang:*/id) custom_ == [NSNull null]) - return (UIBarButtonItem *) [NSNull null]; + return nil; return [[[UIBarButtonItem alloc] initWithTitle:static_cast(custom_.operator NSObject *()) @@ -851,14 +894,7 @@ float CYScrollViewDecelerationRateNormal; [self applyLoadingTitle]; } else { [indicator_ stopAnimating]; - - UIBarButtonItem *button([self customButton]); - if (button == nil) - button = [self rightButton]; - else if (button == (UIBarButtonItem *) [NSNull null]) - button = nil; - - [[self navigationItem] setRightBarButtonItem:button animated:YES]; + [[self navigationItem] setRightBarButtonItem:[self customButton] animated:YES]; } } @@ -873,7 +909,7 @@ float CYScrollViewDecelerationRateNormal; return; if ([self retainsNetworkActivityIndicator]) - [delegate_ retainNetworkActivityIndicator]; + [self.delegate retainNetworkActivityIndicator]; [self didStartLoading]; } @@ -890,7 +926,7 @@ float CYScrollViewDecelerationRateNormal; [[self navigationItem] setTitle:title_]; if ([self retainsNetworkActivityIndicator]) - [delegate_ releaseNetworkActivityIndicator]; + [self.delegate releaseNetworkActivityIndicator]; [self didFinishLoading]; } @@ -923,7 +959,7 @@ float CYScrollViewDecelerationRateNormal; initWithTitle:(kCFCoreFoundationVersionNumber >= 800 ? @" " : @" ") style:UIBarButtonItemStylePlain target:self - action:@selector(reloadButtonClicked) + action:@selector(customButtonClicked) ] autorelease]; UIActivityIndicatorViewStyle style; @@ -1026,7 +1062,7 @@ float CYScrollViewDecelerationRateNormal; [webview_ setBackgroundColor:nil]; [scroller_ setFixedBackgroundPattern:YES]; - [scroller_ setBackgroundColor:color_]; + [scroller_ setBackgroundColor:self.pageColor]; [scroller_ setClipsSubviews:YES]; [scroller_ setBounces:YES]; @@ -1263,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:)