]> git.saurik.com Git - cydia.git/blob - UICaboodle/BrowserView.mm
b5a7b9033d8dd362d31c4e7856a2d8d3d22c7aab
[cydia.git] / UICaboodle / BrowserView.mm
1 #include <UIKit/UIKit.h>
2 #include "iPhonePrivate.h"
3
4 #include "UCPlatform.h"
5
6 #include <UICaboodle/BrowserView.h>
7 #include <UICaboodle/UCLocalize.h>
8
9 //#include <QuartzCore/CALayer.h>
10 // XXX: fix the minimum requirement
11 extern NSString * const kCAFilterNearest;
12
13 #include <WebCore/WebCoreThread.h>
14
15 #include <WebKit/WebPolicyDelegate.h>
16 #include <WebKit/WebPreferences.h>
17
18 #include <WebKit/DOMCSSPrimitiveValue.h>
19 #include <WebKit/DOMCSSStyleDeclaration.h>
20 #include <WebKit/DOMDocument.h>
21 #include <WebKit/DOMHTMLBodyElement.h>
22 #include <WebKit/DOMRGBColor.h>
23
24 //#include <WebCore/Page.h>
25 //#include <WebCore/Settings.h>
26
27 #include "substrate.h"
28
29 #define ForSaurik 0
30 #define DefaultTimeout_ 120.0
31
32 #define ShowInternals 0
33 #define LogBrowser 0
34 #define LogMessages 0
35
36 #define lprintf(args...) fprintf(stderr, args)
37
38 // WebThreadLocked {{{
39 struct WebThreadLocked {
40 _finline WebThreadLocked() {
41 WebThreadLock();
42 }
43
44 _finline ~WebThreadLocked() {
45 WebThreadUnlock();
46 }
47 };
48 // }}}
49
50 template <typename Type_>
51 static inline void CYRelease(Type_ &value) {
52 if (value != nil) {
53 [value release];
54 value = nil;
55 }
56 }
57
58 float CYScrollViewDecelerationRateNormal;
59
60 @interface WebView (Apple)
61 - (void) _setLayoutInterval:(float)interval;
62 - (void) _setAllowsMessaging:(BOOL)allows;
63 @end
64
65 @interface WebPreferences (Apple)
66 + (void) _setInitialDefaultTextEncodingToSystemEncoding;
67 - (void) _setLayoutInterval:(NSInteger)interval;
68 - (void) setOfflineWebApplicationCacheEnabled:(BOOL)enabled;
69 @end
70
71 /* Indirect Delegate {{{ */
72 @interface IndirectDelegate : NSObject <
73 HookProtocol
74 > {
75 _transient volatile id delegate_;
76 }
77
78 - (void) setDelegate:(id)delegate;
79 - (id) initWithDelegate:(id)delegate;
80 @end
81
82 @implementation IndirectDelegate
83
84 - (void) setDelegate:(id)delegate {
85 delegate_ = delegate;
86 }
87
88 - (id) initWithDelegate:(id)delegate {
89 delegate_ = delegate;
90 return self;
91 }
92
93 - (void) didDismissModalViewController {
94 if (delegate_ != nil)
95 return [delegate_ didDismissModalViewController];
96 }
97
98 - (IMP) methodForSelector:(SEL)sel {
99 if (IMP method = [super methodForSelector:sel])
100 return method;
101 fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
102 return NULL;
103 }
104
105 - (BOOL) respondsToSelector:(SEL)sel {
106 if ([super respondsToSelector:sel])
107 return YES;
108
109 // XXX: WebThreadCreateNSInvocation returns nil
110
111 #if ShowInternals
112 fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
113 #endif
114
115 return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
116 }
117
118 - (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
119 if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
120 return method;
121
122 #if ShowInternals
123 fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
124 #endif
125
126 if (delegate_ != nil)
127 if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
128 return sig;
129
130 // XXX: I fucking hate Apple so very very bad
131 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
132 }
133
134 - (void) forwardInvocation:(NSInvocation *)inv {
135 SEL sel = [inv selector];
136 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
137 [inv invokeWithTarget:delegate_];
138 }
139
140 @end
141 /* }}} */
142
143 @implementation WebScriptObject (UICaboodle)
144
145 - (NSUInteger) count {
146 id length([self valueForKey:@"length"]);
147 if ([length respondsToSelector:@selector(intValue)])
148 return [length intValue];
149 else
150 return 0;
151 }
152
153 - (id) objectAtIndex:(unsigned)index {
154 return [self webScriptValueAtIndex:index];
155 }
156
157 @end
158
159 // CYWebPolicyDecision* {{{
160 enum CYWebPolicyDecision {
161 CYWebPolicyDecisionUnknown,
162 CYWebPolicyDecisionDownload,
163 CYWebPolicyDecisionIgnore,
164 CYWebPolicyDecisionUse,
165 };
166
167 @interface CYWebPolicyDecisionMediator : NSObject <
168 WebPolicyDecisionListener
169 > {
170 id<WebPolicyDecisionListener> listener_;
171 CYWebPolicyDecision decision_;
172 }
173
174 - (id) initWithListener:(id<WebPolicyDecisionListener>)listener;
175
176 - (CYWebPolicyDecision) decision;
177 - (bool) decided;
178 - (bool) decide;
179
180 @end
181
182 @implementation CYWebPolicyDecisionMediator
183
184 - (id) initWithListener:(id<WebPolicyDecisionListener>)listener {
185 if ((self = [super init]) != nil) {
186 listener_ = listener;
187 } return self;
188 }
189
190 - (CYWebPolicyDecision) decision {
191 return decision_;
192 }
193
194 - (bool) decided {
195 return decision_ != CYWebPolicyDecisionUnknown;
196 }
197
198 - (bool) decide {
199 switch (decision_) {
200 case CYWebPolicyDecisionUnknown:
201 default:
202 NSLog(@"CYWebPolicyDecisionUnknown");
203 return false;
204
205 case CYWebPolicyDecisionDownload: [listener_ download]; break;
206 case CYWebPolicyDecisionIgnore: [listener_ ignore]; break;
207 case CYWebPolicyDecisionUse: [listener_ use]; break;
208 }
209
210 return true;
211 }
212
213 - (void) download {
214 decision_ = CYWebPolicyDecisionDownload;
215 }
216
217 - (void) ignore {
218 decision_ = CYWebPolicyDecisionIgnore;
219 }
220
221 - (void) use {
222 decision_ = CYWebPolicyDecisionUse;
223 }
224
225 @end
226 // }}}
227
228 @implementation CYWebView : UIWebView
229
230 #if ShowInternals
231 #include "UICaboodle/UCInternal.h"
232 #endif
233
234 - (id) initWithFrame:(CGRect)frame {
235 if ((self = [super initWithFrame:frame]) != nil) {
236 } return self;
237 }
238
239 - (void) dealloc {
240 [super dealloc];
241 }
242
243 - (id<CYWebViewDelegate>) delegate {
244 return (id<CYWebViewDelegate>) [super delegate];
245 }
246
247 /*- (WebView *) webView:(WebView *)view createWebViewWithRequest:(NSURLRequest *)request {
248 id<CYWebViewDelegate> delegate([self delegate]);
249 WebView *created(nil);
250 if (created == nil && [delegate respondsToSelector:@selector(webView:createWebViewWithRequest:)])
251 created = [delegate webView:view createWebViewWithRequest:request];
252 if (created == nil && [UIWebView instancesRespondToSelector:@selector(webView:createWebViewWithRequest:)])
253 created = [super webView:view createWebViewWithRequest:request];
254 return created;
255 }*/
256
257 // webView:addMessageToConsole: (X.Xx) {{{
258 static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) {
259 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
260 if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)])
261 [uiWebView webView:view addMessageToConsole:message];
262 }
263
264 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
265 id<CYWebViewDelegate> delegate([self delegate]);
266 if ([delegate respondsToSelector:@selector(webView:addMessageToConsole:)])
267 [delegate webView:view addMessageToConsole:message];
268 if ([UIWebView instancesRespondToSelector:@selector(webView:addMessageToConsole:)])
269 [super webView:view addMessageToConsole:message];
270 }
271 // }}}
272 // webView:decidePolicyForNavigationAction:request:frame:decisionListener: (2.0+) {{{
273 - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
274 id<CYWebViewDelegate> delegate([self delegate]);
275 CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]);
276 if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)])
277 [delegate webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator];
278 if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)])
279 [super webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator];
280 [mediator decide];
281 }
282 // }}}
283 // webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: (3.0+) {{{
284 static void $UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *action, NSURLRequest *request, NSString *frame, id<WebPolicyDecisionListener> listener) {
285 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
286 if ([uiWebView respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
287 [uiWebView webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:listener];
288 }
289
290 - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
291 id<CYWebViewDelegate> delegate([self delegate]);
292 CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]);
293 if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
294 [delegate webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator];
295 if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
296 [super webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator];
297 [mediator decide];
298 }
299 // }}}
300 // webView:didClearWindowObject:forFrame: (3.2+) {{{
301 static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) {
302 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
303 if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
304 [uiWebView webView:view didClearWindowObject:window forFrame:frame];
305 }
306
307 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
308 id<CYWebViewDelegate> delegate([self delegate]);
309 if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
310 [delegate webView:view didClearWindowObject:window forFrame:frame];
311 if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)])
312 [super webView:view didClearWindowObject:window forFrame:frame];
313 }
314 // }}}
315 // webView:didFailLoadWithError:forFrame: (2.0+) {{{
316 - (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
317 id<CYWebViewDelegate> delegate([self delegate]);
318 if ([delegate respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)])
319 [delegate webView:view didFailLoadWithError:error forFrame:frame];
320 if ([UIWebView instancesRespondToSelector:@selector(webView:didFailLoadWithError:forFrame:)])
321 [super webView:view didFailLoadWithError:error forFrame:frame];
322 }
323 // }}}
324 // webView:didFailProvisionalLoadWithError:forFrame: (2.0+) {{{
325 - (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
326 id<CYWebViewDelegate> delegate([self delegate]);
327 if ([delegate respondsToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)])
328 [delegate webView:view didFailProvisionalLoadWithError:error forFrame:frame];
329 if ([UIWebView instancesRespondToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)])
330 [super webView:view didFailProvisionalLoadWithError:error forFrame:frame];
331 }
332 // }}}
333 // webView:didFinishLoadForFrame: (2.0+) {{{
334 - (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame {
335 id<CYWebViewDelegate> delegate([self delegate]);
336 if ([delegate respondsToSelector:@selector(webView:didFinishLoadForFrame:)])
337 [delegate webView:view didFinishLoadForFrame:frame];
338 if ([UIWebView instancesRespondToSelector:@selector(webView:didFinishLoadForFrame:)])
339 [super webView:view didFinishLoadForFrame:frame];
340 }
341 // }}}
342 // webView:didReceiveTitle:forFrame: (3.2+) {{{
343 static void $UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSString *title, WebFrame *frame) {
344 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
345 if ([uiWebView respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)])
346 [uiWebView webView:view didReceiveTitle:title forFrame:frame];
347 }
348
349 - (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
350 id<CYWebViewDelegate> delegate([self delegate]);
351 if ([delegate respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)])
352 [delegate webView:view didReceiveTitle:title forFrame:frame];
353 if ([UIWebView instancesRespondToSelector:@selector(webView:didReceiveTitle:forFrame:)])
354 [super webView:view didReceiveTitle:title forFrame:frame];
355 }
356 // }}}
357 // webView:didStartProvisionalLoadForFrame: (2.0+) {{{
358 - (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame {
359 id<CYWebViewDelegate> delegate([self delegate]);
360 if ([delegate respondsToSelector:@selector(webView:didStartProvisionalLoadForFrame:)])
361 [delegate webView:view didStartProvisionalLoadForFrame:frame];
362 if ([UIWebView instancesRespondToSelector:@selector(webView:didStartProvisionalLoadForFrame:)])
363 [super webView:view didStartProvisionalLoadForFrame:frame];
364 }
365 // }}}
366 // webView:resource:willSendRequest:redirectResponse:fromDataSource: (3.2+) {{{
367 static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, id identifier, NSURLRequest *request, NSURLResponse *response, WebDataSource *source) {
368 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
369 if ([uiWebView respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
370 request = [uiWebView webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
371 return request;
372 }
373
374 - (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
375 id<CYWebViewDelegate> delegate([self delegate]);
376 if ([UIWebView instancesRespondToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
377 request = [super webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
378 if ([delegate respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
379 request = [delegate webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
380 return request;
381 }
382 // }}}
383 // webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: (2.1+) {{{
384 - (void) webView:(WebView *)view runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
385 id<CYWebViewDelegate> delegate([self delegate]);
386 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)])
387 if (
388 ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptAlertPanelWithMessage:initiatedByFrame:)] ||
389 [delegate webView:view shouldRunJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame]
390 )
391 [super webView:view runJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame];
392 }
393 // }}}
394 // webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame: (2.1+) {{{
395 - (BOOL) webView:(WebView *)view runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
396 id<CYWebViewDelegate> delegate([self delegate]);
397 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)])
398 if (
399 ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptConfirmPanelWithMessage:initiatedByFrame:)] ||
400 [delegate webView:view shouldRunJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame]
401 )
402 return [super webView:view runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame];
403 return NO;
404 }
405 // }}}
406 // webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame: (2.1+) {{{
407 - (NSString *) webView:(WebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
408 id<CYWebViewDelegate> delegate([self delegate]);
409 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)])
410 if (
411 ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)] ||
412 [delegate webView:view shouldRunJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame]
413 )
414 return [super webView:view runJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame];
415 return nil;
416 }
417 // }}}
418 // webViewClose: (3.2+) {{{
419 static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view) {
420 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
421 if ([uiWebView respondsToSelector:@selector(webViewClose:)])
422 [uiWebView webViewClose:view];
423 }
424
425 - (void) webViewClose:(WebView *)view {
426 id<CYWebViewDelegate> delegate([self delegate]);
427 if ([delegate respondsToSelector:@selector(webViewClose:)])
428 [delegate webViewClose:view];
429 if ([UIWebView instancesRespondToSelector:@selector(webViewClose:)])
430 [super webViewClose:view];
431 }
432 // }}}
433
434 - (void) _updateViewSettings {
435 [super _updateViewSettings];
436
437 id<CYWebViewDelegate> delegate([self delegate]);
438 if ([delegate respondsToSelector:@selector(webViewUpdateViewSettings:)])
439 [delegate webViewUpdateViewSettings:self];
440 }
441
442 + (void) initialize {
443 if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) {
444 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12");
445 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), (IMP) &$UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$, "v28@0:4@8@12@16@20@24");
446 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16");
447 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didReceiveTitle:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$, "v20@0:4@8@12@16");
448 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), (IMP) &$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$, "@28@0:4@8@12@16@20@24");
449 class_addMethod($UIWebViewWebViewDelegate, @selector(webViewClose:), (IMP) &$UIWebViewWebViewDelegate$webViewClose$, "v12@0:4@8");
450 }
451 }
452
453 @end
454
455 @implementation BrowserController
456
457 #if ShowInternals
458 #include "UICaboodle/UCInternal.h"
459 #endif
460
461 + (void) _initialize {
462 [WebPreferences _setInitialDefaultTextEncodingToSystemEncoding];
463
464 if (float *_UIScrollViewDecelerationRateNormal = reinterpret_cast<float *>(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal")))
465 CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
466 else // XXX: this actually might be fast on some older systems: we should look into this
467 CYScrollViewDecelerationRateNormal = 0.998;
468 }
469
470 - (void) dealloc {
471 #if LogBrowser
472 NSLog(@"[BrowserController dealloc]");
473 #endif
474
475 [webview_ setDelegate:nil];
476
477 [indirect_ setDelegate:nil];
478 [indirect_ release];
479
480 if (challenge_ != nil)
481 [challenge_ release];
482
483 if (request_ != nil)
484 [request_ release];
485
486 if (closer_ != nil)
487 [closer_ release];
488
489 if (title_ != nil)
490 [title_ release];
491
492 if ([loading_ count] != 0)
493 [delegate_ releaseNetworkActivityIndicator];
494 [loading_ release];
495
496 [reloaditem_ release];
497 [loadingitem_ release];
498
499 [indicator_ release];
500
501 [super dealloc];
502 }
503
504 - (void) setURL:(NSURL *)url {
505 _assert(request_ == nil);
506
507 request_ = [[NSURLRequest
508 requestWithURL:url
509 cachePolicy:NSURLRequestUseProtocolCachePolicy
510 timeoutInterval:DefaultTimeout_
511 ] retain];
512 }
513
514 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
515 [self loadRequest:[NSURLRequest
516 requestWithURL:url
517 cachePolicy:policy
518 timeoutInterval:DefaultTimeout_
519 ]];
520 }
521
522 - (void) loadURL:(NSURL *)url {
523 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
524 }
525
526 - (void) loadRequest:(NSURLRequest *)request {
527 #if LogBrowser
528 NSLog(@"loadRequest:%@", request);
529 #endif
530
531 error_ = false;
532
533 WebThreadLocked lock;
534 [webview_ loadRequest:request];
535 }
536
537 - (void) reloadURLWithCache:(BOOL)cache {
538 if (request_ == nil)
539 return;
540
541 NSMutableURLRequest *request([request_ mutableCopy]);
542 [request setCachePolicy:(cache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData)];
543
544 [request_ autorelease];
545 request_ = [request retain];
546
547 if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
548 [self loadRequest:request_];
549 else {
550 UIAlertView *alert = [[[UIAlertView alloc]
551 initWithTitle:UCLocalize("RESUBMIT_FORM")
552 message:nil
553 delegate:self
554 cancelButtonTitle:UCLocalize("CANCEL")
555 otherButtonTitles:
556 UCLocalize("SUBMIT"),
557 nil
558 ] autorelease];
559
560 [alert setContext:@"submit"];
561 [alert show];
562 }
563 }
564
565 - (void) reloadURL {
566 [self reloadURLWithCache:YES];
567 }
568
569 - (void) reloadData {
570 [super reloadData];
571 [self reloadURLWithCache:YES];
572 }
573
574 - (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
575 custom_ = button;
576 style_ = style;
577 function_ = function;
578
579 [self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
580 }
581
582 - (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
583 custom_ = button;
584 style_ = style;
585 function_ = function;
586
587
588 [self performSelectorOnMainThread:@selector(applyRightButton) withObject:nil waitUntilDone:NO];
589 }
590
591 - (void) setPopupHook:(id)function {
592 if (closer_ != nil)
593 [closer_ autorelease];
594 if (function == nil)
595 closer_ = nil;
596 else
597 closer_ = [function retain];
598 }
599
600 - (void) _setViewportWidth {
601 [[webview_ _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
602 }
603
604 - (void) setViewportWidth:(float)width {
605 width_ = width != 0 ? width : [[self class] defaultWidth];
606 [self _setViewportWidth];
607 }
608
609 - (void) _setViewportWidthOnMainThread:(NSNumber *)width {
610 [self setViewportWidth:[width floatValue]];
611 }
612
613 - (void) setViewportWidthOnMainThread:(float)width {
614 [self performSelectorOnMainThread:@selector(_setViewportWidthOnMainThread:) withObject:[NSNumber numberWithFloat:width] waitUntilDone:NO];
615 }
616
617 - (void) webViewUpdateViewSettings:(UIWebView *)view {
618 [self _setViewportWidth];
619 }
620
621 - (void) _openMailToURL:(NSURL *)url {
622 [[UIApplication sharedApplication] openURL:url];// asPanel:YES];
623 }
624
625 - (bool) _allowJavaScriptPanel {
626 return true;
627 }
628
629 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
630 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
631 [self _didFinishLoading];
632
633 if ([error code] == NSURLErrorCancelled)
634 return;
635
636 if ([frame parentFrame] == nil) {
637 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
638 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
639 [[error localizedDescription] stringByAddingPercentEscapes]
640 ]]];
641
642 error_ = true;
643 }
644 }
645
646 // CYWebViewDelegate {{{
647 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
648 #if LogMessages
649 NSLog(@"addMessageToConsole:%@", message);
650 #endif
651 }
652
653 - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
654 #if LogBrowser
655 NSLog(@"decidePolicyForNavigationAction:%@ request:%@ frame:%@", action, request, frame);
656 #endif
657
658 if ([frame parentFrame] == nil) {
659 if (!error_) {
660 if (request_ != nil)
661 [request_ autorelease];
662 if (request == nil)
663 request_ = nil;
664 else
665 request_ = [request retain];
666 }
667 }
668 }
669
670 - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
671 #if LogBrowser
672 NSLog(@"decidePolicyForNewWindowAction:%@ request:%@ newFrameName:%@", action, request, frame);
673 #endif
674
675 NSURL *url([request URL]);
676 if (url == nil)
677 return;
678
679 if ([frame isEqualToString:@"_open"])
680 [delegate_ openURL:url];
681
682 NSString *scheme([[url scheme] lowercaseString]);
683 if ([scheme isEqualToString:@"mailto"])
684 [self _openMailToURL:url];
685
686 // XXX: filter to internal usage?
687 CYViewController *page([delegate_ pageForURL:url forExternal:NO]);
688
689 if (page == nil) {
690 BrowserController *browser([[[class_ alloc] init] autorelease]);
691 [browser loadRequest:request];
692 page = browser;
693 }
694
695 [page setDelegate:delegate_];
696
697 if (![frame isEqualToString:@"_popup"]) {
698 [[self navigationItem] setTitle:title_];
699
700 [[self navigationController] pushViewController:page animated:YES];
701 } else {
702 UCNavigationController *navigation([[[UCNavigationController alloc] initWithRootViewController:page] autorelease]);
703
704 [navigation setHook:indirect_];
705 [navigation setDelegate:delegate_];
706
707 [[page navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
708 initWithTitle:UCLocalize("CLOSE")
709 style:UIBarButtonItemStylePlain
710 target:page
711 action:@selector(close)
712 ] autorelease]];
713
714 [[self navigationController] presentModalViewController:navigation animated:YES];
715 }
716
717 [listener ignore];
718 }
719
720 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
721 }
722
723 - (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
724 #if LogBrowser
725 NSLog(@"didFailLoadWithError:%@ forFrame:%@", error, frame);
726 #endif
727
728 [self _didFailWithError:error forFrame:frame];
729 }
730
731 - (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
732 #if LogBrowser
733 NSLog(@"didFailProvisionalLoadWithError:%@ forFrame:%@", error, frame);
734 #endif
735
736 [self _didFailWithError:error forFrame:frame];
737 }
738
739 - (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame {
740 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
741
742 if ([frame parentFrame] == nil) {
743 if (DOMDocument *document = [frame DOMDocument])
744 if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"])
745 for (DOMHTMLBodyElement *body in (id) bodies) {
746 DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
747
748 bool colored(false);
749
750 if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) {
751 if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
752 DOMRGBColor *rgb([color getRGBColorValue]);
753
754 float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
755 float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
756 float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
757 float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
758
759 UIColor *uic(nil);
760
761 if (red == 0xc7 && green == 0xce && blue == 0xd5)
762 uic = [UIColor groupTableViewBackgroundColor];
763 else if (alpha != 0)
764 uic = [UIColor
765 colorWithRed:(red / 255)
766 green:(green / 255)
767 blue:(blue / 255)
768 alpha:alpha
769 ];
770
771 if (uic != nil) {
772 colored = true;
773 [scroller_ setBackgroundColor:uic];
774 }
775 }
776 }
777
778 if (!colored)
779 [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
780 break;
781 }
782 }
783
784 [self _didFinishLoading];
785 }
786
787 - (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
788 if ([frame parentFrame] != nil)
789 return;
790
791 if (title_ != nil)
792 [title_ autorelease];
793 title_ = [title retain];
794
795 [[self navigationItem] setTitle:title_];
796 }
797
798 - (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame {
799 [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
800
801 if ([frame parentFrame] == nil) {
802 CYRelease(title_);
803 custom_ = nil;
804 style_ = nil;
805 function_ = nil;
806 CYRelease(closer_);
807
808 // XXX: do we still need to do this?
809 [[self navigationItem] setTitle:nil];
810 }
811
812 [self _didStartLoading];
813 }
814
815 - (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
816 #if LogBrowser
817 NSLog(@"resource:%@ willSendRequest:%@ redirectResponse:%@ fromDataSource:%@", identifier, request, response, source);
818 #endif
819
820 return request;
821 }
822
823 - (bool) webView:(WebView *)view shouldRunJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
824 return [self _allowJavaScriptPanel];
825 }
826
827 - (bool) webView:(WebView *)view shouldRunJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
828 return [self _allowJavaScriptPanel];
829 }
830
831 - (bool) webView:(WebView *)view shouldRunJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
832 return [self _allowJavaScriptPanel];
833 }
834
835 - (void) webViewClose:(WebView *)view {
836 [self close];
837 }
838 // }}}
839
840 - (void) close {
841 [[self navigationController] dismissModalViewControllerAnimated:YES];
842 }
843
844 - (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
845 NSString *context([alert context]);
846
847 if ([context isEqualToString:@"sensitive"]) {
848 switch (button) {
849 case 1:
850 sensitive_ = [NSNumber numberWithBool:YES];
851 break;
852
853 case 2:
854 sensitive_ = [NSNumber numberWithBool:NO];
855 break;
856 }
857
858 [alert dismissWithClickedButtonIndex:-1 animated:YES];
859 } else if ([context isEqualToString:@"challenge"]) {
860 id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
861
862 switch (button) {
863 case 1: {
864 NSString *username([[alert textFieldAtIndex:0] text]);
865 NSString *password([[alert textFieldAtIndex:1] text]);
866
867 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
868
869 [sender useCredential:credential forAuthenticationChallenge:challenge_];
870 } break;
871
872 case 2:
873 [sender cancelAuthenticationChallenge:challenge_];
874 break;
875
876 _nodefault
877 }
878
879 [challenge_ release];
880 challenge_ = nil;
881
882 [alert dismissWithClickedButtonIndex:-1 animated:YES];
883 } else if ([context isEqualToString:@"submit"]) {
884 if (button == [alert cancelButtonIndex]) {
885 } else if (button == [alert firstOtherButtonIndex]) {
886 if (request_ != nil) {
887 WebThreadLocked lock;
888 [webview_ loadRequest:request_];
889 }
890 }
891
892 [alert dismissWithClickedButtonIndex:-1 animated:YES];
893 }
894 }
895
896 - (UIBarButtonItemStyle) rightButtonStyle {
897 if (style_ == nil) normal:
898 return UIBarButtonItemStylePlain;
899 else if ([style_ isEqualToString:@"Normal"])
900 return UIBarButtonItemStylePlain;
901 else if ([style_ isEqualToString:@"Highlighted"])
902 return UIBarButtonItemStyleDone;
903 else goto normal;
904 }
905
906 - (UIBarButtonItem *) customButton {
907 return [[[UIBarButtonItem alloc]
908 initWithTitle:custom_
909 style:[self rightButtonStyle]
910 target:self
911 action:@selector(customButtonClicked)
912 ] autorelease];
913 }
914
915 - (UIBarButtonItem *) rightButton {
916 return reloaditem_;
917 }
918
919 - (void) applyLoadingTitle {
920 [[self navigationItem] setTitle:UCLocalize("LOADING")];
921 }
922
923 - (void) layoutRightButton {
924 [[loadingitem_ view] addSubview:indicator_];
925 [[loadingitem_ view] bringSubviewToFront:indicator_];
926 }
927
928 - (void) applyRightButton {
929 if ([self isLoading]) {
930 [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
931 [self performSelector:@selector(layoutRightButton) withObject:nil afterDelay:0];
932
933 [indicator_ startAnimating];
934 [self applyLoadingTitle];
935 } else {
936 [indicator_ stopAnimating];
937
938 [[self navigationItem] setRightBarButtonItem:(
939 custom_ != nil ? [self customButton] : [self rightButton]
940 ) animated:YES];
941 }
942 }
943
944 - (void) didStartLoading {
945 // Overridden in subclasses.
946 }
947
948 - (void) _didStartLoading {
949 [self applyRightButton];
950
951 if ([loading_ count] != 1)
952 return;
953
954 [delegate_ retainNetworkActivityIndicator];
955 [self didStartLoading];
956 }
957
958 - (void) didFinishLoading {
959 // Overridden in subclasses.
960 }
961
962 - (void) _didFinishLoading {
963 if ([loading_ count] != 0)
964 return;
965
966 [self applyRightButton];
967 [[self navigationItem] setTitle:title_];
968
969 [delegate_ releaseNetworkActivityIndicator];
970 [self didFinishLoading];
971 }
972
973 - (bool) isLoading {
974 return [loading_ count] != 0;
975 }
976
977 - (id) initWithWidth:(float)width ofClass:(Class)_class {
978 if ((self = [super init]) != nil) {
979 class_ = _class;
980 loading_ = [[NSMutableSet alloc] initWithCapacity:5];
981
982 indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
983
984 webview_ = [[[CYWebView alloc] initWithFrame:[[self view] bounds]] autorelease];
985 [webview_ setDelegate:self];
986 [self setView:webview_];
987
988 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
989 [webview_ setDataDetectorTypes:UIDataDetectorTypeAutomatic];
990 else
991 [webview_ setDetectsPhoneNumbers:NO];
992
993 [webview_ setScalesPageToFit:YES];
994
995 UIWebDocumentView *document([webview_ _documentView]);
996
997 // XXX: I think this improves scrolling; the hardcoded-ness sucks
998 [document setTileSize:CGSizeMake(320, 500)];
999
1000 [document setBackgroundColor:[UIColor clearColor]];
1001
1002 // XXX: this is terribly (too?) expensive
1003 [document setDrawsBackground:NO];
1004
1005 WebView *webview([document webView]);
1006 WebPreferences *preferences([webview preferences]);
1007
1008 // XXX: I have no clue if I actually /want/ this modification
1009 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
1010 [webview _setLayoutInterval:0];
1011 else if ([preferences respondsToSelector:@selector(_setLayoutInterval:)])
1012 [preferences _setLayoutInterval:0];
1013
1014 [preferences setCacheModel:WebCacheModelDocumentBrowser];
1015 [preferences setOfflineWebApplicationCacheEnabled:YES];
1016
1017 #if LogMessages
1018 if ([document respondsToSelector:@selector(setAllowsMessaging:)])
1019 [document setAllowsMessaging:YES];
1020 if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
1021 [webview _setAllowsMessaging:YES];
1022 #endif
1023
1024 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
1025 scroller_ = [webview_ _scrollView];
1026
1027 [scroller_ setDirectionalLockEnabled:YES];
1028 [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
1029 [scroller_ setDelaysContentTouches:NO];
1030
1031 [scroller_ setCanCancelContentTouches:YES];
1032 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
1033 UIScroller *scroller([webview_ _scroller]);
1034 scroller_ = (UIScrollView *) scroller;
1035
1036 [scroller setDirectionalScrolling:YES];
1037 // XXX: we might be better off /not/ setting this on older systems
1038 [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
1039 [scroller setScrollHysteresis:0]; /* 8 */
1040
1041 [scroller setThumbDetectionEnabled:NO];
1042
1043 // use NO with UIApplicationUseLegacyEvents(YES)
1044 [scroller setEventMode:YES];
1045
1046 // XXX: this is handled by setBounces, right?
1047 //[scroller setAllowsRubberBanding:YES];
1048 }
1049
1050 [scroller_ setFixedBackgroundPattern:YES];
1051 [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
1052 [scroller_ setClipsSubviews:YES];
1053
1054 [scroller_ setBounces:YES];
1055 [scroller_ setScrollingEnabled:YES];
1056 [scroller_ setShowBackgroundShadow:NO];
1057
1058 [self setViewportWidth:width];
1059
1060 reloaditem_ = [[UIBarButtonItem alloc]
1061 initWithTitle:UCLocalize("RELOAD")
1062 style:[self rightButtonStyle]
1063 target:self
1064 action:@selector(reloadButtonClicked)
1065 ];
1066
1067 loadingitem_ = [[UIBarButtonItem alloc]
1068 initWithTitle:@" "
1069 style:UIBarButtonItemStylePlain
1070 target:self
1071 action:@selector(reloadButtonClicked)
1072 ];
1073
1074 indicator_ = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
1075 [indicator_ setFrame:CGRectMake(15, 5, [indicator_ frame].size.width, [indicator_ frame].size.height)];
1076
1077 [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
1078 [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
1079 } return self;
1080 }
1081
1082 - (id) initWithWidth:(float)width {
1083 return [self initWithWidth:width ofClass:[self class]];
1084 }
1085
1086 - (id) init {
1087 return [self initWithWidth:0];
1088 }
1089
1090 - (id) initWithURL:(NSURL *)url {
1091 if ((self = [self init]) != nil) {
1092 [self setURL:url];
1093 } return self;
1094 }
1095
1096 - (void) didDismissModalViewController {
1097 if (closer_ != nil)
1098 [self callFunction:closer_];
1099 }
1100
1101 - (void) callFunction:(WebScriptObject *)function {
1102 WebThreadLocked lock;
1103
1104 WebView *webview([[webview_ _documentView] webView]);
1105 WebFrame *frame([webview mainFrame]);
1106 WebPreferences *preferences([webview preferences]);
1107
1108 bool maybe([preferences javaScriptCanOpenWindowsAutomatically]);
1109 [preferences setJavaScriptCanOpenWindowsAutomatically:NO];
1110
1111 /*id _private(MSHookIvar<id>(webview, "_private"));
1112 WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
1113 WebCore::Settings *settings(page == NULL ? NULL : page->settings());
1114
1115 bool no;
1116 if (settings == NULL)
1117 no = 0;
1118 else {
1119 no = settings->JavaScriptCanOpenWindowsAutomatically();
1120 settings->setJavaScriptCanOpenWindowsAutomatically(true);
1121 }*/
1122
1123 if (UIWindow *window = [[self view] window])
1124 if (UIResponder *responder = [window firstResponder])
1125 [responder resignFirstResponder];
1126
1127 JSObjectRef object([function JSObject]);
1128 JSGlobalContextRef context([frame globalContext]);
1129 JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
1130
1131 /*if (settings != NULL)
1132 settings->setJavaScriptCanOpenWindowsAutomatically(no);*/
1133
1134 [preferences setJavaScriptCanOpenWindowsAutomatically:maybe];
1135 }
1136
1137 - (void) reloadButtonClicked {
1138 [self reloadURLWithCache:YES];
1139 }
1140
1141 - (void) _customButtonClicked {
1142 [self reloadButtonClicked];
1143 }
1144
1145 - (void) customButtonClicked {
1146 #if !AlwaysReload
1147 if (function_ != nil)
1148 [self callFunction:function_];
1149 else
1150 #endif
1151 [self _customButtonClicked];
1152 }
1153
1154 + (float) defaultWidth {
1155 return 980;
1156 }
1157
1158 - (void) dispatchEvent:(NSString *)event {
1159 WebThreadLocked lock;
1160
1161 NSString *script([NSString stringWithFormat:@
1162 "(function() {"
1163 "var event = this.document.createEvent('Events');"
1164 "event.initEvent('%@', false, false);"
1165 "this.document.dispatchEvent(event);"
1166 "})();"
1167 , event]);
1168
1169 NSMutableArray *frames([NSMutableArray arrayWithObjects:
1170 [[[webview_ _documentView] webView] mainFrame]
1171 , nil]);
1172
1173 while (WebFrame *frame = [frames lastObject]) {
1174 WebScriptObject *object([frame windowObject]);
1175 [object evaluateWebScript:script];
1176 [frames removeLastObject];
1177 [frames addObjectsFromArray:[frame childFrames]];
1178 }
1179 }
1180
1181 - (void) viewWillAppear:(BOOL)animated {
1182 [self dispatchEvent:@"CydiaViewWillAppear"];
1183 [super viewWillAppear:animated];
1184 }
1185
1186 - (void) viewDidAppear:(BOOL)animated {
1187 [self dispatchEvent:@"CydiaViewDidAppear"];
1188 [super viewDidAppear:animated];
1189 }
1190
1191 - (void) viewWillDisappear:(BOOL)animated {
1192 [self dispatchEvent:@"CydiaViewWillDisappear"];
1193 [super viewWillDisappear:animated];
1194 }
1195
1196 - (void) viewDidDisappear:(BOOL)animated {
1197 [self dispatchEvent:@"CydiaViewDidDisappear"];
1198 [super viewDidDisappear:animated];
1199 }
1200
1201 @end