1 // Copyright 2014 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.
5 #ifndef CONTENT_COMMON_NAVIGATION_PARAMS_H_
6 #define CONTENT_COMMON_NAVIGATION_PARAMS_H_
10 #include "base/basictypes.h"
11 #include "base/time/time.h"
12 #include "content/common/content_export.h"
13 #include "content/common/frame_message_enums.h"
14 #include "content/public/common/page_state.h"
15 #include "content/public/common/referrer.h"
16 #include "ui/base/page_transition_types.h"
20 class RefCountedMemory
;
26 // Helper function to determine if the navigation to |url| should make a request
27 // to the network stack. A request should not be sent for data URLs, JavaScript
28 // URLs or about:blank. In these cases, no request needs to be sent.
29 bool ShouldMakeNetworkRequestForURL(const GURL
& url
);
31 // The following structures hold parameters used during a navigation. In
32 // particular they are used by FrameMsg_Navigate, FrameMsg_CommitNavigation and
33 // FrameHostMsg_BeginNavigation.
35 // Provided by the browser or the renderer -------------------------------------
37 // Used by all navigation IPCs.
38 struct CONTENT_EXPORT CommonNavigationParams
{
39 CommonNavigationParams();
40 CommonNavigationParams(const GURL
& url
,
41 const Referrer
& referrer
,
42 ui::PageTransition transition
,
43 FrameMsg_Navigate_Type::Value navigation_type
,
45 base::TimeTicks ui_timestamp
,
46 FrameMsg_UILoadMetricsReportType::Value report_type
,
47 const GURL
& base_url_for_data_url
,
48 const GURL
& history_url_for_data_url
);
49 ~CommonNavigationParams();
51 // The URL to navigate to.
52 // PlzNavigate: May be modified when the navigation is ready to commit.
55 // The URL to send in the "Referer" header field. Can be empty if there is
59 // The type of transition.
60 ui::PageTransition transition
;
62 // Type of navigation.
63 FrameMsg_Navigate_Type::Value navigation_type
;
65 // Allows the URL to be downloaded (true by default).
66 // Avoid downloading when in view-source mode.
69 // Timestamp of the user input event that triggered this navigation. Empty if
70 // the navigation was not triggered by clicking on a link or by receiving an
72 base::TimeTicks ui_timestamp
;
74 // The report type to be used when recording the metric using |ui_timestamp|.
75 FrameMsg_UILoadMetricsReportType::Value report_type
;
77 // Base URL for use in Blink's SubstituteData.
78 // Is only used with data: URLs.
79 GURL base_url_for_data_url
;
81 // History URL for use in Blink's SubstituteData.
82 // Is only used with data: URLs.
83 GURL history_url_for_data_url
;
86 // Provided by the renderer ----------------------------------------------------
88 // This struct holds parameters sent by the renderer to the browser. It is only
89 // used in PlzNavigate (since in the current architecture, the renderer does not
90 // inform the browser of navigations until they commit).
92 // This struct is not used outside of the PlzNavigate project.
93 // PlzNavigate: parameters needed to start a navigation on the IO thread,
94 // following a renderer-initiated navigation request.
95 struct CONTENT_EXPORT BeginNavigationParams
{
96 // TODO(clamy): See if it is possible to reuse this in
97 // ResourceMsg_Request_Params.
98 BeginNavigationParams();
99 BeginNavigationParams(std::string method
,
102 bool has_user_gesture
);
104 // The request method: GET, POST, etc.
107 // Additional HTTP request headers.
110 // net::URLRequest load flags (net::LOAD_NORMAL) by default).
113 // True if the request was user initiated.
114 bool has_user_gesture
;
117 // Provided by the browser -----------------------------------------------------
119 // These structs are sent by the browser to the renderer to start/commit a
120 // navigation depending on whether browser-side navigation is enabled.
121 // Parameters used both in the current architecture and PlzNavigate should be
122 // put in RequestNavigationParams. Parameters only used by the current
123 // architecture should go in StartNavigationParams.
125 // Used by FrameMsg_Navigate. Holds the parameters needed by the renderer to
126 // start a browser-initiated navigation besides those in CommonNavigationParams.
127 // The difference with the RequestNavigationParams below is that they are only
128 // used in the current architecture of navigation, and will not be used by
130 // PlzNavigate: These are not used.
131 struct CONTENT_EXPORT StartNavigationParams
{
132 StartNavigationParams();
133 StartNavigationParams(
135 const std::string
& extra_headers
,
136 const std::vector
<unsigned char>& browser_initiated_post_data
,
137 bool should_replace_current_entry
,
138 int transferred_request_child_id
,
139 int transferred_request_request_id
);
140 ~StartNavigationParams();
142 // Whether the navigation is a POST request (as opposed to a GET).
145 // Extra headers (separated by \n) to send during the request.
146 std::string extra_headers
;
148 // If is_post is true, holds the post_data information from browser. Empty
150 std::vector
<unsigned char> browser_initiated_post_data
;
152 // Informs the RenderView the pending navigation should replace the current
153 // history entry when it commits. This is used for cross-process redirects so
154 // the transferred navigation can recover the navigation state.
155 bool should_replace_current_entry
;
157 // The following two members identify a previous request that has been
158 // created before this navigation is being transferred to a new render view.
159 // This serves the purpose of recycling the old request.
160 // Unless this refers to a transferred navigation, these values are -1 and -1.
161 int transferred_request_child_id
;
162 int transferred_request_request_id
;
165 // Used by FrameMsg_Navigate. Holds the parameters needed by the renderer to
166 // start a browser-initiated navigation besides those in CommonNavigationParams.
167 // PlzNavigate: sent to the renderer to make it issue a stream request for a
168 // navigation that is ready to commit.
169 struct CONTENT_EXPORT RequestNavigationParams
{
170 RequestNavigationParams();
171 RequestNavigationParams(bool is_overriding_user_agent
,
172 base::TimeTicks navigation_start
,
173 const std::vector
<GURL
>& redirects
,
174 bool can_load_local_resources
,
175 base::Time request_time
,
176 const PageState
& page_state
,
179 bool is_same_document_history_load
,
180 bool has_committed_real_load
,
181 bool intended_as_new_entry
,
182 int pending_history_list_offset
,
183 int current_history_list_offset
,
184 int current_history_list_length
,
185 bool should_clear_history_list
);
186 ~RequestNavigationParams();
188 // Whether or not the user agent override string should be used.
189 bool is_overriding_user_agent
;
191 // The navigationStart time to expose through the Navigation Timing API to JS.
192 base::TimeTicks browser_navigation_start
;
194 // Any redirect URLs that occurred before |url|. Useful for cross-process
195 // navigations; defaults to empty.
196 std::vector
<GURL
> redirects
;
198 // Whether or not this url should be allowed to access local file://
200 bool can_load_local_resources
;
202 // The time the request was created. This is used by the old performance
203 // infrastructure to set up DocumentState associated with the RenderView.
204 // TODO(ppi): make it go away.
205 base::Time request_time
;
207 // Opaque history state (received by ViewHostMsg_UpdateState).
208 PageState page_state
;
210 // The page_id for this navigation, or -1 if it is a new navigation. Back,
211 // Forward, and Reload navigations should have a valid page_id. If the load
212 // succeeds, then this page_id will be reflected in the resultant
213 // FrameHostMsg_DidCommitProvisionalLoad message.
216 // For browser-initiated navigations, this is the unique id of the
217 // NavigationEntry being navigated to. (For renderer-initiated navigations it
218 // is 0.) If the load succeeds, then this nav_entry_id will be reflected in
219 // the resulting FrameHostMsg_DidCommitProvisionalLoad message.
222 // For history navigations, this indicates whether the load will stay within
223 // the same document. Defaults to false.
224 bool is_same_document_history_load
;
226 // Whether the frame being navigated has already committed a real page, which
227 // affects how new navigations are classified in the renderer process.
228 // This currently is only ever set to true in --site-per-process mode.
229 // TODO(creis): Create FrameNavigationEntries by default so this always works.
230 bool has_committed_real_load
;
232 // For browser-initiated navigations, this is true if this is a new entry
233 // being navigated to. This is false otherwise. TODO(avi): Remove this when
234 // the pending entry situation is made sane and the browser keeps them around
235 // long enough to match them via nav_entry_id, above.
236 bool intended_as_new_entry
;
238 // For history navigations, this is the offset in the history list of the
239 // pending load. For non-history navigations, this will be ignored.
240 int pending_history_list_offset
;
242 // Where its current page contents reside in session history and the total
243 // size of the session history list.
244 int current_history_list_offset
;
245 int current_history_list_length
;
247 // Whether session history should be cleared. In that case, the RenderView
248 // needs to notify the browser that the clearing was succesful when the
249 // navigation commits.
250 bool should_clear_history_list
;
253 // Helper struct keeping track in one place of all the parameters the browser
254 // needs to provide to the renderer.
255 struct NavigationParams
{
256 NavigationParams(const CommonNavigationParams
& common_params
,
257 const StartNavigationParams
& start_params
,
258 const RequestNavigationParams
& request_params
);
261 CommonNavigationParams common_params
;
262 StartNavigationParams start_params
;
263 RequestNavigationParams request_params
;
266 } // namespace content
268 #endif // CONTENT_COMMON_NAVIGATION_PARAMS_H_