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

Side by Side Diff: chrome/browser/navigation_controller.cc

Issue 4250: Fix a crash when a frame was inserted into a popup and navigated. I added a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/navigation_controller_unittest.cc » ('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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/navigation_controller.h" 5 #include "chrome/browser/navigation_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 " navigated to a valid page. This should be impossible."; 579 " navigated to a valid page. This should be impossible.";
580 return NAV_IGNORE; 580 return NAV_IGNORE;
581 } 581 }
582 582
583 if (params.page_id > active_contents_->GetMaxPageID()) { 583 if (params.page_id > active_contents_->GetMaxPageID()) {
584 // Greater page IDs than we've ever seen before are new pages. We may or may 584 // Greater page IDs than we've ever seen before are new pages. We may or may
585 // not have a pending entry for the page, and this may or may not be the 585 // not have a pending entry for the page, and this may or may not be the
586 // main frame. 586 // main frame.
587 if (PageTransition::IsMainFrame(params.transition)) 587 if (PageTransition::IsMainFrame(params.transition))
588 return NAV_NEW_PAGE; 588 return NAV_NEW_PAGE;
589
590 // When this is a new subframe navigation, we should have a committed page
591 // for which it's a suframe in. This may not be the case when an iframe is
592 // navigated on a popup navigated to about:blank (the iframe would be
593 // written into the popup by script on the main page). For these cases,
594 // there isn't any navigation stuff we can do, so just ignore it.
595 if (!GetLastCommittedEntry())
596 return NAV_IGNORE;
597
598 // Valid subframe navigation.
589 return NAV_NEW_SUBFRAME; 599 return NAV_NEW_SUBFRAME;
590 } 600 }
591 601
592 // Now we know that the notification is for an existing page. Find that entry. 602 // Now we know that the notification is for an existing page. Find that entry.
593 int existing_entry_index = GetEntryIndexWithPageID( 603 int existing_entry_index = GetEntryIndexWithPageID(
594 active_contents_->type(), 604 active_contents_->type(),
595 active_contents_->GetSiteInstance(), 605 active_contents_->GetSiteInstance(),
596 params.page_id); 606 params.page_id);
597 if (existing_entry_index == -1) { 607 if (existing_entry_index == -1) {
598 // The page was not found. It could have been pruned because of the limit on 608 // The page was not found. It could have been pruned because of the limit on
(...skipping 15 matching lines...) Expand all
614 // a reload since it's the same page and not create a new entry for it 624 // a reload since it's the same page and not create a new entry for it
615 // (the user doesn't want to have a new back/forward entry when they do 625 // (the user doesn't want to have a new back/forward entry when they do
616 // this). In this case, we want to just ignore the pending entry and go 626 // this). In this case, we want to just ignore the pending entry and go
617 // back to where we were (the "existing entry"). 627 // back to where we were (the "existing entry").
618 return NAV_SAME_PAGE; 628 return NAV_SAME_PAGE;
619 } 629 }
620 630
621 if (AreURLsInPageNavigation(existing_entry->url(), params.url)) 631 if (AreURLsInPageNavigation(existing_entry->url(), params.url))
622 return NAV_IN_PAGE; 632 return NAV_IN_PAGE;
623 633
624 if (!PageTransition::IsMainFrame(params.transition)) 634 if (!PageTransition::IsMainFrame(params.transition)) {
625 return NAV_AUTO_SUBFRAME; // All manual subframes would get new IDs and 635 // All manual subframes would get new IDs and were handled above, so we
626 // were handled above. 636 // know this is auto. Since the current page was found in the navigation
637 // entry list, we're guaranteed to have a last committed entry.
638 DCHECK(GetLastCommittedEntry());
639 return NAV_AUTO_SUBFRAME;
640 }
641
627 // Since we weeded out "new" navigations above, we know this is an existing 642 // Since we weeded out "new" navigations above, we know this is an existing
628 // navigation. 643 // (back/forward) navigation.
629 return NAV_EXISTING_PAGE; 644 return NAV_EXISTING_PAGE;
630 } 645 }
631 646
632 void NavigationController::RendererDidNavigateToNewPage( 647 void NavigationController::RendererDidNavigateToNewPage(
633 const ViewHostMsg_FrameNavigate_Params& params) { 648 const ViewHostMsg_FrameNavigate_Params& params) {
634 NavigationEntry* new_entry; 649 NavigationEntry* new_entry;
635 if (pending_entry_) { 650 if (pending_entry_) {
636 // TODO(brettw) this assumes that the pending entry is appropriate for the 651 // TODO(brettw) this assumes that the pending entry is appropriate for the
637 // new page that was just loaded. I don't think this is necessarily the 652 // new page that was just loaded. I don't think this is necessarily the
638 // case! We should have some more tracking to know for sure. This goes along 653 // case! We should have some more tracking to know for sure. This goes along
(...skipping 17 matching lines...) Expand all
656 671
657 InsertEntry(new_entry); 672 InsertEntry(new_entry);
658 } 673 }
659 674
660 void NavigationController::RendererDidNavigateToExistingPage( 675 void NavigationController::RendererDidNavigateToExistingPage(
661 const ViewHostMsg_FrameNavigate_Params& params) { 676 const ViewHostMsg_FrameNavigate_Params& params) {
662 // We should only get here for main frame navigations. 677 // We should only get here for main frame navigations.
663 DCHECK(PageTransition::IsMainFrame(params.transition)); 678 DCHECK(PageTransition::IsMainFrame(params.transition));
664 679
665 // This is a back/forward navigation. The existing page for the ID is 680 // This is a back/forward navigation. The existing page for the ID is
666 // guaranteed to exist, and we just need to update it with new information 681 // guaranteed to exist by ClassifyNavigation, and we just need to update it
667 // from the renderer. 682 // with new information from the renderer.
668 int entry_index = GetEntryIndexWithPageID( 683 int entry_index = GetEntryIndexWithPageID(
669 active_contents_->type(), 684 active_contents_->type(),
670 active_contents_->GetSiteInstance(), 685 active_contents_->GetSiteInstance(),
671 params.page_id); 686 params.page_id);
672 DCHECK(entry_index >= 0 && 687 DCHECK(entry_index >= 0 &&
673 entry_index < static_cast<int>(entries_.size())); 688 entry_index < static_cast<int>(entries_.size()));
674 NavigationEntry* entry = entries_[entry_index].get(); 689 NavigationEntry* entry = entries_[entry_index].get();
675 690
676 // The URL may have changed due to redirects. The site instance will normally 691 // The URL may have changed due to redirects. The site instance will normally
677 // be the same except during session restore, when no site instance will be 692 // be the same except during session restore, when no site instance will be
(...skipping 13 matching lines...) Expand all
691 DiscardPendingEntryInternal(); 706 DiscardPendingEntryInternal();
692 707
693 int old_committed_entry_index = last_committed_entry_index_; 708 int old_committed_entry_index = last_committed_entry_index_;
694 last_committed_entry_index_ = entry_index; 709 last_committed_entry_index_ = entry_index;
695 IndexOfActiveEntryChanged(old_committed_entry_index); 710 IndexOfActiveEntryChanged(old_committed_entry_index);
696 } 711 }
697 712
698 void NavigationController::RendererDidNavigateToSamePage( 713 void NavigationController::RendererDidNavigateToSamePage(
699 const ViewHostMsg_FrameNavigate_Params& params) { 714 const ViewHostMsg_FrameNavigate_Params& params) {
700 // This mode implies we have a pending entry that's the same as an existing 715 // This mode implies we have a pending entry that's the same as an existing
701 // entry for this page ID. All we need to do is update the existing entry. 716 // entry for this page ID. This entry is guaranteed to exist by
717 // ClassifyNavigation. All we need to do is update the existing entry.
702 NavigationEntry* existing_entry = GetEntryWithPageID( 718 NavigationEntry* existing_entry = GetEntryWithPageID(
703 active_contents_->type(), 719 active_contents_->type(),
704 active_contents_->GetSiteInstance(), 720 active_contents_->GetSiteInstance(),
705 params.page_id); 721 params.page_id);
706 722
707 // We assign the entry's unique ID to be that of the new one. Since this is 723 // We assign the entry's unique ID to be that of the new one. Since this is
708 // always the result of a user action, we want to dismiss infobars, etc. like 724 // always the result of a user action, we want to dismiss infobars, etc. like
709 // a regular user-initiated navigation. 725 // a regular user-initiated navigation.
710 existing_entry->set_unique_id(pending_entry_->unique_id()); 726 existing_entry->set_unique_id(pending_entry_->unique_id());
711 727
(...skipping 18 matching lines...) Expand all
730 new_entry->set_url(params.url); 746 new_entry->set_url(params.url);
731 InsertEntry(new_entry); 747 InsertEntry(new_entry);
732 } 748 }
733 749
734 void NavigationController::RendererDidNavigateNewSubframe( 750 void NavigationController::RendererDidNavigateNewSubframe(
735 const ViewHostMsg_FrameNavigate_Params& params) { 751 const ViewHostMsg_FrameNavigate_Params& params) {
736 // Manual subframe navigations just get the current entry cloned so the user 752 // Manual subframe navigations just get the current entry cloned so the user
737 // can go back or forward to it. The actual subframe information will be 753 // can go back or forward to it. The actual subframe information will be
738 // stored in the page state for each of those entries. This happens out of 754 // stored in the page state for each of those entries. This happens out of
739 // band with the actual navigations. 755 // band with the actual navigations.
740 DCHECK(GetLastCommittedEntry()); 756 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee "
757 << "that a last committed entry exists.";
741 NavigationEntry* new_entry = new NavigationEntry(*GetLastCommittedEntry()); 758 NavigationEntry* new_entry = new NavigationEntry(*GetLastCommittedEntry());
742 new_entry->set_page_id(params.page_id); 759 new_entry->set_page_id(params.page_id);
743 InsertEntry(new_entry); 760 InsertEntry(new_entry);
744 } 761 }
745 762
746 bool NavigationController::RendererDidNavigateAutoSubframe( 763 bool NavigationController::RendererDidNavigateAutoSubframe(
747 const ViewHostMsg_FrameNavigate_Params& params) { 764 const ViewHostMsg_FrameNavigate_Params& params) {
748 // We're guaranteed to have a previously committed entry, and we now need to 765 // We're guaranteed to have a previously committed entry, and we now need to
749 // handle navigation inside of a subframe in it without creating a new entry. 766 // handle navigation inside of a subframe in it without creating a new entry.
750 DCHECK(GetLastCommittedEntry()); 767 DCHECK(GetLastCommittedEntry());
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 int NavigationController::GetEntryIndexWithPageID( 1228 int NavigationController::GetEntryIndexWithPageID(
1212 TabContentsType type, SiteInstance* instance, int32 page_id) const { 1229 TabContentsType type, SiteInstance* instance, int32 page_id) const {
1213 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { 1230 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) {
1214 if ((entries_[i]->tab_type() == type) && 1231 if ((entries_[i]->tab_type() == type) &&
1215 (entries_[i]->site_instance() == instance) && 1232 (entries_[i]->site_instance() == instance) &&
1216 (entries_[i]->page_id() == page_id)) 1233 (entries_[i]->page_id() == page_id))
1217 return i; 1234 return i;
1218 } 1235 }
1219 return -1; 1236 return -1;
1220 } 1237 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/navigation_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698