]>
Commit | Line | Data |
---|---|---|
f172aa8f | 1 | /* Cydia - iPhone UIKit Front-End for Debian APT |
4c66fad9 | 2 | * Copyright (C) 2008-2015 Jay Freeman (saurik) |
f172aa8f JF |
3 | */ |
4 | ||
6d9696a5 | 5 | /* GNU General Public License, Version 3 {{{ */ |
f172aa8f | 6 | /* |
6d9696a5 JF |
7 | * Cydia is free software: you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published | |
9 | * by the Free Software Foundation, either version 3 of the License, | |
10 | * or (at your option) any later version. | |
f172aa8f | 11 | * |
6d9696a5 JF |
12 | * Cydia is distributed in the hope that it will be useful, but |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
f172aa8f | 16 | * |
6d9696a5 JF |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with Cydia. If not, see <http://www.gnu.org/licenses/>. | |
19 | **/ | |
f172aa8f JF |
20 | /* }}} */ |
21 | ||
63755c48 JF |
22 | #include "CyteKit/UCPlatform.h" |
23 | ||
31f9c8f7 | 24 | #include "CyteKit/dispatchEvent.h" |
d458596e | 25 | #include "CyteKit/WebView.h" |
aa35fd7b | 26 | |
a09f7a48 | 27 | #include "Substrate.hpp" |
435cb857 | 28 | |
aa35fd7b | 29 | #include "iPhonePrivate.h" |
aa35fd7b JF |
30 | |
31 | // CYWebPolicyDecision* {{{ | |
aa35fd7b JF |
32 | @interface CYWebPolicyDecisionMediator : NSObject < |
33 | WebPolicyDecisionListener | |
34 | > { | |
35 | id<WebPolicyDecisionListener> listener_; | |
36 | CYWebPolicyDecision decision_; | |
37 | } | |
38 | ||
39 | - (id) initWithListener:(id<WebPolicyDecisionListener>)listener; | |
40 | ||
41 | - (CYWebPolicyDecision) decision; | |
42 | - (bool) decided; | |
43 | - (bool) decide; | |
44 | ||
45 | @end | |
46 | ||
47 | @implementation CYWebPolicyDecisionMediator | |
48 | ||
49 | - (id) initWithListener:(id<WebPolicyDecisionListener>)listener { | |
50 | if ((self = [super init]) != nil) { | |
51 | listener_ = listener; | |
52 | } return self; | |
53 | } | |
54 | ||
55 | - (CYWebPolicyDecision) decision { | |
56 | return decision_; | |
57 | } | |
58 | ||
59 | - (bool) decided { | |
60 | return decision_ != CYWebPolicyDecisionUnknown; | |
61 | } | |
62 | ||
63 | - (bool) decide { | |
64 | switch (decision_) { | |
65 | case CYWebPolicyDecisionUnknown: | |
66 | default: | |
67 | NSLog(@"CYWebPolicyDecisionUnknown"); | |
68 | return false; | |
69 | ||
70 | case CYWebPolicyDecisionDownload: [listener_ download]; break; | |
71 | case CYWebPolicyDecisionIgnore: [listener_ ignore]; break; | |
72 | case CYWebPolicyDecisionUse: [listener_ use]; break; | |
73 | } | |
74 | ||
75 | return true; | |
76 | } | |
77 | ||
78 | - (void) download { | |
79 | decision_ = CYWebPolicyDecisionDownload; | |
80 | } | |
81 | ||
82 | - (void) ignore { | |
83 | decision_ = CYWebPolicyDecisionIgnore; | |
84 | } | |
85 | ||
86 | - (void) use { | |
87 | decision_ = CYWebPolicyDecisionUse; | |
88 | } | |
89 | ||
90 | @end | |
91 | // }}} | |
92 | ||
f8c9fd4c JF |
93 | @implementation CyteWebView : UIWebView { |
94 | } | |
aa35fd7b JF |
95 | |
96 | #if ShowInternals | |
97 | #include "CyteKit/UCInternal.h" | |
98 | #endif | |
99 | ||
100 | - (id) initWithFrame:(CGRect)frame { | |
101 | if ((self = [super initWithFrame:frame]) != nil) { | |
102 | } return self; | |
103 | } | |
104 | ||
105 | - (void) dealloc { | |
0291a3a6 JF |
106 | if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) { |
107 | UIWebViewInternal *&_internal(MSHookIvar<UIWebViewInternal *>(self, "_internal")); | |
108 | if (&_internal != NULL) { | |
109 | UIWebViewWebViewDelegate *&webViewDelegate(MSHookIvar<UIWebViewWebViewDelegate *>(_internal, "webViewDelegate")); | |
110 | if (&webViewDelegate != NULL) | |
111 | [webViewDelegate _clearUIWebView]; | |
112 | } | |
113 | } | |
114 | ||
aa35fd7b JF |
115 | [super dealloc]; |
116 | } | |
117 | ||
3479309e JF |
118 | - (NSString *) description { |
119 | return [NSString stringWithFormat:@"<%s: %p, %@>", class_getName([self class]), self, [[[self request] URL] absoluteString]]; | |
120 | } | |
121 | ||
1ee69bb4 JF |
122 | - (id<CyteWebViewDelegate>) delegate { |
123 | return (id<CyteWebViewDelegate>) [super delegate]; | |
aa35fd7b JF |
124 | } |
125 | ||
4cc9e99a JF |
126 | - (void) setDelegate:(id<CyteWebViewDelegate>)delegate { |
127 | [super setDelegate:delegate]; | |
128 | } | |
129 | ||
aa35fd7b | 130 | /*- (WebView *) webView:(WebView *)view createWebViewWithRequest:(NSURLRequest *)request { |
1ee69bb4 | 131 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
132 | WebView *created(nil); |
133 | if (created == nil && [delegate respondsToSelector:@selector(webView:createWebViewWithRequest:)]) | |
134 | created = [delegate webView:view createWebViewWithRequest:request]; | |
135 | if (created == nil && [UIWebView instancesRespondToSelector:@selector(webView:createWebViewWithRequest:)]) | |
136 | created = [super webView:view createWebViewWithRequest:request]; | |
137 | return created; | |
138 | }*/ | |
139 | ||
140 | // webView:addMessageToConsole: (X.Xx) {{{ | |
141 | static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) { | |
142 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
143 | if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)]) | |
144 | [uiWebView webView:view addMessageToConsole:message]; | |
145 | } | |
146 | ||
147 | - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message { | |
1ee69bb4 | 148 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
149 | if ([delegate respondsToSelector:@selector(webView:addMessageToConsole:)]) |
150 | [delegate webView:view addMessageToConsole:message]; | |
151 | if ([UIWebView instancesRespondToSelector:@selector(webView:addMessageToConsole:)]) | |
152 | [super webView:view addMessageToConsole:message]; | |
153 | } | |
154 | // }}} | |
155 | // webView:decidePolicyForNavigationAction:request:frame:decisionListener: (2.0+) {{{ | |
156 | - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { | |
1ee69bb4 | 157 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
158 | CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]); |
159 | if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)]) | |
160 | [delegate webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator]; | |
161 | if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)]) | |
162 | [super webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator]; | |
b73d8da0 JF |
163 | if ([delegate respondsToSelector:@selector(webView:didDecidePolicy:forNavigationAction:request:frame:)]) |
164 | [delegate webView:view didDecidePolicy:[mediator decision] forNavigationAction:action request:request frame:frame]; | |
aa35fd7b JF |
165 | [mediator decide]; |
166 | } | |
167 | // }}} | |
168 | // webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: (3.0+) {{{ | |
169 | static void $UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *action, NSURLRequest *request, NSString *frame, id<WebPolicyDecisionListener> listener) { | |
170 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
171 | if ([uiWebView respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)]) | |
172 | [uiWebView webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:listener]; | |
173 | } | |
174 | ||
175 | - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { | |
1ee69bb4 | 176 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
177 | CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]); |
178 | if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)]) | |
179 | [delegate webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator]; | |
180 | if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)]) | |
181 | [super webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator]; | |
182 | [mediator decide]; | |
183 | } | |
184 | // }}} | |
185 | // webView:didClearWindowObject:forFrame: (3.2+) {{{ | |
186 | static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) { | |
187 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
188 | if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)]) | |
189 | [uiWebView webView:view didClearWindowObject:window forFrame:frame]; | |
190 | } | |
191 | ||
192 | - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { | |
1ee69bb4 | 193 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
194 | if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)]) |
195 | [delegate webView:view didClearWindowObject:window forFrame:frame]; | |
196 | if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)]) | |
197 | [super webView:view didClearWindowObject:window forFrame:frame]; | |
198 | } | |
199 | // }}} | |
64ffa332 JF |
200 | // webView:didCommitLoadForFrame: (3.0+) {{{ |
201 | static void $UIWebViewWebViewDelegate$webView$didCommitLoadForFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebFrame *frame) { | |
202 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
203 | if ([uiWebView respondsToSelector:@selector(webView:didCommitLoadForFrame:)]) | |
204 | [uiWebView webView:view didCommitLoadForFrame:frame]; | |
205 | } | |
206 | ||
207 | - (void) webView:(WebView *)view didCommitLoadForFrame:(WebFrame *)frame { | |
208 | id<CyteWebViewDelegate> delegate([self delegate]); | |
209 | if ([delegate respondsToSelector:@selector(webView:didCommitLoadForFrame:)]) | |
210 | [delegate webView:view didCommitLoadForFrame:frame]; | |
211 | if ([UIWebView instancesRespondToSelector:@selector(webView:didCommitLoadForFrame:)]) | |
212 | [super webView:view didCommitLoadForFrame:frame]; | |
213 | } | |
214 | // }}} | |
aa35fd7b JF |
215 | // webView:didFailLoadWithError:forFrame: (2.0+) {{{ |
216 | - (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { | |
1ee69bb4 | 217 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
218 | if ([delegate respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)]) |
219 | [delegate webView:view didFailLoadWithError:error forFrame:frame]; | |
220 | if ([UIWebView instancesRespondToSelector:@selector(webView:didFailLoadWithError:forFrame:)]) | |
221 | [super webView:view didFailLoadWithError:error forFrame:frame]; | |
222 | } | |
223 | // }}} | |
224 | // webView:didFailProvisionalLoadWithError:forFrame: (2.0+) {{{ | |
225 | - (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { | |
1ee69bb4 | 226 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
227 | if ([delegate respondsToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)]) |
228 | [delegate webView:view didFailProvisionalLoadWithError:error forFrame:frame]; | |
229 | if ([UIWebView instancesRespondToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)]) | |
230 | [super webView:view didFailProvisionalLoadWithError:error forFrame:frame]; | |
231 | } | |
232 | // }}} | |
233 | // webView:didFinishLoadForFrame: (2.0+) {{{ | |
234 | - (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame { | |
1ee69bb4 | 235 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
236 | if ([delegate respondsToSelector:@selector(webView:didFinishLoadForFrame:)]) |
237 | [delegate webView:view didFinishLoadForFrame:frame]; | |
238 | if ([UIWebView instancesRespondToSelector:@selector(webView:didFinishLoadForFrame:)]) | |
239 | [super webView:view didFinishLoadForFrame:frame]; | |
240 | } | |
241 | // }}} | |
242 | // webView:didReceiveTitle:forFrame: (3.2+) {{{ | |
243 | static void $UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSString *title, WebFrame *frame) { | |
244 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
245 | if ([uiWebView respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)]) | |
246 | [uiWebView webView:view didReceiveTitle:title forFrame:frame]; | |
247 | } | |
248 | ||
249 | - (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { | |
1ee69bb4 | 250 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
251 | if ([delegate respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)]) |
252 | [delegate webView:view didReceiveTitle:title forFrame:frame]; | |
253 | if ([UIWebView instancesRespondToSelector:@selector(webView:didReceiveTitle:forFrame:)]) | |
254 | [super webView:view didReceiveTitle:title forFrame:frame]; | |
255 | } | |
256 | // }}} | |
257 | // webView:didStartProvisionalLoadForFrame: (2.0+) {{{ | |
258 | - (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame { | |
1ee69bb4 | 259 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
260 | if ([delegate respondsToSelector:@selector(webView:didStartProvisionalLoadForFrame:)]) |
261 | [delegate webView:view didStartProvisionalLoadForFrame:frame]; | |
262 | if ([UIWebView instancesRespondToSelector:@selector(webView:didStartProvisionalLoadForFrame:)]) | |
263 | [super webView:view didStartProvisionalLoadForFrame:frame]; | |
264 | } | |
265 | // }}} | |
754456f5 JF |
266 | // webView:resource:didCancelAuthenticationChallenge:fromDataSource: {{{ |
267 | - (void) webView:(WebView *)view resource:(id)identifier didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source { | |
268 | id<CyteWebViewDelegate> delegate([self delegate]); | |
269 | if ([UIWebView respondsToSelector:@selector(webView:resource:didCancelAuthenticationChallenge:fromDataSource:)]) | |
270 | [super webView:view resource:identifier didCancelAuthenticationChallenge:challenge fromDataSource:source]; | |
271 | if ([delegate respondsToSelector:@selector(webView:resource:didCancelAuthenticationChallenge:fromDataSource:)]) | |
272 | [delegate webView:view resource:identifier didCancelAuthenticationChallenge:challenge fromDataSource:source]; | |
273 | } | |
274 | // }}} | |
275 | // webView:resource:didReceiveAuthenticationChallenge:fromDataSource: {{{ | |
276 | - (void) webView:(WebView *)view resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source { | |
277 | id<CyteWebViewDelegate> delegate([self delegate]); | |
278 | if ([UIWebView respondsToSelector:@selector(webView:resource:didReceiveAuthenticationChallenge:fromDataSource:)]) | |
279 | [super webView:view resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source]; | |
280 | if ([delegate respondsToSelector:@selector(webView:resource:didReceiveAuthenticationChallenge:fromDataSource:)]) | |
281 | [delegate webView:view resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source]; | |
282 | } | |
283 | // }}} | |
aa35fd7b JF |
284 | // webView:resource:willSendRequest:redirectResponse:fromDataSource: (3.2+) {{{ |
285 | static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, id identifier, NSURLRequest *request, NSURLResponse *response, WebDataSource *source) { | |
286 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
287 | if ([uiWebView respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)]) | |
288 | request = [uiWebView webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
289 | return request; | |
290 | } | |
291 | ||
292 | - (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { | |
1ee69bb4 | 293 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
294 | if ([UIWebView instancesRespondToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)]) |
295 | request = [super webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
296 | if ([delegate respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)]) | |
297 | request = [delegate webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
92de61aa JF |
298 | return request; |
299 | } | |
300 | // }}} | |
301 | // webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource: {{{ | |
302 | - (NSURLRequest *) webThreadWebView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { | |
303 | id<CyteWebViewDelegate> delegate([self delegate]); | |
304 | if ([UIWebView instancesRespondToSelector:@selector(webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource:)]) | |
305 | request = [super webThreadWebView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
306 | if ([delegate respondsToSelector:@selector(webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource:)]) | |
307 | request = [delegate webThreadWebView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
aa35fd7b JF |
308 | return request; |
309 | } | |
310 | // }}} | |
311 | // webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: (2.1+) {{{ | |
312 | - (void) webView:(WebView *)view runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 313 | [[self retain] autorelease]; |
1ee69bb4 | 314 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
315 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)]) |
316 | if ( | |
317 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptAlertPanelWithMessage:initiatedByFrame:)] || | |
318 | [delegate webView:view shouldRunJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame] | |
319 | ) | |
320 | [super webView:view runJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame]; | |
321 | } | |
322 | // }}} | |
323 | // webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame: (2.1+) {{{ | |
324 | - (BOOL) webView:(WebView *)view runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 325 | [[self retain] autorelease]; |
1ee69bb4 | 326 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
327 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)]) |
328 | if ( | |
329 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptConfirmPanelWithMessage:initiatedByFrame:)] || | |
330 | [delegate webView:view shouldRunJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame] | |
331 | ) | |
332 | return [super webView:view runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame]; | |
333 | return NO; | |
334 | } | |
335 | // }}} | |
336 | // webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame: (2.1+) {{{ | |
337 | - (NSString *) webView:(WebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 338 | [[self retain] autorelease]; |
1ee69bb4 | 339 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
340 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)]) |
341 | if ( | |
342 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)] || | |
343 | [delegate webView:view shouldRunJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame] | |
344 | ) | |
345 | return [super webView:view runJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame]; | |
346 | return nil; | |
347 | } | |
348 | // }}} | |
349 | // webViewClose: (3.2+) {{{ | |
350 | static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view) { | |
351 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
352 | if ([uiWebView respondsToSelector:@selector(webViewClose:)]) | |
353 | [uiWebView webViewClose:view]; | |
354 | } | |
355 | ||
356 | - (void) webViewClose:(WebView *)view { | |
1ee69bb4 | 357 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
358 | if ([delegate respondsToSelector:@selector(webViewClose:)]) |
359 | [delegate webViewClose:view]; | |
360 | if ([UIWebView instancesRespondToSelector:@selector(webViewClose:)]) | |
361 | [super webViewClose:view]; | |
362 | } | |
363 | // }}} | |
364 | ||
365 | - (void) _updateViewSettings { | |
366 | [super _updateViewSettings]; | |
367 | ||
1ee69bb4 | 368 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
369 | if ([delegate respondsToSelector:@selector(webViewUpdateViewSettings:)]) |
370 | [delegate webViewUpdateViewSettings:self]; | |
371 | } | |
372 | ||
4bcafc01 | 373 | - (void) dispatchEvent:(NSString *)event { |
31f9c8f7 | 374 | [[self _documentView] dispatchEvent:event]; |
4bcafc01 JF |
375 | } |
376 | ||
a713fcd3 JF |
377 | - (void) reloadFromOrigin { |
378 | [[[self _documentView] webView] reloadFromOrigin:nil]; | |
379 | } | |
380 | ||
d821ecc1 JF |
381 | - (UIScrollView *) scrollView { |
382 | if ([self respondsToSelector:@selector(_scrollView)]) | |
383 | return [self _scrollView]; | |
384 | else if ([self respondsToSelector:@selector(_scroller)]) | |
385 | return (UIScrollView *) [self _scroller]; | |
386 | else return nil; | |
387 | } | |
388 | ||
3cf38067 JF |
389 | - (void) setNeedsLayout { |
390 | [super setNeedsLayout]; | |
391 | ||
392 | WebFrame *frame([[[self _documentView] webView] mainFrame]); | |
393 | if ([frame respondsToSelector:@selector(setNeedsLayout)]) | |
394 | [frame setNeedsLayout]; | |
395 | } | |
396 | ||
09865663 JF |
397 | - (NSURLRequest *) request { |
398 | WebFrame *frame([[[self _documentView] webView] mainFrame]); | |
399 | return [([frame provisionalDataSource] ?: [frame dataSource]) request]; | |
400 | } | |
401 | ||
baa2fba3 JF |
402 | @end |
403 | ||
0291a3a6 JF |
404 | static void $UIWebViewWebViewDelegate$_clearUIWebView(UIWebViewWebViewDelegate *self, SEL sel) { |
405 | MSHookIvar<UIWebView *>(self, "uiWebView") = nil; | |
406 | } | |
407 | ||
baa2fba3 | 408 | __attribute__((__constructor__)) static void $() { |
aa35fd7b JF |
409 | if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) { |
410 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12"); | |
411 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), (IMP) &$UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$, "v28@0:4@8@12@16@20@24"); | |
412 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16"); | |
64ffa332 | 413 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didCommitLoadForFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didCommitLoadForFrame$, "v16@0:4@8@12"); |
aa35fd7b JF |
414 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didReceiveTitle:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$, "v20@0:4@8@12@16"); |
415 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), (IMP) &$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$, "@28@0:4@8@12@16@20@24"); | |
416 | class_addMethod($UIWebViewWebViewDelegate, @selector(webViewClose:), (IMP) &$UIWebViewWebViewDelegate$webViewClose$, "v12@0:4@8"); | |
0291a3a6 | 417 | class_addMethod($UIWebViewWebViewDelegate, @selector(_clearUIWebView), (IMP) &$UIWebViewWebViewDelegate$_clearUIWebView, "v8@0:4"); |
aa35fd7b JF |
418 | } |
419 | } | |
a3d01a76 JF |
420 | |
421 | @implementation UIWebDocumentView (Cydia) | |
422 | ||
423 | - (void) _setScrollerOffset:(CGPoint)offset { | |
424 | UIScroller *scroller([self _scroller]); | |
425 | ||
426 | CGSize size([scroller contentSize]); | |
427 | CGSize bounds([scroller bounds].size); | |
428 | ||
429 | CGPoint max; | |
430 | max.x = size.width - bounds.width; | |
431 | max.y = size.height - bounds.height; | |
432 | ||
433 | // wtf Apple?! | |
434 | if (max.x < 0) | |
435 | max.x = 0; | |
436 | if (max.y < 0) | |
437 | max.y = 0; | |
438 | ||
439 | offset.x = offset.x < 0 ? 0 : offset.x > max.x ? max.x : offset.x; | |
440 | offset.y = offset.y < 0 ? 0 : offset.y > max.y ? max.y : offset.y; | |
441 | ||
442 | [scroller setOffset:offset]; | |
443 | } | |
444 | ||
445 | @end |