]> git.saurik.com Git - cydia.git/blame - UICaboodle/BrowserView.mm
Use lowercase identifiers always, even internally.
[cydia.git] / UICaboodle / BrowserView.mm
CommitLineData
c21004b9
JF
1#include <UIKit/UIKit.h>
2#include "iPhonePrivate.h"
3
4#include "UCPlatform.h"
5
275d8115
JF
6#include <UICaboodle/BrowserView.h>
7#include <UICaboodle/UCLocalize.h>
43f3d7f6 8
c21004b9 9//#include <QuartzCore/CALayer.h>
43f3d7f6
JF
10// XXX: fix the minimum requirement
11extern NSString * const kCAFilterNearest;
22f8bed9 12
caa427d1 13#include <WebCore/WebCoreThread.h>
c21004b9
JF
14
15#include <WebKit/WebPolicyDelegate.h>
16#include <WebKit/WebPreferences.h>
17
18#include <WebKit/DOMCSSPrimitiveValue.h>
19#include <WebKit/DOMCSSStyleDeclaration.h>
20#include <WebKit/DOMDocument.h>
21#include <WebKit/DOMHTMLBodyElement.h>
22#include <WebKit/DOMRGBColor.h>
23
24//#include <WebCore/Page.h>
25//#include <WebCore/Settings.h>
caa427d1 26
43f3d7f6
JF
27#include "substrate.h"
28
adcb0422 29#define ForSaurik 0
bfc87a4d 30
2634b249
JF
31template <typename Type_>
32static inline void CYRelease(Type_ &value) {
33 if (value != nil) {
34 [value release];
35 value = nil;
36 }
37}
04fe1349 38
9c1605e2
JF
39float CYScrollViewDecelerationRateNormal;
40
2634b249
JF
41@interface WebView (Apple)
42- (void) _setLayoutInterval:(float)interval;
43@end
44
45@interface WebPreferences (Apple)
46+ (void) _setInitialDefaultTextEncodingToSystemEncoding;
47- (void) _setLayoutInterval:(NSInteger)interval;
48- (void) setOfflineWebApplicationCacheEnabled:(BOOL)enabled;
49@end
327624b6 50
aa5d0de7 51/* Indirect Delegate {{{ */
c21004b9
JF
52@interface IndirectDelegate : NSObject <
53 HookProtocol
54> {
aa5d0de7
JF
55 _transient volatile id delegate_;
56}
57
58- (void) setDelegate:(id)delegate;
59- (id) initWithDelegate:(id)delegate;
60@end
61
62@implementation IndirectDelegate
63
64- (void) setDelegate:(id)delegate {
65 delegate_ = delegate;
66}
67
68- (id) initWithDelegate:(id)delegate {
69 delegate_ = delegate;
70 return self;
71}
72
c21004b9
JF
73- (void) didDismissModalViewController {
74 if (delegate_ != nil)
75 return [delegate_ didDismissModalViewController];
76}
77
caa427d1
JF
78- (IMP) methodForSelector:(SEL)sel {
79 if (IMP method = [super methodForSelector:sel])
80 return method;
81 fprintf(stderr, "methodForSelector:[%s] == NULL\n", sel_getName(sel));
82 return NULL;
83}
84
aa5d0de7 85- (BOOL) respondsToSelector:(SEL)sel {
caa427d1
JF
86 if ([super respondsToSelector:sel])
87 return YES;
88 // XXX: WebThreadCreateNSInvocation returns nil
89 //fprintf(stderr, "[%s]R?%s\n", class_getName(self->isa), sel_getName(sel));
90 return delegate_ == nil ? NO : [delegate_ respondsToSelector:sel];
aa5d0de7
JF
91}
92
93- (NSMethodSignature *) methodSignatureForSelector:(SEL)sel {
caa427d1
JF
94 if (NSMethodSignature *method = [super methodSignatureForSelector:sel])
95 return method;
96 //fprintf(stderr, "[%s]S?%s\n", class_getName(self->isa), sel_getName(sel));
aa5d0de7
JF
97 if (delegate_ != nil)
98 if (NSMethodSignature *sig = [delegate_ methodSignatureForSelector:sel])
99 return sig;
100 // XXX: I fucking hate Apple so very very bad
101 return [NSMethodSignature signatureWithObjCTypes:"v@:"];
102}
103
104- (void) forwardInvocation:(NSInvocation *)inv {
105 SEL sel = [inv selector];
106 if (delegate_ != nil && [delegate_ respondsToSelector:sel])
107 [inv invokeWithTarget:delegate_];
108}
109
110@end
111/* }}} */
112
43f3d7f6 113@implementation WebScriptObject (UICaboodle)
caa427d1 114
96f3833b 115- (NSUInteger) count {
caa427d1
JF
116 id length([self valueForKey:@"length"]);
117 if ([length respondsToSelector:@selector(intValue)])
118 return [length intValue];
119 else
120 return 0;
121}
122
123- (id) objectAtIndex:(unsigned)index {
124 return [self webScriptValueAtIndex:index];
125}
126
127@end
128
2634b249
JF
129// CYWebPolicyDecision* {{{
130enum CYWebPolicyDecision {
131 CYWebPolicyDecisionUnknown,
132 CYWebPolicyDecisionDownload,
133 CYWebPolicyDecisionIgnore,
134 CYWebPolicyDecisionUse,
135};
136
137@interface CYWebPolicyDecisionMediator : NSObject <
138 WebPolicyDecisionListener
139> {
140 id<WebPolicyDecisionListener> listener_;
141 CYWebPolicyDecision decision_;
69b82e6a 142}
2634b249
JF
143
144- (id) initWithListener:(id<WebPolicyDecisionListener>)listener;
145
146- (CYWebPolicyDecision) decision;
147- (bool) decided;
148- (bool) decide;
149
69b82e6a
RP
150@end
151
2634b249 152@implementation CYWebPolicyDecisionMediator
69b82e6a 153
2634b249
JF
154- (id) initWithListener:(id<WebPolicyDecisionListener>)listener {
155 if ((self = [super init]) != nil) {
156 listener_ = listener;
157 } return self;
158}
69b82e6a 159
2634b249
JF
160- (CYWebPolicyDecision) decision {
161 return decision_;
162}
163
164- (bool) decided {
165 return decision_ != CYWebPolicyDecisionUnknown;
166}
167
168- (bool) decide {
169 switch (decision_) {
170 case CYWebPolicyDecisionUnknown:
171 default:
0352f238 172 NSLog(@"CYWebPolicyDecisionUnknown");
2634b249
JF
173 return false;
174
175 case CYWebPolicyDecisionDownload: [listener_ download]; break;
176 case CYWebPolicyDecisionIgnore: [listener_ ignore]; break;
177 case CYWebPolicyDecisionUse: [listener_ use]; break;
178 }
179
180 return true;
181}
182
183- (void) download {
184 decision_ = CYWebPolicyDecisionDownload;
69b82e6a
RP
185}
186
2634b249
JF
187- (void) ignore {
188 decision_ = CYWebPolicyDecisionIgnore;
189}
190
191- (void) use {
192 decision_ = CYWebPolicyDecisionUse;
69b82e6a
RP
193}
194
195@end
2634b249 196// }}}
69b82e6a 197
2634b249 198@implementation CYWebView : UIWebView
ea173384 199
2634b249
JF
200- (id) initWithFrame:(CGRect)frame {
201 if ((self = [super initWithFrame:frame]) != nil) {
202 } return self;
203}
ea173384 204
2634b249
JF
205- (void) dealloc {
206 [super dealloc];
207}
22f8bed9 208
2634b249
JF
209- (id<CYWebViewDelegate>) delegate {
210 return (id<CYWebViewDelegate>) [super delegate];
211}
22f8bed9 212
2634b249 213/*- (WebView *) webView:(WebView *)view createWebViewWithRequest:(NSURLRequest *)request {
7880ff90
JF
214 id<CYWebViewDelegate> delegate([self delegate]);
215 WebView *created(nil);
216 if (created == nil && [delegate respondsToSelector:@selector(webView:createWebViewWithRequest:)])
217 created = [delegate webView:view createWebViewWithRequest:request];
d49718a1 218 if (created == nil && [UIWebView instancesRespondToSelector:@selector(webView:createWebViewWithRequest:)])
7880ff90
JF
219 created = [super webView:view createWebViewWithRequest:request];
220 return created;
2634b249 221}*/
ea173384 222
d49718a1 223// webView:decidePolicyForNavigationAction:request:frame:decisionListener: (2.0+) {{{
2634b249 224- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
d49718a1 225 id<CYWebViewDelegate> delegate([self delegate]);
2634b249 226 CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]);
d49718a1
JF
227 if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)])
228 [delegate webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator];
229 if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)])
2634b249
JF
230 [super webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator];
231 [mediator decide];
232}
d49718a1
JF
233// }}}
234// webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: (3.0+) {{{
235static void $UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *action, NSURLRequest *request, NSString *frame, id<WebPolicyDecisionListener> listener) {
236 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
237 if ([uiWebView respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
238 [uiWebView webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:listener];
239}
ea173384 240
2634b249 241- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
d49718a1 242 id<CYWebViewDelegate> delegate([self delegate]);
2634b249 243 CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]);
d49718a1
JF
244 if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
245 [delegate webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator];
246 if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)])
2634b249
JF
247 [super webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator];
248 [mediator decide];
249}
d49718a1 250// }}}
3a1ff609 251// webView:didClearWindowObject:forFrame: (3.2+) {{{
d49718a1
JF
252static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) {
253 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
254 if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
255 [uiWebView webView:view didClearWindowObject:window forFrame:frame];
256}
327624b6 257
2634b249 258- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
d49718a1
JF
259 id<CYWebViewDelegate> delegate([self delegate]);
260 if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)])
261 [delegate webView:view didClearWindowObject:window forFrame:frame];
262 if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)])
2634b249
JF
263 [super webView:view didClearWindowObject:window forFrame:frame];
264}
d49718a1
JF
265// }}}
266// webView:didFailLoadWithError:forFrame: (2.0+) {{{
2634b249 267- (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
d49718a1
JF
268 id<CYWebViewDelegate> delegate([self delegate]);
269 if ([delegate respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)])
270 [delegate webView:view didFailLoadWithError:error forFrame:frame];
271 if ([UIWebView instancesRespondToSelector:@selector(webView:didFailLoadWithError:forFrame:)])
2634b249 272 [super webView:view didFailLoadWithError:error forFrame:frame];
ea173384 273}
d49718a1
JF
274// }}}
275// webView:didFailProvisionalLoadWithError:forFrame: (2.0+) {{{
2634b249 276- (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
d49718a1
JF
277 id<CYWebViewDelegate> delegate([self delegate]);
278 if ([delegate respondsToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)])
279 [delegate webView:view didFailProvisionalLoadWithError:error forFrame:frame];
280 if ([UIWebView instancesRespondToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)])
2634b249
JF
281 [super webView:view didFailProvisionalLoadWithError:error forFrame:frame];
282}
d49718a1
JF
283// }}}
284// webView:didFinishLoadForFrame: (2.0+) {{{
2634b249 285- (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame {
d49718a1
JF
286 id<CYWebViewDelegate> delegate([self delegate]);
287 if ([delegate respondsToSelector:@selector(webView:didFinishLoadForFrame:)])
288 [delegate webView:view didFinishLoadForFrame:frame];
289 if ([UIWebView instancesRespondToSelector:@selector(webView:didFinishLoadForFrame:)])
2634b249
JF
290 [super webView:view didFinishLoadForFrame:frame];
291}
d49718a1 292// }}}
3a1ff609 293// webView:didReceiveTitle:forFrame: (3.2+) {{{
d49718a1
JF
294static void $UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSString *title, WebFrame *frame) {
295 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
296 if ([uiWebView respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)])
297 [uiWebView webView:view didReceiveTitle:title forFrame:frame];
298}
22f8bed9 299
2634b249 300- (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
d49718a1
JF
301 id<CYWebViewDelegate> delegate([self delegate]);
302 if ([delegate respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)])
303 [delegate webView:view didReceiveTitle:title forFrame:frame];
304 if ([UIWebView instancesRespondToSelector:@selector(webView:didReceiveTitle:forFrame:)])
2634b249
JF
305 [super webView:view didReceiveTitle:title forFrame:frame];
306}
d49718a1
JF
307// }}}
308// webView:didStartProvisionalLoadForFrame: (2.0+) {{{
2634b249 309- (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame {
d49718a1
JF
310 id<CYWebViewDelegate> delegate([self delegate]);
311 if ([delegate respondsToSelector:@selector(webView:didStartProvisionalLoadForFrame:)])
312 [delegate webView:view didStartProvisionalLoadForFrame:frame];
313 if ([UIWebView instancesRespondToSelector:@selector(webView:didStartProvisionalLoadForFrame:)])
2634b249
JF
314 [super webView:view didStartProvisionalLoadForFrame:frame];
315}
d49718a1 316// }}}
3a1ff609 317// webView:resource:willSendRequest:redirectResponse:fromDataSource: (3.2+) {{{
d49718a1
JF
318static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, id identifier, NSURLRequest *request, NSURLResponse *response, WebDataSource *source) {
319 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
320 if ([uiWebView respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
f97db630
JF
321 request = [uiWebView webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
322 return request;
d49718a1 323}
22f8bed9 324
2634b249 325- (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
d49718a1
JF
326 id<CYWebViewDelegate> delegate([self delegate]);
327 if ([UIWebView instancesRespondToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
2634b249 328 request = [super webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
d49718a1
JF
329 if ([delegate respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)])
330 request = [delegate webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source];
331 return request;
2634b249 332}
d49718a1 333// }}}
427754d6 334// webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: (2.1+) {{{
2634b249 335- (void) webView:(WebView *)view runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
d49718a1
JF
336 id<CYWebViewDelegate> delegate([self delegate]);
337 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)])
338 // XXX: check delegate
339 if ([delegate webView:view shouldRunJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame])
2634b249
JF
340 [super webView:view runJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame];
341}
d49718a1 342// }}}
427754d6 343// webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame: (2.1+) {{{
2634b249 344- (BOOL) webView:(WebView *)view runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
d49718a1
JF
345 id<CYWebViewDelegate> delegate([self delegate]);
346 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)])
347 // XXX: check delegate
348 if ([delegate webView:view shouldRunJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame])
2634b249
JF
349 return [super webView:view runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame];
350 return NO;
351}
d49718a1 352// }}}
427754d6 353// webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame: (2.1+) {{{
2634b249 354- (NSString *) webView:(WebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
d49718a1
JF
355 id<CYWebViewDelegate> delegate([self delegate]);
356 if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)])
357 // XXX: check delegate
358 if ([delegate webView:view shouldRunJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame])
2634b249
JF
359 return [super webView:view runJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame];
360 return nil;
361}
d49718a1 362// }}}
3a1ff609 363// webViewClose: (3.2+) {{{
d49718a1
JF
364static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view) {
365 UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView"));
366 if ([uiWebView respondsToSelector:@selector(webViewClose:)])
367 [uiWebView webViewClose:view];
368}
600d005d 369
2634b249 370- (void) webViewClose:(WebView *)view {
d49718a1
JF
371 id<CYWebViewDelegate> delegate([self delegate]);
372 if ([delegate respondsToSelector:@selector(webViewClose:)])
373 [delegate webViewClose:view];
374 if ([UIWebView instancesRespondToSelector:@selector(webViewClose:)])
2634b249
JF
375 [super webViewClose:view];
376}
d49718a1
JF
377// }}}
378
379+ (void) initialize {
380 if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) {
381 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), (IMP) &$UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$, "v28@0:4@8@12@16@20@24");
382 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16");
383 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didReceiveTitle:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$, "v20@0:4@8@12@16");
384 class_addMethod($UIWebViewWebViewDelegate, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), (IMP) &$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$, "@28@0:4@8@12@16@20@24");
385 class_addMethod($UIWebViewWebViewDelegate, @selector(webViewClose:), (IMP) &$UIWebViewWebViewDelegate$webViewClose$, "v12@0:4@8");
386 }
387}
22f8bed9 388
2634b249 389@end
caa427d1 390
2634b249
JF
391#define ShowInternals 0
392#define LogBrowser 1
22f8bed9 393
2634b249 394#define lprintf(args...) fprintf(stderr, args)
22f8bed9 395
2634b249
JF
396@implementation BrowserController
397
398#if ShowInternals
399#include "UICaboodle/UCInternal.h"
22f8bed9
JF
400#endif
401
2634b249
JF
402+ (void) _initialize {
403 [WebPreferences _setInitialDefaultTextEncodingToSystemEncoding];
9c1605e2
JF
404
405 if (float *_UIScrollViewDecelerationRateNormal = reinterpret_cast<float *>(dlsym(RTLD_DEFAULT, "UIScrollViewDecelerationRateNormal")))
406 CYScrollViewDecelerationRateNormal = *_UIScrollViewDecelerationRateNormal;
407 else // XXX: this actually might be fast on some older systems: we should look into this
408 CYScrollViewDecelerationRateNormal = 0.998;
2634b249
JF
409}
410
411- (void) dealloc {
412#if LogBrowser
413 NSLog(@"[BrowserController dealloc]");
414#endif
415
416 [webview_ setDelegate:nil];
417
418 [indirect_ setDelegate:nil];
22f8bed9
JF
419 [indirect_ release];
420
2634b249
JF
421 if (challenge_ != nil)
422 [challenge_ release];
caa427d1 423
2634b249 424 //NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
22f8bed9 425
2634b249
JF
426 if (custom_ != nil)
427 [custom_ release];
22f8bed9
JF
428 if (style_ != nil)
429 [style_ release];
2634b249 430
22f8bed9
JF
431 if (function_ != nil)
432 [function_ release];
12b59862
JF
433 if (closer_ != nil)
434 [closer_ release];
22f8bed9 435
0dceb29b
JF
436 if (sensitive_ != nil)
437 [sensitive_ release];
22f8bed9
JF
438 if (title_ != nil)
439 [title_ release];
2634b249
JF
440
441 [reloaditem_ release];
442 [loadingitem_ release];
443
444 [indicator_ release];
bc11cf5b 445
22f8bed9
JF
446 [super dealloc];
447}
448
449- (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
450 [self loadRequest:[NSURLRequest
451 requestWithURL:url
452 cachePolicy:policy
77801ff1 453 timeoutInterval:120.0
22f8bed9
JF
454 ]];
455}
456
457- (void) loadURL:(NSURL *)url {
458 [self loadURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy];
459}
460
22f8bed9 461- (void) loadRequest:(NSURLRequest *)request {
0352f238
JF
462#if LogBrowser
463 NSLog(@"loadRequest:%@", request);
464#endif
465
fe468f45 466 error_ = false;
caa427d1
JF
467
468 WebThreadLock();
2634b249 469 [webview_ loadRequest:request];
caa427d1 470 WebThreadUnlock();
22f8bed9
JF
471}
472
473- (void) reloadURL {
22f8bed9
JF
474 if (request_ == nil)
475 return;
476
477 if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
fe468f45 478 [self loadRequest:request_];
22f8bed9 479 else {
79ed082a 480 UIAlertView *alert = [[[UIAlertView alloc]
43f3d7f6 481 initWithTitle:UCLocalize("RESUBMIT_FORM")
79ed082a 482 message:nil
22f8bed9 483 delegate:self
79ed082a
GP
484 cancelButtonTitle:UCLocalize("CANCEL")
485 otherButtonTitles:UCLocalize("SUBMIT"), nil
22f8bed9 486 ] autorelease];
2634b249 487
79ed082a
GP
488 [alert setContext:@"submit"];
489 [alert show];
22f8bed9
JF
490 }
491}
492
22f8bed9 493- (void) setButtonImage:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
2634b249
JF
494 if (custom_ != nil)
495 [custom_ autorelease];
496 custom_ = button == nil ? nil : [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:button]]] retain];
22f8bed9
JF
497
498 if (style_ != nil)
499 [style_ autorelease];
500 style_ = style == nil ? nil : [style retain];
501
502 if (function_ != nil)
503 [function_ autorelease];
504 function_ = function == nil ? nil : [function retain];
12b59862 505
bc11cf5b 506 [self applyRightButton];
22f8bed9
JF
507}
508
509- (void) setButtonTitle:(NSString *)button withStyle:(NSString *)style toFunction:(id)function {
2634b249
JF
510 if (custom_ != nil)
511 [custom_ autorelease];
512 custom_ = button == nil ? nil : [button retain];
22f8bed9
JF
513
514 if (style_ != nil)
515 [style_ autorelease];
516 style_ = style == nil ? nil : [style retain];
517
518 if (function_ != nil)
519 [function_ autorelease];
520 function_ = function == nil ? nil : [function retain];
12b59862 521
bc11cf5b 522 [self applyRightButton];
22f8bed9 523}
22f8bed9 524
caa427d1
JF
525- (void) setPopupHook:(id)function {
526 if (closer_ != nil)
527 [closer_ autorelease];
528 closer_ = function == nil ? nil : [function retain];
529}
530
2634b249
JF
531- (void) setViewportWidth:(float)width {
532 width_ = width != 0 ? width : [[self class] defaultWidth];
533 [[webview_ _documentView] setViewportSize:CGSizeMake(width_, UIWebViewGrowsAndShrinksToFitHeight) forDocumentTypes:0x10];
22f8bed9
JF
534}
535
2634b249
JF
536- (void) _openMailToURL:(NSURL *)url {
537 [[UIApplication sharedApplication] openURL:url];// asPanel:YES];
22f8bed9
JF
538}
539
2634b249
JF
540- (bool) _allowJavaScriptPanel {
541 return true;
22f8bed9
JF
542}
543
2634b249
JF
544- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
545 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
546 [self _didFinishLoading];
22f8bed9 547
2634b249 548 if ([error code] == NSURLErrorCancelled)
22f8bed9
JF
549 return;
550
caa427d1 551 if ([frame parentFrame] == nil) {
2634b249
JF
552 [self loadURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",
553 [[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]] absoluteString],
554 [[error localizedDescription] stringByAddingPercentEscapes]
555 ]]];
22f8bed9 556
2634b249
JF
557 error_ = true;
558 }
559}
caa427d1 560
2634b249
JF
561// CYWebViewDelegate {{{
562- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
563#if LogBrowser
564 NSLog(@"decidePolicyForNavigationAction:%@ request:%@ frame:%@", action, request, frame);
565#endif
600d005d 566
ee32e123
JF
567 if ([frame parentFrame] == nil) {
568 if (!error_) {
569 if (request_ != nil)
570 [request_ autorelease];
571 if (request == nil)
572 request_ = nil;
573 else
574 request_ = [request retain];
575 }
caa427d1 576 }
22f8bed9
JF
577}
578
2634b249
JF
579- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
580#if LogBrowser
581 NSLog(@"decidePolicyForNewWindowAction:%@ request:%@ newFrameName:%@", action, request, frame);
582#endif
2e6c1426 583
2634b249
JF
584 NSURL *url([request URL]);
585 if (url == nil)
586 return;
bc11cf5b 587
2634b249
JF
588 if ([frame isEqualToString:@"_open"])
589 [delegate_ openURL:url];
2e6c1426 590
2634b249
JF
591 NSString *scheme([[url scheme] lowercaseString]);
592 if ([scheme isEqualToString:@"mailto"])
593 [self _openMailToURL:url];
a5938ea5 594
2634b249 595 CYViewController *page([delegate_ pageForURL:url hasTag:NULL]);
2fad210a 596
2634b249
JF
597 if (page == nil) {
598 BrowserController *browser([[[class_ alloc] init] autorelease]);
599 [browser loadRequest:request];
600 page = browser;
bc11cf5b 601 }
ce041f4f 602
2634b249 603 [page setDelegate:delegate_];
b5e7eebb 604
2634b249
JF
605 if (![frame isEqualToString:@"_popup"]) {
606 [[self navigationItem] setTitle:title_];
b5e7eebb 607
2634b249
JF
608 [[self navigationController] pushViewController:page animated:YES];
609 } else {
610 UCNavigationController *navigation([[[UCNavigationController alloc] init] autorelease]);
22f8bed9 611
2634b249
JF
612 [navigation setHook:indirect_];
613 [navigation setDelegate:delegate_];
22f8bed9 614
2634b249
JF
615 [navigation setViewControllers:[NSArray arrayWithObject:page]];
616
617 [[page navigationItem] setLeftBarButtonItem:[[[UIBarButtonItem alloc]
618 initWithTitle:UCLocalize("CLOSE")
619 style:UIBarButtonItemStylePlain
620 target:page
621 action:@selector(close)
622 ] autorelease]];
623
624 [[self navigationController] presentModalViewController:navigation animated:YES];
625 }
22f8bed9 626
2634b249 627 [listener ignore];
22f8bed9
JF
628}
629
2634b249 630- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
22f8bed9
JF
631}
632
2634b249
JF
633- (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
634#if LogBrowser
635 NSLog(@"didFailLoadWithError:%@ forFrame:%@", error, frame);
636#endif
637
638 [self _didFailWithError:error forFrame:frame];
22f8bed9
JF
639}
640
2634b249
JF
641- (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame {
642#if LogBrowser
643 NSLog(@"didFailProvisionalLoadWithError:%@ forFrame:%@", error, frame);
644#endif
645
646 [self _didFailWithError:error forFrame:frame];
22f8bed9
JF
647}
648
2634b249 649- (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame {
7592e053 650 [loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
22f8bed9 651
caa427d1 652 if ([frame parentFrame] == nil) {
22f8bed9
JF
653 if (DOMDocument *document = [frame DOMDocument])
654 if (DOMNodeList<NSFastEnumeration> *bodies = [document getElementsByTagName:@"body"])
96f3833b 655 for (DOMHTMLBodyElement *body in (id) bodies) {
22f8bed9
JF
656 DOMCSSStyleDeclaration *style([document getComputedStyle:body pseudoElement:nil]);
657
658 bool colored(false);
659
660 if (DOMCSSPrimitiveValue *color = static_cast<DOMCSSPrimitiveValue *>([style getPropertyCSSValue:@"background-color"])) {
fe468f45
JF
661 if ([color primitiveType] == DOM_CSS_RGBCOLOR) {
662 DOMRGBColor *rgb([color getRGBColorValue]);
663
664 float red([[rgb red] getFloatValue:DOM_CSS_NUMBER]);
665 float green([[rgb green] getFloatValue:DOM_CSS_NUMBER]);
666 float blue([[rgb blue] getFloatValue:DOM_CSS_NUMBER]);
667 float alpha([[rgb alpha] getFloatValue:DOM_CSS_NUMBER]);
668
669 UIColor *uic(nil);
670
671 if (red == 0xc7 && green == 0xce && blue == 0xd5)
4f6056df 672 uic = [UIColor groupTableViewBackgroundColor];
fe468f45
JF
673 else if (alpha != 0)
674 uic = [UIColor
675 colorWithRed:(red / 255)
676 green:(green / 255)
677 blue:(blue / 255)
678 alpha:alpha
679 ];
680
681 if (uic != nil) {
682 colored = true;
683 [scroller_ setBackgroundColor:uic];
684 }
22f8bed9
JF
685 }
686 }
687
688 if (!colored)
4f6056df 689 [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
22f8bed9
JF
690 break;
691 }
692 }
693
2634b249 694 [self _didFinishLoading];
22f8bed9
JF
695}
696
2634b249
JF
697- (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame {
698 if ([frame parentFrame] != nil)
699 return;
caa427d1 700
2634b249
JF
701 title_ = [title retain];
702 [[self navigationItem] setTitle:title_];
703}
22f8bed9 704
2634b249
JF
705- (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame {
706 [loading_ addObject:[NSValue valueWithNonretainedObject:frame]];
7592e053 707
caa427d1 708 if ([frame parentFrame] == nil) {
2634b249
JF
709 CYRelease(title_);
710 CYRelease(custom_);
711 CYRelease(style_);
712 CYRelease(function_);
713 CYRelease(closer_);
714
715 // XXX: do we still need to do this?
716 [[self navigationItem] setTitle:nil];
caa427d1 717 }
fe468f45 718
2634b249 719 [self _didStartLoading];
caa427d1
JF
720}
721
2634b249 722- (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
0352f238
JF
723#if LogBrowser
724 NSLog(@"resource:%@ willSendRequest:%@ redirectResponse:%@ fromDataSource:%@", identifier, request, response, source);
725#endif
726
2634b249 727 return request;
22f8bed9
JF
728}
729
2634b249
JF
730- (bool) webView:(WebView *)view shouldRunJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
731 return [self _allowJavaScriptPanel];
22f8bed9
JF
732}
733
2634b249
JF
734- (bool) webView:(WebView *)view shouldRunJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
735 return [self _allowJavaScriptPanel];
600d005d
JF
736}
737
2634b249
JF
738- (bool) webView:(WebView *)view shouldRunJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame {
739 return [self _allowJavaScriptPanel];
600d005d
JF
740}
741
2634b249
JF
742- (void) webViewClose:(WebView *)view {
743 [self close];
600d005d 744}
2634b249 745// }}}
600d005d 746
2634b249
JF
747- (void) close {
748 [[self navigationController] dismissModalViewControllerAnimated:YES];
600d005d
JF
749}
750
2634b249
JF
751- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)button {
752 NSString *context([alert context]);
600d005d 753
2634b249
JF
754 if ([context isEqualToString:@"sensitive"]) {
755 switch (button) {
756 case 1:
757 sensitive_ = [NSNumber numberWithBool:YES];
758 break;
600d005d 759
2634b249
JF
760 case 2:
761 sensitive_ = [NSNumber numberWithBool:NO];
762 break;
763 }
600d005d 764
2634b249
JF
765 [alert dismissWithClickedButtonIndex:-1 animated:YES];
766 } else if ([context isEqualToString:@"challenge"]) {
767 id<NSURLAuthenticationChallengeSender> sender([challenge_ sender]);
caa427d1 768
2634b249
JF
769 switch (button) {
770 case 1: {
771 NSString *username([[alert textFieldAtIndex:0] text]);
772 NSString *password([[alert textFieldAtIndex:1] text]);
600d005d 773
2634b249 774 NSURLCredential *credential([NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]);
600d005d 775
2634b249
JF
776 [sender useCredential:credential forAuthenticationChallenge:challenge_];
777 } break;
600d005d 778
2634b249
JF
779 case 2:
780 [sender cancelAuthenticationChallenge:challenge_];
781 break;
600d005d 782
2634b249
JF
783 _nodefault
784 }
600d005d 785
2634b249
JF
786 [challenge_ release];
787 challenge_ = nil;
600d005d 788
2634b249
JF
789 [alert dismissWithClickedButtonIndex:-1 animated:YES];
790 } else if ([context isEqualToString:@"submit"]) {
791 switch (button) {
792 case 1:
793 break;
600d005d 794
2634b249
JF
795 case 2:
796 if (request_ != nil) {
797 WebThreadLock();
798 [webview_ loadRequest:request_];
799 WebThreadUnlock();
800 }
801 break;
600d005d 802
2634b249
JF
803 _nodefault
804 }
600d005d 805
2634b249
JF
806 [alert dismissWithClickedButtonIndex:-1 animated:YES];
807 }
600d005d
JF
808}
809
2634b249
JF
810- (UIBarButtonItemStyle) rightButtonStyle {
811 if (style_ == nil) normal:
812 return UIBarButtonItemStylePlain;
813 else if ([style_ isEqualToString:@"Normal"])
814 return UIBarButtonItemStylePlain;
815 else if ([style_ isEqualToString:@"Highlighted"])
816 return UIBarButtonItemStyleDone;
817 else goto normal;
600d005d
JF
818}
819
2634b249
JF
820- (UIBarButtonItem *) customButton {
821 return [[[UIBarButtonItem alloc]
822 initWithTitle:custom_
823 style:[self rightButtonStyle]
824 target:self
825 action:@selector(customButtonClicked)
826 ] autorelease];
caa427d1
JF
827}
828
2634b249
JF
829- (UIBarButtonItem *) rightButton {
830 return reloaditem_;
eb35c522
JF
831}
832
2634b249
JF
833- (void) applyLoadingTitle {
834 [[self navigationItem] setTitle:UCLocalize("LOADING")];
caa427d1
JF
835}
836
2634b249
JF
837- (void) applyRightButton {
838 if ([self isLoading]) {
839 [[self navigationItem] setRightBarButtonItem:loadingitem_ animated:YES];
840 // XXX: why do we do this again here?
841 [[loadingitem_ view] addSubview:indicator_];
842 [self applyLoadingTitle];
843 } else if (custom_ != nil) {
844 [[self navigationItem] setRightBarButtonItem:[self customButton] animated:YES];
845 } else {
846 [[self navigationItem] setRightBarButtonItem:[self rightButton] animated:YES];
847 }
caa427d1
JF
848}
849
2634b249
JF
850- (void) _didStartLoading {
851 [self applyRightButton];
caa427d1
JF
852}
853
2634b249
JF
854- (void) _didFinishLoading {
855 if ([loading_ count] != 0)
856 return;
857
858 [self applyRightButton];
859
860 // XXX: wtf?
861 if (![self isLoading])
862 [[self navigationItem] setTitle:title_];
caa427d1
JF
863}
864
2634b249
JF
865- (bool) isLoading {
866 return [loading_ count] != 0;
caa427d1
JF
867}
868
b5e7eebb
GP
869- (id) initWithWidth:(float)width ofClass:(Class)_class {
870 if ((self = [super init]) != nil) {
245cce8a 871 class_ = _class;
2634b249 872 loading_ = [[NSMutableSet alloc] initWithCapacity:5];
bc11cf5b 873
2634b249 874 indirect_ = [[IndirectDelegate alloc] initWithDelegate:self];
caa427d1 875
2634b249
JF
876 webview_ = [[[CYWebView alloc] initWithFrame:[[self view] bounds]] autorelease];
877 [webview_ setDelegate:self];
878 [self setView:webview_];
22f8bed9 879
2634b249
JF
880 if ([webview_ respondsToSelector:@selector(setDataDetectorTypes:)])
881 [webview_ setDataDetectorTypes:UIDataDetectorTypeAutomatic];
882 else
883 [webview_ setDetectsPhoneNumbers:NO];
22f8bed9 884
2634b249 885 [webview_ setScalesPageToFit:YES];
22f8bed9 886
2634b249 887 UIWebDocumentView *document([webview_ _documentView]);
ea173384 888
2634b249
JF
889 // XXX: I think this improves scrolling; the hardcoded-ness sucks
890 [document setTileSize:CGSizeMake(320, 500)];
ea173384 891
2634b249
JF
892 [document setBackgroundColor:[UIColor clearColor]];
893 [document setDrawsBackground:NO];
ea173384 894
2634b249
JF
895 WebView *webview([document webView]);
896 WebPreferences *preferences([webview preferences]);
22f8bed9 897
2634b249
JF
898 // XXX: I have no clue if I actually /want/ this modification
899 if ([webview respondsToSelector:@selector(_setLayoutInterval:)])
900 [webview _setLayoutInterval:0];
901 else if ([preferences respondsToSelector:@selector(_setLayoutInterval:)])
902 [preferences _setLayoutInterval:0];
22f8bed9 903
2634b249
JF
904 [preferences setCacheModel:WebCacheModelDocumentBrowser];
905 [preferences setOfflineWebApplicationCacheEnabled:YES];
22f8bed9 906
2634b249
JF
907 if ([webview_ respondsToSelector:@selector(_scrollView)]) {
908 scroller_ = [webview_ _scrollView];
22f8bed9 909
2634b249 910 [scroller_ setDirectionalLockEnabled:YES];
9c1605e2 911 [scroller_ setDecelerationRate:CYScrollViewDecelerationRateNormal];
2634b249 912 [scroller_ setDelaysContentTouches:NO];
22f8bed9 913
2634b249
JF
914 [scroller_ setCanCancelContentTouches:YES];
915 } else if ([webview_ respondsToSelector:@selector(_scroller)]) {
916 UIScroller *scroller([webview_ _scroller]);
917 scroller_ = (UIScrollView *) scroller;
22f8bed9 918
2634b249 919 [scroller setDirectionalScrolling:YES];
9c1605e2
JF
920 // XXX: we might be better off /not/ setting this on older systems
921 [scroller setScrollDecelerationFactor:CYScrollViewDecelerationRateNormal]; /* 0.989324 */
2634b249 922 [scroller setScrollHysteresis:0]; /* 8 */
3e9c9e85 923
2634b249 924 [scroller setThumbDetectionEnabled:NO];
ea173384 925
2634b249
JF
926 // use NO with UIApplicationUseLegacyEvents(YES)
927 [scroller setEventMode:YES];
ea173384 928
2634b249
JF
929 // XXX: this is handled by setBounces, right?
930 //[scroller setAllowsRubberBanding:YES];
22f8bed9 931 }
bc11cf5b 932
2634b249
JF
933 [scroller_ setFixedBackgroundPattern:YES];
934 [scroller_ setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
935 [scroller_ setClipsSubviews:YES];
caa427d1 936
2634b249
JF
937 [scroller_ setBounces:YES];
938 [scroller_ setScrollingEnabled:YES];
939 [scroller_ setShowBackgroundShadow:NO];
caa427d1 940
2634b249 941 [self setViewportWidth:width];
bc11cf5b
JF
942
943 reloaditem_ = [[UIBarButtonItem alloc]
944 initWithTitle:UCLocalize("RELOAD")
945 style:[self rightButtonStyle]
946 target:self
947 action:@selector(reloadButtonClicked)
948 ];
949
950 loadingitem_ = [[UIBarButtonItem alloc]
951 initWithTitle:@" "
952 style:UIBarButtonItemStylePlain
953 target:self
954 action:@selector(reloadButtonClicked)
955 ];
2634b249
JF
956
957 CGSize indsize = [UIProgressIndicator defaultSizeForStyle:UIProgressIndicatorStyleMediumWhite];
958 indicator_ = [[UIProgressIndicator alloc] initWithFrame:CGRectMake(15, 5, indsize.width, indsize.height)];
959 [indicator_ setStyle:UIProgressIndicatorStyleMediumWhite];
960 [indicator_ startAnimation];
bc11cf5b 961 [[loadingitem_ view] addSubview:indicator_];
22f8bed9 962
2634b249 963 [webview_ setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
04fe1349 964 [indicator_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
22f8bed9
JF
965 } return self;
966}
967
b5e7eebb
GP
968- (id) initWithWidth:(float)width {
969 return [self initWithWidth:width ofClass:[self class]];
245cce8a
JF
970}
971
b5e7eebb
GP
972- (id) init {
973 return [self initWithWidth:0];
3e9c9e85
JF
974}
975
2634b249
JF
976- (void) didDismissModalViewController {
977 if (closer_ != nil)
978 [self callFunction:closer_];
22f8bed9
JF
979}
980
12b59862 981- (void) callFunction:(WebScriptObject *)function {
caa427d1
JF
982 WebThreadLock();
983
2634b249 984 WebView *webview([[webview_ _documentView] webView]);
12b59862 985 WebFrame *frame([webview mainFrame]);
c21004b9
JF
986 WebPreferences *preferences([webview preferences]);
987
988 bool maybe([preferences javaScriptCanOpenWindowsAutomatically]);
989 [preferences setJavaScriptCanOpenWindowsAutomatically:NO];
22f8bed9 990
c21004b9 991 /*id _private(MSHookIvar<id>(webview, "_private"));
12b59862
JF
992 WebCore::Page *page(_private == nil ? NULL : MSHookIvar<WebCore::Page *>(_private, "page"));
993 WebCore::Settings *settings(page == NULL ? NULL : page->settings());
22f8bed9 994
12b59862
JF
995 bool no;
996 if (settings == NULL)
997 no = 0;
998 else {
999 no = settings->JavaScriptCanOpenWindowsAutomatically();
1000 settings->setJavaScriptCanOpenWindowsAutomatically(true);
c21004b9 1001 }*/
12b59862 1002
b5e7eebb 1003 if (UIWindow *window = [[self view] window])
43f3d7f6
JF
1004 if (UIResponder *responder = [window firstResponder])
1005 [responder resignFirstResponder];
1006
12b59862
JF
1007 JSObjectRef object([function JSObject]);
1008 JSGlobalContextRef context([frame globalContext]);
1009 JSObjectCallAsFunction(context, object, NULL, 0, NULL, NULL);
1010
c21004b9
JF
1011 /*if (settings != NULL)
1012 settings->setJavaScriptCanOpenWindowsAutomatically(no);*/
1013
1014 [preferences setJavaScriptCanOpenWindowsAutomatically:maybe];
caa427d1
JF
1015
1016 WebThreadUnlock();
12b59862
JF
1017}
1018
ce041f4f 1019- (void) reloadButtonClicked {
12b59862
JF
1020 [self reloadURL];
1021}
1022
719d6c2f
DH
1023- (void) _customButtonClicked {
1024 [self reloadButtonClicked];
1025}
1026
ce041f4f 1027- (void) customButtonClicked {
caa427d1
JF
1028#if !AlwaysReload
1029 if (function_ != nil)
12b59862 1030 [self callFunction:function_];
caa427d1
JF
1031 else
1032#endif
719d6c2f 1033 [self _customButtonClicked];
22f8bed9
JF
1034}
1035
3e9c9e85
JF
1036+ (float) defaultWidth {
1037 return 980;
1038}
1039
a5938ea5 1040@end