#include "UCPlatform.h"
#include <UICaboodle/BrowserView.h>
+#include "UICaboodle/PerlCompatibleRegEx.hpp"
#include <UICaboodle/UCLocalize.h>
//#include <QuartzCore/CALayer.h>
@end
/* Indirect Delegate {{{ */
-@interface IndirectDelegate : NSObject <
- HookProtocol
-> {
+@interface IndirectDelegate : NSObject {
_transient volatile id delegate_;
}
return self;
}
-- (void) didDismissModalViewController {
- if (delegate_ != nil)
- return [delegate_ didDismissModalViewController];
-}
-
- (IMP) methodForSelector:(SEL)sel {
if (IMP method = [super methodForSelector:sel])
return method;
if (challenge_ != nil)
[challenge_ release];
- if (request_ != nil)
- [request_ release];
-
- if (closer_ != nil)
- [closer_ release];
-
if (title_ != nil)
[title_ release];
[super dealloc];
}
-- (void) setURL:(NSURL *)url {
- _assert(request_ == nil);
+- (NSURL *) URLWithURL:(NSURL *)url {
+ return url;
+}
- request_ = [[NSURLRequest
- requestWithURL:url
- cachePolicy:NSURLRequestUseProtocolCachePolicy
+- (NSURLRequest *) requestWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
+ return [NSURLRequest
+ requestWithURL:[self URLWithURL:url]
+ cachePolicy:policy
timeoutInterval:DefaultTimeout_
- ] retain];
+ ];
+}
+
+- (void) setURL:(NSURL *)url {
+ _assert(request_ == nil);
+ request_ = [self requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
}
- (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
- [self loadRequest:[NSURLRequest
- requestWithURL:url
- cachePolicy:policy
- timeoutInterval:DefaultTimeout_
- ]];
+ [self loadRequest:[self requestWithURL:url cachePolicy:policy]];
}
- (void) loadURL:(NSURL *)url {
NSMutableURLRequest *request([request_ mutableCopy]);
[request setCachePolicy:(cache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData)];
- [request_ autorelease];
- request_ = [request retain];
+ request_ = request;
if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
[self loadRequest:request_];
[self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
}
-- (void) setPopupHook:(id)function {
- if (closer_ != nil)
- [closer_ autorelease];
- if (function == nil)
- closer_ = nil;
- else
- closer_ = [function retain];
-}
-
- (void) scrollToBottomAnimated:(NSNumber *)animated {
CGSize size([scroller_ contentSize]);
CGPoint offset([scroller_ contentOffset]);
return true;
}
+- (bool) allowsNavigationAction {
+ return allowsNavigationAction_;
+}
+
+- (void) setAllowsNavigationAction:(bool)value {
+ allowsNavigationAction_ = value;
+}
+
+- (void) setAllowsNavigationActionByNumber:(NSNumber *)value {
+ [self setAllowsNavigationAction:[value boolValue]];
+}
+
+- (void) popViewControllerWithNumber:(NSNumber *)value {
+ UINavigationController *navigation([self navigationController]);
+ if ([navigation topViewController] == self)
+ [navigation popViewControllerAnimated:[value boolValue]];
+}
+
- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
[loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
[self _didFinishLoading];
}
}
+- (void) pushRequest:(NSURLRequest *)request asPop:(bool)pop {
+ NSURL *url([request URL]);
+
+ // XXX: filter to internal usage?
+ CYViewController *page([delegate_ pageForURL:url forExternal:NO]);
+
+ if (page == nil) {
+ BrowserController *browser([[[class_ alloc] init] autorelease]);
+ [browser loadRequest:request];
+ page = browser;
+ }
+
+ [page setDelegate:delegate_];
+
+ if (!pop) {
+ [[self navigationItem] setTitle:title_];
+
+ [[self navigationController] pushViewController:page animated:YES];
+ } else {
+ UINavigationController *navigation([[[UINavigationController alloc] initWithRootViewController:page] autorelease]);
+
+ [navigation setDelegate:delegate_];
+
+ [[page navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
+ initWithTitle:UCLocalize("CLOSE")
+ style:UIBarButtonItemStylePlain
+ target:page
+ action:@selector(close)
+ ] autorelease]];
+
+ [[self navigationController] presentModalViewController:navigation animated:YES];
+
+ [delegate_ unloadData];
+ }
+}
+
// CYWebViewDelegate {{{
- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
#if LogMessages
+ static Pcre irritating("^(?:The page at .* displayed insecure content from .*\\.|Unsafe JavaScript attempt to access frame with URL .* from frame with URL .*\\. Domains, protocols and ports must match\\.)\\n$");
+ if (NSString *data = [message objectForKey:@"message"])
+ if (irritating(data))
+ return;
+
NSLog(@"addMessageToConsole:%@", message);
#endif
}
if ([frame parentFrame] == nil) {
if (!error_) {
- if (request_ != nil)
- [request_ autorelease];
- if (request == nil)
- request_ = nil;
- else
- request_ = [request retain];
+ NSURL *url(request == nil ? nil : [request URL]);
+
+ if (request_ == nil || [self allowsNavigationAction] || [[request_ URL] isEqual:url])
+ request_ = request;
+ else {
+ if (url != nil)
+ [self pushRequest:request asPop:NO];
+ [listener ignore];
+ }
}
}
}
if ([frame isEqualToString:@"_open"])
[delegate_ openURL:url];
-
- NSString *scheme([[url scheme] lowercaseString]);
- if ([scheme isEqualToString:@"mailto"])
- [self _openMailToURL:url];
-
- // XXX: filter to internal usage?
- CYViewController *page([delegate_ pageForURL:url forExternal:NO]);
-
- if (page == nil) {
- BrowserController *browser([[[class_ alloc] init] autorelease]);
- [browser loadRequest:request];
- page = browser;
- }
-
- [page setDelegate:delegate_];
-
- if (![frame isEqualToString:@"_popup"]) {
- [[self navigationItem] setTitle:title_];
-
- [[self navigationController] pushViewController:page animated:YES];
- } else {
- UCNavigationController *navigation([[[UCNavigationController alloc] initWithRootViewController:page] autorelease]);
-
- [navigation setHook:indirect_];
- [navigation setDelegate:delegate_];
-
- [[page navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
- initWithTitle:UCLocalize("CLOSE")
- style:UIBarButtonItemStylePlain
- target:page
- action:@selector(close)
- ] autorelease]];
-
- [[self navigationController] presentModalViewController:navigation animated:YES];
+ else {
+ NSString *scheme([[url scheme] lowercaseString]);
+ if ([scheme isEqualToString:@"mailto"])
+ [self _openMailToURL:url];
+ else
+ [self pushRequest:request asPop:[frame isEqualToString:@"_popup"]];
}
[listener ignore];
for (DOMHTMLBodyElement *body in (id) bodies) {
DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
- bool colored(false);
+ UIColor *uic(nil);
if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) {
if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
- UIColor *uic(nil);
-
if (red == 0xc7 && green == 0xce && blue == 0xd5)
- uic = [UIColor groupTableViewBackgroundColor];
+ uic = [UIColor pinStripeColor];
else if (alpha != 0)
uic = [UIColor
colorWithRed:(red / 255)
blue:(blue / 255)
alpha:alpha
];
-
- if (uic != nil) {
- colored = true;
- [scroller_ setBackgroundColor:uic];
- }
}
}
- if (!colored)
- [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
+ [scroller_ setBackgroundColor:(uic ?: [UIColor clearColor])];
break;
}
}
custom_ = nil;
style_ = nil;
function_ = nil;
- CYRelease(closer_);
+
+ [self setHidesNavigationBar:NO];
// XXX: do we still need to do this?
[[self navigationItem] setTitle:nil];
- (id) initWithWidth:(float)width ofClass:(Class)_class {
if ((self = [super init]) != nil) {
+ allowsNavigationAction_ = true;
+
class_ = _class;
loading_ = [[NSMutableSet alloc] initWithCapacity:5];
indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
- webview_ = [[[CYWebView alloc] initWithFrame:[[self view] bounds]] autorelease];
+ CGRect bounds([[self view] bounds]);
+
+ webview_ = [[[CYWebView alloc] initWithFrame:bounds] autorelease];
[webview_ setDelegate:self];
[self setView:webview_];
}
[scroller_ setFixedBackgroundPattern:YES];
- [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
+ [scroller_ setBackgroundColor:[UIColor clearColor]];
[scroller_ setClipsSubviews:YES];
[scroller_ setBounces:YES];
indicator_ = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[indicator_ setFrame:CGRectMake(15, 5, [indicator_ frame].size.width, [indicator_ frame].size.height)];
+ UITableView *table([[[UITableView alloc] initWithFrame:bounds style:UITableViewStyleGrouped] autorelease]);
+ [webview_ insertSubview:table atIndex:0];
+
+ [table setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
[indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
} return self;
} return self;
}
-- (void) didDismissModalViewController {
- if (closer_ != nil)
- [self callFunction:closer_];
-}
-
- (void) callFunction:(WebScriptObject *)function {
WebThreadLocked lock;
[[[self navigationController] navigationBar] setBarStyle:style];
}
+- (void) setNavigationBarTintColor:(UIColor *)color {
+ [[[self navigationController] navigationBar] setTintColor:color];
+}
+
- (void) setHidesBackButton:(bool)value {
[[self navigationItem] setHidesBackButton:value];
}
}
}
+- (bool) hidesNavigationBar {
+ return hidesNavigationBar_;
+}
+
+- (void) _setHidesNavigationBar:(bool)value animated:(bool)animated {
+ if (visible_)
+ [[self navigationController] setNavigationBarHidden:(value && [self hidesNavigationBar]) animated:animated];
+}
+
+- (void) setHidesNavigationBar:(bool)value {
+ if (hidesNavigationBar_ != value) {
+ hidesNavigationBar_ = value;
+ [self _setHidesNavigationBar:YES animated:YES];
+ }
+}
+
+- (void) setHidesNavigationBarByNumber:(NSNumber *)value {
+ [self setHidesNavigationBar:[value boolValue]];
+}
+
- (void) viewWillAppear:(BOOL)animated {
+ visible_ = true;
+
+ if ([self hidesNavigationBar])
+ [self _setHidesNavigationBar:YES animated:animated];
+
[self dispatchEvent:@"CydiaViewWillAppear"];
[super viewWillAppear:animated];
}
- (void) viewDidAppear:(BOOL)animated {
- [self dispatchEvent:@"CydiaViewDidAppear"];
[super viewDidAppear:animated];
+ [self dispatchEvent:@"CydiaViewDidAppear"];
}
- (void) viewWillDisappear:(BOOL)animated {
[self dispatchEvent:@"CydiaViewWillDisappear"];
[super viewWillDisappear:animated];
+
+ if ([self hidesNavigationBar])
+ [self _setHidesNavigationBar:NO animated:animated];
+
+ visible_ = false;
}
- (void) viewDidDisappear:(BOOL)animated {
- [self dispatchEvent:@"CydiaViewDidDisappear"];
[super viewDidDisappear:animated];
+ [self dispatchEvent:@"CydiaViewDidDisappear"];
}
@end