blob: 0ecb21247441a19b4328d23c342705a94fb876af [file] [log] [blame]
clamy5f342202015-03-18 13:47:561// 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
Dmitry Gozman0a527132018-09-21 18:01:045#ifndef CONTENT_RENDERER_NAVIGATION_STATE_H_
6#define CONTENT_RENDERER_NAVIGATION_STATE_H_
clamy5f342202015-03-18 13:47:567
Arthur Hemery1f46de02019-01-31 16:41:538#include <memory>
clamy5f342202015-03-18 13:47:569
avi1023d012015-12-25 02:39:1410#include "base/macros.h"
clamy6b92fcf2018-06-01 13:51:3711#include "content/common/frame.mojom.h"
clamy5f342202015-03-18 13:47:5612#include "content/common/navigation_params.h"
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5113#include "content/common/navigation_params.mojom.h"
Arthur Hemeryd3011f62018-05-30 10:38:4414#include "content/renderer/navigation_client.h"
Arthur Hemery1f46de02019-01-31 16:41:5315
Dmitry Gozman0a527132018-09-21 18:01:0416namespace blink {
17class WebDocumentLoader;
Arthur Hemery1f46de02019-01-31 16:41:5318
19namespace mojom {
20enum class CommitResult;
21}
Dmitry Gozman0a527132018-09-21 18:01:0422}
23
clamy5f342202015-03-18 13:47:5624namespace content {
25
Dmitry Gozman0a527132018-09-21 18:01:0426class CONTENT_EXPORT NavigationState {
clamy5f342202015-03-18 13:47:5627 public:
Dmitry Gozman0a527132018-09-21 18:01:0428 ~NavigationState();
clamy5f342202015-03-18 13:47:5629
David Bokan80f475ac2021-04-23 15:34:0630 static std::unique_ptr<NavigationState> Create(
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5131 mojom::CommonNavigationParamsPtr common_params,
Lucas Furukawa Gadania9c45682019-07-31 22:05:1432 mojom::CommitNavigationParamsPtr commit_params,
Arthur Hemery1f46de02019-01-31 16:41:5333 mojom::NavigationClient::CommitNavigationCallback
34 per_navigation_mojo_interface_callback,
Dmitry Gozmanad64b0e2019-02-21 21:43:1435 std::unique_ptr<NavigationClient> navigation_client,
36 bool was_initiated_in_this_frame);
clamy5f342202015-03-18 13:47:5637
David Bokan80f475ac2021-04-23 15:34:0638 static std::unique_ptr<NavigationState> CreateForSynchronousCommit();
Dmitry Gozman0a527132018-09-21 18:01:0439
40 static NavigationState* FromDocumentLoader(
41 blink::WebDocumentLoader* document_loader);
clamy5f342202015-03-18 13:47:5642
Dmitry Gozman9cfe75d2018-09-18 21:36:0843 // True iff the frame's navigation was within the same document.
44 bool WasWithinSameDocument();
45
David Bokan80f475ac2021-04-23 15:34:0646 bool IsForSynchronousCommit();
clamy5f342202015-03-18 13:47:5647
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5148 const mojom::CommonNavigationParams& common_params() const {
49 return *common_params_;
50 }
Lucas Furukawa Gadania9c45682019-07-31 22:05:1451 const mojom::CommitNavigationParams& commit_params() const {
52 return *commit_params_;
53 }
Dmitry Gozman9b890002020-05-27 15:24:4254 bool has_navigation_client() const { return navigation_client_.get(); }
eugenebutcf731b52017-03-17 17:36:3455 void set_was_within_same_document(bool value) {
56 was_within_same_document_ = value;
57 }
clamy5f342202015-03-18 13:47:5658
Dmitry Gozmanad64b0e2019-02-21 21:43:1459 bool was_initiated_in_this_frame() const {
60 return was_initiated_in_this_frame_;
61 }
62
clamy5f342202015-03-18 13:47:5663 void set_transition_type(ui::PageTransition transition) {
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5164 common_params_->transition = transition;
clamy5f342202015-03-18 13:47:5665 }
66
Dmitry Gozman9b890002020-05-27 15:24:4267 void RunCommitNavigationCallback(
arthursonzogni73fe3212020-11-17 13:24:0768 mojom::DidCommitProvisionalLoadParamsPtr params,
Arthur Hemery1f46de02019-01-31 16:41:5369 mojom::DidCommitProvisionalLoadInterfaceParamsPtr interface_params);
70
clamy5f342202015-03-18 13:47:5671 private:
Dmitry Gozman9b890002020-05-27 15:24:4272 NavigationState(mojom::CommonNavigationParamsPtr common_params,
73 mojom::CommitNavigationParamsPtr commit_params,
David Bokan80f475ac2021-04-23 15:34:0674 bool is_for_synchronous_commit,
Dmitry Gozman9b890002020-05-27 15:24:4275 content::mojom::NavigationClient::CommitNavigationCallback
76 commit_callback,
77 std::unique_ptr<NavigationClient> navigation_client,
78 bool was_initiated_in_this_frame);
clamy5f342202015-03-18 13:47:5679
eugenebutcf731b52017-03-17 17:36:3480 bool was_within_same_document_;
clamy5f342202015-03-18 13:47:5681
Dmitry Gozmanad64b0e2019-02-21 21:43:1482 // Indicates whether the navigation was initiated by the same RenderFrame
83 // it is about to commit in. An example would be a link click.
84 // A counter-example would be user typing in the url bar (browser-initiated
85 // navigation), or a link click leading to a process swap (different
86 // RenderFrame instance).
87 // Used to ensure consistent observer notifications about a navigation.
88 bool was_initiated_in_this_frame_;
89
David Bokan80f475ac2021-04-23 15:34:0690 // True if this navigation is for a renderer synchronous commit (e.g. the
91 // synchronous about:blank navigation, same-origin initiated same-document
92 // navigations), rather than using the browser's navigation stack.
93 const bool is_for_synchronous_commit_;
clamy5f342202015-03-18 13:47:5694
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5195 mojom::CommonNavigationParamsPtr common_params_;
clamy5f342202015-03-18 13:47:5696
97 // Note: if IsContentInitiated() is false, whether this navigation should
98 // replace the current entry in the back/forward history list is determined by
99 // the should_replace_current_entry field in |history_params|. Otherwise, use
100 // replacesCurrentHistoryItem() on the WebDataSource.
101 //
102 // TODO(davidben): It would be good to unify these and have only one source
103 // for the two cases. We can plumb this through WebFrame::loadRequest to set
104 // lockBackForwardList on the FrameLoadRequest. However, this breaks process
105 // swaps because FrameLoader::loadWithNavigationAction treats loads before a
106 // FrameLoader has committedFirstRealDocumentLoad as a replacement. (Added for
107 // http://crbug.com/178380).
Lucas Furukawa Gadania9c45682019-07-31 22:05:14108 mojom::CommitNavigationParamsPtr commit_params_;
clamy5f342202015-03-18 13:47:56109
Arthur Hemeryd3011f62018-05-30 10:38:44110 // The NavigationClient interface gives control over the navigation ongoing in
111 // the browser process.
Arthur Hemeryd3011f62018-05-30 10:38:44112 std::unique_ptr<NavigationClient> navigation_client_;
113
clamy6b92fcf2018-06-01 13:51:37114 // Used to notify whether a commit request from the browser process was
115 // successful or not.
Dmitry Gozman9b890002020-05-27 15:24:42116 mojom::NavigationClient::CommitNavigationCallback commit_callback_;
Arthur Hemery1f46de02019-01-31 16:41:53117
Dmitry Gozman0a527132018-09-21 18:01:04118 DISALLOW_COPY_AND_ASSIGN(NavigationState);
clamy5f342202015-03-18 13:47:56119};
120
121} // namespace content
122
Dmitry Gozman0a527132018-09-21 18:01:04123#endif // CONTENT_RENDERER_NAVIGATION_STATE_H_