diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-18 23:03:00 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-18 23:03:00 +0000 |
commit | 3cc72b1caa55ca87811d8fab1ac9d55f05c2d496 (patch) | |
tree | 4379348afc5100d4188fb03650aa2f8013f5f254 /chrome/renderer | |
parent | 330a9d04c938c3e79c30faade3713a1378b9bdeb (diff) | |
download | chromium_src-3cc72b1caa55ca87811d8fab1ac9d55f05c2d496.zip chromium_src-3cc72b1caa55ca87811d8fab1ac9d55f05c2d496.tar.gz chromium_src-3cc72b1caa55ca87811d8fab1ac9d55f05c2d496.tar.bz2 |
Send session history offset and length parameters in the Navigate message to
keep the renderer's notion of those values properly synchronized with the
NavigationController.
R=brettw
BUG=18062
TEST=see session_history_uitest.cc
Review URL: http://codereview.chromium.org/1090002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/navigation_state.h | 18 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 60 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 7 |
3 files changed, 42 insertions, 43 deletions
diff --git a/chrome/renderer/navigation_state.h b/chrome/renderer/navigation_state.h index d17b542..36a8441 100644 --- a/chrome/renderer/navigation_state.h +++ b/chrome/renderer/navigation_state.h @@ -33,15 +33,18 @@ class NavigationState : public WebKit::WebDataSource::ExtraData { static NavigationState* CreateBrowserInitiated( int32 pending_page_id, + int pending_history_list_offset, PageTransition::Type transition_type, base::Time request_time) { return new NavigationState(transition_type, request_time, false, - pending_page_id); + pending_page_id, + pending_history_list_offset); } static NavigationState* CreateContentInitiated() { // We assume navigations initiated by content are link clicks. - return new NavigationState(PageTransition::LINK, base::Time(), true, -1); + return new NavigationState(PageTransition::LINK, base::Time(), true, -1, + -1); } static NavigationState* FromDataSource(WebKit::WebDataSource* ds) { @@ -58,6 +61,12 @@ class NavigationState : public WebKit::WebDataSource::ExtraData { // Contains the page_id for this navigation or -1 if there is none yet. int32 pending_page_id() const { return pending_page_id_; } + // If pending_page_id() is not -1, then this contains the corresponding + // offset of the page in the back/forward history list. + int pending_history_list_offset() const { + return pending_history_list_offset_; + } + // Contains the transition type that the browser specified when it // initiated the load. PageTransition::Type transition_type() const { return transition_type_; } @@ -219,7 +228,8 @@ class NavigationState : public WebKit::WebDataSource::ExtraData { NavigationState(PageTransition::Type transition_type, const base::Time& request_time, bool is_content_initiated, - int32 pending_page_id) + int32 pending_page_id, + int pending_history_list_offset) : transition_type_(transition_type), load_type_(UNDEFINED_LOAD), request_time_(request_time), @@ -227,6 +237,7 @@ class NavigationState : public WebKit::WebDataSource::ExtraData { request_committed_(false), is_content_initiated_(is_content_initiated), pending_page_id_(pending_page_id), + pending_history_list_offset_(pending_history_list_offset), postpone_loading_data_(false), cache_policy_override_set_(false), cache_policy_override_(WebKit::WebURLRequest::UseProtocolCachePolicy), @@ -248,6 +259,7 @@ class NavigationState : public WebKit::WebDataSource::ExtraData { bool request_committed_; bool is_content_initiated_; int32 pending_page_id_; + int pending_history_list_offset_; GURL searchable_form_url_; std::string searchable_form_encoding_; scoped_ptr<webkit_glue::PasswordForm> password_form_data_; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 818cbd0..d057a7c 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -306,8 +306,8 @@ RenderView::RenderView(RenderThreadBase* render_thread, devtools_agent_(NULL), devtools_client_(NULL), file_chooser_completion_(NULL), - history_back_list_count_(0), - history_forward_list_count_(0), + history_list_offset_(-1), + history_list_length_(0), has_unload_listener_(false), decrement_shared_popup_at_destruction_(false), autofill_query_id_(0), @@ -559,8 +559,6 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) - IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount, - OnUpdateBackForwardListCount) IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, OnGetAllSavableResourceLinksForCurrentPage) IPC_MESSAGE_HANDLER( @@ -850,6 +848,9 @@ void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { if (!webview()) return; + history_list_offset_ = params.current_history_list_offset; + history_list_length_ = params.current_history_list_length; + if (devtools_agent_.get()) devtools_agent_->OnNavigate(); @@ -878,7 +879,10 @@ void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { // initiated any load resulting from JS execution. if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { NavigationState* state = NavigationState::CreateBrowserInitiated( - params.page_id, params.transition, params.request_time); + params.page_id, + params.pending_history_list_offset, + params.transition, + params.request_time); if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) { // We're doing a load of a page that was restored from the last session. // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) @@ -958,7 +962,10 @@ void RenderView::OnLoadAlternateHTMLText(const std::string& html, return; pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( - new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now())); + new_navigation ? -1 : page_id_, + history_list_offset_, + PageTransition::LINK, + Time::Now())); pending_navigation_state_->set_security_info(security_info); webview()->mainFrame()->loadHTMLString( @@ -1944,36 +1951,15 @@ void RenderView::focusPrevious() { } void RenderView::navigateBackForwardSoon(int offset) { - history_back_list_count_ += offset; - history_forward_list_count_ -= offset; - Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); } int RenderView::historyBackListCount() { - return history_back_list_count_; + return history_list_offset_ < 0 ? 0 : history_list_offset_; } int RenderView::historyForwardListCount() { - return history_forward_list_count_; -} - -void RenderView::didAddHistoryItem() { - // We don't want to update the history length for the start page - // navigation. - WebFrame* main_frame = webview()->mainFrame(); - DCHECK(main_frame != NULL); - - WebDataSource* ds = main_frame->dataSource(); - DCHECK(ds != NULL); - - NavigationState* navigation_state = NavigationState::FromDataSource(ds); - DCHECK(navigation_state); - if (navigation_state->transition_type() == PageTransition::START_PAGE) - return; - - history_back_list_count_++; - history_forward_list_count_ = 0; + return history_list_length_ - historyBackListCount() - 1; } void RenderView::didUpdateInspectorSettings() { @@ -2512,6 +2498,7 @@ void RenderView::didFailProvisionalLoad(WebFrame* frame, if (!navigation_state->is_content_initiated()) { pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( navigation_state->pending_page_id(), + navigation_state->pending_history_list_offset(), navigation_state->transition_type(), navigation_state->request_time())); } @@ -2567,6 +2554,13 @@ void RenderView::didCommitProvisionalLoad(WebFrame* frame, // We bump our Page ID to correspond with the new session history entry. page_id_ = next_page_id_++; + // Advance our offset in session history, applying the length limit. There + // is now no forward history. + history_list_offset_++; + if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries) + history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1; + history_list_length_ = history_list_offset_ + 1; + MessageLoop::current()->PostDelayedTask(FROM_HERE, method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_, true), @@ -2588,6 +2582,8 @@ void RenderView::didCommitProvisionalLoad(WebFrame* frame, // This is a successful session history navigation! UpdateSessionHistory(frame); page_id_ = navigation_state->pending_page_id(); + + history_list_offset_ = navigation_state->pending_history_list_offset(); } } @@ -3724,12 +3720,6 @@ void RenderView::OnUpdateBrowserWindowId(int window_id) { browser_window_id_ = window_id; } -void RenderView::OnUpdateBackForwardListCount(int back_list_count, - int forward_list_count) { - history_back_list_count_ = back_list_count; - history_forward_list_count_ = forward_list_count; -} - void RenderView::OnGetAccessibilityInfo( const webkit_glue::WebAccessibility::InParams& in_params, webkit_glue::WebAccessibility::OutParams* out_params) { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 8f7ec80..b70783c 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -263,7 +263,6 @@ class RenderView : public RenderWidget, virtual void navigateBackForwardSoon(int offset); virtual int historyBackListCount(); virtual int historyForwardListCount(); - virtual void didAddHistoryItem(); virtual void focusAccessibilityObject( const WebKit::WebAccessibilityObject& acc_obj); virtual void didChangeAccessibilityObjectState( @@ -709,8 +708,6 @@ class RenderView : public RenderWidget, void OnExecuteCode(const ViewMsg_ExecuteCode_Params& params); void ExecuteCodeImpl(WebKit::WebFrame* frame, const ViewMsg_ExecuteCode_Params& params); - void OnUpdateBackForwardListCount(int back_list_count, - int forward_list_count); void OnGetAccessibilityInfo( const webkit_glue::WebAccessibility::InParams& in_params, webkit_glue::WebAccessibility::OutParams* out_params); @@ -1010,8 +1007,8 @@ class RenderView : public RenderWidget, // choosing operation is underway. WebKit::WebFileChooserCompletion* file_chooser_completion_; - int history_back_list_count_; - int history_forward_list_count_; + int history_list_offset_; + int history_list_length_; // True if the page has any frame-level unload or beforeunload listeners. bool has_unload_listener_; |