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