OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
6 | 6 |
7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 | 8 |
9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "base/metrics/user_metrics.h" | 32 #include "base/metrics/user_metrics.h" |
33 #include "base/metrics/user_metrics_action.h" | 33 #include "base/metrics/user_metrics_action.h" |
34 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
35 #include "base/strings/sys_string_conversions.h" | 35 #include "base/strings/sys_string_conversions.h" |
36 #include "base/strings/utf_string_conversions.h" | 36 #include "base/strings/utf_string_conversions.h" |
37 #include "base/time/time.h" | 37 #include "base/time/time.h" |
38 #include "base/values.h" | 38 #include "base/values.h" |
39 #include "components/url_formatter/url_formatter.h" | 39 #include "components/url_formatter/url_formatter.h" |
40 #import "ios/net/http_response_headers_util.h" | 40 #import "ios/net/http_response_headers_util.h" |
41 #import "ios/net/nsurlrequest_util.h" | 41 #import "ios/net/nsurlrequest_util.h" |
42 #import "ios/web/crw_network_activity_indicator_manager.h" | |
43 #import "ios/web/history_state_util.h" | 42 #import "ios/web/history_state_util.h" |
44 #include "ios/web/interstitials/web_interstitial_impl.h" | 43 #include "ios/web/interstitials/web_interstitial_impl.h" |
45 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" | 44 #import "ios/web/navigation/crw_session_certificate_policy_manager.h" |
46 #import "ios/web/navigation/crw_session_controller.h" | 45 #import "ios/web/navigation/crw_session_controller.h" |
47 #import "ios/web/navigation/crw_session_entry.h" | 46 #import "ios/web/navigation/crw_session_entry.h" |
48 #import "ios/web/navigation/navigation_item_impl.h" | 47 #import "ios/web/navigation/navigation_item_impl.h" |
49 #import "ios/web/navigation/navigation_manager_impl.h" | 48 #import "ios/web/navigation/navigation_manager_impl.h" |
50 #include "ios/web/net/cert_host_pair.h" | 49 #include "ios/web/net/cert_host_pair.h" |
51 #import "ios/web/net/crw_cert_verification_controller.h" | 50 #import "ios/web/net/crw_cert_verification_controller.h" |
52 #import "ios/web/net/crw_ssl_status_updater.h" | 51 #import "ios/web/net/crw_ssl_status_updater.h" |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 @property(nonatomic, readonly) WKWebView* webView; | 482 @property(nonatomic, readonly) WKWebView* webView; |
484 // The scroll view of |webView|. | 483 // The scroll view of |webView|. |
485 @property(nonatomic, readonly) UIScrollView* webScrollView; | 484 @property(nonatomic, readonly) UIScrollView* webScrollView; |
486 // The current page state of the web view. Writing to this property | 485 // The current page state of the web view. Writing to this property |
487 // asynchronously applies the passed value to the current web view. | 486 // asynchronously applies the passed value to the current web view. |
488 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; | 487 @property(nonatomic, readwrite) web::PageDisplayState pageDisplayState; |
489 // The currently displayed native controller, if any. | 488 // The currently displayed native controller, if any. |
490 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController; | 489 @property(nonatomic, readwrite) id<CRWNativeContent> nativeController; |
491 // Returns NavigationManager's session controller. | 490 // Returns NavigationManager's session controller. |
492 @property(nonatomic, readonly) CRWSessionController* sessionController; | 491 @property(nonatomic, readonly) CRWSessionController* sessionController; |
493 // Activity indicator group ID for this web controller. | |
494 @property(nonatomic, readonly) NSString* activityIndicatorGroupID; | |
495 // Dictionary where keys are the names of WKWebView properties and values are | 492 // Dictionary where keys are the names of WKWebView properties and values are |
496 // selector names which should be called when a corresponding property has | 493 // selector names which should be called when a corresponding property has |
497 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 494 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
498 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 495 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
499 // changed. | 496 // changed. |
500 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers; | 497 @property(nonatomic, readonly) NSDictionary* WKWebViewObservers; |
501 // Downloader for PassKit files. Lazy initialized. | 498 // Downloader for PassKit files. Lazy initialized. |
502 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; | 499 @property(nonatomic, readonly) CRWPassKitDownloader* passKitDownloader; |
503 | 500 |
504 // The web view's view of the current URL. During page transitions | 501 // The web view's view of the current URL. During page transitions |
(...skipping 30 matching lines...) Expand all Loading... |
535 // a web page the document has actually changed), or after the load request has | 532 // a web page the document has actually changed), or after the load request has |
536 // been registered for a non-document-changing URL change. Updates internal | 533 // been registered for a non-document-changing URL change. Updates internal |
537 // state not specific to web pages, and informs the delegate. | 534 // state not specific to web pages, and informs the delegate. |
538 - (void)didStartLoadingURL:(const GURL&)URL updateHistory:(BOOL)updateHistory; | 535 - (void)didStartLoadingURL:(const GURL&)URL updateHistory:(BOOL)updateHistory; |
539 // Returns YES if the URL looks like it is one CRWWebController can show. | 536 // Returns YES if the URL looks like it is one CRWWebController can show. |
540 + (BOOL)webControllerCanShow:(const GURL&)url; | 537 + (BOOL)webControllerCanShow:(const GURL&)url; |
541 // Clears the currently-displayed transient content view. | 538 // Clears the currently-displayed transient content view. |
542 - (void)clearTransientContentView; | 539 - (void)clearTransientContentView; |
543 // Returns a lazily created CRWTouchTrackingRecognizer. | 540 // Returns a lazily created CRWTouchTrackingRecognizer. |
544 - (CRWTouchTrackingRecognizer*)touchTrackingRecognizer; | 541 - (CRWTouchTrackingRecognizer*)touchTrackingRecognizer; |
545 // Adds an activity indicator tasks for this web controller. | |
546 - (void)addActivityIndicatorTask; | |
547 // Clears all activity indicator tasks for this web controller. | |
548 - (void)clearActivityIndicatorTasks; | |
549 // Shows placeholder overlay. | 542 // Shows placeholder overlay. |
550 - (void)addPlaceholderOverlay; | 543 - (void)addPlaceholderOverlay; |
551 // Removes placeholder overlay. | 544 // Removes placeholder overlay. |
552 - (void)removePlaceholderOverlay; | 545 - (void)removePlaceholderOverlay; |
553 | 546 |
554 // Returns the current entry from the underlying session controller. | 547 // Returns the current entry from the underlying session controller. |
555 // TODO(stuartmorgan): Audit all calls to these methods; these are just wrappers | 548 // TODO(stuartmorgan): Audit all calls to these methods; these are just wrappers |
556 // around the same logic as GetActiveEntry, so should probably not be used for | 549 // around the same logic as GetActiveEntry, so should probably not be used for |
557 // the same reason that GetActiveEntry is deprecated. (E.g., page operations | 550 // the same reason that GetActiveEntry is deprecated. (E.g., page operations |
558 // should generally be dealing with the last commited entry, not a pending | 551 // should generally be dealing with the last commited entry, not a pending |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 return; | 1160 return; |
1168 | 1161 |
1169 // Unset the delegate on the previous instance. | 1162 // Unset the delegate on the previous instance. |
1170 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) | 1163 if ([self.nativeController respondsToSelector:@selector(setDelegate:)]) |
1171 [self.nativeController setDelegate:nil]; | 1164 [self.nativeController setDelegate:nil]; |
1172 | 1165 |
1173 [_containerView displayNativeContent:nativeController]; | 1166 [_containerView displayNativeContent:nativeController]; |
1174 [self setNativeControllerWebUsageEnabled:_webUsageEnabled]; | 1167 [self setNativeControllerWebUsageEnabled:_webUsageEnabled]; |
1175 } | 1168 } |
1176 | 1169 |
1177 - (NSString*)activityIndicatorGroupID { | |
1178 return [NSString | |
1179 stringWithFormat:@"WebController.NetworkActivityIndicatorKey.%@", | |
1180 self.webStateImpl->GetRequestGroupID()]; | |
1181 } | |
1182 | |
1183 - (NSDictionary*)WKWebViewObservers { | 1170 - (NSDictionary*)WKWebViewObservers { |
1184 return @{ | 1171 return @{ |
1185 @"certificateChain" : @"webViewSecurityFeaturesDidChange", | 1172 @"certificateChain" : @"webViewSecurityFeaturesDidChange", |
1186 @"estimatedProgress" : @"webViewEstimatedProgressDidChange", | 1173 @"estimatedProgress" : @"webViewEstimatedProgressDidChange", |
1187 @"hasOnlySecureContent" : @"webViewSecurityFeaturesDidChange", | 1174 @"hasOnlySecureContent" : @"webViewSecurityFeaturesDidChange", |
1188 @"loading" : @"webViewLoadingStateDidChange", | 1175 @"loading" : @"webViewLoadingStateDidChange", |
1189 @"title" : @"webViewTitleDidChange", | 1176 @"title" : @"webViewTitleDidChange", |
1190 @"URL" : @"webViewURLDidChange", | 1177 @"URL" : @"webViewURLDidChange", |
1191 }; | 1178 }; |
1192 } | 1179 } |
(...skipping 2743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3936 } | 3923 } |
3937 | 3924 |
3938 - (BOOL)userClickedRecently { | 3925 - (BOOL)userClickedRecently { |
3939 if (!_lastUserInteraction) | 3926 if (!_lastUserInteraction) |
3940 return NO; | 3927 return NO; |
3941 return _clickInProgress || | 3928 return _clickInProgress || |
3942 ((CFAbsoluteTimeGetCurrent() - _lastUserInteraction->time) < | 3929 ((CFAbsoluteTimeGetCurrent() - _lastUserInteraction->time) < |
3943 kMaximumDelayForUserInteractionInSeconds); | 3930 kMaximumDelayForUserInteractionInSeconds); |
3944 } | 3931 } |
3945 | 3932 |
3946 - (void)addActivityIndicatorTask { | |
3947 [[CRWNetworkActivityIndicatorManager sharedInstance] | |
3948 startNetworkTaskForGroup:[self activityIndicatorGroupID]]; | |
3949 } | |
3950 | |
3951 - (void)clearActivityIndicatorTasks { | |
3952 [[CRWNetworkActivityIndicatorManager sharedInstance] | |
3953 clearNetworkTasksForGroup:[self activityIndicatorGroupID]]; | |
3954 } | |
3955 | |
3956 #pragma mark Placeholder Overlay Methods | 3933 #pragma mark Placeholder Overlay Methods |
3957 | 3934 |
3958 - (void)addPlaceholderOverlay { | 3935 - (void)addPlaceholderOverlay { |
3959 if (!_overlayPreviewMode) { | 3936 if (!_overlayPreviewMode) { |
3960 // Create |kSnapshotOverlayDelay| second timer to remove image with | 3937 // Create |kSnapshotOverlayDelay| second timer to remove image with |
3961 // transition. | 3938 // transition. |
3962 [self performSelector:@selector(removePlaceholderOverlay) | 3939 [self performSelector:@selector(removePlaceholderOverlay) |
3963 withObject:nil | 3940 withObject:nil |
3964 afterDelay:kSnapshotOverlayDelay]; | 3941 afterDelay:kSnapshotOverlayDelay]; |
3965 } | 3942 } |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4777 CRWWKScriptMessageRouter* messageRouter = | 4754 CRWWKScriptMessageRouter* messageRouter = |
4778 [self webViewConfigurationProvider].GetScriptMessageRouter(); | 4755 [self webViewConfigurationProvider].GetScriptMessageRouter(); |
4779 if (_webView) { | 4756 if (_webView) { |
4780 [messageRouter removeAllScriptMessageHandlersForWebView:_webView]; | 4757 [messageRouter removeAllScriptMessageHandlersForWebView:_webView]; |
4781 } | 4758 } |
4782 [_webView setNavigationDelegate:nil]; | 4759 [_webView setNavigationDelegate:nil]; |
4783 [_webView setUIDelegate:nil]; | 4760 [_webView setUIDelegate:nil]; |
4784 for (NSString* keyPath in self.WKWebViewObservers) { | 4761 for (NSString* keyPath in self.WKWebViewObservers) { |
4785 [_webView removeObserver:self forKeyPath:keyPath]; | 4762 [_webView removeObserver:self forKeyPath:keyPath]; |
4786 } | 4763 } |
4787 [self clearActivityIndicatorTasks]; | |
4788 | 4764 |
4789 _webView.reset([webView retain]); | 4765 _webView.reset([webView retain]); |
4790 | 4766 |
4791 // Set up the new web view. | 4767 // Set up the new web view. |
4792 if (webView) { | 4768 if (webView) { |
4793 base::WeakNSObject<CRWWebController> weakSelf(self); | 4769 base::WeakNSObject<CRWWebController> weakSelf(self); |
4794 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { | 4770 [messageRouter setScriptMessageHandler:^(WKScriptMessage* message) { |
4795 [weakSelf didReceiveScriptMessage:message]; | 4771 [weakSelf didReceiveScriptMessage:message]; |
4796 } | 4772 } |
4797 name:kScriptMessageName | 4773 name:kScriptMessageName |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5426 - (void)webViewSecurityFeaturesDidChange { | 5402 - (void)webViewSecurityFeaturesDidChange { |
5427 if (self.loadPhase == web::LOAD_REQUESTED) { | 5403 if (self.loadPhase == web::LOAD_REQUESTED) { |
5428 // Do not update SSL Status for pending load. It will be updated in | 5404 // Do not update SSL Status for pending load. It will be updated in |
5429 // |webView:didCommitNavigation:| callback. | 5405 // |webView:didCommitNavigation:| callback. |
5430 return; | 5406 return; |
5431 } | 5407 } |
5432 [self updateSSLStatusForCurrentNavigationItem]; | 5408 [self updateSSLStatusForCurrentNavigationItem]; |
5433 } | 5409 } |
5434 | 5410 |
5435 - (void)webViewLoadingStateDidChange { | 5411 - (void)webViewLoadingStateDidChange { |
5436 if ([_webView isLoading]) { | 5412 if ([_webView isLoading] || ![self isCurrentNavigationBackForward]) { |
5437 [self addActivityIndicatorTask]; | |
5438 return; | 5413 return; |
5439 } | 5414 } |
5440 | 5415 |
5441 [self clearActivityIndicatorTasks]; | |
5442 if (![self isCurrentNavigationBackForward]) { | |
5443 return; | |
5444 } | |
5445 | |
5446 GURL webViewURL = net::GURLWithNSURL([_webView URL]); | 5416 GURL webViewURL = net::GURLWithNSURL([_webView URL]); |
5447 | 5417 |
5448 // For failed navigations, WKWebView will sometimes revert to the previous URL | 5418 // For failed navigations, WKWebView will sometimes revert to the previous URL |
5449 // before committing the current navigation or resetting the web view's | 5419 // before committing the current navigation or resetting the web view's |
5450 // |isLoading| property to NO. If this is the first navigation for the web | 5420 // |isLoading| property to NO. If this is the first navigation for the web |
5451 // view, this will result in an empty URL. | 5421 // view, this will result in an empty URL. |
5452 BOOL navigationWasCommitted = _loadPhase != web::LOAD_REQUESTED; | 5422 BOOL navigationWasCommitted = _loadPhase != web::LOAD_REQUESTED; |
5453 if (!navigationWasCommitted && | 5423 if (!navigationWasCommitted && |
5454 (webViewURL.is_empty() || webViewURL == _documentURL)) { | 5424 (webViewURL.is_empty() || webViewURL == _documentURL)) { |
5455 return; | 5425 return; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5802 } | 5772 } |
5803 | 5773 |
5804 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5774 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
5805 } | 5775 } |
5806 | 5776 |
5807 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5777 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
5808 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5778 return [action.request valueForHTTPHeaderField:@"Referer"]; |
5809 } | 5779 } |
5810 | 5780 |
5811 @end | 5781 @end |
OLD | NEW |