]> git.saurik.com Git - cydget.git/blob - LockScreen.mm
Use the new @media to rethink how legacy works.
[cydget.git] / LockScreen.mm
1 /* Cydget - open-source AwayView plugin multiplexer
2 * Copyright (C) 2009-2014 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include <CydiaSubstrate/CydiaSubstrate.h>
23 #include <UIKit/UIKit.h>
24
25 #include <sys/sysctl.h>
26 #include <pthread.h>
27
28 #include <SpringBoardUI/SBAwayViewPluginController.h>
29
30 #include <WebKit/WebFrame.h>
31 #include <WebKit/WebView.h>
32 #include <WebKit/WebPreferences-WebPrivate.h>
33
34 #include "yieldToSelector.h"
35
36 #ifdef USE_ICU_REGEX
37 #include <unicode/uregex.h>
38 #else
39 #include <pcre.h>
40 #endif
41
42 #define _transient
43 #define _forever for (;;)
44
45 _disused static unsigned trace_;
46
47 #define _trace() do { \
48 NSLog(@"_trace(%u)@%s:%u[%s](%p)\n", \
49 trace_++, __FILE__, __LINE__, __FUNCTION__, pthread_self() \
50 ); \
51 } while (false)
52
53 #define _assert(test) do \
54 if (!(test)) { \
55 NSLog(@"_assert(%d:%s)@%s:%u[%s]\n", errno, #test, __FILE__, __LINE__, __FUNCTION__); \
56 exit(-1); \
57 } \
58 while (false)
59
60 #define _syscall(expr) \
61 do if ((long) (expr) != -1) \
62 break; \
63 else switch (errno) { \
64 case EINTR: \
65 continue; \
66 default: \
67 _assert(false); \
68 } while (true)
69
70 extern "C" UIImage *_UIImageWithName(NSString *name);
71
72 typedef uint16_t UChar;
73
74 @interface TPBottomLockBar
75 - (CGFloat) defaultHeight;
76 @end
77
78 @interface UIApplication (Apple)
79 - (void) applicationOpenURL:(NSURL *)url;
80 @end
81
82 @interface UIScroller : UIView
83 - (CGSize) contentSize;
84 - (void) setDirectionalScrolling:(BOOL)directional;
85 - (void) setOffset:(CGPoint)offset;
86 - (void) setScrollDecelerationFactor:(CGFloat)factor;
87 - (void) setScrollHysteresis:(CGFloat)hysteresis;
88 - (void) setThumbDetectionEnabled:(BOOL)enabled;
89 @end
90
91 @interface UIWebDocumentView : UIView
92 - (CGRect) documentBounds;
93 - (void) enableReachability;
94 - (void) loadRequest:(NSURLRequest *)request;
95 - (void) redrawScaledDocument;
96 - (void) setAllowsImageSheet:(BOOL)allows;
97 - (void) setAllowsMessaging:(BOOL)allows;
98 - (void) setAutoresizes:(BOOL)autoresizes;
99 - (void) setContentsPosition:(NSInteger)position;
100 - (void) setDrawsBackground:(BOOL)draws;
101 - (void) _setDocumentType:(NSInteger)type;
102 - (void) setDrawsGrid:(BOOL)draws;
103 - (void) setInitialScale:(float)scale forDocumentTypes:(NSInteger)types;
104 - (void) setLogsTilingChanges:(BOOL)logs;
105 - (void) setMinimumScale:(float)scale forDocumentTypes:(NSInteger)types;
106 - (void) setMinimumSize:(CGSize)size;
107 - (void) setMaximumScale:(float)scale forDocumentTypes:(NSInteger)tpyes;
108 - (void) setSmoothsFonts:(BOOL)smooths;
109 - (void) setTileMinificationFilter:(NSString *)filter;
110 - (void) setTileSize:(CGSize)size;
111 - (void) setTilingEnabled:(BOOL)enabled;
112 - (void) setViewportSize:(CGSize)size forDocumentTypes:(NSInteger)types;
113 - (void) setZoomsFocusedFormControl:(BOOL)zooms;
114 - (void) useSelectionAssistantWithMode:(NSInteger)mode;
115 - (WebView *) webView;
116 @end
117
118 @interface UIView (Apple)
119 - (UIScroller *) _scroller;
120 - (void) setClipsSubviews:(BOOL)clips;
121 - (void) setEnabledGestures:(NSInteger)gestures;
122 - (void) setFixedBackgroundPattern:(BOOL)fixed;
123 - (void) setGestureDelegate:(id)delegate;
124 - (void) setNeedsDisplayOnBoundsChange:(BOOL)needs;
125 - (void) setValue:(NSValue *)value forGestureAttribute:(NSInteger)attribute;
126 - (void) setZoomScale:(float)scale duration:(double)duration;
127 - (void) _setZoomScale:(float)scale duration:(double)duration;
128 @end
129
130 @interface SBLockScreenView : UIView
131 - (BOOL) mediaControlsHidden;
132 @end
133
134 @interface SBLockScreenNotificationListController : NSObject
135 - (BOOL) hasAnyContent;
136 @end
137
138 @interface SBLockScreenViewController : UIViewController
139 - (SBLockScreenView *) lockScreenView;
140 - (BOOL) isShowingMediaControls;
141 - (void) _setMediaControlsVisible:(BOOL)visible;
142 - (SBLockScreenNotificationListController *) _notificationController;
143 @end
144
145 @interface SBLockScreenManager : NSObject
146 + (SBLockScreenManager *) sharedInstance;
147 - (SBLockScreenViewController *) lockScreenViewController;
148 @end
149
150 @protocol CydgetController
151 - (NSDictionary *) currentConfiguration;
152 - (NSString *) currentPath;
153 @end
154
155 static Class $CydgetController(objc_getClass("CydgetController"));
156
157 static bool iOS32, iOS4;
158
159 @interface NSString (UIKit)
160 - (NSString *) stringByAddingPercentEscapes;
161 @end
162
163 @implementation UIWebDocumentView (WebCycript)
164
165 - (void) _setScrollerOffset:(CGPoint)offset {
166 UIScroller *scroller([self _scroller]);
167
168 CGSize size([scroller contentSize]);
169 CGSize bounds([scroller bounds].size);
170
171 CGPoint max;
172 max.x = size.width - bounds.width;
173 max.y = size.height - bounds.height;
174
175 // wtf Apple?!
176 if (max.x < 0)
177 max.x = 0;
178 if (max.y < 0)
179 max.y = 0;
180
181 offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x;
182 offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y;
183
184 [scroller setOffset:offset];
185 }
186
187 @end
188
189 #ifdef USE_ICU_REGEX
190 /* ICU Regular Expression {{{ */
191 class RegEx {
192 private:
193 URegularExpression *regex_;
194
195 public:
196 RegEx(const char *regex) {
197 UParseError error;
198 UErrorCode status(U_ZERO_ERROR);
199 regex_ = uregex_openC(regex, 0, &error, &status);
200 if (U_FAILURE(status))
201 @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"*** RegEx(): [%u] %s", error.offset, u_errorName(status)] userInfo:nil];
202 }
203
204 ~RegEx() {
205 uregex_close(regex_);
206 }
207
208 bool operator ()(NSString *string) {
209 return operator ()(reinterpret_cast<const uint16_t *>([string cStringUsingEncoding:NSUTF16StringEncoding]), [string length]);
210 }
211
212 bool operator ()(const UChar *data, size_t size) {
213 UErrorCode status(U_ZERO_ERROR);
214 uregex_setText(regex_, data, size, &status);
215 _assert(U_SUCCESS(status));
216 bool matches(uregex_matches(regex_, 0, &status));
217 _assert(U_SUCCESS(status));
218 return matches;
219 }
220 };
221 /* }}} */
222 #else
223 /* Perl-Compatible RegEx {{{ */
224 class RegEx {
225 private:
226 pcre *code_;
227 pcre_extra *study_;
228 int capture_;
229 int *matches_;
230 const char *data_;
231
232 public:
233 RegEx(const char *regex) :
234 study_(NULL)
235 {
236 const char *error;
237 int offset;
238 code_ = pcre_compile(regex, 0, &error, &offset, NULL);
239
240 if (code_ == NULL)
241 @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"*** RegEx(): [%u] %s", offset, error] userInfo:nil];
242
243 pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_);
244 matches_ = new int[(capture_ + 1) * 3];
245 }
246
247 ~RegEx() {
248 pcre_free(code_);
249 delete matches_;
250 }
251
252 bool operator ()(NSString *data) {
253 // XXX: length is for characters, not for bytes
254 return operator ()([data UTF8String], [data length]);
255 }
256
257 bool operator ()(const char *data, size_t size) {
258 data_ = data;
259 return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
260 }
261 };
262 /* }}} */
263 #endif
264
265 @interface DOMCSSStyleSheet : NSObject
266 - (int) addRule:(NSString *)rule style:(NSString *)style index:(unsigned)index;
267 - (void) deleteRule:(unsigned)index;
268 @end
269
270 @interface DOMStyleSheetList : NSObject
271 - (DOMCSSStyleSheet *) item:(unsigned)index;
272 @end
273
274 @interface DOMDocument : NSObject
275 - (DOMStyleSheetList *) styleSheets;
276 @end
277
278 static float CYScrollViewDecelerationRateNormal;
279
280 @interface NSURL (Apple)
281 - (BOOL) isSpringboardHandledURL;
282 @end
283
284 @interface UIScrollView (Apple)
285 - (void) setDecelerationRate:(CGFloat)value;
286 - (void) setScrollingEnabled:(BOOL)enabled;
287 - (void) setShowBackgroundShadow:(BOOL)show;
288 @end
289
290 @interface UIWebView (Apple)
291 - (UIWebDocumentView *) _documentView;
292 - (void) setDataDetectorTypes:(NSInteger)types;
293 - (void) _setDrawInWebThread:(BOOL)draw;
294 - (UIScrollView *) _scrollView;
295 - (UIScroller *) _scroller;
296 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message;
297 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
298 @end
299
300 @interface WebView (Apple)
301 - (void) _setLayoutInterval:(float)interval;
302 - (void) _setAllowsMessaging:(BOOL)allows;
303 - (void) setShouldUpdateWhileOffscreen:(BOOL)update;
304 @end
305
306 @protocol CydgetWebViewDelegate <UIWebViewDelegate>
307 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame;
308 @end
309
310 @class UIWebViewWebViewDelegate;
311
312 @interface CydgetWebView : UIWebView {
313 }
314
315 - (void) updateStyles;
316
317 @end
318
319 MSClassHook(UIApplication)
320 MSClassHook(SBLockScreenManager)
321
322 MSInstanceMessageHook1(void, UIApplication, openURL, NSURL *, url) {
323 [self applicationOpenURL:url];
324 }
325
326 @implementation NSURL (Cydget)
327
328 - (NSNumber *) cydget$isSpringboardHandledURL {
329 return [NSNumber numberWithBool:[self isSpringboardHandledURL]];
330 }
331
332 @end
333
334 MSClassHook(NSURL)
335
336 MSInstanceMessageHook0(BOOL, NSURL, isSpringboardHandledURL) {
337 if (![NSThread isMainThread])
338 return MSOldCall();
339
340 return [[self cydget$yieldToSelector:@selector(cydget$isSpringboardHandledURL)] boolValue];
341 }
342
343 @implementation CydgetWebView
344
345 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
346 NSObject<CydgetWebViewDelegate> *delegate((NSObject<CydgetWebViewDelegate> *) [self delegate]);
347 if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
348 [delegate webView:view didClearWindowObject:window forFrame:frame];
349 if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)])
350 [super webView:view didClearWindowObject:window forFrame:frame];
351 }
352
353 - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
354 NSLog(@"addMessageToConsole:%@", message);
355
356 if ([UIWebView instancesRespondToSelector:@selector(webView:addMessageToConsole:)])
357 [super webView:view addMessageToConsole:message];
358 }
359
360 - (void) updateStyles {
361 DOMCSSStyleSheet *sheet([[[[[[self _documentView] webView] mainFrame] DOMDocument] styleSheets] item:0]);
362 [sheet addRule:@"cydget" style:@"color: black" index:0];
363 [sheet deleteRule:0];
364 }
365
366 @end
367
368 @interface WebCydgetLockScreenView : UIView <UIWebViewDelegate> {
369 CydgetWebView *webview_;
370 UIScrollView *scroller_;
371 NSString *cycript_;
372 }
373
374 - (void) updateStyles;
375
376 @end
377
378 @implementation WebCydgetLockScreenView
379
380 //#include "UICaboodle/UCInternal.h"
381
382 - (void) dealloc {
383 [webview_ setDelegate:nil];
384 [webview_ release];
385 [super dealloc];
386 }
387
388 - (void) loadRequest:(NSURLRequest *)request {
389 [webview_ loadRequest:request];
390 }
391
392 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
393 [self loadRequest:[NSURLRequest
394 requestWithURL:url
395 cachePolicy:policy
396 timeoutInterval:30.0
397 ]];
398 }
399
400 - (void) loadURL:(NSURL *)url {
401 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
402 }
403
404 - (id) initWithURL:(NSURL *)url {
405 CGRect frame = [[UIScreen mainScreen] bounds];
406 if (kCFCoreFoundationVersionNumber < 800)
407 frame.size.height -= 20; //[[[$SBStatusBarController sharedStatusBarController] statusBarView] frame].size.height;
408
409 if ((self = [super initWithFrame:frame]) != nil) {
410 CGRect bounds([self bounds]);
411 if (kCFCoreFoundationVersionNumber < 800)
412 bounds.size.height -= [TPBottomLockBar defaultHeight];
413
414 webview_ = [[CydgetWebView alloc] initWithFrame:bounds];
415 [webview_ setDelegate:self];
416 [self addSubview:webview_];
417
418 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
419 [webview_ setDataDetectorTypes:0x80000000];
420 else
421 [webview_ setDetectsPhoneNumbers:NO];
422
423 [webview_ setScalesPageToFit:YES];
424
425 if (kCFCoreFoundationVersionNumber < 478.61)
426 if ([webview_ respondsToSelector:@selector(_setDrawInWebThread:)])
427 [webview_ _setDrawInWebThread:NO];
428
429 UIWebDocumentView *document([webview_ _documentView]);
430 WebView *webview([document webView]);
431 WebPreferences *preferences([webview preferences]);
432
433 [document setTileSize:CGSizeMake(bounds.size.width, 500)];
434
435 [document setBackgroundColor:[UIColor clearColor]];
436 [document setDrawsBackground:NO];
437
438 [webview setPreferencesIdentifier:@"WebCycript"];
439
440 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
441 [webview _setLayoutInterval:0];
442 else
443 [preferences _setLayoutInterval:0];
444
445 [preferences setCacheModel:WebCacheModelDocumentViewer];
446 [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
447 [preferences setOfflineWebApplicationCacheEnabled:YES];
448
449 if ([webview respondsToSelector:@selector(setShouldUpdateWhileOffscreen:)])
450 [webview setShouldUpdateWhileOffscreen:NO];
451
452 if ([document respondsToSelector:@selector(setAllowsMessaging:)])
453 [document setAllowsMessaging:YES];
454 if ([webview respondsToSelector:@selector(_setAllowsMessaging:)])
455 [webview _setAllowsMessaging:YES];
456
457 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
458 scroller_ = [webview_ _scrollView];
459
460 [scroller_ setDirectionalLockEnabled:YES];
461 [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
462 [scroller_ setDelaysContentTouches:NO];
463
464 [scroller_ setCanCancelContentTouches:YES];
465
466 [scroller_ setAlwaysBounceVertical:NO];
467 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
468 UIScroller *scroller([webview_ _scroller]);
469 scroller_ = (UIScrollView *) scroller;
470
471 [scroller setDirectionalScrolling:YES];
472 [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
473 [scroller setScrollHysteresis:0]; /* 8 */
474
475 [scroller setThumbDetectionEnabled:NO];
476 }
477
478 [webview_ setOpaque:NO];
479 [webview_ setBackgroundColor:[UIColor clearColor]];
480
481 [scroller_ setFixedBackgroundPattern:YES];
482 [scroller_ setBackgroundColor:[UIColor clearColor]];
483 [scroller_ setClipsSubviews:NO];
484
485 [scroller_ setBounces:YES];
486 [scroller_ setShowBackgroundShadow:NO]; /* YES */
487
488 [self setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
489 [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
490
491 NSDictionary *configuration([$CydgetController currentConfiguration]);
492 cycript_ = [configuration objectForKey:@"CycriptURLs"];
493
494 [scroller_ setScrollingEnabled:[[configuration objectForKey:@"Scrollable"] boolValue]];
495
496 [self loadURL:url];
497 } return self;
498 }
499
500 - (void) webView:(WebView *)webview didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
501 if (cycript_ != nil)
502 if (NSString *href = [[[[frame dataSource] request] URL] absoluteString])
503 if (RegEx([cycript_ UTF8String])(href))
504 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
505 if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CydgetSetupContext"))) {
506 WebFrame *frame([webview mainFrame]);
507 JSGlobalContextRef context([frame globalContext]);
508 @try {
509 CYSetupContext(context);
510 } @catch (NSException *e) {
511 NSLog(@"*** CydgetSetupContext => %@", e);
512 }
513 }
514 }
515
516 - (void) updateStyles {
517 [webview_ updateStyles];
518 }
519
520 @end
521
522 @interface WebCycriptLockScreenController : SBAwayViewPluginController {
523 NSDictionary *configuration_;
524 bool legacy_;
525 bool media_;
526 bool items_;
527 WebCydgetLockScreenView *background_;
528 WebCydgetLockScreenView *foreground_;
529 }
530
531 @end
532
533 #include <string>
534
535 struct State {
536 unsigned state;
537 };
538
539 namespace JSC {
540 class JSGlobalData;
541 class UString;
542 }
543
544 namespace WebCore {
545 class KURL;
546 }
547
548 namespace WebCore {
549 struct String {
550 void *impl_;
551 }; }
552
553 namespace JSC {
554 struct SourceCode {
555 void *provider_;
556 int start_;
557 int end_;
558 int line_;
559 }; }
560
561 namespace JSC {
562 union ScriptSourceCode {
563 struct {
564 JSC::SourceCode source_;
565 } Old;
566 struct {
567 void *provider_;
568 JSC::SourceCode source_;
569 } New;
570 }; }
571
572 // String Helpers {{{
573 static const UChar *(*_ZNK7WebCore6String10charactersEv)(const WebCore::String *);
574 static const UChar *(*_ZN7WebCore6String29charactersWithNullTerminationEv)(const WebCore::String *);
575 static unsigned (*_ZNK7WebCore6String6lengthEv)(const WebCore::String *);
576
577 static bool StringGet(const WebCore::String &string, const UChar *&data, size_t &length) {
578 bool terminated;
579
580 if (_ZNK7WebCore6String10charactersEv != NULL) {
581 data = (*_ZNK7WebCore6String10charactersEv)(&string);
582 terminated = false;
583 } else if (_ZN7WebCore6String29charactersWithNullTerminationEv != NULL) {
584 data = (*_ZN7WebCore6String29charactersWithNullTerminationEv)(&string);
585 terminated = true;
586 } else return false;
587
588 if (data == NULL)
589 return false;
590
591 if (_ZNK7WebCore6String6lengthEv != NULL)
592 length = (*_ZNK7WebCore6String6lengthEv)(&string);
593 else if (terminated)
594 for (length = 0; data[length] != 0; ++length);
595 else return false;
596
597 return true;
598 }
599
600 static bool StringEquals(const WebCore::String &string, const char *value) {
601 const UChar *data;
602 size_t size;
603 if (!StringGet(string, data, size))
604 return false;
605
606 size_t length(strlen(value));
607 if (size != length)
608 return false;
609
610 for (size_t index(0); index != length; ++index)
611 if (data[index] != value[index])
612 return false;
613
614 return true;
615 }
616 // }}}
617 // State Machine {{{
618 static bool cycript_;
619
620 MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, const WebCore::String &mime) {
621 if (!StringEquals(mime, "text/cycript")) {
622 cycript_ = false;
623 return __ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE(mime);
624 }
625
626 static void *handle(dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL));
627 if (handle == NULL)
628 return false;
629
630 cycript_ = true;
631 return true;
632 }
633 // }}}
634 // Script Compiler {{{
635 static void Log(const WebCore::String &string) {
636 #if 0
637 const UChar *data;
638 size_t length;
639 if (!StringGet(string, data, length))
640 return;
641
642 UChar terminated[length + 1];
643 terminated[length] = 0;
644 memcpy(terminated, data, length * 2);
645 NSLog(@"wtf %p:%zu:%S:", &string, length, terminated);
646 #endif
647 }
648
649 static bool Cycriptify(const uint16_t *&data, size_t &size) {
650 cycript_ = false;
651
652 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
653 if (void (*CydgetMemoryParse)(const uint16_t **, size_t *) = reinterpret_cast<void (*)(const uint16_t **, size_t *)>(dlsym(handle, "CydgetMemoryParse"))) @try {
654 CydgetMemoryParse(&data, &size);
655 return true;
656 } @catch (NSException *e) {
657 NSLog(@"*** CydgetMemoryParse => %@", e);
658 }
659 return false;
660 }
661
662 static void (*_ZN7WebCore6String6appendEPKtj)(WebCore::String *, const UChar *, unsigned);
663 static void (*_ZN7WebCore6String8truncateEj)(WebCore::String *, unsigned);
664
665 static void Cycriptify(const WebCore::String &source, int *psize = NULL) {
666 if (!cycript_)
667 return;
668 cycript_ = false;
669
670 const UChar *data;
671 size_t length;
672 if (!StringGet(source, data, length))
673 return;
674
675 size_t size(length);
676 if (!Cycriptify(data, size))
677 return;
678
679 WebCore::String &script(const_cast<WebCore::String &>(source));
680 _ZN7WebCore6String8truncateEj(&script, 0);
681 _ZN7WebCore6String6appendEPKtj(&script, data, size);
682
683 if (psize != NULL)
684 *psize = size;
685
686 free((void *) data);
687
688 Log(source);
689 }
690 // }}}
691
692 static WebCore::String *string;
693
694 // iOS 2.x
695 MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, void *_this, const WebCore::String &string, State state, const WebCore::String &url, int line) {
696 Cycriptify(string);
697 return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i(_this, string, state, url, line);
698 }
699
700 // iOS 3.x
701 MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::SourceCode **_this, JSC::JSGlobalData *global, int *line, JSC::UString *message) {
702 /*if (cycript_) {
703 JSC::SourceCode *source(_this[iOS32 ? 6 : 0]);
704 const uint16_t *data(source->data());
705 size_t size(source->length());
706
707 if (Cycriptify(data, size)) {
708 source->~SourceCode();
709 // XXX: I actually don't have the original URL here: pants
710 new (source) JSC::SourceCode(JSC::UStringSourceProvider::create(JSC::UString(data, size), "cycript://"), 1);
711 free((void *) data);
712 }
713 }*/
714
715 return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, global, line, message);
716 }
717
718 // iOS 3.x cdata
719 MSHook(const WebCore::String &, _ZNK7WebCore4Node11textContentEb, void *_this, bool convert) {
720 const WebCore::String &code(__ZNK7WebCore4Node11textContentEb(_this, convert));
721 string = const_cast<WebCore::String *>(&code);
722 Log(code);
723 Cycriptify(code);
724 return code;
725 }
726
727 // iOS 4.x cdata
728 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, void *_this, const WebCore::String &source, const WebCore::KURL &url, int line) {
729 Cycriptify(source);
730 return __ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi(_this, source, url, line);
731 }
732
733 // iOS 4.x+5.0 @src=
734 MSHook(const WebCore::String &, _ZN7WebCore12CachedScript6scriptEv, void *_this) {
735 const WebCore::String &script(__ZN7WebCore12CachedScript6scriptEv(_this));
736 string = const_cast<WebCore::String *>(&script);
737 Log(script);
738 return script;
739 }
740
741 // iOS 4.x @src=
742 MSHook(State, _ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, void *_this, JSC::ScriptSourceCode &script, State state) {
743 if (string != NULL) {
744 JSC::SourceCode *source(iOS4 ? &script.New.source_ : &script.Old.source_);
745 Cycriptify(*string, &source->end_);
746 string = NULL;
747 }
748
749 return __ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE(_this, script, state);
750 }
751
752 // iOS 5.0 cdata
753 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, void *_this, const WebCore::String &source, const WebCore::KURL &url, void *position) {
754 Cycriptify(source);
755 return __ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE(_this, source, url, position);
756 }
757
758 // iOS 5.0 @src=
759 MSHook(void, _ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, void *_this, void *position, int legacy) {
760 string = NULL;
761 return __ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE(_this, position, legacy);
762 }
763
764 void (*$_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE)(void *_this, int legacy);
765
766 // iOS 5.0 @src=
767 MSHook(void, _ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, void *_this, JSC::ScriptSourceCode &script) {
768 if (string != NULL) {
769 JSC::SourceCode *source(&script.New.source_);
770 $_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE(_this, 0);
771 Cycriptify(*string, &source->end_);
772 string = NULL;
773 }
774
775 return __ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE(_this, script);
776 }
777
778 // iOS 6.0 cdata
779 MSHook(void, _ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, void *_this, const WebCore::String &source, const WebCore::KURL &url, void *position) {
780 Cycriptify(source);
781 return __ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE(_this, source, url, position);
782 }
783
784 // iOS 6.0 @src=
785 MSHook(void, _ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, void *_this, void *position, int legacy) {
786 string = NULL;
787 return __ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE(_this, position, legacy);
788 }
789
790 /* Cydget:// Protocol {{{ */
791 @interface CydgetURLProtocol : NSURLProtocol {
792 }
793
794 @end
795
796 @implementation CydgetURLProtocol
797
798 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
799 NSURL *url([request URL]);
800 if (url == nil)
801 return NO;
802 NSString *scheme([[url scheme] lowercaseString]);
803 if (scheme == nil || ![scheme isEqualToString:@"cydget"])
804 return NO;
805 return YES;
806 }
807
808 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
809 return request;
810 }
811
812 - (void) _returnPNGWithImage:(UIImage *)icon forRequest:(NSURLRequest *)request {
813 id<NSURLProtocolClient> client([self client]);
814 if (icon == nil)
815 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
816 else {
817 NSData *data(UIImagePNGRepresentation(icon));
818
819 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"image/png" expectedContentLength:-1 textEncodingName:nil] autorelease]);
820 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
821 [client URLProtocol:self didLoadData:data];
822 [client URLProtocolDidFinishLoading:self];
823 }
824 }
825
826 - (void) startLoading {
827 id<NSURLProtocolClient> client([self client]);
828 NSURLRequest *request([self request]);
829
830 NSURL *url([request URL]);
831 NSString *href([url absoluteString]);
832
833 NSString *path([href substringFromIndex:9]);
834 NSRange slash([path rangeOfString:@"/"]);
835
836 NSString *command;
837 if (slash.location == NSNotFound) {
838 command = path;
839 path = nil;
840 } else {
841 command = [path substringToIndex:slash.location];
842 path = [path substringFromIndex:(slash.location + 1)];
843 }
844
845 if ([command isEqualToString:@"_UIImageWithName"]) {
846 if (path == nil)
847 goto fail;
848 path = [path stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
849 UIImage *icon(_UIImageWithName(path));
850 [self _returnPNGWithImage:icon forRequest:request];
851 } else fail: {
852 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
853 }
854 }
855
856 - (void) stopLoading {
857 }
858
859 @end
860 /* }}} */
861 /* Cydget-CGI:// Protocol {{{ */
862 @interface CydgetCGIURLProtocol : NSURLProtocol {
863 pid_t pid_;
864 CFHTTPMessageRef http_;
865 NSFileHandle *handle_;
866 }
867
868 @end
869
870 @implementation CydgetCGIURLProtocol
871
872 + (BOOL) canInitWithRequest:(NSURLRequest *)request {
873 NSURL *url([request URL]);
874 if (url == nil)
875 return NO;
876 NSString *scheme([[url scheme] lowercaseString]);
877 if (scheme == nil || ![scheme isEqualToString:@"cydget-cgi"])
878 return NO;
879 return YES;
880 }
881
882 + (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
883 return request;
884 }
885
886 - (id) initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse *)response client:(id<NSURLProtocolClient>)client {
887 if ((self = [super initWithRequest:request cachedResponse:response client:client]) != nil) {
888 pid_ = -1;
889 } return self;
890 }
891
892 - (void) startLoading {
893 id<NSURLProtocolClient> client([self client]);
894 NSURLRequest *request([self request]);
895 NSURL *url([request URL]);
896
897 NSString *path([url path]);
898 if (path == nil) {
899 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
900 return;
901 }
902
903 NSFileManager *manager([NSFileManager defaultManager]);
904 if (![manager fileExistsAtPath:path]) {
905 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
906 return;
907 }
908
909 int fds[2];
910 _assert(pipe(fds) != -1);
911
912 _assert(pid_ == -1);
913 pid_ = fork();
914 if (pid_ == -1) {
915 _assert(close(fds[0]) != -1);
916 _assert(close(fds[1]) != -1);
917 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
918 return;
919 }
920
921 if (pid_ == 0) {
922 const char *script([path UTF8String]);
923
924 setenv("GATEWAY_INTERFACE", "CGI/1.1", true);
925 setenv("SCRIPT_FILENAME", script, true);
926 NSString *query([url query]);
927 if (query != nil)
928 setenv("QUERY_STRING", [query UTF8String], true);
929
930 _assert(dup2(fds[1], 1) != -1);
931 _assert(close(fds[0]) != -1);
932 _assert(close(fds[1]) != -1);
933
934 execl(script, script, NULL);
935 exit(1);
936 _assert(false);
937 }
938
939 _assert(close(fds[1]) != -1);
940
941 _assert(http_ == NULL);
942 http_ = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE);
943 CFHTTPMessageAppendBytes(http_, (const uint8_t *) "HTTP/1.1 200 OK\r\n", 17);
944
945 _assert(handle_ == nil);
946 handle_ = [[NSFileHandle alloc] initWithFileDescriptor:fds[0] closeOnDealloc:YES];
947
948 [[NSNotificationCenter defaultCenter]
949 addObserver:self
950 selector:@selector(onRead:)
951 name:@"NSFileHandleReadCompletionNotification"
952 object:handle_
953 ];
954
955 [handle_ readInBackgroundAndNotify];
956 }
957
958 - (void) onRead:(NSNotification *)notification {
959 NSFileHandle *handle([notification object]);
960
961 NSData *data([[notification userInfo] objectForKey:NSFileHandleNotificationDataItem]);
962
963 if (size_t length = [data length]) {
964 CFHTTPMessageAppendBytes(http_, reinterpret_cast<const UInt8 *>([data bytes]), length);
965 [handle readInBackgroundAndNotify];
966 } else {
967 id<NSURLProtocolClient> client([self client]);
968
969 CFStringRef mime(CFHTTPMessageCopyHeaderFieldValue(http_, CFSTR("Content-type")));
970 if (mime == NULL)
971 [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]];
972 else {
973 NSURLRequest *request([self request]);
974
975 NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:(NSString *)mime expectedContentLength:-1 textEncodingName:nil] autorelease]);
976 CFRelease(mime);
977
978 [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
979
980 CFDataRef body(CFHTTPMessageCopyBody(http_));
981 [client URLProtocol:self didLoadData:(NSData *)body];
982 CFRelease(body);
983
984 [client URLProtocolDidFinishLoading:self];
985 }
986
987 CFRelease(http_);
988 http_ = NULL;
989 }
990 }
991
992 //[client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil]];
993
994 - (void) stopLoading_ {
995 [[NSNotificationCenter defaultCenter] removeObserver:self];
996
997 if (handle_ != nil) {
998 [handle_ release];
999 handle_ = nil;
1000 }
1001
1002 if (pid_ != -1) {
1003 kill(pid_, SIGTERM);
1004 int status;
1005 _syscall(waitpid(pid_, &status, 0));
1006 pid_ = -1;
1007 }
1008 }
1009
1010 - (void) stopLoading {
1011 [self
1012 performSelectorOnMainThread:@selector(stopLoading_)
1013 withObject:nil
1014 waitUntilDone:NO
1015 ];
1016 }
1017
1018 @end
1019 /* }}} */
1020
1021 namespace WebCore {
1022 class MediaQueryEvaluator;
1023 class CSSParserValueList;
1024 }
1025
1026 namespace WebCore {
1027 struct MediaQueryExp {
1028 String feature_;
1029 void *value_;
1030 bool valid_;
1031 String cache_;
1032 }; }
1033
1034 bool CYHaveMediaControls() {
1035 SBLockScreenView *view([[[$SBLockScreenManager sharedInstance] lockScreenViewController] lockScreenView]);
1036 return view != nil && ![view mediaControlsHidden];
1037 //return [[[$SBLockScreenManager sharedInstance] lockScreenViewController] isShowingMediaControls];
1038 }
1039
1040 bool CYHaveNotificationList() {
1041 SBLockScreenNotificationListController *controller([[[$SBLockScreenManager sharedInstance] lockScreenViewController] _notificationController]);
1042 return controller != nil && [controller hasAnyContent];
1043 }
1044
1045 MSHook(bool, _ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, WebCore::MediaQueryEvaluator *_this, WebCore::String &query) {
1046 Log(query); if (false);
1047 else if (kCFCoreFoundationVersionNumber >= 800 && StringEquals(query, "cydget-media-controls"))
1048 return CYHaveMediaControls();
1049 else if (kCFCoreFoundationVersionNumber >= 800 && StringEquals(query, "cydget-notification-list"))
1050 return CYHaveNotificationList();
1051 else
1052 return __ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE(_this, query);
1053 }
1054
1055 MSHook(void, _ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, WebCore::MediaQueryExp *_this, WebCore::String &query, WebCore::CSSParserValueList *values) {
1056 Log(query);
1057 __ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE(_this, query, values);
1058 if (!_this->valid_) if (
1059 StringEquals(query, "cydget-media-controls") ||
1060 StringEquals(query, "cydget-notification-list") ||
1061 false) _this->valid_ = true;
1062 }
1063
1064 template <typename Type_>
1065 static void dlset(Type_ &function, const char *name) {
1066 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1067 }
1068
1069 template <typename Type_>
1070 static void msset_(Type_ &function, const char *name, MSImageRef handle) {
1071 function = reinterpret_cast<Type_>(MSFindSymbol(handle, name));
1072 }
1073
1074 #define msset(function, handle) \
1075 msset_(function, "_" #function, handle)
1076
1077 @implementation WebCycriptLockScreenController
1078
1079 static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) {
1080 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
1081 if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)])
1082 [uiWebView webView:view addMessageToConsole:message];
1083 }
1084
1085 static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) {
1086 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
1087 if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
1088 [uiWebView webView:view didClearWindowObject:window forFrame:frame];
1089 }
1090
1091 + (void) initialize {
1092 if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) {
1093 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12");
1094 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16");
1095 }
1096
1097 if (CGFloat *_UIScrollViewDecelerationRateNormal = reinterpret_cast<CGFloat *>(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal")))
1098 CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
1099 else // XXX: this actually might be fast on some older systems: we should look into this
1100 CYScrollViewDecelerationRateNormal = 0.998;
1101
1102 iOS4 = kCFCoreFoundationVersionNumber >= 550.32;
1103 iOS32 = !iOS4 && kCFCoreFoundationVersionNumber >= 478.61;
1104
1105 int maxproc;
1106 size_t size(sizeof(maxproc));
1107 if (sysctlbyname("kern.maxproc", &maxproc, &size, NULL, 0) == -1)
1108 NSLog(@"sysctlbyname(\"kern.maxproc\", ?)");
1109 else if (maxproc < 72) {
1110 maxproc = 72;
1111 if (sysctlbyname("kern.maxproc", NULL, NULL, &maxproc, sizeof(maxproc)) == -1)
1112 NSLog(@"sysctlbyname(\"kern.maxproc\", #)");
1113 }
1114
1115 [NSURLProtocol registerClass:[CydgetURLProtocol class]];
1116 [WebView registerURLSchemeAsLocal:@"cydget"];
1117
1118 [NSURLProtocol registerClass:[CydgetCGIURLProtocol class]];
1119 [WebView registerURLSchemeAsLocal:@"cydget-cgi"];
1120
1121 MSImageRef JavaScriptCore(MSGetImageByName("/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore"));
1122 MSImageRef WebCore(MSGetImageByName("/System/Library/PrivateFrameworks/WebCore.framework/WebCore"));
1123
1124 if (!iOS4) {
1125 void (*_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)(JSC::SourceCode **, JSC::JSGlobalData *, int *, JSC::UString *);
1126 dlset(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, "_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE");
1127 if (_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE != NULL)
1128 MSHookFunction(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE));
1129 }
1130
1131 bool (*_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE)(const WebCore::String &) = NULL;
1132 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE == NULL)
1133 MSHookSymbol(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE", WebCore);
1134 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE == NULL)
1135 MSHookSymbol(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, "__ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKN3WTF6StringE", WebCore);
1136 if (_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE != NULL)
1137 MSHookFunction(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE, MSHake(_ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6StringE));
1138
1139 void (*_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi)(void *, const WebCore::String &, const WebCore::KURL &, int) = NULL;
1140 if (_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi == NULL)
1141 MSHookSymbol(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, "__ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi", WebCore);
1142 if (_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi != NULL)
1143 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKNS_6StringERKNS_4KURLEi));
1144
1145 if (!iOS4) {
1146 const WebCore::String &(*_ZNK7WebCore4Node11textContentEb)(void *, bool) = NULL;
1147 if (_ZNK7WebCore4Node11textContentEb == NULL)
1148 MSHookSymbol(_ZNK7WebCore4Node11textContentEb, "__ZNK7WebCore4Node11textContentEb", WebCore);
1149 if (_ZNK7WebCore4Node11textContentEb != NULL)
1150 MSHookFunction(_ZNK7WebCore4Node11textContentEb, MSHake(_ZNK7WebCore4Node11textContentEb));
1151 }
1152
1153 const WebCore::String &(*_ZN7WebCore12CachedScript6scriptEv)(void *) = NULL;
1154 if (_ZN7WebCore12CachedScript6scriptEv == NULL)
1155 MSHookSymbol(_ZN7WebCore12CachedScript6scriptEv, "__ZN7WebCore12CachedScript6scriptEv", WebCore);
1156 if (_ZN7WebCore12CachedScript6scriptEv != NULL)
1157 MSHookFunction(_ZN7WebCore12CachedScript6scriptEv, MSHake(_ZN7WebCore12CachedScript6scriptEv));
1158
1159 State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i)(void *, const WebCore::String &, State, const WebCore::String &, int) = NULL;
1160 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i == NULL)
1161 MSHookSymbol(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i", WebCore);
1162 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i != NULL)
1163 MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_6StringENS0_5StateES3_i));
1164
1165 State (*_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE)(void *, JSC::ScriptSourceCode &, State) = NULL;
1166 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE == NULL)
1167 MSHookSymbol(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, "__ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE", WebCore);
1168 if (_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE != NULL)
1169 MSHookFunction(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE, MSHake(_ZN7WebCore13HTMLTokenizer15scriptExecutionERKNS_16ScriptSourceCodeENS0_5StateE));
1170
1171 void (*_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE)(void *, const WebCore::String &, const WebCore::KURL &, void *);
1172 msset(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, WebCore);
1173 if (_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE != NULL)
1174 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionINS1_14OneBasedNumberEEE));
1175
1176 void (*_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE)(void *, const WebCore::String &, const WebCore::KURL &, void *);
1177 msset(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, WebCore);
1178 if (_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE != NULL)
1179 MSHookFunction(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE, MSHake(_ZN7WebCore16ScriptSourceCodeC2ERKN3WTF6StringERKNS_4KURLERKNS1_12TextPositionE));
1180
1181 void (*_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE)(void *, void *, int);
1182 msset(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, WebCore);
1183 if (_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE != NULL)
1184 MSHookFunction(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE, MSHake(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionINS1_14OneBasedNumberEEENS0_17LegacyTypeSupportE));
1185
1186 void (*_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE)(void *, void *, int);
1187 msset(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, WebCore);
1188 if (_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE != NULL)
1189 MSHookFunction(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE, MSHake(_ZN7WebCore13ScriptElement13prepareScriptERKN3WTF12TextPositionENS0_17LegacyTypeSupportE));
1190
1191 MSHookSymbol($_ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE, "__ZNK7WebCore13ScriptElement21isScriptTypeSupportedENS0_17LegacyTypeSupportE", WebCore);
1192
1193 void (*_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE)(void *, JSC::ScriptSourceCode &);
1194 msset(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, WebCore);
1195 if (_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE != NULL)
1196 MSHookFunction(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE, MSHake(_ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE));
1197
1198 if (_ZN7WebCore6String6appendEPKtj == NULL)
1199 MSHookSymbol(_ZN7WebCore6String6appendEPKtj, "__ZN7WebCore6String6appendEPKtj", WebCore);
1200 if (_ZN7WebCore6String6appendEPKtj == NULL)
1201 msset(_ZN7WebCore6String6appendEPKtj, JavaScriptCore);
1202 if (_ZN7WebCore6String6appendEPKtj == NULL)
1203 MSHookSymbol(_ZN7WebCore6String6appendEPKtj, "__ZN3WTF6String6appendEPKtj", JavaScriptCore);
1204
1205 if (_ZN7WebCore6String8truncateEj == NULL)
1206 MSHookSymbol(_ZN7WebCore6String8truncateEj, "__ZN7WebCore6String8truncateEj", WebCore);
1207 if (_ZN7WebCore6String8truncateEj == NULL)
1208 msset(_ZN7WebCore6String8truncateEj, JavaScriptCore);
1209 if (_ZN7WebCore6String8truncateEj == NULL)
1210 MSHookSymbol(_ZN7WebCore6String8truncateEj, "__ZN3WTF6String8truncateEj", JavaScriptCore);
1211
1212 msset(_ZNK7WebCore6String10charactersEv, WebCore);
1213
1214 msset(_ZN7WebCore6String29charactersWithNullTerminationEv, JavaScriptCore);
1215 if (_ZN7WebCore6String29charactersWithNullTerminationEv == NULL)
1216 MSHookSymbol(_ZN7WebCore6String29charactersWithNullTerminationEv, "__ZN3WTF6String29charactersWithNullTerminationEv", JavaScriptCore);
1217
1218 msset(_ZNK7WebCore6String6lengthEv, WebCore);
1219
1220 bool (*_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE)(WebCore::MediaQueryEvaluator *, WebCore::String &);
1221 msset(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, WebCore);
1222 if (_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE != NULL)
1223 MSHookFunction(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE, MSHake(_ZNK7WebCore19MediaQueryEvaluator4evalEPKNS_13MediaQueryExpE));
1224
1225 void (*_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE)(WebCore::MediaQueryExp *, WebCore::String &, WebCore::CSSParserValueList *);
1226 msset(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, WebCore);
1227 if (_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE != NULL)
1228 MSHookFunction(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE, MSHake(_ZN7WebCore13MediaQueryExpC2ERKN3WTF12AtomicStringEPNS_18CSSParserValueListE));
1229 }
1230
1231 + (id) rootViewController {
1232 return [[[self alloc] init] autorelease];
1233 }
1234
1235 - (void) dealloc {
1236 [configuration_ release];
1237 [background_ release];
1238 [foreground_ release];
1239 [super dealloc];
1240 }
1241
1242 - (id) init {
1243 if ((self = [super init]) != nil) {
1244 configuration_ = [[$CydgetController currentConfiguration] retain];
1245 legacy_ = [configuration_ objectForKey:@"Background"] == nil;
1246 media_ = [[configuration_ objectForKey:@"MediaControls"] boolValue];
1247 items_ = [[configuration_ objectForKey:@"NotificationList"] boolValue];
1248 } return self;
1249 }
1250
1251 - (void) loadView {
1252 NSURL *base([NSURL fileURLWithPath:[$CydgetController currentPath]]);
1253
1254 if (NSString *background = [configuration_ objectForKey:@"Background"])
1255 background_ = [[WebCydgetLockScreenView alloc] initWithURL:[NSURL URLWithString:background relativeToURL:base]];
1256
1257 if (NSString *homepage = [configuration_ objectForKey:@"Homepage"]) {
1258 foreground_ = [[WebCydgetLockScreenView alloc] initWithURL:[NSURL URLWithString:homepage relativeToURL:base]];
1259 [self setView:foreground_];
1260 }
1261 }
1262
1263 - (void) purgeView {
1264 [background_ removeFromSuperview];
1265 [background_ release];
1266 background_ = nil;
1267 [foreground_ removeFromSuperview];
1268 [foreground_ release];
1269 foreground_ = nil;
1270 [super purgeView];
1271 }
1272
1273 - (void) updateStyles {
1274 [foreground_ updateStyles];
1275 [background_ updateStyles];
1276 }
1277
1278 - (UIView *) backgroundView {
1279 return background_;
1280 }
1281
1282 - (BOOL) showAwayItems {
1283 return YES;
1284 }
1285
1286 - (BOOL) updateHidden {
1287 if (foreground_ == nil)
1288 return true;
1289 bool media(CYHaveMediaControls());
1290 [foreground_ setHidden:media];
1291 return media;
1292 }
1293
1294 - (BOOL) showDateView {
1295 if (kCFCoreFoundationVersionNumber < 800)
1296 return false;
1297 [self updateStyles];
1298 if (!legacy_ && foreground_ == nil)
1299 return true;
1300 if (!items_ && CYHaveNotificationList())
1301 return true;
1302 return false;
1303 }
1304
1305 - (BOOL) allowsLockScreenMediaControls {
1306 if (kCFCoreFoundationVersionNumber < 800)
1307 return true;
1308 return media_;
1309 }
1310
1311 /*- (BOOL) showHeaderView {
1312 return YES;
1313 }*/
1314
1315 // 0: view is rendered above head
1316 // 1: view moves as one with head
1317 // 2: view moves up and down only
1318 // 3: view simply never does move
1319 - (NSUInteger) presentationStyle {
1320 return 1;
1321 }
1322
1323 // 1: light blur
1324 // 2: heavy blur
1325 // 3: just black
1326 // 4: legibility
1327 // 5: no overlay
1328 - (NSUInteger) overlayStyle {
1329 return legacy_ ? 1 : 4;
1330 }
1331
1332 // 1: blur -> view -> list
1333 // 2: view -> blur -> list
1334 // 3: view. unblur below?!
1335 // 4: blur -> list -> view
1336 - (NSUInteger) notificationBehavior {
1337 return items_ ? 1 : 2;
1338 }
1339
1340 - (BOOL) viewWantsFullscreenLayout {
1341 return kCFCoreFoundationVersionNumber >= 800;
1342 }
1343
1344 /*- (BOOL) viewWantsOverlayLayout {
1345 return kCFCoreFoundationVersionNumber >= 800;
1346 }*/
1347
1348 - (BOOL) shouldDisableOnUnlock {
1349 return YES;
1350 }
1351
1352 - (BOOL) canBeAlwaysFullscreen {
1353 return YES;
1354 }
1355
1356 /*- (BOOL) wantsSwipeGestureRecognizer {
1357 return YES;
1358 }
1359
1360 - (BOOL) handleGesture:(int)arg1 fingerCount:(NSUInteger)fingers {
1361 return NO;
1362 return YES;
1363 }*/
1364
1365 // - (void) lockScreenMediaControlsShown:(BOOL)shown;
1366
1367 - (BOOL) handleMenuButtonDoubleTap {
1368 if (kCFCoreFoundationVersionNumber >= 800) {
1369 SBLockScreenViewController *controller([[$SBLockScreenManager sharedInstance] lockScreenViewController]);
1370 [controller _setMediaControlsVisible:![controller isShowingMediaControls]];
1371 [self updateStyles];
1372 }
1373
1374 return [super handleMenuButtonDoubleTap];
1375 }
1376
1377 @end
1378
1379 MSClassHook(WebView)
1380 MSMetaClassHook(WebView)
1381
1382 MSClassMessageHook0(void, WebView, enableWebThread) {
1383 if (kCFCoreFoundationVersionNumber >= 478.61)
1384 return MSOldCall();
1385
1386 NSLog(@"-[WebView enableWebThread]");
1387 }