• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "content/public/common/page_transition_types.h"
12 
13 namespace 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.
18 class CONTENT_EXPORT NavigationState {
19  public:
20   virtual ~NavigationState();
21 
CreateBrowserInitiated(int32 pending_page_id,int pending_history_list_offset,bool history_list_was_cleared,content::PageTransition transition_type)22   static NavigationState* CreateBrowserInitiated(
23       int32 pending_page_id,
24       int pending_history_list_offset,
25       bool history_list_was_cleared,
26       content::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 
CreateContentInitiated()34   static NavigationState* CreateContentInitiated() {
35     return new NavigationState(
36         content::PAGE_TRANSITION_LINK, true, -1, -1, false);
37   }
38 
39   // Contains the page_id for this navigation or -1 if there is none yet.
pending_page_id()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.
pending_history_list_offset()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.
history_list_was_cleared()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).
should_replace_current_entry()64   bool should_replace_current_entry() const {
65     return should_replace_current_entry_;
66   }
set_should_replace_current_entry(bool value)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.
transition_type()73   content::PageTransition transition_type() const { return transition_type_; }
set_transition_type(content::PageTransition type)74   void set_transition_type(content::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.
request_committed()80   bool request_committed() const { return request_committed_; }
set_request_committed(bool value)81   void set_request_committed(bool value) { request_committed_ = value; }
82 
83   // True if this navigation was not initiated via WebFrame::LoadRequest.
is_content_initiated()84   bool is_content_initiated() const { return is_content_initiated_; }
85 
86   // True iff the frame's navigation was within the same page.
set_was_within_same_page(bool value)87   void set_was_within_same_page(bool value) { was_within_same_page_ = value; }
was_within_same_page()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.
set_transferred_request_child_id(int value)94   void set_transferred_request_child_id(int value) {
95     transferred_request_child_id_ = value;
96   }
transferred_request_child_id()97   int transferred_request_child_id() const {
98     return transferred_request_child_id_;
99   }
set_transferred_request_request_id(int value)100   void set_transferred_request_request_id(int value) {
101     transferred_request_request_id_ = value;
102   }
transferred_request_request_id()103   int transferred_request_request_id() const {
104     return transferred_request_request_id_;
105   }
set_allow_download(bool value)106   void set_allow_download(bool value) {
107     allow_download_ = value;
108   }
allow_download()109   bool allow_download() const {
110     return allow_download_;
111   }
112 
set_extra_headers(const std::string & extra_headers)113   void set_extra_headers(const std::string& extra_headers) {
114     extra_headers_ = extra_headers;
115   }
extra_headers()116   const std::string& extra_headers() { return extra_headers_; }
117 
118  private:
119   NavigationState(content::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   content::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