iOS web browser with a focus on security and privacy
at master 98 lines 3.0 kB view raw
1/* 2 * Endless 3 * Copyright (c) 2014-2015 joshua stein <jcs@jcs.org> 4 * 5 * See LICENSE file for redistribution terms. 6 */ 7 8#import "AppDelegate.h" 9#import "CookieController.h" 10 11@implementation CookieController { 12 AppDelegate *appDelegate; 13 NSMutableArray *sortedCookieHosts; 14} 15 16- (void)viewDidLoad 17{ 18 [super viewDidLoad]; 19 20 appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 21 22 sortedCookieHosts = [NSMutableArray arrayWithArray:[[appDelegate cookieJar] sortedHostCounts]]; 23 24 self.title = NSLocalizedString(@"Cookies and Local Storage", nil); 25 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) style:UIBarButtonItemStyleDone target:self.navigationController action:@selector(dismissModalViewControllerAnimated:)]; 26} 27 28- (void)didReceiveMemoryWarning 29{ 30 [super didReceiveMemoryWarning]; 31 // Dispose of any resources that can be recreated. 32} 33 34#pragma mark - Table view data source 35 36- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 37{ 38 return 1; 39} 40 41- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 42{ 43 return [sortedCookieHosts count]; 44} 45 46- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 47{ 48 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cookie"]; 49 if (cell == nil) 50 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cookie"]; 51 52 NSDictionary *c = [sortedCookieHosts objectAtIndex:indexPath.row]; 53 cell.textLabel.text = [c allKeys][0]; 54 NSDictionary *ccounts = [c allValues][0]; 55 int ccount = [[ccounts objectForKey:@"cookies"] intValue]; 56 int lscount = [[ccounts objectForKey:@"localStorage"] intValue]; 57 58 if (ccount) { 59 cell.detailTextLabel.text = [NSString stringWithFormat:@"%d cookie%@", ccount, (ccount == 1 ? @"" : @"s")]; 60 } 61 if (lscount) { 62 if (ccount) { 63 cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, local storage", cell.detailTextLabel.text]; 64 } 65 else { 66 cell.detailTextLabel.text = [NSString stringWithFormat:@"local storage"]; 67 } 68 } 69 70 return cell; 71} 72 73- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 74{ 75 return YES; 76} 77 78- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 79{ 80 [tableView deselectRowAtIndexPath:indexPath animated:YES]; 81} 82 83- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 84{ 85 if (editingStyle == UITableViewCellEditingStyleDelete) { 86 [[appDelegate cookieJar] clearAllDataForHost:[[sortedCookieHosts objectAtIndex:[indexPath row]] allKeys][0]]; 87 [sortedCookieHosts removeObjectAtIndex:[indexPath row]]; 88 89 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 90 } 91} 92 93- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 94{ 95 return NO; 96} 97 98@end