]> git.saurik.com Git - cydget.git/blob - LockScreen.mm
Checkpoint.
[cydget.git] / LockScreen.mm
1 /* CydgetScript - open-source IntelliDial replacement
2 * Copyright (C) 2009 Jay Freeman (saurik)
3 */
4
5 /*
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the
11 * above copyright notice, this list of conditions
12 * and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the
17 * distribution.
18 * 3. The name of the author may not be used to endorse
19 * or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #include <substrate.h>
39 #include <sys/sysctl.h>
40
41 #import <GraphicsServices/GraphicsServices.h>
42 #import <UIKit/UIKit.h>
43 #import <AddressBook/AddressBook.h>
44
45 #import <SpringBoardUI/SBAwayViewPluginController.h>
46 #import <TelephonyUI/TPBottomLockBar.h>
47
48 #import <QuartzCore/CALayer.h>
49 // XXX: fix the minimum requirement
50 extern NSString * const kCAFilterNearest;
51
52 #include <WebKit/DOMCSSPrimitiveValue.h>
53 #include <WebKit/DOMCSSStyleDeclaration.h>
54 #include <WebKit/DOMDocument.h>
55 #include <WebKit/DOMHTMLBodyElement.h>
56 #include <WebKit/DOMNodeList.h>
57 #include <WebKit/DOMRGBColor.h>
58
59 #include <WebKit/WebFrame.h>
60 #include <WebKit/WebPolicyDelegate.h>
61 #include <WebKit/WebPreferences.h>
62 #include <WebKit/WebScriptObject.h>
63
64 #import <WebKit/WebView.h>
65 #import <WebKit/WebView-WebPrivate.h>
66
67 #include <WebCore/Page.h>
68 #include <WebCore/Settings.h>
69
70 #include <WebCore/WebCoreThread.h>
71 #include <WebKit/WebPreferences-WebPrivate.h>
72
73 #include "JSGlobalData.h"
74 #include "SourceCode.h"
75
76 #include <apr-1/apr_pools.h>
77 #include <pcre.h>
78
79 @interface WebView (UICaboodle)
80 - (void) setScriptDebugDelegate:(id)delegate;
81 - (void) _setFormDelegate:(id)delegate;
82 - (void) _setUIKitDelegate:(id)delegate;
83 - (void) setWebMailDelegate:(id)delegate;
84 - (void) _setLayoutInterval:(float)interval;
85 @end
86
87 #define _transient
88 #define _forever for (;;)
89
90 _disused static unsigned trace_;
91
92 #define _trace() do { \
93 NSLog(@"_trace(%u)@%s:%u[%s]\n", \
94 trace_++, __FILE__, __LINE__, __FUNCTION__\
95 ); \
96 } while (false)
97
98 #define _assert(test) do \
99 if (!(test)) { \
100 fprintf(stderr, "_assert(%d:%s)@%s:%u[%s]\n", errno, #test, __FILE__, __LINE__, __FUNCTION__); \
101 exit(-1); \
102 } \
103 while (false)
104
105 #define _syscall(expr) \
106 do if ((long) (expr) != -1) \
107 break; \
108 else switch (errno) { \
109 case EINTR: \
110 continue; \
111 default: \
112 _assert(false); \
113 } while (true)
114
115 @protocol CydgetController
116 - (NSDictionary *) currentConfiguration;
117 @end
118
119 static Class $CydgetController(objc_getClass("CydgetController"));
120
121 @interface NSString (UIKit)
122 - (NSString *) stringByAddingPercentEscapes;
123 @end
124
125 @implementation UIWebDocumentView (WebCycript)
126
127 - (void) _setScrollerOffset:(CGPoint)offset {
128 UIScroller *scroller([self _scroller]);
129
130 CGSize size([scroller contentSize]);
131 CGSize bounds([scroller bounds].size);
132
133 CGPoint max;
134 max.x = size.width - bounds.width;
135 max.y = size.height - bounds.height;
136
137 // wtf Apple?!
138 if (max.x < 0)
139 max.x = 0;
140 if (max.y < 0)
141 max.y = 0;
142
143 offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x;
144 offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y;
145
146 [scroller setOffset:offset];
147 }
148
149 @end
150
151 /* Perl-Compatible RegEx {{{ */
152 class Pcre {
153 private:
154 pcre *code_;
155 pcre_extra *study_;
156 int capture_;
157 int *matches_;
158 const char *data_;
159
160 public:
161 Pcre(const char *regex, int options = 0) :
162 study_(NULL)
163 {
164 const char *error;
165 int offset;
166 code_ = pcre_compile(regex, options, &error, &offset, NULL);
167
168 if (code_ == NULL)
169 @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"*** Pcre(,): [%u] %s", offset, error] userInfo:nil];
170
171 pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_);
172 matches_ = new int[(capture_ + 1) * 3];
173 }
174
175 ~Pcre() {
176 pcre_free(code_);
177 delete matches_;
178 }
179
180 NSString *operator [](size_t match) {
181 return [[[NSString alloc] initWithBytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2]) encoding:NSUTF8StringEncoding] autorelease];
182 }
183
184 bool operator ()(NSString *data) {
185 // XXX: length is for characters, not for bytes
186 return operator ()([data UTF8String], [data length]);
187 }
188
189 bool operator ()(const char *data, size_t size) {
190 data_ = data;
191 return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
192 }
193 };
194 /* }}} */
195 /* WebCycript Delegate {{{ */
196 @interface WebCycriptDelegate : NSObject {
197 _transient volatile id delegate_;
198 }
199
200 - (void) setDelegate:(id)delegate;
201 - (id) initWithDelegate:(id)delegate;
202 @end
203
204 @implementation WebCycriptDelegate
205
206 - (void) setDelegate:(id)delegate {
207 delegate_ = delegate;
208 }
209
210 - (id) initWithDelegate:(id)delegate {
211 delegate_ = delegate;
212 return self;
213 }
214
215 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
216 if (delegate_ != nil)
217 return [delegate_ webView:sender didClearWindowObject:window forFrame:frame];
218 }
219
220 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
221 if (delegate_ != nil)
222 return [delegate_ webView:sender didCommitLoadForFrame:frame];
223 }
224
225 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
226 if (delegate_ != nil)
227 return [delegate_ webView:sender didFailLoadWithError:error forFrame:frame];
228 }
229
230 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
231 if (delegate_ != nil)
232 return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame];
233 }
234
235 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
236 if (delegate_ != nil)
237 return [delegate_ webView:sender didFinishLoadForFrame:frame];
238 }
239
240 /*- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
241 if (delegate_ != nil)
242 return [delegate_ webView:sender didReceiveTitle:title forFrame:frame];
243 }*/
244
245 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
246 if (delegate_ != nil)
247 return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame];
248 }
249
250 /*- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
251 if (delegate_ != nil)
252 return [delegate_ webView:sender resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source];
253 }*/
254
255 /*- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
256 if (delegate_ != nil)
257 return [delegate_ webView:sender resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:source];
258 return nil;
259 }*/
260
261 - (IMP) methodForSelector:(SEL)sel {
262 if (IMP method = [super methodForSelector:sel])
263 return method;
264 fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
265 return NULL;
266 }
267
268 - (BOOL) respondsToSelector:(SEL)sel {
269 if ([super respondsToSelector:sel])
270 return YES;
271 // XXX: WebThreadCreateNSInvocation returns nil
272 //fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
273 return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
274 }
275
276 - (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
277 if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
278 return method;
279 //fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
280 if (delegate_ != nil)
281 if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
282 return sig;
283 // XXX: I fucking hate Apple so very very bad
284 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
285 }
286
287 - (void) forwardInvocation:(NSInvocation *)inv {
288 SEL sel = [inv selector];
289 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
290 [inv invokeWithTarget:delegate_];
291 }
292
293 @end
294 /* }}} */
295
296 @interface WebCydgetLockScreenView : UIView {
297 WebCycriptDelegate *indirect_;
298 UIProgressIndicator *indicator_;
299 UIScroller *scroller_;
300 UIWebDocumentView *document_;
301
302 NSString *cycript_;
303 bool scrollable_;
304
305 float width_;
306 CGSize size_;
307 bool editing_;
308
309 NSNumber *confirm_;
310
311 NSMutableSet *loading_;
312 bool error_;
313 bool reloading_;
314
315 //UIKeyboard *keyboard_;
316 }
317
318 @end
319
320 @implementation WebCydgetLockScreenView
321
322 //#include "UICaboodle/UCInternal.h"
323
324 - (void) dealloc {
325 WebThreadLock();
326
327 WebView *webview([document_ webView]);
328 [webview setFrameLoadDelegate:nil];
329 [webview setResourceLoadDelegate:nil];
330 [webview setUIDelegate:nil];
331 [webview setScriptDebugDelegate:nil];
332 [webview setPolicyDelegate:nil];
333
334 /* XXX: these are set by UIWebDocumentView
335 [webview setDownloadDelegate:nil];
336 [webview _setFormDelegate:nil];
337 [webview _setUIKitDelegate:nil];
338 [webview setEditingDelegate:nil];*/
339
340 /* XXX: no one sets this, ever
341 [webview setWebMailDelegate:nil];*/
342
343 [document_ setDelegate:nil];
344 [document_ setGestureDelegate:nil];
345 [document_ setFormEditingDelegate:nil];
346 [document_ setInteractionDelegate:nil];
347
348 [indirect_ setDelegate:nil];
349
350 [webview close];
351 [document_ release];
352
353 [indirect_ release];
354
355 WebThreadUnlock();
356
357 [scroller_ setDelegate:nil];
358
359 if (confirm_ != nil)
360 [confirm_ release];
361
362 //[keyboard_ release];
363
364 [scroller_ release];
365 [indicator_ release];
366 [loading_ release];
367 [super dealloc];
368 }
369
370 + (float) defaultWidth {
371 return 980;
372 }
373
374 - (void) _setTileDrawingEnabled:(BOOL)enabled {
375 //[document_ setTileDrawingEnabled:enabled];
376 }
377
378 - (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
379 [self _setTileDrawingEnabled:NO];
380 }
381
382 - (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
383 [self _setTileDrawingEnabled:YES];
384 [document_ redrawScaledDocument];
385 }
386
387 - (void) setViewportWidth:(float)width {
388 width_ = width != 0 ? width : [[self class] defaultWidth];
389 [document_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
390 }
391
392 - (void) scrollerWillStartDragging:(UIScroller *)scroller {
393 [self _setTileDrawingEnabled:NO];
394 }
395
396 - (void) scrollerDidEndDragging:(UIScroller *)scroller willSmoothScroll:(BOOL)smooth {
397 [self _setTileDrawingEnabled:YES];
398 }
399
400 - (void) scrollerDidEndDragging:(UIScroller *)scroller {
401 [self _setTileDrawingEnabled:YES];
402 }
403
404 - (void) loadRequest:(NSURLRequest *)request {
405 error_ = false;
406
407 WebThreadLock();
408 [document_ loadRequest:request];
409 WebThreadUnlock();
410 }
411
412 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
413 [self loadRequest:[NSURLRequest
414 requestWithURL:url
415 cachePolicy:policy
416 timeoutInterval:30.0
417 ]];
418 }
419
420 - (void) loadURL:(NSURL *)url {
421 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
422 }
423
424 - (id) init {
425 CGRect frame = {{0, 0}, {320, 480}};
426 frame.size.height -= GSDefaultStatusBarHeight();
427
428 if ((self = [super initWithFrame:frame]) != nil) {
429 loading_ = [[NSMutableSet alloc] initWithCapacity:3];
430
431 struct CGRect bounds([self bounds]);
432
433 scroller_ = [[UIScroller alloc] initWithFrame:bounds];
434 [self addSubview:scroller_];
435
436 [scroller_ setFixedBackgroundPattern:YES];
437 [scroller_ setBackgroundColor:[UIColor blackColor]];
438
439 [scroller_ setScrollingEnabled:YES];
440 [scroller_ setClipsSubviews:YES];
441 [scroller_ setAllowsRubberBanding:YES];
442
443 [scroller_ setDelegate:self];
444 [scroller_ setBounces:YES];
445 [scroller_ setScrollHysteresis:8];
446 [scroller_ setThumbDetectionEnabled:NO];
447 [scroller_ setDirectionalScrolling:YES];
448 [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */
449 [scroller_ setEventMode:YES];
450 [scroller_ setShowBackgroundShadow:NO]; /* YES */
451 [scroller_ setAllowsRubberBanding:YES]; /* Vertical */
452 [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
453
454 CGRect rect([scroller_ bounds]);
455 //rect.size.height = 0;
456
457 WebThreadLock();
458
459 document_ = [[UIWebDocumentView alloc] initWithFrame:rect];
460 WebView *webview([document_ webView]);
461
462 [document_ setBackgroundColor:[UIColor blackColor]];
463 if ([document_ respondsToSelector:@selector(setDrawsBackground:)])
464 [document_ setDrawsBackground:NO];
465 [webview setDrawsBackground:NO];
466
467 [webview setPreferencesIdentifier:@"WebCycript"];
468
469 [document_ setTileSize:CGSizeMake(rect.size.width, 500)];
470
471 if ([document_ respondsToSelector:@selector(enableReachability)])
472 [document_ enableReachability];
473
474 [document_ setAllowsMessaging:YES];
475
476 if ([document_ respondsToSelector:@selector(useSelectionAssistantWithMode:)])
477 [document_ useSelectionAssistantWithMode:0];
478
479 [document_ setTilingEnabled:YES];
480 [document_ setDrawsGrid:NO];
481 [document_ setLogsTilingChanges:NO];
482 [document_ setTileMinificationFilter:kCAFilterNearest];
483
484 if ([document_ respondsToSelector:@selector(setDataDetectorTypes:)])
485 /* XXX: abstractify */
486 [document_ setDataDetectorTypes:0x80000000];
487 else
488 [document_ setDetectsPhoneNumbers:NO];
489
490 [document_ setAutoresizes:YES];
491
492 [document_ setMinimumScale:0.25f forDocumentTypes:0x10];
493 [document_ setMaximumScale:5.00f forDocumentTypes:0x10];
494 [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
495 //[document_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
496
497 [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
498
499 [document_ setMinimumScale:1.00f forDocumentTypes:0x8];
500 [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
501 [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
502
503 [document_ _setDocumentType:0x4];
504
505 if ([document_ respondsToSelector:@selector(setZoomsFocusedFormControl:)])
506 [document_ setZoomsFocusedFormControl:YES];
507 [document_ setContentsPosition:7];
508 [document_ setEnabledGestures:0xa];
509 [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
510 [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
511
512 [document_ setSmoothsFonts:YES];
513 [document_ setAllowsImageSheet:YES];
514 [webview _setUsesLoaderCache:YES];
515
516 [webview setGroupName:@"CydgetGroup"];
517
518 WebPreferences *preferences([webview preferences]);
519
520 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
521 [webview _setLayoutInterval:0];
522 else
523 [preferences _setLayoutInterval:0];
524
525 [self setViewportWidth:0];
526
527 [document_ setDelegate:self];
528 [document_ setGestureDelegate:self];
529 [document_ setFormEditingDelegate:self];
530 [document_ setInteractionDelegate:self];
531
532 [scroller_ addSubview:document_];
533
534 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
535
536 indirect_ = [[WebCycriptDelegate alloc] initWithDelegate:self];
537
538 [webview setFrameLoadDelegate:indirect_];
539 [webview setPolicyDelegate:indirect_];
540 [webview setResourceLoadDelegate:indirect_];
541 [webview setUIDelegate:indirect_];
542
543 /* XXX: do not turn this on under penalty of extreme pain */
544 [webview setScriptDebugDelegate:nil];
545
546 WebThreadUnlock();
547
548 CGSize indsize([UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]);
549 indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
550 [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
551
552 [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
553 [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
554
555 NSDictionary *configuration([$CydgetController currentConfiguration]);
556
557 cycript_ = [configuration objectForKey:@"CycriptURLs"];
558
559 scrollable_ = [[configuration objectForKey:@"Scrollable"] boolValue];
560 [scroller_ setScrollingEnabled:scrollable_];
561
562 NSString *homepage([configuration objectForKey:@"Homepage"]);
563 [self loadURL:[NSURL URLWithString:homepage]];
564
565 /*[UIKeyboard initImplementationNow];
566 CGSize keysize = [UIKeyboard defaultSize];
567 CGRect keyrect = {{0, [self bounds].size.height - 100}, keysize};
568 keyboard_ = [[UIKeyboard alloc] initWithFrame:keyrect];
569 [self addSubview:keyboard_];
570
571 [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 0, 100, 100)]];
572 [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 150, 100, 100)]];
573 [self addSubview:[[UITextView alloc] initWithFrame:CGRectMake(200, 300, 100, 100)]];*/
574 } return self;
575 }
576
577 - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
578 [self retain];
579
580 UIActionSheet *sheet = [[[UIActionSheet alloc]
581 initWithTitle:nil
582 buttons:[NSArray arrayWithObjects:@"OK", nil]
583 defaultButtonIndex:0
584 delegate:self
585 context:@"alert"
586 ] autorelease];
587
588 [sheet setBodyText:message];
589 [sheet popupAlertAnimated:YES];
590 }
591
592 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
593 [self retain];
594
595 UIActionSheet *sheet = [[[UIActionSheet alloc]
596 initWithTitle:nil
597 buttons:[NSArray arrayWithObjects:@"OK", @"CANCEL", nil]
598 defaultButtonIndex:0
599 delegate:indirect_
600 context:@"confirm"
601 ] autorelease];
602
603 [sheet setNumberOfRows:1];
604 [sheet setBodyText:message];
605 [sheet popupAlertAnimated:YES];
606
607 NSRunLoop *loop([NSRunLoop currentRunLoop]);
608 NSDate *future([NSDate distantFuture]);
609
610 while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
611
612 NSNumber *confirm([confirm_ autorelease]);
613 confirm_ = nil;
614
615 [self autorelease];
616 return [confirm boolValue];
617 }
618
619 /* XXX: WebThreadLock? */
620 - (void) _fixScroller:(CGRect)bounds {
621 float extra;
622 if (!editing_)
623 extra = 0;
624 else {
625 UIFormAssistant *assistant([UIFormAssistant sharedFormAssistant]);
626 CGRect peripheral([assistant peripheralFrame]);
627 extra = peripheral.size.height;
628 }
629
630 CGRect subrect([scroller_ frame]);
631 subrect.size.height -= [TPBottomLockBar defaultHeight];
632 subrect.size.height -= extra;
633 [scroller_ setScrollerIndicatorSubrect:subrect];
634
635 #undef NSSize
636 NSSize visible(NSMakeSize(subrect.size.width, subrect.size.height));
637 [document_ setValue:[NSValue valueWithSize:visible] forGestureAttribute:UIGestureAttributeVisibleSize];
638
639 CGSize size(size_);
640 size.height += extra;
641 size.height += [TPBottomLockBar defaultHeight];
642 [scroller_ setContentSize:size];
643
644 [scroller_ releaseRubberBandIfNecessary];
645 }
646
647 - (void) fixScroller {
648 CGRect bounds([document_ documentBounds]);
649 [self _fixScroller:bounds];
650 }
651
652 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
653 size_ = frame.size;
654 [self _fixScroller:frame];
655 }
656
657 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
658 [self view:sender didSetFrame:frame];
659 }
660
661 - (void) formAssistant:(id)sender didBeginEditingFormNode:(id)node {
662 }
663
664 - (void) formAssistant:(id)sender didEndEditingFormNode:(id)node {
665 [self fixScroller];
666 }
667
668 - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
669 editing_ = true;
670 }
671
672 - (void) webView:(WebView *)sender didBeginEditingFormElement:(id)element {
673 [self fixScroller];
674 }
675
676 - (void) webViewDidEndEditingFormElements:(WebView *)sender {
677 editing_ = false;
678 [self fixScroller];
679 }
680
681 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
682 if (cycript_ != nil)
683 if (NSString *href = [[[[frame dataSource] request] URL] absoluteString])
684 if (Pcre([cycript_ UTF8String], 0 /*XXX:PCRE_UTF8*/)(href))
685 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
686 if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CydgetSetupContext"))) {
687 WebView *webview([document_ webView]);
688 WebFrame *frame([webview mainFrame]);
689 JSGlobalContextRef context([frame globalContext]);
690 CYSetupContext(context);
691 }
692 }
693
694 - (bool) isLoading {
695 return [loading_ count] != 0;
696 }
697
698 - (void) reloadButtons {
699 if ([self isLoading]) {
700 [UIApp setNetworkActivityIndicatorVisible:YES];
701 [indicator_ startAnimation];
702 } else {
703 [UIApp setNetworkActivityIndicatorVisible:NO];
704 [indicator_ stopAnimation];
705 }
706 }
707
708 - (void) _finishLoading {
709 size_t count([loading_ count]);
710 /*if (count == 0)
711 [self autorelease];*/
712 if (reloading_ || count != 0)
713 return;
714 [self reloadButtons];
715 }
716
717 - (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
718 return [document_ webView:sender shouldScrollToPoint:point forFrame:frame];
719 }
720
721 - (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame {
722 return [document_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
723 }
724
725 - (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame {
726 return [document_ webView:sender needsScrollNotifications:notifications forFrame:frame];
727 }
728
729 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
730 return [document_ webView:sender didCommitLoadForFrame:frame];
731 }
732
733 - (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame {
734 return [document_ webView:sender didReceiveDocTypeForFrame:frame];
735 }
736
737 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
738 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
739 [self _finishLoading];
740 return [document_ webView:sender didFinishLoadForFrame:frame];
741 }
742
743 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
744 /*if ([loading_ count] == 0)
745 [self retain];*/
746 [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
747
748 if ([frame parentFrame] == nil) {
749 [document_ resignFirstResponder];
750
751 reloading_ = false;
752
753 [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
754
755 if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)])
756 [scroller_ setZoomScale:1 duration:0];
757 else if ([scroller_ respondsToSelector:@selector(_setZoomScale:duration:)])
758 [scroller_ _setZoomScale:1 duration:0];
759 /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
760 [scroller_ setZoomScale:1 animated:NO];*/
761
762 CGRect rect([scroller_ bounds]);
763 //rect.size.height = 0;
764 [document_ setFrame:rect];
765 }
766
767 [self reloadButtons];
768 }
769
770 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
771 /*if ([frame parentFrame] == nil)
772 [self autorelease];*/
773
774 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
775 [self _finishLoading];
776
777 if (reloading_)
778 return;
779
780 if ([frame parentFrame] == nil) {
781 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
782 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
783 [[error localizedDescription] stringByAddingPercentEscapes]
784 ]]];
785
786 error_ = true;
787 }
788 }
789
790 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
791 [self _didFailWithError:error forFrame:frame];
792 }
793
794 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
795 [self _didFailWithError:error forFrame:frame];
796 }
797
798 - (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
799 fprintf(stderr, "Console:%s\n", [[dictionary description] UTF8String]);
800 }
801
802 @end
803
804 @interface WebCycriptLockScreenController : SBAwayViewPluginController {
805 }
806
807 @end
808
809 #include <string>
810
811 static bool cycript_;
812 static bool jscript_;
813
814 static void SetParser(bool cycript, bool jscript) {
815 cycript_ = cycript;
816 jscript_ = jscript;
817 }
818
819 static bool GetParser0() {
820 return cycript_;
821 }
822
823 static bool GetParser1() {
824 return jscript_;
825 }
826
827 static void Cycriptify(apr_pool_t *pool, const uint16_t *&data, size_t &size) {
828 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
829 if (void (*CYParseUChar)(apr_pool_t *, const uint16_t **, size_t *) = reinterpret_cast<void (*)(apr_pool_t *, const uint16_t **, size_t *)>(dlsym(handle, "CydgetPoolParse")))
830 CYParseUChar(pool, &data, &size);
831 }
832
833 extern "C" void *_ZN3JSC7UString3Rep14nullBaseStringE __attribute__((__weak_import__));
834 extern "C" void *_ZN3JSC7UString3Rep7destroyEv __attribute__((__weak_import__));
835 extern "C" void *_ZN3JSC7UStringC1EPKti __attribute__((__weak_import__));
836 extern "C" void *_ZN3JSC7UStringC1EPKc __attribute__((__weak_import__));
837 extern "C" void *_ZNK3JSC7UString6substrEii __attribute__((__weak_import__));
838 extern "C" void *_ZN3WTF10fastMallocEm __attribute__((__weak_import__));
839 extern "C" void WTFReportAssertionFailure(const char *, int, const char *, const char *) __attribute__((__weak_import__));
840 extern "C" void *_ZN3WTF8fastFreeEPv __attribute__((__weak_import__));
841
842 bool CYWeakHell() {
843 return
844 &_ZN3JSC7UString3Rep14nullBaseStringE == NULL ||
845 &_ZN3JSC7UString3Rep7destroyEv == NULL ||
846 &_ZN3JSC7UStringC1EPKti == NULL ||
847 &_ZN3JSC7UStringC1EPKc == NULL ||
848 &_ZNK3JSC7UString6substrEii == NULL ||
849 &_ZN3WTF10fastMallocEm == NULL ||
850 &WTFReportAssertionFailure == NULL ||
851 &_ZN3WTF8fastFreeEPv == NULL ||
852 false;
853 }
854
855 MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::SourceCode **_this, JSC::JSGlobalData *global, int *line, JSC::UString *message) {
856 if (!GetParser0())
857 return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message);
858 else {
859 SetParser(false, true);
860
861 JSC::SourceCode *source(*_this);
862 const uint16_t *data(source->data());
863 size_t size(source->length());
864
865 apr_pool_t *pool;
866 apr_pool_create(&pool, NULL);
867
868 Cycriptify(pool, data, size);
869 source->~SourceCode();
870 new (source) JSC::SourceCode(JSC::UStringSourceProvider::create(JSC::UString(data, size), "cycript://"), 1);
871
872 apr_pool_destroy(pool);
873
874 __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message);
875 }
876 }
877
878 MSHook(void, _ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, void *_this, int start, const UChar *code, unsigned length, int *source, int *line, JSC::UString *message) {
879 if (!GetParser0())
880 return __ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE(_this, start, code, length, source, line, message);
881 else {
882 const uint16_t *data(code);
883 size_t size(length);
884
885 apr_pool_t *pool;
886 apr_pool_create(&pool, NULL);
887
888 Cycriptify(pool, data, size);
889 __ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE(_this, start, data, size, source, line, message);
890
891 apr_pool_destroy(pool);
892 }
893 }
894
895 struct State {
896 unsigned state;
897 };
898
899 MSHook(State, _ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, State state) {
900 SetParser(false, true);
901 state = __ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE(state);
902 SetParser(false, false);
903 return state;
904 }
905
906 MSHook(void, _ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, void *resource) {
907 SetParser(false, true);
908 __ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE(resource);
909 SetParser(false, false);
910 }
911
912 MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) {
913 if (!GetParser1() || mime != "text/cycript")
914 return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime);
915
916 static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL));
917 if (handle == NULL)
918 return false;
919
920 SetParser(true, true);
921 return true;
922 }
923
924 /* Cydget:// Protocol {{{ */
925 @interface CydgetURLProtocol : NSURLProtocol {
926 }
927
928 @end
929
930 @implementation CydgetURLProtocol
931
932 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
933 NSURL *url([request URL]);
934 if (url == nil)
935 return NO;
936 NSString *scheme([[url scheme] lowercaseString]);
937 if (scheme == nil || ![scheme isEqualToString:@"cydget"])
938 return NO;
939 return YES;
940 }
941
942 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
943 return request;
944 }
945
946 - (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request {
947 id<NSURLProtocolClient> client([self client]);
948 if (icon == nil)
949 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
950 else {
951 NSData *data(UIImagePNGRepresentation(icon));
952
953 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
954 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
955 [client URLProtocol:self didLoadData:data];
956 [client URLProtocolDidFinishLoading:self];
957 }
958 }
959
960 - (void) startLoading {
961 id<NSURLProtocolClient> client([self client]);
962 NSURLRequest *request([self request]);
963
964 NSURL *url([request URL]);
965 NSString *href([url absoluteString]);
966
967 NSString *path([href substringFromIndex:9]);
968 NSRange slash([path rangeOfString:@"/"]);
969
970 NSString *command;
971 if (slash.location == NSNotFound) {
972 command = path;
973 path = nil;
974 } else {
975 command = [path substringToIndex:slash.location];
976 path = [path substringFromIndex:(slash.location + 1)];
977 }
978
979 if ([command isEqualToString:@"_UIImageWithName"]) {
980 if (path == nil)
981 goto fail;
982 path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
983 UIImage *icon(_UIImageWithName(path));
984 [self _returnPNGWithImage:icon forRequest:request];
985 } else fail: {
986 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
987 }
988 }
989
990 - (void) stopLoading {
991 }
992
993 @end
994 /* }}} */
995 /* Cydget-PHP:// Protocol {{{ */
996 @interface CydgetPHPURLProtocol : NSURLProtocol {
997 pid_t pid_;
998 CFHTTPMessageRef http_;
999 NSFileHandle *handle_;
1000 }
1001
1002 @end
1003
1004 @implementation CydgetPHPURLProtocol
1005
1006 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
1007 NSURL *url([request URL]);
1008 if (url == nil)
1009 return NO;
1010 NSString *scheme([[url scheme] lowercaseString]);
1011 if (scheme == nil || ![scheme isEqualToString:@"cydget-php"])
1012 return NO;
1013 return YES;
1014 }
1015
1016 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
1017 return request;
1018 }
1019
1020 - (id) initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)response client:(id<NSURLProtocolClient>)client {
1021 if ((self = [super initWithRequest:request cachedResponse:response client:client]) != nil) {
1022 pid_ = -1;
1023 } return self;
1024 }
1025
1026 - (void) startLoading {
1027 id<NSURLProtocolClient> client([self client]);
1028 NSURLRequest *request([self request]);
1029 NSURL *url([request URL]);
1030
1031 NSString *path([url path]);
1032 if (path == nil || ![path hasSuffix:@".php"]) {
1033 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
1034 return;
1035 }
1036
1037 NSFileManager *manager([NSFileManager defaultManager]);
1038 if (![manager fileExistsAtPath:path]) {
1039 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
1040 return;
1041 }
1042
1043 int fds[2];
1044 _assert(pipe(fds) != -1);
1045
1046 _assert(pid_ == -1);
1047 pid_ = fork();
1048 if (pid_ == -1) {
1049 _assert(close(fds[0]) != -1);
1050 _assert(close(fds[1]) != -1);
1051 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
1052 return;
1053 }
1054
1055 if (pid_ == 0) {
1056 setenv("GATEWAY_INTERFACE", "CGI/1.1", true);
1057 setenv("SCRIPT_FILENAME", [path UTF8String], true);
1058 NSString *query([url query]);
1059 if (query != nil)
1060 setenv("QUERY_STRING", [query UTF8String], true);
1061
1062 _assert(dup2(fds[1], 1) != -1);
1063 _assert(close(fds[0]) != -1);
1064 _assert(close(fds[1]) != -1);
1065
1066 execl("/usr/bin/php-cgi", "php-cgi", NULL);
1067 exit(1);
1068 _assert(false);
1069 }
1070
1071 _assert(close(fds[1]) != -1);
1072
1073 _assert(http_ == NULL);
1074 http_ = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE);
1075 CFHTTPMessageAppendBytes(http_, (const uint8_t *) "HTTP/1.1 200 OK\r\n", 17);
1076
1077 _assert(handle_ == nil);
1078 handle_ = [[NSFileHandle alloc] initWithFileDescriptor:fds[0] closeOnDealloc:YES];
1079
1080 [[NSNotificationCenter defaultCenter]
1081 addObserver:self
1082 selector:@selector(onRead:)
1083 name:@"NSFileHandleReadCompletionNotification"
1084 object:handle_
1085 ];
1086
1087 [handle_ readInBackgroundAndNotify];
1088 }
1089
1090 - (void) onRead:(NSNotification *)notification {
1091 NSFileHandle *handle([notification object]);
1092
1093 NSData *data([[notification userInfo] objectForKey:NSFileHandleNotificationDataItem]);
1094
1095 if (size_t length = [data length]) {
1096 CFHTTPMessageAppendBytes(http_, reinterpret_cast<const UInt8 *>([data bytes]), length);
1097 [handle readInBackgroundAndNotify];
1098 } else {
1099 id<NSURLProtocolClient> client([self client]);
1100
1101 CFStringRef mime(CFHTTPMessageCopyHeaderFieldValue(http_, CFSTR("Content-type")));
1102 if (mime == NULL)
1103 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]];
1104 else {
1105 NSURLRequest *request([self request]);
1106
1107 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:(NSString *)mime expectedContentLength:-1 textEncodingName:nil] autorelease]);
1108 CFRelease(mime);
1109
1110 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
1111
1112 CFDataRef body(CFHTTPMessageCopyBody(http_));
1113 [client URLProtocol:self didLoadData:(NSData *)body];
1114 CFRelease(body);
1115
1116 [client URLProtocolDidFinishLoading:self];
1117 }
1118
1119 CFRelease(http_);
1120 http_ = NULL;
1121 }
1122 }
1123
1124 //[client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil]];
1125
1126 - (void) stopLoading {
1127 [[NSNotificationCenter defaultCenter] removeObserver:self];
1128 [handle_ release];
1129 handle_ = nil;
1130
1131 if (pid_ != -1) {
1132 kill(pid_, SIGTERM);
1133 int status;
1134 _syscall(waitpid(pid_, &status, 0));
1135 pid_ = -1;
1136 }
1137 }
1138
1139 @end
1140 /* }}} */
1141
1142 template <typename Type_>
1143 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1144 struct nlist &name(nl[index]);
1145 uintptr_t value(name.n_value);
1146 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1147 value |= 0x00000001;
1148 function = reinterpret_cast<Type_>(value);
1149 }
1150
1151 template <typename Type_>
1152 static void dlset(Type_ &function, const char *name) {
1153 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1154 }
1155
1156 @implementation WebCycriptLockScreenController
1157
1158 + (void) initialize {
1159 int maxproc;
1160 size_t size(sizeof(maxproc));
1161 if (sysctlbyname("kern.maxproc", &maxproc, &size, NULL, 0) == -1)
1162 NSLog(@"sysctlbyname(\"kern.maxproc\", ?)");
1163 else if (maxproc < 72) {
1164 maxproc = 72;
1165 if (sysctlbyname("kern.maxproc", NULL, NULL, &maxproc, sizeof(maxproc)) == -1)
1166 NSLog(@"sysctlbyname(\"kern.maxproc\", #)");
1167 }
1168
1169 apr_initialize();
1170
1171 [NSURLProtocol registerClass:[CydgetURLProtocol class]];
1172 [NSURLProtocol registerClass:[CydgetPHPURLProtocol class]];
1173
1174 void (*_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)(JSC::SourceCode **, JSC::JSGlobalData *, int *, JSC::UString *);
1175 dlset(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, "_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE");
1176 if (_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE != NULL)
1177 MSHookFunction(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE));
1178
1179 void (*_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE)(void *, int, const UChar *, unsigned, int *, int *, JSC::UString *);
1180 dlset(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, "_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE");
1181 if (_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE != NULL)
1182 MSHookFunction(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE, MSHake(_ZN3KJS6Parser5parseEiPKNS_5UCharEjPiS4_PNS_7UStringE));
1183
1184 struct nlist nl[4];
1185 memset(nl, 0, sizeof(nl));
1186 nl[0].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE";
1187 nl[1].n_un.n_name = (char *) "__ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE";
1188 nl[2].n_un.n_name = (char *) "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE";
1189 nlist("/System/Library/PrivateFrameworks/WebCore.framework/WebCore", nl);
1190
1191 State (*_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE)(State);
1192 nlset(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, nl, 0);
1193 MSHookFunction(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer13scriptHandlerENS0_5StateE));
1194
1195 void (*_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE)(void *);
1196 nlset(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, nl, 1);
1197 MSHookFunction(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE, MSHake(_ZN7WebCore13HTMLTokenizer14notifyFinishedEPNS_14CachedResourceE));
1198
1199 bool (*_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)(const WebCore::String &);
1200 nlset(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, nl, 2);
1201 MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE));
1202 }
1203
1204 + (id) rootViewController {
1205 return [[[self alloc] init] autorelease];
1206 }
1207
1208 - (void) loadView {
1209 [self setView:[[[WebCydgetLockScreenView alloc] init] autorelease]];
1210 }
1211
1212 @end