iOS web browser with a focus on security and privacy
1/*
2 * Endless
3 * Copyright (c) 2017 joshua stein <jcs@jcs.org>
4 *
5 * See LICENSE file for redistribution terms.
6 */
7
8#import "URLBlockerRuleController.h"
9#import "URLBlocker.h"
10
11#import "HTTPSEverywhere.h"
12
13@implementation URLBlockerRuleController
14
15- (id)initWithStyle:(UITableViewStyle)style
16{
17 self = [super initWithStyle:style];
18
19 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", nil) style:UIBarButtonItemStyleDone target:self.navigationController action:@selector(dismissModalViewControllerAnimated:)];
20
21 self.sortedRuleRows = [[NSMutableArray alloc] initWithCapacity:[[URLBlocker targets] count]];
22 self.inUseRuleRows = [[NSMutableArray alloc] init];
23
24 NSDictionary *inUse = nil;
25 if ([[self.appDelegate webViewController] curWebViewTab] != nil)
26 inUse = [[[self.appDelegate webViewController] curWebViewTab] applicableURLBlockerTargets];
27
28 for (NSString *k in [[[URLBlocker targets] allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]) {
29 RuleEditorRow *row = [[RuleEditorRow alloc] init];
30 row.key = k;
31 row.textLabel = k;
32 row.detailTextLabel = [[URLBlocker targets] objectForKey:k];
33
34 if (inUse && [inUse objectForKey:k])
35 [self.inUseRuleRows addObject:row];
36 else
37 [self.sortedRuleRows addObject:row];
38 }
39
40 self.inUseRuleRows = [NSMutableArray arrayWithArray:self.inUseRuleRows];
41 self.sortedRuleRows = [NSMutableArray arrayWithArray:self.sortedRuleRows];
42
43 self.title = NSLocalizedString(@"Blocked 3rd-Party Hosts", nil);
44
45 return self;
46}
47
48- (NSString *)ruleDisabledReason:(RuleEditorRow *)row
49{
50 return [[URLBlocker disabledTargets] objectForKey:[row key]];
51}
52
53- (void)disableRuleForRow:(RuleEditorRow *)row withReason:(NSString *)reason
54{
55 [URLBlocker disableTargetByHost:[row key] withReason:reason];
56}
57
58- (void)enableRuleForRow:(RuleEditorRow *)row
59{
60 [URLBlocker enableTargetByHost:[row key]];
61}
62
63@end