Ben Copsey

Bug fixes and tweaks

@@ -55,21 +55,40 @@ NSLock *dialogLock = nil; @@ -55,21 +55,40 @@ NSLock *dialogLock = nil;
55 [[self loginDialog] setDelegate:self]; 55 [[self loginDialog] setDelegate:self];
56 56
57 // We show the login form in a table view, similar to Safari's authentication dialog 57 // We show the login form in a table view, similar to Safari's authentication dialog
58 - UITableView *table = [[[UITableView alloc] initWithFrame:CGRectMake(0,50,320,480) style:UITableViewStyleGrouped] autorelease]; 58 + UITableView *table = [[[UITableView alloc] initWithFrame:CGRectMake(0,80,320,480) style:UITableViewStyleGrouped] autorelease];
59 [table setDelegate:self]; 59 [table setDelegate:self];
60 [table setDataSource:self]; 60 [table setDataSource:self];
61 [[self loginDialog] addSubview:table]; 61 [[self loginDialog] addSubview:table];
62 [[self loginDialog] showInView:[[[UIApplication sharedApplication] windows] objectAtIndex:0]]; 62 [[self loginDialog] showInView:[[[UIApplication sharedApplication] windows] objectAtIndex:0]];
63 [[self loginDialog] setFrame:CGRectMake(0,0,320,480)]; 63 [[self loginDialog] setFrame:CGRectMake(0,0,320,480)];
64 64
65 - UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,80)] autorelease]; 65 + // Setup the title (Couldn't figure out how to put this in the same toolbar as the buttons)
66 - //[toolbar setFrame:CGRectMake(0,20,320,50)]; 66 + UIToolbar *titleBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,30)] autorelease];
  67 + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,0,300,30)];
  68 + if ([self type] == ASIProxyAuthenticationType) {
  69 + [label setText:@"Login to this secure proxy server."];
  70 + } else {
  71 + [label setText:@"Login to this secure server."];
  72 + }
  73 + [label setTextColor:[UIColor blackColor]];
  74 + [label setFont:[UIFont systemFontOfSize:13.0]];
  75 + [label setShadowColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:0.5]];
  76 + [label setShadowOffset:CGSizeMake(0, 1.0)];
  77 + [label setOpaque:NO];
  78 + [label setBackgroundColor:nil];
  79 + [label setTextAlignment:UITextAlignmentCenter];
  80 +
  81 + [titleBar addSubview:label];
  82 + [[self loginDialog] addSubview:titleBar];
  83 +
  84 + // Setup the toolbar
  85 + UIToolbar *toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0,30,320,50)] autorelease];
  86 +
67 NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease]; 87 NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
68 UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAuthenticationFromDialog:)] autorelease]; 88 UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAuthenticationFromDialog:)] autorelease];
69 - //[backButton setContentEdgeInsets:UIEdgeInsetsMake(0,20,0,0)];  
70 [items addObject:backButton]; 89 [items addObject:backButton];
71 90
72 - UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,170,50)]; 91 + label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,170,50)];
73 [label setText:[[[self request] url] host]]; 92 [label setText:[[[self request] url] host]];
74 [label setTextColor:[UIColor whiteColor]]; 93 [label setTextColor:[UIColor whiteColor]];
75 [label setFont:[UIFont boldSystemFontOfSize:22.0]]; 94 [label setFont:[UIFont boldSystemFontOfSize:22.0]];
@@ -80,14 +99,19 @@ NSLock *dialogLock = nil; @@ -80,14 +99,19 @@ NSLock *dialogLock = nil;
80 [label setTextAlignment:UITextAlignmentCenter]; 99 [label setTextAlignment:UITextAlignmentCenter];
81 100
82 [toolbar addSubview:label]; 101 [toolbar addSubview:label];
83 -  
84 - UIBarButtonItem *labelButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:nil action:nil] autorelease];  
85 102
86 - //[labelButton setCustomView:label]; 103 + UIBarButtonItem *labelButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:nil action:nil] autorelease];
87 - //[items addObject:labelButton]; 104 + [labelButton setCustomView:label];
  105 + [items addObject:labelButton];
88 [items addObject:[[[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleDone target:self action:@selector(loginWithCredentialsFromDialog:)] autorelease]]; 106 [items addObject:[[[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleDone target:self action:@selector(loginWithCredentialsFromDialog:)] autorelease]];
89 [toolbar setItems:items]; 107 [toolbar setItems:items];
  108 +
90 [[self loginDialog] addSubview:toolbar]; 109 [[self loginDialog] addSubview:toolbar];
  110 +
  111 + // Force reload the table content, and focus the first field to show the keyboard
  112 + [table reloadData];
  113 + [[[[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] subviews] objectAtIndex:2] becomeFirstResponder];
  114 +
91 } 115 }
92 116
93 - (void)cancelAuthenticationFromDialog:(id)sender 117 - (void)cancelAuthenticationFromDialog:(id)sender
@@ -164,10 +188,12 @@ NSLock *dialogLock = nil; @@ -164,10 +188,12 @@ NSLock *dialogLock = nil;
164 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section 188 - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
165 { 189 {
166 if (section == [self numberOfSectionsInTableView:tableView]-1) { 190 if (section == [self numberOfSectionsInTableView:tableView]-1) {
167 - if ([[[[self request] url] scheme] isEqualToString:@"https"]) { 191 + // If we're using Basic authentication and the connection is not using SSL, we'll show the plain text message
168 - return @"Password will be sent securely."; 192 + if ([[[self request] authenticationScheme] isEqualToString:(NSString *)kCFHTTPAuthenticationSchemeBasic] && ![[[[self request] url] scheme] isEqualToString:@"https"]) {
169 - } else {  
170 return @"Password will be sent in the clear."; 193 return @"Password will be sent in the clear.";
  194 + // We are using Digest, NTLM, or any scheme over SSL
  195 + } else {
  196 + return @"Password will be sent securely.";
171 } 197 }
172 } 198 }
173 return nil; 199 return nil;
@@ -267,26 +267,32 @@ @@ -267,26 +267,32 @@
267 [ASIHTTPRequest setProgress:progress forProgressIndicator:[self downloadProgressDelegate]]; 267 [ASIHTTPRequest setProgress:progress forProgressIndicator:[self downloadProgressDelegate]];
268 } 268 }
269 269
  270 +
270 // Since this queue takes over as the delegate for all requests it contains, it should forward authorisation requests to its own delegate 271 // Since this queue takes over as the delegate for all requests it contains, it should forward authorisation requests to its own delegate
271 -- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request 272 +- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request
272 { 273 {
273 - if ([[self delegate] respondsToSelector:@selector(authorizationNeededForRequest:)]) { 274 + if ([[self delegate] respondsToSelector:@selector(authenticationNeededForRequest:)]) {
274 - [[self delegate] performSelector:@selector(authorizationNeededForRequest:) withObject:request]; 275 + [[self delegate] performSelector:@selector(authenticationNeededForRequest:) withObject:request];
275 } 276 }
276 } 277 }
277 278
278 -- (void)proxyAuthorizationNeededForRequest:(ASIHTTPRequest *)request 279 +- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request
279 { 280 {
280 - if ([[self delegate] respondsToSelector:@selector(proxyAuthorizationNeededForRequest:)]) { 281 + if ([[self delegate] respondsToSelector:@selector(proxyAuthenticationNeededForRequest:)]) {
281 - [[self delegate] performSelector:@selector(proxyAuthorizationNeededForRequest:) withObject:request]; 282 + [[self delegate] performSelector:@selector(proxyAuthenticationNeededForRequest:) withObject:request];
282 } 283 }
283 } 284 }
284 285
285 286
286 - (BOOL)respondsToSelector:(SEL)selector 287 - (BOOL)respondsToSelector:(SEL)selector
287 { 288 {
288 - if (selector == @selector(authorizationNeededForRequest:)) { 289 + if (selector == @selector(authenticationNeededForRequest:)) {
289 - if ([[self delegate] respondsToSelector:@selector(authorizationNeededForRequest:)]) { 290 + if ([[self delegate] respondsToSelector:@selector(authenticationNeededForRequest:)]) {
  291 + return YES;
  292 + }
  293 + return NO;
  294 + } else if (selector == @selector(proxyAuthenticationNeededForRequest:)) {
  295 + if ([[self delegate] respondsToSelector:@selector(proxyAuthenticationNeededForRequest:)]) {
290 return YES; 296 return YES;
291 } 297 }
292 return NO; 298 return NO;
@@ -355,7 +355,7 @@ IMPORTANT @@ -355,7 +355,7 @@ IMPORTANT
355 } 355 }
356 356
357 357
358 -- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request 358 +- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request
359 { 359 {
360 // We're using this method in multiple tests: 360 // We're using this method in multiple tests:
361 // testProgressWithAuthentication will set a userInfo dictionary on the main request, to tell us not to supply credentials 361 // testProgressWithAuthentication will set a userInfo dictionary on the main request, to tell us not to supply credentials
@@ -45,31 +45,31 @@ @@ -45,31 +45,31 @@
45 [topSecretInfo setFont:[UIFont boldSystemFontOfSize:12]]; 45 [topSecretInfo setFont:[UIFont boldSystemFontOfSize:12]];
46 } 46 }
47 47
48 -//- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request 48 +- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request
49 -//{ 49 +{
50 -// // Why oh why is there no contextInfo for alertView like on Mac OS ?! 50 + // Why oh why is there no contextInfo for alertView like on Mac OS ?!
51 -// [self setRequestRequiringProxyAuthentication:nil]; 51 + [self setRequestRequiringProxyAuthentication:nil];
52 -// [self setRequestRequiringAuthentication:request]; 52 + [self setRequestRequiringAuthentication:request];
53 -// 53 +
54 -// [ASIHTTPRequest showAuthenticationDialogForRequest:request]; 54 +
55 -// 55 + UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
56 -// //UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease]; 56 + // These are undocumented, use at your own risk!
57 -// // These are undocumented, use at your own risk! 57 + // A better general approach would be to subclass UIAlertView, or just use ASIHTTPRequest's built-in dialog
58 -// // A better general approach would be to subclass UIAlertView 58 + [alertView addTextFieldWithValue:@"" label:@"Username"];
59 -// //[alertView addTextFieldWithValue:@"" label:@"Username"]; 59 + [alertView addTextFieldWithValue:@"" label:@"Password"];
60 -// //[alertView addTextFieldWithValue:@"" label:@"Password"]; 60 + [alertView show];
61 -// 61 +
62 -//} 62 +}
63 -// 63 +
64 -//- (void)proxyAuthorizationNeededForRequest:(ASIHTTPRequest *)request 64 +- (void)proxyAuthenticationNeededForRequest:(ASIHTTPRequest *)request
65 -//{ 65 +{
66 -// [self setRequestRequiringAuthentication:nil]; 66 + [self setRequestRequiringAuthentication:nil];
67 -// [self setRequestRequiringProxyAuthentication:request]; 67 + [self setRequestRequiringProxyAuthentication:request];
68 -// UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login to proxy" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease]; 68 + UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login to proxy" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
69 -// [alertView addTextFieldWithValue:@"" label:@"Username"]; 69 + [alertView addTextFieldWithValue:@"" label:@"Username"];
70 -// [alertView addTextFieldWithValue:@"" label:@"Password"]; 70 + [alertView addTextFieldWithValue:@"" label:@"Password"];
71 -// [alertView show]; 71 + [alertView show];
72 -//} 72 +}
73 73
74 74
75 75
@@ -86,14 +86,22 @@ @@ -86,14 +86,22 @@
86 [[self requestRequiringProxyAuthentication] retryWithAuthentication]; 86 [[self requestRequiringProxyAuthentication] retryWithAuthentication];
87 } 87 }
88 } else { 88 } else {
89 - if ([self requestRequiringAuthentication]) { 89 + [[self requestRequiringAuthentication] cancelAuthentication];
90 - [[self requestRequiringAuthentication] cancelLoad]; 90 + }
91 - } else { 91 +}
92 - [[self requestRequiringProxyAuthentication] cancelLoad]; 92 +
  93 +- (BOOL)respondsToSelector:(SEL)selector
  94 +{
  95 + if (selector == @selector(authenticationNeededForRequest:) || selector == @selector(proxyAuthenticationNeededForRequest:)) {
  96 + if ([useBuiltInDialog isOn]) {
  97 + return NO;
93 } 98 }
  99 + return YES;
94 } 100 }
  101 + return [super respondsToSelector:selector];
95 } 102 }
96 103
  104 +
97 - (void)didReceiveMemoryWarning { 105 - (void)didReceiveMemoryWarning {
98 [super didReceiveMemoryWarning]; 106 [super didReceiveMemoryWarning];
99 } 107 }