clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 1 | // 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 Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 5 | #ifndef CONTENT_RENDERER_NAVIGATION_STATE_H_ |
| 6 | #define CONTENT_RENDERER_NAVIGATION_STATE_H_ |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 7 | |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 8 | #include <memory> |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 9 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 10 | #include "base/macros.h" |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 11 | #include "content/common/frame.mojom.h" |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 12 | #include "content/common/navigation_params.h" |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 13 | #include "content/common/navigation_params.mojom.h" |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 14 | #include "content/renderer/navigation_client.h" |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 15 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 16 | namespace blink { |
| 17 | class WebDocumentLoader; |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 18 | |
| 19 | namespace mojom { |
| 20 | enum class CommitResult; |
| 21 | } |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 22 | } |
| 23 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 24 | namespace content { |
| 25 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 26 | class CONTENT_EXPORT NavigationState { |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 27 | public: |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 28 | ~NavigationState(); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 29 | |
David Bokan | 80f475ac | 2021-04-23 15:34:06 | [diff] [blame] | 30 | static std::unique_ptr<NavigationState> Create( |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 31 | mojom::CommonNavigationParamsPtr common_params, |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 32 | mojom::CommitNavigationParamsPtr commit_params, |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 33 | mojom::NavigationClient::CommitNavigationCallback |
| 34 | per_navigation_mojo_interface_callback, |
Dmitry Gozman | ad64b0e | 2019-02-21 21:43:14 | [diff] [blame] | 35 | std::unique_ptr<NavigationClient> navigation_client, |
| 36 | bool was_initiated_in_this_frame); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 37 | |
David Bokan | 80f475ac | 2021-04-23 15:34:06 | [diff] [blame] | 38 | static std::unique_ptr<NavigationState> CreateForSynchronousCommit(); |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 39 | |
| 40 | static NavigationState* FromDocumentLoader( |
| 41 | blink::WebDocumentLoader* document_loader); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 42 | |
Dmitry Gozman | 9cfe75d | 2018-09-18 21:36:08 | [diff] [blame] | 43 | // True iff the frame's navigation was within the same document. |
| 44 | bool WasWithinSameDocument(); |
| 45 | |
David Bokan | 80f475ac | 2021-04-23 15:34:06 | [diff] [blame] | 46 | bool IsForSynchronousCommit(); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 47 | |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 48 | const mojom::CommonNavigationParams& common_params() const { |
| 49 | return *common_params_; |
| 50 | } |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 51 | const mojom::CommitNavigationParams& commit_params() const { |
| 52 | return *commit_params_; |
| 53 | } |
Dmitry Gozman | 9b89000 | 2020-05-27 15:24:42 | [diff] [blame] | 54 | bool has_navigation_client() const { return navigation_client_.get(); } |
eugenebut | cf731b5 | 2017-03-17 17:36:34 | [diff] [blame] | 55 | void set_was_within_same_document(bool value) { |
| 56 | was_within_same_document_ = value; |
| 57 | } |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 58 | |
Dmitry Gozman | ad64b0e | 2019-02-21 21:43:14 | [diff] [blame] | 59 | bool was_initiated_in_this_frame() const { |
| 60 | return was_initiated_in_this_frame_; |
| 61 | } |
| 62 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 63 | void set_transition_type(ui::PageTransition transition) { |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 64 | common_params_->transition = transition; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 65 | } |
| 66 | |
Dmitry Gozman | 9b89000 | 2020-05-27 15:24:42 | [diff] [blame] | 67 | void RunCommitNavigationCallback( |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 68 | mojom::DidCommitProvisionalLoadParamsPtr params, |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 69 | mojom::DidCommitProvisionalLoadInterfaceParamsPtr interface_params); |
| 70 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 71 | private: |
Dmitry Gozman | 9b89000 | 2020-05-27 15:24:42 | [diff] [blame] | 72 | NavigationState(mojom::CommonNavigationParamsPtr common_params, |
| 73 | mojom::CommitNavigationParamsPtr commit_params, |
David Bokan | 80f475ac | 2021-04-23 15:34:06 | [diff] [blame] | 74 | bool is_for_synchronous_commit, |
Dmitry Gozman | 9b89000 | 2020-05-27 15:24:42 | [diff] [blame] | 75 | content::mojom::NavigationClient::CommitNavigationCallback |
| 76 | commit_callback, |
| 77 | std::unique_ptr<NavigationClient> navigation_client, |
| 78 | bool was_initiated_in_this_frame); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 79 | |
eugenebut | cf731b5 | 2017-03-17 17:36:34 | [diff] [blame] | 80 | bool was_within_same_document_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 81 | |
Dmitry Gozman | ad64b0e | 2019-02-21 21:43:14 | [diff] [blame] | 82 | // 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 Bokan | 80f475ac | 2021-04-23 15:34:06 | [diff] [blame] | 90 | // 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_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 94 | |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 95 | mojom::CommonNavigationParamsPtr common_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 96 | |
| 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 Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 108 | mojom::CommitNavigationParamsPtr commit_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 109 | |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 110 | // The NavigationClient interface gives control over the navigation ongoing in |
| 111 | // the browser process. |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 112 | std::unique_ptr<NavigationClient> navigation_client_; |
| 113 | |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 114 | // Used to notify whether a commit request from the browser process was |
| 115 | // successful or not. |
Dmitry Gozman | 9b89000 | 2020-05-27 15:24:42 | [diff] [blame] | 116 | mojom::NavigationClient::CommitNavigationCallback commit_callback_; |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 117 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 118 | DISALLOW_COPY_AND_ASSIGN(NavigationState); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | } // namespace content |
| 122 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 123 | #endif // CONTENT_RENDERER_NAVIGATION_STATE_H_ |