Guest User

Untitled

a guest
Jan 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. //
  2. // BPPrivateWebView.m
  3. // BPUI
  4. //
  5. // Created by akisute on 11/09/11.
  6. //
  7. /*
  8. Copyright (c) 2011 Masashi Ono.
  9.  
  10. Permission is hereby granted, free of charge, to any person obtaining a copy of
  11. this software and associated documentation files (the "Software"), to deal in
  12. the Software without restriction, including without limitation the rights to
  13. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  14. of the Software, and to permit persons to whom the Software is furnished to do
  15. so, subject to the following conditions:
  16.  
  17. The above copyright notice and this permission notice shall be included in all
  18. copies or substantial portions of the Software.
  19.  
  20. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  26. SOFTWARE.
  27. */
  28.  
  29. #import "BPPrivateWebView.h"
  30.  
  31.  
  32. #ifdef DEBUG
  33. @interface UIWebView(BPPrivateWebView_PrivateAPI)
  34.  
  35. // とりあえず使えそうなUIWebViewのPrivate Methodを列挙してみました。
  36. // UIWebViewはWebKitのクラスのdelegateになっているのでこの辺が使えます
  37.  
  38. - (BOOL)webView:(id)arg1 resource:(id)arg2 canAuthenticateAgainstProtectionSpace:(id)arg3 forDataSource:(id)arg4;
  39. - (void)webView:(id)arg1 resource:(id)arg2 didCancelAuthenticationChallenge:(id)arg3 fromDataSource:(id)arg4;
  40. - (void)webView:(id)arg1 resource:(id)arg2 didReceiveAuthenticationChallenge:(id)arg3 fromDataSource:(id)arg4;
  41. - (void)webView:(id)arg1 resource:(id)arg2 didFailLoadingWithError:(id)arg3 fromDataSource:(id)arg4;
  42. - (void)webView:(id)arg1 resource:(id)arg2 didFinishLoadingFromDataSource:(id)arg3;
  43.  
  44. - (id)webView:(id)arg1 resource:(id)arg2 willSendRequest:(id)arg3 redirectResponse:(id)arg4 fromDataSource:(id)arg5;
  45. - (id)webView:(id)arg1 connectionPropertiesForResource:(id)arg2 dataSource:(id)arg3;
  46.  
  47. @end
  48. #endif
  49.  
  50.  
  51. #pragma mark -
  52.  
  53.  
  54. @interface BPPrivateWebView ()
  55. - (void)__logWebDataSource:(id)webDataSource;
  56. @end
  57.  
  58.  
  59. #pragma mark -
  60.  
  61.  
  62. @implementation BPPrivateWebView
  63.  
  64.  
  65. @synthesize authenticationDelegate = _authenticationDelegate;
  66. @synthesize enableVerboseLog = _enableVerboseLog;
  67.  
  68.  
  69. #pragma mark - Init/dealloc
  70.  
  71.  
  72. - (id)initWithFrame:(CGRect)frame
  73. {
  74. self = [super initWithFrame:frame];
  75. if (self) {
  76. self.authenticationDelegate = nil;
  77. self.enableVerboseLog = NO;
  78. }
  79. return self;
  80. }
  81.  
  82. - (id)initWithCoder:(NSCoder *)aDecoder
  83. {
  84. self = [super initWithCoder:aDecoder];
  85. if (self) {
  86. // NSCoding not supported
  87. }
  88. return self;
  89. }
  90.  
  91. - (void)dealloc
  92. {
  93. [super dealloc];
  94. }
  95.  
  96.  
  97. #pragma mark - Private
  98.  
  99.  
  100. - (void)__logWebDataSource:(id)webDataSource
  101. {
  102. if (self.enableVerboseLog) {
  103. NSLog(@" * dataSource = %@", webDataSource);
  104. NSLog(@" * dataSource.initialRequest = %@", [webDataSource valueForKey:@"initialRequest"]);
  105. NSLog(@" * dataSource.request = %@", [webDataSource valueForKey:@"request"]);
  106. NSLog(@" * dataSource.response = %@", [webDataSource valueForKey:@"request"]);
  107. NSLog(@" * dataSource.isLoading = %d", [webDataSource isLoading]);
  108. NSLog(@" * dataSource.pageTitle = %@", [webDataSource valueForKey:@"pageTitle"]);
  109. NSLog(@" * dataSource.textEncodingName = %@", [webDataSource valueForKey:@"textEncodingName"]);
  110. NSLog(@" * dataSource.webArchive = %@", [webDataSource valueForKey:@"webArchive"]);
  111. NSLog(@" * dataSource.mainResource = %@", [webDataSource valueForKey:@"mainResource"]);
  112. NSLog(@" * dataSource.data = %@", [webDataSource valueForKey:@"data"]);
  113. }
  114. }
  115.  
  116. #pragma mark - WebKit private callbacks
  117. #ifdef DEBUG
  118.  
  119. - (BOOL)webView:(id)arg1 resource:(id)arg2 canAuthenticateAgainstProtectionSpace:(id)arg3 forDataSource:(id)arg4
  120. {
  121. if (self.enableVerboseLog) {
  122. NSLog(@"%s", __func__);
  123. NSLog(@" * resource = %@", arg2);
  124. NSLog(@" * protectionSpace = %@", arg3);
  125. [self __logWebDataSource:arg4];
  126. }
  127.  
  128. if ([self.authenticationDelegate respondsToSelector:@selector(webView:canAuthenticateAgainstProtectionSpace:)]) {
  129. return [self.authenticationDelegate webView:self canAuthenticateAgainstProtectionSpace:arg3];
  130. } else {
  131. return [super webView:arg1 resource:arg2 canAuthenticateAgainstProtectionSpace:arg3 forDataSource:arg4];
  132. }
  133. }
  134.  
  135. - (void)webView:(id)arg1 resource:(id)arg2 didCancelAuthenticationChallenge:(id)arg3 fromDataSource:(id)arg4
  136. {
  137. if (self.enableVerboseLog) {
  138. NSLog(@"%s", __func__);
  139. NSLog(@" * resource = %@", arg2);
  140. NSLog(@" * authenticationChallenge = %@", arg3);
  141. [self __logWebDataSource:arg4];
  142. }
  143.  
  144. if ([self.authenticationDelegate respondsToSelector:@selector(webView:didCancelAuthenticationChallenge:)]) {
  145. [self.authenticationDelegate webView:self didCancelAuthenticationChallenge:arg3];
  146. } else {
  147. [super webView:arg1 resource:arg2 didCancelAuthenticationChallenge:arg3 fromDataSource:arg4];
  148. }
  149. }
  150.  
  151. - (void)webView:(id)arg1 resource:(id)arg2 didReceiveAuthenticationChallenge:(id)arg3 fromDataSource:(id)arg4
  152. {
  153. if (self.enableVerboseLog) {
  154. NSLog(@"%s", __func__);
  155. NSLog(@" * resource = %@", arg2);
  156. NSLog(@" * authenticationChallenge = %@", arg3);
  157. [self __logWebDataSource:arg4];
  158. }
  159.  
  160. if ([self.authenticationDelegate respondsToSelector:@selector(webView:didReceiveAuthenticationChallenge:)]) {
  161. [self.authenticationDelegate webView:self didReceiveAuthenticationChallenge:arg3];
  162. } else {
  163. [super webView:arg1 resource:arg2 didReceiveAuthenticationChallenge:arg3 fromDataSource:arg4];
  164. }
  165. }
  166.  
  167. - (void)webView:(id)arg1 resource:(id)arg2 didFailLoadingWithError:(id)arg3 fromDataSource:(id)arg4
  168. {
  169. if (self.enableVerboseLog) {
  170. NSLog(@"%s", __func__);
  171. NSLog(@" * resource = %@", arg2);
  172. NSLog(@" * error = %@", arg3);
  173. [self __logWebDataSource:arg4];
  174. }
  175.  
  176. [super webView:arg1 resource:arg2 didFailLoadingWithError:arg3 fromDataSource:arg4];
  177. }
  178.  
  179. - (void)webView:(id)arg1 resource:(id)arg2 didFinishLoadingFromDataSource:(id)arg3
  180. {
  181. if (self.enableVerboseLog) {
  182. NSLog(@"%s", __func__);
  183. NSLog(@" * resource = %@", arg2);
  184. [self __logWebDataSource:arg3];
  185. }
  186.  
  187. [super webView:arg1 resource:arg2 didFinishLoadingFromDataSource:arg3];
  188. }
  189.  
  190. - (id)webView:(id)arg1 resource:(id)arg2 willSendRequest:(id)arg3 redirectResponse:(id)arg4 fromDataSource:(id)arg5
  191. {
  192. if (self.enableVerboseLog) {
  193. NSLog(@"%s", __func__);
  194. NSLog(@" * resource = %@", arg2);
  195. NSLog(@" * request = %@", arg3);
  196. NSLog(@" * redirectResponse = %@", arg4);
  197. [self __logWebDataSource:arg5];
  198. }
  199.  
  200. return [super webView:arg1 resource:arg2 willSendRequest:arg3 redirectResponse:arg4 fromDataSource:arg5];
  201. }
  202.  
  203. - (id)webView:(id)arg1 connectionPropertiesForResource:(id)arg2 dataSource:(id)arg3
  204. {
  205. if (self.enableVerboseLog) {
  206. NSLog(@"%s", __func__);
  207. NSLog(@" * resource = %@", arg2);
  208. [self __logWebDataSource:arg3];
  209. }
  210.  
  211. return [super webView:arg1 connectionPropertiesForResource:arg2 dataSource:arg3];
  212. }
  213.  
  214. #endif
  215.  
  216. @end
Add Comment
Please, Sign In to add comment