]> git.saurik.com Git - cydia.git/blame - CyteKit/WebViewController.mm
Fix Restart SpringBoard on iOS 3 (maybe others?).
[cydia.git] / CyteKit / WebViewController.mm
CommitLineData
819a0ab1 1#include "CyteKit/UCPlatform.h"
2b2a4e33
JF
2#include "CyteKit/WebViewController.h"
3
4#include "CyteKit/MFMailComposeViewController-MailToURL.h"
819a0ab1 5
c21004b9
JF
6#include "iPhonePrivate.h"
7
cfc530e6 8#include "CyteKit/IndirectDelegate.h"
d458596e
JF
9#include "CyteKit/Localize.h"
10#include "CyteKit/WebViewController.h"
819a0ab1 11#include "CyteKit/PerlCompatibleRegEx.hpp"
4bcafc01 12#include "CyteKit/WebThreadLocked.hpp"
43f3d7f6 13
c21004b9 14//#include <QuartzCore/CALayer.h>
43f3d7f6
JF
15// XXX: fix the minimum requirement
16extern NSString * const kCAFilterNearest;
22f8bed9 17
caa427d1 18#include <WebCore/WebCoreThread.h>
c21004b9 19
5e640a64
JF
20#import <WebKit/WebKitErrors.h>
21#import <WebKit/WebPreferences.h>
c21004b9
JF
22
23#include <WebKit/DOMCSSPrimitiveValue.h>
24#include <WebKit/DOMCSSStyleDeclaration.h>
25#include <WebKit/DOMDocument.h>
26#include <WebKit/DOMHTMLBodyElement.h>
27#include <WebKit/DOMRGBColor.h>
28
bf7c998c
JF
29#include <dlfcn.h>
30#include <objc/runtime.h>
31
adcb0422 32#define ForSaurik 0
eb09425a 33#define DefaultTimeout_ 120.0
bfc87a4d 34
0815487b
JF
35#define ShowInternals 0
36#define LogBrowser 0
72bdb258 37#define LogMessages 0
0815487b
JF
38
39#define lprintf(args...) fprintf(stderr, args)
40
7c80833f
JF
41JSValueRef (*$JSObjectCallAsFunction)(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef *);
42
2b2a4e33
JF
43// XXX: centralize these special class things to some file or mechanism?
44static Class $MFMailComposeViewController;
45
9c1605e2
JF
46float CYScrollViewDecelerationRateNormal;
47
2634b249
JF
48@interface WebView (Apple)
49- (void) _setLayoutInterval:(float)interval;
72bdb258 50- (void) _setAllowsMessaging:(BOOL)allows;
2634b249
JF
51@end
52
aa1e1906
JF
53@interface WebFrame (Cydia)
54- (void) cydia$updateHeight;
55@end
56
dffe1eb1
JF
57@implementation WebFrame (Cydia)
58
59- (NSString *) description {
60 return [NSString stringWithFormat:@"<%s: %p, %@>", class_getName([self class]), self, [[[([self provisionalDataSource] ?: [self dataSource]) request] URL] absoluteString]];
61}
62
aa1e1906
JF
63- (void) cydia$updateHeight {
64 [[[self frameElement] style]
65 setProperty:@"height"
66 value:[NSString stringWithFormat:@"%dpx",
67 [[[self DOMDocument] body] scrollHeight]]
68 priority:nil];
69}
70
dffe1eb1
JF
71@end
72
aa5d0de7 73/* Indirect Delegate {{{ */
aa5d0de7
JF
74@implementation IndirectDelegate
75
353dda5b
JF
76- (id) delegate {
77 return delegate_;
78}
79
aa5d0de7
JF
80- (void) setDelegate:(id)delegate {
81 delegate_ = delegate;
82}
83
84- (id) initWithDelegate:(id)delegate {
85 delegate_ = delegate;
86 return self;
87}
88
caa427d1
JF
89- (IMP) methodForSelector:(SEL)sel {
90 if (IMP method = [super methodForSelector:sel])
91 return method;
92 fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
93 return NULL;
94}
95
aa5d0de7 96- (BOOL) respondsToSelector:(SEL)sel {
caa427d1
JF
97 if ([super respondsToSelector:sel])
98 return YES;
0815487b 99
caa427d1 100 // XXX: WebThreadCreateNSInvocation returns nil
0815487b
JF
101
102#if ShowInternals
103 fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
104#endif
105
caa427d1 106 return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
aa5d0de7
JF
107}
108
109- (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
caa427d1
JF
110 if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
111 return method;
0815487b
JF
112
113#if ShowInternals
114 fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
115#endif
116
aa5d0de7
JF
117 if (delegate_ != nil)
118 if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
119 return sig;
0815487b 120
aa5d0de7
JF
121 // XXX: I fucking hate Apple so very very bad
122 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
123}
124
125- (void) forwardInvocation:(NSInvocation *)inv {
126 SEL sel = [inv selector];
127 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
128 [inv invokeWithTarget:delegate_];
129}
130
131@end
132/* }}} */
133
09e89a8a 134@implementation CyteWebViewController
2634b249
JF
135
136#if ShowInternals
819a0ab1 137#include "CyteKit/UCInternal.h"
22f8bed9
JF
138#endif
139
2634b249
JF
140+ (void) _initialize {
141 [WebPreferences _setInitialDefaultTextEncodingToSystemEncoding];
9c1605e2 142
7c80833f
JF
143 void *js(NULL);
144 if (js == NULL)
145 js = dlopen("/System/Library/Frameworks/JavaScriptCore.framework/JavaScriptCore", RTLD_GLOBAL | RTLD_LAZY);
146 if (js == NULL)
147 js = dlopen("/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore", RTLD_GLOBAL | RTLD_LAZY);
148 if (js != NULL)
149 $JSObjectCallAsFunction = reinterpret_cast<JSValueRef (*)(JSContextRef, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef *)>(dlsym(js, "JSObjectCallAsFunction"));
150
2b2a4e33
JF
151 dlopen("/System/Library/Frameworks/MessageUI.framework/MessageUI", RTLD_GLOBAL | RTLD_LAZY);
152 $MFMailComposeViewController = objc_getClass("MFMailComposeViewController");
153
9c1605e2
JF
154 if (float *_UIScrollViewDecelerationRateNormal = reinterpret_cast<float *>(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal")))
155 CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
156 else // XXX: this actually might be fast on some older systems: we should look into this
157 CYScrollViewDecelerationRateNormal = 0.998;
2634b249
JF
158}
159
2713be8e
JF
160- (bool) retainsNetworkActivityIndicator {
161 return true;
162}
163
8b74eaff
JF
164- (void) releaseNetworkActivityIndicator {
165 if ([loading_ count] != 0) {
166 [loading_ removeAllObjects];
167
168 if ([self retainsNetworkActivityIndicator])
169 [delegate_ releaseNetworkActivityIndicator];
170 }
171}
172
2634b249
JF
173- (void) dealloc {
174#if LogBrowser
09e89a8a 175 NSLog(@"[CyteWebViewController dealloc]");
2634b249
JF
176#endif
177
8b74eaff 178 [self releaseNetworkActivityIndicator];
bc11cf5b 179
22f8bed9
JF
180 [super dealloc];
181}
182
e3e0246d
JF
183- (NSString *) description {
184 return [NSString stringWithFormat:@"<%s: %p, %@>", class_getName([self class]), self, [[request_ URL] absoluteString]];
185}
186
6f837280
JF
187- (CyteWebView *) webView {
188 return (CyteWebView *) [self view];
189}
190
dd48f2e6
JF
191- (NSURL *) URLWithURL:(NSURL *)url {
192 return url;
193}
eb09425a 194
f050e4d9
JF
195- (NSURLRequest *) requestWithURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy referrer:(NSString *)referrer {
196 NSMutableURLRequest *request([NSMutableURLRequest
dd48f2e6
JF
197 requestWithURL:[self URLWithURL:url]
198 cachePolicy:policy
eb09425a 199 timeoutInterval:DefaultTimeout_
f050e4d9
JF
200 ]);
201
202 [request setValue:referrer forHTTPHeaderField:@"Referer"];
203
204 return request;
eb09425a
JF
205}
206
e8eda555 207- (void) setRequest:(NSURLRequest *)request {
dd48f2e6 208 _assert(request_ == nil);
e8eda555
JF
209 request_ = request;
210}
211
212- (void) setURL:(NSURL *)url {
f050e4d9
JF
213 [self setURL:url withReferrer:nil];
214}
215
216- (void) setURL:(NSURL *)url withReferrer:(NSString *)referrer {
217 [self setRequest:[self requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy referrer:referrer]];
dd48f2e6
JF
218}
219
22f8bed9 220- (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
f050e4d9 221 [self loadRequest:[self requestWithURL:url cachePolicy:policy referrer:nil]];
22f8bed9
JF
222}
223
224- (void) loadURL:(NSURL *)url {
225 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
226}
227
22f8bed9 228- (void) loadRequest:(NSURLRequest *)request {
0352f238
JF
229#if LogBrowser
230 NSLog(@"loadRequest:%@", request);
231#endif
232
fe468f45 233 error_ = false;
d9fc1d37 234 ready_ = true;
caa427d1 235
0893a034 236 WebThreadLocked lock;
6f837280 237 [[self webView] loadRequest:request];
22f8bed9
JF
238}
239
b13b8664 240- (void) reloadURLWithCache:(BOOL)cache {
22f8bed9
JF
241 if (request_ == nil)
242 return;
243
b13b8664
JF
244 NSMutableURLRequest *request([request_ mutableCopy]);
245 [request setCachePolicy:(cache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData)];
246
a374f380 247 request_ = request;
b13b8664 248
d69dbfc5 249 if (cache || [request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
fe468f45 250 [self loadRequest:request_];
22f8bed9 251 else {
79ed082a 252 UIAlertView *alert = [[[UIAlertView alloc]
43f3d7f6 253 initWithTitle:UCLocalize("RESUBMIT_FORM")
79ed082a 254 message:nil
22f8bed9 255 delegate:self
79ed082a 256 cancelButtonTitle:UCLocalize("CANCEL")
1aa29546
JF
257 otherButtonTitles:
258 UCLocalize("SUBMIT"),
259 nil
22f8bed9 260 ] autorelease];
2634b249 261
79ed082a
GP
262 [alert setContext:@"submit"];
263 [alert show];
22f8bed9
JF
264 }
265}
266
eb09425a
JF
267- (void) reloadData {
268 [super reloadData];
d9fc1d37
JF
269
270 if (ready_)
271 [self dispatchEvent:@"CydiaReloadData"];
272 else
273 [self reloadURLWithCache:YES];
eb09425a
JF
274}
275
22f8bed9 276- (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
46d3a5cf
JF
277 custom_ = button;
278 style_ = style;
279 function_ = function;
12b59862 280
70a9ff4e 281 [self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
22f8bed9
JF
282}
283
284- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
46d3a5cf
JF
285 custom_ = button;
286 style_ = style;
287 function_ = function;
22f8bed9 288
ed5566c7
JF
289 [self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
290}
12b59862 291
ed5566c7
JF
292- (void) removeButton {
293 custom_ = [NSNull null];
70a9ff4e 294 [self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
22f8bed9 295}
22f8bed9 296
8e3b68d4
JF
297- (void) scrollToBottomAnimated:(NSNumber *)animated {
298 CGSize size([scroller_ contentSize]);
299 CGPoint offset([scroller_ contentOffset]);
300 CGRect frame([scroller_ frame]);
301
302 if (size.height - offset.y < frame.size.height + 20.f) {
303 CGRect rect = {{0, size.height-1}, {size.width, 1}};
304 [scroller_ scrollRectToVisible:rect animated:[animated boolValue]];
305 }
306}
307
7e37a676 308- (void) _setViewportWidth {
6f837280 309 [[[self webView] _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
7e37a676
JF
310}
311
2634b249
JF
312- (void) setViewportWidth:(float)width {
313 width_ = width != 0 ? width : [[self class] defaultWidth];
7e37a676
JF
314 [self _setViewportWidth];
315}
316
8dbdaafa
JF
317- (void) _setViewportWidthOnMainThread:(NSNumber *)width {
318 [self setViewportWidth:[width floatValue]];
319}
320
321- (void) setViewportWidthOnMainThread:(float)width {
322 [self performSelectorOnMainThread:@selector(_setViewportWidthOnMainThread:) withObject:[NSNumber numberWithFloat:width] waitUntilDone:NO];
323}
324
7e37a676
JF
325- (void) webViewUpdateViewSettings:(UIWebView *)view {
326 [self _setViewportWidth];
22f8bed9
JF
327}
328
2b2a4e33
JF
329- (void) mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
330 [self dismissModalViewControllerAnimated:YES];
331}
332
22485d93
JF
333- (void) _setupMail:(MFMailComposeViewController *)controller {
334}
335
2634b249 336- (void) _openMailToURL:(NSURL *)url {
2b2a4e33
JF
337 if ($MFMailComposeViewController != nil && [$MFMailComposeViewController canSendMail]) {
338 MFMailComposeViewController *controller([[[$MFMailComposeViewController alloc] init] autorelease]);
339 [controller setMailComposeDelegate:self];
340
341 [controller setMailToURL:url];
342
22485d93
JF
343 [self _setupMail:controller];
344
2b2a4e33
JF
345 [self presentModalViewController:controller animated:YES];
346 return;
347 }
348
8ea72491
JF
349 UIApplication *app([UIApplication sharedApplication]);
350 if ([app respondsToSelector:@selector(openURL:asPanel:)])
351 [app openURL:url asPanel:YES];
352 else
353 [app openURL:url];
22f8bed9
JF
354}
355
2634b249
JF
356- (bool) _allowJavaScriptPanel {
357 return true;
22f8bed9
JF
358}
359
8366df5e
JF
360- (bool) allowsNavigationAction {
361 return allowsNavigationAction_;
362}
363
364- (void) setAllowsNavigationAction:(bool)value {
365 allowsNavigationAction_ = value;
366}
367
368- (void) setAllowsNavigationActionByNumber:(NSNumber *)value {
369 [self setAllowsNavigationAction:[value boolValue]];
52498c7e
JF
370}
371
8d497e2a
JF
372- (void) popViewControllerWithNumber:(NSNumber *)value {
373 UINavigationController *navigation([self navigationController]);
374 if ([navigation topViewController] == self)
375 [navigation popViewControllerAnimated:[value boolValue]];
376}
377
2634b249 378- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
8b74eaff
JF
379 NSValue *object([NSValue valueWithNonretainedObject:frame]);
380 if (![loading_ containsObject:object])
381 return;
382 [loading_ removeObject:object];
383
2634b249 384 [self _didFinishLoading];
22f8bed9 385
46b423a7 386 if ([[error domain] isEqualToString:NSURLErrorDomain] && [error code] == NSURLErrorCancelled)
22f8bed9
JF
387 return;
388
fe2d3954 389 if ([[error domain] isEqualToString:WebKitErrorDomain] && [error code] == WebKitErrorFrameLoadInterruptedByPolicyChange) {
5bb0da03 390 request_ = nil;
fe2d3954
JF
391 return;
392 }
393
caa427d1 394 if ([frame parentFrame] == nil) {
2634b249
JF
395 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
396 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
397 [[error localizedDescription] stringByAddingPercentEscapes]
398 ]]];
22f8bed9 399
2634b249
JF
400 error_ = true;
401 }
402}
caa427d1 403
f050e4d9
JF
404- (void) pushRequest:(NSURLRequest *)request forAction:(NSDictionary *)action asPop:(bool)pop {
405 WebFrame *frame(nil);
406 if (NSDictionary *WebActionElement = [action objectForKey:@"WebActionElementKey"])
407 frame = [WebActionElement objectForKey:@"WebElementFrame"];
408 if (frame == nil)
409 frame = [[[[self webView] _documentView] webView] mainFrame];
410
411 WebDataSource *source([frame provisionalDataSource] ?: [frame dataSource]);
412 NSString *referrer([request valueForHTTPHeaderField:@"Referer"] ?: [[[source request] URL] absoluteString]);
413
2634b249 414 NSURL *url([request URL]);
a5938ea5 415
028dbd1c 416 // XXX: filter to internal usage?
f050e4d9 417 CyteViewController *page([delegate_ pageForURL:url forExternal:NO withReferrer:referrer]);
2fad210a 418
2634b249 419 if (page == nil) {
09e89a8a 420 CyteWebViewController *browser([[[class_ alloc] init] autorelease]);
0620c393 421 [browser setRequest:request];
2634b249 422 page = browser;
bc11cf5b 423 }
ce041f4f 424
2634b249 425 [page setDelegate:delegate_];
b5e7eebb 426
52498c7e 427 if (!pop) {
2634b249 428 [[self navigationItem] setTitle:title_];
b5e7eebb 429
2634b249
JF
430 [[self navigationController] pushViewController:page animated:YES];
431 } else {
2e26757e 432 UINavigationController *navigation([[[UINavigationController alloc] initWithRootViewController:page] autorelease]);
22f8bed9 433
2634b249 434 [navigation setDelegate:delegate_];
22f8bed9 435
2634b249
JF
436 [[page navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
437 initWithTitle:UCLocalize("CLOSE")
438 style:UIBarButtonItemStylePlain
439 target:page
440 action:@selector(close)
441 ] autorelease]];
442
45e66037 443 [[self navigationController] presentModalViewController:navigation animated:YES];
2634b249 444 }
52498c7e
JF
445}
446
1ee69bb4 447// CyteWebViewDelegate {{{
52498c7e
JF
448- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
449#if LogMessages
c8f62968
JF
450 static Pcre irritating("^(?"
451 ":" "The page at .* displayed insecure content from .*\\."
452 "|" "Unsafe JavaScript attempt to access frame with URL .* from frame with URL .*\\. Domains, protocols and ports must match\\."
453 ")\\n$");
454
c81b955f
JF
455 if (NSString *data = [message objectForKey:@"message"])
456 if (irritating(data))
457 return;
458
52498c7e
JF
459 NSLog(@"addMessageToConsole:%@", message);
460#endif
461}
462
463- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
464#if LogBrowser
f050e4d9 465 NSLog(@"decidePolicyForNavigationAction:%@ request:%@ %@ frame:%@", action, request, [request allHTTPHeaderFields], frame);
52498c7e
JF
466#endif
467
468 if ([frame parentFrame] == nil) {
469 if (!error_) {
8366df5e
JF
470 NSURL *url(request == nil ? nil : [request URL]);
471
d323285e 472 if (request_ != nil && ![[request_ URL] isEqual:url] && ![self allowsNavigationAction]) {
8366df5e 473 if (url != nil)
f050e4d9 474 [self pushRequest:request forAction:action asPop:NO];
52498c7e
JF
475 [listener ignore];
476 }
477 }
478 }
479}
480
d323285e 481- (void) webView:(WebView *)view didDecidePolicy:(CYWebPolicyDecision)decision forNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame {
77d4e15b
JF
482#if LogBrowser
483 NSLog(@"didDecidePolicy:%u forNavigationAction:%@ request:%@ frame:%@", decision, action, request, [request allHTTPHeaderFields], frame);
484#endif
485
486 if ([frame parentFrame] == nil) {
487 switch (decision) {
488 case CYWebPolicyDecisionIgnore:
489 if ([[request_ URL] isEqual:[request URL]])
490 request_ = nil;
491 break;
492
493 case CYWebPolicyDecisionUse:
494 if (!error_)
495 request_ = request;
496 break;
497
498 default:
499 break;
500 }
501 }
d323285e
JF
502}
503
f050e4d9 504- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
52498c7e 505#if LogBrowser
f050e4d9 506 NSLog(@"decidePolicyForNewWindowAction:%@ request:%@ %@ newFrameName:%@", action, request, [request allHTTPHeaderFields], name);
52498c7e
JF
507#endif
508
509 NSURL *url([request URL]);
510 if (url == nil)
511 return;
512
f050e4d9 513 if ([name isEqualToString:@"_open"])
52498c7e
JF
514 [delegate_ openURL:url];
515 else {
516 NSString *scheme([[url scheme] lowercaseString]);
517 if ([scheme isEqualToString:@"mailto"])
518 [self _openMailToURL:url];
519 else
f050e4d9 520 [self pushRequest:request forAction:action asPop:[name isEqualToString:@"_popup"]];
52498c7e 521 }
22f8bed9 522
2634b249 523 [listener ignore];
22f8bed9
JF
524}
525
2634b249 526- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
c215c5ed
JF
527#if LogBrowser
528 NSLog(@"didClearWindowObject:%@ forFrame:%@", window, frame);
529#endif
22f8bed9
JF
530}
531
64ffa332
JF
532- (void) webView:(WebView *)view didCommitLoadForFrame:(WebFrame *)frame {
533#if LogBrowser
534 NSLog(@"didCommitLoadForFrame:%@", frame);
535#endif
536
537 if ([frame parentFrame] == nil) {
b3be8c0c 538 loaded_ = true;
64ffa332
JF
539 }
540}
541
2634b249
JF
542- (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
543#if LogBrowser
544 NSLog(@"didFailLoadWithError:%@ forFrame:%@", error, frame);
545#endif
546
547 [self _didFailWithError:error forFrame:frame];
22f8bed9
JF
548}
549
2634b249
JF
550- (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
551#if LogBrowser
552 NSLog(@"didFailProvisionalLoadWithError:%@ forFrame:%@", error, frame);
553#endif
554
555 [self _didFailWithError:error forFrame:frame];
22f8bed9
JF
556}
557
2634b249 558- (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame {
8b74eaff
JF
559 NSValue *object([NSValue valueWithNonretainedObject:frame]);
560 if (![loading_ containsObject:object])
561 return;
562 [loading_ removeObject:object];
22f8bed9 563
caa427d1 564 if ([frame parentFrame] == nil) {
22f8bed9 565 if (DOMDocument *document = [frame DOMDocument])
4cc9e99a 566 if (DOMNodeList *bodies = [document getElementsByTagName:@"body"])
96f3833b 567 for (DOMHTMLBodyElement *body in (id) bodies) {
22f8bed9
JF
568 DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
569
65ea9562 570 UIColor *uic(nil);
22f8bed9
JF
571
572 if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) {
fe468f45
JF
573 if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
574 DOMRGBColor *rgb([color getRGBColorValue]);
575
576 float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
577 float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
578 float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
579 float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
580
a7bc69f5
JF
581 uic = [UIColor
582 colorWithRed:(red / 255)
583 green:(green / 255)
584 blue:(blue / 255)
585 alpha:alpha
586 ];
22f8bed9
JF
587 }
588 }
589
a7bc69f5 590 [scroller_ setBackgroundColor:uic];
22f8bed9
JF
591 break;
592 }
593 }
594
2634b249 595 [self _didFinishLoading];
22f8bed9
JF
596}
597
2634b249
JF
598- (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
599 if ([frame parentFrame] != nil)
600 return;
caa427d1 601
7b33d201 602 title_ = title;
3931b718 603
2634b249
JF
604 [[self navigationItem] setTitle:title_];
605}
22f8bed9 606
2634b249 607- (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame {
a86042fa
JF
608#if LogBrowser
609 NSLog(@"didStartProvisionalLoadForFrame:%@", frame);
610#endif
611
2634b249 612 [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
7592e053 613
caa427d1 614 if ([frame parentFrame] == nil) {
7b33d201 615 title_ = nil;
46d3a5cf
JF
616 custom_ = nil;
617 style_ = nil;
618 function_ = nil;
2634b249 619
aa1e1906
JF
620 [registered_ removeAllObjects];
621 timer_ = nil;
622
622a9912
JF
623 allowsNavigationAction_ = true;
624
5cdfcd6f 625 [self setHidesNavigationBar:NO];
db698f42 626 [self setScrollAlwaysBounceVertical:true];
4886cc81 627 [self setScrollIndicatorStyle:UIScrollViewIndicatorStyleDefault];
5cdfcd6f 628
2634b249
JF
629 // XXX: do we still need to do this?
630 [[self navigationItem] setTitle:nil];
caa427d1 631 }
fe468f45 632
2634b249 633 [self _didStartLoading];
caa427d1
JF
634}
635
2634b249 636- (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
0352f238
JF
637#if LogBrowser
638 NSLog(@"resource:%@ willSendRequest:%@ redirectResponse:%@ fromDataSource:%@", identifier, request, response, source);
639#endif
640
2634b249 641 return request;
22f8bed9
JF
642}
643
2634b249
JF
644- (bool) webView:(WebView *)view shouldRunJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
645 return [self _allowJavaScriptPanel];
22f8bed9
JF
646}
647
2634b249
JF
648- (bool) webView:(WebView *)view shouldRunJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
649 return [self _allowJavaScriptPanel];
600d005d
JF
650}
651
2634b249
JF
652- (bool) webView:(WebView *)view shouldRunJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
653 return [self _allowJavaScriptPanel];
600d005d
JF
654}
655
2634b249
JF
656- (void) webViewClose:(WebView *)view {
657 [self close];
600d005d 658}
2634b249 659// }}}
600d005d 660
2634b249 661- (void) close {
19f2d77f 662 [[[self navigationController] parentOrPresentingViewController] dismissModalViewControllerAnimated:YES];
600d005d
JF
663}
664
2634b249
JF
665- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
666 NSString *context([alert context]);
600d005d 667
2634b249
JF
668 if ([context isEqualToString:@"sensitive"]) {
669 switch (button) {
670 case 1:
671 sensitive_ = [NSNumber numberWithBool:YES];
672 break;
600d005d 673
2634b249
JF
674 case 2:
675 sensitive_ = [NSNumber numberWithBool:NO];
676 break;
677 }
600d005d 678
2634b249
JF
679 [alert dismissWithClickedButtonIndex:-1 animated:YES];
680 } else if ([context isEqualToString:@"challenge"]) {
681 id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
caa427d1 682
2634b249
JF
683 switch (button) {
684 case 1: {
685 NSString *username([[alert textFieldAtIndex:0] text]);
686 NSString *password([[alert textFieldAtIndex:1] text]);
600d005d 687
2634b249 688 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
600d005d 689
2634b249
JF
690 [sender useCredential:credential forAuthenticationChallenge:challenge_];
691 } break;
600d005d 692
2634b249
JF
693 case 2:
694 [sender cancelAuthenticationChallenge:challenge_];
695 break;
600d005d 696
2634b249
JF
697 _nodefault
698 }
600d005d 699
2634b249 700 challenge_ = nil;
600d005d 701
2634b249
JF
702 [alert dismissWithClickedButtonIndex:-1 animated:YES];
703 } else if ([context isEqualToString:@"submit"]) {
75b95256
JF
704 if (button == [alert cancelButtonIndex]) {
705 } else if (button == [alert firstOtherButtonIndex]) {
706 if (request_ != nil) {
0893a034 707 WebThreadLocked lock;
6f837280 708 [[self webView] loadRequest:request_];
75b95256 709 }
2634b249 710 }
600d005d 711
2634b249
JF
712 [alert dismissWithClickedButtonIndex:-1 animated:YES];
713 }
600d005d
JF
714}
715
2634b249
JF
716- (UIBarButtonItemStyle) rightButtonStyle {
717 if (style_ == nil) normal:
718 return UIBarButtonItemStylePlain;
719 else if ([style_ isEqualToString:@"Normal"])
720 return UIBarButtonItemStylePlain;
721 else if ([style_ isEqualToString:@"Highlighted"])
722 return UIBarButtonItemStyleDone;
723 else goto normal;
600d005d
JF
724}
725
2634b249 726- (UIBarButtonItem *) customButton {
29756674
JF
727 if (custom_ == nil)
728 return nil;
4cc9e99a 729 else if ((/*clang:*/id) custom_ == [NSNull null])
29756674
JF
730 return (UIBarButtonItem *) [NSNull null];
731
732 return [[[UIBarButtonItem alloc]
ed5566c7 733 initWithTitle:static_cast<NSString *>(custom_.operator NSObject *())
2634b249
JF
734 style:[self rightButtonStyle]
735 target:self
736 action:@selector(customButtonClicked)
737 ] autorelease];
caa427d1
JF
738}
739
e6124cb6
JF
740- (UIBarButtonItem *) leftButton {
741 UINavigationItem *item([self navigationItem]);
742 if ([item backBarButtonItem] != nil && ![item hidesBackButton])
743 return nil;
744
745 if (UINavigationController *navigation = [self navigationController])
19f2d77f 746 if ([[navigation parentOrPresentingViewController] modalViewController] == navigation)
e6124cb6
JF
747 return [[[UIBarButtonItem alloc]
748 initWithTitle:UCLocalize("CLOSE")
749 style:UIBarButtonItemStylePlain
750 target:self
751 action:@selector(close)
752 ] autorelease];
753
754 return nil;
755}
756
757- (void) applyLeftButton {
758 [[self navigationItem] setLeftBarButtonItem:[self leftButton]];
759}
760
2634b249
JF
761- (UIBarButtonItem *) rightButton {
762 return reloaditem_;
eb35c522
JF
763}
764
2634b249
JF
765- (void) applyLoadingTitle {
766 [[self navigationItem] setTitle:UCLocalize("LOADING")];
caa427d1
JF
767}
768
c83a464d
JF
769- (void) layoutRightButton {
770 [[loadingitem_ view] addSubview:indicator_];
771 [[loadingitem_ view] bringSubviewToFront:indicator_];
772}
773
2634b249
JF
774- (void) applyRightButton {
775 if ([self isLoading]) {
776 [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
c83a464d 777 [self performSelector:@selector(layoutRightButton) withObject:nil afterDelay:0];
8d603a7d
JF
778
779 [indicator_ startAnimating];
2634b249 780 [self applyLoadingTitle];
2634b249 781 } else {
8d603a7d
JF
782 [indicator_ stopAnimating];
783
29756674
JF
784 UIBarButtonItem *button([self customButton]);
785 if (button == nil)
786 button = [self rightButton];
787 else if (button == (UIBarButtonItem *) [NSNull null])
788 button = nil;
789
bf965437 790 [[self navigationItem] setRightBarButtonItem:button animated:YES];
2634b249 791 }
caa427d1
JF
792}
793
df30fbee
GP
794- (void) didStartLoading {
795 // Overridden in subclasses.
796}
797
2634b249
JF
798- (void) _didStartLoading {
799 [self applyRightButton];
54043703
JF
800
801 if ([loading_ count] != 1)
802 return;
df30fbee 803
2713be8e
JF
804 if ([self retainsNetworkActivityIndicator])
805 [delegate_ retainNetworkActivityIndicator];
806
df30fbee
GP
807 [self didStartLoading];
808}
809
810- (void) didFinishLoading {
811 // Overridden in subclasses.
caa427d1
JF
812}
813
2634b249
JF
814- (void) _didFinishLoading {
815 if ([loading_ count] != 0)
816 return;
817
818 [self applyRightButton];
df30fbee 819 [[self navigationItem] setTitle:title_];
2634b249 820
2713be8e
JF
821 if ([self retainsNetworkActivityIndicator])
822 [delegate_ releaseNetworkActivityIndicator];
823
df30fbee 824 [self didFinishLoading];
caa427d1
JF
825}
826
2634b249
JF
827- (bool) isLoading {
828 return [loading_ count] != 0;
caa427d1
JF
829}
830
b5e7eebb
GP
831- (id) initWithWidth:(float)width ofClass:(Class)_class {
832 if ((self = [super init]) != nil) {
6f837280
JF
833 width_ = width;
834 class_ = _class;
835
df08be87
JF
836 allowsNavigationAction_ = true;
837
7b33d201 838 loading_ = [NSMutableSet setWithCapacity:5];
aa1e1906 839 registered_ = [NSMutableSet setWithCapacity:5];
7b33d201 840 indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
caa427d1 841
6f837280
JF
842 reloaditem_ = [[[UIBarButtonItem alloc]
843 initWithTitle:UCLocalize("RELOAD")
844 style:[self rightButtonStyle]
845 target:self
846 action:@selector(reloadButtonClicked)
847 ] autorelease];
65ea9562 848
6f837280 849 loadingitem_ = [[[UIBarButtonItem alloc]
5328a9f0 850 initWithTitle:(kCFCoreFoundationVersionNumber >= 800 ? @" " : @" ")
6f837280
JF
851 style:UIBarButtonItemStylePlain
852 target:self
853 action:@selector(reloadButtonClicked)
854 ] autorelease];
22f8bed9 855
5328a9f0
JF
856 UIActivityIndicatorViewStyle style;
857 float left;
858 if (kCFCoreFoundationVersionNumber >= 800) {
859 style = UIActivityIndicatorViewStyleGray;
860 left = 7;
861 } else {
862 style = UIActivityIndicatorViewStyleWhite;
863 left = 15;
864 }
865
866 indicator_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:style] autorelease];
867 [indicator_ setFrame:CGRectMake(left, 5, [indicator_ frame].size.width, [indicator_ frame].size.height)];
6f837280 868 [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
22f8bed9 869
6f837280
JF
870 [self applyLeftButton];
871 [self applyRightButton];
872 } return self;
873}
22f8bed9 874
c6cf66c7
JF
875- (NSString *) applicationNameForUserAgent {
876 return nil;
877}
878
6f837280
JF
879- (void) loadView {
880 CGRect bounds([[UIScreen mainScreen] applicationFrame]);
ea173384 881
6f837280
JF
882 webview_ = [[[CyteWebView alloc] initWithFrame:bounds] autorelease];
883 [webview_ setDelegate:self];
884 [self setView:webview_];
ea173384 885
6f837280
JF
886 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
887 [webview_ setDataDetectorTypes:UIDataDetectorTypeAutomatic];
888 else
889 [webview_ setDetectsPhoneNumbers:NO];
14f17703 890
6f837280 891 [webview_ setScalesPageToFit:YES];
ea173384 892
6f837280 893 UIWebDocumentView *document([webview_ _documentView]);
22f8bed9 894
6f837280
JF
895 // XXX: I think this improves scrolling; the hardcoded-ness sucks
896 [document setTileSize:CGSizeMake(320, 500)];
22f8bed9 897
6f837280
JF
898 WebView *webview([document webView]);
899 WebPreferences *preferences([webview preferences]);
72bdb258 900
6f837280
JF
901 // XXX: I have no clue if I actually /want/ this modification
902 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
903 [webview _setLayoutInterval:0];
904 else if ([preferences respondsToSelector:@selector(_setLayoutInterval:)])
905 [preferences _setLayoutInterval:0];
22f8bed9 906
6f837280
JF
907 [preferences setCacheModel:WebCacheModelDocumentBrowser];
908 [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
64cc10e2
JF
909
910 if ([preferences respondsToSelector:@selector(setOfflineWebApplicationCacheEnabled:)])
911 [preferences setOfflineWebApplicationCacheEnabled:YES];
22f8bed9 912
c6cf66c7
JF
913 if (NSString *agent = [self applicationNameForUserAgent])
914 [webview setApplicationNameForUserAgent:agent];
915
6f837280
JF
916 if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)])
917 [webview setShouldUpdateWhileOffscreen:NO];
22f8bed9 918
6f837280
JF
919#if LogMessages
920 if ([document respondsToSelector:@selector(setAllowsMessaging:)])
921 [document setAllowsMessaging:YES];
922 if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
923 [webview _setAllowsMessaging:YES];
924#endif
3e9c9e85 925
6f837280
JF
926 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
927 scroller_ = [webview_ _scrollView];
ea173384 928
6f837280
JF
929 [scroller_ setDirectionalLockEnabled:YES];
930 [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
931 [scroller_ setDelaysContentTouches:NO];
ea173384 932
6f837280
JF
933 [scroller_ setCanCancelContentTouches:YES];
934 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
935 UIScroller *scroller([webview_ _scroller]);
936 scroller_ = (UIScrollView *) scroller;
bc11cf5b 937
6f837280
JF
938 [scroller setDirectionalScrolling:YES];
939 // XXX: we might be better off /not/ setting this on older systems
940 [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
941 [scroller setScrollHysteresis:0]; /* 8 */
caa427d1 942
6f837280 943 [scroller setThumbDetectionEnabled:NO];
caa427d1 944
6f837280
JF
945 // use NO with UIApplicationUseLegacyEvents(YES)
946 [scroller setEventMode:YES];
bc11cf5b 947
6f837280
JF
948 // XXX: this is handled by setBounces, right?
949 //[scroller setAllowsRubberBanding:YES];
950 }
bc11cf5b 951
6f837280 952 [scroller_ setFixedBackgroundPattern:YES];
a7bc69f5 953 [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
6f837280 954 [scroller_ setClipsSubviews:YES];
2634b249 955
6f837280
JF
956 [scroller_ setBounces:YES];
957 [scroller_ setScrollingEnabled:YES];
958 [scroller_ setShowBackgroundShadow:NO];
22f8bed9 959
6f837280 960 [self setViewportWidth:width_];
65ea9562 961
6f837280 962 [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
47a40da6
JF
963
964 ready_ = false;
6f837280
JF
965}
966
967- (void) releaseSubviews {
968 webview_ = nil;
969 scroller_ = nil;
7be3eb32 970
8b74eaff
JF
971 [self releaseNetworkActivityIndicator];
972
7be3eb32 973 [super releaseSubviews];
22f8bed9
JF
974}
975
b5e7eebb
GP
976- (id) initWithWidth:(float)width {
977 return [self initWithWidth:width ofClass:[self class]];
245cce8a
JF
978}
979
b5e7eebb
GP
980- (id) init {
981 return [self initWithWidth:0];
3e9c9e85
JF
982}
983
eb09425a
JF
984- (id) initWithURL:(NSURL *)url {
985 if ((self = [self init]) != nil) {
986 [self setURL:url];
987 } return self;
988}
989
68bd7c60
JF
990- (id) initWithRequest:(NSURLRequest *)request {
991 if ((self = [self init]) != nil) {
992 [self setRequest:request];
993 } return self;
994}
995
12b59862 996- (void) callFunction:(WebScriptObject *)function {
0893a034 997 WebThreadLocked lock;
caa427d1 998
6f837280 999 WebView *webview([[[self webView] _documentView] webView]);
12b59862 1000 WebFrame *frame([webview mainFrame]);
c21004b9 1001
12b59862 1002 JSGlobalContextRef context([frame globalContext]);
9dbfe708 1003 JSObjectRef object([function JSObject]);
7c80833f
JF
1004 if ($JSObjectCallAsFunction != NULL)
1005 ($JSObjectCallAsFunction)(context, object, NULL, 0, NULL, NULL);
12b59862
JF
1006}
1007
ce041f4f 1008- (void) reloadButtonClicked {
d69dbfc5 1009 [self reloadURLWithCache:NO];
12b59862
JF
1010}
1011
719d6c2f
DH
1012- (void) _customButtonClicked {
1013 [self reloadButtonClicked];
1014}
1015
ce041f4f 1016- (void) customButtonClicked {
caa427d1
JF
1017#if !AlwaysReload
1018 if (function_ != nil)
12b59862 1019 [self callFunction:function_];
caa427d1
JF
1020 else
1021#endif
719d6c2f 1022 [self _customButtonClicked];
22f8bed9
JF
1023}
1024
3e9c9e85
JF
1025+ (float) defaultWidth {
1026 return 980;
1027}
1028
82406217
JF
1029- (void) setNavigationBarStyle:(NSString *)name {
1030 UIBarStyle style;
1031 if ([name isEqualToString:@"Black"])
1032 style = UIBarStyleBlack;
1033 else
1034 style = UIBarStyleDefault;
1035
1036 [[[self navigationController] navigationBar] setBarStyle:style];
1037}
1038
00984204
JF
1039- (void) setNavigationBarTintColor:(UIColor *)color {
1040 [[[self navigationController] navigationBar] setTintColor:color];
1041}
1042
c31c825d
JF
1043- (void) setBadgeValue:(id)value {
1044 [[[self navigationController] tabBarItem] setBadgeValue:value];
1045}
1046
b8a5d89d
JF
1047- (void) setHidesBackButton:(bool)value {
1048 [[self navigationItem] setHidesBackButton:value];
e6124cb6 1049 [self applyLeftButton];
b8a5d89d
JF
1050}
1051
1052- (void) setHidesBackButtonByNumber:(NSNumber *)value {
1053 [self setHidesBackButton:[value boolValue]];
1054}
1055
f196b921 1056- (void) dispatchEvent:(NSString *)event {
6f837280 1057 [[self webView] dispatchEvent:event];
f196b921
JF
1058}
1059
5cdfcd6f
JF
1060- (bool) hidesNavigationBar {
1061 return hidesNavigationBar_;
1062}
1063
1064- (void) _setHidesNavigationBar:(bool)value animated:(bool)animated {
1065 if (visible_)
1066 [[self navigationController] setNavigationBarHidden:(value && [self hidesNavigationBar]) animated:animated];
1067}
1068
1069- (void) setHidesNavigationBar:(bool)value {
1070 if (hidesNavigationBar_ != value) {
1071 hidesNavigationBar_ = value;
1072 [self _setHidesNavigationBar:YES animated:YES];
1073 }
1074}
1075
1076- (void) setHidesNavigationBarByNumber:(NSNumber *)value {
1077 [self setHidesNavigationBar:[value boolValue]];
1078}
1079
db698f42
JF
1080- (void) setScrollAlwaysBounceVertical:(bool)value {
1081 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
1082 UIScrollView *scroller([webview_ _scrollView]);
1083 [scroller setAlwaysBounceVertical:value];
1084 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
1085 //UIScroller *scroller([webview_ _scroller]);
1086 // XXX: I am sad here.
1087 } else return;
1088}
1089
1090- (void) setScrollAlwaysBounceVerticalNumber:(NSNumber *)value {
1091 [self setScrollAlwaysBounceVertical:[value boolValue]];
1092}
1093
4886cc81
JF
1094- (void) setScrollIndicatorStyle:(UIScrollViewIndicatorStyle)style {
1095 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
1096 UIScrollView *scroller([webview_ _scrollView]);
1097 [scroller setIndicatorStyle:style];
1098 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
1099 UIScroller *scroller([webview_ _scroller]);
1100 [scroller setScrollerIndicatorStyle:style];
1101 } else return;
1102}
1103
1104- (void) setScrollIndicatorStyleWithName:(NSString *)style {
1105 UIScrollViewIndicatorStyle value;
1106
1107 if (false);
1108 else if ([style isEqualToString:@"default"])
1109 value = UIScrollViewIndicatorStyleDefault;
1110 else if ([style isEqualToString:@"black"])
1111 value = UIScrollViewIndicatorStyleBlack;
1112 else if ([style isEqualToString:@"white"])
1113 value = UIScrollViewIndicatorStyleWhite;
1114 else return;
1115
1116 [self setScrollIndicatorStyle:value];
1117}
1118
f196b921 1119- (void) viewWillAppear:(BOOL)animated {
5cdfcd6f
JF
1120 visible_ = true;
1121
1122 if ([self hidesNavigationBar])
1123 [self _setHidesNavigationBar:YES animated:animated];
1124
3cf38067
JF
1125 // XXX: why isn't this evern called automatically?
1126 [[self webView] setNeedsLayout];
1127
f196b921
JF
1128 [self dispatchEvent:@"CydiaViewWillAppear"];
1129 [super viewWillAppear:animated];
1130}
1131
1132- (void) viewDidAppear:(BOOL)animated {
f196b921 1133 [super viewDidAppear:animated];
5cdfcd6f 1134 [self dispatchEvent:@"CydiaViewDidAppear"];
f196b921
JF
1135}
1136
1137- (void) viewWillDisappear:(BOOL)animated {
1138 [self dispatchEvent:@"CydiaViewWillDisappear"];
1139 [super viewWillDisappear:animated];
5cdfcd6f
JF
1140
1141 if ([self hidesNavigationBar])
1142 [self _setHidesNavigationBar:NO animated:animated];
1143
1144 visible_ = false;
f196b921
JF
1145}
1146
1147- (void) viewDidDisappear:(BOOL)animated {
f196b921 1148 [super viewDidDisappear:animated];
5cdfcd6f 1149 [self dispatchEvent:@"CydiaViewDidDisappear"];
f196b921
JF
1150}
1151
aa1e1906
JF
1152- (void) updateHeights:(NSTimer *)timer {
1153 for (WebFrame *frame in (id) registered_)
1154 [frame cydia$updateHeight];
1155}
1156
1157- (void) registerFrame:(WebFrame *)frame {
1158 [registered_ addObject:frame];
1159
1160 if (timer_ == nil)
1161 timer_ = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(updateHeights:) userInfo:nil repeats:YES];
1162}
1163
a5938ea5 1164@end