1 #include "CyteKit/UCPlatform.h"
3 #include <UIKit/UIKit.h>
4 #include "iPhonePrivate.h"
6 #include "CyteKit/CyteLocalize.h"
7 #include "CyteKit/CyteWebViewController.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 CYViewController *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 {
601 return custom_ == [NSNull null] ? nil : [[[UIBarButtonItem alloc]
602 initWithTitle:static_cast<NSString *>(custom_.operator NSObject *())
603 style:[self rightButtonStyle]
605 action:@selector(customButtonClicked)
609 - (UIBarButtonItem *) rightButton {
613 - (void) applyLoadingTitle {
614 [[self navigationItem] setTitle:UCLocalize("LOADING")];
617 - (void) layoutRightButton {
618 [[loadingitem_ view] addSubview:indicator_];
619 [[loadingitem_ view] bringSubviewToFront:indicator_];
622 - (void) applyRightButton {
623 if ([self isLoading]) {
624 [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
625 [self performSelector:@selector(layoutRightButton) withObject:nil afterDelay:0];
627 [indicator_ startAnimating];
628 [self applyLoadingTitle];
630 [indicator_ stopAnimating];
632 [[self navigationItem] setRightBarButtonItem:(
633 custom_ != nil ? [self customButton] : [self rightButton]
638 - (void) didStartLoading {
639 // Overridden in subclasses.
642 - (void) _didStartLoading {
643 [self applyRightButton];
645 if ([loading_ count] != 1)
648 [delegate_ retainNetworkActivityIndicator];
649 [self didStartLoading];
652 - (void) didFinishLoading {
653 // Overridden in subclasses.
656 - (void) _didFinishLoading {
657 if ([loading_ count] != 0)
660 [self applyRightButton];
661 [[self navigationItem] setTitle:title_];
663 [delegate_ releaseNetworkActivityIndicator];
664 [self didFinishLoading];
668 return [loading_ count] != 0;
671 - (id) initWithWidth:(float)width ofClass:(Class)_class {
672 if ((self = [super init]) != nil) {
673 allowsNavigationAction_ = true;
676 loading_ = [[NSMutableSet alloc] initWithCapacity:5];
678 indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
680 CGRect bounds([[self view] bounds]);
682 webview_ = [[[CyteWebView alloc] initWithFrame:bounds] autorelease];
683 [webview_ setDelegate:self];
684 [self setView:webview_];
686 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
687 [webview_ setDataDetectorTypes:UIDataDetectorTypeAutomatic];
689 [webview_ setDetectsPhoneNumbers:NO];
691 [webview_ setScalesPageToFit:YES];
693 UIWebDocumentView *document([webview_ _documentView]);
695 // XXX: I think this improves scrolling; the hardcoded-ness sucks
696 [document setTileSize:CGSizeMake(320, 500)];
698 [document setBackgroundColor:[UIColor clearColor]];
700 // XXX: this is terribly (too?) expensive
701 [document setDrawsBackground:NO];
703 WebView *webview([document webView]);
704 WebPreferences *preferences([webview preferences]);
706 // XXX: I have no clue if I actually /want/ this modification
707 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
708 [webview _setLayoutInterval:0];
709 else if ([preferences respondsToSelector:@selector(_setLayoutInterval:)])
710 [preferences _setLayoutInterval:0];
712 [preferences setCacheModel:WebCacheModelDocumentBrowser];
713 [preferences setOfflineWebApplicationCacheEnabled:YES];
716 if ([document respondsToSelector:@selector(setAllowsMessaging:)])
717 [document setAllowsMessaging:YES];
718 if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
719 [webview _setAllowsMessaging:YES];
722 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
723 scroller_ = [webview_ _scrollView];
725 [scroller_ setDirectionalLockEnabled:YES];
726 [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
727 [scroller_ setDelaysContentTouches:NO];
729 [scroller_ setCanCancelContentTouches:YES];
730 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
731 UIScroller *scroller([webview_ _scroller]);
732 scroller_ = (UIScrollView *) scroller;
734 [scroller setDirectionalScrolling:YES];
735 // XXX: we might be better off /not/ setting this on older systems
736 [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
737 [scroller setScrollHysteresis:0]; /* 8 */
739 [scroller setThumbDetectionEnabled:NO];
741 // use NO with UIApplicationUseLegacyEvents(YES)
742 [scroller setEventMode:YES];
744 // XXX: this is handled by setBounces, right?
745 //[scroller setAllowsRubberBanding:YES];
748 [scroller_ setFixedBackgroundPattern:YES];
749 [scroller_ setBackgroundColor:[UIColor clearColor]];
750 [scroller_ setClipsSubviews:YES];
752 [scroller_ setBounces:YES];
753 [scroller_ setScrollingEnabled:YES];
754 [scroller_ setShowBackgroundShadow:NO];
756 [self setViewportWidth:width];
758 reloaditem_ = [[UIBarButtonItem alloc]
759 initWithTitle:UCLocalize("RELOAD")
760 style:[self rightButtonStyle]
762 action:@selector(reloadButtonClicked)
765 loadingitem_ = [[UIBarButtonItem alloc]
767 style:UIBarButtonItemStylePlain
769 action:@selector(reloadButtonClicked)
772 indicator_ = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
773 [indicator_ setFrame:CGRectMake(15, 5, [indicator_ frame].size.width, [indicator_ frame].size.height)];
775 UITableView *table([[[UITableView alloc] initWithFrame:bounds style:UITableViewStyleGrouped] autorelease]);
776 [webview_ insertSubview:table atIndex:0];
778 [table setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
779 [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
780 [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
784 - (id) initWithWidth:(float)width {
785 return [self initWithWidth:width ofClass:[self class]];
789 return [self initWithWidth:0];
792 - (id) initWithURL:(NSURL *)url {
793 if ((self = [self init]) != nil) {
798 - (void) callFunction:(WebScriptObject *)function {
799 WebThreadLocked lock;
801 WebView *webview([[webview_ _documentView] webView]);
802 WebFrame *frame([webview mainFrame]);
803 WebPreferences *preferences([webview preferences]);
805 bool maybe([preferences javaScriptCanOpenWindowsAutomatically]);
806 [preferences setJavaScriptCanOpenWindowsAutomatically:NO];
808 /*id _private(MSHookIvar<id>(webview, "_private"));
809 WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
810 WebCore::Settings *settings(page == NULL ? NULL : page->settings());
813 if (settings == NULL)
816 no = settings->JavaScriptCanOpenWindowsAutomatically();
817 settings->setJavaScriptCanOpenWindowsAutomatically(true);
820 if (UIWindow *window = [[self view] window])
821 if (UIResponder *responder = [window firstResponder])
822 [responder resignFirstResponder];
824 JSObjectRef object([function JSObject]);
825 JSGlobalContextRef context([frame globalContext]);
826 JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
828 /*if (settings != NULL)
829 settings->setJavaScriptCanOpenWindowsAutomatically(no);*/
831 [preferences setJavaScriptCanOpenWindowsAutomatically:maybe];
834 - (void) reloadButtonClicked {
835 [self reloadURLWithCache:YES];
838 - (void) _customButtonClicked {
839 [self reloadButtonClicked];
842 - (void) customButtonClicked {
844 if (function_ != nil)
845 [self callFunction:function_];
848 [self _customButtonClicked];
851 + (float) defaultWidth {
855 - (void) setNavigationBarStyle:(NSString *)name {
857 if ([name isEqualToString:@"Black"])
858 style = UIBarStyleBlack;
860 style = UIBarStyleDefault;
862 [[[self navigationController] navigationBar] setBarStyle:style];
865 - (void) setNavigationBarTintColor:(UIColor *)color {
866 [[[self navigationController] navigationBar] setTintColor:color];
869 - (void) setBadgeValue:(id)value {
870 [[[self navigationController] tabBarItem] setBadgeValue:value];
873 - (void) setHidesBackButton:(bool)value {
874 [[self navigationItem] setHidesBackButton:value];
877 - (void) setHidesBackButtonByNumber:(NSNumber *)value {
878 [self setHidesBackButton:[value boolValue]];
881 - (void) dispatchEvent:(NSString *)event {
882 [webview_ dispatchEvent:event];
885 - (bool) hidesNavigationBar {
886 return hidesNavigationBar_;
889 - (void) _setHidesNavigationBar:(bool)value animated:(bool)animated {
891 [[self navigationController] setNavigationBarHidden:(value && [self hidesNavigationBar]) animated:animated];
894 - (void) setHidesNavigationBar:(bool)value {
895 if (hidesNavigationBar_ != value) {
896 hidesNavigationBar_ = value;
897 [self _setHidesNavigationBar:YES animated:YES];
901 - (void) setHidesNavigationBarByNumber:(NSNumber *)value {
902 [self setHidesNavigationBar:[value boolValue]];
905 - (void) viewWillAppear:(BOOL)animated {
908 if ([self hidesNavigationBar])
909 [self _setHidesNavigationBar:YES animated:animated];
911 [self dispatchEvent:@"CydiaViewWillAppear"];
912 [super viewWillAppear:animated];
915 - (void) viewDidAppear:(BOOL)animated {
916 [super viewDidAppear:animated];
917 [self dispatchEvent:@"CydiaViewDidAppear"];
920 - (void) viewWillDisappear:(BOOL)animated {
921 [self dispatchEvent:@"CydiaViewWillDisappear"];
922 [super viewWillDisappear:animated];
924 if ([self hidesNavigationBar])
925 [self _setHidesNavigationBar:NO animated:animated];
930 - (void) viewDidDisappear:(BOOL)animated {
931 [super viewDidDisappear:animated];
932 [self dispatchEvent:@"CydiaViewDidDisappear"];