From 72bdb25841675b854c4f782dd0a3f6decd928a3f Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 16 Feb 2011 18:43:35 -0800 Subject: [PATCH] Add LogMessages and use for console.log. --- UICaboodle/BrowserView.h | 1 + UICaboodle/BrowserView.mm | 31 +++++++++++++++++++++++++++++++ iPhonePrivate.h | 1 + 3 files changed, 33 insertions(+) diff --git a/UICaboodle/BrowserView.h b/UICaboodle/BrowserView.h index 79652f38..f6d689aa 100644 --- a/UICaboodle/BrowserView.h +++ b/UICaboodle/BrowserView.h @@ -24,6 +24,7 @@ @class IndirectDelegate; @protocol CYWebViewDelegate +- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message; - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener; - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id)listener; - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame; diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index 56ee2667..8bc0eff4 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -31,6 +31,7 @@ extern NSString * const kCAFilterNearest; #define ShowInternals 0 #define LogBrowser 0 +#define LogMessages 0 #define lprintf(args...) fprintf(stderr, args) @@ -46,6 +47,7 @@ float CYScrollViewDecelerationRateNormal; @interface WebView (Apple) - (void) _setLayoutInterval:(float)interval; +- (void) _setAllowsMessaging:(BOOL)allows; @end @interface WebPreferences (Apple) @@ -240,6 +242,21 @@ enum CYWebPolicyDecision { return created; }*/ +// webView:addMessageToConsole: (X.Xx) {{{ +static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) { + UIWebView *uiWebView(MSHookIvar(self, "uiWebView")); + if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)]) + [uiWebView webView:view addMessageToConsole:message]; +} + +- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message { + id delegate([self delegate]); + if ([delegate respondsToSelector:@selector(webView:addMessageToConsole:)]) + [delegate webView:view addMessageToConsole:message]; + if ([UIWebView instancesRespondToSelector:@selector(webView:addMessageToConsole:)]) + [super webView:view addMessageToConsole:message]; +} +// }}} // webView:decidePolicyForNavigationAction:request:frame:decisionListener: (2.0+) {{{ - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { id delegate([self delegate]); @@ -412,6 +429,7 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se + (void) initialize { if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) { + class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12"); class_addMethod($UIWebViewWebViewDelegate, @selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), (IMP) &$UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$, "v28@0:4@8@12@16@20@24"); class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16"); class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didReceiveTitle:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$, "v20@0:4@8@12@16"); @@ -635,6 +653,12 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se } // CYWebViewDelegate {{{ +- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message { +#if LogMessages + NSLog(@"addMessageToConsole:%@", message); +#endif +} + - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { #if LogBrowser NSLog(@"decidePolicyForNavigationAction:%@ request:%@ frame:%@", action, request, frame); @@ -999,6 +1023,13 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se [preferences setCacheModel:WebCacheModelDocumentBrowser]; [preferences setOfflineWebApplicationCacheEnabled:YES]; +#if LogMessages + if ([document respondsToSelector:@selector(setAllowsMessaging:)]) + [document setAllowsMessaging:YES]; + if ([webview respondsToSelector:@selector(_setAllowsMessaging:)]) + [webview _setAllowsMessaging:YES]; +#endif + if ([webview_ respondsToSelector:@selector(_scrollView)]) { scroller_ = [webview_ _scrollView]; diff --git a/iPhonePrivate.h b/iPhonePrivate.h index 96d3f10d..47463355 100644 --- a/iPhonePrivate.h +++ b/iPhonePrivate.h @@ -289,6 +289,7 @@ typedef enum { - (UIScrollView *) _scrollView; - (UIScroller *) _scroller; - (void) _updateViewSettings; +- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message; //- (WebView *) webView:(WebView *)view createWebViewWithRequest:(NSURLRequest *)request; - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener; - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id)listener; -- 2.45.2