Skip to content

Commit

Permalink
[ios] Add more checks for nil last committed item.
Browse files Browse the repository at this point in the history
Catch more edge cases where last committed item can be nil if
navigating when about://newtab is still loading.

Bug: 931273
TBR: sdefresne@
Change-Id: I29bdd0a5f8c5b6e9a098face36c87c6bc0b5ee13
Reviewed-on: https://chromium-review.googlesource.com/c/1469427
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: Eugene But <eugenebut@chromium.org>
Auto-Submit: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631915}
  • Loading branch information
Justin Cohen authored and Commit Bot committed Feb 13, 2019
1 parent 21db539 commit 47f9015
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
void WebStateTopSitesObserver::DidFinishNavigation(
web::WebState* web_state,
web::NavigationContext* navigation_context) {
if (top_sites_ && navigation_context->HasCommitted()) {
// TODO(crbug.com/931841): Remove GetLastCommittedItem nil check once
// HasComitted has been fixed.
if (top_sites_ && navigation_context->HasCommitted() &&
web_state->GetNavigationManager()->GetLastCommittedItem()) {
top_sites_->OnNavigationCommitted(
web_state->GetNavigationManager()->GetLastCommittedItem()->GetURL());
}
Expand Down
5 changes: 4 additions & 1 deletion ios/chrome/browser/history/history_tab_helper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@
return;
}

if (!navigation_context->HasCommitted()) {
// TODO(crbug.com/931841): Remove GetLastCommittedItem nil check once
// HasComitted has been fixed.
if (!navigation_context->HasCommitted() ||
!web_state_->GetNavigationManager()->GetLastCommittedItem()) {
// Navigation was replaced or aborted.
return;
}
Expand Down
5 changes: 4 additions & 1 deletion ios/chrome/browser/infobars/infobar_manager_impl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@
web::WebState* web_state,
web::NavigationContext* navigation_context) {
DCHECK_EQ(web_state_, web_state);
if (navigation_context->HasCommitted()) {
// TODO(crbug.com/931841): Remove GetLastCommittedItem nil check once
// HasComitted has been fixed.
if (navigation_context->HasCommitted() &&
web_state->GetNavigationManager()->GetLastCommittedItem()) {
OnNavigation(CreateNavigationDetails(
web_state->GetNavigationManager()->GetLastCommittedItem(),
navigation_context->IsSameDocument()));
Expand Down

0 comments on commit 47f9015

Please sign in to comment.