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

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

Issue 2225343002: Navigation: move RestoreType and ReloadType into a separate file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase+ Created 4 years, 4 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // 108 //
109 // An empty state is treated as a new navigation by WebKit, which would mean 109 // An empty state is treated as a new navigation by WebKit, which would mean
110 // losing the navigation entries and generating a new navigation entry after 110 // losing the navigation entries and generating a new navigation entry after
111 // this one. We don't want that. To avoid this we create a valid state which 111 // this one. We don't want that. To avoid this we create a valid state which
112 // WebKit will not treat as a new navigation. 112 // WebKit will not treat as a new navigation.
113 void SetPageStateIfEmpty(NavigationEntryImpl* entry) { 113 void SetPageStateIfEmpty(NavigationEntryImpl* entry) {
114 if (!entry->GetPageState().IsValid()) 114 if (!entry->GetPageState().IsValid())
115 entry->SetPageState(PageState::CreateFromURL(entry->GetURL())); 115 entry->SetPageState(PageState::CreateFromURL(entry->GetURL()));
116 } 116 }
117 117
118 NavigationEntryImpl::RestoreType ControllerRestoreTypeToEntryType(
Charlie Reis 2016/08/11 23:58:43 I admit this does seem a bit unnecessary. I think
119 NavigationController::RestoreType type) {
120 switch (type) {
121 case NavigationController::RESTORE_CURRENT_SESSION:
122 return NavigationEntryImpl::RESTORE_CURRENT_SESSION;
123 case NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY:
124 return NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY;
125 case NavigationController::RESTORE_LAST_SESSION_CRASHED:
126 return NavigationEntryImpl::RESTORE_LAST_SESSION_CRASHED;
127 }
128 NOTREACHED();
129 return NavigationEntryImpl::RESTORE_CURRENT_SESSION;
130 }
131
132 // Configure all the NavigationEntries in entries for restore. This resets 118 // Configure all the NavigationEntries in entries for restore. This resets
133 // the transition type to reload and makes sure the content state isn't empty. 119 // the transition type to reload and makes sure the content state isn't empty.
134 void ConfigureEntriesForRestore( 120 void ConfigureEntriesForRestore(
135 std::vector<std::unique_ptr<NavigationEntryImpl>>* entries, 121 std::vector<std::unique_ptr<NavigationEntryImpl>>* entries,
136 NavigationController::RestoreType type) { 122 RestoreType type) {
137 for (size_t i = 0; i < entries->size(); ++i) { 123 for (size_t i = 0; i < entries->size(); ++i) {
138 // Use a transition type of reload so that we don't incorrectly increase 124 // Use a transition type of reload so that we don't incorrectly increase
139 // the typed count. 125 // the typed count.
140 (*entries)[i]->SetTransitionType(ui::PAGE_TRANSITION_RELOAD); 126 (*entries)[i]->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
141 (*entries)[i]->set_restore_type(ControllerRestoreTypeToEntryType(type)); 127 (*entries)[i]->set_restore_type(type);
142 // NOTE(darin): This code is only needed for backwards compat. 128 // NOTE(darin): This code is only needed for backwards compat.
143 SetPageStateIfEmpty((*entries)[i].get()); 129 SetPageStateIfEmpty((*entries)[i].get());
144 } 130 }
145 } 131 }
146 132
147 // Determines whether or not we should be carrying over a user agent override 133 // Determines whether or not we should be carrying over a user agent override
148 // between two NavigationEntries. 134 // between two NavigationEntries.
149 bool ShouldKeepOverride(const NavigationEntry* last_entry) { 135 bool ShouldKeepOverride(const NavigationEntry* last_entry) {
150 return last_entry && last_entry->GetIsOverridingUserAgent(); 136 return last_entry && last_entry->GetIsOverridingUserAgent();
151 } 137 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 failed_pending_entry_id_(0), 218 failed_pending_entry_id_(0),
233 last_committed_entry_index_(-1), 219 last_committed_entry_index_(-1),
234 pending_entry_index_(-1), 220 pending_entry_index_(-1),
235 transient_entry_index_(-1), 221 transient_entry_index_(-1),
236 delegate_(delegate), 222 delegate_(delegate),
237 max_restored_page_id_(-1), 223 max_restored_page_id_(-1),
238 ssl_manager_(this), 224 ssl_manager_(this),
239 needs_reload_(false), 225 needs_reload_(false),
240 is_initial_navigation_(true), 226 is_initial_navigation_(true),
241 in_navigate_to_pending_entry_(false), 227 in_navigate_to_pending_entry_(false),
242 pending_reload_(NO_RELOAD), 228 pending_reload_(ReloadType::NONE),
243 get_timestamp_callback_(base::Bind(&base::Time::Now)), 229 get_timestamp_callback_(base::Bind(&base::Time::Now)),
244 screenshot_manager_(new NavigationEntryScreenshotManager(this)) { 230 screenshot_manager_(new NavigationEntryScreenshotManager(this)) {
245 DCHECK(browser_context_); 231 DCHECK(browser_context_);
246 } 232 }
247 233
248 NavigationControllerImpl::~NavigationControllerImpl() { 234 NavigationControllerImpl::~NavigationControllerImpl() {
249 DiscardNonCommittedEntriesInternal(); 235 DiscardNonCommittedEntriesInternal();
250 } 236 }
251 237
252 WebContents* NavigationControllerImpl::GetWebContents() const { 238 WebContents* NavigationControllerImpl::GetWebContents() const {
(...skipping 21 matching lines...) Expand all
274 260
275 // At this point, the |entries| is full of empty scoped_ptrs, so it can be 261 // At this point, the |entries| is full of empty scoped_ptrs, so it can be
276 // cleared out safely. 262 // cleared out safely.
277 entries->clear(); 263 entries->clear();
278 264
279 // And finish the restore. 265 // And finish the restore.
280 FinishRestore(selected_navigation, type); 266 FinishRestore(selected_navigation, type);
281 } 267 }
282 268
283 void NavigationControllerImpl::Reload(bool check_for_repost) { 269 void NavigationControllerImpl::Reload(bool check_for_repost) {
284 ReloadType type = RELOAD; 270 ReloadType type = ReloadType::NORMAL;
285 if (base::FeatureList::IsEnabled( 271 if (base::FeatureList::IsEnabled(
286 features::kNonValidatingReloadOnNormalReload)) { 272 features::kNonValidatingReloadOnNormalReload)) {
287 type = RELOAD_MAIN_RESOURCE; 273 type = ReloadType::MAIN_RESOURCE;
288 } 274 }
289 ReloadInternal(check_for_repost, type); 275 ReloadInternal(check_for_repost, type);
290 } 276 }
291 void NavigationControllerImpl::ReloadToRefreshContent(bool check_for_repost) { 277 void NavigationControllerImpl::ReloadToRefreshContent(bool check_for_repost) {
292 ReloadType type = RELOAD; 278 ReloadType type = ReloadType::NORMAL;
293 if (base::FeatureList::IsEnabled( 279 if (base::FeatureList::IsEnabled(
294 features::kNonValidatingReloadOnRefreshContent)) { 280 features::kNonValidatingReloadOnRefreshContent)) {
295 type = RELOAD_MAIN_RESOURCE; 281 type = ReloadType::MAIN_RESOURCE;
296 } 282 }
297 ReloadInternal(check_for_repost, type); 283 ReloadInternal(check_for_repost, type);
298 } 284 }
299 void NavigationControllerImpl::ReloadBypassingCache(bool check_for_repost) { 285 void NavigationControllerImpl::ReloadBypassingCache(bool check_for_repost) {
300 ReloadInternal(check_for_repost, RELOAD_BYPASSING_CACHE); 286 ReloadInternal(check_for_repost, ReloadType::BYPASSING_CACHE);
301 } 287 }
302 void NavigationControllerImpl::ReloadOriginalRequestURL(bool check_for_repost) { 288 void NavigationControllerImpl::ReloadOriginalRequestURL(bool check_for_repost) {
303 ReloadInternal(check_for_repost, RELOAD_ORIGINAL_REQUEST_URL); 289 ReloadInternal(check_for_repost, ReloadType::ORIGINAL_REQUEST_URL);
304 } 290 }
305 void NavigationControllerImpl::ReloadDisableLoFi(bool check_for_repost) { 291 void NavigationControllerImpl::ReloadDisableLoFi(bool check_for_repost) {
306 ReloadInternal(check_for_repost, RELOAD_DISABLE_LOFI_MODE); 292 ReloadInternal(check_for_repost, ReloadType::DISABLE_LOFI_MODE);
307 } 293 }
308 294
309 void NavigationControllerImpl::ReloadInternal(bool check_for_repost, 295 void NavigationControllerImpl::ReloadInternal(bool check_for_repost,
310 ReloadType reload_type) { 296 ReloadType reload_type) {
311 if (transient_entry_index_ != -1) { 297 if (transient_entry_index_ != -1) {
312 // If an interstitial is showing, treat a reload as a navigation to the 298 // If an interstitial is showing, treat a reload as a navigation to the
313 // transient entry's URL. 299 // transient entry's URL.
314 NavigationEntryImpl* transient_entry = GetTransientEntry(); 300 NavigationEntryImpl* transient_entry = GetTransientEntry();
315 if (!transient_entry) 301 if (!transient_entry)
316 return; 302 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 site_instance->HasWrongProcessForURL(entry->GetURL())) { 358 site_instance->HasWrongProcessForURL(entry->GetURL())) {
373 // Create a navigation entry that resembles the current one, but do not 359 // Create a navigation entry that resembles the current one, but do not
374 // copy page id, site instance, content state, or timestamp. 360 // copy page id, site instance, content state, or timestamp.
375 NavigationEntryImpl* nav_entry = NavigationEntryImpl::FromNavigationEntry( 361 NavigationEntryImpl* nav_entry = NavigationEntryImpl::FromNavigationEntry(
376 CreateNavigationEntry( 362 CreateNavigationEntry(
377 entry->GetURL(), entry->GetReferrer(), entry->GetTransitionType(), 363 entry->GetURL(), entry->GetReferrer(), entry->GetTransitionType(),
378 false, entry->extra_headers(), browser_context_).release()); 364 false, entry->extra_headers(), browser_context_).release());
379 365
380 // Mark the reload type as NO_RELOAD, so navigation will not be considered 366 // Mark the reload type as NO_RELOAD, so navigation will not be considered
381 // a reload in the renderer. 367 // a reload in the renderer.
382 reload_type = NavigationController::NO_RELOAD; 368 reload_type = ReloadType::NONE;
383 369
384 nav_entry->set_should_replace_entry(true); 370 nav_entry->set_should_replace_entry(true);
385 pending_entry_ = nav_entry; 371 pending_entry_ = nav_entry;
386 DCHECK_EQ(-1, pending_entry_index_); 372 DCHECK_EQ(-1, pending_entry_index_);
387 } else { 373 } else {
388 pending_entry_ = entry; 374 pending_entry_ = entry;
389 pending_entry_index_ = current_index; 375 pending_entry_index_ = current_index;
390 376
391 // The title of the page being reloaded might have been removed in the 377 // The title of the page being reloaded might have been removed in the
392 // meanwhile, so we need to revert to the default title upon reload and 378 // meanwhile, so we need to revert to the default title upon reload and
393 // invalidate the previously cached title (SetTitle will do both). 379 // invalidate the previously cached title (SetTitle will do both).
394 // See Chromium issue 96041. 380 // See Chromium issue 96041.
395 pending_entry_->SetTitle(base::string16()); 381 pending_entry_->SetTitle(base::string16());
396 382
397 pending_entry_->SetTransitionType(ui::PAGE_TRANSITION_RELOAD); 383 pending_entry_->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
398 } 384 }
399 385
400 NavigateToPendingEntry(reload_type); 386 NavigateToPendingEntry(reload_type);
401 } 387 }
402 } 388 }
403 389
404 void NavigationControllerImpl::CancelPendingReload() { 390 void NavigationControllerImpl::CancelPendingReload() {
405 DCHECK(pending_reload_ != NO_RELOAD); 391 DCHECK(pending_reload_ != ReloadType::NONE);
406 pending_reload_ = NO_RELOAD; 392 pending_reload_ = ReloadType::NONE;
407 } 393 }
408 394
409 void NavigationControllerImpl::ContinuePendingReload() { 395 void NavigationControllerImpl::ContinuePendingReload() {
410 if (pending_reload_ == NO_RELOAD) { 396 if (pending_reload_ == ReloadType::NONE) {
411 NOTREACHED(); 397 NOTREACHED();
412 } else { 398 } else {
413 ReloadInternal(false, pending_reload_); 399 ReloadInternal(false, pending_reload_);
414 pending_reload_ = NO_RELOAD; 400 pending_reload_ = ReloadType::NONE;
415 } 401 }
416 } 402 }
417 403
418 bool NavigationControllerImpl::IsInitialNavigation() const { 404 bool NavigationControllerImpl::IsInitialNavigation() const {
419 return is_initial_navigation_; 405 return is_initial_navigation_;
420 } 406 }
421 407
422 bool NavigationControllerImpl::IsInitialBlankNavigation() const { 408 bool NavigationControllerImpl::IsInitialBlankNavigation() const {
423 // TODO(creis): Once we create a NavigationEntry for the initial blank page, 409 // TODO(creis): Once we create a NavigationEntry for the initial blank page,
424 // we'll need to check for entry count 1 and restore_type RESTORE_NONE (to 410 // we'll need to check for entry count 1 and restore_type NONE (to exclude
425 // exclude the cloned tab case). 411 // the cloned tab case).
426 return IsInitialNavigation() && GetEntryCount() == 0; 412 return IsInitialNavigation() && GetEntryCount() == 0;
427 } 413 }
428 414
429 NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID( 415 NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID(
430 SiteInstance* instance, 416 SiteInstance* instance,
431 int32_t page_id) const { 417 int32_t page_id) const {
432 int index = GetEntryIndexWithPageID(instance, page_id); 418 int index = GetEntryIndexWithPageID(instance, page_id);
433 return (index != -1) ? entries_[index].get() : nullptr; 419 return (index != -1) ? entries_[index].get() : nullptr;
434 } 420 }
435 421
436 NavigationEntryImpl* 422 NavigationEntryImpl*
437 NavigationControllerImpl::GetEntryWithUniqueID(int nav_entry_id) const { 423 NavigationControllerImpl::GetEntryWithUniqueID(int nav_entry_id) const {
438 int index = GetEntryIndexWithUniqueID(nav_entry_id); 424 int index = GetEntryIndexWithUniqueID(nav_entry_id);
439 return (index != -1) ? entries_[index].get() : nullptr; 425 return (index != -1) ? entries_[index].get() : nullptr;
440 } 426 }
441 427
442 void NavigationControllerImpl::LoadEntry( 428 void NavigationControllerImpl::LoadEntry(
443 std::unique_ptr<NavigationEntryImpl> entry) { 429 std::unique_ptr<NavigationEntryImpl> entry) {
444 // When navigating to a new page, we don't know for sure if we will actually 430 // When navigating to a new page, we don't know for sure if we will actually
445 // end up leaving the current page. The new page load could for example 431 // end up leaving the current page. The new page load could for example
446 // result in a download or a 'no content' response (e.g., a mailto: URL). 432 // result in a download or a 'no content' response (e.g., a mailto: URL).
447 SetPendingEntry(std::move(entry)); 433 SetPendingEntry(std::move(entry));
448 NavigateToPendingEntry(NO_RELOAD); 434 NavigateToPendingEntry(ReloadType::NONE);
449 } 435 }
450 436
451 void NavigationControllerImpl::SetPendingEntry( 437 void NavigationControllerImpl::SetPendingEntry(
452 std::unique_ptr<NavigationEntryImpl> entry) { 438 std::unique_ptr<NavigationEntryImpl> entry) {
453 DiscardNonCommittedEntriesInternal(); 439 DiscardNonCommittedEntriesInternal();
454 pending_entry_ = entry.release(); 440 pending_entry_ = entry.release();
455 NotificationService::current()->Notify( 441 NotificationService::current()->Notify(
456 NOTIFICATION_NAV_ENTRY_PENDING, 442 NOTIFICATION_NAV_ENTRY_PENDING,
457 Source<NavigationController>(this), 443 Source<NavigationController>(this),
458 Details<NavigationEntry>(pending_entry_)); 444 Details<NavigationEntry>(pending_entry_));
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 587 }
602 } 588 }
603 589
604 DiscardNonCommittedEntries(); 590 DiscardNonCommittedEntries();
605 591
606 pending_entry_index_ = index; 592 pending_entry_index_ = index;
607 entries_[pending_entry_index_]->SetTransitionType( 593 entries_[pending_entry_index_]->SetTransitionType(
608 ui::PageTransitionFromInt( 594 ui::PageTransitionFromInt(
609 entries_[pending_entry_index_]->GetTransitionType() | 595 entries_[pending_entry_index_]->GetTransitionType() |
610 ui::PAGE_TRANSITION_FORWARD_BACK)); 596 ui::PAGE_TRANSITION_FORWARD_BACK));
611 NavigateToPendingEntry(NO_RELOAD); 597 NavigateToPendingEntry(ReloadType::NONE);
612 } 598 }
613 599
614 void NavigationControllerImpl::GoToOffset(int offset) { 600 void NavigationControllerImpl::GoToOffset(int offset) {
615 // Note: This is actually reached in unit tests. 601 // Note: This is actually reached in unit tests.
616 if (!CanGoToOffset(offset)) 602 if (!CanGoToOffset(offset))
617 return; 603 return;
618 604
619 GoToIndex(GetIndexForOffset(offset)); 605 GoToIndex(GetIndexForOffset(offset));
620 } 606 }
621 607
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 if (GetLastCommittedEntry()) { 780 if (GetLastCommittedEntry()) {
795 details->previous_url = GetLastCommittedEntry()->GetURL(); 781 details->previous_url = GetLastCommittedEntry()->GetURL();
796 details->previous_entry_index = GetLastCommittedEntryIndex(); 782 details->previous_entry_index = GetLastCommittedEntryIndex();
797 } else { 783 } else {
798 details->previous_url = GURL(); 784 details->previous_url = GURL();
799 details->previous_entry_index = -1; 785 details->previous_entry_index = -1;
800 } 786 }
801 787
802 // If there is a pending entry at this point, it should have a SiteInstance, 788 // If there is a pending entry at this point, it should have a SiteInstance,
803 // except for restored entries. 789 // except for restored entries.
804 DCHECK(pending_entry_index_ == -1 || 790 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance() ||
805 pending_entry_->site_instance() || 791 pending_entry_->restore_type() != RestoreType::NONE);
806 pending_entry_->restore_type() != NavigationEntryImpl::RESTORE_NONE); 792 if (pending_entry_ && pending_entry_->restore_type() != RestoreType::NONE) {
807 if (pending_entry_ && 793 pending_entry_->set_restore_type(RestoreType::NONE);
808 pending_entry_->restore_type() != NavigationEntryImpl::RESTORE_NONE) 794 }
809 pending_entry_->set_restore_type(NavigationEntryImpl::RESTORE_NONE);
810 795
811 // The renderer tells us whether the navigation replaces the current entry. 796 // The renderer tells us whether the navigation replaces the current entry.
812 details->did_replace_entry = params.should_replace_current_entry; 797 details->did_replace_entry = params.should_replace_current_entry;
813 798
814 // Do navigation-type specific actions. These will make and commit an entry. 799 // Do navigation-type specific actions. These will make and commit an entry.
815 details->type = ClassifyNavigation(rfh, params); 800 details->type = ClassifyNavigation(rfh, params);
816 801
817 // is_in_page must be computed before the entry gets committed. 802 // is_in_page must be computed before the entry gets committed.
818 details->is_in_page = IsURLInPageNavigation(params.url, params.origin, 803 details->is_in_page = IsURLInPageNavigation(params.url, params.origin,
819 params.was_within_same_page, rfh); 804 params.was_within_same_page, rfh);
820 805
821 switch (details->type) { 806 switch (details->type) {
822 case NAVIGATION_TYPE_NEW_PAGE: 807 case NavigationType::NEW_PAGE:
Charlie Reis 2016/08/11 23:58:43 What's the motivation for changing this one? I'm
Takashi Toyoshima 2016/09/07 12:07:44 My understanding is "enum class" is encouraged to
823 RendererDidNavigateToNewPage(rfh, params, details->is_in_page, 808 RendererDidNavigateToNewPage(rfh, params, details->is_in_page,
824 details->did_replace_entry); 809 details->did_replace_entry);
825 break; 810 break;
826 case NAVIGATION_TYPE_EXISTING_PAGE: 811 case NavigationType::EXISTING_PAGE:
827 details->did_replace_entry = details->is_in_page; 812 details->did_replace_entry = details->is_in_page;
828 RendererDidNavigateToExistingPage(rfh, params); 813 RendererDidNavigateToExistingPage(rfh, params);
829 break; 814 break;
830 case NAVIGATION_TYPE_SAME_PAGE: 815 case NavigationType::SAME_PAGE:
831 RendererDidNavigateToSamePage(rfh, params); 816 RendererDidNavigateToSamePage(rfh, params);
832 break; 817 break;
833 case NAVIGATION_TYPE_NEW_SUBFRAME: 818 case NavigationType::NEW_SUBFRAME:
834 RendererDidNavigateNewSubframe(rfh, params, details->is_in_page, 819 RendererDidNavigateNewSubframe(rfh, params, details->is_in_page,
835 details->did_replace_entry); 820 details->did_replace_entry);
836 break; 821 break;
837 case NAVIGATION_TYPE_AUTO_SUBFRAME: 822 case NavigationType::AUTO_SUBFRAME:
838 if (!RendererDidNavigateAutoSubframe(rfh, params)) 823 if (!RendererDidNavigateAutoSubframe(rfh, params))
839 return false; 824 return false;
840 break; 825 break;
841 case NAVIGATION_TYPE_NAV_IGNORE: 826 case NavigationType::NAV_IGNORE:
842 // If a pending navigation was in progress, this canceled it. We should 827 // If a pending navigation was in progress, this canceled it. We should
843 // discard it and make sure it is removed from the URL bar. After that, 828 // discard it and make sure it is removed from the URL bar. After that,
844 // there is nothing we can do with this navigation, so we just return to 829 // there is nothing we can do with this navigation, so we just return to
845 // the caller that nothing has happened. 830 // the caller that nothing has happened.
846 if (pending_entry_) { 831 if (pending_entry_) {
847 DiscardNonCommittedEntries(); 832 DiscardNonCommittedEntries();
848 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); 833 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
849 } 834 }
850 return false; 835 return false;
851 default: 836 default:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 return true; 924 return true;
940 } 925 }
941 926
942 NavigationType NavigationControllerImpl::ClassifyNavigation( 927 NavigationType NavigationControllerImpl::ClassifyNavigation(
943 RenderFrameHostImpl* rfh, 928 RenderFrameHostImpl* rfh,
944 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) const { 929 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) const {
945 if (params.did_create_new_entry) { 930 if (params.did_create_new_entry) {
946 // A new entry. We may or may not have a pending entry for the page, and 931 // A new entry. We may or may not have a pending entry for the page, and
947 // this may or may not be the main frame. 932 // this may or may not be the main frame.
948 if (!rfh->GetParent()) { 933 if (!rfh->GetParent()) {
949 return NAVIGATION_TYPE_NEW_PAGE; 934 return NavigationType::NEW_PAGE;
950 } 935 }
951 936
952 // When this is a new subframe navigation, we should have a committed page 937 // When this is a new subframe navigation, we should have a committed page
953 // in which it's a subframe. This may not be the case when an iframe is 938 // in which it's a subframe. This may not be the case when an iframe is
954 // navigated on a popup navigated to about:blank (the iframe would be 939 // navigated on a popup navigated to about:blank (the iframe would be
955 // written into the popup by script on the main page). For these cases, 940 // written into the popup by script on the main page). For these cases,
956 // there isn't any navigation stuff we can do, so just ignore it. 941 // there isn't any navigation stuff we can do, so just ignore it.
957 if (!GetLastCommittedEntry()) 942 if (!GetLastCommittedEntry())
958 return NAVIGATION_TYPE_NAV_IGNORE; 943 return NavigationType::NAV_IGNORE;
959 944
960 // Valid subframe navigation. 945 // Valid subframe navigation.
961 return NAVIGATION_TYPE_NEW_SUBFRAME; 946 return NavigationType::NEW_SUBFRAME;
962 } 947 }
963 948
964 // Cross-process location.replace navigations should be classified as New with 949 // Cross-process location.replace navigations should be classified as New with
965 // replacement rather than ExistingPage, since it is not safe to reuse the 950 // replacement rather than ExistingPage, since it is not safe to reuse the
966 // NavigationEntry. 951 // NavigationEntry.
967 // TODO(creis): Have the renderer classify location.replace as 952 // TODO(creis): Have the renderer classify location.replace as
968 // did_create_new_entry for all cases and eliminate this special case. This 953 // did_create_new_entry for all cases and eliminate this special case. This
969 // requires updating several test expectations. See https://crbug.com/596707. 954 // requires updating several test expectations. See https://crbug.com/596707.
970 if (!rfh->GetParent() && GetLastCommittedEntry() && 955 if (!rfh->GetParent() && GetLastCommittedEntry() &&
971 GetLastCommittedEntry()->site_instance() != rfh->GetSiteInstance() && 956 GetLastCommittedEntry()->site_instance() != rfh->GetSiteInstance() &&
972 params.should_replace_current_entry) { 957 params.should_replace_current_entry) {
973 return NAVIGATION_TYPE_NEW_PAGE; 958 return NavigationType::NEW_PAGE;
974 } 959 }
975 960
976 // We only clear the session history when navigating to a new page. 961 // We only clear the session history when navigating to a new page.
977 DCHECK(!params.history_list_was_cleared); 962 DCHECK(!params.history_list_was_cleared);
978 963
979 if (rfh->GetParent()) { 964 if (rfh->GetParent()) {
980 // All manual subframes would be did_create_new_entry and handled above, so 965 // All manual subframes would be did_create_new_entry and handled above, so
981 // we know this is auto. 966 // we know this is auto.
982 if (GetLastCommittedEntry()) { 967 if (GetLastCommittedEntry()) {
983 return NAVIGATION_TYPE_AUTO_SUBFRAME; 968 return NavigationType::AUTO_SUBFRAME;
984 } else { 969 } else {
985 // We ignore subframes created in non-committed pages; we'd appreciate if 970 // We ignore subframes created in non-committed pages; we'd appreciate if
986 // people stopped doing that. 971 // people stopped doing that.
987 return NAVIGATION_TYPE_NAV_IGNORE; 972 return NavigationType::NAV_IGNORE;
988 } 973 }
989 } 974 }
990 975
991 if (params.nav_entry_id == 0) { 976 if (params.nav_entry_id == 0) {
992 // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't 977 // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't
993 // create a new page. 978 // create a new page.
994 979
995 // Just like above in the did_create_new_entry case, it's possible to 980 // Just like above in the did_create_new_entry case, it's possible to
996 // scribble onto an uncommitted page. Again, there isn't any navigation 981 // scribble onto an uncommitted page. Again, there isn't any navigation
997 // stuff that we can do, so ignore it here as well. 982 // stuff that we can do, so ignore it here as well.
998 NavigationEntry* last_committed = GetLastCommittedEntry(); 983 NavigationEntry* last_committed = GetLastCommittedEntry();
999 if (!last_committed) 984 if (!last_committed)
1000 return NAVIGATION_TYPE_NAV_IGNORE; 985 return NavigationType::NAV_IGNORE;
1001 986
1002 // This is history.replaceState(), history.reload(), or a client-side 987 // This is history.replaceState(), history.reload(), or a client-side
1003 // redirect. 988 // redirect.
1004 return NAVIGATION_TYPE_EXISTING_PAGE; 989 return NavigationType::EXISTING_PAGE;
1005 } 990 }
1006 991
1007 if (pending_entry_ && pending_entry_index_ == -1 && 992 if (pending_entry_ && pending_entry_index_ == -1 &&
1008 pending_entry_->GetUniqueID() == params.nav_entry_id) { 993 pending_entry_->GetUniqueID() == params.nav_entry_id) {
1009 // In this case, we have a pending entry for a load of a new URL but Blink 994 // In this case, we have a pending entry for a load of a new URL but Blink
1010 // didn't do a new navigation (params.did_create_new_entry). First check to 995 // didn't do a new navigation (params.did_create_new_entry). First check to
1011 // make sure Blink didn't treat a new cross-process navigation as inert, and 996 // make sure Blink didn't treat a new cross-process navigation as inert, and
1012 // thus set params.did_create_new_entry to false. In that case, we must 997 // thus set params.did_create_new_entry to false. In that case, we must
1013 // treat it as NEW since the SiteInstance doesn't match the entry. 998 // treat it as NEW since the SiteInstance doesn't match the entry.
1014 if (GetLastCommittedEntry()->site_instance() != rfh->GetSiteInstance()) 999 if (GetLastCommittedEntry()->site_instance() != rfh->GetSiteInstance())
1015 return NAVIGATION_TYPE_NEW_PAGE; 1000 return NavigationType::NEW_PAGE;
1016 1001
1017 // Otherwise, this happens when you press enter in the URL bar to reload. We 1002 // Otherwise, this happens when you press enter in the URL bar to reload. We
1018 // will create a pending entry, but Blink will convert it to a reload since 1003 // will create a pending entry, but Blink will convert it to a reload since
1019 // it's the same page and not create a new entry for it (the user doesn't 1004 // it's the same page and not create a new entry for it (the user doesn't
1020 // want to have a new back/forward entry when they do this). Therefore we 1005 // want to have a new back/forward entry when they do this). Therefore we
1021 // want to just ignore the pending entry and go back to where we were (the 1006 // want to just ignore the pending entry and go back to where we were (the
1022 // "existing entry"). 1007 // "existing entry").
1023 // TODO(creis,avi): Eliminate SAME_PAGE in https://crbug.com/536102. 1008 // TODO(creis,avi): Eliminate SAME_PAGE in https://crbug.com/536102.
1024 return NAVIGATION_TYPE_SAME_PAGE; 1009 return NavigationType::SAME_PAGE;
1025 } 1010 }
1026 1011
1027 if (params.intended_as_new_entry) { 1012 if (params.intended_as_new_entry) {
1028 // This was intended to be a navigation to a new entry but the pending entry 1013 // This was intended to be a navigation to a new entry but the pending entry
1029 // got cleared in the meanwhile. Classify as EXISTING_PAGE because we may or 1014 // got cleared in the meanwhile. Classify as EXISTING_PAGE because we may or
1030 // may not have a pending entry. 1015 // may not have a pending entry.
1031 return NAVIGATION_TYPE_EXISTING_PAGE; 1016 return NavigationType::EXISTING_PAGE;
1032 } 1017 }
1033 1018
1034 if (params.url_is_unreachable && failed_pending_entry_id_ != 0 && 1019 if (params.url_is_unreachable && failed_pending_entry_id_ != 0 &&
1035 params.nav_entry_id == failed_pending_entry_id_) { 1020 params.nav_entry_id == failed_pending_entry_id_) {
1036 // If the renderer was going to a new pending entry that got cleared because 1021 // If the renderer was going to a new pending entry that got cleared because
1037 // of an error, this is the case of the user trying to retry a failed load 1022 // of an error, this is the case of the user trying to retry a failed load
1038 // by pressing return. Classify as EXISTING_PAGE because we probably don't 1023 // by pressing return. Classify as EXISTING_PAGE because we probably don't
1039 // have a pending entry. 1024 // have a pending entry.
1040 return NAVIGATION_TYPE_EXISTING_PAGE; 1025 return NavigationType::EXISTING_PAGE;
1041 } 1026 }
1042 1027
1043 // Now we know that the notification is for an existing page. Find that entry. 1028 // Now we know that the notification is for an existing page. Find that entry.
1044 int existing_entry_index = GetEntryIndexWithUniqueID(params.nav_entry_id); 1029 int existing_entry_index = GetEntryIndexWithUniqueID(params.nav_entry_id);
1045 if (existing_entry_index == -1) { 1030 if (existing_entry_index == -1) {
1046 // The renderer has committed a navigation to an entry that no longer 1031 // The renderer has committed a navigation to an entry that no longer
1047 // exists. Because the renderer is showing that page, resurrect that entry. 1032 // exists. Because the renderer is showing that page, resurrect that entry.
1048 return NAVIGATION_TYPE_NEW_PAGE; 1033 return NavigationType::NEW_PAGE;
1049 } 1034 }
1050 1035
1051 // Since we weeded out "new" navigations above, we know this is an existing 1036 // Since we weeded out "new" navigations above, we know this is an existing
1052 // (back/forward) navigation. 1037 // (back/forward) navigation.
1053 return NAVIGATION_TYPE_EXISTING_PAGE; 1038 return NavigationType::EXISTING_PAGE;
1054 } 1039 }
1055 1040
1056 void NavigationControllerImpl::RendererDidNavigateToNewPage( 1041 void NavigationControllerImpl::RendererDidNavigateToNewPage(
1057 RenderFrameHostImpl* rfh, 1042 RenderFrameHostImpl* rfh,
1058 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 1043 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
1059 bool is_in_page, 1044 bool is_in_page,
1060 bool replace_entry) { 1045 bool replace_entry) {
1061 std::unique_ptr<NavigationEntryImpl> new_entry; 1046 std::unique_ptr<NavigationEntryImpl> new_entry;
1062 bool update_virtual_url = false; 1047 bool update_virtual_url = false;
1063 1048
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 1453
1469 for (SessionStorageNamespaceMap::const_iterator it = 1454 for (SessionStorageNamespaceMap::const_iterator it =
1470 source.session_storage_namespace_map_.begin(); 1455 source.session_storage_namespace_map_.begin();
1471 it != source.session_storage_namespace_map_.end(); 1456 it != source.session_storage_namespace_map_.end();
1472 ++it) { 1457 ++it) {
1473 SessionStorageNamespaceImpl* source_namespace = 1458 SessionStorageNamespaceImpl* source_namespace =
1474 static_cast<SessionStorageNamespaceImpl*>(it->second.get()); 1459 static_cast<SessionStorageNamespaceImpl*>(it->second.get());
1475 session_storage_namespace_map_[it->first] = source_namespace->Clone(); 1460 session_storage_namespace_map_[it->first] = source_namespace->Clone();
1476 } 1461 }
1477 1462
1478 FinishRestore(source.last_committed_entry_index_, RESTORE_CURRENT_SESSION); 1463 FinishRestore(source.last_committed_entry_index_,
1464 RestoreType::CURRENT_SESSION);
1479 1465
1480 // Copy the max page id map from the old tab to the new tab. This ensures 1466 // Copy the max page id map from the old tab to the new tab. This ensures
1481 // that new and existing navigations in the tab's current SiteInstances 1467 // that new and existing navigations in the tab's current SiteInstances
1482 // are identified properly. 1468 // are identified properly.
1483 delegate_->CopyMaxPageIDsFrom(source.delegate()->GetWebContents()); 1469 delegate_->CopyMaxPageIDsFrom(source.delegate()->GetWebContents());
1484 } 1470 }
1485 1471
1486 void NavigationControllerImpl::CopyStateFromAndPrune( 1472 void NavigationControllerImpl::CopyStateFromAndPrune(
1487 NavigationController* temp, 1473 NavigationController* temp,
1488 bool replace_entry) { 1474 bool replace_entry) {
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 needs_reload_ = false; 1759 needs_reload_ = false;
1774 1760
1775 // If we were navigating to a slow-to-commit page, and the user performs 1761 // If we were navigating to a slow-to-commit page, and the user performs
1776 // a session history navigation to the last committed page, RenderViewHost 1762 // a session history navigation to the last committed page, RenderViewHost
1777 // will force the throbber to start, but WebKit will essentially ignore the 1763 // will force the throbber to start, but WebKit will essentially ignore the
1778 // navigation, and won't send a message to stop the throbber. To prevent this 1764 // navigation, and won't send a message to stop the throbber. To prevent this
1779 // from happening, we drop the navigation here and stop the slow-to-commit 1765 // from happening, we drop the navigation here and stop the slow-to-commit
1780 // page from loading (which would normally happen during the navigation). 1766 // page from loading (which would normally happen during the navigation).
1781 if (pending_entry_index_ != -1 && 1767 if (pending_entry_index_ != -1 &&
1782 pending_entry_index_ == last_committed_entry_index_ && 1768 pending_entry_index_ == last_committed_entry_index_ &&
1783 (entries_[pending_entry_index_]->restore_type() == 1769 (entries_[pending_entry_index_]->restore_type() == RestoreType::NONE) &&
1784 NavigationEntryImpl::RESTORE_NONE) &&
1785 (entries_[pending_entry_index_]->GetTransitionType() & 1770 (entries_[pending_entry_index_]->GetTransitionType() &
1786 ui::PAGE_TRANSITION_FORWARD_BACK)) { 1771 ui::PAGE_TRANSITION_FORWARD_BACK)) {
1787 delegate_->Stop(); 1772 delegate_->Stop();
1788 1773
1789 // If an interstitial page is showing, we want to close it to get back 1774 // If an interstitial page is showing, we want to close it to get back
1790 // to what was showing before. 1775 // to what was showing before.
1791 if (delegate_->GetInterstitialPage()) 1776 if (delegate_->GetInterstitialPage())
1792 delegate_->GetInterstitialPage()->DontProceed(); 1777 delegate_->GetInterstitialPage()->DontProceed();
1793 1778
1794 DiscardNonCommittedEntries(); 1779 DiscardNonCommittedEntries();
1795 return; 1780 return;
1796 } 1781 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 } 1962 }
1978 1963
1979 void NavigationControllerImpl::LoadIfNecessary() { 1964 void NavigationControllerImpl::LoadIfNecessary() {
1980 if (!needs_reload_) 1965 if (!needs_reload_)
1981 return; 1966 return;
1982 1967
1983 // Calling Reload() results in ignoring state, and not loading. 1968 // Calling Reload() results in ignoring state, and not loading.
1984 // Explicitly use NavigateToPendingEntry so that the renderer uses the 1969 // Explicitly use NavigateToPendingEntry so that the renderer uses the
1985 // cached state. 1970 // cached state.
1986 if (pending_entry_) { 1971 if (pending_entry_) {
1987 NavigateToPendingEntry(NO_RELOAD); 1972 NavigateToPendingEntry(ReloadType::NONE);
1988 } else if (last_committed_entry_index_ != -1) { 1973 } else if (last_committed_entry_index_ != -1) {
1989 pending_entry_index_ = last_committed_entry_index_; 1974 pending_entry_index_ = last_committed_entry_index_;
1990 NavigateToPendingEntry(NO_RELOAD); 1975 NavigateToPendingEntry(ReloadType::NONE);
1991 } else { 1976 } else {
1992 // If there is something to reload, the successful reload will clear the 1977 // If there is something to reload, the successful reload will clear the
1993 // |needs_reload_| flag. Otherwise, just do it here. 1978 // |needs_reload_| flag. Otherwise, just do it here.
1994 needs_reload_ = false; 1979 needs_reload_ = false;
1995 } 1980 }
1996 } 1981 }
1997 1982
1998 void NavigationControllerImpl::NotifyEntryChanged( 1983 void NavigationControllerImpl::NotifyEntryChanged(
1999 const NavigationEntry* entry) { 1984 const NavigationEntry* entry) {
2000 EntryChangedDetails det; 1985 EntryChangedDetails det;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 } 2089 }
2105 } 2090 }
2106 } 2091 }
2107 2092
2108 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 2093 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
2109 const base::Callback<base::Time()>& get_timestamp_callback) { 2094 const base::Callback<base::Time()>& get_timestamp_callback) {
2110 get_timestamp_callback_ = get_timestamp_callback; 2095 get_timestamp_callback_ = get_timestamp_callback;
2111 } 2096 }
2112 2097
2113 } // namespace content 2098 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698