1 /* CydgetScript - open-source IntelliDial replacement
2 * Copyright (C) 2009 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
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
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.
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.
38 #include <substrate.h>
40 #import <GraphicsServices/GraphicsServices.h>
41 #import <UIKit/UIKit.h>
42 #import <AddressBook/AddressBook.h>
44 #import <SpringBoardUI/SBAwayViewPluginController.h>
45 #import <TelephonyUI/TPBottomLockBar.h>
47 #import <QuartzCore/CALayer.h>
48 // XXX: fix the minimum requirement
49 extern NSString * const kCAFilterNearest;
51 #include <WebKit/DOMCSSPrimitiveValue.h>
52 #include <WebKit/DOMCSSStyleDeclaration.h>
53 #include <WebKit/DOMDocument.h>
54 #include <WebKit/DOMHTMLBodyElement.h>
55 #include <WebKit/DOMNodeList.h>
56 #include <WebKit/DOMRGBColor.h>
58 #include <WebKit/WebFrame.h>
59 #include <WebKit/WebPolicyDelegate.h>
60 #include <WebKit/WebPreferences.h>
61 #include <WebKit/WebScriptObject.h>
63 #import <WebKit/WebView.h>
64 #import <WebKit/WebView-WebPrivate.h>
66 #include <WebCore/Page.h>
67 #include <WebCore/Settings.h>
69 #include <WebCore/WebCoreThread.h>
70 #include <WebKit/WebPreferences-WebPrivate.h>
73 #include "JSGlobalData.h"
75 @interface WebView (UICaboodle)
76 - (void) setScriptDebugDelegate:(id)delegate;
77 - (void) _setFormDelegate:(id)delegate;
78 - (void) _setUIKitDelegate:(id)delegate;
79 - (void) setWebMailDelegate:(id)delegate;
80 - (void) _setLayoutInterval:(float)interval;
84 #define _forever for (;;)
86 _disused static unsigned trace_;
88 #define _trace() do { \
89 NSLog(@"_trace(%u)@%s:%u[%s]\n", \
90 trace_++, __FILE__, __LINE__, __FUNCTION__\
94 @protocol CydgetController
95 - (NSDictionary *) currentConfiguration;
98 static void (*CYSetupContext)(JSGlobalContextRef);
100 static Class $CydgetController(objc_getClass("CydgetController"));
102 @interface NSString (UIKit)
103 - (NSString *) stringByAddingPercentEscapes;
106 @implementation UIWebDocumentView (WebCycript)
108 - (void) _setScrollerOffset:(CGPoint)offset {
109 UIScroller *scroller([self _scroller]);
111 CGSize size([scroller contentSize]);
112 CGSize bounds([scroller bounds].size);
115 max.x = size.width - bounds.width;
116 max.y = size.height - bounds.height;
124 offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x;
125 offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y;
127 [scroller setOffset:offset];
132 /* WebCycript Delegate {{{ */
133 @interface WebCycriptDelegate : NSObject {
134 _transient volatile id delegate_;
137 - (void) setDelegate:(id)delegate;
138 - (id) initWithDelegate:(id)delegate;
141 @implementation WebCycriptDelegate
143 - (void) setDelegate:(id)delegate {
144 delegate_ = delegate;
147 - (id) initWithDelegate:(id)delegate {
148 delegate_ = delegate;
152 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
153 if (delegate_ != nil)
154 return [delegate_ webView:sender didClearWindowObject:window forFrame:frame];
157 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
158 if (delegate_ != nil)
159 return [delegate_ webView:sender didCommitLoadForFrame:frame];
162 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
163 if (delegate_ != nil)
164 return [delegate_ webView:sender didFailLoadWithError:error forFrame:frame];
167 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
168 if (delegate_ != nil)
169 return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame];
172 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
173 if (delegate_ != nil)
174 return [delegate_ webView:sender didFinishLoadForFrame:frame];
177 /*- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
178 if (delegate_ != nil)
179 return [delegate_ webView:sender didReceiveTitle:title forFrame:frame];
182 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
183 if (delegate_ != nil)
184 return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame];
187 /*- (void) webView:(WebView *)sender resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source {
188 if (delegate_ != nil)
189 return [delegate_ webView:sender resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source];
192 /*- (NSURLRequest *) webView:(WebView *)sender resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse fromDataSource:(WebDataSource *)source {
193 if (delegate_ != nil)
194 return [delegate_ webView:sender resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:source];
198 - (IMP) methodForSelector:(SEL)sel {
199 if (IMP method = [super methodForSelector:sel])
201 fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
205 - (BOOL) respondsToSelector:(SEL)sel {
206 if ([super respondsToSelector:sel])
208 // XXX: WebThreadCreateNSInvocation returns nil
209 //fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
210 return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
213 - (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
214 if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
216 //fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
217 if (delegate_ != nil)
218 if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
220 // XXX: I fucking hate Apple so very very bad
221 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
224 - (void) forwardInvocation:(NSInvocation *)inv {
225 SEL sel = [inv selector];
226 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
227 [inv invokeWithTarget:delegate_];
233 @interface WebCydgetLockScreenView : UIView {
234 WebCycriptDelegate *indirect_;
235 UIProgressIndicator *indicator_;
236 UIScroller *scroller_;
237 UIWebDocumentView *document_;
248 NSMutableSet *loading_;
255 @implementation WebCydgetLockScreenView
257 //#include "UICaboodle/UCInternal.h"
262 WebView *webview([document_ webView]);
263 [webview setFrameLoadDelegate:nil];
264 [webview setResourceLoadDelegate:nil];
265 [webview setUIDelegate:nil];
266 [webview setScriptDebugDelegate:nil];
267 [webview setPolicyDelegate:nil];
269 /* XXX: these are set by UIWebDocumentView
270 [webview setDownloadDelegate:nil];
271 [webview _setFormDelegate:nil];
272 [webview _setUIKitDelegate:nil];
273 [webview setEditingDelegate:nil];*/
275 /* XXX: no one sets this, ever
276 [webview setWebMailDelegate:nil];*/
278 [document_ setDelegate:nil];
279 [document_ setGestureDelegate:nil];
280 [document_ setFormEditingDelegate:nil];
281 [document_ setInteractionDelegate:nil];
283 [indirect_ setDelegate:nil];
292 [scroller_ setDelegate:nil];
298 [indicator_ release];
302 + (float) defaultWidth {
306 - (void) _setTileDrawingEnabled:(BOOL)enabled {
307 //[document_ setTileDrawingEnabled:enabled];
310 - (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
311 [self _setTileDrawingEnabled:NO];
314 - (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
315 [self _setTileDrawingEnabled:YES];
316 [document_ redrawScaledDocument];
319 - (void) setViewportWidth:(float)width {
320 width_ = width != 0 ? width : [[self class] defaultWidth];
321 [document_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
324 - (void) scrollerWillStartDragging:(UIScroller *)scroller {
325 [self _setTileDrawingEnabled:NO];
328 - (void) scrollerDidEndDragging:(UIScroller *)scroller willSmoothScroll:(BOOL)smooth {
329 [self _setTileDrawingEnabled:YES];
332 - (void) scrollerDidEndDragging:(UIScroller *)scroller {
333 [self _setTileDrawingEnabled:YES];
336 - (void) loadRequest:(NSURLRequest *)request {
340 [document_ loadRequest:request];
344 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
345 [self loadRequest:[NSURLRequest
352 - (void) loadURL:(NSURL *)url {
353 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
357 CGRect frame = {{0, 0}, {320, 480}};
358 frame.size.height -= GSDefaultStatusBarHeight();
360 if ((self = [super initWithFrame:frame]) != nil) {
361 struct CGRect bounds([self bounds]);
363 scroller_ = [[UIScroller alloc] initWithFrame:bounds];
364 [self addSubview:scroller_];
366 [scroller_ setFixedBackgroundPattern:YES];
367 [scroller_ setBackgroundColor:[UIColor blackColor]];
369 [scroller_ setScrollingEnabled:YES];
370 [scroller_ setClipsSubviews:YES];
371 [scroller_ setAllowsRubberBanding:YES];
373 [scroller_ setDelegate:self];
374 [scroller_ setBounces:YES];
375 [scroller_ setScrollHysteresis:8];
376 [scroller_ setThumbDetectionEnabled:NO];
377 [scroller_ setDirectionalScrolling:YES];
378 [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */
379 [scroller_ setEventMode:YES];
380 [scroller_ setShowBackgroundShadow:NO]; /* YES */
381 [scroller_ setAllowsRubberBanding:YES]; /* Vertical */
382 [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
384 CGRect rect([scroller_ bounds]);
385 //rect.size.height = 0;
389 document_ = [[UIWebDocumentView alloc] initWithFrame:rect];
390 WebView *webview([document_ webView]);
392 [document_ setBackgroundColor:[UIColor blackColor]];
393 if ([document_ respondsToSelector:@selector(setDrawsBackground:)])
394 [document_ setDrawsBackground:NO];
395 [webview setDrawsBackground:NO];
397 [webview setPreferencesIdentifier:@"WebCycript"];
399 [document_ setTileSize:CGSizeMake(rect.size.width, 500)];
401 if ([document_ respondsToSelector:@selector(enableReachability)])
402 [document_ enableReachability];
404 [document_ setAllowsMessaging:YES];
406 if ([document_ respondsToSelector:@selector(useSelectionAssistantWithMode:)])
407 [document_ useSelectionAssistantWithMode:0];
409 [document_ setTilingEnabled:YES];
410 [document_ setDrawsGrid:NO];
411 [document_ setLogsTilingChanges:NO];
412 [document_ setTileMinificationFilter:kCAFilterNearest];
414 if ([document_ respondsToSelector:@selector(setDataDetectorTypes:)])
415 /* XXX: abstractify */
416 [document_ setDataDetectorTypes:0x80000000];
418 [document_ setDetectsPhoneNumbers:NO];
420 [document_ setAutoresizes:YES];
422 [document_ setMinimumScale:0.25f forDocumentTypes:0x10];
423 [document_ setMaximumScale:5.00f forDocumentTypes:0x10];
424 [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
425 //[document_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
427 [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
429 [document_ setMinimumScale:1.00f forDocumentTypes:0x8];
430 [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
431 [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
433 [document_ _setDocumentType:0x4];
435 if ([document_ respondsToSelector:@selector(setZoomsFocusedFormControl:)])
436 [document_ setZoomsFocusedFormControl:YES];
437 [document_ setContentsPosition:7];
438 [document_ setEnabledGestures:0xa];
439 [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
440 [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
442 [document_ setSmoothsFonts:YES];
443 [document_ setAllowsImageSheet:YES];
444 [webview _setUsesLoaderCache:YES];
446 [webview setGroupName:@"CydgetGroup"];
448 WebPreferences *preferences([webview preferences]);
450 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
451 [webview _setLayoutInterval:0];
453 [preferences _setLayoutInterval:0];
455 [self setViewportWidth:0];
457 [document_ setDelegate:self];
458 [document_ setGestureDelegate:self];
459 [document_ setFormEditingDelegate:self];
460 [document_ setInteractionDelegate:self];
462 [scroller_ addSubview:document_];
464 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
466 indirect_ = [[WebCycriptDelegate alloc] initWithDelegate:self];
468 [webview setFrameLoadDelegate:indirect_];
469 [webview setPolicyDelegate:indirect_];
470 [webview setResourceLoadDelegate:indirect_];
471 [webview setUIDelegate:indirect_];
473 /* XXX: do not turn this on under penalty of extreme pain */
474 [webview setScriptDebugDelegate:nil];
478 CGSize indsize([UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]);
479 indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
480 [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
482 [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
483 [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
485 NSDictionary *configuration([$CydgetController currentConfiguration]);
487 cycript_ = [[configuration objectForKey:@"Cycript"] boolValue];
489 scrollable_ = [[configuration objectForKey:@"Scrollable"] boolValue];
490 [scroller_ setScrollingEnabled:scrollable_];
492 NSString *homepage([configuration objectForKey:@"Homepage"]);
493 [self loadURL:[NSURL URLWithString:homepage]];
497 - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
500 UIActionSheet *sheet = [[[UIActionSheet alloc]
502 buttons:[NSArray arrayWithObjects:@"OK", nil]
508 [sheet setBodyText:message];
509 [sheet popupAlertAnimated:YES];
512 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
515 UIActionSheet *sheet = [[[UIActionSheet alloc]
517 buttons:[NSArray arrayWithObjects:@"OK", @"CANCEL", nil]
523 [sheet setNumberOfRows:1];
524 [sheet setBodyText:message];
525 [sheet popupAlertAnimated:YES];
527 NSRunLoop *loop([NSRunLoop currentRunLoop]);
528 NSDate *future([NSDate distantFuture]);
530 while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
532 NSNumber *confirm([confirm_ autorelease]);
536 return [confirm boolValue];
539 /* XXX: WebThreadLock? */
540 - (void) _fixScroller:(CGRect)bounds {
545 UIFormAssistant *assistant([UIFormAssistant sharedFormAssistant]);
546 CGRect peripheral([assistant peripheralFrame]);
547 extra = peripheral.size.height;
550 CGRect subrect([scroller_ frame]);
551 subrect.size.height -= [TPBottomLockBar defaultHeight];
552 subrect.size.height -= extra;
553 [scroller_ setScrollerIndicatorSubrect:subrect];
556 NSSize visible(NSMakeSize(subrect.size.width, subrect.size.height));
557 [document_ setValue:[NSValue valueWithSize:visible] forGestureAttribute:UIGestureAttributeVisibleSize];
560 size.height += extra;
561 size.height += [TPBottomLockBar defaultHeight];
562 [scroller_ setContentSize:size];
564 [scroller_ releaseRubberBandIfNecessary];
567 - (void) fixScroller {
568 CGRect bounds([document_ documentBounds]);
569 [self _fixScroller:bounds];
572 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
574 [self _fixScroller:frame];
577 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
578 [self view:sender didSetFrame:frame];
581 - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
585 - (void) webView:(WebView *)sender didBeginEditingFormElement:(id)element {
589 - (void) webViewDidEndEditingFormElements:(WebView *)sender {
594 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
595 if (cycript_ && CYSetupContext != NULL) {
596 WebView *webview([document_ webView]);
597 WebFrame *frame([webview mainFrame]);
598 JSGlobalContextRef context([frame globalContext]);
599 CYSetupContext(context);
604 return [loading_ count] != 0;
607 - (void) reloadButtons {
608 if ([self isLoading])
609 [indicator_ startAnimation];
611 [indicator_ stopAnimation];
614 - (void) _finishLoading {
615 size_t count([loading_ count]);
617 [self autorelease];*/
618 if (reloading_ || count != 0)
620 [self reloadButtons];
623 - (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
624 return [document_ webView:sender shouldScrollToPoint:point forFrame:frame];
627 - (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame {
628 return [document_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
631 - (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame {
632 return [document_ webView:sender needsScrollNotifications:notifications forFrame:frame];
635 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
636 return [document_ webView:sender didCommitLoadForFrame:frame];
639 - (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame {
640 return [document_ webView:sender didReceiveDocTypeForFrame:frame];
643 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
644 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
645 [self _finishLoading];
646 return [document_ webView:sender didFinishLoadForFrame:frame];
649 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
650 /*if ([loading_ count] == 0)
652 [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
654 if ([frame parentFrame] == nil) {
655 [document_ resignFirstResponder];
659 [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
661 if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)])
662 [scroller_ setZoomScale:1 duration:0];
663 else if ([scroller_ respondsToSelector:@selector(_setZoomScale:duration:)])
664 [scroller_ _setZoomScale:1 duration:0];
665 /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
666 [scroller_ setZoomScale:1 animated:NO];*/
668 CGRect rect([scroller_ bounds]);
669 //rect.size.height = 0;
670 [document_ setFrame:rect];
673 [self reloadButtons];
676 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
677 /*if ([frame parentFrame] == nil)
678 [self autorelease];*/
680 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
681 [self _finishLoading];
686 if ([frame parentFrame] == nil) {
687 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
688 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
689 [[error localizedDescription] stringByAddingPercentEscapes]
696 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
697 [self _didFailWithError:error forFrame:frame];
700 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
701 [self _didFailWithError:error forFrame:frame];
704 - (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
705 fprintf(stderr, "Console:%s\n", [[dictionary description] UTF8String]);
710 @interface WebCycriptLockScreenController : SBAwayViewPluginController {
715 /*extern "C" void _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(JSC::Parser *, JSC::JSGlobalData *, int *, JSC::UString *);
716 MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::Parser *_this, JSC::JSGlobalData *data, int *line, JSC::UString *message) {
717 return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, data, line, message);
720 /* Cydget:// Protocol {{{ */
721 @interface CydgetURLProtocol : NSURLProtocol {
726 @implementation CydgetURLProtocol
728 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
729 NSURL *url([request URL]);
732 NSString *scheme([[url scheme] lowercaseString]);
733 if (scheme == nil || ![scheme isEqualToString:@"cydget"])
738 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
742 - (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request {
743 id<NSURLProtocolClient> client([self client]);
745 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
747 NSData *data(UIImagePNGRepresentation(icon));
749 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
750 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
751 [client URLProtocol:self didLoadData:data];
752 [client URLProtocolDidFinishLoading:self];
756 - (void) startLoading {
757 id<NSURLProtocolClient> client([self client]);
758 NSURLRequest *request([self request]);
760 NSURL *url([request URL]);
761 NSString *href([url absoluteString]);
763 NSString *path([href substringFromIndex:9]);
764 NSRange slash([path rangeOfString:@"/"]);
767 if (slash.location == NSNotFound) {
771 command = [path substringToIndex:slash.location];
772 path = [path substringFromIndex:(slash.location + 1)];
775 if ([command isEqualToString:@"_UIImageWithName"]) {
778 path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
779 UIImage *icon(_UIImageWithName(path));
780 [self _returnPNGWithImage:icon forRequest:request];
782 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
786 - (void) stopLoading {
792 @implementation WebCycriptLockScreenController
794 + (void) initialize {
795 [NSURLProtocol registerClass:[CydgetURLProtocol class]];
796 //MSHookFunction(&_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE));
797 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
798 CYSetupContext = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CYSetupContext"));
801 + (id) rootViewController {
802 return [[[self alloc] init] autorelease];
806 [self setView:[[[WebCydgetLockScreenView alloc] init] autorelease]];