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