-
Notifications
You must be signed in to change notification settings - Fork 2
/
CydiaBrowserView.mm
58 lines (44 loc) · 2.08 KB
/
CydiaBrowserView.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#import "CydiaBrowserView.h"
@implementation CydiaBrowserView
- (void) dealloc {
[cydia_ release];
[super dealloc];
}
- (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
[super webView:sender didClearWindowObject:window forFrame:frame];
[window setValue:cydia_ forKey:@"cydia"];
}
- (void) _setMoreHeaders:(NSMutableURLRequest *)request {
if (System_ != NULL)
[request setValue:System_ forHTTPHeaderField:@"X-System"];
if (Machine_ != NULL)
[request setValue:[NSString stringWithUTF8String:Machine_] forHTTPHeaderField:@"X-Machine"];
if (UniqueID_ != nil)
[request setValue:UniqueID_ forHTTPHeaderField:@"X-Unique-ID"];
if (Role_ != nil)
[request setValue:Role_ forHTTPHeaderField:@"X-Role"];
}
- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
NSMutableURLRequest *copy = [request mutableCopy];
[self _setMoreHeaders:copy];
return copy;
}
- (id) initWithBook:(RVBook *)book forWidth:(float)width {
if ((self = [super initWithBook:book forWidth:width ofClass:[CydiaBrowserView class]]) != nil) {
cydia_ = [[CydiaObject alloc] initWithDelegate:indirect_];
WebView *webview([webview_ webView]);
Package *package([[Database sharedInstance] packageWithName:@"cydia"]);
NSString *application = package == nil ? @"Cydia" : [NSString
stringWithFormat:@"Cydia/%@",
[package installed]
];
if (Safari_ != nil)
application = [NSString stringWithFormat:@"Safari/%@ %@", Safari_, application];
if (Build_ != nil)
application = [NSString stringWithFormat:@"Mobile/%@ %@", Build_, application];
if (Product_ != nil)
application = [NSString stringWithFormat:@"Version/%@ %@", Product_, application];
[webview setApplicationNameForUserAgent:application];
} return self;
}
@end