summaryrefslogtreecommitdiff
path: root/CyteKit/CyteWebView.mm
diff options
context:
space:
mode:
Diffstat (limited to 'CyteKit/CyteWebView.mm')
-rw-r--r--CyteKit/CyteWebView.mm24
1 files changed, 24 insertions, 0 deletions
diff --git a/CyteKit/CyteWebView.mm b/CyteKit/CyteWebView.mm
index 720bb72..5c07039 100644
--- a/CyteKit/CyteWebView.mm
+++ b/CyteKit/CyteWebView.mm
@@ -38,6 +38,7 @@
/* }}} */
#include "CyteKit/CyteWebView.h"
+#include "CyteKit/WebThreadLocked.hpp"
#include <CydiaSubstrate/CydiaSubstrate.h>
@@ -326,6 +327,29 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
[delegate webViewUpdateViewSettings:self];
}
+- (void) dispatchEvent:(NSString *)event {
+ WebThreadLocked lock;
+
+ NSString *script([NSString stringWithFormat:@
+ "(function() {"
+ "var event = this.document.createEvent('Events');"
+ "event.initEvent('%@', false, false);"
+ "this.document.dispatchEvent(event);"
+ "})();"
+ , event]);
+
+ NSMutableArray *frames([NSMutableArray arrayWithObjects:
+ [[[self _documentView] webView] mainFrame]
+ , nil]);
+
+ while (WebFrame *frame = [frames lastObject]) {
+ WebScriptObject *object([frame windowObject]);
+ [object evaluateWebScript:script];
+ [frames removeLastObject];
+ [frames addObjectsFromArray:[frame childFrames]];
+ }
+}
+
+ (void) initialize {
if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) {
class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12");