diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-28 21:34:18 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-03-07 02:41:32 -0800 |
commit | 4bcafc016a94c555e6a91a1c50c35b201d389e66 (patch) | |
tree | 836fdea68e12c9cafb7578d06a3a4bd43be273b0 /CyteKit/CyteWebView.mm | |
parent | 5276ff21e3ed70bb2c65099fff053e7eac49a936 (diff) |
Move -[BrowserController dispatchEvent:] to CYWebView.
Diffstat (limited to 'CyteKit/CyteWebView.mm')
-rw-r--r-- | CyteKit/CyteWebView.mm | 24 |
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"); |