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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl.cc

Issue 2919593007: Always update the omnibox URL when cancelling via onbeforeunload (Closed)
Patch Set: Test tweaking 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 /* 5 /*
6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * 10 *
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 return false; 888 return false;
889 } 889 }
890 break; 890 break;
891 case NAVIGATION_TYPE_NAV_IGNORE: 891 case NAVIGATION_TYPE_NAV_IGNORE:
892 // If a pending navigation was in progress, this canceled it. We should 892 // If a pending navigation was in progress, this canceled it. We should
893 // discard it and make sure it is removed from the URL bar. After that, 893 // discard it and make sure it is removed from the URL bar. After that,
894 // there is nothing we can do with this navigation, so we just return to 894 // there is nothing we can do with this navigation, so we just return to
895 // the caller that nothing has happened. 895 // the caller that nothing has happened.
896 if (pending_entry_) { 896 if (pending_entry_) {
897 DiscardNonCommittedEntries(); 897 DiscardNonCommittedEntries();
898 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
899 } 898 }
900 return false; 899 return false;
901 default: 900 default:
902 NOTREACHED(); 901 NOTREACHED();
903 } 902 }
904 903
905 // At this point, we know that the navigation has just completed, so 904 // At this point, we know that the navigation has just completed, so
906 // record the time. 905 // record the time.
907 // 906 //
908 // TODO(akalin): Use "sane time" as described in 907 // TODO(akalin): Use "sane time" as described in
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 DCHECK(index < GetEntryCount()); 1727 DCHECK(index < GetEntryCount());
1729 DCHECK(index != last_committed_entry_index_); 1728 DCHECK(index != last_committed_entry_index_);
1730 1729
1731 DiscardNonCommittedEntries(); 1730 DiscardNonCommittedEntries();
1732 1731
1733 entries_.erase(entries_.begin() + index); 1732 entries_.erase(entries_.begin() + index);
1734 if (last_committed_entry_index_ > index) 1733 if (last_committed_entry_index_ > index)
1735 last_committed_entry_index_--; 1734 last_committed_entry_index_--;
1736 } 1735 }
1737 1736
1738 void NavigationControllerImpl::DiscardNonCommittedEntries() { 1737 void NavigationControllerImpl::DiscardNonCommittedEntries() {
ncarter (slow) 2017/06/01 23:08:07 I debated whether to go with the approach you see
Charlie Reis 2017/06/02 23:57:57 I like the approach you've taken. Can you update
ncarter (slow) 2017/06/19 18:14:18 Done.
1739 bool transient = transient_entry_index_ != -1; 1738 bool discarding_visible_entry = GetVisibleEntry() != GetLastCommittedEntry();
1739 bool had_transient_entry = GetTransientEntry() != nullptr;
1740
1741 // Clearing the transient entry should always result in a change to the
1742 // visible entry.
1743 DCHECK(!had_transient_entry || discarding_visible_entry);
1744
1745 // Actually discard pending entries.
1740 DiscardNonCommittedEntriesInternal(); 1746 DiscardNonCommittedEntriesInternal();
1741 1747
1742 // If there was a transient entry, invalidate everything so the new active 1748 DCHECK_EQ(GetVisibleEntry(), GetLastCommittedEntry());
1743 // entry state is shown. 1749 DCHECK(!GetTransientEntry());
1744 if (transient) { 1750 DCHECK(!GetPendingEntry());
1745 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_ALL); 1751
1752 if (discarding_visible_entry) {
1753 // If we discarded a visible transient entry, invalidate all.
1754 // Otherwise we've discarded a pending entry, and we only
1755 // need to invalidate the URL.
1756 delegate_->NotifyNavigationStateChanged(
1757 had_transient_entry ? INVALIDATE_TYPE_ALL : INVALIDATE_TYPE_URL);
1746 } 1758 }
1747 } 1759 }
1748 1760
1749 NavigationEntryImpl* NavigationControllerImpl::GetPendingEntry() const { 1761 NavigationEntryImpl* NavigationControllerImpl::GetPendingEntry() const {
1750 // If there is no pending_entry_, there should be no pending_entry_index_. 1762 // If there is no pending_entry_, there should be no pending_entry_index_.
1751 DCHECK(pending_entry_ || pending_entry_index_ == -1); 1763 DCHECK(pending_entry_ || pending_entry_index_ == -1);
1752 1764
1753 // If there is a pending_entry_index_, then pending_entry_ must be the entry 1765 // If there is a pending_entry_index_, then pending_entry_ must be the entry
1754 // at that index. 1766 // at that index.
1755 DCHECK(pending_entry_index_ == -1 || 1767 DCHECK(pending_entry_index_ == -1 ||
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 DCHECK(pending_entry_index_ == -1 || 2205 DCHECK(pending_entry_index_ == -1 ||
2194 pending_entry_ == GetEntryAtIndex(pending_entry_index_)); 2206 pending_entry_ == GetEntryAtIndex(pending_entry_index_));
2195 } 2207 }
2196 2208
2197 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 2209 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
2198 const base::Callback<base::Time()>& get_timestamp_callback) { 2210 const base::Callback<base::Time()>& get_timestamp_callback) {
2199 get_timestamp_callback_ = get_timestamp_callback; 2211 get_timestamp_callback_ = get_timestamp_callback;
2200 } 2212 }
2201 2213
2202 } // namespace content 2214 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698