]> git.saurik.com Git - cydget.git/blob - LockScreen.mm
5207b154d091761f643a6eb29c02f81c5e7c721b
[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
40 #import <GraphicsServices/GraphicsServices.h>
41 #import <UIKit/UIKit.h>
42 #import <AddressBook/AddressBook.h>
43
44 #import <SpringBoardUI/SBAwayViewPluginController.h>
45 #import <TelephonyUI/TPBottomLockBar.h>
46
47 #import <QuartzCore/CALayer.h>
48 // XXX: fix the minimum requirement
49 extern NSString * const kCAFilterNearest;
50
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>
57
58 #include <WebKit/WebFrame.h>
59 #include <WebKit/WebPolicyDelegate.h>
60 #include <WebKit/WebPreferences.h>
61 #include <WebKit/WebScriptObject.h>
62
63 #import <WebKit/WebView.h>
64 #import <WebKit/WebView-WebPrivate.h>
65
66 #include <WebCore/Page.h>
67 #include <WebCore/Settings.h>
68
69 #include <WebCore/WebCoreThread.h>
70 #include <WebKit/WebPreferences-WebPrivate.h>
71
72 //#include "Parser.h"
73 #include "JSGlobalData.h"
74
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;
81 @end
82
83 #define _transient
84 #define _forever for (;;)
85
86 _disused static unsigned trace_;
87
88 #define _trace() do { \
89 NSLog(@"_trace(%u)@%s:%u[%s]\n", \
90 trace_++, __FILE__, __LINE__, __FUNCTION__\
91 ); \
92 } while (false)
93
94 @protocol CydgetController
95 - (NSDictionary *) currentConfiguration;
96 @end
97
98 static void (*CYSetupContext)(JSGlobalContextRef);
99
100 static Class $CydgetController(objc_getClass("CydgetController"));
101
102 @interface NSString (UIKit)
103 - (NSString *) stringByAddingPercentEscapes;
104 @end
105
106 @implementation UIWebDocumentView (WebCycript)
107
108 - (void) _setScrollerOffset:(CGPoint)offset {
109 UIScroller *scroller([self _scroller]);
110
111 CGSize size([scroller contentSize]);
112 CGSize bounds([scroller bounds].size);
113
114 CGPoint max;
115 max.x = size.width - bounds.width;
116 max.y = size.height - bounds.height;
117
118 // wtf Apple?!
119 if (max.x < 0)
120 max.x = 0;
121 if (max.y < 0)
122 max.y = 0;
123
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;
126
127 [scroller setOffset:offset];
128 }
129
130 @end
131
132 /* WebCycript Delegate {{{ */
133 @interface WebCycriptDelegate : NSObject {
134 _transient volatile id delegate_;
135 }
136
137 - (void) setDelegate:(id)delegate;
138 - (id) initWithDelegate:(id)delegate;
139 @end
140
141 @implementation WebCycriptDelegate
142
143 - (void) setDelegate:(id)delegate {
144 delegate_ = delegate;
145 }
146
147 - (id) initWithDelegate:(id)delegate {
148 delegate_ = delegate;
149 return self;
150 }
151
152 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
153 if (delegate_ != nil)
154 return [delegate_ webView:sender didClearWindowObject:window forFrame:frame];
155 }
156
157 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
158 if (delegate_ != nil)
159 return [delegate_ webView:sender didCommitLoadForFrame:frame];
160 }
161
162 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
163 if (delegate_ != nil)
164 return [delegate_ webView:sender didFailLoadWithError:error forFrame:frame];
165 }
166
167 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
168 if (delegate_ != nil)
169 return [delegate_ webView:sender didFailProvisionalLoadWithError:error forFrame:frame];
170 }
171
172 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
173 if (delegate_ != nil)
174 return [delegate_ webView:sender didFinishLoadForFrame:frame];
175 }
176
177 /*- (void) webView:(WebView *)sender didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
178 if (delegate_ != nil)
179 return [delegate_ webView:sender didReceiveTitle:title forFrame:frame];
180 }*/
181
182 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
183 if (delegate_ != nil)
184 return [delegate_ webView:sender didStartProvisionalLoadForFrame:frame];
185 }
186
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];
190 }*/
191
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];
195 return nil;
196 }*/
197
198 - (IMP) methodForSelector:(SEL)sel {
199 if (IMP method = [super methodForSelector:sel])
200 return method;
201 fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
202 return NULL;
203 }
204
205 - (BOOL) respondsToSelector:(SEL)sel {
206 if ([super respondsToSelector:sel])
207 return YES;
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];
211 }
212
213 - (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
214 if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
215 return method;
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])
219 return sig;
220 // XXX: I fucking hate Apple so very very bad
221 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
222 }
223
224 - (void) forwardInvocation:(NSInvocation *)inv {
225 SEL sel = [inv selector];
226 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
227 [inv invokeWithTarget:delegate_];
228 }
229
230 @end
231 /* }}} */
232
233 @interface WebCydgetLockScreenView : UIView {
234 WebCycriptDelegate *indirect_;
235 UIProgressIndicator *indicator_;
236 UIScroller *scroller_;
237 UIWebDocumentView *document_;
238
239 bool cycript_;
240 float width_;
241 CGSize size_;
242 bool editing_;
243
244 NSNumber *confirm_;
245
246 NSMutableSet *loading_;
247 bool error_;
248 bool reloading_;
249 }
250
251 @end
252
253 @implementation WebCydgetLockScreenView
254
255 //#include "UICaboodle/UCInternal.h"
256
257 - (void) dealloc {
258 WebThreadLock();
259
260 WebView *webview([document_ webView]);
261 [webview setFrameLoadDelegate:nil];
262 [webview setResourceLoadDelegate:nil];
263 [webview setUIDelegate:nil];
264 [webview setScriptDebugDelegate:nil];
265 [webview setPolicyDelegate:nil];
266
267 /* XXX: these are set by UIWebDocumentView
268 [webview setDownloadDelegate:nil];
269 [webview _setFormDelegate:nil];
270 [webview _setUIKitDelegate:nil];
271 [webview setEditingDelegate:nil];*/
272
273 /* XXX: no one sets this, ever
274 [webview setWebMailDelegate:nil];*/
275
276 [document_ setDelegate:nil];
277 [document_ setGestureDelegate:nil];
278 [document_ setFormEditingDelegate:nil];
279 [document_ setInteractionDelegate:nil];
280
281 [indirect_ setDelegate:nil];
282
283 [webview close];
284 [document_ release];
285
286 [indirect_ release];
287
288 WebThreadUnlock();
289
290 [scroller_ setDelegate:nil];
291
292 if (confirm_ != nil)
293 [confirm_ release];
294
295 [scroller_ release];
296 [indicator_ release];
297 [super dealloc];
298 }
299
300 + (float) defaultWidth {
301 return 980;
302 }
303
304 - (void) _setTileDrawingEnabled:(BOOL)enabled {
305 //[document_ setTileDrawingEnabled:enabled];
306 }
307
308 - (void) willStartGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
309 [self _setTileDrawingEnabled:NO];
310 }
311
312 - (void) didFinishGesturesInView:(UIView *)view forEvent:(GSEventRef)event {
313 [self _setTileDrawingEnabled:YES];
314 [document_ redrawScaledDocument];
315 }
316
317 - (void) setViewportWidth:(float)width {
318 width_ = width != 0 ? width : [[self class] defaultWidth];
319 [document_ setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
320 }
321
322 - (void) scrollerWillStartDragging:(UIScroller *)scroller {
323 [self _setTileDrawingEnabled:NO];
324 }
325
326 - (void) scrollerDidEndDragging:(UIScroller *)scroller willSmoothScroll:(BOOL)smooth {
327 [self _setTileDrawingEnabled:YES];
328 }
329
330 - (void) scrollerDidEndDragging:(UIScroller *)scroller {
331 [self _setTileDrawingEnabled:YES];
332 }
333
334 - (void) loadRequest:(NSURLRequest *)request {
335 error_ = false;
336
337 WebThreadLock();
338 [document_ loadRequest:request];
339 WebThreadUnlock();
340 }
341
342 - (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
343 [self loadRequest:[NSURLRequest
344 requestWithURL:url
345 cachePolicy:policy
346 timeoutInterval:30.0
347 ]];
348 }
349
350 - (void) loadURL:(NSURL *)url {
351 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
352 }
353
354 - (id) init {
355 CGRect frame = {{0, 0}, {320, 480}};
356 frame.size.height -= GSDefaultStatusBarHeight();
357
358 if ((self = [super initWithFrame:frame]) != nil) {
359 struct CGRect bounds([self bounds]);
360
361 scroller_ = [[UIScroller alloc] initWithFrame:bounds];
362 [self addSubview:scroller_];
363
364 [scroller_ setFixedBackgroundPattern:YES];
365 [scroller_ setBackgroundColor:[UIColor blackColor]];
366
367 [scroller_ setScrollingEnabled:YES];
368 [scroller_ setClipsSubviews:YES];
369 [scroller_ setAllowsRubberBanding:YES];
370
371 [scroller_ setDelegate:self];
372 [scroller_ setBounces:YES];
373 [scroller_ setScrollHysteresis:8];
374 [scroller_ setThumbDetectionEnabled:NO];
375 [scroller_ setDirectionalScrolling:YES];
376 [scroller_ setScrollDecelerationFactor:0.99]; /* 0.989324 */
377 [scroller_ setEventMode:YES];
378 [scroller_ setShowBackgroundShadow:NO]; /* YES */
379 [scroller_ setAllowsRubberBanding:YES]; /* Vertical */
380 [scroller_ setAdjustForContentSizeChange:YES]; /* NO */
381
382 CGRect rect([scroller_ bounds]);
383 //rect.size.height = 0;
384
385 WebThreadLock();
386
387 document_ = [[UIWebDocumentView alloc] initWithFrame:rect];
388 WebView *webview([document_ webView]);
389
390 [document_ setBackgroundColor:[UIColor blackColor]];
391 if ([document_ respondsToSelector:@selector(setDrawsBackground:)])
392 [document_ setDrawsBackground:NO];
393 [webview setDrawsBackground:NO];
394
395 [webview setPreferencesIdentifier:@"WebCycript"];
396
397 [document_ setTileSize:CGSizeMake(rect.size.width, 500)];
398
399 if ([document_ respondsToSelector:@selector(enableReachability)])
400 [document_ enableReachability];
401
402 [document_ setAllowsMessaging:YES];
403
404 if ([document_ respondsToSelector:@selector(useSelectionAssistantWithMode:)])
405 [document_ useSelectionAssistantWithMode:0];
406
407 [document_ setTilingEnabled:YES];
408 [document_ setDrawsGrid:NO];
409 [document_ setLogsTilingChanges:NO];
410 [document_ setTileMinificationFilter:kCAFilterNearest];
411
412 if ([document_ respondsToSelector:@selector(setDataDetectorTypes:)])
413 /* XXX: abstractify */
414 [document_ setDataDetectorTypes:0x80000000];
415 else
416 [document_ setDetectsPhoneNumbers:NO];
417
418 [document_ setAutoresizes:YES];
419
420 [document_ setMinimumScale:0.25f forDocumentTypes:0x10];
421 [document_ setMaximumScale:5.00f forDocumentTypes:0x10];
422 [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x10];
423 //[document_ setViewportSize:CGSizeMake(980, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
424
425 [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x2];
426
427 [document_ setMinimumScale:1.00f forDocumentTypes:0x8];
428 [document_ setInitialScale:UIWebViewScalesToFitScale forDocumentTypes:0x8];
429 [document_ setViewportSize:CGSizeMake(320, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x8];
430
431 [document_ _setDocumentType:0x4];
432
433 if ([document_ respondsToSelector:@selector(setZoomsFocusedFormControl:)])
434 [document_ setZoomsFocusedFormControl:YES];
435 [document_ setContentsPosition:7];
436 [document_ setEnabledGestures:0xa];
437 [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeIsZoomRubberBandEnabled];
438 [document_ setValue:[NSNumber numberWithBool:YES] forGestureAttribute:UIGestureAttributeUpdatesScroller];
439
440 [document_ setSmoothsFonts:YES];
441 [document_ setAllowsImageSheet:YES];
442 [webview _setUsesLoaderCache:YES];
443
444 [webview setGroupName:@"CydgetGroup"];
445
446 WebPreferences *preferences([webview preferences]);
447
448 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
449 [webview _setLayoutInterval:0];
450 else
451 [preferences _setLayoutInterval:0];
452
453 [self setViewportWidth:0];
454
455 [document_ setDelegate:self];
456 [document_ setGestureDelegate:self];
457 [document_ setFormEditingDelegate:self];
458 [document_ setInteractionDelegate:self];
459
460 [scroller_ addSubview:document_];
461
462 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
463
464 indirect_ = [[WebCycriptDelegate alloc] initWithDelegate:self];
465
466 [webview setFrameLoadDelegate:indirect_];
467 [webview setPolicyDelegate:indirect_];
468 [webview setResourceLoadDelegate:indirect_];
469 [webview setUIDelegate:indirect_];
470
471 /* XXX: do not turn this on under penalty of extreme pain */
472 [webview setScriptDebugDelegate:nil];
473
474 WebThreadUnlock();
475
476 CGSize indsize([UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite]);
477 indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(281, 12, indsize.width, indsize.height)];
478 [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
479
480 [self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
481 [scroller_ setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
482
483 NSDictionary *configuration([$CydgetController currentConfiguration]);
484 cycript_ = [[configuration objectForKey:@"Cycript"] boolValue];
485 NSString *homepage([configuration objectForKey:@"Homepage"]);
486 [self loadURL:[NSURL URLWithString:homepage]];
487 } return self;
488 }
489
490 - (void) webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
491 [self retain];
492
493 UIActionSheet *sheet = [[[UIActionSheet alloc]
494 initWithTitle:nil
495 buttons:[NSArray arrayWithObjects:@"OK", nil]
496 defaultButtonIndex:0
497 delegate:self
498 context:@"alert"
499 ] autorelease];
500
501 [sheet setBodyText:message];
502 [sheet popupAlertAnimated:YES];
503 }
504
505 - (BOOL) webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
506 [self retain];
507
508 UIActionSheet *sheet = [[[UIActionSheet alloc]
509 initWithTitle:nil
510 buttons:[NSArray arrayWithObjects:@"OK", @"CANCEL", nil]
511 defaultButtonIndex:0
512 delegate:indirect_
513 context:@"confirm"
514 ] autorelease];
515
516 [sheet setNumberOfRows:1];
517 [sheet setBodyText:message];
518 [sheet popupAlertAnimated:YES];
519
520 NSRunLoop *loop([NSRunLoop currentRunLoop]);
521 NSDate *future([NSDate distantFuture]);
522
523 while (confirm_ == nil && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
524
525 NSNumber *confirm([confirm_ autorelease]);
526 confirm_ = nil;
527
528 [self autorelease];
529 return [confirm boolValue];
530 }
531
532 /* XXX: WebThreadLock? */
533 - (void) _fixScroller:(CGRect)bounds {
534 float extra;
535 if (!editing_)
536 extra = 0;
537 else {
538 UIFormAssistant *assistant([UIFormAssistant sharedFormAssistant]);
539 CGRect peripheral([assistant peripheralFrame]);
540 extra = peripheral.size.height;
541 }
542
543 CGRect subrect([scroller_ frame]);
544 subrect.size.height -= [TPBottomLockBar defaultHeight];
545 subrect.size.height -= extra;
546 [scroller_ setScrollerIndicatorSubrect:subrect];
547
548 #undef NSSize
549 NSSize visible(NSMakeSize(subrect.size.width, subrect.size.height));
550 [document_ setValue:[NSValue valueWithSize:visible] forGestureAttribute:UIGestureAttributeVisibleSize];
551
552 CGSize size(size_);
553 size.height += extra;
554 size.height += [TPBottomLockBar defaultHeight];
555 [scroller_ setContentSize:size];
556
557 [scroller_ releaseRubberBandIfNecessary];
558 }
559
560 - (void) fixScroller {
561 CGRect bounds([document_ documentBounds]);
562 [self _fixScroller:bounds];
563 }
564
565 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame {
566 size_ = frame.size;
567 [self _fixScroller:frame];
568 }
569
570 - (void) view:(UIView *)sender didSetFrame:(CGRect)frame oldFrame:(CGRect)old {
571 [self view:sender didSetFrame:frame];
572 }
573
574 - (void) webView:(WebView *)sender willBeginEditingFormElement:(id)element {
575 editing_ = true;
576 }
577
578 - (void) webView:(WebView *)sender didBeginEditingFormElement:(id)element {
579 [self fixScroller];
580 }
581
582 - (void) webViewDidEndEditingFormElements:(WebView *)sender {
583 editing_ = false;
584 [self fixScroller];
585 }
586
587 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
588 if (cycript_ && CYSetupContext != NULL) {
589 WebView *webview([document_ webView]);
590 WebFrame *frame([webview mainFrame]);
591 JSGlobalContextRef context([frame globalContext]);
592 CYSetupContext(context);
593 }
594 }
595
596 - (bool) isLoading {
597 return [loading_ count] != 0;
598 }
599
600 - (void) reloadButtons {
601 if ([self isLoading])
602 [indicator_ startAnimation];
603 else
604 [indicator_ stopAnimation];
605 }
606
607 - (void) _finishLoading {
608 size_t count([loading_ count]);
609 /*if (count == 0)
610 [self autorelease];*/
611 if (reloading_ || count != 0)
612 return;
613 [self reloadButtons];
614 }
615
616 - (BOOL) webView:(WebView *)sender shouldScrollToPoint:(struct CGPoint)point forFrame:(WebFrame *)frame {
617 return [document_ webView:sender shouldScrollToPoint:point forFrame:frame];
618 }
619
620 - (void) webView:(WebView *)sender didReceiveViewportArguments:(id)arguments forFrame:(WebFrame *)frame {
621 return [document_ webView:sender didReceiveViewportArguments:arguments forFrame:frame];
622 }
623
624 - (void) webView:(WebView *)sender needsScrollNotifications:(id)notifications forFrame:(WebFrame *)frame {
625 return [document_ webView:sender needsScrollNotifications:notifications forFrame:frame];
626 }
627
628 - (void) webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame {
629 return [document_ webView:sender didCommitLoadForFrame:frame];
630 }
631
632 - (void) webView:(WebView *)sender didReceiveDocTypeForFrame:(WebFrame *)frame {
633 return [document_ webView:sender didReceiveDocTypeForFrame:frame];
634 }
635
636 - (void) webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
637 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
638 [self _finishLoading];
639 return [document_ webView:sender didFinishLoadForFrame:frame];
640 }
641
642 - (void) webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
643 /*if ([loading_ count] == 0)
644 [self retain];*/
645 [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
646
647 if ([frame parentFrame] == nil) {
648 [document_ resignFirstResponder];
649
650 reloading_ = false;
651
652 [scroller_ scrollPointVisibleAtTopLeft:CGPointZero];
653
654 if ([scroller_ respondsToSelector:@selector(setZoomScale:duration:)])
655 [scroller_ setZoomScale:1 duration:0];
656 else if ([scroller_ respondsToSelector:@selector(_setZoomScale:duration:)])
657 [scroller_ _setZoomScale:1 duration:0];
658 /*else if ([scroller_ respondsToSelector:@selector(setZoomScale:animated:)])
659 [scroller_ setZoomScale:1 animated:NO];*/
660
661 CGRect rect([scroller_ bounds]);
662 //rect.size.height = 0;
663 [document_ setFrame:rect];
664 }
665
666 [self reloadButtons];
667 }
668
669 - (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
670 /*if ([frame parentFrame] == nil)
671 [self autorelease];*/
672
673 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
674 [self _finishLoading];
675
676 if (reloading_)
677 return;
678
679 if ([frame parentFrame] == nil) {
680 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
681 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
682 [[error localizedDescription] stringByAddingPercentEscapes]
683 ]]];
684
685 error_ = true;
686 }
687 }
688
689 - (void) webView:(WebView *)sender didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
690 [self _didFailWithError:error forFrame:frame];
691 }
692
693 - (void) webView:(WebView *)sender didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
694 [self _didFailWithError:error forFrame:frame];
695 }
696
697 - (void) webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary {
698 fprintf(stderr, "Console:%s\n", [[dictionary description] UTF8String]);
699 }
700
701 @end
702
703 @interface WebCycriptLockScreenController : SBAwayViewPluginController {
704 }
705
706 @end
707
708 /*extern "C" void _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(JSC::Parser *, JSC::JSGlobalData *, int *, JSC::UString *);
709 MSHook(void, _ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, JSC::Parser *_this, JSC::JSGlobalData *data, int *line, JSC::UString *message) {
710 return __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE(_this, data, line, message);
711 }*/
712
713 @implementation WebCycriptLockScreenController
714
715 + (void) initialize {
716 //MSHookFunction(&_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, MSHake(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE));
717 if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
718 CYSetupContext = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CYSetupContext"));
719 }
720
721 + (id) rootViewController {
722 return [[[self alloc] init] autorelease];
723 }
724
725 - (void) loadView {
726 [self setView:[[[WebCydgetLockScreenView alloc] init] autorelease]];
727 }
728
729 @end