]> git.saurik.com Git - cydia.git/commitdiff
Fix Cydia's popup blocking (broken since iOS 4.2).
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 29 Oct 2014 15:22:05 +0000 (08:22 -0700)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 29 Oct 2014 15:22:05 +0000 (08:22 -0700)
CyteKit/WebViewController.mm
iPhonePrivate.h

index bf2643b2bda3037e2a3efdfbc648b473519bb998..7d91177f9fee707b11557902274f29f1da966393 100644 (file)
@@ -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 {
index 64e8ea280cd31170928f6ac6f0478c1161d75c42..42a700d8708069f2e4bbe8a58571fd5c11a68f88 100644 (file)
@@ -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