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

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

Issue 2600233003: Discard SSL certificates for non-committed entries to save memory. (Closed)
Patch Set: Created 3 years, 12 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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 552
553 NavigationEntryImpl* NavigationControllerImpl::GetEntryAtOffset( 553 NavigationEntryImpl* NavigationControllerImpl::GetEntryAtOffset(
554 int offset) const { 554 int offset) const {
555 return GetEntryAtIndex(GetIndexForOffset(offset)); 555 return GetEntryAtIndex(GetIndexForOffset(offset));
556 } 556 }
557 557
558 int NavigationControllerImpl::GetIndexForOffset(int offset) const { 558 int NavigationControllerImpl::GetIndexForOffset(int offset) const {
559 return GetCurrentEntryIndex() + offset; 559 return GetCurrentEntryIndex() + offset;
560 } 560 }
561 561
562 void NavigationControllerImpl::DiscardUnusedSSLCerts() {
563 for (size_t i = 0; i < entries_.size(); ++i) {
564 if (static_cast<int>(i) != last_committed_entry_index_)
565 entries_[i]->GetSSL().certificate = nullptr;
566 }
567 }
568
562 void NavigationControllerImpl::TakeScreenshot() { 569 void NavigationControllerImpl::TakeScreenshot() {
563 screenshot_manager_->TakeScreenshot(); 570 screenshot_manager_->TakeScreenshot();
564 } 571 }
565 572
566 void NavigationControllerImpl::SetScreenshotManager( 573 void NavigationControllerImpl::SetScreenshotManager(
567 std::unique_ptr<NavigationEntryScreenshotManager> manager) { 574 std::unique_ptr<NavigationEntryScreenshotManager> manager) {
568 if (manager.get()) 575 if (manager.get())
569 screenshot_manager_ = std::move(manager); 576 screenshot_manager_ = std::move(manager);
570 else 577 else
571 screenshot_manager_.reset(new NavigationEntryScreenshotManager(this)); 578 screenshot_manager_.reset(new NavigationEntryScreenshotManager(this));
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 // is now likely canceled. If it is not canceled, we will treat it as a new 1272 // is now likely canceled. If it is not canceled, we will treat it as a new
1266 // navigation when it arrives, which is also ok. 1273 // navigation when it arrives, which is also ok.
1267 // 1274 //
1268 // Note that we need to use the "internal" version since we don't want to 1275 // Note that we need to use the "internal" version since we don't want to
1269 // actually change any other state, just kill the pointer. 1276 // actually change any other state, just kill the pointer.
1270 DiscardNonCommittedEntriesInternal(); 1277 DiscardNonCommittedEntriesInternal();
1271 1278
1272 // If a transient entry was removed, the indices might have changed, so we 1279 // If a transient entry was removed, the indices might have changed, so we
1273 // have to query the entry index again. 1280 // have to query the entry index again.
1274 last_committed_entry_index_ = GetIndexOfEntry(entry); 1281 last_committed_entry_index_ = GetIndexOfEntry(entry);
1282 DiscardUnusedSSLCerts();
1275 } 1283 }
1276 1284
1277 void NavigationControllerImpl::RendererDidNavigateToSamePage( 1285 void NavigationControllerImpl::RendererDidNavigateToSamePage(
1278 RenderFrameHostImpl* rfh, 1286 RenderFrameHostImpl* rfh,
1279 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 1287 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
1280 NavigationHandleImpl* handle) { 1288 NavigationHandleImpl* handle) {
1281 // This classification says that we have a pending entry that's the same as 1289 // This classification says that we have a pending entry that's the same as
1282 // the last committed entry. This entry is guaranteed to exist by 1290 // the last committed entry. This entry is guaranteed to exist by
1283 // ClassifyNavigation. All we need to do is update the existing entry. 1291 // ClassifyNavigation. All we need to do is update the existing entry.
1284 NavigationEntryImpl* existing_entry = GetLastCommittedEntry(); 1292 NavigationEntryImpl* existing_entry = GetLastCommittedEntry();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 dest_top_url.SchemeIsHTTPOrHTTPS() && 1398 dest_top_url.SchemeIsHTTPOrHTTPS() &&
1391 current_top_url.GetOrigin() != dest_top_url.GetOrigin()) { 1399 current_top_url.GetOrigin() != dest_top_url.GetOrigin()) {
1392 bad_message::ReceivedBadMessage(rfh->GetProcess(), 1400 bad_message::ReceivedBadMessage(rfh->GetProcess(),
1393 bad_message::NC_AUTO_SUBFRAME); 1401 bad_message::NC_AUTO_SUBFRAME);
1394 } 1402 }
1395 1403
1396 // We only need to discard the pending entry in this history navigation 1404 // We only need to discard the pending entry in this history navigation
1397 // case. For newly created subframes, there was no pending entry. 1405 // case. For newly created subframes, there was no pending entry.
1398 last_committed_entry_index_ = entry_index; 1406 last_committed_entry_index_ = entry_index;
1399 DiscardNonCommittedEntriesInternal(); 1407 DiscardNonCommittedEntriesInternal();
1408 DiscardUnusedSSLCerts();
1400 1409
1401 // History navigations should send a commit notification. 1410 // History navigations should send a commit notification.
1402 send_commit_notification = true; 1411 send_commit_notification = true;
1403 } 1412 }
1404 } 1413 }
1405 1414
1406 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 1415 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
1407 // This may be a "new auto" case where we add a new FrameNavigationEntry, or 1416 // This may be a "new auto" case where we add a new FrameNavigationEntry, or
1408 // it may be a "history auto" case where we update an existing one. 1417 // it may be a "history auto" case where we update an existing one.
1409 NavigationEntryImpl* last_committed = GetLastCommittedEntry(); 1418 NavigationEntryImpl* last_committed = GetLastCommittedEntry();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 // Ignore the source's current entry if merging with replacement. 1554 // Ignore the source's current entry if merging with replacement.
1546 // TODO(davidben): This should preserve entries forward of the current 1555 // TODO(davidben): This should preserve entries forward of the current
1547 // too. http://crbug.com/317872 1556 // too. http://crbug.com/317872
1548 if (replace_entry && max_source_index > 0) 1557 if (replace_entry && max_source_index > 0)
1549 max_source_index--; 1558 max_source_index--;
1550 1559
1551 InsertEntriesFrom(*source, max_source_index); 1560 InsertEntriesFrom(*source, max_source_index);
1552 1561
1553 // Adjust indices such that the last entry and pending are at the end now. 1562 // Adjust indices such that the last entry and pending are at the end now.
1554 last_committed_entry_index_ = GetEntryCount() - 1; 1563 last_committed_entry_index_ = GetEntryCount() - 1;
1564 DiscardUnusedSSLCerts();
1555 1565
1556 delegate_->SetHistoryOffsetAndLength(last_committed_entry_index_, 1566 delegate_->SetHistoryOffsetAndLength(last_committed_entry_index_,
1557 GetEntryCount()); 1567 GetEntryCount());
1558 } 1568 }
1559 1569
1560 bool NavigationControllerImpl::CanPruneAllButLastCommitted() { 1570 bool NavigationControllerImpl::CanPruneAllButLastCommitted() {
1561 // If there is no last committed entry, we cannot prune. Even if there is a 1571 // If there is no last committed entry, we cannot prune. Even if there is a
1562 // pending entry, it may not commit, leaving this WebContents blank, despite 1572 // pending entry, it may not commit, leaving this WebContents blank, despite
1563 // possibly giving it new entries via CopyStateFromAndPrune. 1573 // possibly giving it new entries via CopyStateFromAndPrune.
1564 if (last_committed_entry_index_ == -1) 1574 if (last_committed_entry_index_ == -1)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 current_size--; 1765 current_size--;
1756 } 1766 }
1757 if (num_pruned > 0) // Only notify if we did prune something. 1767 if (num_pruned > 0) // Only notify if we did prune something.
1758 NotifyPrunedEntries(this, false, num_pruned); 1768 NotifyPrunedEntries(this, false, num_pruned);
1759 } 1769 }
1760 1770
1761 PruneOldestEntryIfFull(); 1771 PruneOldestEntryIfFull();
1762 1772
1763 entries_.push_back(std::move(entry)); 1773 entries_.push_back(std::move(entry));
1764 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; 1774 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1;
1775 DiscardUnusedSSLCerts();
1765 } 1776 }
1766 1777
1767 void NavigationControllerImpl::PruneOldestEntryIfFull() { 1778 void NavigationControllerImpl::PruneOldestEntryIfFull() {
1768 if (entries_.size() >= max_entry_count()) { 1779 if (entries_.size() >= max_entry_count()) {
1769 DCHECK_EQ(max_entry_count(), entries_.size()); 1780 DCHECK_EQ(max_entry_count(), entries_.size());
1770 DCHECK_GT(last_committed_entry_index_, 0); 1781 DCHECK_GT(last_committed_entry_index_, 0);
1771 RemoveEntryAtIndex(0); 1782 RemoveEntryAtIndex(0);
1772 NotifyPrunedEntries(this, true, 1); 1783 NotifyPrunedEntries(this, true, 1);
1773 } 1784 }
1774 } 1785 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 Source<NavigationController>(this), 2073 Source<NavigationController>(this),
2063 Details<EntryChangedDetails>(&det)); 2074 Details<EntryChangedDetails>(&det));
2064 } 2075 }
2065 2076
2066 void NavigationControllerImpl::FinishRestore(int selected_index, 2077 void NavigationControllerImpl::FinishRestore(int selected_index,
2067 RestoreType type) { 2078 RestoreType type) {
2068 DCHECK(selected_index >= 0 && selected_index < GetEntryCount()); 2079 DCHECK(selected_index >= 0 && selected_index < GetEntryCount());
2069 ConfigureEntriesForRestore(&entries_, type); 2080 ConfigureEntriesForRestore(&entries_, type);
2070 2081
2071 last_committed_entry_index_ = selected_index; 2082 last_committed_entry_index_ = selected_index;
2083 DiscardUnusedSSLCerts();
2072 } 2084 }
2073 2085
2074 void NavigationControllerImpl::DiscardNonCommittedEntriesInternal() { 2086 void NavigationControllerImpl::DiscardNonCommittedEntriesInternal() {
2075 DiscardPendingEntry(false); 2087 DiscardPendingEntry(false);
2076 DiscardTransientEntry(); 2088 DiscardTransientEntry();
2077 } 2089 }
2078 2090
2079 void NavigationControllerImpl::DiscardPendingEntry(bool was_failure) { 2091 void NavigationControllerImpl::DiscardPendingEntry(bool was_failure) {
2080 // It is not safe to call DiscardPendingEntry while NavigateToEntry is in 2092 // It is not safe to call DiscardPendingEntry while NavigateToEntry is in
2081 // progress, since this will cause a use-after-free. (We only allow this 2093 // progress, since this will cause a use-after-free. (We only allow this
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 } 2165 }
2154 } 2166 }
2155 } 2167 }
2156 2168
2157 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 2169 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
2158 const base::Callback<base::Time()>& get_timestamp_callback) { 2170 const base::Callback<base::Time()>& get_timestamp_callback) {
2159 get_timestamp_callback_ = get_timestamp_callback; 2171 get_timestamp_callback_ = get_timestamp_callback;
2160 } 2172 }
2161 2173
2162 } // namespace content 2174 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.h ('k') | content/public/browser/ssl_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698