]>
Commit | Line | Data |
---|---|---|
f172aa8f | 1 | /* Cydia - iPhone UIKit Front-End for Debian APT |
323746d3 | 2 | * Copyright (C) 2008-2013 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 | |
435cb857 JF |
25 | #include <CydiaSubstrate/CydiaSubstrate.h> |
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]; | |
295 | return request; | |
296 | } | |
297 | // }}} | |
298 | // webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: (2.1+) {{{ | |
299 | - (void) webView:(WebView *)view runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 300 | [[self retain] autorelease]; |
1ee69bb4 | 301 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
302 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)]) |
303 | if ( | |
304 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptAlertPanelWithMessage:initiatedByFrame:)] || | |
305 | [delegate webView:view shouldRunJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame] | |
306 | ) | |
307 | [super webView:view runJavaScriptAlertPanelWithMessage:message initiatedByFrame:frame]; | |
308 | } | |
309 | // }}} | |
310 | // webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame: (2.1+) {{{ | |
311 | - (BOOL) webView:(WebView *)view runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 312 | [[self retain] autorelease]; |
1ee69bb4 | 313 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
314 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)]) |
315 | if ( | |
316 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptConfirmPanelWithMessage:initiatedByFrame:)] || | |
317 | [delegate webView:view shouldRunJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame] | |
318 | ) | |
319 | return [super webView:view runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:frame]; | |
320 | return NO; | |
321 | } | |
322 | // }}} | |
323 | // webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame: (2.1+) {{{ | |
324 | - (NSString *) webView:(WebView *)view runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)text initiatedByFrame:(WebFrame *)frame { | |
eea75e8f | 325 | [[self retain] autorelease]; |
1ee69bb4 | 326 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
327 | if ([UIWebView instancesRespondToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)]) |
328 | if ( | |
329 | ![delegate respondsToSelector:@selector(webView:shouldRunJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)] || | |
330 | [delegate webView:view shouldRunJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame] | |
331 | ) | |
332 | return [super webView:view runJavaScriptTextInputPanelWithPrompt:prompt defaultText:text initiatedByFrame:frame]; | |
333 | return nil; | |
334 | } | |
335 | // }}} | |
336 | // webViewClose: (3.2+) {{{ | |
337 | static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *self, SEL sel, WebView *view) { | |
338 | UIWebView *uiWebView(MSHookIvar<UIWebView *>(self, "uiWebView")); | |
339 | if ([uiWebView respondsToSelector:@selector(webViewClose:)]) | |
340 | [uiWebView webViewClose:view]; | |
341 | } | |
342 | ||
343 | - (void) webViewClose:(WebView *)view { | |
1ee69bb4 | 344 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
345 | if ([delegate respondsToSelector:@selector(webViewClose:)]) |
346 | [delegate webViewClose:view]; | |
347 | if ([UIWebView instancesRespondToSelector:@selector(webViewClose:)]) | |
348 | [super webViewClose:view]; | |
349 | } | |
350 | // }}} | |
351 | ||
352 | - (void) _updateViewSettings { | |
353 | [super _updateViewSettings]; | |
354 | ||
1ee69bb4 | 355 | id<CyteWebViewDelegate> delegate([self delegate]); |
aa35fd7b JF |
356 | if ([delegate respondsToSelector:@selector(webViewUpdateViewSettings:)]) |
357 | [delegate webViewUpdateViewSettings:self]; | |
358 | } | |
359 | ||
4bcafc01 | 360 | - (void) dispatchEvent:(NSString *)event { |
31f9c8f7 | 361 | [[self _documentView] dispatchEvent:event]; |
4bcafc01 JF |
362 | } |
363 | ||
a713fcd3 JF |
364 | - (void) reloadFromOrigin { |
365 | [[[self _documentView] webView] reloadFromOrigin:nil]; | |
366 | } | |
367 | ||
d821ecc1 JF |
368 | - (UIScrollView *) scrollView { |
369 | if ([self respondsToSelector:@selector(_scrollView)]) | |
370 | return [self _scrollView]; | |
371 | else if ([self respondsToSelector:@selector(_scroller)]) | |
372 | return (UIScrollView *) [self _scroller]; | |
373 | else return nil; | |
374 | } | |
375 | ||
3cf38067 JF |
376 | - (void) setNeedsLayout { |
377 | [super setNeedsLayout]; | |
378 | ||
379 | WebFrame *frame([[[self _documentView] webView] mainFrame]); | |
380 | if ([frame respondsToSelector:@selector(setNeedsLayout)]) | |
381 | [frame setNeedsLayout]; | |
382 | } | |
383 | ||
09865663 JF |
384 | - (NSURLRequest *) request { |
385 | WebFrame *frame([[[self _documentView] webView] mainFrame]); | |
386 | return [([frame provisionalDataSource] ?: [frame dataSource]) request]; | |
387 | } | |
388 | ||
baa2fba3 JF |
389 | @end |
390 | ||
0291a3a6 JF |
391 | static void $UIWebViewWebViewDelegate$_clearUIWebView(UIWebViewWebViewDelegate *self, SEL sel) { |
392 | MSHookIvar<UIWebView *>(self, "uiWebView") = nil; | |
393 | } | |
394 | ||
baa2fba3 | 395 | __attribute__((__constructor__)) static void $() { |
aa35fd7b JF |
396 | if (Class $UIWebViewWebViewDelegate = objc_getClass("UIWebViewWebViewDelegate")) { |
397 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:addMessageToConsole:), (IMP) &$UIWebViewWebViewDelegate$webView$addMessageToConsole$, "v16@0:4@8@12"); | |
398 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), (IMP) &$UIWebViewWebViewDelegate$webView$decidePolicyForNewWindowAction$request$newFrameName$decisionListener$, "v28@0:4@8@12@16@20@24"); | |
399 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didClearWindowObject:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didClearWindowObject$forFrame$, "v20@0:4@8@12@16"); | |
64ffa332 | 400 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didCommitLoadForFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didCommitLoadForFrame$, "v16@0:4@8@12"); |
aa35fd7b JF |
401 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:didReceiveTitle:forFrame:), (IMP) &$UIWebViewWebViewDelegate$webView$didReceiveTitle$forFrame$, "v20@0:4@8@12@16"); |
402 | class_addMethod($UIWebViewWebViewDelegate, @selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:), (IMP) &$UIWebViewWebViewDelegate$webView$resource$willSendRequest$redirectResponse$fromDataSource$, "@28@0:4@8@12@16@20@24"); | |
403 | class_addMethod($UIWebViewWebViewDelegate, @selector(webViewClose:), (IMP) &$UIWebViewWebViewDelegate$webViewClose$, "v12@0:4@8"); | |
0291a3a6 | 404 | class_addMethod($UIWebViewWebViewDelegate, @selector(_clearUIWebView), (IMP) &$UIWebViewWebViewDelegate$_clearUIWebView, "v8@0:4"); |
aa35fd7b JF |
405 | } |
406 | } |