navigation_state.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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
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      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
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.
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  // Contains the transition type that the browser specified when it
55  // initiated the load.
56  content::PageTransition transition_type() const { return transition_type_; }
57  void set_transition_type(content::PageTransition type) {
58    transition_type_ = type;
59  }
60
61  // True if we have already processed the "DidCommitLoad" event for this
62  // request.  Used by session history.
63  bool request_committed() const { return request_committed_; }
64  void set_request_committed(bool value) { request_committed_ = value; }
65
66  // True if this navigation was not initiated via WebFrame::LoadRequest.
67  bool is_content_initiated() const { return is_content_initiated_; }
68
69  // True iff the frame's navigation was within the same page.
70  void set_was_within_same_page(bool value) { was_within_same_page_ = value; }
71  bool was_within_same_page() const { return was_within_same_page_; }
72
73  // transferred_request_child_id and transferred_request_request_id identify
74  // a request that has been created before the navigation is being transferred
75  // to a new renderer. This is used to recycle the old request once the new
76  // renderer tries to pick up the navigation of the old one.
77  void set_transferred_request_child_id(int value) {
78    transferred_request_child_id_ = value;
79  }
80  int transferred_request_child_id() const {
81    return transferred_request_child_id_;
82  }
83  void set_transferred_request_request_id(int value) {
84    transferred_request_request_id_ = value;
85  }
86  int transferred_request_request_id() const {
87    return transferred_request_request_id_;
88  }
89  void set_allow_download(bool value) {
90    allow_download_ = value;
91  }
92  bool allow_download() const {
93    return allow_download_;
94  }
95
96  void set_extra_headers(const std::string& extra_headers) {
97    extra_headers_ = extra_headers;
98  }
99  const std::string& extra_headers() { return extra_headers_; }
100
101 private:
102  NavigationState(content::PageTransition transition_type,
103                  bool is_content_initiated,
104                  int32 pending_page_id,
105                  int pending_history_list_offset,
106                  bool history_list_was_cleared);
107
108  content::PageTransition transition_type_;
109  bool request_committed_;
110  bool is_content_initiated_;
111  int32 pending_page_id_;
112  int pending_history_list_offset_;
113  bool history_list_was_cleared_;
114
115  bool was_within_same_page_;
116  int transferred_request_child_id_;
117  int transferred_request_request_id_;
118  bool allow_download_;
119  std::string extra_headers_;
120
121  DISALLOW_COPY_AND_ASSIGN(NavigationState);
122};
123
124}  // namespace content
125
126#endif  // CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
127