@class IndirectDelegate;
+@interface Diversion : NSObject
+- (id) initWithFrom:(NSString *)from to:(NSString *)to;
+@end
+
@protocol CyteWebViewControllerDelegate
- (void) retainNetworkActivityIndicator;
- (void) releaseNetworkActivityIndicator;
- (id) initWithWidth:(float)width;
- (id) initWithWidth:(float)width ofClass:(Class)_class;
++ (void) setApplicationNameForUserAgent:(NSString *)userAgent;
+- (NSString *) applicationNameForUserAgent;
+
- (void) callFunction:(WebScriptObject *)function;
- (void) reloadURLWithCache:(BOOL)cache;
- (void) registerFrame:(WebFrame *)frame;
++ (void) addDiversion:(Diversion *)diversion;
+
@end
#endif//CyteKit_WebViewController_H
@end
+// Diversion {{{
+static _H<NSMutableSet> Diversions_;
+
+@implementation Diversion {
+ RegEx pattern_;
+ _H<NSString> key_;
+ _H<NSString> format_;
+}
+
+- (id) initWithFrom:(NSString *)from to:(NSString *)to {
+ if ((self = [super init]) != nil) {
+ pattern_ = [from UTF8String];
+ key_ = from;
+ format_ = to;
+ } return self;
+}
+
+- (NSString *) divert:(NSString *)url {
+ return !pattern_(url) ? nil : pattern_->*format_;
+}
+
++ (NSURL *) divertURL:(NSURL *)url {
+ divert:
+ NSString *href([url absoluteString]);
+
+ for (Diversion *diversion in (id) Diversions_)
+ if (NSString *diverted = [diversion divert:href]) {
+#if !ForRelease
+ NSLog(@"div: %@", diverted);
+#endif
+ url = [NSURL URLWithString:diverted];
+ goto divert;
+ }
+
+ return url;
+}
+
+- (NSString *) key {
+ return key_;
+}
+
+- (NSUInteger) hash {
+ return [key_ hash];
+}
+
+- (BOOL) isEqual:(Diversion *)object {
+ return self == object || [self class] == [object class] && [key_ isEqual:[object key]];
+}
+
+@end
+// }}}
/* Indirect Delegate {{{ */
@implementation IndirectDelegate
CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
else // XXX: this actually might be fast on some older systems: we should look into this
CYScrollViewDecelerationRateNormal = 0.998;
+
+ Diversions_ = [NSMutableSet setWithCapacity:0];
}
- (bool) retainsNetworkActivityIndicator {
return (CyteWebViewController *) (IndirectDelegate *) indirect_;
}
++ (void) addDiversion:(Diversion *)diversion {
+ [Diversions_ addObject:diversion];
+}
+
- (NSURL *) URLWithURL:(NSURL *)url {
- return url;
+ return [Diversion divertURL:url];
}
- (NSURLRequest *) requestWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy referrer:(NSString *)referrer {
} return self;
}
+static _H<NSString> UserAgent_;
++ (void) setApplicationNameForUserAgent:(NSString *)userAgent {
+ UserAgent_ = userAgent;
+}
+
- (NSString *) applicationNameForUserAgent {
- return nil;
+ return UserAgent_;
}
- (void) loadView {
static NSString *ChipID_ = nil;
static NSString *BBSNum_ = nil;
static _H<NSString> UniqueID_;
-static _H<NSString> UserAgent_;
static _H<NSString> Product_;
static _H<NSString> Safari_;
@end
/* }}} */
-static _H<NSMutableSet> Diversions_;
-
-@interface Diversion : NSObject {
- RegEx pattern_;
- _H<NSString> key_;
- _H<NSString> format_;
-}
-
-@end
-
-@implementation Diversion
-
-- (id) initWithFrom:(NSString *)from to:(NSString *)to {
- if ((self = [super init]) != nil) {
- pattern_ = [from UTF8String];
- key_ = from;
- format_ = to;
- } return self;
-}
-
-- (NSString *) divert:(NSString *)url {
- return !pattern_(url) ? nil : pattern_->*format_;
-}
-
-+ (NSURL *) divertURL:(NSURL *)url {
- divert:
- NSString *href([url absoluteString]);
-
- for (Diversion *diversion in (id) Diversions_)
- if (NSString *diverted = [diversion divert:href]) {
-#if !ForRelease
- NSLog(@"div: %@", diverted);
-#endif
- url = [NSURL URLWithString:diverted];
- goto divert;
- }
-
- return url;
-}
-
-- (NSString *) key {
- return key_;
-}
-
-- (NSUInteger) hash {
- return [key_ hash];
-}
-
-- (BOOL) isEqual:(Diversion *)object {
- return self == object || [self class] == [object class] && [key_ isEqual:[object key]];
-}
-
-@end
-
@interface CydiaObject : NSObject {
_H<CyteWebViewController> indirect_;
_transient id delegate_;
_H<CydiaObject> cydia_;
}
-+ (void) addDiversion:(Diversion *)diversion;
+ (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request;
+ (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia;
- (void) setDelegate:(id)delegate;
}
- (void) addInternalRedirect:(NSString *)from :(NSString *)to {
- [CydiaWebViewController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO];
+ [CyteWebViewController performSelectorOnMainThread:@selector(addDiversion:) withObject:[[[Diversion alloc] initWithFrom:from to:to] autorelease] waitUntilDone:NO];
}
- (NSDictionary *) getApplicationInfo:(NSString *)display value:(NSString *)key {
return nil;
}
-+ (void) _initialize {
- [super _initialize];
-
- Diversions_ = [NSMutableSet setWithCapacity:0];
-}
-
-+ (void) addDiversion:(Diversion *)diversion {
- [Diversions_ addObject:diversion];
-}
-
- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
[super webView:view didClearWindowObject:window forFrame:frame];
[CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
[controller addAttachmentData:[NSData dataWithContentsOfFile:@"/tmp/dpkgl.log"] mimeType:@"text/plain" fileName:@"dpkgl.log"];
}
-- (NSURL *) URLWithURL:(NSURL *)url {
- return [Diversion divertURL:url];
-}
-
- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
return [CydiaWebViewController requestWithHeaders:[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source]];
}
[cydia_ setDelegate:delegate];
}
-- (NSString *) applicationNameForUserAgent {
- return UserAgent_;
-}
-
- (id) init {
if ((self = [super initWithWidth:0 ofClass:[CydiaWebViewController class]]) != nil) {
cydia_ = [[[CydiaObject alloc] initWithDelegate:self.indirect] autorelease];
[BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]];
}
- [CydiaWebViewController _initialize];
+ [CyteWebViewController _initialize];
[NSURLProtocol registerClass:[CydiaURLProtocol class]];
if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", Product_))
agent = [NSString stringWithFormat:@"Version/%@ %@", match[1], agent];
- UserAgent_ = agent;
+ [CyteWebViewController setApplicationNameForUserAgent:agent];
/* }}} */
/* Load Database {{{ */
SectionMap_ = [[[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sections" ofType:@"plist"]] autorelease];