]>
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 | ||
31f9c8f7 | 22 | #include "CyteKit/dispatchEvent.h" |
d458596e | 23 | #include "CyteKit/WebView.h" |
aa35fd7b | 24 | |
a09f7a48 | 25 | #include "Substrate.hpp" |
435cb857 | 26 | |
aa35fd7b | 27 | #include "iPhonePrivate.h" |
aa35fd7b JF |
28 | |
29 | // CYWebPolicyDecision* {{{ | |
aa35fd7b JF |
30 | @interface CYWebPolicyDecisionMediator : NSObject < |
31 | WebPolicyDecisionListener | |
32 | > { | |
33 | id<WebPolicyDecisionListener> listener_; | |
34 | CYWebPolicyDecision decision_; | |
35 | } | |
36 | ||
37 | - (id) initWithListener:(id<WebPolicyDecisionListener>)listener; | |
38 | ||
39 | - (CYWebPolicyDecision) decision; | |
40 | - (bool) decided; | |
41 | - (bool) decide; | |
42 | ||
43 | @end | |
44 | ||
45 | @implementation CYWebPolicyDecisionMediator | |
46 | ||
47 | - (id) initWithListener:(id<WebPolicyDecisionListener>)listener { | |
48 | if ((self = [super init]) != nil) { | |
49 | listener_ = listener; | |
50 | } return self; | |
51 | } | |
52 | ||
53 | - (CYWebPolicyDecision) decision { | |
54 | return decision_; | |
55 | } | |
56 | ||
57 | - (bool) decided { | |
58 | return decision_ != CYWebPolicyDecisionUnknown; | |
59 | } | |
60 | ||
61 | - (bool) decide { | |
62 | switch (decision_) { | |
63 | case CYWebPolicyDecisionUnknown: | |
64 | default: | |
65 | NSLog(@"CYWebPolicyDecisionUnknown"); | |
66 | return false; | |
67 | ||
68 | case CYWebPolicyDecisionDownload: [listener_ download]; break; | |
69 | case CYWebPolicyDecisionIgnore: [listener_ ignore]; break; | |
70 | case CYWebPolicyDecisionUse: [listener_ use]; break; | |
71 | } | |
72 | ||
73 | return true; | |
74 | } | |
75 | ||
76 | - (void) download { | |
77 | decision_ = CYWebPolicyDecisionDownload; | |
78 | } | |
79 | ||
80 | - (void) ignore { | |
81 | decision_ = CYWebPolicyDecisionIgnore; | |
82 | } | |
83 | ||
84 | - (void) use { | |
85 | decision_ = CYWebPolicyDecisionUse; | |
86 | } | |
87 | ||
88 | @end | |
89 | // }}} | |
90 | ||
1ee69bb4 | 91 | @implementation CyteWebView : UIWebView |
aa35fd7b JF |
92 | |
93 | #if ShowInternals | |
94 | #include "CyteKit/UCInternal.h" | |
95 | #endif | |
96 | ||
97 | - (id) initWithFrame:(CGRect)frame { | |
98 | if ((self = [super initWithFrame:frame]) != nil) { | |
99 | } return self; | |
100 | } | |
101 | ||
102 | - (void) dealloc { | |
0291a3a6 JF |
103 | if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_3_0) { |
104 | UIWebViewInternal *&_internal(MSHookIvar<UIWebViewInternal *>(self, "_internal")); | |
105 | if (&_internal != NULL) { | |
106 | UIWebViewWebViewDelegate *&webViewDelegate(MSHookIvar<UIWebViewWebViewDelegate *>(_internal, "webViewDelegate")); | |
107 | if (&webViewDelegate != NULL) | |
108 | [webViewDelegate _clearUIWebView]; | |
109 | } | |
110 | } | |
111 | ||
aa35fd7b JF |
112 | [super dealloc]; |
113 | } | |
114 | ||
3479309e JF |
115 | - (NSString *) description { |
116 | return [NSString stringWithFormat:@"<%s: %p, %@>", class_getName([self class]), self, [[[self request] URL] absoluteString]]; | |
117 | } | |
118 | ||
1ee69bb4 JF |
119 | - (id<CyteWebViewDelegate>) delegate { |
120 | return (id<CyteWebViewDelegate>) [super delegate]; | |
aa35fd7b JF |
121 | } |
122 | ||
4cc9e99a JF |
123 | - (void) setDelegate:(id<CyteWebViewDelegate>)delegate { |
124 | [super setDelegate:delegate]; | |
125 | } | |
126 | ||
aa35fd7b | 127 | /*- (WebView *) webView:(WebView *)view createWebViewWithRequest:(NSURLRequest *)request { |
1ee69bb4 | 128 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
129 | WebView *created(nil); |
130 | if (created == nil && [delegate respondsToSelector:@selector(webView:createWebViewWithRequest:)]) | |
131 | created = [delegate webView:view createWebViewWithRequest:request]; | |
132 | if (created == nil && [UIWebView instancesRespondToSelector:@selector(webView:createWebViewWithRequest:)]) | |
133 | created = [super webView:view createWebViewWithRequest:request]; | |
134 | return created; | |
135 | }*/ | |
136 | ||
137 | // webView:addMessageToConsole: (X.Xx) {{{ | |
138 | static void $UIWebViewWebViewDelegate$webView$addMessageToConsole$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *message) { | |
139 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
140 | if ([uiWebView respondsToSelector:@selector(webView:addMessageToConsole:)]) | |
141 | [uiWebView webView:view addMessageToConsole:message]; | |
142 | } | |
143 | ||
144 | - (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message { | |
1ee69bb4 | 145 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
146 | if ([delegate respondsToSelector:@selector(webView:addMessageToConsole:)]) |
147 | [delegate webView:view addMessageToConsole:message]; | |
148 | if ([UIWebView instancesRespondToSelector:@selector(webView:addMessageToConsole:)]) | |
149 | [super webView:view addMessageToConsole:message]; | |
150 | } | |
151 | // }}} | |
152 | // webView:decidePolicyForNavigationAction:request:frame:decisionListener: (2.0+) {{{ | |
153 | - (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { | |
1ee69bb4 | 154 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
155 | CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]); |
156 | if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)]) | |
157 | [delegate webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator]; | |
158 | if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNavigationAction:request:frame:decisionListener:)]) | |
159 | [super webView:view decidePolicyForNavigationAction:action request:request frame:frame decisionListener:mediator]; | |
b73d8da0 JF |
160 | if ([delegate respondsToSelector:@selector(webView:didDecidePolicy:forNavigationAction:request:frame:)]) |
161 | [delegate webView:view didDecidePolicy:[mediator decision] forNavigationAction:action request:request frame:frame]; | |
aa35fd7b JF |
162 | [mediator decide]; |
163 | } | |
164 | // }}} | |
165 | // webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener: (3.0+) {{{ | |
166 | static void $UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSDictionary *action, NSURLRequest *request, NSString *frame, id<WebPolicyDecisionListener> listener) { | |
167 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
168 | if ([uiWebView respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)]) | |
169 | [uiWebView webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:listener]; | |
170 | } | |
171 | ||
172 | - (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener { | |
1ee69bb4 | 173 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
174 | CYWebPolicyDecisionMediator *mediator([[[CYWebPolicyDecisionMediator alloc] initWithListener:listener] autorelease]); |
175 | if (![mediator decided] && [delegate respondsToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)]) | |
176 | [delegate webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator]; | |
177 | if (![mediator decided] && [UIWebView instancesRespondToSelector:@selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:)]) | |
178 | [super webView:view decidePolicyForNewWindowAction:action request:request newFrameName:frame decisionListener:mediator]; | |
179 | [mediator decide]; | |
180 | } | |
181 | // }}} | |
182 | // webView:didClearWindowObject:forFrame: (3.2+) {{{ | |
183 | static void $UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebScriptObject *window, WebFrame *frame) { | |
184 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
185 | if ([uiWebView respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)]) | |
186 | [uiWebView webView:view didClearWindowObject:window forFrame:frame]; | |
187 | } | |
188 | ||
189 | - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame { | |
1ee69bb4 | 190 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
191 | if ([delegate respondsToSelector:@selector(webView:didClearWindowObject:forFrame:)]) |
192 | [delegate webView:view didClearWindowObject:window forFrame:frame]; | |
193 | if ([UIWebView instancesRespondToSelector:@selector(webView:didClearWindowObject:forFrame:)]) | |
194 | [super webView:view didClearWindowObject:window forFrame:frame]; | |
195 | } | |
196 | // }}} | |
64ffa332 JF |
197 | // webView:didCommitLoadForFrame: (3.0+) {{{ |
198 | static void $UIWebViewWebViewDelegate$webView$didCommitLoadForFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, WebFrame *frame) { | |
199 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
200 | if ([uiWebView respondsToSelector:@selector(webView:didCommitLoadForFrame:)]) | |
201 | [uiWebView webView:view didCommitLoadForFrame:frame]; | |
202 | } | |
203 | ||
204 | - (void) webView:(WebView *)view didCommitLoadForFrame:(WebFrame *)frame { | |
205 | id<CyteWebViewDelegate> delegate([self delegate]); | |
206 | if ([delegate respondsToSelector:@selector(webView:didCommitLoadForFrame:)]) | |
207 | [delegate webView:view didCommitLoadForFrame:frame]; | |
208 | if ([UIWebView instancesRespondToSelector:@selector(webView:didCommitLoadForFrame:)]) | |
209 | [super webView:view didCommitLoadForFrame:frame]; | |
210 | } | |
211 | // }}} | |
aa35fd7b JF |
212 | // webView:didFailLoadWithError:forFrame: (2.0+) {{{ |
213 | - (void) webView:(WebView *)view didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { | |
1ee69bb4 | 214 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
215 | if ([delegate respondsToSelector:@selector(webView:didFailLoadWithError:forFrame:)]) |
216 | [delegate webView:view didFailLoadWithError:error forFrame:frame]; | |
217 | if ([UIWebView instancesRespondToSelector:@selector(webView:didFailLoadWithError:forFrame:)]) | |
218 | [super webView:view didFailLoadWithError:error forFrame:frame]; | |
219 | } | |
220 | // }}} | |
221 | // webView:didFailProvisionalLoadWithError:forFrame: (2.0+) {{{ | |
222 | - (void) webView:(WebView *)view didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame { | |
1ee69bb4 | 223 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
224 | if ([delegate respondsToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)]) |
225 | [delegate webView:view didFailProvisionalLoadWithError:error forFrame:frame]; | |
226 | if ([UIWebView instancesRespondToSelector:@selector(webView:didFailProvisionalLoadWithError:forFrame:)]) | |
227 | [super webView:view didFailProvisionalLoadWithError:error forFrame:frame]; | |
228 | } | |
229 | // }}} | |
230 | // webView:didFinishLoadForFrame: (2.0+) {{{ | |
231 | - (void) webView:(WebView *)view didFinishLoadForFrame:(WebFrame *)frame { | |
1ee69bb4 | 232 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
233 | if ([delegate respondsToSelector:@selector(webView:didFinishLoadForFrame:)]) |
234 | [delegate webView:view didFinishLoadForFrame:frame]; | |
235 | if ([UIWebView instancesRespondToSelector:@selector(webView:didFinishLoadForFrame:)]) | |
236 | [super webView:view didFinishLoadForFrame:frame]; | |
237 | } | |
238 | // }}} | |
239 | // webView:didReceiveTitle:forFrame: (3.2+) {{{ | |
240 | static void $UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, NSString *title, WebFrame *frame) { | |
241 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
242 | if ([uiWebView respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)]) | |
243 | [uiWebView webView:view didReceiveTitle:title forFrame:frame]; | |
244 | } | |
245 | ||
246 | - (void) webView:(WebView *)view didReceiveTitle:(NSString *)title forFrame:(WebFrame *)frame { | |
1ee69bb4 | 247 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
248 | if ([delegate respondsToSelector:@selector(webView:didReceiveTitle:forFrame:)]) |
249 | [delegate webView:view didReceiveTitle:title forFrame:frame]; | |
250 | if ([UIWebView instancesRespondToSelector:@selector(webView:didReceiveTitle:forFrame:)]) | |
251 | [super webView:view didReceiveTitle:title forFrame:frame]; | |
252 | } | |
253 | // }}} | |
254 | // webView:didStartProvisionalLoadForFrame: (2.0+) {{{ | |
255 | - (void) webView:(WebView *)view didStartProvisionalLoadForFrame:(WebFrame *)frame { | |
1ee69bb4 | 256 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
257 | if ([delegate respondsToSelector:@selector(webView:didStartProvisionalLoadForFrame:)]) |
258 | [delegate webView:view didStartProvisionalLoadForFrame:frame]; | |
259 | if ([UIWebView instancesRespondToSelector:@selector(webView:didStartProvisionalLoadForFrame:)]) | |
260 | [super webView:view didStartProvisionalLoadForFrame:frame]; | |
261 | } | |
262 | // }}} | |
754456f5 JF |
263 | // webView:resource:didCancelAuthenticationChallenge:fromDataSource: {{{ |
264 | - (void) webView:(WebView *)view resource:(id)identifier didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source { | |
265 | id<CyteWebViewDelegate> delegate([self delegate]); | |
266 | if ([UIWebView respondsToSelector:@selector(webView:resource:didCancelAuthenticationChallenge:fromDataSource:)]) | |
267 | [super webView:view resource:identifier didCancelAuthenticationChallenge:challenge fromDataSource:source]; | |
268 | if ([delegate respondsToSelector:@selector(webView:resource:didCancelAuthenticationChallenge:fromDataSource:)]) | |
269 | [delegate webView:view resource:identifier didCancelAuthenticationChallenge:challenge fromDataSource:source]; | |
270 | } | |
271 | // }}} | |
272 | // webView:resource:didReceiveAuthenticationChallenge:fromDataSource: {{{ | |
273 | - (void) webView:(WebView *)view resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)source { | |
274 | id<CyteWebViewDelegate> delegate([self delegate]); | |
275 | if ([UIWebView respondsToSelector:@selector(webView:resource:didReceiveAuthenticationChallenge:fromDataSource:)]) | |
276 | [super webView:view resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source]; | |
277 | if ([delegate respondsToSelector:@selector(webView:resource:didReceiveAuthenticationChallenge:fromDataSource:)]) | |
278 | [delegate webView:view resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:source]; | |
279 | } | |
280 | // }}} | |
aa35fd7b JF |
281 | // webView:resource:willSendRequest:redirectResponse:fromDataSource: (3.2+) {{{ |
282 | static NSURLRequest *$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view, id identifier, NSURLRequest *request, NSURLResponse *response, WebDataSource *source) { | |
283 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
284 | if ([uiWebView respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)]) | |
285 | request = [uiWebView webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
286 | return request; | |
287 | } | |
288 | ||
289 | - (NSURLRequest *) webView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { | |
1ee69bb4 | 290 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
291 | if ([UIWebView instancesRespondToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)]) |
292 | request = [super webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
293 | if ([delegate respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)]) | |
294 | request = [delegate webView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
92de61aa JF |
295 | return request; |
296 | } | |
297 | // }}} | |
298 | // webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource: {{{ | |
299 | - (NSURLRequest *) webThreadWebView:(WebView *)view resource:(id)identifier willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source { | |
300 | id<CyteWebViewDelegate> delegate([self delegate]); | |
301 | if ([UIWebView instancesRespondToSelector:@selector(webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource:)]) | |
302 | request = [super webThreadWebView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
303 | if ([delegate respondsToSelector:@selector(webThreadWebView:resource:willSendRequest:redirectResponse:fromDataSource:)]) | |
304 | request = [delegate webThreadWebView:view resource:identifier willSendRequest:request redirectResponse:response fromDataSource:source]; | |
aa35fd7b JF |
305 | return request; |
306 | } | |
307 | // }}} | |
308 | // webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: (2.1+) {{{ | |
309 | - (void) webView:(WebView *)view runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 310 | [[self retain] autorelease]; |
1ee69bb4 | 311 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
312 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)]) |
313 | if ( | |
314 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptAlertPanelWithMessage:initiatedByFrame:)] || | |
315 | [delegate webView:view shouldRunJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame] | |
316 | ) | |
317 | [super webView:view runJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame]; | |
318 | } | |
319 | // }}} | |
320 | // webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame: (2.1+) {{{ | |
321 | - (BOOL) webView:(WebView *)view runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 322 | [[self retain] autorelease]; |
1ee69bb4 | 323 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
324 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)]) |
325 | if ( | |
326 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptConfirmPanelWithMessage:initiatedByFrame:)] || | |
327 | [delegate webView:view shouldRunJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame] | |
328 | ) | |
329 | return [super webView:view runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame]; | |
330 | return NO; | |
331 | } | |
332 | // }}} | |
333 | // webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame: (2.1+) {{{ | |
334 | - (NSString *) webView:(WebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 335 | [[self retain] autorelease]; |
1ee69bb4 | 336 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
337 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)]) |
338 | if ( | |
339 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)] || | |
340 | [delegate webView:view shouldRunJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame] | |
341 | ) | |
342 | return [super webView:view runJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame]; | |
343 | return nil; | |
344 | } | |
345 | // }}} | |
346 | // webViewClose: (3.2+) {{{ | |
347 | static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view) { | |
348 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
349 | if ([uiWebView respondsToSelector:@selector(webViewClose:)]) | |
350 | [uiWebView webViewClose:view]; | |
351 | } | |
352 | ||
353 | - (void) webViewClose:(WebView *)view { | |
1ee69bb4 | 354 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
355 | if ([delegate respondsToSelector:@selector(webViewClose:)]) |
356 | [delegate webViewClose:view]; | |
357 | if ([UIWebView instancesRespondToSelector:@selector(webViewClose:)]) | |
358 | [super webViewClose:view]; | |
359 | } | |
360 | // }}} | |
361 | ||
362 | - (void) _updateViewSettings { | |
363 | [super _updateViewSettings]; | |
364 | ||
1ee69bb4 | 365 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
366 | if ([delegate respondsToSelector:@selector(webViewUpdateViewSettings:)]) |
367 | [delegate webViewUpdateViewSettings:self]; | |
368 | } | |
369 | ||
4bcafc01 | 370 | - (void) dispatchEvent:(NSString *)event { |
31f9c8f7 | 371 | [[self _documentView] dispatchEvent:event]; |
4bcafc01 JF |
372 | } |
373 | ||
a713fcd3 JF |
374 | - (void) reloadFromOrigin { |
375 | [[[self _documentView] webView] reloadFromOrigin:nil]; | |
376 | } | |
377 | ||
d821ecc1 JF |
378 | - (UIScrollView *) scrollView { |
379 | if ([self respondsToSelector:@selector(_scrollView)]) | |
380 | return [self _scrollView]; | |
381 | else if ([self respondsToSelector:@selector(_scroller)]) | |
382 | return (UIScrollView *) [self _scroller]; | |
383 | else return nil; | |
384 | } | |
385 | ||
3cf38067 JF |
386 | - (void) setNeedsLayout { |
387 | [super setNeedsLayout]; | |
388 | ||
389 | WebFrame *frame([[[self _documentView] webView] mainFrame]); | |
390 | if ([frame respondsToSelector:@selector(setNeedsLayout)]) | |
391 | [frame setNeedsLayout]; | |
392 | } | |
393 | ||
09865663 JF |
394 | - (NSURLRequest *) request { |
395 | WebFrame *frame([[[self _documentView] webView] mainFrame]); | |
396 | return [([frame provisionalDataSource] ?: [frame dataSource]) request]; | |
397 | } | |
398 | ||
baa2fba3 JF |
399 | @end |
400 | ||
0291a3a6 JF |
401 | static void $UIWebViewWebViewDelegate$_clearUIWebView(UIWebViewWebViewDelegate *self, SEL sel) { |
402 | MSHookIvar<UIWebView *>(self, "uiWebView") = nil; | |
403 | } | |
404 | ||
baa2fba3 | 405 | __attribute__((__constructor__)) static void $() { |
aa35fd7b JF |
406 | if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) { |
407 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12"); | |
408 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), (IMP) &$UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$, "v28@0:4@8@12@16@20@24"); | |
409 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16"); | |
64ffa332 | 410 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didCommitLoadForFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didCommitLoadForFrame$, "v16@0:4@8@12"); |
aa35fd7b JF |
411 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didReceiveTitle:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$, "v20@0:4@8@12@16"); |
412 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), (IMP) &$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$, "@28@0:4@8@12@16@20@24"); | |
413 | class_addMethod($UIWebViewWebViewDelegate, @selector(webViewClose:), (IMP) &$UIWebViewWebViewDelegate$webViewClose$, "v12@0:4@8"); | |
0291a3a6 | 414 | class_addMethod($UIWebViewWebViewDelegate, @selector(_clearUIWebView), (IMP) &$UIWebViewWebViewDelegate$_clearUIWebView, "v8@0:4"); |
aa35fd7b JF |
415 | } |
416 | } |