/* }}} */
/* Browser Implementation {{{ */
@implementation BrowserView
+
+#if ForSaurik
#include "internals.h"
+#endif
- (void) dealloc {
if (challenge_ != nil)
[function_ release];
[scroller_ release];
- [urls_ release];
[indicator_ release];
if (confirm_ != nil)
[confirm_ release];
[self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
}
-- (NSURLRequest *) _addHeadersToRequest:(NSURLRequest *)request {
+- (NSMutableURLRequest *) _addHeadersToRequest:(NSURLRequest *)request {
NSMutableURLRequest *copy = [request mutableCopy];
if (Machine_ != NULL)
- [copy addValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
+ [copy setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
if (UniqueID_ != nil)
- [copy addValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
+ [copy setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
if (Role_ != nil)
- [copy addValue:Role_ forHTTPHeaderField:@"X-Role"];
+ [copy setValue:Role_ forHTTPHeaderField:@"X-Role"];
return copy;
}
}
- (void) reloadURL {
- if ([urls_ count] == 0)
+ NSLog(@"rlu:%@", request_);
+ if (request_ == nil)
return;
- NSURL *url = [[[urls_ lastObject] retain] autorelease];
- [urls_ removeLastObject];
- [self loadURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData];
+
+ if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
+ [webview_ loadRequest:request_];
+ else {
+ UIActionSheet *sheet = [[[UIActionSheet alloc]
+ initWithTitle:@"Are you sure you want to submit this form again?"
+ buttons:[NSArray arrayWithObjects:@"Cancel", @"Submit", nil]
+ defaultButtonIndex:0
+ delegate:self
+ context:@"submit"
+ ] autorelease];
+
+ [sheet setNumberOfRows:1];
+ [sheet popupAlertAnimated:YES];
+ }
}
- (WebView *) webView {
[window setValue:self forKey:@"cydia"];
}
+- (void) webView:(WebView *)sender unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame {
+ NSLog(@"err:%@", error);
+}
+
- (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
if (NSURL *url = [request URL]) {
if (name != nil && [name isEqualToString:@"_open"])
}
- (void) webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+ if (request == nil) ignore: {
+ [listener ignore];
+ return;
+ }
+
NSURL *url([request URL]);
if (url == nil) use: {
+ if ([frame parentFrame] == nil) {
+ if (request_ != nil)
+ [request_ autorelease];
+ request_ = [request retain];
+ NSLog(@"dpn:%@", request_);
+ }
+
[listener use];
return;
}
+#if ForSaurik
else NSLog(@"nav:%@:%@", url, [action description]);
+#endif
const NSArray *capability(reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability)));
) {
open:
[UIApp openURL:url];
- ignore:
- [listener ignore];
- return;
+ goto ignore;
}
int store(_not(int));
[challenge_ release];
challenge_ = nil;
+ [sheet dismiss];
+ } else if ([context isEqualToString:@"submit"]) {
+ switch (button) {
+ case 1:
+ break;
+
+ case 2:
+ if (request_ != nil)
+ [webview_ loadRequest:request_];
+ break;
+
+ default:
+ _assert(false);
+ }
+
[sheet dismiss];
}
}
[browser setDelegate:delegate_];
if (pushed) {
- [browser loadRequest:[self _addHeadersToRequest:request]];
+ [browser loadRequest:request];
[book_ pushPage:browser];
}
[book_ reloadTitleForPage:self];
- WebView *webview = [webview_ webView];
- NSString *href = [webview mainFrameURL];
- [urls_ addObject:[NSURL URLWithString:href]];
-
[scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
CGRect webrect = [scroller_ bounds];
[webview setScriptDebugDelegate:self];
[webview setPolicyDelegate:self];
- urls_ = [[NSMutableArray alloc] initWithCapacity:16];
-
[self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
} return self;