navigation_state.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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/public/common/page_transition_types.h"
11
12namespace content {
13
14// NavigationState is the portion of DocumentState that is affected by
15// in-document navigation.
16// TODO(simonjam): Move this to HistoryItem's ExtraData.
17class NavigationState {
18 public:
19  virtual ~NavigationState();
20
21  static NavigationState* CreateBrowserInitiated(
22      int32 pending_page_id,
23      int pending_history_list_offset,
24      content::PageTransition transition_type) {
25    return new NavigationState(transition_type, false, pending_page_id,
26                               pending_history_list_offset);
27  }
28
29  static NavigationState* CreateContentInitiated() {
30    return new NavigationState(content::PAGE_TRANSITION_LINK, true, -1, -1);
31  }
32
33  // Contains the page_id for this navigation or -1 if there is none yet.
34  int32 pending_page_id() const { return pending_page_id_; }
35
36  // If pending_page_id() is not -1, then this contains the corresponding
37  // offset of the page in the back/forward history list.
38  int pending_history_list_offset() const {
39    return pending_history_list_offset_;
40  }
41
42  // Contains the transition type that the browser specified when it
43  // initiated the load.
44  content::PageTransition transition_type() const { return transition_type_; }
45  void set_transition_type(content::PageTransition type) {
46    transition_type_ = type;
47  }
48
49  // True if we have already processed the "DidCommitLoad" event for this
50  // request.  Used by session history.
51  bool request_committed() const { return request_committed_; }
52  void set_request_committed(bool value) { request_committed_ = value; }
53
54  // True if this navigation was not initiated via WebFrame::LoadRequest.
55  bool is_content_initiated() const { return is_content_initiated_; }
56
57  // True iff the frame's navigation was within the same page.
58  void set_was_within_same_page(bool value) { was_within_same_page_ = value; }
59  bool was_within_same_page() const { return was_within_same_page_; }
60
61  // transferred_request_child_id and transferred_request_request_id identify
62  // a request that has been created before the navigation is being transferred
63  // to a new renderer. This is used to recycle the old request once the new
64  // renderer tries to pick up the navigation of the old one.
65  void set_transferred_request_child_id(int value) {
66    transferred_request_child_id_ = value;
67  }
68  int transferred_request_child_id() const {
69    return transferred_request_child_id_;
70  }
71  void set_transferred_request_request_id(int value) {
72    transferred_request_request_id_ = value;
73  }
74  int transferred_request_request_id() const {
75    return transferred_request_request_id_;
76  }
77  void set_allow_download(bool value) {
78    allow_download_ = value;
79  }
80  bool allow_download() const {
81    return allow_download_;
82  }
83
84  void set_extra_headers(const std::string& extra_headers) {
85    extra_headers_ = extra_headers;
86  }
87  const std::string& extra_headers() { return extra_headers_; }
88
89 private:
90  NavigationState(content::PageTransition transition_type,
91                  bool is_content_initiated,
92                  int32 pending_page_id,
93                  int pending_history_list_offset);
94
95  content::PageTransition transition_type_;
96  bool request_committed_;
97  bool is_content_initiated_;
98  int32 pending_page_id_;
99  int pending_history_list_offset_;
100
101  bool was_within_same_page_;
102  int transferred_request_child_id_;
103  int transferred_request_request_id_;
104  bool allow_download_;
105  std::string extra_headers_;
106
107  DISALLOW_COPY_AND_ASSIGN(NavigationState);
108};
109
110}  // namespace content
111
112#endif  // CONTENT_PUBLIC_RENDERER_NAVIGATION_STATE_H_
113