Commit b1077e4b authored by Yi Su's avatar Yi Su Committed by Commit Bot

Move CRWWebController.webPageChangedWithContext into

CRWWKNavigationHandler.

This CL moves CRWWebController.webPageChangedWithContext into
CRWWKNavigationHandler. It's now public to be used by KVO callbacks.

Bug: 956511
Change-Id: Id6fbe145e6994c47498a0ed7e9e35494ec7ac82f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1645353
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666628}
parent 8b0309e8
...@@ -97,19 +97,10 @@ class WKBackForwardListItemHolder; ...@@ -97,19 +97,10 @@ class WKBackForwardListItemHolder;
- (void)navigationHandlerDisplayWebView: - (void)navigationHandlerDisplayWebView:
(CRWWKNavigationHandler*)navigationHandler; (CRWWKNavigationHandler*)navigationHandler;
// Resets any state that is associated with a specific document object (e.g.,
// page interaction tracking).
- (void)navigationHandlerResetDocumentSpecificState:
(CRWWKNavigationHandler*)navigationHandler;
// Notifies the delegate that the page has actually started loading. // Notifies the delegate that the page has actually started loading.
- (void)navigationHandlerDidStartLoading: - (void)navigationHandlerDidStartLoading:
(CRWWKNavigationHandler*)navigationHandler; (CRWWKNavigationHandler*)navigationHandler;
// Notifies the delegate that the web page has changed document and/or URL.
- (void)navigationHandler:(CRWWKNavigationHandler*)navigationHandler
didChangePageWithContext:(web::NavigationContextImpl*)context;
// Instructs the delegate to update the SSL status for the current navigation // Instructs the delegate to update the SSL status for the current navigation
// item. // item.
- (void)navigationHandlerUpdateSSLStatusForCurrentNavigationItem: - (void)navigationHandlerUpdateSSLStatusForCurrentNavigationItem:
...@@ -210,6 +201,13 @@ class WKBackForwardListItemHolder; ...@@ -210,6 +201,13 @@ class WKBackForwardListItemHolder;
forContext:(std::unique_ptr<web::NavigationContextImpl>) forContext:(std::unique_ptr<web::NavigationContextImpl>)
originalContext; originalContext;
// Called when the web page has changed document and/or URL, and so the page
// navigation should be reported to the delegate, and internal state updated to
// reflect the fact that the navigation has occurred. |context| contains
// information about the navigation that triggered the document/URL change.
- (void)webPageChangedWithContext:(web::NavigationContextImpl*)context
webView:(WKWebView*)webView;
@end @end
#endif // IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_HANDLER_H_ #endif // IOS_WEB_NAVIGATION_CRW_WK_NAVIGATION_HANDLER_H_
...@@ -874,7 +874,7 @@ const web::CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100; ...@@ -874,7 +874,7 @@ const web::CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100;
} }
DCHECK(found_correct_navigation_item); DCHECK(found_correct_navigation_item);
} }
[self.delegate navigationHandlerResetDocumentSpecificState:self]; [self resetDocumentSpecificState];
[self.delegate navigationHandlerDidStartLoading:self]; [self.delegate navigationHandlerDidStartLoading:self];
} else if (context) { } else if (context) {
// If |navigation| is nil (which happens for windows open by DOM), then it // If |navigation| is nil (which happens for windows open by DOM), then it
...@@ -885,7 +885,7 @@ const web::CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100; ...@@ -885,7 +885,7 @@ const web::CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100;
if (isLastNavigation || if (isLastNavigation ||
(web::features::StorePendingItemInContext() && (web::features::StorePendingItemInContext() &&
self.navigationManagerImpl->GetPendingItemIndex() == -1)) { self.navigationManagerImpl->GetPendingItemIndex() == -1)) {
[self.delegate navigationHandler:self didChangePageWithContext:context]; [self webPageChangedWithContext:context webView:webView];
} else if (!web::GetWebClient()->IsSlimNavigationManagerEnabled()) { } else if (!web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
// WKWebView has more than one in progress navigation, and committed // WKWebView has more than one in progress navigation, and committed
// navigation was not the latest. Change last committed item to one that // navigation was not the latest. Change last committed item to one that
...@@ -1979,6 +1979,13 @@ const web::CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100; ...@@ -1979,6 +1979,13 @@ const web::CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100;
framesManager->RemoveAllWebFrames(); framesManager->RemoveAllWebFrames();
} }
// Resets any state that is associated with a specific document object (e.g.,
// page interaction tracking).
- (void)resetDocumentSpecificState {
self.userInteractionState->SetLastUserInteraction(nullptr);
self.userInteractionState->SetTapInProgress(false);
}
#pragma mark - Public methods #pragma mark - Public methods
- (void)stopLoading { - (void)stopLoading {
...@@ -2207,4 +2214,41 @@ const web::CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100; ...@@ -2207,4 +2214,41 @@ const web::CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100;
return [self.navigationStates contextForNavigation:navigation]; return [self.navigationStates contextForNavigation:navigation];
} }
- (void)webPageChangedWithContext:(web::NavigationContextImpl*)context
webView:(WKWebView*)webView {
web::Referrer referrer = self.currentReferrer;
// If no referrer was known in advance, record it now. (If there was one,
// keep it since it will have a more accurate URL and policy than what can
// be extracted from the landing page.)
web::NavigationItem* currentItem = self.currentNavItem;
// TODO(crbug.com/925304): Pending item (which should be used here) should be
// owned by NavigationContext object. Pending item should never be null.
if (currentItem && !currentItem->GetReferrer().url.is_valid()) {
currentItem->SetReferrer(referrer);
}
// TODO(crbug.com/956511): This shouldn't be called for hash state or
// push/replaceState.
[self resetDocumentSpecificState];
[self.delegate navigationHandlerDidStartLoading:self];
// Do not commit pending item in the middle of loading a placeholder URL. The
// item will be committed when the native content or webUI is displayed.
if (!context->IsPlaceholderNavigation()) {
self.navigationManagerImpl->CommitPendingItem(context->ReleaseItem());
if (web::features::StorePendingItemInContext() &&
context->IsLoadingHtmlString()) {
self.navigationManagerImpl->GetLastCommittedItem()->SetURL(
context->GetUrl());
}
// If a SafeBrowsing warning is currently displayed, the user has tapped
// the button on the warning page to proceed to the site, the site has
// started loading, and the warning is about to be removed. In this case,
// the transient item for the warning needs to be removed too.
if (web::IsSafeBrowsingWarningDisplayedInWebView(webView))
self.navigationManagerImpl->DiscardNonCommittedItems();
}
}
@end @end
...@@ -3049,56 +3049,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -3049,56 +3049,6 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
#pragma mark - WKNavigationDelegate Helpers #pragma mark - WKNavigationDelegate Helpers
// Called when the web page has changed document and/or URL, and so the page
// navigation should be reported to the delegate, and internal state updated to
// reflect the fact that the navigation has occurred. |context| contains
// information about the navigation that triggered the document/URL change.
// TODO(stuartmorgan): This method conflates document changes and URL changes;
// we should be distinguishing better, and be clear about the expected
// WebDelegate and WCO callbacks in each case.
- (void)webPageChangedWithContext:(web::NavigationContextImpl*)context {
web::Referrer referrer = self.navigationHandler.currentReferrer;
// If no referrer was known in advance, record it now. (If there was one,
// keep it since it will have a more accurate URL and policy than what can
// be extracted from the landing page.)
web::NavigationItem* currentItem = self.currentNavItem;
// TODO(crbug.com/925304): Pending item (which should be used here) should be
// owned by NavigationContext object. Pending item should never be null.
if (currentItem && !currentItem->GetReferrer().url.is_valid()) {
currentItem->SetReferrer(referrer);
}
// TODO(stuartmorgan): This shouldn't be called for hash state or
// push/replaceState.
[self resetDocumentSpecificState];
[self didStartLoading];
// Do not commit pending item in the middle of loading a placeholder URL. The
// item will be committed when the native content or webUI is displayed.
if (!context->IsPlaceholderNavigation()) {
self.navigationManagerImpl->CommitPendingItem(context->ReleaseItem());
if (web::features::StorePendingItemInContext() &&
context->IsLoadingHtmlString()) {
self.navigationManagerImpl->GetLastCommittedItem()->SetURL(
context->GetUrl());
}
// If a SafeBrowsing warning is currently displayed, the user has tapped
// the button on the warning page to proceed to the site, the site has
// started loading, and the warning is about to be removed. In this case,
// the transient item for the warning needs to be removed too.
if (web::IsSafeBrowsingWarningDisplayedInWebView(self.webView))
self.navigationManagerImpl->DiscardNonCommittedItems();
}
}
// Resets any state that is associated with a specific document object (e.g.,
// page interaction tracking).
- (void)resetDocumentSpecificState {
_userInteractionState.SetLastUserInteraction(nullptr);
_userInteractionState.SetTapInProgress(false);
}
// Called when a page (native or web) has actually started loading (i.e., for // Called when a page (native or web) has actually started loading (i.e., for
// a web page the document has actually changed), or after the load request has // a web page the document has actually changed), or after the load request has
// been registered for a non-document-changing URL change. Updates internal // been registered for a non-document-changing URL change. Updates internal
...@@ -3269,7 +3219,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -3269,7 +3219,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
hasUserGesture:NO hasUserGesture:NO
rendererInitiated:YES rendererInitiated:YES
placeholderNavigation:IsPlaceholderUrl(webViewURL)]; placeholderNavigation:IsPlaceholderUrl(webViewURL)];
[self webPageChangedWithContext:newContext.get()]; [self.navigationHandler webPageChangedWithContext:newContext.get()
webView:self.webView];
newContext->SetHasCommitted(!isSameDocumentNavigation); newContext->SetHasCommitted(!isSameDocumentNavigation);
self.webStateImpl->OnNavigationFinished(newContext.get()); self.webStateImpl->OnNavigationFinished(newContext.get());
// TODO(crbug.com/792515): It is OK, but very brittle, to call // TODO(crbug.com/792515): It is OK, but very brittle, to call
...@@ -3289,7 +3240,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -3289,7 +3240,8 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
existingContext->SetIsSameDocument(isSameDocumentNavigation); existingContext->SetIsSameDocument(isSameDocumentNavigation);
existingContext->SetHasCommitted(!isSameDocumentNavigation); existingContext->SetHasCommitted(!isSameDocumentNavigation);
self.webStateImpl->OnNavigationStarted(existingContext); self.webStateImpl->OnNavigationStarted(existingContext);
[self webPageChangedWithContext:existingContext]; [self.navigationHandler webPageChangedWithContext:existingContext
webView:self.webView];
self.webStateImpl->OnNavigationFinished(existingContext); self.webStateImpl->OnNavigationFinished(existingContext);
} }
} }
...@@ -3689,21 +3641,11 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -3689,21 +3641,11 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
[self displayWebView]; [self displayWebView];
} }
- (void)navigationHandlerResetDocumentSpecificState:
(CRWWKNavigationHandler*)navigationHandler {
[self resetDocumentSpecificState];
}
- (void)navigationHandlerDidStartLoading: - (void)navigationHandlerDidStartLoading:
(CRWWKNavigationHandler*)navigationHandler { (CRWWKNavigationHandler*)navigationHandler {
[self didStartLoading]; [self didStartLoading];
} }
- (void)navigationHandler:(CRWWKNavigationHandler*)navigationHandler
didChangePageWithContext:(web::NavigationContextImpl*)context {
[self webPageChangedWithContext:context];
}
- (void)navigationHandlerUpdateSSLStatusForCurrentNavigationItem: - (void)navigationHandlerUpdateSSLStatusForCurrentNavigationItem:
(CRWWKNavigationHandler*)navigationHandler { (CRWWKNavigationHandler*)navigationHandler {
[self updateSSLStatusForCurrentNavigationItem]; [self updateSSLStatusForCurrentNavigationItem];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment