blob: f8e465da3b38b4db7ffec79f5ea17865f9d2b029 [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"
Arthur Hemeryd3011f62018-05-30 10:38:4414#include "content/renderer/navigation_client.h"
Arthur Hemery1f46de02019-01-31 16:41:5315
16struct FrameHostMsg_DidCommitProvisionalLoad_Params;
clamy5f342202015-03-18 13:47:5617
Dmitry Gozman0a527132018-09-21 18:01:0418namespace blink {
19class WebDocumentLoader;
Arthur Hemery1f46de02019-01-31 16:41:5320
21namespace mojom {
22enum class CommitResult;
23}
Dmitry Gozman0a527132018-09-21 18:01:0424}
25
clamy5f342202015-03-18 13:47:5626namespace content {
27
Dmitry Gozman0a527132018-09-21 18:01:0428class CONTENT_EXPORT NavigationState {
clamy5f342202015-03-18 13:47:5629 public:
Dmitry Gozman0a527132018-09-21 18:01:0430 ~NavigationState();
clamy5f342202015-03-18 13:47:5631
Dmitry Gozman0a527132018-09-21 18:01:0432 static std::unique_ptr<NavigationState> CreateBrowserInitiated(
clamy5f342202015-03-18 13:47:5633 const CommonNavigationParams& common_params,
Nasko Oskovc36327d2019-01-03 23:23:0434 const CommitNavigationParams& commit_params,
clamy6b92fcf2018-06-01 13:51:3735 base::TimeTicks time_commit_requested,
Arthur Hemery2e079d22019-01-07 15:45:4536 mojom::FrameNavigationControl::CommitNavigationCallback callback,
Arthur Hemery1f46de02019-01-31 16:41:5337 mojom::NavigationClient::CommitNavigationCallback
38 per_navigation_mojo_interface_callback,
Dmitry Gozmanad64b0e2019-02-21 21:43:1439 std::unique_ptr<NavigationClient> navigation_client,
40 bool was_initiated_in_this_frame);
clamy5f342202015-03-18 13:47:5641
Dmitry Gozman0a527132018-09-21 18:01:0442 static std::unique_ptr<NavigationState> CreateContentInitiated();
43
44 static NavigationState* FromDocumentLoader(
45 blink::WebDocumentLoader* document_loader);
clamy5f342202015-03-18 13:47:5646
Dmitry Gozman9cfe75d2018-09-18 21:36:0847 // True iff the frame's navigation was within the same document.
48 bool WasWithinSameDocument();
49
50 // True if this navigation was not initiated via WebFrame::LoadRequest.
51 bool IsContentInitiated();
clamy5f342202015-03-18 13:47:5652
53 const CommonNavigationParams& common_params() const { return common_params_; }
Nasko Oskovc36327d2019-01-03 23:23:0454 const CommitNavigationParams& commit_params() const { return commit_params_; }
clamy5f342202015-03-18 13:47:5655 bool request_committed() const { return request_committed_; }
Arthur Hemery1f46de02019-01-31 16:41:5356 bool uses_per_navigation_mojo_interface() const {
57 return navigation_client_.get();
58 }
clamy5f342202015-03-18 13:47:5659 void set_request_committed(bool value) { request_committed_ = value; }
eugenebutcf731b52017-03-17 17:36:3460 void set_was_within_same_document(bool value) {
61 was_within_same_document_ = value;
62 }
clamy5f342202015-03-18 13:47:5663
Dmitry Gozmanad64b0e2019-02-21 21:43:1464 bool was_initiated_in_this_frame() const {
65 return was_initiated_in_this_frame_;
66 }
67
clamy5f342202015-03-18 13:47:5668 void set_transition_type(ui::PageTransition transition) {
69 common_params_.transition = transition;
70 }
71
arthursonzogni2dbfc5092018-02-27 20:42:0972 base::TimeTicks time_commit_requested() const {
73 return time_commit_requested_;
74 }
75
Arthur Hemeryd3011f62018-05-30 10:38:4476 // Only used when PerNavigationMojoInterface is enabled.
77 void set_navigation_client(
78 std::unique_ptr<NavigationClient> navigation_client_impl) {
79 navigation_client_ = std::move(navigation_client_impl);
80 }
81
Arthur Hemery43fa80c2018-07-05 09:50:0882 void set_navigation_start(const base::TimeTicks& navigation_start) {
83 common_params_.navigation_start = navigation_start;
84 }
85
clamy6b92fcf2018-06-01 13:51:3786 void RunCommitNavigationCallback(blink::mojom::CommitResult result);
87
Arthur Hemery1f46de02019-01-31 16:41:5388 void RunPerNavigationInterfaceCommitNavigationCallback(
89 std::unique_ptr<::FrameHostMsg_DidCommitProvisionalLoad_Params> params,
90 mojom::DidCommitProvisionalLoadInterfaceParamsPtr interface_params);
91
clamy5f342202015-03-18 13:47:5692 private:
Dmitry Gozman0a527132018-09-21 18:01:0493 NavigationState(
clamy6b92fcf2018-06-01 13:51:3794 const CommonNavigationParams& common_params,
Nasko Oskovc36327d2019-01-03 23:23:0495 const CommitNavigationParams& commit_params,
clamy6b92fcf2018-06-01 13:51:3796 base::TimeTicks time_commit_requested,
97 bool is_content_initiated,
Arthur Hemery2e079d22019-01-07 15:45:4598 content::mojom::FrameNavigationControl::CommitNavigationCallback callback,
Arthur Hemery1f46de02019-01-31 16:41:5399 content::mojom::NavigationClient::CommitNavigationCallback
100 per_navigation_mojo_interface_callback,
Dmitry Gozmanad64b0e2019-02-21 21:43:14101 std::unique_ptr<NavigationClient> navigation_client,
102 bool was_initiated_in_this_frame);
clamy5f342202015-03-18 13:47:56103
104 bool request_committed_;
eugenebutcf731b52017-03-17 17:36:34105 bool was_within_same_document_;
clamy5f342202015-03-18 13:47:56106
Dmitry Gozmanad64b0e2019-02-21 21:43:14107 // Indicates whether the navigation was initiated by the same RenderFrame
108 // it is about to commit in. An example would be a link click.
109 // A counter-example would be user typing in the url bar (browser-initiated
110 // navigation), or a link click leading to a process swap (different
111 // RenderFrame instance).
112 // Used to ensure consistent observer notifications about a navigation.
113 bool was_initiated_in_this_frame_;
114
clamy5f342202015-03-18 13:47:56115 // True if this navigation was not initiated via WebFrame::LoadRequest.
116 const bool is_content_initiated_;
117
118 CommonNavigationParams common_params_;
clamy5f342202015-03-18 13:47:56119
120 // Note: if IsContentInitiated() is false, whether this navigation should
121 // replace the current entry in the back/forward history list is determined by
122 // the should_replace_current_entry field in |history_params|. Otherwise, use
123 // replacesCurrentHistoryItem() on the WebDataSource.
124 //
125 // TODO(davidben): It would be good to unify these and have only one source
126 // for the two cases. We can plumb this through WebFrame::loadRequest to set
127 // lockBackForwardList on the FrameLoadRequest. However, this breaks process
128 // swaps because FrameLoader::loadWithNavigationAction treats loads before a
129 // FrameLoader has committedFirstRealDocumentLoad as a replacement. (Added for
130 // http://crbug.com/178380).
Nasko Oskovc36327d2019-01-03 23:23:04131 const CommitNavigationParams commit_params_;
clamy5f342202015-03-18 13:47:56132
arthursonzogni2dbfc5092018-02-27 20:42:09133 // Time when RenderFrameImpl::CommitNavigation() is called.
134 base::TimeTicks time_commit_requested_;
135
Arthur Hemeryd3011f62018-05-30 10:38:44136 // The NavigationClient interface gives control over the navigation ongoing in
137 // the browser process.
138 // Only used when PerNavigationMojoInterface is enabled.
139 std::unique_ptr<NavigationClient> navigation_client_;
140
clamy6b92fcf2018-06-01 13:51:37141 // Used to notify whether a commit request from the browser process was
142 // successful or not.
143 mojom::FrameNavigationControl::CommitNavigationCallback commit_callback_;
144
Arthur Hemery1f46de02019-01-31 16:41:53145 // Temporary member meant to be used in place of |commit_callback_| when
146 // PerNavigationMojoInterface is enabled. Should eventually replace it
147 // completely.
148 mojom::NavigationClient::CommitNavigationCallback
149 per_navigation_mojo_interface_commit_callback_;
150
Dmitry Gozman0a527132018-09-21 18:01:04151 DISALLOW_COPY_AND_ASSIGN(NavigationState);
clamy5f342202015-03-18 13:47:56152};
153
154} // namespace content
155
Dmitry Gozman0a527132018-09-21 18:01:04156#endif // CONTENT_RENDERER_NAVIGATION_STATE_H_