blob: 10778a1b72218e577e24a66bf3e030c899ca8ee3 [file] [log] [blame]
thestigf80564462015-09-29 23:12:081// Copyright 2015 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 CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_
6#define CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_
7
8#include <string>
9#include <vector>
10
11#include "base/memory/ref_counted.h"
avi655876a2015-12-25 07:18:1512#include "build/build_config.h"
thestigf80564462015-09-29 23:12:0813#include "content/public/browser/global_request_id.h"
14#include "content/public/browser/site_instance.h"
15#include "content/public/common/referrer.h"
lukasza477a5a22016-06-16 18:28:4316#include "content/public/common/resource_request_body.h"
thestigf80564462015-09-29 23:12:0817#include "ui/base/page_transition_types.h"
18#include "ui/base/window_open_disposition.h"
19#include "ui/gfx/geometry/rect.h"
20#include "url/gurl.h"
21
22class Browser;
23class Profile;
24
25namespace content {
26class WebContents;
27struct OpenURLParams;
28}
29
30namespace chrome {
31
32// Parameters that tell Navigate() what to do.
33//
34// Some basic examples:
35//
36// Simple Navigate to URL in current tab:
37// chrome::NavigateParams params(browser, GURL("http://www.google.com/"),
38// ui::PAGE_TRANSITION_LINK);
39// chrome::Navigate(&params);
40//
41// Open bookmark in new background tab:
42// chrome::NavigateParams params(browser, url,
43// ui::PAGE_TRANSITION_AUTO_BOOKMARK);
44// params.disposition = NEW_BACKGROUND_TAB;
45// chrome::Navigate(&params);
46//
47// Opens a popup WebContents:
48// chrome::NavigateParams params(browser, popup_contents);
49// params.source_contents = source_contents;
50// chrome::Navigate(&params);
51//
52// See browser_navigator_browsertest.cc for more examples.
53
54// TODO(thestig): Split or ifdef out more fields that are not used on Android.
55struct NavigateParams {
56#if defined(OS_ANDROID)
57 explicit NavigateParams(content::WebContents* a_target_contents);
mfomitcheve5994952016-01-26 23:01:4558#else
thestigf80564462015-09-29 23:12:0859 NavigateParams(Browser* browser,
60 const GURL& a_url,
61 ui::PageTransition a_transition);
62 NavigateParams(Browser* browser,
63 content::WebContents* a_target_contents);
64#endif
65 NavigateParams(Profile* profile,
66 const GURL& a_url,
67 ui::PageTransition a_transition);
vmpstrb8aacbe2016-02-26 02:00:4868 NavigateParams(const NavigateParams& other);
thestigf80564462015-09-29 23:12:0869 ~NavigateParams();
70
71 // The URL/referrer to be loaded. Ignored if |target_contents| is non-NULL.
72 GURL url;
73 content::Referrer referrer;
74
jochen67b271b2016-08-03 13:50:2175 // The frame name to be used for the main frame.
76 std::string frame_name;
77
thestigf80564462015-09-29 23:12:0878 // The browser-global ID of the frame to navigate, or -1 for the main frame.
79 int frame_tree_node_id;
80
81 // Any redirect URLs that occurred for this navigation before |url|.
82 // Usually empty.
83 std::vector<GURL> redirect_chain;
84
85 // Indicates whether this navigation will be sent using POST.
thestigf80564462015-09-29 23:12:0886 bool uses_post;
87
88 // The post data when the navigation uses POST.
lukasza477a5a22016-06-16 18:28:4389 scoped_refptr<content::ResourceRequestBody> post_data;
thestigf80564462015-09-29 23:12:0890
91 // Extra headers to add to the request for this page. Headers are
92 // represented as "<name>: <value>" and separated by \r\n. The entire string
93 // is terminated by \r\n. May be empty if no extra headers are needed.
94 std::string extra_headers;
95
96 // [in] A WebContents to be navigated or inserted into the target
97 // Browser's tabstrip. If NULL, |url| or the homepage will be used
98 // instead. When non-NULL, Navigate() assumes it has already been
99 // navigated to its intended destination and will not load any URL in it
100 // (i.e. |url| is ignored).
101 // Default is NULL.
102 // [out] The WebContents in which the navigation occurred or that was
103 // inserted. Guaranteed non-NULL except for note below:
104 // Note: If this field is set to NULL by the caller and Navigate() creates
105 // a new WebContents, this field will remain NULL and the
106 // WebContents deleted if the WebContents it created is
107 // not added to a TabStripModel before Navigate() returns.
108 content::WebContents* target_contents;
109
110 // [in] The WebContents that initiated the Navigate() request if such
111 // context is necessary. Default is NULL, i.e. no context.
112 // [out] If NULL, this value will be set to the selected WebContents in
113 // the originating browser prior to the operation performed by
114 // Navigate(). However, if the originating page is from a different
115 // profile (e.g. an OFF_THE_RECORD page originating from a non-OTR
116 // window), then |source_contents| is reset to NULL.
117 content::WebContents* source_contents;
118
119 // The disposition requested by the navigation source. Default is
120 // CURRENT_TAB. What follows is a set of coercions that happen to this value
121 // when other factors are at play:
122 //
123 // [in]: Condition: [out]:
124 // NEW_BACKGROUND_TAB target browser tabstrip is empty NEW_FOREGROUND_TAB
125 // CURRENT_TAB " " " NEW_FOREGROUND_TAB
126 // OFF_THE_RECORD target browser profile is incog. NEW_FOREGROUND_TAB
127 //
128 // If disposition is NEW_BACKGROUND_TAB, TabStripModel::ADD_ACTIVE is
129 // removed from |tabstrip_add_types| automatically.
130 // If disposition is one of NEW_WINDOW, NEW_POPUP, NEW_FOREGROUND_TAB or
131 // SINGLETON_TAB, then TabStripModel::ADD_ACTIVE is automatically added to
132 // |tabstrip_add_types|.
133 WindowOpenDisposition disposition;
134
lukaszaf206da92017-04-20 23:26:51135 // Controls creation of new web contents (in case |disposition| asks for a new
136 // tab or window). If |force_new_process_for_new_contents| is true, then we
137 // try to put the new contents in a new renderer, even if they are same-site
138 // as |source_site_instance| (this is subject to renderer process limits).
139 bool force_new_process_for_new_contents;
140
thestigf80564462015-09-29 23:12:08141 // Sets browser->is_trusted_source. Default is false.
142 bool trusted_source;
143
144 // The transition type of the navigation. Default is
145 // ui::PAGE_TRANSITION_LINK when target_contents is specified in the
146 // constructor.
147 ui::PageTransition transition;
148
149 // Whether this navigation was initiated by the renderer process. Default is
150 // false.
151 bool is_renderer_initiated;
152
153 // The index the caller would like the tab to be positioned at in the
154 // TabStrip. The actual index will be determined by the TabHandler in
155 // accordance with |add_types|. Defaults to -1 (allows the TabHandler to
156 // decide).
157 int tabstrip_index;
158
159 // A bitmask of values defined in TabStripModel::AddTabTypes. Helps
160 // determine where to insert a new tab and whether or not it should be
161 // selected, among other properties. Default is ADD_ACTIVE.
162 int tabstrip_add_types;
163
164 // If non-empty, the new tab is an app tab.
165 std::string extension_app_id;
166
167 // If non-empty, specifies the desired initial position and size of the
168 // window if |disposition| == NEW_POPUP.
169 // TODO(beng): Figure out if this can be used to create Browser windows
170 // for other callsites that use set_override_bounds, or
171 // remove this comment.
172 gfx::Rect window_bounds;
173
174 // Determines if and how the target window should be made visible at the end
175 // of the call to Navigate().
176 enum WindowAction {
177 // Do not show or activate the browser window after navigating.
178 NO_ACTION,
179 // Show and activate the browser window after navigating.
180 SHOW_WINDOW,
181 // Show the browser window after navigating but do not activate.
182 SHOW_WINDOW_INACTIVE
183 };
184 // Default is NO_ACTION (don't show or activate the window).
185 // If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to
186 // NO_ACTION, |window_action| will be set to SHOW_WINDOW.
187 WindowAction window_action;
188
189 // If false then the navigation was not initiated by a user gesture.
190 // Default is true.
191 bool user_gesture;
192
193 // What to do with the path component of the URL for singleton navigations.
194 enum PathBehavior {
195 // Two URLs with differing paths are different.
196 RESPECT,
197 // Ignore path when finding existing tab, navigate to new URL.
198 IGNORE_AND_NAVIGATE,
199 // Ignore path when finding existing tab, don't navigate tab.
200 IGNORE_AND_STAY_PUT,
201 };
202 // Default is RESPECT.
203 PathBehavior path_behavior;
204
205 // What to do with the ref component of the URL for singleton navigations.
206 enum RefBehavior {
207 // Two URLs with differing refs are same.
208 IGNORE_REF,
209 // Two URLs with differing refs are different.
210 RESPECT_REF,
211 };
212 // Default is IGNORE.
213 RefBehavior ref_behavior;
214
mfomitcheve5994952016-01-26 23:01:45215#if !defined(OS_ANDROID)
thestigf80564462015-09-29 23:12:08216 // [in] Specifies a Browser object where the navigation could occur or the
217 // tab could be added. Navigate() is not obliged to use this Browser if
218 // it is not compatible with the operation being performed. This can be
219 // NULL, in which case |initiating_profile| must be provided.
220 // [out] Specifies the Browser object where the navigation occurred or the
221 // tab was added. Guaranteed non-NULL unless the disposition did not
222 // require a navigation, in which case this is set to NULL
pkastinge64c1db2016-07-01 20:45:42223 // (SAVE_TO_DISK, IGNORE_ACTION).
thestigf80564462015-09-29 23:12:08224 // Note: If |show_window| is set to false and a new Browser is created by
225 // Navigate(), the caller is responsible for showing it so that its
226 // window can assume responsibility for the Browser's lifetime (Browser
227 // objects are deleted when the user closes a visible browser window).
228 Browser* browser;
229#endif
230
231 // The profile that is initiating the navigation. If there is a non-NULL
232 // browser passed in via |browser|, it's profile will be used instead.
233 Profile* initiating_profile;
234
thestigf80564462015-09-29 23:12:08235 // Indicates whether this navigation should replace the current
236 // navigation entry.
237 bool should_replace_current_entry;
238
239 // Indicates whether |target_contents| is being created with a window.opener.
240 bool created_with_opener;
241
djacobo825aa6a82016-09-29 22:47:19242 // Whether or not the related navigation was started in the context menu.
243 bool started_from_context_menu;
244
thestigf80564462015-09-29 23:12:08245 // SiteInstance of the frame that initiated the navigation or null if we
246 // don't know it. This should be assigned from the OpenURLParams of the
247 // WebContentsDelegate::OpenURLFromTab implementation and is used to determine
248 // the SiteInstance that will be used for the resulting frame in the case of
249 // an about:blank or a data url navigation.
250 scoped_refptr<content::SiteInstance> source_site_instance;
251
252 private:
253 NavigateParams();
254};
255
256// Copies fields from |params| struct to |nav_params| struct.
257void FillNavigateParamsFromOpenURLParams(chrome::NavigateParams* nav_params,
258 const content::OpenURLParams& params);
259
260} // namespace chrome
261
262#endif // CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_