1 #include "CyteKit/UCPlatform.h"
3 #include <UIKit/UIKit.h>
4 #include "iPhonePrivate.h"
6 #include "CyteKit/Localize.h"
7 #include "CyteKit/WebViewController.h"
8 #include "CyteKit/PerlCompatibleRegEx.hpp"
9 #include "CyteKit/WebThreadLocked.hpp"
11 //#include <QuartzCore/CALayer.h>
12 // XXX: fix the minimum requirement
13 extern NSString * const kCAFilterNearest;
15 #include <WebCore/WebCoreThread.h>
17 #include <WebKit/WebPreferences.h>
19 #include <WebKit/DOMCSSPrimitiveValue.h>
20 #include <WebKit/DOMCSSStyleDeclaration.h>
21 #include <WebKit/DOMDocument.h>
22 #include <WebKit/DOMHTMLBodyElement.h>
23 #include <WebKit/DOMRGBColor.h>
26 #define DefaultTimeout_ 120.0
28 #define ShowInternals 0
32 #define lprintf(args...) fprintf(stderr, args)
34 template <typename Type_>
35 static inline void CYRelease(Type_ &value) {
42 float CYScrollViewDecelerationRateNormal;
44 @interface WebView (Apple)
45 - (void) _setLayoutInterval:(float)interval;
46 - (void) _setAllowsMessaging:(BOOL)allows;
49 @interface WebPreferences (Apple)
50 + (void) _setInitialDefaultTextEncodingToSystemEncoding;
51 - (void) _setLayoutInterval:(NSInteger)interval;
52 - (void) setOfflineWebApplicationCacheEnabled:(BOOL)enabled;
55 /* Indirect Delegate {{{ */
56 @interface IndirectDelegate : NSObject {
57 _transient volatile id delegate_;
60 - (void) setDelegate:(id)delegate;
61 - (id) initWithDelegate:(id)delegate;
64 @implementation IndirectDelegate
66 - (void) setDelegate:(id)delegate {
70 - (id) initWithDelegate:(id)delegate {
75 - (IMP) methodForSelector:(SEL)sel {
76 if (IMP method = [super methodForSelector:sel])
78 fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
82 - (BOOL) respondsToSelector:(SEL)sel {
83 if ([super respondsToSelector:sel])
86 // XXX: WebThreadCreateNSInvocation returns nil
89 fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
92 return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
95 - (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
96 if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
100 fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
103 if (delegate_ != nil)
104 if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
107 // XXX: I fucking hate Apple so very very bad
108 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
111 - (void) forwardInvocation:(NSInvocation *)inv {
112 SEL sel = [inv selector];
113 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
114 [inv invokeWithTarget:delegate_];
120 @implementation CyteWebViewController
123 #include "CyteKit/UCInternal.h"
126 + (void) _initialize {
127 [WebPreferences _setInitialDefaultTextEncodingToSystemEncoding];
129 if (float *_UIScrollViewDecelerationRateNormal = reinterpret_cast<float *>(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal")))
130 CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
131 else // XXX: this actually might be fast on some older systems: we should look into this
132 CYScrollViewDecelerationRateNormal = 0.998;
137 NSLog(@"[CyteWebViewController dealloc]");
140 [webview_ setDelegate:nil];
142 [indirect_ setDelegate:nil];
145 if (challenge_ != nil)
146 [challenge_ release];
151 if ([loading_ count] != 0)
152 [delegate_ releaseNetworkActivityIndicator];
155 [reloaditem_ release];
156 [loadingitem_ release];
158 [indicator_ release];
163 - (NSURL *) URLWithURL:(NSURL *)url {
167 - (NSURLRequest *) requestWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
169 requestWithURL:[self URLWithURL:url]
171 timeoutInterval:DefaultTimeout_
175 - (void) setURL:(NSURL *)url {
176 _assert(request_ == nil);
177 request_ = [self requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
180 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
181 [self loadRequest:[self requestWithURL:url cachePolicy:policy]];
184 - (void) loadURL:(NSURL *)url {
185 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
188 - (void) loadRequest:(NSURLRequest *)request {
190 NSLog(@"loadRequest:%@", request);
195 WebThreadLocked lock;
196 [webview_ loadRequest:request];
199 - (void) reloadURLWithCache:(BOOL)cache {
203 NSMutableURLRequest *request([request_ mutableCopy]);
204 [request setCachePolicy:(cache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData)];
208 if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
209 [self loadRequest:request_];
211 UIAlertView *alert = [[[UIAlertView alloc]
212 initWithTitle:UCLocalize("RESUBMIT_FORM")
215 cancelButtonTitle:UCLocalize("CANCEL")
217 UCLocalize("SUBMIT"),
221 [alert setContext:@"submit"];
227 [self reloadURLWithCache:YES];
230 - (void) reloadData {
232 [self reloadURLWithCache:YES];
235 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
238 function_ = function;
240 [self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
243 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
246 function_ = function;
248 [self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
251 - (void) removeButton {
252 custom_ = [NSNull null];
253 [self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
256 - (void) scrollToBottomAnimated:(NSNumber *)animated {
257 CGSize size([scroller_ contentSize]);
258 CGPoint offset([scroller_ contentOffset]);
259 CGRect frame([scroller_ frame]);
261 if (size.height - offset.y < frame.size.height + 20.f) {
262 CGRect rect = {{0, size.height-1}, {size.width, 1}};
263 [scroller_ scrollRectToVisible:rect animated:[animated boolValue]];
267 - (void) _setViewportWidth {
268 [[webview_ _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
271 - (void) setViewportWidth:(float)width {
272 width_ = width != 0 ? width : [[self class] defaultWidth];
273 [self _setViewportWidth];
276 - (void) _setViewportWidthOnMainThread:(NSNumber *)width {
277 [self setViewportWidth:[width floatValue]];
280 - (void) setViewportWidthOnMainThread:(float)width {
281 [self performSelectorOnMainThread:@selector(_setViewportWidthOnMainThread:) withObject:[NSNumber numberWithFloat:width] waitUntilDone:NO];
284 - (void) webViewUpdateViewSettings:(UIWebView *)view {
285 [self _setViewportWidth];
288 - (void) _openMailToURL:(NSURL *)url {
289 [[UIApplication sharedApplication] openURL:url];// asPanel:YES];
292 - (bool) _allowJavaScriptPanel {
296 - (bool) allowsNavigationAction {
297 return allowsNavigationAction_;
300 - (void) setAllowsNavigationAction:(bool)value {
301 allowsNavigationAction_ = value;
304 - (void) setAllowsNavigationActionByNumber:(NSNumber *)value {
305 [self setAllowsNavigationAction:[value boolValue]];
308 - (void) popViewControllerWithNumber:(NSNumber *)value {
309 UINavigationController *navigation([self navigationController]);
310 if ([navigation topViewController] == self)
311 [navigation popViewControllerAnimated:[value boolValue]];
314 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
315 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
316 [self _didFinishLoading];
318 if ([error code] == NSURLErrorCancelled)
321 if ([frame parentFrame] == nil) {
322 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
323 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
324 [[error localizedDescription] stringByAddingPercentEscapes]
331 - (void) pushRequest:(NSURLRequest *)request asPop:(bool)pop {
332 NSURL *url([request URL]);
334 // XXX: filter to internal usage?
335 CyteViewController *page([delegate_ pageForURL:url forExternal:NO]);
338 CyteWebViewController *browser([[[class_ alloc] init] autorelease]);
339 [browser loadRequest:request];
343 [page setDelegate:delegate_];
346 [[self navigationItem] setTitle:title_];
348 [[self navigationController] pushViewController:page animated:YES];
350 UINavigationController *navigation([[[UINavigationController alloc] initWithRootViewController:page] autorelease]);
352 [navigation setDelegate:delegate_];
354 [[page navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
355 initWithTitle:UCLocalize("CLOSE")
356 style:UIBarButtonItemStylePlain
358 action:@selector(close)
361 [[self navigationController] presentModalViewController:navigation animated:YES];
363 [delegate_ unloadData];
367 // CyteWebViewDelegate {{{
368 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
370 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$");
371 if (NSString *data = [message objectForKey:@"message"])
372 if (irritating(data))
375 NSLog(@"addMessageToConsole:%@", message);
379 - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
381 NSLog(@"decidePolicyForNavigationAction:%@ request:%@ frame:%@", action, request, frame);
384 if ([frame parentFrame] == nil) {
386 NSURL *url(request == nil ? nil : [request URL]);
388 if (request_ == nil || [self allowsNavigationAction] || [[request_ URL] isEqual:url])
392 [self pushRequest:request asPop:NO];
399 - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
401 NSLog(@"decidePolicyForNewWindowAction:%@ request:%@ newFrameName:%@", action, request, frame);
404 NSURL *url([request URL]);
408 if ([frame isEqualToString:@"_open"])
409 [delegate_ openURL:url];
411 NSString *scheme([[url scheme] lowercaseString]);
412 if ([scheme isEqualToString:@"mailto"])
413 [self _openMailToURL:url];
415 [self pushRequest:request asPop:[frame isEqualToString:@"_popup"]];
421 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
424 - (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
426 NSLog(@"didFailLoadWithError:%@ forFrame:%@", error, frame);
429 [self _didFailWithError:error forFrame:frame];
432 - (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
434 NSLog(@"didFailProvisionalLoadWithError:%@ forFrame:%@", error, frame);
437 [self _didFailWithError:error forFrame:frame];
440 - (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame {
441 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
443 if ([frame parentFrame] == nil) {
444 if (DOMDocument *document = [frame DOMDocument])
445 if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"])
446 for (DOMHTMLBodyElement *body in (id) bodies) {
447 DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
451 if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) {
452 if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
453 DOMRGBColor *rgb([color getRGBColorValue]);
455 float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
456 float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
457 float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
458 float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
460 if (red == 0xc7 && green == 0xce && blue == 0xd5)
461 uic = [UIColor pinStripeColor];
464 colorWithRed:(red / 255)
472 [scroller_ setBackgroundColor:(uic ?: [UIColor clearColor])];
477 [self _didFinishLoading];
480 - (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
481 if ([frame parentFrame] != nil)
485 [title_ autorelease];
486 title_ = [title retain];
488 [[self navigationItem] setTitle:title_];
491 - (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame {
492 [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
494 if ([frame parentFrame] == nil) {
500 [self setHidesNavigationBar:NO];
502 // XXX: do we still need to do this?
503 [[self navigationItem] setTitle:nil];
506 [self _didStartLoading];
509 - (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
511 NSLog(@"resource:%@ willSendRequest:%@ redirectResponse:%@ fromDataSource:%@", identifier, request, response, source);
517 - (bool) webView:(WebView *)view shouldRunJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
518 return [self _allowJavaScriptPanel];
521 - (bool) webView:(WebView *)view shouldRunJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
522 return [self _allowJavaScriptPanel];
525 - (bool) webView:(WebView *)view shouldRunJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
526 return [self _allowJavaScriptPanel];
529 - (void) webViewClose:(WebView *)view {
535 [[self navigationController] dismissModalViewControllerAnimated:YES];
538 - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
539 NSString *context([alert context]);
541 if ([context isEqualToString:@"sensitive"]) {
544 sensitive_ = [NSNumber numberWithBool:YES];
548 sensitive_ = [NSNumber numberWithBool:NO];
552 [alert dismissWithClickedButtonIndex:-1 animated:YES];
553 } else if ([context isEqualToString:@"challenge"]) {
554 id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
558 NSString *username([[alert textFieldAtIndex:0] text]);
559 NSString *password([[alert textFieldAtIndex:1] text]);
561 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
563 [sender useCredential:credential forAuthenticationChallenge:challenge_];
567 [sender cancelAuthenticationChallenge:challenge_];
573 [challenge_ release];
576 [alert dismissWithClickedButtonIndex:-1 animated:YES];
577 } else if ([context isEqualToString:@"submit"]) {
578 if (button == [alert cancelButtonIndex]) {
579 } else if (button == [alert firstOtherButtonIndex]) {
580 if (request_ != nil) {
581 WebThreadLocked lock;
582 [webview_ loadRequest:request_];
586 [alert dismissWithClickedButtonIndex:-1 animated:YES];
590 - (UIBarButtonItemStyle) rightButtonStyle {
591 if (style_ == nil) normal:
592 return UIBarButtonItemStylePlain;
593 else if ([style_ isEqualToString:@"Normal"])
594 return UIBarButtonItemStylePlain;
595 else if ([style_ isEqualToString:@"Highlighted"])
596 return UIBarButtonItemStyleDone;
600 - (UIBarButtonItem *) customButton {
603 else if (custom_ == [NSNull null])
604 return (UIBarButtonItem *) [NSNull null];
606 return [[[UIBarButtonItem alloc]
607 initWithTitle:static_cast<NSString *>(custom_.operator NSObject *())
608 style:[self rightButtonStyle]
610 action:@selector(customButtonClicked)
614 - (UIBarButtonItem *) rightButton {
618 - (void) applyLoadingTitle {
619 [[self navigationItem] setTitle:UCLocalize("LOADING")];
622 - (void) layoutRightButton {
623 [[loadingitem_ view] addSubview:indicator_];
624 [[loadingitem_ view] bringSubviewToFront:indicator_];
627 - (void) applyRightButton {
628 if ([self isLoading]) {
629 [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
630 [self performSelector:@selector(layoutRightButton) withObject:nil afterDelay:0];
632 [indicator_ startAnimating];
633 [self applyLoadingTitle];
635 [indicator_ stopAnimating];
637 UIBarButtonItem *button([self customButton]);
639 button = [self rightButton];
640 else if (button == (UIBarButtonItem *) [NSNull null])
643 [[self navigationItem] setRightBarButtonItem:button];
647 - (void) didStartLoading {
648 // Overridden in subclasses.
651 - (void) _didStartLoading {
652 [self applyRightButton];
654 if ([loading_ count] != 1)
657 [delegate_ retainNetworkActivityIndicator];
658 [self didStartLoading];
661 - (void) didFinishLoading {
662 // Overridden in subclasses.
665 - (void) _didFinishLoading {
666 if ([loading_ count] != 0)
669 [self applyRightButton];
670 [[self navigationItem] setTitle:title_];
672 [delegate_ releaseNetworkActivityIndicator];
673 [self didFinishLoading];
677 return [loading_ count] != 0;
680 - (id) initWithWidth:(float)width ofClass:(Class)_class {
681 if ((self = [super init]) != nil) {
682 allowsNavigationAction_ = true;
685 loading_ = [[NSMutableSet alloc] initWithCapacity:5];
687 indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
689 CGRect bounds([[self view] bounds]);
691 webview_ = [[[CyteWebView alloc] initWithFrame:bounds] autorelease];
692 [webview_ setDelegate:self];
693 [self setView:webview_];
695 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
696 [webview_ setDataDetectorTypes:UIDataDetectorTypeAutomatic];
698 [webview_ setDetectsPhoneNumbers:NO];
700 [webview_ setScalesPageToFit:YES];
702 UIWebDocumentView *document([webview_ _documentView]);
704 // XXX: I think this improves scrolling; the hardcoded-ness sucks
705 [document setTileSize:CGSizeMake(320, 500)];
707 [document setBackgroundColor:[UIColor clearColor]];
709 // XXX: this is terribly (too?) expensive
710 [document setDrawsBackground:NO];
712 WebView *webview([document webView]);
713 WebPreferences *preferences([webview preferences]);
715 // XXX: I have no clue if I actually /want/ this modification
716 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
717 [webview _setLayoutInterval:0];
718 else if ([preferences respondsToSelector:@selector(_setLayoutInterval:)])
719 [preferences _setLayoutInterval:0];
721 [preferences setCacheModel:WebCacheModelDocumentBrowser];
722 [preferences setOfflineWebApplicationCacheEnabled:YES];
725 if ([document respondsToSelector:@selector(setAllowsMessaging:)])
726 [document setAllowsMessaging:YES];
727 if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
728 [webview _setAllowsMessaging:YES];
731 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
732 scroller_ = [webview_ _scrollView];
734 [scroller_ setDirectionalLockEnabled:YES];
735 [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
736 [scroller_ setDelaysContentTouches:NO];
738 [scroller_ setCanCancelContentTouches:YES];
739 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
740 UIScroller *scroller([webview_ _scroller]);
741 scroller_ = (UIScrollView *) scroller;
743 [scroller setDirectionalScrolling:YES];
744 // XXX: we might be better off /not/ setting this on older systems
745 [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
746 [scroller setScrollHysteresis:0]; /* 8 */
748 [scroller setThumbDetectionEnabled:NO];
750 // use NO with UIApplicationUseLegacyEvents(YES)
751 [scroller setEventMode:YES];
753 // XXX: this is handled by setBounces, right?
754 //[scroller setAllowsRubberBanding:YES];
757 [scroller_ setFixedBackgroundPattern:YES];
758 [scroller_ setBackgroundColor:[UIColor clearColor]];
759 [scroller_ setClipsSubviews:YES];
761 [scroller_ setBounces:YES];
762 [scroller_ setScrollingEnabled:YES];
763 [scroller_ setShowBackgroundShadow:NO];
765 [self setViewportWidth:width];
767 reloaditem_ = [[UIBarButtonItem alloc]
768 initWithTitle:UCLocalize("RELOAD")
769 style:[self rightButtonStyle]
771 action:@selector(reloadButtonClicked)
774 loadingitem_ = [[UIBarButtonItem alloc]
776 style:UIBarButtonItemStylePlain
778 action:@selector(reloadButtonClicked)
781 indicator_ = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
782 [indicator_ setFrame:CGRectMake(15, 5, [indicator_ frame].size.width, [indicator_ frame].size.height)];
784 UITableView *table([[[UITableView alloc] initWithFrame:bounds style:UITableViewStyleGrouped] autorelease]);
785 [webview_ insertSubview:table atIndex:0];
787 [table setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
788 [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
789 [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
793 - (id) initWithWidth:(float)width {
794 return [self initWithWidth:width ofClass:[self class]];
798 return [self initWithWidth:0];
801 - (id) initWithURL:(NSURL *)url {
802 if ((self = [self init]) != nil) {
807 - (void) callFunction:(WebScriptObject *)function {
808 WebThreadLocked lock;
810 WebView *webview([[webview_ _documentView] webView]);
811 WebFrame *frame([webview mainFrame]);
812 WebPreferences *preferences([webview preferences]);
814 bool maybe([preferences javaScriptCanOpenWindowsAutomatically]);
815 [preferences setJavaScriptCanOpenWindowsAutomatically:NO];
817 /*id _private(MSHookIvar<id>(webview, "_private"));
818 WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
819 WebCore::Settings *settings(page == NULL ? NULL : page->settings());
822 if (settings == NULL)
825 no = settings->JavaScriptCanOpenWindowsAutomatically();
826 settings->setJavaScriptCanOpenWindowsAutomatically(true);
829 if (UIWindow *window = [[self view] window])
830 if (UIResponder *responder = [window firstResponder])
831 [responder resignFirstResponder];
833 JSObjectRef object([function JSObject]);
834 JSGlobalContextRef context([frame globalContext]);
835 JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
837 /*if (settings != NULL)
838 settings->setJavaScriptCanOpenWindowsAutomatically(no);*/
840 [preferences setJavaScriptCanOpenWindowsAutomatically:maybe];
843 - (void) reloadButtonClicked {
844 [self reloadURLWithCache:YES];
847 - (void) _customButtonClicked {
848 [self reloadButtonClicked];
851 - (void) customButtonClicked {
853 if (function_ != nil)
854 [self callFunction:function_];
857 [self _customButtonClicked];
860 + (float) defaultWidth {
864 - (void) setNavigationBarStyle:(NSString *)name {
866 if ([name isEqualToString:@"Black"])
867 style = UIBarStyleBlack;
869 style = UIBarStyleDefault;
871 [[[self navigationController] navigationBar] setBarStyle:style];
874 - (void) setNavigationBarTintColor:(UIColor *)color {
875 [[[self navigationController] navigationBar] setTintColor:color];
878 - (void) setBadgeValue:(id)value {
879 [[[self navigationController] tabBarItem] setBadgeValue:value];
882 - (void) setHidesBackButton:(bool)value {
883 [[self navigationItem] setHidesBackButton:value];
886 - (void) setHidesBackButtonByNumber:(NSNumber *)value {
887 [self setHidesBackButton:[value boolValue]];
890 - (void) dispatchEvent:(NSString *)event {
891 [webview_ dispatchEvent:event];
894 - (bool) hidesNavigationBar {
895 return hidesNavigationBar_;
898 - (void) _setHidesNavigationBar:(bool)value animated:(bool)animated {
900 [[self navigationController] setNavigationBarHidden:(value && [self hidesNavigationBar]) animated:animated];
903 - (void) setHidesNavigationBar:(bool)value {
904 if (hidesNavigationBar_ != value) {
905 hidesNavigationBar_ = value;
906 [self _setHidesNavigationBar:YES animated:YES];
910 - (void) setHidesNavigationBarByNumber:(NSNumber *)value {
911 [self setHidesNavigationBar:[value boolValue]];
914 - (void) viewWillAppear:(BOOL)animated {
917 if ([self hidesNavigationBar])
918 [self _setHidesNavigationBar:YES animated:animated];
920 [self dispatchEvent:@"CydiaViewWillAppear"];
921 [super viewWillAppear:animated];
924 - (void) viewDidAppear:(BOOL)animated {
925 [super viewDidAppear:animated];
926 [self dispatchEvent:@"CydiaViewDidAppear"];
929 - (void) viewWillDisappear:(BOOL)animated {
930 [self dispatchEvent:@"CydiaViewWillDisappear"];
931 [super viewWillDisappear:animated];
933 if ([self hidesNavigationBar])
934 [self _setHidesNavigationBar:NO animated:animated];
939 - (void) viewDidDisappear:(BOOL)animated {
940 [super viewDidDisappear:animated];
941 [self dispatchEvent:@"CydiaViewDidDisappear"];