]> git.saurik.com Git - cydia.git/blobdiff - UICaboodle/BrowserView.mm
Move reserved_ linkages up to Cytore::Block.
[cydia.git] / UICaboodle / BrowserView.mm
index 73f615539260b782ccca8e6ccda846814e9b3378..d73bca930b70473d3721cf7eafe5881b793d68b7 100644 (file)
@@ -169,6 +169,7 @@ enum CYWebPolicyDecision {
     switch (decision_) {
         case CYWebPolicyDecisionUnknown:
         default:
+            NSLog(@"CYWebPolicyDecisionUnknown");
             return false;
 
         case CYWebPolicyDecisionDownload: [listener_ download]; break;
@@ -210,12 +211,13 @@ enum CYWebPolicyDecision {
 }
 
 /*- (WebView *) webView:(WebView *)view createWebViewWithRequest:(NSURLRequest *)request {
-    NSLog(@"createWebViewWithRequest:%@", request);
-    WebView *created(nil); // XXX
+    id<CYWebViewDelegate> delegate([self delegate]);
+    WebView *created(nil);
+    if (created == nil && [delegate respondsToSelector:@selector(webView:createWebViewWithRequest:)])
+        created = [delegate webView:view createWebViewWithRequest:request];
     if (created == nil && [UIWebView instancesRespondToSelector:@selector(webView:createWebViewWithRequest:)])
-        return [super webView:view createWebViewWithRequest:request];
-    else
-        return created;
+        created = [super webView:view createWebViewWithRequest:request];
+    return created;
 }*/
 
 // webView:decidePolicyForNavigationAction:request:frame:decisionListener: (2.0+) {{{
@@ -246,7 +248,7 @@ static void $UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$req
     [mediator decide];
 }
 // }}}
-// webView:didClearWindowObject:forFrame: (3.2, 4.1+) {{{
+// webView:didClearWindowObject:forFrame: (3.2+) {{{
 static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) {
     UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
     if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
@@ -288,7 +290,7 @@ static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIW
         [super webView:view didFinishLoadForFrame:frame];
 }
 // }}}
-// webView:didReceiveTitle:forFrame: (3.2, 4.1+) {{{
+// webView:didReceiveTitle:forFrame: (3.2+) {{{
 static void $UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSString *title, WebFrame *frame) {
     UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
     if ([uiWebView respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)])
@@ -312,13 +314,12 @@ static void $UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$(UIWebVie
         [super webView:view didStartProvisionalLoadForFrame:frame];
 }
 // }}}
-// webView:resource:willSendRequest:redirectResponse:fromDataSource: (3.2, 4.1+) {{{
+// webView:resource:willSendRequest:redirectResponse:fromDataSource: (3.2+) {{{
 static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, id identifier, NSURLRequest *request, NSURLResponse *response, WebDataSource *source) {
     UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
     if ([uiWebView respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
-        return [uiWebView webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
-    else
-        return request;
+        request = [uiWebView webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
+    return request;
 }
 
 - (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
@@ -330,7 +331,7 @@ static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$
     return request;
 }
 // }}}
-// webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: (2.2+) {{{
+// webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: (2.1+) {{{
 - (void) webView:(WebView *)view runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
     id<CYWebViewDelegate> delegate([self delegate]);
     if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)])
@@ -339,7 +340,7 @@ static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$
             [super webView:view runJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame];
 }
 // }}}
-// webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame: (2.2+) {{{
+// webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame: (2.1+) {{{
 - (BOOL) webView:(WebView *)view runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
     id<CYWebViewDelegate> delegate([self delegate]);
     if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)])
@@ -349,7 +350,7 @@ static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$
     return NO;
 }
 // }}}
-// webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame: (2.2+) {{{
+// webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame: (2.1+) {{{
 - (NSString *) webView:(WebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
     id<CYWebViewDelegate> delegate([self delegate]);
     if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)])
@@ -359,7 +360,7 @@ static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$
     return nil;
 }
 // }}}
-// webViewClose: (3.2, 4.1+) {{{
+// webViewClose: (3.2+) {{{
 static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view) {
     UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
     if ([uiWebView respondsToSelector:@selector(webViewClose:)])
@@ -375,6 +376,14 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
 }
 // }}}
 
+- (void) _updateViewSettings {
+    [super _updateViewSettings];
+
+    id<CYWebViewDelegate> delegate([self delegate]);
+    if ([delegate respondsToSelector:@selector(webViewUpdateViewSettings:)])
+        [delegate webViewUpdateViewSettings:self];
+}
+
 + (void) initialize {
     if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) {
         class_addMethod($UIWebViewWebViewDelegate, @selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), (IMP) &$UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$, "v28@0:4@8@12@16@20@24");
@@ -388,7 +397,7 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
 @end
 
 #define ShowInternals 0
-#define LogBrowser 1
+#define LogBrowser 0
 
 #define lprintf(args...) fprintf(stderr, args)
 
@@ -420,6 +429,9 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
     if (challenge_ != nil)
         [challenge_ release];
 
+    if (request_ != nil)
+        [request_ release];
+
     //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
 
     if (custom_ != nil)
@@ -432,11 +444,11 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
     if (closer_ != nil)
         [closer_ release];
 
-    if (sensitive_ != nil)
-        [sensitive_ release];
     if (title_ != nil)
         [title_ release];
 
+    [loading_ release];
+
     [reloaditem_ release];
     [loadingitem_ release];
 
@@ -458,6 +470,10 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
 }
 
 - (void) loadRequest:(NSURLRequest *)request {
+#if LogBrowser
+    NSLog(@"loadRequest:%@", request);
+#endif
+
     error_ = false;
 
     WebThreadLock();
@@ -488,15 +504,24 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
     if (custom_ != nil)
         [custom_ autorelease];
-    custom_ = button == nil ? nil : [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:button]]] retain];
+    if (button == nil)
+        custom_ = nil;
+    else
+        custom_ = [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:button]]] retain];
 
     if (style_ != nil)
         [style_ autorelease];
-    style_ = style == nil ? nil : [style retain];
+    if (style == nil)
+        style_ = nil;
+    else
+        style_ = [style retain];
 
     if (function_ != nil)
         [function_ autorelease];
-    function_ = function == nil ? nil : [function retain];
+    if (function == nil)
+        function_ = nil;
+    else
+        function_ = [function retain];
 
     [self applyRightButton];
 }
@@ -504,15 +529,24 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
     if (custom_ != nil)
         [custom_ autorelease];
-    custom_ = button == nil ? nil : [button retain];
+    if (button == nil)
+        custom_ = nil;
+    else
+        custom_ = [button retain];
 
     if (style_ != nil)
         [style_ autorelease];
-    style_ = style == nil ? nil : [style retain];
+    if (style == nil)
+        style_ = nil;
+    else
+        style_ = [style retain];
 
     if (function_ != nil)
         [function_ autorelease];
-    function_ = function == nil ? nil : [function retain];
+    if (function == nil)
+        function_ = nil;
+    else
+        function_ = [function retain];
 
     [self applyRightButton];
 }
@@ -520,12 +554,23 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
 - (void) setPopupHook:(id)function {
     if (closer_ != nil)
         [closer_ autorelease];
-    closer_ = function == nil ? nil : [function retain];
+    if (function == nil)
+        closer_ = nil;
+    else
+        closer_ = [function retain];
+}
+
+- (void) _setViewportWidth {
+    [[webview_ _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
 }
 
 - (void) setViewportWidth:(float)width {
     width_ = width != 0 ? width : [[self class] defaultWidth];
-    [[webview_ _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
+    [self _setViewportWidth];
+}
+
+- (void) webViewUpdateViewSettings:(UIWebView *)view {
+    [self _setViewportWidth];
 }
 
 - (void) _openMailToURL:(NSURL *)url {
@@ -559,13 +604,15 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
     NSLog(@"decidePolicyForNavigationAction:%@ request:%@ frame:%@", action, request, frame);
 #endif
 
-    if (!error_ && [frame parentFrame] == nil) {
-        if (request_ != nil)
-            [request_ autorelease];
-        if (request == nil)
-            request_ = nil;
-        else
-            request_ = [request retain];
+    if ([frame parentFrame] == nil) {
+        if (!error_) {
+            if (request_ != nil)
+                [request_ autorelease];
+            if (request == nil)
+                request_ = nil;
+            else
+                request_ = [request retain];
+        }
     }
 }
 
@@ -691,7 +738,10 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
     if ([frame parentFrame] != nil)
         return;
 
+    if (title_ != nil)
+        [title_ autorelease];
     title_ = [title retain];
+
     [[self navigationItem] setTitle:title_];
 }
 
@@ -713,6 +763,10 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
 }
 
 - (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+#if LogBrowser
+    NSLog(@"resource:%@ willSendRequest:%@ redirectResponse:%@ fromDataSource:%@", identifier, request, response, source);
+#endif
+
     return request;
 }
 
@@ -826,7 +880,7 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
 - (void) applyRightButton {
     if ([self isLoading]) {
         [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
-        // XXX: why do we do this again here?
+        // XXX: why do we do this again here? (if we don't, just remove indicator_)
         [[loadingitem_ view] addSubview:indicator_];
         [self applyLoadingTitle];
     } else if (custom_ != nil) {
@@ -879,6 +933,8 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se
         [document setTileSize:CGSizeMake(320, 500)];
 
         [document setBackgroundColor:[UIColor clearColor]];
+
+        // XXX: this is terribly (too?) expensive
         [document setDrawsBackground:NO];
 
         WebView *webview([document webView]);