return url;
}
-- (NSURLRequest *) requestWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
- return [NSURLRequest
+- (NSURLRequest *) requestWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy referrer:(NSString *)referrer {
+ NSMutableURLRequest *request([NSMutableURLRequest
requestWithURL:[self URLWithURL:url]
cachePolicy:policy
timeoutInterval:DefaultTimeout_
- ];
+ ]);
+
+ [request setValue:referrer forHTTPHeaderField:@"Referer"];
+
+ return request;
}
- (void) setRequest:(NSURLRequest *)request {
}
- (void) setURL:(NSURL *)url {
- [self setRequest:[self requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy]];
+ [self setURL:url withReferrer:nil];
+}
+
+- (void) setURL:(NSURL *)url withReferrer:(NSString *)referrer {
+ [self setRequest:[self requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy referrer:referrer]];
}
- (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
- [self loadRequest:[self requestWithURL:url cachePolicy:policy]];
+ [self loadRequest:[self requestWithURL:url cachePolicy:policy referrer:nil]];
}
- (void) loadURL:(NSURL *)url {
}
}
-- (void) pushRequest:(NSURLRequest *)request asPop:(bool)pop {
+- (void) pushRequest:(NSURLRequest *)request forAction:(NSDictionary *)action asPop:(bool)pop {
+ WebFrame *frame(nil);
+ if (NSDictionary *WebActionElement = [action objectForKey:@"WebActionElementKey"])
+ frame = [WebActionElement objectForKey:@"WebElementFrame"];
+ if (frame == nil)
+ frame = [[[[self webView] _documentView] webView] mainFrame];
+
+ WebDataSource *source([frame provisionalDataSource] ?: [frame dataSource]);
+ NSString *referrer([request valueForHTTPHeaderField:@"Referer"] ?: [[[source request] URL] absoluteString]);
+
NSURL *url([request URL]);
// XXX: filter to internal usage?
- CyteViewController *page([delegate_ pageForURL:url forExternal:NO]);
+ CyteViewController *page([delegate_ pageForURL:url forExternal:NO withReferrer:referrer]);
if (page == nil) {
CyteWebViewController *browser([[[class_ alloc] init] autorelease]);
- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
#if LogBrowser
- NSLog(@"decidePolicyForNavigationAction:%@ request:%@ frame:%@", action, request, frame);
+ NSLog(@"decidePolicyForNavigationAction:%@ request:%@ %@ frame:%@", action, request, [request allHTTPHeaderFields], frame);
#endif
if ([frame parentFrame] == nil) {
if (request_ != nil && ![[request_ URL] isEqual:url] && ![self allowsNavigationAction]) {
if (url != nil)
- [self pushRequest:request asPop:NO];
+ [self pushRequest:request forAction:action asPop:NO];
[listener ignore];
}
}
request_ = request;
}
-- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
#if LogBrowser
- NSLog(@"decidePolicyForNewWindowAction:%@ request:%@ newFrameName:%@", action, request, frame);
+ NSLog(@"decidePolicyForNewWindowAction:%@ request:%@ %@ newFrameName:%@", action, request, [request allHTTPHeaderFields], name);
#endif
NSURL *url([request URL]);
if (url == nil)
return;
- if ([frame isEqualToString:@"_open"])
+ if ([name isEqualToString:@"_open"])
[delegate_ openURL:url];
else {
NSString *scheme([[url scheme] lowercaseString]);
if ([scheme isEqualToString:@"mailto"])
[self _openMailToURL:url];
else
- [self pushRequest:request asPop:[frame isEqualToString:@"_popup"]];
+ [self pushRequest:request forAction:action asPop:[name isEqualToString:@"_popup"]];
}
[listener ignore];
- (void) showSettings;
- (UIProgressHUD *) addProgressHUD;
- (void) removeProgressHUD:(UIProgressHUD *)hud;
-- (CyteViewController *) pageForPackage:(NSString *)name;
- (void) showActionSheet:(UIActionSheet *)sheet fromItem:(UIBarButtonItem *)item;
- (void) reloadDataWithInvocation:(NSInvocation *)invocation;
@end
_H<UIBarButtonItem> button_;
}
-- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name;
+- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name withReferrer:(NSString *)referrer;
@end
}
#endif
-- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name {
+- (id) initWithDatabase:(Database *)database forPackage:(NSString *)name withReferrer:(NSString *)referrer {
if ((self = [super init]) != nil) {
database_ = database;
buttons_ = [NSMutableArray arrayWithCapacity:4];
name_ = name == nil ? @"" : [NSString stringWithString:name];
- [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/package/%@", UI_, (id) name_]]];
+ [self setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/package/%@", UI_, (id) name_]] withReferrer:referrer];
} return self;
}
@implementation PackageListController
+- (NSURL *) referrerURL {
+ return [self navigationURL];
+}
+
- (bool) isSummarized {
return false;
}
}
- (void) didSelectPackage:(Package *)package {
- CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id]] autorelease]);
+ CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id] withReferrer:[[self referrerURL] absoluteString]] autorelease]);
[view setDelegate:delegate_];
[[self navigationController] pushViewController:view animated:YES];
}
@implementation SectionController
+- (NSURL *) referrerURL {
+ NSString *name = section_;
+ if (name == nil)
+ name = @"all";
+
+ return [NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/sections/%@", UI_, [name stringByAddingPercentEscapesIncludingReserved]]];
+}
+
- (NSURL *) navigationURL {
NSString *name = section_;
if (name == nil)
if ([frame isEqualToString:@"_open"])
[delegate_ openURL:url];
else {
- CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+ WebFrame *frame(nil);
+ if (NSDictionary *WebActionElement = [action objectForKey:@"WebActionElementKey"])
+ frame = [WebActionElement objectForKey:@"WebElementFrame"];
+ if (frame == nil)
+ frame = [view mainFrame];
+
+ WebDataSource *source([frame provisionalDataSource] ?: [frame dataSource]);
+
+ CyteViewController *controller([delegate_ pageForURL:url forExternal:NO withReferrer:([request valueForHTTPHeaderField:@"Referer"] ?: [[[source request] URL] absoluteString])] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
[controller setDelegate:delegate_];
[[self navigationController] pushViewController:controller animated:YES];
}
- (NSIndexPath *) tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path {
Package *package([self packageAtIndexPath:path]);
- CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id]] autorelease]);
+ CYPackageController *view([[[CYPackageController alloc] initWithDatabase:database_ forPackage:[package id] withReferrer:[NSString stringWithFormat:@"%@/#!/changes/", UI_]] autorelease]);
[view setDelegate:delegate_];
[[self navigationController] pushViewController:view animated:YES];
return path;
if ([frame isEqualToString:@"_open"])
[delegate_ openURL:url];
else {
- CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+ WebFrame *frame(nil);
+ if (NSDictionary *WebActionElement = [action objectForKey:@"WebActionElementKey"])
+ frame = [WebActionElement objectForKey:@"WebElementFrame"];
+ if (frame == nil)
+ frame = [view mainFrame];
+
+ WebDataSource *source([frame provisionalDataSource] ?: [frame dataSource]);
+
+ CyteViewController *controller([delegate_ pageForURL:url forExternal:NO withReferrer:([request valueForHTTPHeaderField:@"Referer"] ?: [[[source request] URL] absoluteString])] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
[controller setDelegate:delegate_];
[[self navigationController] pushViewController:controller animated:YES];
}
@implementation SearchController
+- (NSURL *) referrerURL {
+ return [NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/search?q=%@", UI_, [([search_ text] ?: @"") stringByAddingPercentEscapesIncludingReserved]]];
+}
+
- (NSURL *) navigationURL {
if ([search_ text] == nil || [[search_ text] isEqualToString:@""])
return [NSURL URLWithString:@"cydia://search"];
@implementation InstalledController
+- (NSURL *) referrerURL {
+ return [NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/installed/", UI_]];
+}
+
- (NSURL *) navigationURL {
return [NSURL URLWithString:@"cydia://installed"];
}
@implementation SourceController
+- (NSURL *) referrerURL {
+ return [NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/sources/%@", UI_, [key_ stringByAddingPercentEscapesIncludingReserved]]];
+}
+
- (NSURL *) navigationURL {
return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sources/%@", [key_ stringByAddingPercentEscapesIncludingReserved]]];
}
[window_ setUserInteractionEnabled:YES];
}
-- (CyteViewController *) pageForPackage:(NSString *)name {
- return [[[CYPackageController alloc] initWithDatabase:database_ forPackage:name] autorelease];
+- (CyteViewController *) pageForPackage:(NSString *)name withReferrer:(NSString *)referrer {
+ return [[[CYPackageController alloc] initWithDatabase:database_ forPackage:name withReferrer:referrer] autorelease];
}
-- (CyteViewController *) pageForURL:(NSURL *)url forExternal:(BOOL)external {
+- (CyteViewController *) pageForURL:(NSURL *)url forExternal:(BOOL)external withReferrer:(NSString *)referrer {
NSString *scheme([[url scheme] lowercaseString]);
if ([[url absoluteString] length] <= [scheme length] + 3)
return nil;
NSArray *components([path componentsSeparatedByString:@"/"]);
if ([scheme isEqualToString:@"apptapp"] && [components count] > 0 && [[components objectAtIndex:0] isEqualToString:@"package"]) {
- CyteViewController *controller([self pageForPackage:[components objectAtIndex:1]]);
+ CyteViewController *controller([self pageForPackage:[components objectAtIndex:1] withReferrer:referrer]);
if (controller != nil)
[controller setDelegate:self];
return controller;
NSString *argument = [components objectAtIndex:1];
if ([base isEqualToString:@"package"]) {
- controller = [self pageForPackage:argument];
+ controller = [self pageForPackage:argument withReferrer:referrer];
}
if (!external && [base isEqualToString:@"search"]) {
}
- (BOOL) openCydiaURL:(NSURL *)url forExternal:(BOOL)external {
- CyteViewController *page([self pageForURL:url forExternal:external]);
+ CyteViewController *page([self pageForURL:url forExternal:external withReferrer:nil]);
if (page != nil)
[tabbar_ setUnselectedViewController:page];
for (unsigned int nav = 0; nav < [stack count]; nav++) {
NSString *addr = [stack objectAtIndex:nav];
NSURL *url = [NSURL URLWithString:addr];
- CyteViewController *page = [self pageForURL:url forExternal:NO];
+ CyteViewController *page = [self pageForURL:url forExternal:NO withReferrer:nil];
if (page != nil)
[current addObject:page];
}