Commit 7aae11ad authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[ios] Save WKNavigationType in NavigationContextImpl.

This is the first step to removing _lastRegisteredRequestURL from
CRWWebController. See crbug.com/792515 for rationale.

There are two use cases for _lastRegisteredRequestURL:
1. As the URL of the pending navigation
2. Detect fast back-forward navigations in
   |-webViewLoadingStateDidChange| to explicitly trigger
   |-didFinishNavigation:|

NavigationContext::GetUrl() can already support (1).
NavigationContext::GetPageTransition() cannot current distinguish fast
and slow back-forward navigation. Storing WKNavigationType makes this
possible.

Bug: 789993,792515
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I4a919a48bd1d7755d006dbebff305558e885c8f2
Reviewed-on: https://chromium-review.googlesource.com/806766
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522235}
parent 6bde89c7
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef IOS_WEB_WEB_STATE_NAVIGATION_CONTEXT_IMPL_H_ #ifndef IOS_WEB_WEB_STATE_NAVIGATION_CONTEXT_IMPL_H_
#define IOS_WEB_WEB_STATE_NAVIGATION_CONTEXT_IMPL_H_ #define IOS_WEB_WEB_STATE_NAVIGATION_CONTEXT_IMPL_H_
#import <WebKit/WebKit.h>
#include <memory> #include <memory>
#import "base/mac/scoped_nsobject.h" #import "base/mac/scoped_nsobject.h"
...@@ -54,6 +56,10 @@ class NavigationContextImpl : public NavigationContext { ...@@ -54,6 +56,10 @@ class NavigationContextImpl : public NavigationContext {
int GetNavigationItemUniqueID() const; int GetNavigationItemUniqueID() const;
void SetNavigationItemUniqueID(int unique_id); void SetNavigationItemUniqueID(int unique_id);
// Optional WKNavigationType of the associated navigation in WKWebView.
void SetWKNavigationType(WKNavigationType wk_navigation_type);
WKNavigationType GetWKNavigationType() const;
private: private:
NavigationContextImpl(WebState* web_state, NavigationContextImpl(WebState* web_state,
const GURL& url, const GURL& url,
...@@ -62,13 +68,14 @@ class NavigationContextImpl : public NavigationContext { ...@@ -62,13 +68,14 @@ class NavigationContextImpl : public NavigationContext {
WebState* web_state_ = nullptr; WebState* web_state_ = nullptr;
GURL url_; GURL url_;
ui::PageTransition page_transition_; const ui::PageTransition page_transition_;
bool is_same_document_ = false; bool is_same_document_ = false;
bool is_post_ = false; bool is_post_ = false;
base::scoped_nsobject<NSError> error_; base::scoped_nsobject<NSError> error_;
scoped_refptr<net::HttpResponseHeaders> response_headers_; scoped_refptr<net::HttpResponseHeaders> response_headers_;
bool is_renderer_initiated_ = false; bool is_renderer_initiated_ = false;
int navigation_item_unique_id_ = -1; int navigation_item_unique_id_ = -1;
WKNavigationType wk_navigation_type_ = WKNavigationTypeOther;
DISALLOW_COPY_AND_ASSIGN(NavigationContextImpl); DISALLOW_COPY_AND_ASSIGN(NavigationContextImpl);
}; };
......
...@@ -98,6 +98,15 @@ void NavigationContextImpl::SetNavigationItemUniqueID(int unique_id) { ...@@ -98,6 +98,15 @@ void NavigationContextImpl::SetNavigationItemUniqueID(int unique_id) {
navigation_item_unique_id_ = unique_id; navigation_item_unique_id_ = unique_id;
} }
void NavigationContextImpl::SetWKNavigationType(
WKNavigationType wk_navigation_type) {
wk_navigation_type_ = wk_navigation_type;
}
WKNavigationType NavigationContextImpl::GetWKNavigationType() const {
return wk_navigation_type_;
}
NavigationContextImpl::NavigationContextImpl(WebState* web_state, NavigationContextImpl::NavigationContextImpl(WebState* web_state,
const GURL& url, const GURL& url,
ui::PageTransition page_transition, ui::PageTransition page_transition,
......
...@@ -66,6 +66,7 @@ TEST_F(NavigationContextImplTest, Setters) { ...@@ -66,6 +66,7 @@ TEST_F(NavigationContextImplTest, Setters) {
ASSERT_FALSE(context->GetError()); ASSERT_FALSE(context->GetError());
ASSERT_FALSE(context->IsRendererInitiated()); ASSERT_FALSE(context->IsRendererInitiated());
ASSERT_NE(response_headers_.get(), context->GetResponseHeaders()); ASSERT_NE(response_headers_.get(), context->GetResponseHeaders());
EXPECT_EQ(WKNavigationTypeOther, context->GetWKNavigationType());
// SetSameDocument // SetSameDocument
context->SetIsSameDocument(true); context->SetIsSameDocument(true);
...@@ -74,6 +75,8 @@ TEST_F(NavigationContextImplTest, Setters) { ...@@ -74,6 +75,8 @@ TEST_F(NavigationContextImplTest, Setters) {
EXPECT_FALSE(context->GetError()); EXPECT_FALSE(context->GetError());
EXPECT_FALSE(context->IsRendererInitiated()); EXPECT_FALSE(context->IsRendererInitiated());
EXPECT_NE(response_headers_.get(), context->GetResponseHeaders()); EXPECT_NE(response_headers_.get(), context->GetResponseHeaders());
EXPECT_EQ(WKNavigationTypeOther, context->GetWKNavigationType());
EXPECT_EQ(WKNavigationTypeOther, context->GetWKNavigationType());
// SetPost // SetPost
context->SetIsPost(true); context->SetIsPost(true);
...@@ -82,6 +85,7 @@ TEST_F(NavigationContextImplTest, Setters) { ...@@ -82,6 +85,7 @@ TEST_F(NavigationContextImplTest, Setters) {
EXPECT_FALSE(context->GetError()); EXPECT_FALSE(context->GetError());
EXPECT_FALSE(context->IsRendererInitiated()); EXPECT_FALSE(context->IsRendererInitiated());
EXPECT_NE(response_headers_.get(), context->GetResponseHeaders()); EXPECT_NE(response_headers_.get(), context->GetResponseHeaders());
EXPECT_EQ(WKNavigationTypeOther, context->GetWKNavigationType());
// SetErrorPage // SetErrorPage
NSError* error = [[NSError alloc] init]; NSError* error = [[NSError alloc] init];
...@@ -91,6 +95,7 @@ TEST_F(NavigationContextImplTest, Setters) { ...@@ -91,6 +95,7 @@ TEST_F(NavigationContextImplTest, Setters) {
EXPECT_EQ(error, context->GetError()); EXPECT_EQ(error, context->GetError());
EXPECT_FALSE(context->IsRendererInitiated()); EXPECT_FALSE(context->IsRendererInitiated());
EXPECT_NE(response_headers_.get(), context->GetResponseHeaders()); EXPECT_NE(response_headers_.get(), context->GetResponseHeaders());
EXPECT_EQ(WKNavigationTypeOther, context->GetWKNavigationType());
// SetResponseHeaders // SetResponseHeaders
context->SetResponseHeaders(response_headers_); context->SetResponseHeaders(response_headers_);
...@@ -99,6 +104,7 @@ TEST_F(NavigationContextImplTest, Setters) { ...@@ -99,6 +104,7 @@ TEST_F(NavigationContextImplTest, Setters) {
EXPECT_EQ(error, context->GetError()); EXPECT_EQ(error, context->GetError());
EXPECT_FALSE(context->IsRendererInitiated()); EXPECT_FALSE(context->IsRendererInitiated());
EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders()); EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders());
EXPECT_EQ(WKNavigationTypeOther, context->GetWKNavigationType());
// SetIsRendererInitiated // SetIsRendererInitiated
context->SetIsRendererInitiated(true); context->SetIsRendererInitiated(true);
...@@ -107,6 +113,16 @@ TEST_F(NavigationContextImplTest, Setters) { ...@@ -107,6 +113,16 @@ TEST_F(NavigationContextImplTest, Setters) {
EXPECT_EQ(error, context->GetError()); EXPECT_EQ(error, context->GetError());
EXPECT_TRUE(context->IsRendererInitiated()); EXPECT_TRUE(context->IsRendererInitiated());
EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders()); EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders());
EXPECT_EQ(WKNavigationTypeOther, context->GetWKNavigationType());
// SetWKNavigationType
context->SetWKNavigationType(WKNavigationTypeBackForward);
EXPECT_TRUE(context->IsSameDocument());
ASSERT_TRUE(context->IsPost());
EXPECT_EQ(error, context->GetError());
EXPECT_TRUE(context->IsRendererInitiated());
EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders());
EXPECT_EQ(WKNavigationTypeBackForward, context->GetWKNavigationType());
} }
} // namespace web } // namespace web
...@@ -1365,10 +1365,13 @@ registerLoadRequestForURL:(const GURL&)URL ...@@ -1365,10 +1365,13 @@ registerLoadRequestForURL:(const GURL&)URL
[self pageTransitionFromNavigationType:navigationType]; [self pageTransitionFromNavigationType:navigationType];
// The referrer is not known yet, and will be updated later. // The referrer is not known yet, and will be updated later.
const web::Referrer emptyReferrer; const web::Referrer emptyReferrer;
return [self registerLoadRequestForURL:URL std::unique_ptr<web::NavigationContextImpl> context =
referrer:emptyReferrer [self registerLoadRequestForURL:URL
transition:transition referrer:emptyReferrer
sameDocumentNavigation:sameDocumentNavigation]; transition:transition
sameDocumentNavigation:sameDocumentNavigation];
context->SetWKNavigationType(navigationType);
return context;
} }
- (std::unique_ptr<web::NavigationContextImpl>) - (std::unique_ptr<web::NavigationContextImpl>)
...@@ -5222,6 +5225,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -5222,6 +5225,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
} else { } else {
// |didCommitNavigation:| may not be called for fast navigation, so update // |didCommitNavigation:| may not be called for fast navigation, so update
// the navigation type now as it is already known. // the navigation type now as it is already known.
navigationContext->SetWKNavigationType(WKNavigationTypeBackForward);
holder->set_navigation_type(WKNavigationTypeBackForward); holder->set_navigation_type(WKNavigationTypeBackForward);
navigation = navigation =
[_webView goToBackForwardListItem:holder->back_forward_list_item()]; [_webView goToBackForwardListItem:holder->back_forward_list_item()];
......
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