blob: bcbc454b959c0fa09f8e2a6546f741e1dc0bc755 [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
17struct FrameHostMsg_DidCommitProvisionalLoad_Params;
clamy5f342202015-03-18 13:47:5618
Dmitry Gozman0a527132018-09-21 18:01:0419namespace blink {
20class WebDocumentLoader;
Arthur Hemery1f46de02019-01-31 16:41:5321
22namespace mojom {
23enum class CommitResult;
24}
Dmitry Gozman0a527132018-09-21 18:01:0425}
26
clamy5f342202015-03-18 13:47:5627namespace content {
28
Dmitry Gozman0a527132018-09-21 18:01:0429class CONTENT_EXPORT NavigationState {
clamy5f342202015-03-18 13:47:5630 public:
Dmitry Gozman0a527132018-09-21 18:01:0431 ~NavigationState();
clamy5f342202015-03-18 13:47:5632
Dmitry Gozman0a527132018-09-21 18:01:0433 static std::unique_ptr<NavigationState> CreateBrowserInitiated(
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5134 mojom::CommonNavigationParamsPtr common_params,
Lucas Furukawa Gadania9c45682019-07-31 22:05:1435 mojom::CommitNavigationParamsPtr commit_params,
Arthur Hemery1f46de02019-01-31 16:41:5336 mojom::NavigationClient::CommitNavigationCallback
37 per_navigation_mojo_interface_callback,
Dmitry Gozmanad64b0e2019-02-21 21:43:1438 std::unique_ptr<NavigationClient> navigation_client,
39 bool was_initiated_in_this_frame);
clamy5f342202015-03-18 13:47:5640
Dmitry Gozman0a527132018-09-21 18:01:0441 static std::unique_ptr<NavigationState> CreateContentInitiated();
42
43 static NavigationState* FromDocumentLoader(
44 blink::WebDocumentLoader* document_loader);
clamy5f342202015-03-18 13:47:5645
Dmitry Gozman9cfe75d2018-09-18 21:36:0846 // True iff the frame's navigation was within the same document.
47 bool WasWithinSameDocument();
48
49 // True if this navigation was not initiated via WebFrame::LoadRequest.
50 bool IsContentInitiated();
clamy5f342202015-03-18 13:47:5651
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5152 const mojom::CommonNavigationParams& common_params() const {
53 return *common_params_;
54 }
Lucas Furukawa Gadania9c45682019-07-31 22:05:1455 const mojom::CommitNavigationParams& commit_params() const {
56 return *commit_params_;
57 }
Dmitry Gozman9b890002020-05-27 15:24:4258 bool has_navigation_client() const { return navigation_client_.get(); }
eugenebutcf731b52017-03-17 17:36:3459 void set_was_within_same_document(bool value) {
60 was_within_same_document_ = value;
61 }
clamy5f342202015-03-18 13:47:5662
Dmitry Gozmanad64b0e2019-02-21 21:43:1463 bool was_initiated_in_this_frame() const {
64 return was_initiated_in_this_frame_;
65 }
66
clamy5f342202015-03-18 13:47:5667 void set_transition_type(ui::PageTransition transition) {
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5168 common_params_->transition = transition;
clamy5f342202015-03-18 13:47:5669 }
70
Dmitry Gozman9b890002020-05-27 15:24:4271 void RunCommitNavigationCallback(
Arthur Hemery1f46de02019-01-31 16:41:5372 std::unique_ptr<::FrameHostMsg_DidCommitProvisionalLoad_Params> params,
73 mojom::DidCommitProvisionalLoadInterfaceParamsPtr interface_params);
74
clamy5f342202015-03-18 13:47:5675 private:
Dmitry Gozman9b890002020-05-27 15:24:4276 NavigationState(mojom::CommonNavigationParamsPtr common_params,
77 mojom::CommitNavigationParamsPtr commit_params,
78 bool is_content_initiated,
79 content::mojom::NavigationClient::CommitNavigationCallback
80 commit_callback,
81 std::unique_ptr<NavigationClient> navigation_client,
82 bool was_initiated_in_this_frame);
clamy5f342202015-03-18 13:47:5683
eugenebutcf731b52017-03-17 17:36:3484 bool was_within_same_document_;
clamy5f342202015-03-18 13:47:5685
Dmitry Gozmanad64b0e2019-02-21 21:43:1486 // Indicates whether the navigation was initiated by the same RenderFrame
87 // it is about to commit in. An example would be a link click.
88 // A counter-example would be user typing in the url bar (browser-initiated
89 // navigation), or a link click leading to a process swap (different
90 // RenderFrame instance).
91 // Used to ensure consistent observer notifications about a navigation.
92 bool was_initiated_in_this_frame_;
93
clamy5f342202015-03-18 13:47:5694 // True if this navigation was not initiated via WebFrame::LoadRequest.
95 const bool is_content_initiated_;
96
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5197 mojom::CommonNavigationParamsPtr common_params_;
clamy5f342202015-03-18 13:47:5698
99 // Note: if IsContentInitiated() is false, whether this navigation should
100 // replace the current entry in the back/forward history list is determined by
101 // the should_replace_current_entry field in |history_params|. Otherwise, use
102 // replacesCurrentHistoryItem() on the WebDataSource.
103 //
104 // TODO(davidben): It would be good to unify these and have only one source
105 // for the two cases. We can plumb this through WebFrame::loadRequest to set
106 // lockBackForwardList on the FrameLoadRequest. However, this breaks process
107 // swaps because FrameLoader::loadWithNavigationAction treats loads before a
108 // FrameLoader has committedFirstRealDocumentLoad as a replacement. (Added for
109 // http://crbug.com/178380).
Lucas Furukawa Gadania9c45682019-07-31 22:05:14110 mojom::CommitNavigationParamsPtr commit_params_;
clamy5f342202015-03-18 13:47:56111
Arthur Hemeryd3011f62018-05-30 10:38:44112 // The NavigationClient interface gives control over the navigation ongoing in
113 // the browser process.
114 // Only used when PerNavigationMojoInterface is enabled.
115 std::unique_ptr<NavigationClient> navigation_client_;
116
clamy6b92fcf2018-06-01 13:51:37117 // Used to notify whether a commit request from the browser process was
118 // successful or not.
Dmitry Gozman9b890002020-05-27 15:24:42119 mojom::NavigationClient::CommitNavigationCallback commit_callback_;
Arthur Hemery1f46de02019-01-31 16:41:53120
Dmitry Gozman0a527132018-09-21 18:01:04121 DISALLOW_COPY_AND_ASSIGN(NavigationState);
clamy5f342202015-03-18 13:47:56122};
123
124} // namespace content
125
Dmitry Gozman0a527132018-09-21 18:01:04126#endif // CONTENT_RENDERER_NAVIGATION_STATE_H_