]> git.saurik.com Git - cydia.git/blob - UICaboodle/BrowserView.mm
Fixed a serious localization bug.
[cydia.git] / UICaboodle / BrowserView.mm
1 #include <UICaboodle/BrowserView.h>
2 #include <UICaboodle/UCLocalize.h>
3
4 #import <QuartzCore/CALayer.h>
5 // XXX: fix the minimum requirement
6 extern NSString * const kCAFilterNearest;
7
8 #include <WebCore/WebCoreThread.h>
9
10 #include "substrate.h"
11
12 @interface NSString (UIKit)
13 - (NSString *) stringByAddingPercentEscapes;
14 @end
15
16 /* Indirect Delegate {{{ */
17 @interface IndirectDelegate : NSObject {
18 _transient volatile id delegate_;
19 }
20
21 - (void) setDelegate:(id)delegate;
22 - (id) initWithDelegate:(id)delegate;
23 @end
24
25 @implementation IndirectDelegate
26
27 - (void) setDelegate:(id)delegate {
28 delegate_ = delegate;
29 }
30
31 - (id) initWithDelegate:(id)delegate {
32 delegate_ = delegate;
33 return self;
34 }
35
36 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
37 if (delegate_ != nil)
38 return [delegate_ webView:sender didClearWindowObject:window forFrame:frame];
39 }
40
41 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
42 if (delegate_ != nil)
43 return [delegate_ webView:sender didCommitLoadForFrame:frame];
44 }
45
46 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
47 if (delegate_ != nil)
48 return [delegate_ webView:sender didFailLoadWithError:error forFrame:frame];
49 }
50
51 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
52 if (delegate_ != nil)
53 return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame];
54 }
55
56 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
57 if (delegate_ != nil)
58 return [delegate_ webView:sender didFinishLoadForFrame:frame];
59 }
60
61 - (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
62 if (delegate_ != nil)
63 return [delegate_ webView:sender didReceiveTitle:title forFrame:frame];
64 }
65
66 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
67 if (delegate_ != nil)
68 return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame];
69 }
70
71 - (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
72 if (delegate_ != nil)
73 return [delegate_ webView:sender resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source];
74 }
75
76 - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
77 if (delegate_ != nil)
78 return [delegate_ webView:sender resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:source];
79 return nil;
80 }
81
82 - (IMP) methodForSelector:(SEL)sel {
83 if (IMP method = [super methodForSelector:sel])
84 return method;
85 fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
86 return NULL;
87 }
88
89 - (BOOL) respondsToSelector:(SEL)sel {
90 if ([super respondsToSelector:sel])
91 return YES;
92 // XXX: WebThreadCreateNSInvocation returns nil
93 //fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
94 return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
95 }
96
97 - (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
98 if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
99 return method;
100 //fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
101 if (delegate_ != nil)
102 if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
103 return sig;
104 // XXX: I fucking hate Apple so very very bad
105 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
106 }
107
108 - (void) forwardInvocation:(NSInvocation *)inv {
109 SEL sel = [inv selector];
110 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
111 [inv invokeWithTarget:delegate_];
112 }
113
114 @end
115 /* }}} */
116
117 @interface WebView (UICaboodle)
118 - (void) setScriptDebugDelegate:(id)delegate;
119 - (void) _setFormDelegate:(id)delegate;
120 - (void) _setUIKitDelegate:(id)delegate;
121 - (void) setWebMailDelegate:(id)delegate;
122 - (void) _setLayoutInterval:(float)interval;
123 @end
124
125 @implementation WebScriptObject (UICaboodle)
126
127 - (unsigned) count {
128 id length([self valueForKey:@"length"]);
129 if ([length respondsToSelector:@selector(intValue)])
130 return [length intValue];
131 else
132 return 0;
133 }
134
135 - (id) objectAtIndex:(unsigned)index {
136 return [self webScriptValueAtIndex:index];
137 }
138
139 @end
140
141 #if 0
142 /* Mail Composition {{{ */
143 @interface MailToView : PopUpView {
144 MailComposeController *controller_;
145 }
146
147 - (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url;
148
149 @end
150
151 @implementation MailToView
152
153 - (void) dealloc {
154 [controller_ release];
155 [super dealloc];
156 }
157
158 - (void) mailComposeControllerWillAttemptToSend:(MailComposeController *)controller {
159 NSLog(@"will");
160 }
161
162 - (void) mailComposeControllerDidAttemptToSend:(MailComposeController *)controller mailDelivery:(id)delivery {
163 NSLog(@"did:%@", delivery);
164 // [UIApp setStatusBarShowsProgress:NO];
165 if ([controller error]){
166 NSArray *buttons = [NSArray arrayWithObjects:UCLocalize("OK"), nil];
167 UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self];
168 [mailAlertSheet setBodyText:[controller error]];
169 [mailAlertSheet popupAlertAnimated:YES];
170 }
171 }
172
173 - (void) showError {
174 NSLog(@"%@", [controller_ error]);
175 NSArray *buttons = [NSArray arrayWithObjects:UCLocalize("OK"), nil];
176 UIActionSheet *mailAlertSheet = [[UIActionSheet alloc] initWithTitle:UCLocalize("ERROR") buttons:buttons defaultButtonIndex:0 delegate:self context:self];
177 [mailAlertSheet setBodyText:[controller_ error]];
178 [mailAlertSheet popupAlertAnimated:YES];
179 }
180
181 - (void) deliverMessage { _pooled
182 setuid(501);
183 setgid(501);
184
185 if (![controller_ deliverMessage])
186 [self performSelectorOnMainThread:@selector(showError) withObject:nil waitUntilDone:NO];
187 }
188
189 - (void) mailComposeControllerCompositionFinished:(MailComposeController *)controller {
190 if ([controller_ needsDelivery])
191 [NSThread detachNewThreadSelector:@selector(deliverMessage) toTarget:self withObject:nil];
192 else
193 [self cancel];
194 }
195
196 - (id) initWithView:(UIView *)view delegate:(id)delegate url:(NSURL *)url {
197 if ((self = [super initWithView:view delegate:delegate]) != nil) {
198 controller_ = [[MailComposeController alloc] initForContentSize:[overlay_ bounds].size];
199 [controller_ setDelegate:self];
200 [controller_ initializeUI];
201 [controller_ setupForURL:url];
202
203 UIView *view([controller_ view]);
204 [overlay_ addSubview:view];
205 } return self;
206 }
207
208 @end
209 /* }}} */
210 #endif
211
212 @implementation BrowserView
213
214 #if ShowInternals
215 #include "Internals.h"
216 #endif
217
218 - (void) dealloc {
219 #if LogBrowser
220 NSLog(@"[BrowserView dealloc]");
221 #endif
222
223 if (challenge_ != nil)
224 [challenge_ release];
225
226 WebThreadLock();
227
228 WebView *webview = [webview_ webView];
229 [webview setFrameLoadDelegate:nil];
230 [webview setResourceLoadDelegate:nil];
231 [webview setUIDelegate:nil];
232 [webview setScriptDebugDelegate:nil];
233 [webview setPolicyDelegate:nil];
234
235 [webview setDownloadDelegate:nil];
236
237 /* XXX: these are set by UIWebDocumentView
238 [webview _setFormDelegate:nil];
239 [webview _setUIKitDelegate:nil];
240 [webview setEditingDelegate:nil];*/
241
242 /* XXX: no one sets this, ever
243 [webview setWebMailDelegate:nil];*/
244
245 [webview_ setDelegate:nil];
246 [webview_ setGestureDelegate:nil];
247 [webview_ setFormEditingDelegate:nil];
248 [webview_ setInteractionDelegate:nil];
249
250 [indirect_ setDelegate:nil];
251
252 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
253
254 [webview close];
255
256 #if RecycleWebViews
257 [webview_ removeFromSuperview];
258 [Documents_ addObject:[webview_ autorelease]];
259 #else
260 [webview_ release];
261 #endif
262
263 [indirect_ release];
264
265 WebThreadUnlock();
266
267 [scroller_ setDelegate:nil];
268
269 if (button_ != nil)
270 [button_ release];
271 if (style_ != nil)
272 [style_ release];
273 if (function_ != nil)
274 [function_ release];
275 if (finish_ != nil)
276 [finish_ release];
277 if (closer_ != nil)
278 [closer_ release];
279 if (special_ != nil)
280 [special_ release];
281
282 [scroller_ release];
283 [indicator_ release];
284 if (confirm_ != nil)
285 [confirm_ release];
286 if (sensitive_ != nil)
287 [sensitive_ release];
288 if (title_ != nil)
289 [title_ release];
290 [super dealloc];
291 }
292
293 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
294 [self loadRequest:[NSURLRequest
295 requestWithURL:url
296 cachePolicy:policy
297 timeoutInterval:30.0
298 ]];
299 }
300
301 - (void) loadURL:(NSURL *)url {
302 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
303 }
304
305 - (void) loadRequest:(NSURLRequest *)request {
306 pushed_ = true;
307 error_ = false;
308
309 WebThreadLock();
310 [webview_ loadRequest:request];
311 WebThreadUnlock();
312 }
313
314 - (void) reloadURL {
315 if (request_ == nil)
316 return;
317
318 if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
319 [self loadRequest:request_];
320 else {
321 UIActionSheet *sheet = [[[UIActionSheet alloc]
322 initWithTitle:UCLocalize("RESUBMIT_FORM")
323 buttons:[NSArray arrayWithObjects:UCLocalize("CANCEL"), UCLocalize("SUBMIT"), nil]
324 defaultButtonIndex:0
325 delegate:self
326 context:@"submit"
327 ] autorelease];
328
329 [sheet setNumberOfRows:1];
330 [sheet popupAlertAnimated:YES];
331 }
332 }
333
334 - (WebView *) webView {
335 return [webview_ webView];
336 }
337
338 - (UIWebDocumentView *) documentView {
339 return webview_;
340 }
341
342 /* XXX: WebThreadLock? */
343 - (void) _fixScroller:(CGRect)bounds {
344 float extra;
345 if (!editing_)
346 extra = 0;
347 else {
348 UIFormAssistant *assistant([UIFormAssistant sharedFormAssistant]);
349 CGRect peripheral([assistant peripheralFrame]);
350 #if LogBrowser
351 NSLog(@"per:%f", peripheral.size.height);
352 #endif
353 extra = peripheral.size.height;
354 }
355
356 CGRect subrect([scroller_ frame]);
357 subrect.size.height -= extra;
358 [scroller_ setScrollerIndicatorSubrect:subrect];
359
360 NSSize visible(NSMakeSize(subrect.size.width, subrect.size.height));
361 [webview_ setValue:[NSValue valueWithSize:visible] forGestureAttribute:UIGestureAttributeVisibleSize];
362
363 CGSize size(size_);
364 size.height += extra;
365 [scroller_ setContentSize:size];
366
367 [scroller_ releaseRubberBandIfNecessary];
368 }
369
370 - (void) fixScroller {
371 CGRect bounds([webview_ documentBounds]);
372 #if TrackResize
373 NSLog(@"_fs:(%f,%f+%f,%f)", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
374 #endif
375 [self _fixScroller:bounds];
376 }
377
378 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
379 size_ = frame.size;
380 #if TrackResize
381 NSLog(@"dsf:(%f,%f+%f,%f)", frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
382 #endif
383 [self _fixScroller:frame];
384 }
385
386 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
387 [self view:sender didSetFrame:frame];
388 }
389
390 - (void) pushPage:(RVPage *)page {
391 [page setDelegate:delegate_];
392 [self setBackButtonTitle:title_];
393 [book_ pushPage:page];
394 }
395
396 - (void) _pushPage {
397 if (pushed_)
398 return;
399 // WTR: [self autorelease];
400 pushed_ = true;
401 [book_ pushPage:self];
402 }
403
404 - (void) swapPage:(RVPage *)page {
405 [page setDelegate:delegate_];
406 if (pushed_)
407 [book_ swapPage:page];
408 else
409 [book_ pushPage:page];
410 }
411
412 - (BOOL) getSpecial:(NSURL *)url swap:(BOOL)swap {
413 #if LogBrowser
414 NSLog(@"getSpecial:%@", url);
415 #endif
416
417 if (RVPage *page = [delegate_ pageForURL:url hasTag:NULL]) {
418 if (swap)
419 [self swapPage:page];
420 else
421 [self pushPage:page];
422
423 return true;
424 } else
425 return false;
426 }
427
428 - (void) webViewShow:(WebView *)sender {
429 /* XXX: this is where I cry myself to sleep */
430 }
431
432 - (bool) _allowJavaScriptPanel {
433 return true;
434 }
435
436 - (bool) allowSensitiveRequests {
437 return [self _allowJavaScriptPanel];
438 }
439
440 - (void) _promptForSensitive:(NSMutableArray *)array {
441 NSString *name([array objectAtIndex:0]);
442
443 UIActionSheet *sheet = [[[UIActionSheet alloc]
444 initWithTitle:nil
445 buttons:[NSArray arrayWithObjects:UCLocalize("YES"), UCLocalize("NO"), nil]
446 defaultButtonIndex:0
447 delegate:indirect_
448 context:@"sensitive"
449 ] autorelease];
450
451 NSString *host(@"XXX");
452
453 [sheet setNumberOfRows:1];
454 [sheet setBodyText:[NSString stringWithFormat:@"The website at %@ is requesting your phone's %@. This is almost certainly for product licensing purposes. Will you allow this?", host, name]];
455 [sheet popupAlertAnimated:YES];
456
457 NSRunLoop *loop([NSRunLoop currentRunLoop]);
458 NSDate *future([NSDate distantFuture]);
459
460 while (sensitive_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
461
462 NSNumber *sensitive([sensitive_ autorelease]);
463 sensitive_ = nil;
464
465 [self autorelease];
466 [array replaceObjectAtIndex:0 withObject:sensitive];
467 }
468
469 - (bool) promptForSensitive:(NSString *)name {
470 if (![self allowSensitiveRequests])
471 return false;
472
473 NSMutableArray *array([NSMutableArray arrayWithCapacity:1]);
474 [array addObject:name];
475
476 [self performSelectorOnMainThread:@selector(_promptForSensitive:) withObject:array waitUntilDone:YES];
477 return [[array lastObject] boolValue];
478 }
479
480 - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
481 if (![self _allowJavaScriptPanel])
482 return;
483 [self retain];
484
485 UIActionSheet *sheet = [[[UIActionSheet alloc]
486 initWithTitle:nil
487 buttons:[NSArray arrayWithObjects:UCLocalize("OK"), nil]
488 defaultButtonIndex:0
489 delegate:self
490 context:@"alert"
491 ] autorelease];
492
493 [sheet setBodyText:message];
494 [sheet popupAlertAnimated:YES];
495 }
496
497 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
498 if (![self _allowJavaScriptPanel])
499 return NO;
500 [self retain];
501
502 UIActionSheet *sheet = [[[UIActionSheet alloc]
503 initWithTitle:nil
504 buttons:[NSArray arrayWithObjects:UCLocalize("OK"), UCLocalize("CANCEL"), nil]
505 defaultButtonIndex:0
506 delegate:indirect_
507 context:@"confirm"
508 ] autorelease];
509
510 [sheet setNumberOfRows:1];
511 [sheet setBodyText:message];
512 [sheet popupAlertAnimated:YES];
513
514 NSRunLoop *loop([NSRunLoop currentRunLoop]);
515 NSDate *future([NSDate distantFuture]);
516
517 while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
518
519 NSNumber *confirm([confirm_ autorelease]);
520 confirm_ = nil;
521
522 [self autorelease];
523 return [confirm boolValue];
524 }
525
526 - (void) setAutoPopup:(BOOL)popup {
527 popup_ = popup;
528 }
529
530 - (void) setSpecial:(id)function {
531 if (special_ != nil)
532 [special_ autorelease];
533 special_ = function == nil ? nil : [function retain];
534 }
535
536 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
537 if (button_ != nil)
538 [button_ autorelease];
539 button_ = button == nil ? nil : [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:button]]] retain];
540
541 if (style_ != nil)
542 [style_ autorelease];
543 style_ = style == nil ? nil : [style retain];
544
545 if (function_ != nil)
546 [function_ autorelease];
547 function_ = function == nil ? nil : [function retain];
548
549 [self reloadButtons];
550 }
551
552 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
553 if (button_ != nil)
554 [button_ autorelease];
555 button_ = button == nil ? nil : [button retain];
556
557 if (style_ != nil)
558 [style_ autorelease];
559 style_ = style == nil ? nil : [style retain];
560
561 if (function_ != nil)
562 [function_ autorelease];
563 function_ = function == nil ? nil : [function retain];
564
565 [self reloadButtons];
566 }
567
568 - (void) setFinishHook:(id)function {
569 if (finish_ != nil)
570 [finish_ autorelease];
571 finish_ = function == nil ? nil : [function retain];
572 }
573
574 - (void) setPopupHook:(id)function {
575 if (closer_ != nil)
576 [closer_ autorelease];
577 closer_ = function == nil ? nil : [function retain];
578 }
579
580 - (void) _openMailToURL:(NSURL *)url {
581 // XXX: this makes me sad
582 #if 0
583 [[[MailToView alloc] initWithView:underlay_ delegate:self url:url] autorelease];
584 #else
585 [UIApp openURL:url];// asPanel:YES];
586 #endif
587 }
588
589 - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
590 editing_ = true;
591 }
592
593 - (void) webView:(WebView *)sender didBeginEditingFormElement:(id)element {
594 [self fixScroller];
595 }
596
597 - (void) webViewDidEndEditingFormElements:(WebView *)sender {
598 editing_ = false;
599 [self fixScroller];
600 }
601
602 - (void) webViewClose:(WebView *)sender {
603 [book_ close];
604 }
605
606 - (void) close {
607 [book_ close];
608 }
609
610 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
611 }
612
613 - (void) webView:(WebView *)sender unableToImplementPolicyWithError:(NSError *)error frame:(WebFrame *)frame {
614 NSLog(@"err:%@", error);
615 }
616
617 - (void) webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)name decisionListener:(id<WebPolicyDecisionListener>)listener {
618 #if LogBrowser
619 NSLog(@"nwa:%@", name);
620 #endif
621
622 if (NSURL *url = [request URL]) {
623 if (name == nil) unknown: {
624 if (![self getSpecial:url swap:NO]) {
625 NSString *scheme([[url scheme] lowercaseString]);
626 if ([scheme isEqualToString:@"mailto"])
627 [self _openMailToURL:url];
628 else goto use;
629 }
630 } else if ([name isEqualToString:@"_open"])
631 [delegate_ openURL:url];
632 else if ([name isEqualToString:@"_popup"]) {
633 NSString *scheme([[url scheme] lowercaseString]);
634 if ([scheme isEqualToString:@"mailto"])
635 [self _openMailToURL:url];
636 else {
637 RVBook *book([[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
638 [book setHook:indirect_];
639
640 RVPage *page([delegate_ pageForURL:url hasTag:NULL]);
641 if (page == nil) {
642 /* XXX: call createWebViewWithRequest instead? */
643
644 [self setBackButtonTitle:title_];
645
646 BrowserView *browser([[[BrowserView alloc] initWithBook:book] autorelease]);
647 [browser loadURL:url];
648 page = browser;
649 }
650
651 [book setDelegate:delegate_];
652 [page setDelegate:delegate_];
653
654 [book setPage:page];
655 [book_ pushBook:book];
656 }
657 } else goto unknown;
658
659 [listener ignore];
660 } else use:
661 [listener use];
662 }
663
664 - (void) webView:(WebView *)sender decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
665 if ([WebView canShowMIMEType:type])
666 [listener use];
667 else {
668 // XXX: handle more mime types!
669 [listener ignore];
670
671 WebView *webview([webview_ webView]);
672 if (frame == [webview mainFrame])
673 [UIApp openURL:[request URL]];
674 }
675 }
676
677 - (void) webView:(WebView *)sender decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
678 if (request == nil) ignore: {
679 [listener ignore];
680 return;
681 }
682
683 NSURL *url([request URL]);
684
685 if (url == nil) use: {
686 if (!error_ && [frame parentFrame] == nil) {
687 if (request_ != nil)
688 [request_ autorelease];
689 request_ = [request retain];
690 #if LogBrowser
691 NSLog(@"dpn:%@", request_);
692 #endif
693 }
694
695 [listener use];
696
697 WebView *webview([webview_ webView]);
698 if (frame == [webview mainFrame])
699 [self _pushPage];
700 return;
701 }
702 #if LogBrowser
703 else NSLog(@"nav:%@:%@", url, [action description]);
704 #endif
705
706 const NSArray *capability;
707
708 #if 0 // XXX:3:GSSystemCopyCapability
709 capability = reinterpret_cast<const NSArray *>(GSSystemGetCapability(kGSDisplayIdentifiersCapability));
710 #else
711 capability = nil;
712 #endif
713
714 if (capability != nil && (
715 [capability containsObject:@"com.apple.Maps"] && [url mapsURL] ||
716 [capability containsObject:@"com.apple.youtube"] && [url youTubeURL]
717 )) {
718 open:
719 [UIApp openURL:url];
720 goto ignore;
721 }
722
723 int store(_not(int));
724 if (NSURL *itms = [url itmsURL:&store]) {
725 #if LogBrowser
726 NSLog(@"itms#%@#%u#%@", url, store, itms);
727 #endif
728
729 if (capability != nil && (
730 store == 1 && [capability containsObject:@"com.apple.MobileStore"] ||
731 store == 2 && [capability containsObject:@"com.apple.AppStore"]
732 )) {
733 url = itms;
734 goto open;
735 }
736 }
737
738 NSString *scheme([[url scheme] lowercaseString]);
739
740 if ([scheme isEqualToString:@"tel"]) {
741 // XXX: intelligence
742 goto open;
743 }
744
745 if ([scheme isEqualToString:@"mailto"]) {
746 [self _openMailToURL:url];
747 goto ignore;
748 }
749
750 if ([self getSpecial:url swap:YES])
751 goto ignore;
752 else if ([WebView _canHandleRequest:request])
753 goto use;
754 else if ([url isSpringboardHandledURL])
755 goto open;
756 else
757 goto use;
758 }
759
760 - (void) webView:(WebView *)sender setStatusText:(NSString *)text {
761 //lprintf("Status:%s\n", [text UTF8String]);
762 }
763
764 - (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
765 NSString *context([sheet context]);
766
767 if ([context isEqualToString:@"alert"]) {
768 [self autorelease];
769 [sheet dismiss];
770 } else if ([context isEqualToString:@"confirm"]) {
771 switch (button) {
772 case 1:
773 confirm_ = [NSNumber numberWithBool:YES];
774 break;
775
776 case 2:
777 confirm_ = [NSNumber numberWithBool:NO];
778 break;
779 }
780
781 [sheet dismiss];
782 } else if ([context isEqualToString:@"sensitive"]) {
783 switch (button) {
784 case 1:
785 sensitive_ = [NSNumber numberWithBool:YES];
786 break;
787
788 case 2:
789 sensitive_ = [NSNumber numberWithBool:NO];
790 break;
791 }
792
793 [sheet dismiss];
794 } else if ([context isEqualToString:@"challenge"]) {
795 id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
796
797 switch (button) {
798 case 1: {
799 NSString *username([[sheet textFieldAtIndex:0] text]);
800 NSString *password([[sheet textFieldAtIndex:1] text]);
801
802 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
803
804 [sender useCredential:credential forAuthenticationChallenge:challenge_];
805 } break;
806
807 case 2:
808 [sender cancelAuthenticationChallenge:challenge_];
809 break;
810
811 default:
812 _assert(false);
813 }
814
815 [challenge_ release];
816 challenge_ = nil;
817
818 [sheet dismiss];
819 } else if ([context isEqualToString:@"submit"]) {
820 switch (button) {
821 case 1:
822 break;
823
824 case 2:
825 if (request_ != nil) {
826 WebThreadLock();
827 [webview_ loadRequest:request_];
828 WebThreadUnlock();
829 }
830 break;
831
832 default:
833 _assert(false);
834 }
835
836 [sheet dismiss];
837 }
838 }
839
840 - (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
841 challenge_ = [challenge retain];
842
843 NSURLProtectionSpace *space([challenge protectionSpace]);
844 NSString *realm([space realm]);
845 if (realm == nil)
846 realm = @"";
847
848 UIActionSheet *sheet = [[[UIActionSheet alloc]
849 initWithTitle:realm
850 buttons:[NSArray arrayWithObjects:UCLocalize("LOGIN"), UCLocalize("CANCEL"), nil]
851 defaultButtonIndex:0
852 delegate:self
853 context:@"challenge"
854 ] autorelease];
855
856 [sheet setNumberOfRows:1];
857
858 [sheet addTextFieldWithValue:@"" label:UCLocalize("USERNAME")];
859 [sheet addTextFieldWithValue:@"" label:UCLocalize("PASSWORD")];
860
861 UITextField *username([sheet textFieldAtIndex:0]); {
862 UITextInputTraits *traits([username textInputTraits]);
863 [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
864 [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
865 [traits setKeyboardType:UIKeyboardTypeASCIICapable];
866 [traits setReturnKeyType:UIReturnKeyNext];
867 }
868
869 UITextField *password([sheet textFieldAtIndex:1]); {
870 UITextInputTraits *traits([password textInputTraits]);
871 [traits setAutocapitalizationType:UITextAutocapitalizationTypeNone];
872 [traits setAutocorrectionType:UITextAutocorrectionTypeNo];
873 [traits setKeyboardType:UIKeyboardTypeASCIICapable];
874 // XXX: UIReturnKeyDone
875 [traits setReturnKeyType:UIReturnKeyNext];
876 [traits setSecureTextEntry:YES];
877 }
878
879 [sheet popupAlertAnimated:YES];
880 }
881
882 - (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
883 return request;
884 }
885
886 - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request windowFeatures:(NSDictionary *)features {
887 //- (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request userGesture:(BOOL)gesture {
888 #if LogBrowser
889 NSLog(@"cwv:%@ (%@): %@", request, title_, features == nil ? @"{}" : [features description]);
890 //NSLog(@"cwv:%@ (%@): %@", request, title_, gesture ? @"Yes" : @"No");
891 #endif
892
893 NSNumber *value([features objectForKey:@"width"]);
894 float width(value == nil ? 0 : [value floatValue]);
895
896 RVBook *book(!popup_ ? book_ : [[[RVPopUpBook alloc] initWithFrame:[delegate_ popUpBounds]] autorelease]);
897
898 /* XXX: deal with cydia:// pages */
899 BrowserView *browser([[[BrowserView alloc] initWithBook:book forWidth:width] autorelease]);
900
901 if (features != nil && popup_) {
902 [book setDelegate:delegate_];
903 [book setHook:indirect_];
904 [browser setDelegate:delegate_];
905
906 [browser loadRequest:request];
907
908 [book setPage:browser];
909 [book_ pushBook:book];
910 } else if (request == nil) {
911 [self setBackButtonTitle:title_];
912 [browser setDelegate:delegate_];
913 [browser retain];
914 } else {
915 [self pushPage:browser];
916 [browser loadRequest:request];
917 }
918
919 return [browser webView];
920 }
921
922 - (WebView *) webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request {
923 return [self webView:sender createWebViewWithRequest:request windowFeatures:nil];
924 //return [self webView:sender createWebViewWithRequest:request userGesture:YES];
925 }
926
927 - (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
928 if ([frame parentFrame] != nil)
929 return;
930
931 title_ = [title retain];
932 [book_ reloadTitleForPage:self];
933 }
934
935 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
936 if ([loading_ count] == 0)
937 [self retain];
938 [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
939
940 if ([frame parentFrame] == nil) {
941 [webview_ resignFirstResponder];
942
943 reloading_ = false;
944
945 if (title_ != nil) {
946 [title_ release];
947 title_ = nil;
948 }
949
950 if (button_ != nil) {
951 [button_ release];
952 button_ = nil;
953 }
954
955 if (style_ != nil) {
956 [style_ release];
957 style_ = nil;
958 }
959
960 if (function_ != nil) {
961 [function_ release];
962 function_ = nil;
963 }
964
965 if (finish_ != nil) {
966 [finish_ release];
967 finish_ = nil;
968 }
969
970 if (closer_ != nil) {
971 [closer_ release];
972 closer_ = nil;
973 }
974
975 if (special_ != nil) {
976 [special_ release];
977 special_ = nil;
978 }
979
980 [book_ reloadTitleForPage:self];
981
982 [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
983
984 if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)])
985 [scroller_ setZoomScale:1 duration:0];
986 else if ([scroller_ respondsToSelector:@selector(_setZoomScale:duration:)])
987 [scroller_ _setZoomScale:1 duration:0];
988 /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
989 [scroller_ setZoomScale:1 animated:NO];*/
990
991 CGRect webrect = [scroller_ bounds];
992 webrect.size.height = 0;
993 [webview_ setFrame:webrect];
994 }
995
996 [self reloadButtons];
997 }
998
999 - (void) _finishLoading {
1000 size_t count([loading_ count]);
1001 if (count == 0)
1002 [self autorelease];
1003 if (reloading_ || count != 0)
1004 return;
1005 if (finish_ != nil)
1006 [self callFunction:finish_];
1007 [self reloadButtons];
1008 }
1009
1010 - (bool) isLoading {
1011 return [loading_ count] != 0;
1012 }
1013
1014 - (void) reloadButtons {
1015 if ([self isLoading])
1016 [indicator_ startAnimation];
1017 else
1018 [indicator_ stopAnimation];
1019 [super reloadButtons];
1020 }
1021
1022 - (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
1023 return [webview_ webView:sender shouldScrollToPoint:point forFrame:frame];
1024 }
1025
1026 - (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame {
1027 return [webview_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
1028 }
1029
1030 - (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame {
1031 return [webview_ webView:sender needsScrollNotifications:notifications forFrame:frame];
1032 }
1033
1034 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
1035 [self _pushPage];
1036 return [webview_ webView:sender didCommitLoadForFrame:frame];
1037 }
1038
1039 - (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame {
1040 return [webview_ webView:sender didReceiveDocTypeForFrame:frame];
1041 }
1042
1043 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
1044 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
1045 [self _finishLoading];
1046
1047 if ([frame parentFrame] == nil) {
1048 if (DOMDocument *document = [frame DOMDocument])
1049 if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"])
1050 for (DOMHTMLBodyElement *body in bodies) {
1051 DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
1052
1053 bool colored(false);
1054
1055 if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) {
1056 if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
1057 DOMRGBColor *rgb([color getRGBColorValue]);
1058
1059 float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
1060 float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
1061 float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
1062 float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
1063
1064 UIColor *uic(nil);
1065
1066 if (red == 0xc7 && green == 0xce && blue == 0xd5)
1067 uic = [UIColor pinStripeColor];
1068 else if (alpha != 0)
1069 uic = [UIColor
1070 colorWithRed:(red / 255)
1071 green:(green / 255)
1072 blue:(blue / 255)
1073 alpha:alpha
1074 ];
1075
1076 if (uic != nil) {
1077 colored = true;
1078 [scroller_ setBackgroundColor:uic];
1079 }
1080 }
1081 }
1082
1083 if (!colored)
1084 [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
1085 break;
1086 }
1087 }
1088
1089 return [webview_ webView:sender didFinishLoadForFrame:frame];
1090 }
1091
1092 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
1093 if ([frame parentFrame] == nil)
1094 [self autorelease];
1095
1096 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
1097 [self _finishLoading];
1098
1099 if (reloading_)
1100 return;
1101
1102 if ([frame parentFrame] == nil) {
1103 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
1104 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
1105 [[error localizedDescription] stringByAddingPercentEscapes]
1106 ]]];
1107
1108 error_ = true;
1109 }
1110 }
1111
1112 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
1113 [self _didFailWithError:error forFrame:frame];
1114 }
1115
1116 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
1117 [self _didFailWithError:error forFrame:frame];
1118 }
1119
1120 - (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
1121 #if LogBrowser || ForSaurik
1122 lprintf("Console:%s\n", [[dictionary description] UTF8String]);
1123 #endif
1124 }
1125
1126 /* XXX: fix this stupid include file
1127 - (void) webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)database {
1128 [origin setQuota:0x500000];
1129 }*/
1130
1131 - (void) _setTileDrawingEnabled:(BOOL)enabled {
1132 //[webview_ setTileDrawingEnabled:enabled];
1133 }
1134
1135 - (void) setViewportWidth:(float)width {
1136 width_ = width ? width != 0 : [[self class] defaultWidth];
1137 [webview_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
1138 }
1139
1140 - (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
1141 [self _setTileDrawingEnabled:NO];
1142 }
1143
1144 - (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
1145 [self _setTileDrawingEnabled:YES];
1146 [webview_ redrawScaledDocument];
1147 }
1148
1149 - (void) scrollerWillStartDragging:(UIScroller *)scroller {
1150 [self _setTileDrawingEnabled:NO];
1151 }
1152
1153 - (void) scrollerDidEndDragging:(UIScroller *)scroller willSmoothScroll:(BOOL)smooth {
1154 [self _setTileDrawingEnabled:YES];
1155 }
1156
1157 - (void) scrollerDidEndDragging:(UIScroller *)scroller {
1158 [self _setTileDrawingEnabled:YES];
1159 }
1160
1161 - (id) initWithBook:(RVBook *)book forWidth:(float)width {
1162 if ((self = [super initWithBook:book]) != nil) {
1163 loading_ = [[NSMutableSet alloc] initWithCapacity:3];
1164 popup_ = false;
1165
1166 struct CGRect bounds = [self bounds];
1167
1168 scroller_ = [[UIScroller alloc] initWithFrame:bounds];
1169 [self addSubview:scroller_];
1170
1171 [scroller_ setFixedBackgroundPattern:YES];
1172 [scroller_ setBackgroundColor:[UIColor pinStripeColor]];
1173
1174 [scroller_ setScrollingEnabled:YES];
1175 [scroller_ setClipsSubviews:YES];
1176 [scroller_ setAllowsRubberBanding:YES];
1177
1178 [scroller_ setDelegate:self];
1179 [scroller_ setBounces:YES];
1180 [scroller_ setScrollHysteresis:8];
1181 [scroller_ setThumbDetectionEnabled:NO];
1182 [scroller_ setDirectionalScrolling:YES];
1183 [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */
1184 [scroller_ setEventMode:YES];
1185 [scroller_ setShowBackgroundShadow:NO]; /* YES */
1186 [scroller_ setAllowsRubberBanding:YES]; /* Vertical */
1187 [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
1188
1189 CGRect webrect = [scroller_ bounds];
1190 webrect.size.height = 0;
1191
1192 WebView *webview;
1193
1194 WebThreadLock();
1195
1196 #if RecycleWebViews
1197 webview_ = [Documents_ lastObject];
1198 if (webview_ != nil) {
1199 webview_ = [webview_ retain];
1200 webview = [webview_ webView];
1201 [Documents_ removeLastObject];
1202 [webview_ setFrame:webrect];
1203 } else {
1204 #else
1205 if (true) {
1206 #endif
1207 webview_ = [[UIWebDocumentView alloc] initWithFrame:webrect];
1208 webview = [webview_ webView];
1209
1210 // XXX: this is terribly (too?) expensive
1211 //[webview_ setDrawsBackground:NO];
1212 [webview setPreferencesIdentifier:@"Cydia"];
1213
1214 [webview_ setTileSize:CGSizeMake(webrect.size.width, 500)];
1215
1216 [webview_ setAllowsMessaging:YES];
1217
1218 [webview_ setTilingEnabled:YES];
1219 [webview_ setDrawsGrid:NO];
1220 [webview_ setLogsTilingChanges:NO];
1221 [webview_ setTileMinificationFilter:kCAFilterNearest];
1222 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
1223 /* XXX: abstractify */
1224 [webview_ setDataDetectorTypes:0x80000000];
1225 else
1226 [webview_ setDetectsPhoneNumbers:NO];
1227 [webview_ setAutoresizes:YES];
1228
1229 [webview_ setMinimumScale:0.25f forDocumentTypes:0x10];
1230 [webview_ setMaximumScale:5.00f forDocumentTypes:0x10];
1231 [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
1232 //[webview_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
1233
1234 [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
1235
1236 [webview_ setMinimumScale:1.00f forDocumentTypes:0x8];
1237 [webview_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
1238 [webview_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
1239
1240 [webview_ _setDocumentType:0x4];
1241
1242 if ([webview_ respondsToSelector:@selector(UIWebDocumentView:)])
1243 [webview_ setZoomsFocusedFormControl:YES];
1244 [webview_ setContentsPosition:7];
1245 [webview_ setEnabledGestures:0xa];
1246 [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
1247 [webview_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
1248
1249 [webview_ setSmoothsFonts:YES];
1250 [webview_ setAllowsImageSheet:YES];
1251 [webview _setUsesLoaderCache:YES];
1252
1253 [webview setGroupName:@"CydiaGroup"];
1254 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
1255 [webview _setLayoutInterval:0];
1256 }
1257
1258 [self setViewportWidth:width];
1259
1260 [webview_ setDelegate:self];
1261 [webview_ setGestureDelegate:self];
1262 [webview_ setFormEditingDelegate:self];
1263 [webview_ setInteractionDelegate:self];
1264
1265 [scroller_ addSubview:webview_];
1266
1267 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
1268
1269 indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
1270
1271 [webview setFrameLoadDelegate:indirect_];
1272 [webview setResourceLoadDelegate:indirect_];
1273 [webview setUIDelegate:indirect_];
1274 [webview setScriptDebugDelegate:indirect_];
1275 [webview setPolicyDelegate:indirect_];
1276
1277 WebThreadUnlock();
1278
1279 CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
1280 indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
1281 [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
1282
1283 [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
1284 [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
1285
1286 /*UIWebView *test([[[UIWebView alloc] initWithFrame:[self bounds]] autorelease]);
1287 [test loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.saurik.com/"]]];
1288 [self addSubview:test];*/
1289 } return self;
1290 }
1291
1292 - (id) initWithBook:(RVBook *)book {
1293 return [self initWithBook:book forWidth:0];
1294 }
1295
1296 - (NSString *) stringByEvaluatingJavaScriptFromString:(NSString *)script {
1297 WebThreadLock();
1298 WebView *webview([webview_ webView]);
1299 NSString *string([webview stringByEvaluatingJavaScriptFromString:script]);
1300 WebThreadUnlock();
1301 return string;
1302 }
1303
1304 - (void) callFunction:(WebScriptObject *)function {
1305 WebThreadLock();
1306
1307 WebView *webview([webview_ webView]);
1308 WebFrame *frame([webview mainFrame]);
1309
1310 id _private(MSHookIvar<id>(webview, "_private"));
1311 WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
1312 WebCore::Settings *settings(page == NULL ? NULL : page->settings());
1313
1314 bool no;
1315 if (settings == NULL)
1316 no = 0;
1317 else {
1318 no = settings->JavaScriptCanOpenWindowsAutomatically();
1319 settings->setJavaScriptCanOpenWindowsAutomatically(true);
1320 }
1321
1322 if (UIWindow *window = [self window])
1323 if (UIResponder *responder = [window firstResponder])
1324 [responder resignFirstResponder];
1325
1326 JSObjectRef object([function JSObject]);
1327 JSGlobalContextRef context([frame globalContext]);
1328 JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
1329
1330 if (settings != NULL)
1331 settings->setJavaScriptCanOpenWindowsAutomatically(no);
1332
1333 WebThreadUnlock();
1334 }
1335
1336 - (void) didCloseBook:(RVBook *)book {
1337 if (closer_ != nil)
1338 [self callFunction:closer_];
1339 }
1340
1341 - (void) __rightButtonClicked {
1342 reloading_ = true;
1343 [self reloadURL];
1344 }
1345
1346 - (void) _rightButtonClicked {
1347 #if !AlwaysReload
1348 if (function_ != nil)
1349 [self callFunction:function_];
1350 else
1351 #endif
1352 [self __rightButtonClicked];
1353 }
1354
1355 - (id) _rightButtonTitle {
1356 return UCLocalize("RELOAD");
1357 }
1358
1359 - (id) rightButtonTitle {
1360 return [self isLoading] ? @"" : button_ != nil ? button_ : [self _rightButtonTitle];
1361 }
1362
1363 - (UINavigationButtonStyle) rightButtonStyle {
1364 if (style_ == nil) normal:
1365 return UINavigationButtonStyleNormal;
1366 else if ([style_ isEqualToString:@"Normal"])
1367 return UINavigationButtonStyleNormal;
1368 else if ([style_ isEqualToString:@"Back"])
1369 return UINavigationButtonStyleBack;
1370 else if ([style_ isEqualToString:@"Highlighted"])
1371 return UINavigationButtonStyleHighlighted;
1372 else if ([style_ isEqualToString:@"Destructive"])
1373 return UINavigationButtonStyleDestructive;
1374 else goto normal;
1375 }
1376
1377 - (NSString *) title {
1378 return title_ == nil ? UCLocalize("LOADING") : title_;
1379 }
1380
1381 - (NSString *) backButtonTitle {
1382 return UCLocalize("BROWSER");
1383 }
1384
1385 - (void) setPageActive:(BOOL)active {
1386 if (!active)
1387 [indicator_ removeFromSuperview];
1388 else
1389 [[book_ navigationBar] addSubview:indicator_];
1390 }
1391
1392 - (void) resetViewAnimated:(BOOL)animated {
1393 }
1394
1395 - (void) setPushed:(bool)pushed {
1396 pushed_ = pushed;
1397 }
1398
1399 + (float) defaultWidth {
1400 return 980;
1401 }
1402
1403 @end