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" |
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 | |
| 16 | struct FrameHostMsg_DidCommitProvisionalLoad_Params; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 17 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 18 | namespace blink { |
| 19 | class WebDocumentLoader; |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 20 | |
| 21 | namespace mojom { |
| 22 | enum class CommitResult; |
| 23 | } |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 24 | } |
| 25 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 26 | namespace content { |
| 27 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 28 | class CONTENT_EXPORT NavigationState { |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 29 | public: |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 30 | ~NavigationState(); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 31 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 32 | static std::unique_ptr<NavigationState> CreateBrowserInitiated( |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 33 | const CommonNavigationParams& common_params, |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 34 | const CommitNavigationParams& commit_params, |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 35 | base::TimeTicks time_commit_requested, |
Arthur Hemery | 2e079d2 | 2019-01-07 15:45:45 | [diff] [blame] | 36 | mojom::FrameNavigationControl::CommitNavigationCallback callback, |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 37 | mojom::NavigationClient::CommitNavigationCallback |
| 38 | per_navigation_mojo_interface_callback, |
Dmitry Gozman | ad64b0e | 2019-02-21 21:43:14 | [diff] [blame] | 39 | std::unique_ptr<NavigationClient> navigation_client, |
| 40 | bool was_initiated_in_this_frame); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 41 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 42 | static std::unique_ptr<NavigationState> CreateContentInitiated(); |
| 43 | |
| 44 | static NavigationState* FromDocumentLoader( |
| 45 | blink::WebDocumentLoader* document_loader); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 46 | |
Dmitry Gozman | 9cfe75d | 2018-09-18 21:36:08 | [diff] [blame] | 47 | // 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(); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 52 | |
| 53 | const CommonNavigationParams& common_params() const { return common_params_; } |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 54 | const CommitNavigationParams& commit_params() const { return commit_params_; } |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 55 | bool request_committed() const { return request_committed_; } |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 56 | bool uses_per_navigation_mojo_interface() const { |
| 57 | return navigation_client_.get(); |
| 58 | } |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 59 | void set_request_committed(bool value) { request_committed_ = value; } |
eugenebut | cf731b5 | 2017-03-17 17:36:34 | [diff] [blame] | 60 | void set_was_within_same_document(bool value) { |
| 61 | was_within_same_document_ = value; |
| 62 | } |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 63 | |
Dmitry Gozman | ad64b0e | 2019-02-21 21:43:14 | [diff] [blame] | 64 | bool was_initiated_in_this_frame() const { |
| 65 | return was_initiated_in_this_frame_; |
| 66 | } |
| 67 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 68 | void set_transition_type(ui::PageTransition transition) { |
| 69 | common_params_.transition = transition; |
| 70 | } |
| 71 | |
arthursonzogni | 2dbfc509 | 2018-02-27 20:42:09 | [diff] [blame] | 72 | base::TimeTicks time_commit_requested() const { |
| 73 | return time_commit_requested_; |
| 74 | } |
| 75 | |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 76 | // 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 Hemery | 43fa80c | 2018-07-05 09:50:08 | [diff] [blame] | 82 | void set_navigation_start(const base::TimeTicks& navigation_start) { |
| 83 | common_params_.navigation_start = navigation_start; |
| 84 | } |
| 85 | |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 86 | void RunCommitNavigationCallback(blink::mojom::CommitResult result); |
| 87 | |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 88 | void RunPerNavigationInterfaceCommitNavigationCallback( |
| 89 | std::unique_ptr<::FrameHostMsg_DidCommitProvisionalLoad_Params> params, |
| 90 | mojom::DidCommitProvisionalLoadInterfaceParamsPtr interface_params); |
| 91 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 92 | private: |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 93 | NavigationState( |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 94 | const CommonNavigationParams& common_params, |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 95 | const CommitNavigationParams& commit_params, |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 96 | base::TimeTicks time_commit_requested, |
| 97 | bool is_content_initiated, |
Arthur Hemery | 2e079d2 | 2019-01-07 15:45:45 | [diff] [blame] | 98 | content::mojom::FrameNavigationControl::CommitNavigationCallback callback, |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 99 | content::mojom::NavigationClient::CommitNavigationCallback |
| 100 | per_navigation_mojo_interface_callback, |
Dmitry Gozman | ad64b0e | 2019-02-21 21:43:14 | [diff] [blame] | 101 | std::unique_ptr<NavigationClient> navigation_client, |
| 102 | bool was_initiated_in_this_frame); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 103 | |
| 104 | bool request_committed_; |
eugenebut | cf731b5 | 2017-03-17 17:36:34 | [diff] [blame] | 105 | bool was_within_same_document_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 106 | |
Dmitry Gozman | ad64b0e | 2019-02-21 21:43:14 | [diff] [blame] | 107 | // 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 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 115 | // True if this navigation was not initiated via WebFrame::LoadRequest. |
| 116 | const bool is_content_initiated_; |
| 117 | |
| 118 | CommonNavigationParams common_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 119 | |
| 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 Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 131 | const CommitNavigationParams commit_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 132 | |
arthursonzogni | 2dbfc509 | 2018-02-27 20:42:09 | [diff] [blame] | 133 | // Time when RenderFrameImpl::CommitNavigation() is called. |
| 134 | base::TimeTicks time_commit_requested_; |
| 135 | |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 136 | // 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 | |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 141 | // Used to notify whether a commit request from the browser process was |
| 142 | // successful or not. |
| 143 | mojom::FrameNavigationControl::CommitNavigationCallback commit_callback_; |
| 144 | |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame] | 145 | // 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 Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 151 | DISALLOW_COPY_AND_ASSIGN(NavigationState); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | } // namespace content |
| 155 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 156 | #endif // CONTENT_RENDERER_NAVIGATION_STATE_H_ |