Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2950853002: Gracefully handle didCommitNavigation: call after didFinishNavigation: (Closed)
Patch Set: Updated comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_wk_navigation_states.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4520 matching lines...) Expand 10 before | Expand all | Expand 10 after
4531 // the pending load. 4531 // the pending load.
4532 _pendingNavigationInfo.reset(); 4532 _pendingNavigationInfo.reset();
4533 _certVerificationErrors->Clear(); 4533 _certVerificationErrors->Clear();
4534 [_navigationStates removeNavigation:navigation]; 4534 [_navigationStates removeNavigation:navigation];
4535 } 4535 }
4536 4536
4537 - (void)webView:(WKWebView*)webView 4537 - (void)webView:(WKWebView*)webView
4538 didCommitNavigation:(WKNavigation*)navigation { 4538 didCommitNavigation:(WKNavigation*)navigation {
4539 [self displayWebView]; 4539 [self displayWebView];
4540 4540
4541 bool navigationFinished = [_navigationStates stateForNavigation:navigation] ==
4542 web::WKNavigationState::FINISHED;
4543
4541 // Record the navigation state. 4544 // Record the navigation state.
4542 [_navigationStates setState:web::WKNavigationState::COMMITTED 4545 [_navigationStates setState:web::WKNavigationState::COMMITTED
4543 forNavigation:navigation]; 4546 forNavigation:navigation];
4544 4547
4545 DCHECK_EQ(_webView, webView); 4548 DCHECK_EQ(_webView, webView);
4546 _certVerificationErrors->Clear(); 4549 _certVerificationErrors->Clear();
4547 4550
4548 // This is the point where the document's URL has actually changed, and 4551 // This is the point where the document's URL has actually changed, and
4549 // pending navigation information should be applied to state information. 4552 // pending navigation information should be applied to state information.
4550 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; 4553 [self setDocumentURL:net::GURLWithNSURL([_webView URL])];
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
4622 // item title should be updated. 4625 // item title should be updated.
4623 [self setNavigationItemTitle:[_webView title]]; 4626 [self setNavigationItemTitle:[_webView title]];
4624 4627
4625 // Report cases where SSL cert is missing for a secure connection. 4628 // Report cases where SSL cert is missing for a secure connection.
4626 if (_documentURL.SchemeIsCryptographic()) { 4629 if (_documentURL.SchemeIsCryptographic()) {
4627 scoped_refptr<net::X509Certificate> cert = 4630 scoped_refptr<net::X509Certificate> cert =
4628 web::CreateCertFromChain([_webView certificateChain]); 4631 web::CreateCertFromChain([_webView certificateChain]);
4629 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", 4632 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection",
4630 static_cast<bool>(cert)); 4633 static_cast<bool>(cert));
4631 } 4634 }
4635
4636 if (navigationFinished) {
4637 // webView:didFinishNavigation: was called before
4638 // webView:didCommitNavigation:, so remove the navigation now and signal
4639 // that navigation was finished.
4640 [_navigationStates removeNavigation:navigation];
4641 [self didFinishNavigation:navigation];
4642 }
4632 } 4643 }
4633 4644
4634 - (void)webView:(WKWebView*)webView 4645 - (void)webView:(WKWebView*)webView
4635 didFinishNavigation:(WKNavigation*)navigation { 4646 didFinishNavigation:(WKNavigation*)navigation {
4647 bool navigationCommitted =
4648 [_navigationStates stateForNavigation:navigation] ==
4649 web::WKNavigationState::COMMITTED;
4636 [_navigationStates setState:web::WKNavigationState::FINISHED 4650 [_navigationStates setState:web::WKNavigationState::FINISHED
4637 forNavigation:navigation]; 4651 forNavigation:navigation];
4638 4652
4639 DCHECK(!_isHalted); 4653 DCHECK(!_isHalted);
4640 // Trigger JavaScript driven post-document-load-completion tasks. 4654 // Trigger JavaScript driven post-document-load-completion tasks.
4641 // TODO(crbug.com/546350): Investigate using 4655 // TODO(crbug.com/546350): Investigate using
4642 // WKUserScriptInjectionTimeAtDocumentEnd to inject this material at the 4656 // WKUserScriptInjectionTimeAtDocumentEnd to inject this material at the
4643 // appropriate time rather than invoking here. 4657 // appropriate time rather than invoking here.
4644 web::ExecuteJavaScript(webView, @"__gCrWeb.didFinishNavigation()", nil); 4658 web::ExecuteJavaScript(webView, @"__gCrWeb.didFinishNavigation()", nil);
4645 [self didFinishNavigation:navigation]; 4659 [self didFinishNavigation:navigation];
4646 [_navigationStates removeNavigation:navigation]; 4660
4661 // Remove navigation only if it has been committed. Otherwise it will be
4662 // removed in webView:didCommitNavigation: callback.
4663 if (navigationCommitted) {
4664 [_navigationStates removeNavigation:navigation];
4665 }
4647 } 4666 }
4648 4667
4649 - (void)webView:(WKWebView*)webView 4668 - (void)webView:(WKWebView*)webView
4650 didFailNavigation:(WKNavigation*)navigation 4669 didFailNavigation:(WKNavigation*)navigation
4651 withError:(NSError*)error { 4670 withError:(NSError*)error {
4652 [_navigationStates setState:web::WKNavigationState::FAILED 4671 [_navigationStates setState:web::WKNavigationState::FAILED
4653 forNavigation:navigation]; 4672 forNavigation:navigation];
4654 4673
4655 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) 4674 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION)
4656 inMainFrame:YES 4675 inMainFrame:YES
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
5219 - (NSUInteger)observerCount { 5238 - (NSUInteger)observerCount {
5220 DCHECK_EQ(_observerBridges.size(), [_observers count]); 5239 DCHECK_EQ(_observerBridges.size(), [_observers count]);
5221 return [_observers count]; 5240 return [_observers count];
5222 } 5241 }
5223 5242
5224 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { 5243 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action {
5225 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; 5244 return [action.request valueForHTTPHeaderField:kReferrerHeaderName];
5226 } 5245 }
5227 5246
5228 @end 5247 @end
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_state/ui/crw_wk_navigation_states.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698