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

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

Issue 16162003: Introduce content::PageState (again). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 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 | Annotate | Revision Log
OLDNEW
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/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" // Temporary 9 #include "base/string_number_conversions.h" // Temporary
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 22 matching lines...) Expand all
33 #include "content/public/browser/storage_partition.h" 33 #include "content/public/browser/storage_partition.h"
34 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
35 #include "content/public/browser/web_contents_delegate.h" 35 #include "content/public/browser/web_contents_delegate.h"
36 #include "content/public/common/content_client.h" 36 #include "content/public/common/content_client.h"
37 #include "content/public/common/content_constants.h" 37 #include "content/public/common/content_constants.h"
38 #include "content/public/common/url_constants.h" 38 #include "content/public/common/url_constants.h"
39 #include "net/base/escape.h" 39 #include "net/base/escape.h"
40 #include "net/base/mime_util.h" 40 #include "net/base/mime_util.h"
41 #include "net/base/net_util.h" 41 #include "net/base/net_util.h"
42 #include "skia/ext/platform_canvas.h" 42 #include "skia/ext/platform_canvas.h"
43 #include "webkit/glue/glue_serialize.h"
44 43
45 namespace content { 44 namespace content {
46 namespace { 45 namespace {
47 46
48 const int kInvalidateAll = 0xFFFFFFFF; 47 const int kInvalidateAll = 0xFFFFFFFF;
49 48
50 // Invoked when entries have been pruned, or removed. For example, if the 49 // Invoked when entries have been pruned, or removed. For example, if the
51 // current entries are [google, digg, yahoo], with the current entry google, 50 // current entries are [google, digg, yahoo], with the current entry google,
52 // and the user types in cnet, then digg and yahoo are pruned. 51 // and the user types in cnet, then digg and yahoo are pruned.
53 void NotifyPrunedEntries(NavigationControllerImpl* nav_controller, 52 void NotifyPrunedEntries(NavigationControllerImpl* nav_controller,
54 bool from_front, 53 bool from_front,
55 int count) { 54 int count) {
56 PrunedDetails details; 55 PrunedDetails details;
57 details.from_front = from_front; 56 details.from_front = from_front;
58 details.count = count; 57 details.count = count;
59 NotificationService::current()->Notify( 58 NotificationService::current()->Notify(
60 NOTIFICATION_NAV_LIST_PRUNED, 59 NOTIFICATION_NAV_LIST_PRUNED,
61 Source<NavigationController>(nav_controller), 60 Source<NavigationController>(nav_controller),
62 Details<PrunedDetails>(&details)); 61 Details<PrunedDetails>(&details));
63 } 62 }
64 63
65 // Ensure the given NavigationEntry has a valid state, so that WebKit does not 64 // Ensure the given NavigationEntry has a valid state, so that WebKit does not
66 // get confused if we navigate back to it. 65 // get confused if we navigate back to it.
67 // 66 //
68 // An empty state is treated as a new navigation by WebKit, which would mean 67 // An empty state is treated as a new navigation by WebKit, which would mean
69 // losing the navigation entries and generating a new navigation entry after 68 // losing the navigation entries and generating a new navigation entry after
70 // this one. We don't want that. To avoid this we create a valid state which 69 // this one. We don't want that. To avoid this we create a valid state which
71 // WebKit will not treat as a new navigation. 70 // WebKit will not treat as a new navigation.
72 void SetContentStateIfEmpty(NavigationEntryImpl* entry) { 71 void SetPageStateIfEmpty(NavigationEntryImpl* entry) {
73 if (entry->GetContentState().empty()) { 72 if (!entry->GetPageState().IsValid())
74 entry->SetContentState( 73 entry->SetPageState(PageState::CreateFromURL(entry->GetURL()));
75 webkit_glue::CreateHistoryStateForURL(entry->GetURL()));
76 }
77 } 74 }
78 75
79 NavigationEntryImpl::RestoreType ControllerRestoreTypeToEntryType( 76 NavigationEntryImpl::RestoreType ControllerRestoreTypeToEntryType(
80 NavigationController::RestoreType type) { 77 NavigationController::RestoreType type) {
81 switch (type) { 78 switch (type) {
82 case NavigationController::RESTORE_CURRENT_SESSION: 79 case NavigationController::RESTORE_CURRENT_SESSION:
83 return NavigationEntryImpl::RESTORE_CURRENT_SESSION; 80 return NavigationEntryImpl::RESTORE_CURRENT_SESSION;
84 case NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY: 81 case NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY:
85 return NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY; 82 return NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY;
86 case NavigationController::RESTORE_LAST_SESSION_CRASHED: 83 case NavigationController::RESTORE_LAST_SESSION_CRASHED:
87 return NavigationEntryImpl::RESTORE_LAST_SESSION_CRASHED; 84 return NavigationEntryImpl::RESTORE_LAST_SESSION_CRASHED;
88 } 85 }
89 NOTREACHED(); 86 NOTREACHED();
90 return NavigationEntryImpl::RESTORE_CURRENT_SESSION; 87 return NavigationEntryImpl::RESTORE_CURRENT_SESSION;
91 } 88 }
92 89
93 // Configure all the NavigationEntries in entries for restore. This resets 90 // Configure all the NavigationEntries in entries for restore. This resets
94 // the transition type to reload and makes sure the content state isn't empty. 91 // the transition type to reload and makes sure the content state isn't empty.
95 void ConfigureEntriesForRestore( 92 void ConfigureEntriesForRestore(
96 std::vector<linked_ptr<NavigationEntryImpl> >* entries, 93 std::vector<linked_ptr<NavigationEntryImpl> >* entries,
97 NavigationController::RestoreType type) { 94 NavigationController::RestoreType type) {
98 for (size_t i = 0; i < entries->size(); ++i) { 95 for (size_t i = 0; i < entries->size(); ++i) {
99 // Use a transition type of reload so that we don't incorrectly increase 96 // Use a transition type of reload so that we don't incorrectly increase
100 // the typed count. 97 // the typed count.
101 (*entries)[i]->SetTransitionType(PAGE_TRANSITION_RELOAD); 98 (*entries)[i]->SetTransitionType(PAGE_TRANSITION_RELOAD);
102 (*entries)[i]->set_restore_type(ControllerRestoreTypeToEntryType(type)); 99 (*entries)[i]->set_restore_type(ControllerRestoreTypeToEntryType(type));
103 // NOTE(darin): This code is only needed for backwards compat. 100 // NOTE(darin): This code is only needed for backwards compat.
104 SetContentStateIfEmpty((*entries)[i].get()); 101 SetPageStateIfEmpty((*entries)[i].get());
105 } 102 }
106 } 103 }
107 104
108 // See NavigationController::IsURLInPageNavigation for how this works and why. 105 // See NavigationController::IsURLInPageNavigation for how this works and why.
109 bool AreURLsInPageNavigation(const GURL& existing_url, 106 bool AreURLsInPageNavigation(const GURL& existing_url,
110 const GURL& new_url, 107 const GURL& new_url,
111 bool renderer_says_in_page) { 108 bool renderer_says_in_page) {
112 if (existing_url == new_url) 109 if (existing_url == new_url)
113 return renderer_says_in_page; 110 return renderer_says_in_page;
114 111
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 time_smoother_.GetSmoothedTime(get_timestamp_callback_.Run()); 759 time_smoother_.GetSmoothedTime(get_timestamp_callback_.Run());
763 DVLOG(1) << "Navigation finished at (smoothed) timestamp " 760 DVLOG(1) << "Navigation finished at (smoothed) timestamp "
764 << timestamp.ToInternalValue(); 761 << timestamp.ToInternalValue();
765 762
766 // We should not have a pending entry anymore. Clear it again in case any 763 // We should not have a pending entry anymore. Clear it again in case any
767 // error cases above forgot to do so. 764 // error cases above forgot to do so.
768 DiscardNonCommittedEntriesInternal(); 765 DiscardNonCommittedEntriesInternal();
769 766
770 // All committed entries should have nonempty content state so WebKit doesn't 767 // All committed entries should have nonempty content state so WebKit doesn't
771 // get confused when we go back to them (see the function for details). 768 // get confused when we go back to them (see the function for details).
772 DCHECK(!params.content_state.empty()); 769 DCHECK(params.page_state.IsValid());
773 NavigationEntryImpl* active_entry = 770 NavigationEntryImpl* active_entry =
774 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry()); 771 NavigationEntryImpl::FromNavigationEntry(GetLastCommittedEntry());
775 active_entry->SetTimestamp(timestamp); 772 active_entry->SetTimestamp(timestamp);
776 active_entry->SetContentState(params.content_state); 773 active_entry->SetPageState(params.page_state);
777 // No longer needed since content state will hold the post data if any. 774 // No longer needed since content state will hold the post data if any.
778 active_entry->SetBrowserInitiatedPostData(NULL); 775 active_entry->SetBrowserInitiatedPostData(NULL);
779 776
780 // Once committed, we do not need to track if the entry was initiated by 777 // Once committed, we do not need to track if the entry was initiated by
781 // the renderer. 778 // the renderer.
782 active_entry->set_is_renderer_initiated(false); 779 active_entry->set_is_renderer_initiated(false);
783 780
784 // Once committed, we no longer need to track whether the session history was 781 // Once committed, we no longer need to track whether the session history was
785 // cleared. Navigating to this entry again shouldn't clear it again. 782 // cleared. Navigating to this entry again shouldn't clear it again.
786 active_entry->set_should_clear_history_list(false); 783 active_entry->set_should_clear_history_list(false);
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 } 1674 }
1678 } 1675 }
1679 } 1676 }
1680 1677
1681 void NavigationControllerImpl::SetGetTimestampCallbackForTest( 1678 void NavigationControllerImpl::SetGetTimestampCallbackForTest(
1682 const base::Callback<base::Time()>& get_timestamp_callback) { 1679 const base::Callback<base::Time()>& get_timestamp_callback) {
1683 get_timestamp_callback_ = get_timestamp_callback; 1680 get_timestamp_callback_ = get_timestamp_callback;
1684 } 1681 }
1685 1682
1686 } // namespace content 1683 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698