blob: 334421f24f667d95db62530a32931a81b33199cc [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"
Arthur Hemery1f46de02019-01-31 16:41:5311#include "base/time/time.h"
clamy6b92fcf2018-06-01 13:51:3712#include "content/common/frame.mojom.h"
clamy5f342202015-03-18 13:47:5613#include "content/common/navigation_params.h"
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5114#include "content/common/navigation_params.mojom.h"
Arthur Hemeryd3011f62018-05-30 10:38:4415#include "content/renderer/navigation_client.h"
Arthur Hemery1f46de02019-01-31 16:41:5316
Dmitry Gozman0a527132018-09-21 18:01:0417namespace blink {
18class WebDocumentLoader;
Arthur Hemery1f46de02019-01-31 16:41:5319
20namespace mojom {
21enum class CommitResult;
22}
Dmitry Gozman0a527132018-09-21 18:01:0423}
24
clamy5f342202015-03-18 13:47:5625namespace content {
26
Dmitry Gozman0a527132018-09-21 18:01:0427class CONTENT_EXPORT NavigationState {
clamy5f342202015-03-18 13:47:5628 public:
Dmitry Gozman0a527132018-09-21 18:01:0429 ~NavigationState();
clamy5f342202015-03-18 13:47:5630
David Bokan80f475ac2021-04-23 15:34:0631 static std::unique_ptr<NavigationState> Create(
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5132 mojom::CommonNavigationParamsPtr common_params,
Lucas Furukawa Gadania9c45682019-07-31 22:05:1433 mojom::CommitNavigationParamsPtr commit_params,
Arthur Hemery1f46de02019-01-31 16:41:5334 mojom::NavigationClient::CommitNavigationCallback
35 per_navigation_mojo_interface_callback,
Dmitry Gozmanad64b0e2019-02-21 21:43:1436 std::unique_ptr<NavigationClient> navigation_client,
37 bool was_initiated_in_this_frame);
clamy5f342202015-03-18 13:47:5638
David Bokan80f475ac2021-04-23 15:34:0639 static std::unique_ptr<NavigationState> CreateForSynchronousCommit();
Dmitry Gozman0a527132018-09-21 18:01:0440
41 static NavigationState* FromDocumentLoader(
42 blink::WebDocumentLoader* document_loader);
clamy5f342202015-03-18 13:47:5643
Dmitry Gozman9cfe75d2018-09-18 21:36:0844 // True iff the frame's navigation was within the same document.
45 bool WasWithinSameDocument();
46
David Bokan80f475ac2021-04-23 15:34:0647 bool IsForSynchronousCommit();
clamy5f342202015-03-18 13:47:5648
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5149 const mojom::CommonNavigationParams& common_params() const {
50 return *common_params_;
51 }
Lucas Furukawa Gadania9c45682019-07-31 22:05:1452 const mojom::CommitNavigationParams& commit_params() const {
53 return *commit_params_;
54 }
Dmitry Gozman9b890002020-05-27 15:24:4255 bool has_navigation_client() const { return navigation_client_.get(); }
eugenebutcf731b52017-03-17 17:36:3456 void set_was_within_same_document(bool value) {
57 was_within_same_document_ = value;
58 }
clamy5f342202015-03-18 13:47:5659
Dmitry Gozmanad64b0e2019-02-21 21:43:1460 bool was_initiated_in_this_frame() const {
61 return was_initiated_in_this_frame_;
62 }
63
clamy5f342202015-03-18 13:47:5664 void set_transition_type(ui::PageTransition transition) {
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5165 common_params_->transition = transition;
clamy5f342202015-03-18 13:47:5666 }
67
Dmitry Gozman9b890002020-05-27 15:24:4268 void RunCommitNavigationCallback(
arthursonzogni73fe3212020-11-17 13:24:0769 mojom::DidCommitProvisionalLoadParamsPtr params,
Arthur Hemery1f46de02019-01-31 16:41:5370 mojom::DidCommitProvisionalLoadInterfaceParamsPtr interface_params);
71
clamy5f342202015-03-18 13:47:5672 private:
Dmitry Gozman9b890002020-05-27 15:24:4273 NavigationState(mojom::CommonNavigationParamsPtr common_params,
74 mojom::CommitNavigationParamsPtr commit_params,
David Bokan80f475ac2021-04-23 15:34:0675 bool is_for_synchronous_commit,
Dmitry Gozman9b890002020-05-27 15:24:4276 content::mojom::NavigationClient::CommitNavigationCallback
77 commit_callback,
78 std::unique_ptr<NavigationClient> navigation_client,
79 bool was_initiated_in_this_frame);
clamy5f342202015-03-18 13:47:5680
eugenebutcf731b52017-03-17 17:36:3481 bool was_within_same_document_;
clamy5f342202015-03-18 13:47:5682
Dmitry Gozmanad64b0e2019-02-21 21:43:1483 // Indicates whether the navigation was initiated by the same RenderFrame
84 // it is about to commit in. An example would be a link click.
85 // A counter-example would be user typing in the url bar (browser-initiated
86 // navigation), or a link click leading to a process swap (different
87 // RenderFrame instance).
88 // Used to ensure consistent observer notifications about a navigation.
89 bool was_initiated_in_this_frame_;
90
David Bokan80f475ac2021-04-23 15:34:0691 // True if this navigation is for a renderer synchronous commit (e.g. the
92 // synchronous about:blank navigation, same-origin initiated same-document
93 // navigations), rather than using the browser's navigation stack.
94 const bool is_for_synchronous_commit_;
clamy5f342202015-03-18 13:47:5695
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5196 mojom::CommonNavigationParamsPtr common_params_;
clamy5f342202015-03-18 13:47:5697
98 // Note: if IsContentInitiated() is false, whether this navigation should
99 // replace the current entry in the back/forward history list is determined by
100 // the should_replace_current_entry field in |history_params|. Otherwise, use
101 // replacesCurrentHistoryItem() on the WebDataSource.
102 //
103 // TODO(davidben): It would be good to unify these and have only one source
104 // for the two cases. We can plumb this through WebFrame::loadRequest to set
105 // lockBackForwardList on the FrameLoadRequest. However, this breaks process
106 // swaps because FrameLoader::loadWithNavigationAction treats loads before a
107 // FrameLoader has committedFirstRealDocumentLoad as a replacement. (Added for
108 // http://crbug.com/178380).
Lucas Furukawa Gadania9c45682019-07-31 22:05:14109 mojom::CommitNavigationParamsPtr commit_params_;
clamy5f342202015-03-18 13:47:56110
Arthur Hemeryd3011f62018-05-30 10:38:44111 // The NavigationClient interface gives control over the navigation ongoing in
112 // the browser process.
Arthur Hemeryd3011f62018-05-30 10:38:44113 std::unique_ptr<NavigationClient> navigation_client_;
114
clamy6b92fcf2018-06-01 13:51:37115 // Used to notify whether a commit request from the browser process was
116 // successful or not.
Dmitry Gozman9b890002020-05-27 15:24:42117 mojom::NavigationClient::CommitNavigationCallback commit_callback_;
Arthur Hemery1f46de02019-01-31 16:41:53118
Dmitry Gozman0a527132018-09-21 18:01:04119 DISALLOW_COPY_AND_ASSIGN(NavigationState);
clamy5f342202015-03-18 13:47:56120};
121
122} // namespace content
123
Dmitry Gozman0a527132018-09-21 18:01:04124#endif // CONTENT_RENDERER_NAVIGATION_STATE_H_