OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 #import "ios/web/web_state/ui/web_view_js_utils.h" | 37 #import "ios/web/web_state/ui/web_view_js_utils.h" |
38 #import "ios/web/web_state/web_state_impl.h" | 38 #import "ios/web/web_state/web_state_impl.h" |
39 #import "ios/web/web_state/wk_web_view_security_util.h" | 39 #import "ios/web/web_state/wk_web_view_security_util.h" |
40 #import "net/base/mac/url_conversions.h" | 40 #import "net/base/mac/url_conversions.h" |
41 #include "net/cert/x509_certificate.h" | 41 #include "net/cert/x509_certificate.h" |
42 #include "net/ssl/ssl_info.h" | 42 #include "net/ssl/ssl_info.h" |
43 #include "url/url_constants.h" | 43 #include "url/url_constants.h" |
44 | 44 |
45 #pragma mark - | 45 #pragma mark - |
46 | 46 |
47 @interface CRWWKWebViewWebController () { | 47 @interface CRWWKWebViewWebController () |
48 // The actual URL of the document object (i.e., the last committed URL). | |
49 // TODO(crbug.com/549616): Remove this in favor of just updating the | |
50 // navigation manager and treating that as authoritative. For now, this allows | |
51 // sharing the flow that's currently in the superclass. | |
52 GURL _documentURL; | |
53 | |
54 // YES if the user has interacted with the content area since the last URL | |
55 // change. | |
56 BOOL _interactionRegisteredSinceLastURLChange; | |
57 } | |
58 | 48 |
59 // Returns YES if the given WKBackForwardListItem is valid to use for | 49 // Returns YES if the given WKBackForwardListItem is valid to use for |
60 // navigation. | 50 // navigation. |
61 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; | 51 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; |
62 | 52 |
63 @end | 53 @end |
64 | 54 |
65 @implementation CRWWKWebViewWebController | 55 @implementation CRWWKWebViewWebController |
66 | 56 |
67 #pragma mark - Protected property implementations | |
68 | |
69 - (GURL)documentURL { | |
70 return _documentURL; | |
71 } | |
72 | |
73 - (BOOL)interactionRegisteredSinceLastURLChange { | |
74 return _interactionRegisteredSinceLastURLChange; | |
75 } | |
76 | |
77 // Overridden to track interactions since URL change. | |
78 - (void)setUserInteractionRegistered:(BOOL)flag { | |
79 [super setUserInteractionRegistered:flag]; | |
80 if (flag) | |
81 _interactionRegisteredSinceLastURLChange = YES; | |
82 } | |
83 | |
84 #pragma mark Protected method implementations | 57 #pragma mark Protected method implementations |
85 | 58 |
86 - (GURL)webURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel { | |
87 DCHECK(trustLevel); | |
88 *trustLevel = web::URLVerificationTrustLevel::kAbsolute; | |
89 return _documentURL; | |
90 } | |
91 | |
92 // The core.js cannot pass messages back to obj-c if it is injected | 59 // The core.js cannot pass messages back to obj-c if it is injected |
93 // to |WEB_VIEW_DOCUMENT| because it does not support iframe creation used | 60 // to |WEB_VIEW_DOCUMENT| because it does not support iframe creation used |
94 // by core.js to communicate back. That functionality is only supported | 61 // by core.js to communicate back. That functionality is only supported |
95 // by |WEB_VIEW_HTML_DOCUMENT|. |WEB_VIEW_DOCUMENT| is used when displaying | 62 // by |WEB_VIEW_HTML_DOCUMENT|. |WEB_VIEW_DOCUMENT| is used when displaying |
96 // non-HTML contents (e.g. PDF documents). | 63 // non-HTML contents (e.g. PDF documents). |
97 - (web::WebViewDocumentType)webViewDocumentType { | 64 - (web::WebViewDocumentType)webViewDocumentType { |
98 // This happens during tests. | 65 // This happens during tests. |
99 if (!self.webView) { | 66 if (!self.webView) { |
100 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 67 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
101 } | 68 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 CGFloat zoomScale = zoomState.zoom_scale(); | 185 CGFloat zoomScale = zoomState.zoom_scale(); |
219 if (zoomScale < self.webScrollView.minimumZoomScale) | 186 if (zoomScale < self.webScrollView.minimumZoomScale) |
220 zoomScale = self.webScrollView.minimumZoomScale; | 187 zoomScale = self.webScrollView.minimumZoomScale; |
221 if (zoomScale > self.webScrollView.maximumZoomScale) | 188 if (zoomScale > self.webScrollView.maximumZoomScale) |
222 zoomScale = self.webScrollView.maximumZoomScale; | 189 zoomScale = self.webScrollView.maximumZoomScale; |
223 self.webScrollView.zoomScale = zoomScale; | 190 self.webScrollView.zoomScale = zoomScale; |
224 } | 191 } |
225 | 192 |
226 #pragma mark Private methods | 193 #pragma mark Private methods |
227 | 194 |
228 - (void)setDocumentURL:(const GURL&)newURL { | |
229 if (newURL != _documentURL) { | |
230 _documentURL = newURL; | |
231 _interactionRegisteredSinceLastURLChange = NO; | |
232 } | |
233 } | |
234 | |
235 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item { | 195 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item { |
236 // The current back-forward list item MUST be in the WKWebView's back-forward | 196 // The current back-forward list item MUST be in the WKWebView's back-forward |
237 // list to be valid. | 197 // list to be valid. |
238 WKBackForwardList* list = [self.webView backForwardList]; | 198 WKBackForwardList* list = [self.webView backForwardList]; |
239 return list.currentItem == item || | 199 return list.currentItem == item || |
240 [list.forwardList indexOfObject:item] != NSNotFound || | 200 [list.forwardList indexOfObject:item] != NSNotFound || |
241 [list.backList indexOfObject:item] != NSNotFound; | 201 [list.backList indexOfObject:item] != NSNotFound; |
242 } | 202 } |
243 | 203 |
244 - (void)webViewWebProcessDidCrash { | 204 - (void)webViewWebProcessDidCrash { |
(...skipping 23 matching lines...) Expand all Loading... |
268 } | 228 } |
269 | 229 |
270 - (void)webViewScrollViewDidEndDragging: | 230 - (void)webViewScrollViewDidEndDragging: |
271 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy | 231 (CRWWebViewScrollViewProxy*)webViewScrollViewProxy |
272 willDecelerate:(BOOL)decelerate { | 232 willDecelerate:(BOOL)decelerate { |
273 [self evaluateJavaScript:@"__gCrWeb.setWebViewScrollViewIsDragging(false)" | 233 [self evaluateJavaScript:@"__gCrWeb.setWebViewScrollViewIsDragging(false)" |
274 stringResultHandler:nil]; | 234 stringResultHandler:nil]; |
275 } | 235 } |
276 | 236 |
277 @end | 237 @end |
OLD | NEW |