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