| 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 // reflect the fact that the navigation has occurred. | 480 // reflect the fact that the navigation has occurred. |
| 481 // TODO(stuartmorgan): The code conflates URL changes and document object | 481 // TODO(stuartmorgan): The code conflates URL changes and document object |
| 482 // changes; the two need to be separated and handled differently. | 482 // changes; the two need to be separated and handled differently. |
| 483 - (void)webPageChanged; | 483 - (void)webPageChanged; |
| 484 // Resets any state that is associated with a specific document object (e.g., | 484 // Resets any state that is associated with a specific document object (e.g., |
| 485 // page interaction tracking). | 485 // page interaction tracking). |
| 486 - (void)resetDocumentSpecificState; | 486 - (void)resetDocumentSpecificState; |
| 487 // Called when a page (native or web) has actually started loading (i.e., for | 487 // Called when a page (native or web) has actually started loading (i.e., for |
| 488 // a web page the document has actually changed), or after the load request has | 488 // a web page the document has actually changed), or after the load request has |
| 489 // been registered for a non-document-changing URL change. Updates internal | 489 // been registered for a non-document-changing URL change. Updates internal |
| 490 // state not specific to web pages, and informs the delegate. | 490 // state not specific to web pages. |
| 491 - (void)didStartLoadingURL:(const GURL&)URL updateHistory:(BOOL)updateHistory; | 491 - (void)didStartLoadingURL:(const GURL&)URL; |
| 492 // Returns YES if the URL looks like it is one CRWWebController can show. | 492 // Returns YES if the URL looks like it is one CRWWebController can show. |
| 493 + (BOOL)webControllerCanShow:(const GURL&)url; | 493 + (BOOL)webControllerCanShow:(const GURL&)url; |
| 494 // Clears the currently-displayed transient content view. | 494 // Clears the currently-displayed transient content view. |
| 495 - (void)clearTransientContentView; | 495 - (void)clearTransientContentView; |
| 496 // Returns a lazily created CRWTouchTrackingRecognizer. | 496 // Returns a lazily created CRWTouchTrackingRecognizer. |
| 497 - (CRWTouchTrackingRecognizer*)touchTrackingRecognizer; | 497 - (CRWTouchTrackingRecognizer*)touchTrackingRecognizer; |
| 498 // Shows placeholder overlay. | 498 // Shows placeholder overlay. |
| 499 - (void)addPlaceholderOverlay; | 499 - (void)addPlaceholderOverlay; |
| 500 // Removes placeholder overlay. | 500 // Removes placeholder overlay. |
| 501 - (void)removePlaceholderOverlay; | 501 - (void)removePlaceholderOverlay; |
| (...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 // Only update the MIME type in the holder if there was MIME type information | 1774 // Only update the MIME type in the holder if there was MIME type information |
| 1775 // as part of this pending load. It will be nil when doing a fast | 1775 // as part of this pending load. It will be nil when doing a fast |
| 1776 // back/forward navigation, for instance, because the callback that would | 1776 // back/forward navigation, for instance, because the callback that would |
| 1777 // populate it is not called in that flow. | 1777 // populate it is not called in that flow. |
| 1778 if ([_pendingNavigationInfo MIMEType]) | 1778 if ([_pendingNavigationInfo MIMEType]) |
| 1779 holder->set_mime_type([_pendingNavigationInfo MIMEType]); | 1779 holder->set_mime_type([_pendingNavigationInfo MIMEType]); |
| 1780 } | 1780 } |
| 1781 | 1781 |
| 1782 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess { | 1782 - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess { |
| 1783 const GURL currentURL([self currentURL]); | 1783 const GURL currentURL([self currentURL]); |
| 1784 [self didStartLoadingURL:currentURL updateHistory:loadSuccess]; | 1784 [self didStartLoadingURL:currentURL]; |
| 1785 _loadPhase = web::PAGE_LOADED; | 1785 _loadPhase = web::PAGE_LOADED; |
| 1786 if (loadSuccess) { | 1786 if (loadSuccess) { |
| 1787 _webStateImpl->OnNavigationCommitted(currentURL); | 1787 _webStateImpl->OnNavigationCommitted(currentURL); |
| 1788 } else { | 1788 } else { |
| 1789 _webStateImpl->OnErrorPageNavigation(currentURL); | 1789 _webStateImpl->OnErrorPageNavigation(currentURL); |
| 1790 } | 1790 } |
| 1791 | 1791 |
| 1792 // Perform post-load-finished updates. | 1792 // Perform post-load-finished updates. |
| 1793 [self didFinishWithURL:currentURL loadSuccess:loadSuccess]; | 1793 [self didFinishWithURL:currentURL loadSuccess:loadSuccess]; |
| 1794 | 1794 |
| (...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3031 // be extracted from the landing page.) | 3031 // be extracted from the landing page.) |
| 3032 web::NavigationItem* currentItem = [self currentNavItem]; | 3032 web::NavigationItem* currentItem = [self currentNavItem]; |
| 3033 if (!currentItem->GetReferrer().url.is_valid()) { | 3033 if (!currentItem->GetReferrer().url.is_valid()) { |
| 3034 currentItem->SetReferrer(referrer); | 3034 currentItem->SetReferrer(referrer); |
| 3035 } | 3035 } |
| 3036 | 3036 |
| 3037 // TODO(stuartmorgan): This shouldn't be called for hash state or | 3037 // TODO(stuartmorgan): This shouldn't be called for hash state or |
| 3038 // push/replaceState. | 3038 // push/replaceState. |
| 3039 [self resetDocumentSpecificState]; | 3039 [self resetDocumentSpecificState]; |
| 3040 | 3040 |
| 3041 [self didStartLoadingURL:currentURL updateHistory:YES]; | 3041 [self didStartLoadingURL:currentURL]; |
| 3042 } | 3042 } |
| 3043 | 3043 |
| 3044 - (void)resetDocumentSpecificState { | 3044 - (void)resetDocumentSpecificState { |
| 3045 _lastUserInteraction.reset(); | 3045 _lastUserInteraction.reset(); |
| 3046 _clickInProgress = NO; | 3046 _clickInProgress = NO; |
| 3047 } | 3047 } |
| 3048 | 3048 |
| 3049 - (void)didStartLoadingURL:(const GURL&)url updateHistory:(BOOL)updateHistory { | 3049 - (void)didStartLoadingURL:(const GURL&)URL { |
| 3050 _loadPhase = web::PAGE_LOADING; | 3050 _loadPhase = web::PAGE_LOADING; |
| 3051 _URLOnStartLoading = url; | 3051 _URLOnStartLoading = URL; |
| 3052 _displayStateOnStartLoading = self.pageDisplayState; | 3052 _displayStateOnStartLoading = self.pageDisplayState; |
| 3053 | 3053 |
| 3054 self.userInteractionRegistered = NO; | 3054 self.userInteractionRegistered = NO; |
| 3055 _pageHasZoomed = NO; | 3055 _pageHasZoomed = NO; |
| 3056 | 3056 |
| 3057 [[self sessionController] commitPendingItem]; | 3057 [[self sessionController] commitPendingItem]; |
| 3058 [_delegate webDidStartLoadingURL:url shouldUpdateHistory:updateHistory]; | |
| 3059 } | 3058 } |
| 3060 | 3059 |
| 3061 - (void)wasShown { | 3060 - (void)wasShown { |
| 3062 if ([self.nativeController respondsToSelector:@selector(wasShown)]) { | 3061 if ([self.nativeController respondsToSelector:@selector(wasShown)]) { |
| 3063 [self.nativeController wasShown]; | 3062 [self.nativeController wasShown]; |
| 3064 } | 3063 } |
| 3065 } | 3064 } |
| 3066 | 3065 |
| 3067 - (void)wasHidden { | 3066 - (void)wasHidden { |
| 3068 if (_isHalted) | 3067 if (_isHalted) |
| (...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4658 if (!_lastRegisteredRequestURL.is_valid() && | 4657 if (!_lastRegisteredRequestURL.is_valid() && |
| 4659 _documentURL != _lastRegisteredRequestURL) { | 4658 _documentURL != _lastRegisteredRequestURL) { |
| 4660 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| | 4659 // if |_lastRegisteredRequestURL| is an invalid URL, then |_documentURL| |
| 4661 // will be "about:blank". | 4660 // will be "about:blank". |
| 4662 [[self sessionController] updatePendingItem:_documentURL]; | 4661 [[self sessionController] updatePendingItem:_documentURL]; |
| 4663 } | 4662 } |
| 4664 DCHECK(_documentURL == _lastRegisteredRequestURL || | 4663 DCHECK(_documentURL == _lastRegisteredRequestURL || |
| 4665 (!_lastRegisteredRequestURL.is_valid() && | 4664 (!_lastRegisteredRequestURL.is_valid() && |
| 4666 _documentURL.spec() == url::kAboutBlankURL)); | 4665 _documentURL.spec() == url::kAboutBlankURL)); |
| 4667 | 4666 |
| 4668 self.webStateImpl->OnNavigationCommitted(_documentURL); | 4667 self.webStateImpl->UpdateHttpResponseHeaders(_documentURL); |
| 4669 [self commitPendingNavigationInfo]; | 4668 [self commitPendingNavigationInfo]; |
| 4670 if ([self currentBackForwardListItemHolder]->navigation_type() == | 4669 if ([self currentBackForwardListItemHolder]->navigation_type() == |
| 4671 WKNavigationTypeBackForward) { | 4670 WKNavigationTypeBackForward) { |
| 4672 // A fast back/forward won't call decidePolicyForNavigationResponse, so | 4671 // A fast back/forward won't call decidePolicyForNavigationResponse, so |
| 4673 // the MIME type needs to be updated explicitly. | 4672 // the MIME type needs to be updated explicitly. |
| 4674 NSString* storedMIMEType = | 4673 NSString* storedMIMEType = |
| 4675 [self currentBackForwardListItemHolder]->mime_type(); | 4674 [self currentBackForwardListItemHolder]->mime_type(); |
| 4676 if (storedMIMEType) { | 4675 if (storedMIMEType) { |
| 4677 self.webStateImpl->SetContentsMimeType( | 4676 self.webStateImpl->SetContentsMimeType( |
| 4678 base::SysNSStringToUTF8(storedMIMEType)); | 4677 base::SysNSStringToUTF8(storedMIMEType)); |
| 4679 } | 4678 } |
| 4680 } | 4679 } |
| 4681 | 4680 |
| 4682 // This point should closely approximate the document object change, so reset | 4681 // This point should closely approximate the document object change, so reset |
| 4683 // the list of injected scripts to those that are automatically injected. | 4682 // the list of injected scripts to those that are automatically injected. |
| 4684 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 4683 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
| 4685 if ([self contentIsHTML] || self.webState->GetContentsMimeType().empty()) { | 4684 if ([self contentIsHTML] || self.webState->GetContentsMimeType().empty()) { |
| 4686 // In unit tests MIME type will be empty, because loadHTML:forURL: does not | 4685 // In unit tests MIME type will be empty, because loadHTML:forURL: does not |
| 4687 // notify web view delegate about received response, so web controller does | 4686 // notify web view delegate about received response, so web controller does |
| 4688 // not get a chance to properly update MIME type. | 4687 // not get a chance to properly update MIME type. |
| 4689 [self injectWindowID]; | 4688 [self injectWindowID]; |
| 4690 } | 4689 } |
| 4691 | 4690 |
| 4692 [self webPageChanged]; | 4691 [self webPageChanged]; |
| 4692 self.webStateImpl->OnNavigationCommitted(_documentURL); |
| 4693 | 4693 |
| 4694 [self updateSSLStatusForCurrentNavigationItem]; | 4694 [self updateSSLStatusForCurrentNavigationItem]; |
| 4695 | 4695 |
| 4696 // Attempt to update the HTML5 history state. | 4696 // Attempt to update the HTML5 history state. |
| 4697 [self updateHTML5HistoryState]; | 4697 [self updateHTML5HistoryState]; |
| 4698 | 4698 |
| 4699 // This is the point where pending entry has been committed, and navigation | 4699 // This is the point where pending entry has been committed, and navigation |
| 4700 // item title should be updated. | 4700 // item title should be updated. |
| 4701 [self setNavigationItemTitle:[_webView title]]; | 4701 [self setNavigationItemTitle:[_webView title]]; |
| 4702 | 4702 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4870 return; | 4870 return; |
| 4871 } | 4871 } |
| 4872 | 4872 |
| 4873 if (!navigationWasCommitted && ![_pendingNavigationInfo cancelled]) { | 4873 if (!navigationWasCommitted && ![_pendingNavigationInfo cancelled]) { |
| 4874 // A fast back/forward within the same origin does not call | 4874 // A fast back/forward within the same origin does not call |
| 4875 // |didCommitNavigation:|, so signal page change explicitly. | 4875 // |didCommitNavigation:|, so signal page change explicitly. |
| 4876 DCHECK_EQ(_documentURL.GetOrigin(), webViewURL.GetOrigin()); | 4876 DCHECK_EQ(_documentURL.GetOrigin(), webViewURL.GetOrigin()); |
| 4877 BOOL isSameDocumentNavigation = | 4877 BOOL isSameDocumentNavigation = |
| 4878 [self isKVOChangePotentialSameDocumentNavigationToURL:webViewURL]; | 4878 [self isKVOChangePotentialSameDocumentNavigationToURL:webViewURL]; |
| 4879 [self setDocumentURL:webViewURL]; | 4879 [self setDocumentURL:webViewURL]; |
| 4880 [self webPageChanged]; |
| 4880 if (isSameDocumentNavigation) { | 4881 if (isSameDocumentNavigation) { |
| 4881 _webStateImpl->OnSamePageNavigation(webViewURL); | 4882 _webStateImpl->OnSamePageNavigation(webViewURL); |
| 4882 } else { | 4883 } else { |
| 4883 _webStateImpl->OnNavigationCommitted(webViewURL); | 4884 _webStateImpl->OnNavigationCommitted(webViewURL); |
| 4884 } | 4885 } |
| 4885 [self webPageChanged]; | |
| 4886 } | 4886 } |
| 4887 | 4887 |
| 4888 [self updateSSLStatusForCurrentNavigationItem]; | 4888 [self updateSSLStatusForCurrentNavigationItem]; |
| 4889 | 4889 |
| 4890 // Fast back forward navigation may not call |didFinishNavigation:|, so | 4890 // Fast back forward navigation may not call |didFinishNavigation:|, so |
| 4891 // signal did finish navigation explicitly. | 4891 // signal did finish navigation explicitly. |
| 4892 if (_lastRegisteredRequestURL == _documentURL) { | 4892 if (_lastRegisteredRequestURL == _documentURL) { |
| 4893 [self didFinishNavigation]; | 4893 [self didFinishNavigation]; |
| 4894 } | 4894 } |
| 4895 } | 4895 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5027 if (!_changingHistoryState) { | 5027 if (!_changingHistoryState) { |
| 5028 // If this wasn't a previously-expected load (e.g., certain back/forward | 5028 // If this wasn't a previously-expected load (e.g., certain back/forward |
| 5029 // navigations), register the load request. | 5029 // navigations), register the load request. |
| 5030 if (![self isLoadRequestPendingForURL:newURL]) | 5030 if (![self isLoadRequestPendingForURL:newURL]) |
| 5031 [self registerLoadRequest:newURL]; | 5031 [self registerLoadRequest:newURL]; |
| 5032 } | 5032 } |
| 5033 | 5033 |
| 5034 [self setDocumentURL:newURL]; | 5034 [self setDocumentURL:newURL]; |
| 5035 | 5035 |
| 5036 if (!_changingHistoryState) { | 5036 if (!_changingHistoryState) { |
| 5037 [self didStartLoadingURL:_documentURL updateHistory:YES]; | 5037 [self didStartLoadingURL:_documentURL]; |
| 5038 _webStateImpl->OnSamePageNavigation(newURL); | 5038 _webStateImpl->OnSamePageNavigation(newURL); |
| 5039 [self updateSSLStatusForCurrentNavigationItem]; | 5039 [self updateSSLStatusForCurrentNavigationItem]; |
| 5040 [self didFinishNavigation]; | 5040 [self didFinishNavigation]; |
| 5041 } | 5041 } |
| 5042 } | 5042 } |
| 5043 | 5043 |
| 5044 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { | 5044 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { |
| 5045 if (self.loadPhase != web::LOAD_REQUESTED) | 5045 if (self.loadPhase != web::LOAD_REQUESTED) |
| 5046 return NO; | 5046 return NO; |
| 5047 | 5047 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5219 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5219 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
| 5220 _lastRegisteredRequestURL = URL; | 5220 _lastRegisteredRequestURL = URL; |
| 5221 _loadPhase = web::LOAD_REQUESTED; | 5221 _loadPhase = web::LOAD_REQUESTED; |
| 5222 } | 5222 } |
| 5223 | 5223 |
| 5224 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5224 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
| 5225 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5225 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
| 5226 } | 5226 } |
| 5227 | 5227 |
| 5228 @end | 5228 @end |
| OLD | NEW |