Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "content/browser/web_contents/navigation_controller_impl.h" | 5 #include "content/browser/web_contents/navigation_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 return existing_url.ReplaceComponents(replacements) == | 130 return existing_url.ReplaceComponents(replacements) == |
| 131 new_url.ReplaceComponents(replacements); | 131 new_url.ReplaceComponents(replacements); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Determines whether or not we should be carrying over a user agent override | 134 // Determines whether or not we should be carrying over a user agent override |
| 135 // between two NavigationEntries. | 135 // between two NavigationEntries. |
| 136 bool ShouldKeepOverride(const NavigationEntry* last_entry) { | 136 bool ShouldKeepOverride(const NavigationEntry* last_entry) { |
| 137 return last_entry && last_entry->GetIsOverridingUserAgent(); | 137 return last_entry && last_entry->GetIsOverridingUserAgent(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Returns whether a screenshot should be taken because of the page transition. | |
|
Charlie Reis
2013/01/07 19:50:23
What's the intention here? You're returning no fo
| |
| 141 bool ShouldTakeScreenshotForTransition(PageTransition transition) { | |
| 142 // Never take a screenshot if the main page didn't navigate. | |
| 143 if (!PageTransitionIsMainFrame(transition)) | |
| 144 return false; | |
| 145 | |
| 146 int core = transition & PAGE_TRANSITION_CORE_MASK; | |
| 147 switch (core) { | |
| 148 case PAGE_TRANSITION_TYPED: | |
| 149 case PAGE_TRANSITION_AUTO_BOOKMARK: | |
| 150 case PAGE_TRANSITION_RELOAD: | |
| 151 return false; | |
| 152 } | |
| 153 | |
| 154 int qualifier = transition & PAGE_TRANSITION_QUALIFIER_MASK; | |
| 155 if (qualifier & (PAGE_TRANSITION_FORWARD_BACK | | |
| 156 PAGE_TRANSITION_FROM_ADDRESS_BAR)) { | |
| 157 return false; | |
| 158 } | |
| 159 | |
| 160 return true; | |
| 161 } | |
| 162 | |
| 140 } // namespace | 163 } // namespace |
| 141 | 164 |
| 142 // NavigationControllerImpl ---------------------------------------------------- | 165 // NavigationControllerImpl ---------------------------------------------------- |
| 143 | 166 |
| 144 const size_t kMaxEntryCountForTestingNotSet = -1; | 167 const size_t kMaxEntryCountForTestingNotSet = -1; |
| 145 | 168 |
| 146 // static | 169 // static |
| 147 size_t NavigationControllerImpl::max_entry_count_for_testing_ = | 170 size_t NavigationControllerImpl::max_entry_count_for_testing_ = |
| 148 kMaxEntryCountForTestingNotSet; | 171 kMaxEntryCountForTestingNotSet; |
| 149 | 172 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 } | 546 } |
| 524 | 547 |
| 525 if (!entry) { | 548 if (!entry) { |
| 526 LOG(ERROR) << "Invalid entry with unique id: " << unique_id; | 549 LOG(ERROR) << "Invalid entry with unique id: " << unique_id; |
| 527 return; | 550 return; |
| 528 } | 551 } |
| 529 | 552 |
| 530 std::vector<unsigned char> data; | 553 std::vector<unsigned char> data; |
| 531 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap->GetBitmap(), true, &data)) | 554 if (gfx::PNGCodec::EncodeBGRASkBitmap(bitmap->GetBitmap(), true, &data)) |
| 532 entry->SetScreenshotPNGData(data); | 555 entry->SetScreenshotPNGData(data); |
| 556 else | |
| 557 entry->SetScreenshotPNGData(std::vector<unsigned char>()); | |
| 533 } | 558 } |
| 534 | 559 |
| 535 bool NavigationControllerImpl::CanGoBack() const { | 560 bool NavigationControllerImpl::CanGoBack() const { |
| 536 return entries_.size() > 1 && GetCurrentEntryIndex() > 0; | 561 return entries_.size() > 1 && GetCurrentEntryIndex() > 0; |
| 537 } | 562 } |
| 538 | 563 |
| 539 bool NavigationControllerImpl::CanGoForward() const { | 564 bool NavigationControllerImpl::CanGoForward() const { |
| 540 int index = GetCurrentEntryIndex(); | 565 int index = GetCurrentEntryIndex(); |
| 541 return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); | 566 return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); |
| 542 } | 567 } |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 void NavigationControllerImpl::DocumentLoadedInFrame() { | 773 void NavigationControllerImpl::DocumentLoadedInFrame() { |
| 749 is_initial_navigation_ = false; | 774 is_initial_navigation_ = false; |
| 750 } | 775 } |
| 751 | 776 |
| 752 bool NavigationControllerImpl::RendererDidNavigate( | 777 bool NavigationControllerImpl::RendererDidNavigate( |
| 753 const ViewHostMsg_FrameNavigate_Params& params, | 778 const ViewHostMsg_FrameNavigate_Params& params, |
| 754 LoadCommittedDetails* details) { | 779 LoadCommittedDetails* details) { |
| 755 // When navigating away from the current page, take a screenshot of it in the | 780 // When navigating away from the current page, take a screenshot of it in the |
| 756 // current state so that it can be used during an overscroll-navigation | 781 // current state so that it can be used during an overscroll-navigation |
| 757 // gesture. | 782 // gesture. |
| 758 if (details->is_main_frame) | 783 if (ShouldTakeScreenshotForTransition(params.transition)) |
| 759 TakeScreenshot(); | 784 TakeScreenshot(); |
| 760 | 785 |
| 761 // Save the previous state before we clobber it. | 786 // Save the previous state before we clobber it. |
| 762 if (GetLastCommittedEntry()) { | 787 if (GetLastCommittedEntry()) { |
| 763 details->previous_url = GetLastCommittedEntry()->GetURL(); | 788 details->previous_url = GetLastCommittedEntry()->GetURL(); |
| 764 details->previous_entry_index = GetLastCommittedEntryIndex(); | 789 details->previous_entry_index = GetLastCommittedEntryIndex(); |
| 765 } else { | 790 } else { |
| 766 details->previous_url = GURL(); | 791 details->previous_url = GURL(); |
| 767 details->previous_entry_index = -1; | 792 details->previous_entry_index = -1; |
| 768 } | 793 } |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1541 } | 1566 } |
| 1542 | 1567 |
| 1543 // For session history navigations only the pending_entry_index_ is set. | 1568 // For session history navigations only the pending_entry_index_ is set. |
| 1544 if (!pending_entry_) { | 1569 if (!pending_entry_) { |
| 1545 DCHECK_NE(pending_entry_index_, -1); | 1570 DCHECK_NE(pending_entry_index_, -1); |
| 1546 pending_entry_ = entries_[pending_entry_index_].get(); | 1571 pending_entry_ = entries_[pending_entry_index_].get(); |
| 1547 } | 1572 } |
| 1548 | 1573 |
| 1549 if (!web_contents_->NavigateToPendingEntry(reload_type)) | 1574 if (!web_contents_->NavigateToPendingEntry(reload_type)) |
| 1550 DiscardNonCommittedEntries(); | 1575 DiscardNonCommittedEntries(); |
| 1576 else if (reload_type == NO_RELOAD) | |
|
Charlie Reis
2013/01/07 19:50:23
We should put a return after DiscardNonCommittedEn
sadrul
2013/01/08 00:16:29
The issue here is that, in some cases (especially
| |
| 1577 TakeScreenshot(); | |
| 1551 | 1578 |
| 1552 // If the entry is being restored and doesn't have a SiteInstance yet, fill | 1579 // If the entry is being restored and doesn't have a SiteInstance yet, fill |
| 1553 // it in now that we know. This allows us to find the entry when it commits. | 1580 // it in now that we know. This allows us to find the entry when it commits. |
| 1554 // This works for browser-initiated navigations. We handle renderer-initiated | 1581 // This works for browser-initiated navigations. We handle renderer-initiated |
| 1555 // navigations to restored entries in WebContentsImpl::OnGoToEntryAtOffset. | 1582 // navigations to restored entries in WebContentsImpl::OnGoToEntryAtOffset. |
| 1556 if (pending_entry_ && !pending_entry_->site_instance() && | 1583 if (pending_entry_ && !pending_entry_->site_instance() && |
| 1557 pending_entry_->restore_type() != NavigationEntryImpl::RESTORE_NONE) { | 1584 pending_entry_->restore_type() != NavigationEntryImpl::RESTORE_NONE) { |
| 1558 pending_entry_->set_site_instance(static_cast<SiteInstanceImpl*>( | 1585 pending_entry_->set_site_instance(static_cast<SiteInstanceImpl*>( |
| 1559 web_contents_->GetPendingSiteInstance())); | 1586 web_contents_->GetPendingSiteInstance())); |
| 1560 pending_entry_->set_restore_type(NavigationEntryImpl::RESTORE_NONE); | 1587 pending_entry_->set_restore_type(NavigationEntryImpl::RESTORE_NONE); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1676 } | 1703 } |
| 1677 } | 1704 } |
| 1678 } | 1705 } |
| 1679 | 1706 |
| 1680 void NavigationControllerImpl::SetGetTimestampCallbackForTest( | 1707 void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
| 1681 const base::Callback<base::Time()>& get_timestamp_callback) { | 1708 const base::Callback<base::Time()>& get_timestamp_callback) { |
| 1682 get_timestamp_callback_ = get_timestamp_callback; | 1709 get_timestamp_callback_ = get_timestamp_callback; |
| 1683 } | 1710 } |
| 1684 | 1711 |
| 1685 } // namespace content | 1712 } // namespace content |
| OLD | NEW |