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, |
Arthur Hemery | 2e079d2 | 2019-01-07 15:45:45 | [diff] [blame] | 39 | std::unique_ptr<NavigationClient> navigation_client); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 40 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 41 | static std::unique_ptr<NavigationState> CreateContentInitiated(); |
| 42 | |
| 43 | static NavigationState* FromDocumentLoader( |
| 44 | blink::WebDocumentLoader* document_loader); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 45 | |
Dmitry Gozman | 9cfe75d | 2018-09-18 21:36:08 | [diff] [blame] | 46 | // 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(); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 51 | |
| 52 | const CommonNavigationParams& common_params() const { return common_params_; } |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 53 | const CommitNavigationParams& commit_params() const { return commit_params_; } |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 54 | bool request_committed() const { return request_committed_; } |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame^] | 55 | bool uses_per_navigation_mojo_interface() const { |
| 56 | return navigation_client_.get(); |
| 57 | } |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 58 | void set_request_committed(bool value) { request_committed_ = value; } |
eugenebut | cf731b5 | 2017-03-17 17:36:34 | [diff] [blame] | 59 | void set_was_within_same_document(bool value) { |
| 60 | was_within_same_document_ = value; |
| 61 | } |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 62 | |
| 63 | void set_transition_type(ui::PageTransition transition) { |
| 64 | common_params_.transition = transition; |
| 65 | } |
| 66 | |
arthursonzogni | 2dbfc509 | 2018-02-27 20:42:09 | [diff] [blame] | 67 | base::TimeTicks time_commit_requested() const { |
| 68 | return time_commit_requested_; |
| 69 | } |
| 70 | |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 71 | // Only used when PerNavigationMojoInterface is enabled. |
| 72 | void set_navigation_client( |
| 73 | std::unique_ptr<NavigationClient> navigation_client_impl) { |
| 74 | navigation_client_ = std::move(navigation_client_impl); |
| 75 | } |
| 76 | |
Arthur Hemery | 43fa80c | 2018-07-05 09:50:08 | [diff] [blame] | 77 | void set_navigation_start(const base::TimeTicks& navigation_start) { |
| 78 | common_params_.navigation_start = navigation_start; |
| 79 | } |
| 80 | |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 81 | void RunCommitNavigationCallback(blink::mojom::CommitResult result); |
| 82 | |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame^] | 83 | void RunPerNavigationInterfaceCommitNavigationCallback( |
| 84 | std::unique_ptr<::FrameHostMsg_DidCommitProvisionalLoad_Params> params, |
| 85 | mojom::DidCommitProvisionalLoadInterfaceParamsPtr interface_params); |
| 86 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 87 | private: |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 88 | NavigationState( |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 89 | const CommonNavigationParams& common_params, |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 90 | const CommitNavigationParams& commit_params, |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 91 | base::TimeTicks time_commit_requested, |
| 92 | bool is_content_initiated, |
Arthur Hemery | 2e079d2 | 2019-01-07 15:45:45 | [diff] [blame] | 93 | content::mojom::FrameNavigationControl::CommitNavigationCallback callback, |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame^] | 94 | content::mojom::NavigationClient::CommitNavigationCallback |
| 95 | per_navigation_mojo_interface_callback, |
Arthur Hemery | 2e079d2 | 2019-01-07 15:45:45 | [diff] [blame] | 96 | std::unique_ptr<NavigationClient> navigation_client); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 97 | |
| 98 | bool request_committed_; |
eugenebut | cf731b5 | 2017-03-17 17:36:34 | [diff] [blame] | 99 | bool was_within_same_document_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 100 | |
| 101 | // True if this navigation was not initiated via WebFrame::LoadRequest. |
| 102 | const bool is_content_initiated_; |
| 103 | |
| 104 | CommonNavigationParams common_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 105 | |
| 106 | // Note: if IsContentInitiated() is false, whether this navigation should |
| 107 | // replace the current entry in the back/forward history list is determined by |
| 108 | // the should_replace_current_entry field in |history_params|. Otherwise, use |
| 109 | // replacesCurrentHistoryItem() on the WebDataSource. |
| 110 | // |
| 111 | // TODO(davidben): It would be good to unify these and have only one source |
| 112 | // for the two cases. We can plumb this through WebFrame::loadRequest to set |
| 113 | // lockBackForwardList on the FrameLoadRequest. However, this breaks process |
| 114 | // swaps because FrameLoader::loadWithNavigationAction treats loads before a |
| 115 | // FrameLoader has committedFirstRealDocumentLoad as a replacement. (Added for |
| 116 | // http://crbug.com/178380). |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 117 | const CommitNavigationParams commit_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 118 | |
arthursonzogni | 2dbfc509 | 2018-02-27 20:42:09 | [diff] [blame] | 119 | // Time when RenderFrameImpl::CommitNavigation() is called. |
| 120 | base::TimeTicks time_commit_requested_; |
| 121 | |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 122 | // The NavigationClient interface gives control over the navigation ongoing in |
| 123 | // the browser process. |
| 124 | // Only used when PerNavigationMojoInterface is enabled. |
| 125 | std::unique_ptr<NavigationClient> navigation_client_; |
| 126 | |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 127 | // Used to notify whether a commit request from the browser process was |
| 128 | // successful or not. |
| 129 | mojom::FrameNavigationControl::CommitNavigationCallback commit_callback_; |
| 130 | |
Arthur Hemery | 1f46de0 | 2019-01-31 16:41:53 | [diff] [blame^] | 131 | // Temporary member meant to be used in place of |commit_callback_| when |
| 132 | // PerNavigationMojoInterface is enabled. Should eventually replace it |
| 133 | // completely. |
| 134 | mojom::NavigationClient::CommitNavigationCallback |
| 135 | per_navigation_mojo_interface_commit_callback_; |
| 136 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 137 | DISALLOW_COPY_AND_ASSIGN(NavigationState); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | } // namespace content |
| 141 | |
Dmitry Gozman | 0a52713 | 2018-09-21 18:01:04 | [diff] [blame] | 142 | #endif // CONTENT_RENDERER_NAVIGATION_STATE_H_ |