File: browser_navigator_params.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (382 lines) | stat: -rw-r--r-- 16,719 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_
#define CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "components/captive_portal/core/captive_portal_types.h"
#include "content/public/browser/child_process_host.h"
#include "content/public/browser/global_request_id.h"
#include "content/public/browser/reload_type.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/site_instance.h"
#include "content/public/common/referrer.h"
#include "services/network/public/cpp/resource_request_body.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "third_party/blink/public/common/navigation/impression.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/navigation/system_entropy.mojom.h"
#include "third_party/blink/public/mojom/navigation/was_activated_option.mojom.h"
#include "third_party/blink/public/mojom/window_features/window_features.mojom.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"

#if !BUILDFLAG(IS_ANDROID)
#include "components/tab_groups/tab_group_id.h"
#endif

class Browser;
class Profile;

namespace content {
class RenderFrameHost;
class WebContents;
struct OpenURLParams;
}  // namespace content

// Parameters that tell Navigate() what to do.
//
// Some basic examples:
//
// Simple Navigate to URL in current tab:
// NavigateParams params(browser, GURL("http://www.google.com/"),
//                               ui::PAGE_TRANSITION_LINK);
// Navigate(&params);
//
// Open bookmark in new background tab:
// NavigateParams params(browser, url,
//                               ui::PAGE_TRANSITION_AUTO_BOOKMARK);
// params.disposition = NEW_BACKGROUND_TAB;
// Navigate(&params);
//
// Opens a popup WebContents:
// NavigateParams params(browser, popup_contents);
// params.source_contents = source_contents;
// Navigate(&params);
//
// See browser_navigator_browsertest.cc for more examples.

// TODO(thestig): Split or ifdef out more fields that are not used on Android.
struct NavigateParams {
#if BUILDFLAG(IS_ANDROID)
  explicit NavigateParams(
      std::unique_ptr<content::WebContents> contents_to_insert);
#else
  NavigateParams(Browser* browser,
                 const GURL& a_url,
                 ui::PageTransition a_transition);
  NavigateParams(Browser* browser,
                 std::unique_ptr<content::WebContents> contents_to_insert);
#endif
  NavigateParams(Profile* profile,
                 const GURL& a_url,
                 ui::PageTransition a_transition);

  NavigateParams(const NavigateParams&) = delete;
  NavigateParams& operator=(const NavigateParams&) = delete;

  NavigateParams(NavigateParams&& params);

  ~NavigateParams();

  // Copies fields from |params| struct to |nav_params| struct.
  void FillNavigateParamsFromOpenURLParams(
      const content::OpenURLParams& params);

  // The URL/referrer to be loaded. Ignored if |contents_to_insert| is non-NULL.
  GURL url;
  content::Referrer referrer;

  // The frame token of the initiator of the navigation. This is best effort: it
  // is only defined for some renderer-initiated navigations (e.g., not drag and
  // drop), and the frame with the corresponding frame token may have been
  // deleted before the navigation begins. It is defined if and only if
  // |initiator_process_id| below is.
  std::optional<blink::LocalFrameToken> initiator_frame_token;

  // ID of the renderer process of the frame host that initiated the navigation.
  // This is defined if and only if |initiator_frame_token| above is, and it is
  // only valid in conjunction with it.
  int initiator_process_id = content::ChildProcessHost::kInvalidUniqueID;

  // The origin of the initiator of the navigation.
  std::optional<url::Origin> initiator_origin;

  // The base url of the initiator of the navigation. This is only set if the
  // url is about:blank or about:srcdoc.
  std::optional<GURL> initiator_base_url;

  // The frame name to be used for the main frame.
  std::string frame_name;

  // The browser-global ID of the frame to navigate, or the default invalid
  // value for the main frame.
  content::FrameTreeNodeId frame_tree_node_id;

  // Any redirect URLs that occurred for this navigation before |url|.
  // Usually empty.
  std::vector<GURL> redirect_chain;

  // The post data when the navigation uses POST.
  scoped_refptr<network::ResourceRequestBody> post_data;

  // Extra headers to add to the request for this page.  Headers are
  // represented as "<name>: <value>" and separated by \r\n.  The entire string
  // is terminated by \r\n.  May be empty if no extra headers are needed.
  std::string extra_headers;

  // Input parameter.
  // WebContents to be inserted into the target Browser's tabstrip. If NULL,
  // |url| or the homepage will be used instead. When non-NULL, Navigate()
  // assumes it has already been navigated to its intended destination and will
  // not load any URL in it (i.e. |url| is ignored). Default is NULL.
  std::unique_ptr<content::WebContents> contents_to_insert;

  // Input parameter.
  // Only used by Singleton tabs. Causes a tab-switch in addition to navigation.
  raw_ptr<content::WebContents, AcrossTasksDanglingUntriaged>
      switch_to_singleton_tab = nullptr;

  // Output parameter.
  // The WebContents in which the navigation occurred or that was inserted.
  // Guaranteed non-NULL except for note below:
  //
  // Note: If this field is set to NULL by the caller and Navigate() creates a
  // new WebContents, this field will remain NULL and the WebContents deleted if
  // the WebContents it created is not added to a TabStripModel before
  // Navigate() returns.
  raw_ptr<content::WebContents, DanglingUntriaged>
      navigated_or_inserted_contents = nullptr;

  // [in]  The WebContents that initiated the Navigate() request if such
  //       context is necessary. Default is NULL, i.e. no context.
  // [out] If NULL, this value will be set to the selected WebContents in
  //       the originating browser prior to the operation performed by
  //       Navigate(). However, if the originating page is from a different
  //       profile (e.g. an OFF_THE_RECORD page originating from a non-OTR
  //       window), then |source_contents| is reset to NULL.
  raw_ptr<content::WebContents, AcrossTasksDanglingUntriaged> source_contents =
      nullptr;

  // The disposition requested by the navigation source. Default is
  // CURRENT_TAB. What follows is a set of coercions that happen to this value
  // when other factors are at play:
  //
  // [in]:                Condition:                        [out]:
  // NEW_BACKGROUND_TAB   target browser tabstrip is empty  NEW_FOREGROUND_TAB
  // CURRENT_TAB          "     "     "                     NEW_FOREGROUND_TAB
  // NEW_BACKGROUND_TAB   target browser is an app browser  NEW_FOREGROUND_TAB
  // OFF_THE_RECORD       target browser profile is incog.  NEW_FOREGROUND_TAB
  //
  // If disposition is NEW_BACKGROUND_TAB, AddTabTypes::ADD_ACTIVE is
  // removed from |tabstrip_add_types| automatically.
  // If disposition is one of NEW_WINDOW, NEW_POPUP, NEW_FOREGROUND_TAB or
  // SINGLETON_TAB, then AddTabTypes::ADD_ACTIVE is automatically added to
  // |tabstrip_add_types|.
  WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB;

  // Allows setting the opener for the case when new WebContents are created
  // (i.e. when |disposition| asks for a new tab or window).
  raw_ptr<content::RenderFrameHost> opener = nullptr;

  // Sets browser->is_trusted_source.
  bool trusted_source = false;

  // The transition type of the navigation.
  ui::PageTransition transition = ui::PAGE_TRANSITION_LINK;

  // Whether this navigation was initiated by the renderer process.
  bool is_renderer_initiated = false;

  // The index the caller would like the tab to be positioned at in the
  // TabStrip. The actual index will be determined by the TabHandler in
  // accordance with |add_types|. The default allows the TabHandler to decide.
  int tabstrip_index = -1;

  // If non-empty, the new tab is an app tab.
  std::string app_id;

  // Specifies the desired window features if `disposition` is NEW_POPUP.
  blink::mojom::WindowFeatures window_features;

  // Determines if and how the target window should be made visible at the end
  // of the call to Navigate().
  enum WindowAction {
    // Do not show or activate the browser window after navigating.
    NO_ACTION,
    // Show and activate the browser window after navigating.
    SHOW_WINDOW,
    // Show the browser window after navigating but do not activate.
    // Note: This may cause a space / virtual desktop switch if the window is
    // being shown on a display which is currently showing a fullscreen app.
    // (crbug.com/1315749).
    SHOW_WINDOW_INACTIVE
  };
  // Default is NO_ACTION (don't show or activate the window).
  // If disposition is NEW_WINDOW or NEW_POPUP, and |window_action| is set to
  // NO_ACTION, |window_action| will be set to SHOW_WINDOW.
  WindowAction window_action = NO_ACTION;

  // Captive portal type for this browser window.
  captive_portal::CaptivePortalWindowType captive_portal_window_type =
      captive_portal::CaptivePortalWindowType::kNone;

  // Whether the browser popup is being created as a tab modal. If true,
  // `disposition` should be NEW_POPUP. Additionally, it prevents card saving
  // and other prompts for payments autofill enrollment.
  bool is_tab_modal_popup_deprecated = false;

  // If false then the navigation was not initiated by a user gesture. This
  // variable will be set to true for popups to get windows focus even if
  // the navigation was not triggered by user gesture.
  bool user_gesture = true;

  // Whether the navigation was initiated by a user gesture. Unlike
  // `user_gesture`, this value will not change during the course of the
  // navigation.
  // TODO(https://crbug.com/394614633): remove this once the user gesture hack
  // is fixed.
  bool original_user_gesture = true;

  // What to do with the path component of the URL for singleton navigations.
  enum PathBehavior {
    // Two URLs with differing paths are different.
    RESPECT,
    // Ignore path when finding existing tab, navigate to new URL.
    IGNORE_AND_NAVIGATE,
  };
  PathBehavior path_behavior = RESPECT;

#if !BUILDFLAG(IS_ANDROID)
  // [in]  Specifies a Browser object where the navigation could occur or the
  //       tab could be added. Navigate() is not obliged to use this Browser if
  //       it is not compatible with the operation being performed. This can be
  //       NULL, in which case |initiating_profile| must be provided.
  // [out] Specifies the Browser object where the navigation occurred or the
  //       tab was added. Guaranteed non-NULL unless the disposition did not
  //       require a navigation, in which case this is set to NULL
  //       (SAVE_TO_DISK, IGNORE_ACTION).
  // Note: If |show_window| is set to false and a new Browser is created by
  //       Navigate(), the caller is responsible for showing it so that its
  //       window can assume responsibility for the Browser's lifetime (Browser
  //       objects are deleted when the user closes a visible browser window).
  raw_ptr<Browser, AcrossTasksDanglingUntriaged> browser = nullptr;

  // The group the caller would like the tab to be added to.
  std::optional<tab_groups::TabGroupId> group;

  // True if the navigation was initiated in response to a sync message. This is
  // used in tab group sync to identify the sync initiated navigations and
  // blocking them from sending back to sync which would otherwise cause
  // ping-pong issue. They will still be allowed to load locally like a normal
  // navigation.
  bool navigation_initiated_from_sync = false;

  // A bitmask of values defined in TabStripModel::AddTabTypes. Helps
  // determine where to insert a new tab and whether or not it should be
  // selected, among other properties.
  int tabstrip_add_types = AddTabTypes::ADD_ACTIVE;
#endif

  // The profile that is initiating the navigation. If there is a non-NULL
  // browser passed in via |browser|, it's profile will be used instead.
  raw_ptr<Profile> initiating_profile = nullptr;

  // Indicates whether this navigation  should replace the current
  // navigation entry.
  bool should_replace_current_entry = false;

  // Indicates whether |contents_to_insert| is being created by another window,
  // and thus can be closed via window.close(). This may be true even when
  // "noopener" was used.
  bool opened_by_another_window = false;

  // Whether or not the related navigation was started in the context menu.
  bool started_from_context_menu = false;

  // SiteInstance of the frame that initiated the navigation or null if we
  // don't know it. This should be assigned from the OpenURLParams of the
  // WebContentsDelegate::OpenURLFromTab implementation and is used to determine
  // the SiteInstance that will be used for the resulting frame in the case of
  // an about:blank or a data url navigation.
  scoped_refptr<content::SiteInstance> source_site_instance;

  // Optional URLLoaderFactory to facilitate blob URL loading.
  scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory;

  // Indicates that the navigation should happen in an pwa window if
  // possible, i.e. if the is a PWA installed for the target URL.
  bool open_pwa_window_if_possible = false;

  // Indicates that the navigation must happen in a PWA window. If a PWA
  // window can't be created, the navigation will be cancelled.
  bool force_open_pwa_window = false;

  // The time when the input which led to the navigation occurred. Currently
  // only set when a link is clicked or the navigation takes place from the
  // desktop omnibox.
  base::TimeTicks input_start;

  // Indicates that the new page should have a propagated user activation.
  // This should be used when we want to pass an activation that occurred
  // outside of the page and pass it to the page as if it happened on a prior
  // page. For example, if the assistant opens a page we should treat the
  // user's interaction with the assistant as a previous user activation.
  blink::mojom::WasActivatedOption was_activated =
      blink::mojom::WasActivatedOption::kUnknown;

  // If this navigation was initiated from a link that specified the
  // hrefTranslate attribute, this contains the attribute's value (a BCP47
  // language code). Empty otherwise.
  std::string href_translate;

  // Indicates the reload type of this navigation.
  content::ReloadType reload_type = content::ReloadType::NONE;

  // Optional impression associated with this navigation. Only set on
  // navigations that originate from links with impression attributes. Used for
  // conversion measurement.
  std::optional<blink::Impression> impression;

  // True if the navigation was initiated by typing in the omnibox but the typed
  // text didn't have a scheme such as http or https (e.g. google.com), and
  // https was used as the default scheme for the navigation. This is used by
  // TypedNavigationUpgradeThrottle to determine if the navigation should be
  // observed and fall back to using http scheme if necessary.
  bool is_using_https_as_default_scheme = false;

  // True if the navigation was initiated by typing in the omnibox and the typed
  // text had an explicit http scheme.
  bool url_typed_with_http_scheme = false;

  // Indicates if the page load occurs during a non-optimal performance state.
  // This value is only suggested based upon the load context, and can be
  // overridden by other factors.
  blink::mojom::SystemEntropy suggested_system_entropy =
      blink::mojom::SystemEntropy::kNormal;

  // This option forces PWA navigation capturing (which captures some
  // navigations into PWA windows or tabs) off. This is only recommended to be
  // used if the navigation MUST not be captured. See
  // https://bit.ly/pwa-navigation-capturing for a description about what PWA
  // navigation capturing does. Setting this field to `true` will disable all of
  // the behaviors listed in that document.
  bool pwa_navigation_capturing_force_off = false;

 private:
  NavigateParams();
};

#endif  // CHROME_BROWSER_UI_BROWSER_NAVIGATOR_PARAMS_H_