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 bool should_replace_current_entry
,
46 base::TimeTicks ui_timestamp
,
47 FrameMsg_UILoadMetricsReportType::Value report_type
,
48 const GURL
& base_url_for_data_url
,
49 const GURL
& history_url_for_data_url
);
50 ~CommonNavigationParams();
52 // The URL to navigate to.
53 // PlzNavigate: May be modified when the navigation is ready to commit.
56 // The URL to send in the "Referer" header field. Can be empty if there is
60 // The type of transition.
61 ui::PageTransition transition
;
63 // Type of navigation.
64 FrameMsg_Navigate_Type::Value navigation_type
;
66 // Allows the URL to be downloaded (true by default).
67 // Avoid downloading when in view-source mode.
70 // Informs the RenderView the pending navigation should replace the current
71 // history entry when it commits. This is used for cross-process redirects so
72 // the transferred navigation can recover the navigation state.
73 // PlzNavigate: this is used by client-side redirects to indicate that when
74 // the navigation commits, it should commit in the existing page.
75 bool should_replace_current_entry
;
77 // Timestamp of the user input event that triggered this navigation. Empty if
78 // the navigation was not triggered by clicking on a link or by receiving an
80 base::TimeTicks ui_timestamp
;
82 // The report type to be used when recording the metric using |ui_timestamp|.
83 FrameMsg_UILoadMetricsReportType::Value report_type
;
85 // Base URL for use in Blink's SubstituteData.
86 // Is only used with data: URLs.
87 GURL base_url_for_data_url
;
89 // History URL for use in Blink's SubstituteData.
90 // Is only used with data: URLs.
91 GURL history_url_for_data_url
;
94 // Provided by the renderer ----------------------------------------------------
96 // This struct holds parameters sent by the renderer to the browser. It is only
97 // used in PlzNavigate (since in the current architecture, the renderer does not
98 // inform the browser of navigations until they commit).
100 // This struct is not used outside of the PlzNavigate project.
101 // PlzNavigate: parameters needed to start a navigation on the IO thread,
102 // following a renderer-initiated navigation request.
103 struct CONTENT_EXPORT BeginNavigationParams
{
104 // TODO(clamy): See if it is possible to reuse this in
105 // ResourceMsg_Request_Params.
106 BeginNavigationParams();
107 BeginNavigationParams(std::string method
,
110 bool has_user_gesture
);
112 // The request method: GET, POST, etc.
115 // Additional HTTP request headers.
118 // net::URLRequest load flags (net::LOAD_NORMAL) by default).
121 // True if the request was user initiated.
122 bool has_user_gesture
;
125 // Provided by the browser -----------------------------------------------------
127 // These structs are sent by the browser to the renderer to start/commit a
128 // navigation depending on whether browser-side navigation is enabled.
129 // Parameters used both in the current architecture and PlzNavigate should be
130 // put in RequestNavigationParams. Parameters only used by the current
131 // architecture should go in StartNavigationParams.
133 // Used by FrameMsg_Navigate. Holds the parameters needed by the renderer to
134 // start a browser-initiated navigation besides those in CommonNavigationParams.
135 // The difference with the RequestNavigationParams below is that they are only
136 // used in the current architecture of navigation, and will not be used by
138 // PlzNavigate: These are not used.
139 struct CONTENT_EXPORT StartNavigationParams
{
140 StartNavigationParams();
141 StartNavigationParams(
143 const std::string
& extra_headers
,
144 const std::vector
<unsigned char>& browser_initiated_post_data
,
145 #if defined(OS_ANDROID)
146 bool has_user_gesture
,
148 int transferred_request_child_id
,
149 int transferred_request_request_id
);
150 ~StartNavigationParams();
152 // Whether the navigation is a POST request (as opposed to a GET).
155 // Extra headers (separated by \n) to send during the request.
156 std::string extra_headers
;
158 // If is_post is true, holds the post_data information from browser. Empty
160 std::vector
<unsigned char> browser_initiated_post_data
;
162 #if defined(OS_ANDROID)
163 bool has_user_gesture
;
166 // The following two members identify a previous request that has been
167 // created before this navigation is being transferred to a new render view.
168 // This serves the purpose of recycling the old request.
169 // Unless this refers to a transferred navigation, these values are -1 and -1.
170 int transferred_request_child_id
;
171 int transferred_request_request_id
;
174 // Used by FrameMsg_Navigate. Holds the parameters needed by the renderer to
175 // start a browser-initiated navigation besides those in CommonNavigationParams.
176 // PlzNavigate: sent to the renderer to make it issue a stream request for a
177 // navigation that is ready to commit.
178 struct CONTENT_EXPORT RequestNavigationParams
{
179 RequestNavigationParams();
180 RequestNavigationParams(bool is_overriding_user_agent
,
181 base::TimeTicks navigation_start
,
182 const std::vector
<GURL
>& redirects
,
183 bool can_load_local_resources
,
184 base::Time request_time
,
185 const PageState
& page_state
,
188 bool is_same_document_history_load
,
189 bool has_committed_real_load
,
190 bool intended_as_new_entry
,
191 int pending_history_list_offset
,
192 int current_history_list_offset
,
193 int current_history_list_length
,
194 bool should_clear_history_list
);
195 ~RequestNavigationParams();
197 // Whether or not the user agent override string should be used.
198 bool is_overriding_user_agent
;
200 // The navigationStart time to expose through the Navigation Timing API to JS.
201 base::TimeTicks browser_navigation_start
;
203 // Any redirect URLs that occurred before |url|. Useful for cross-process
204 // navigations; defaults to empty.
205 std::vector
<GURL
> redirects
;
207 // Whether or not this url should be allowed to access local file://
209 bool can_load_local_resources
;
211 // The time the request was created. This is used by the old performance
212 // infrastructure to set up DocumentState associated with the RenderView.
213 // TODO(ppi): make it go away.
214 base::Time request_time
;
216 // Opaque history state (received by ViewHostMsg_UpdateState).
217 PageState page_state
;
219 // The page_id for this navigation, or -1 if it is a new navigation. Back,
220 // Forward, and Reload navigations should have a valid page_id. If the load
221 // succeeds, then this page_id will be reflected in the resultant
222 // FrameHostMsg_DidCommitProvisionalLoad message.
225 // For browser-initiated navigations, this is the unique id of the
226 // NavigationEntry being navigated to. (For renderer-initiated navigations it
227 // is 0.) If the load succeeds, then this nav_entry_id will be reflected in
228 // the resulting FrameHostMsg_DidCommitProvisionalLoad message.
231 // For history navigations, this indicates whether the load will stay within
232 // the same document. Defaults to false.
233 bool is_same_document_history_load
;
235 // Whether the frame being navigated has already committed a real page, which
236 // affects how new navigations are classified in the renderer process.
237 // This currently is only ever set to true in --site-per-process mode.
238 // TODO(creis): Create FrameNavigationEntries by default so this always works.
239 bool has_committed_real_load
;
241 // For browser-initiated navigations, this is true if this is a new entry
242 // being navigated to. This is false otherwise. TODO(avi): Remove this when
243 // the pending entry situation is made sane and the browser keeps them around
244 // long enough to match them via nav_entry_id, above.
245 bool intended_as_new_entry
;
247 // For history navigations, this is the offset in the history list of the
248 // pending load. For non-history navigations, this will be ignored.
249 int pending_history_list_offset
;
251 // Where its current page contents reside in session history and the total
252 // size of the session history list.
253 int current_history_list_offset
;
254 int current_history_list_length
;
256 // Whether session history should be cleared. In that case, the RenderView
257 // needs to notify the browser that the clearing was succesful when the
258 // navigation commits.
259 bool should_clear_history_list
;
262 // Helper struct keeping track in one place of all the parameters the browser
263 // needs to provide to the renderer.
264 struct NavigationParams
{
265 NavigationParams(const CommonNavigationParams
& common_params
,
266 const StartNavigationParams
& start_params
,
267 const RequestNavigationParams
& request_params
);
270 CommonNavigationParams common_params
;
271 StartNavigationParams start_params
;
272 RequestNavigationParams request_params
;
275 } // namespace content
277 #endif // CONTENT_COMMON_NAVIGATION_PARAMS_H_