Chromium Code Reviews| Index: ios/web/web_state/ui/crw_web_controller.mm |
| diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm |
| index 1b062d63aee892b687fedd1995303fa904cea7fc..880d85b6e7f6522911c300b68f810621cfbf7feb 100644 |
| --- a/ios/web/web_state/ui/crw_web_controller.mm |
| +++ b/ios/web/web_state/ui/crw_web_controller.mm |
| @@ -82,6 +82,7 @@ |
| #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" |
| #import "ios/web/web_state/js/crw_js_post_request_loader.h" |
| #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
| +#include "ios/web/web_state/navigation_context_impl.h" |
| #import "ios/web/web_state/page_viewport_state.h" |
| #import "ios/web/web_state/ui/crw_context_menu_controller.h" |
| #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" |
| @@ -565,7 +566,7 @@ NSError* WKWebViewErrorWithSource(NSError* error, WKWebViewErrorSource source) { |
| // Returns |YES| if |url| should be loaded in a native view. |
| - (BOOL)shouldLoadURLInNativeView:(const GURL&)url; |
| // Loads the request into the |webView|. |
| -- (void)loadRequest:(NSMutableURLRequest*)request; |
| +- (WKNavigation*)loadRequest:(NSMutableURLRequest*)request; |
| // Loads POST request with body in |_wkWebView| by constructing an HTML page |
| // that executes the request through JavaScript and replaces document with the |
| // result. |
| @@ -573,7 +574,7 @@ NSError* WKWebViewErrorWithSource(NSError* error, WKWebViewErrorSource source) { |
| // the data is passed to |_wkWebView| on main thread. |
| // This is necessary because WKWebView ignores POST request body. |
| // Workaround for https://bugs.webkit.org/show_bug.cgi?id=145410 |
| -- (void)loadPOSTRequest:(NSMutableURLRequest*)request; |
| +- (WKNavigation*)loadPOSTRequest:(NSMutableURLRequest*)request; |
| // Loads the HTML into the page at the given URL. |
| - (void)loadHTML:(NSString*)html forURL:(const GURL&)url; |
| @@ -646,14 +647,18 @@ NSError* WKWebViewErrorWithSource(NSError* error, WKWebViewErrorSource source) { |
| // Attempts to handle a script message. Returns YES on success, NO otherwise. |
| - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; |
| // Registers load request with empty referrer and link or client redirect |
| -// transition based on user interaction state. |
| -- (void)registerLoadRequest:(const GURL&)URL; |
| +// transition based on user interaction state. Returns navigation context for |
| +// this request. |
| +- (std::unique_ptr<web::NavigationContextImpl>)registerLoadRequestForURL: |
| + (const GURL&)URL; |
| // Prepares web controller and delegates for anticipated page change. |
| // Allows several methods to invoke webWill/DidAddPendingURL on anticipated page |
| // change, using the same cached request and calculated transition types. |
| -- (void)registerLoadRequest:(const GURL&)URL |
| - referrer:(const web::Referrer&)referrer |
| - transition:(ui::PageTransition)transition; |
| +// Returns navigation context for this request. |
| +- (std::unique_ptr<web::NavigationContextImpl>) |
| +registerLoadRequestForURL:(const GURL&)URL |
| + referrer:(const web::Referrer&)referrer |
| + transition:(ui::PageTransition)transition; |
| // Updates the HTML5 history state of the page using the current NavigationItem. |
| // For same-document navigations and navigations affected by |
| // window.history.[push/replace]State(), the URL and serialized state object |
| @@ -1445,7 +1450,8 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| return [_webView estimatedProgress]; |
| } |
| -- (void)registerLoadRequest:(const GURL&)URL { |
| +- (std::unique_ptr<web::NavigationContextImpl>)registerLoadRequestForURL: |
| + (const GURL&)URL { |
| // Get the navigation type from the last main frame load request, and try to |
| // map that to a PageTransition. |
| WKNavigationType navigationType = |
| @@ -1478,12 +1484,15 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| } |
| // The referrer is not known yet, and will be updated later. |
| const web::Referrer emptyReferrer; |
| - [self registerLoadRequest:URL referrer:emptyReferrer transition:transition]; |
| + return [self registerLoadRequestForURL:URL |
| + referrer:emptyReferrer |
| + transition:transition]; |
| } |
| -- (void)registerLoadRequest:(const GURL&)requestURL |
| - referrer:(const web::Referrer&)referrer |
| - transition:(ui::PageTransition)transition { |
| +- (std::unique_ptr<web::NavigationContextImpl>) |
| +registerLoadRequestForURL:(const GURL&)requestURL |
| + referrer:(const web::Referrer&)referrer |
| + transition:(ui::PageTransition)transition { |
| // Transfer time is registered so that further transitions within the time |
| // envelope are not also registered as links. |
| _lastTransferTimeInSeconds = CFAbsoluteTimeGetCurrent(); |
| @@ -1516,8 +1525,13 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| web::NavigationInitiationType::RENDERER_INITIATED, |
| web::NavigationManager::UserAgentOverrideOption::INHERIT); |
| } |
| + std::unique_ptr<web::NavigationContextImpl> context = |
| + web::NavigationContextImpl::CreateNavigationContext( |
| + _webStateImpl, requestURL, nullptr /* response_headers */); |
| _webStateImpl->SetIsLoading(true); |
| + // TODO(crbug.com/713836): pass context to |OnProvisionalNavigationStarted|. |
| _webStateImpl->OnProvisionalNavigationStarted(requestURL); |
| + return context; |
| } |
| - (void)updateHTML5HistoryState { |
| @@ -1812,9 +1826,10 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| item->SetVirtualURL([nativeContent virtualURL]); |
| } |
| - [self registerLoadRequest:targetURL |
| - referrer:referrer |
| - transition:self.currentTransition]; |
| + std::unique_ptr<web::NavigationContextImpl> navigationContext = |
| + [self registerLoadRequestForURL:targetURL |
| + referrer:referrer |
| + transition:self.currentTransition]; |
|
kkhorimoto
2017/04/25 13:45:50
I'm assuming that this will be utilized in a later
Eugene But (OOO till 7-30)
2017/04/27 16:12:06
Yes, here:
https://codereview.chromium.org/284244
|
| [self loadNativeViewWithSuccess:YES]; |
| } |
| @@ -4155,12 +4170,14 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); |
| } |
| -- (void)loadRequest:(NSMutableURLRequest*)request { |
| +- (WKNavigation*)loadRequest:(NSMutableURLRequest*)request { |
| + WKNavigation* navigation = [_webView loadRequest:request]; |
| [_navigationStates setState:web::WKNavigationState::REQUESTED |
| - forNavigation:[_webView loadRequest:request]]; |
| + forNavigation:navigation]; |
| + return navigation; |
| } |
| -- (void)loadPOSTRequest:(NSMutableURLRequest*)request { |
| +- (WKNavigation*)loadPOSTRequest:(NSMutableURLRequest*)request { |
| if (!_POSTRequestLoader) { |
| _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); |
| } |
| @@ -4168,17 +4185,16 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| CRWWKScriptMessageRouter* messageRouter = |
| [self webViewConfigurationProvider].GetScriptMessageRouter(); |
| - [_POSTRequestLoader loadPOSTRequest:request |
| - inWebView:_webView |
| - messageRouter:messageRouter |
| - completionHandler:^(NSError* loadError) { |
| - if (loadError) |
| - [self handleLoadError:loadError |
| - inMainFrame:YES |
| - forNavigation:nil]; |
| - else |
| - self.webStateImpl->SetContentsMimeType("text/html"); |
| - }]; |
| + return [_POSTRequestLoader |
| + loadPOSTRequest:request |
| + inWebView:_webView |
| + messageRouter:messageRouter |
| + completionHandler:^(NSError* loadError) { |
| + if (loadError) |
| + [self handleLoadError:loadError inMainFrame:YES forNavigation:nil]; |
| + else |
| + self.webStateImpl->SetContentsMimeType("text/html"); |
| + }]; |
| } |
| - (void)loadHTML:(NSString*)HTML forURL:(const GURL&)URL { |
| @@ -4476,7 +4492,8 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| } |
| return; |
| } else { |
| - [self registerLoadRequest:webViewURL]; |
| + std::unique_ptr<web::NavigationContextImpl> navigationContext = |
| + [self registerLoadRequestForURL:webViewURL]; |
| } |
| } |
| @@ -4490,9 +4507,11 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| [_navigationStates setState:web::WKNavigationState::REDIRECTED |
| forNavigation:navigation]; |
| - [self registerLoadRequest:net::GURLWithNSURL(webView.URL) |
| - referrer:[self currentReferrer] |
| - transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; |
| + // It is fine to ignore returned NavigationContet as it did not |
|
kkhorimoto
2017/04/25 13:45:50
s/Contet/Context
Eugene But (OOO till 7-30)
2017/04/27 16:12:06
Done.
|
| + // change after the redirect. |
|
kkhorimoto
2017/04/25 13:45:50
I don't really understand this comment. It looks
Eugene But (OOO till 7-30)
2017/04/27 16:12:06
Updated the comment. Please let me know if it is s
|
| + [self registerLoadRequestForURL:net::GURLWithNSURL(webView.URL) |
| + referrer:[self currentReferrer] |
| + transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; |
| } |
| - (void)webView:(WKWebView*)webView |
| @@ -4961,11 +4980,12 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| // registering a load request logically comes before updating the document |
| // URL, but also must come first since it uses state that is reset on URL |
| // changes. |
| + std::unique_ptr<web::NavigationContextImpl> navigationContext; |
| if (!_changingHistoryState) { |
| // If this wasn't a previously-expected load (e.g., certain back/forward |
| // navigations), register the load request. |
| if (![self isLoadRequestPendingForURL:newURL]) |
| - [self registerLoadRequest:newURL]; |
| + navigationContext = [self registerLoadRequestForURL:newURL]; |
| } |
| [self setDocumentURL:newURL]; |
| @@ -5015,9 +5035,10 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| [request setAllHTTPHeaderFields:self.currentHTTPHeaders]; |
| GURL navigationURL = |
| currentItem ? currentItem->GetURL() : GURL::EmptyGURL(); |
| - [self registerLoadRequest:navigationURL |
| - referrer:self.currentNavItemReferrer |
| - transition:self.currentTransition]; |
| + std::unique_ptr<web::NavigationContextImpl> navigationContext = |
| + [self registerLoadRequestForURL:navigationURL |
| + referrer:self.currentNavItemReferrer |
| + transition:self.currentTransition]; |
| [self loadPOSTRequest:request]; |
| return; |
| } |
| @@ -5025,9 +5046,10 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| ProceduralBlock defaultNavigationBlock = ^{ |
| web::NavigationItem* item = self.currentNavItem; |
| GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); |
| - [self registerLoadRequest:navigationURL |
| - referrer:self.currentNavItemReferrer |
| - transition:self.currentTransition]; |
| + std::unique_ptr<web::NavigationContextImpl> navigationContext = |
| + [self registerLoadRequestForURL:navigationURL |
| + referrer:self.currentNavItemReferrer |
| + transition:self.currentTransition]; |
| [self loadRequest:request]; |
| [self reportBackForwardNavigationTypeForFastNavigation:NO]; |
| }; |
| @@ -5062,9 +5084,10 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; |
| // so |reload| must be explicitly called. |
| web::NavigationItem* item = self.currentNavItem; |
| GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); |
| - [self registerLoadRequest:navigationURL |
| - referrer:self.currentNavItemReferrer |
| - transition:self.currentTransition]; |
| + std::unique_ptr<web::NavigationContextImpl> navigationContext = |
| + [self registerLoadRequestForURL:navigationURL |
| + referrer:self.currentNavItemReferrer |
| + transition:self.currentTransition]; |
| WKNavigation* navigation = nil; |
| if (navigationURL == net::GURLWithNSURL([_webView URL])) { |
| navigation = [_webView reload]; |