summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2014-10-29 08:22:05 -0700
committerJay Freeman (saurik) <saurik@saurik.com>2014-10-29 08:22:05 -0700
commitd331bfc3c3efdde44dfd4e81c50703e51f958a2f (patch)
tree3b4c384d7f40311603078a29315cc15345729966
parent6da09548ebbfc7b2412409492fe135a928ab0c64 (diff)
Fix Cydia's popup blocking (broken since iOS 4.2).
-rw-r--r--CyteKit/WebViewController.mm22
-rw-r--r--iPhonePrivate.h2
2 files changed, 22 insertions, 2 deletions
diff --git a/CyteKit/WebViewController.mm b/CyteKit/WebViewController.mm
index bf2643b..7d91177 100644
--- a/CyteKit/WebViewController.mm
+++ b/CyteKit/WebViewController.mm
@@ -942,7 +942,7 @@ float CYScrollViewDecelerationRateNormal;
[preferences _setLayoutInterval:0];
[preferences setCacheModel:WebCacheModelDocumentBrowser];
- [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+ [preferences setJavaScriptCanOpenWindowsAutomatically:NO];
if ([preferences respondsToSelector:@selector(setOfflineWebApplicationCacheEnabled:)])
[preferences setOfflineWebApplicationCacheEnabled:YES];
@@ -1040,16 +1040,34 @@ float CYScrollViewDecelerationRateNormal;
} return self;
}
++ (void) _lockJavaScript:(WebPreferences *)preferences {
+ WebThreadLocked lock;
+ [preferences setJavaScriptCanOpenWindowsAutomatically:NO];
+}
+
- (void) callFunction:(WebScriptObject *)function {
WebThreadLocked lock;
WebView *webview([[[self webView] _documentView] webView]);
- WebFrame *frame([webview mainFrame]);
+ WebPreferences *preferences([webview preferences]);
+ [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+ if ([webview respondsToSelector:@selector(_preferencesChanged:)])
+ [webview _preferencesChanged:preferences];
+ else
+ [webview _preferencesChangedNotification:[NSNotification notificationWithName:@"" object:preferences]];
+
+ WebFrame *frame([webview mainFrame]);
JSGlobalContextRef context([frame globalContext]);
+
JSObjectRef object([function JSObject]);
if ($JSObjectCallAsFunction != NULL)
($JSObjectCallAsFunction)(context, object, NULL, 0, NULL, NULL);
+
+ // XXX: the JavaScript code submits a form, which seems to happen asynchronously
+ NSObject *target([CyteWebViewController class]);
+ [NSObject cancelPreviousPerformRequestsWithTarget:target selector:@selector(_lockJavaScript:) object:preferences];
+ [target performSelector:@selector(_lockJavaScript:) withObject:preferences afterDelay:1];
}
- (void) reloadButtonClicked {
diff --git a/iPhonePrivate.h b/iPhonePrivate.h
index 64e8ea2..42a700d 100644
--- a/iPhonePrivate.h
+++ b/iPhonePrivate.h
@@ -353,6 +353,8 @@ static const UIActivityIndicatorViewStyle UIActivityIndicatorViewStyleWhiteTiny(
@end
@interface WebView (Apple)
+- (void) _preferencesChanged:(WebPreferences *)preferences;
+- (void) _preferencesChangedNotification:(NSNotification *)notification;
- (void) _setLayoutInterval:(float)interval;
- (void) _setAllowsMessaging:(BOOL)allows;
@end