navigation_state.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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
3// found in the LICENSE file.
4
5#ifndef CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
6#define CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
7
8#include <string>
9
10#include "content/common/content_export.h"
11#include "ui/base/page_transition_types.h"
12
13namespace content {
14
15// NavigationState is the portion of DocumentState that is affected by
16// in-document navigation.
17// TODO(simonjam): Move this to HistoryItem's ExtraData.
18class CONTENT_EXPORT NavigationState {
19 public:
20  virtual ~NavigationState();
21
22  static NavigationState* CreateBrowserInitiated(
23      int32 pending_page_id,
24      int pending_history_list_offset,
25      bool history_list_was_cleared,
26      ui::PageTransition transition_type) {
27    return new NavigationState(transition_type,
28                               false,
29                               pending_page_id,
30                               pending_history_list_offset,
31                               history_list_was_cleared);
32  }
33
34  static NavigationState* CreateContentInitiated() {
35    return new NavigationState(
36        ui::PAGE_TRANSITION_LINK, true, -1, -1, false);
37  }
38
39  // Contains the page_id for this navigation or -1 if there is none yet.
40  int32 pending_page_id() const { return pending_page_id_; }
41
42  // If pending_page_id() is not -1, then this contains the corresponding
43  // offset of the page in the back/forward history list.
44  int pending_history_list_offset() const {
45    return pending_history_list_offset_;
46  }
47
48  // If pending_page_id() is not -1, then this returns true if the session
49  // history was cleared during this navigation.
50  bool history_list_was_cleared() const {
51    return history_list_was_cleared_;
52  }
53
54  // If is_content_initiated() is false, whether this navigation should replace
55  // the current entry in the back/forward history list. Otherwise, use
56  // replacesCurrentHistoryItem() on the WebDataSource.
57  //
58  // TODO(davidben): It would be good to unify these and have only one source
59  // for the two cases. We can plumb this through WebFrame::loadRequest to set
60  // lockBackForwardList on the FrameLoadRequest. However, this breaks process
61  // swaps because FrameLoader::loadWithNavigationAction treats loads before a
62  // FrameLoader has committedFirstRealDocumentLoad as a replacement. (Added for
63  // http://crbug.com/178380).
64  bool should_replace_current_entry() const {
65    return should_replace_current_entry_;
66  }
67  void set_should_replace_current_entry(bool value) {
68    should_replace_current_entry_ = value;
69  }
70
71  // Contains the transition type that the browser specified when it
72  // initiated the load.
73  ui::PageTransition transition_type() const { return transition_type_; }
74  void set_transition_type(ui::PageTransition type) {
75    transition_type_ = type;
76  }
77
78  // True if we have already processed the "DidCommitLoad" event for this
79  // request.  Used by session history.
80  bool request_committed() const { return request_committed_; }
81  void set_request_committed(bool value) { request_committed_ = value; }
82
83  // True if this navigation was not initiated via WebFrame::LoadRequest.
84  bool is_content_initiated() const { return is_content_initiated_; }
85
86  // True iff the frame's navigation was within the same page.
87  void set_was_within_same_page(bool value) { was_within_same_page_ = value; }
88  bool was_within_same_page() const { return was_within_same_page_; }
89
90  // transferred_request_child_id and transferred_request_request_id identify
91  // a request that has been created before the navigation is being transferred
92  // to a new renderer. This is used to recycle the old request once the new
93  // renderer tries to pick up the navigation of the old one.
94  void set_transferred_request_child_id(int value) {
95    transferred_request_child_id_ = value;
96  }
97  int transferred_request_child_id() const {
98    return transferred_request_child_id_;
99  }
100  void set_transferred_request_request_id(int value) {
101    transferred_request_request_id_ = value;
102  }
103  int transferred_request_request_id() const {
104    return transferred_request_request_id_;
105  }
106  void set_allow_download(bool value) {
107    allow_download_ = value;
108  }
109  bool allow_download() const {
110    return allow_download_;
111  }
112
113  void set_extra_headers(const std::string& extra_headers) {
114    extra_headers_ = extra_headers;
115  }
116  const std::string& extra_headers() { return extra_headers_; }
117
118 private:
119  NavigationState(ui::PageTransition transition_type,
120                  bool is_content_initiated,
121                  int32 pending_page_id,
122                  int pending_history_list_offset,
123                  bool history_list_was_cleared);
124
125  ui::PageTransition transition_type_;
126  bool request_committed_;
127  bool is_content_initiated_;
128  int32 pending_page_id_;
129  int pending_history_list_offset_;
130  bool history_list_was_cleared_;
131  bool should_replace_current_entry_;
132
133  bool was_within_same_page_;
134  int transferred_request_child_id_;
135  int transferred_request_request_id_;
136  bool allow_download_;
137  std::string extra_headers_;
138
139  DISALLOW_COPY_AND_ASSIGN(NavigationState);
140};
141
142}  // namespace content
143
144#endif  // CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
145