iOS web browser with a focus on security and privacy
1/*
2 * Endless
3 * Copyright (c) 2014-2017 joshua stein <jcs@jcs.org>
4 *
5 * See LICENSE file for redistribution terms.
6 */
7
8#import <Foundation/Foundation.h>
9#import <UIKit/UIKit.h>
10
11#import "SSLCertificate.h"
12
13#define ZOOM_OUT_SCALE 0.8
14#define ZOOM_OUT_SCALE_ROTATED 0.7
15
16typedef NS_ENUM(NSInteger, WebViewTabSecureMode) {
17 WebViewTabSecureModeInsecure,
18 WebViewTabSecureModeMixed,
19 WebViewTabSecureModeSecure,
20 WebViewTabSecureModeSecureEV,
21};
22
23static const struct keyboard_map_entry {
24 char *input;
25 int keycode;
26 int keypress_keycode;
27 int shift_keycode;
28 int shift_keypress_keycode;
29} keyboard_map[] = {
30 { "UIKeyInputEscape", 27, 0, 0 },
31
32 { "`", 192, '`', '~' },
33 { "1", '1', '1', '!' },
34 { "2", '2', '2', '@' },
35 { "3", '3', '3', '#' },
36 { "4", '4', '4', '$' },
37 { "5", '5', '5', '%' },
38 { "6", '6', '6', '^' },
39 { "7", '7', '7', '&' },
40 { "8", '8', '8', '*' },
41 { "9", '9', '9', '(' },
42 { "0", '0', '0', ')' },
43 { "-", 189, '-', '_' },
44 { "=", 187, '=', '+' },
45 { "\b", 8, 0, 0 },
46
47 { "\t", 9, 0, 0 },
48 { "q", 'Q', 'q', 'Q' },
49 { "w", 'W', 'w', 'W' },
50 { "e", 'E', 'e', 'E' },
51 { "r", 'R', 'r', 'R' },
52 { "t", 'T', 't', 'T' },
53 { "y", 'Y', 'y', 'Y' },
54 { "u", 'U', 'u', 'U' },
55 { "i", 'I', 'i', 'I' },
56 { "o", 'O', 'o', 'O' },
57 { "p", 'P', 'p', 'P' },
58 { "[", 219, '[', '{' },
59 { "]", 221, ']', '}' },
60 { "\\", 220, '\\', '|' },
61
62 { "a", 'A', 'a', 'A' },
63 { "s", 'S', 's', 'S' },
64 { "d", 'D', 'd', 'D' },
65 { "f", 'F', 'f', 'F' },
66 { "g", 'G', 'g', 'G' },
67 { "h", 'H', 'h', 'H' },
68 { "j", 'J', 'j', 'J' },
69 { "k", 'K', 'k', 'K' },
70 { "l", 'L', 'l', 'L' },
71 { ";", 186, ';', ':' },
72 { "'", 222, '\'', '"' },
73 { "\r", 13, 0, 0 },
74
75 { "z", 'Z', 'z', 'Z' },
76 { "x", 'X', 'x', 'X' },
77 { "c", 'C', 'c', 'C' },
78 { "v", 'V', 'v', 'V' },
79 { "b", 'B', 'b', 'B' },
80 { "n", 'N', 'n', 'N' },
81 { "m", 'M', 'm', 'M' },
82 { ",", 188, ',', '<' },
83 { ".", 190, '.', '>' },
84 { "/", 191, '/', '/' },
85
86 { " ", ' ', ' ', ' ' },
87 { "UIKeyInputLeftArrow", 37, 0, 0 },
88 { "UIKeyInputUpArrow", 38, 0, 0 },
89 { "UIKeyInputRightArrow", 39, 0, 0 },
90 { "UIKeyInputDownArrow", 40, 0, 0 },
91
92 { NULL }
93};
94
95@interface WebViewTab : NSObject <UIWebViewDelegate, UIGestureRecognizerDelegate>
96
97@property (strong, atomic) UIView *viewHolder;
98@property (strong, atomic) UIWebView *webView;
99@property (strong, atomic) NSURL *url;
100@property BOOL needsRefresh;
101@property (strong, atomic) NSNumber *tabIndex;
102@property (strong, atomic) UIView *titleHolder;
103@property (strong, atomic) UILabel *title;
104@property (strong, atomic) UILabel *closer;
105@property (strong, nonatomic) NSNumber *progress;
106
107@property WebViewTabSecureMode secureMode;
108@property (strong, nonatomic) SSLCertificate *SSLCertificate;
109@property NSMutableDictionary *applicableHTTPSEverywhereRules;
110
111/* for javascript IPC */
112@property (strong, atomic) NSString *randID;
113@property (strong, atomic) NSNumber *openedByTabHash;
114
115+ (WebViewTab *)openedWebViewTabByRandID:(NSString *)randID;
116
117- (id)initWithFrame:(CGRect)frame;
118- (id)initWithFrame:(CGRect)frame withRestorationIdentifier:(NSString *)rid;
119- (void)updateFrame:(CGRect)frame;
120- (void)loadURL:(NSURL *)u;
121- (void)searchFor:(NSString *)query;
122- (BOOL)canGoBack;
123- (BOOL)canGoForward;
124- (void)goBack;
125- (void)goForward;
126- (void)refresh;
127- (void)forceRefresh;
128- (void)zoomOut;
129- (void)zoomNormal;
130- (void)handleKeyCommand:(UIKeyCommand *)keyCommand;
131
132@end