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 | |
| 5 | #ifndef CONTENT_RENDERER_NAVIGATION_STATE_IMPL_H_ |
| 6 | #define CONTENT_RENDERER_NAVIGATION_STATE_IMPL_H_ |
| 7 | |
| 8 | #include <string> |
| 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" |
| 13 | #include "content/public/renderer/navigation_state.h" |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 14 | #include "content/renderer/navigation_client.h" |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 15 | #include "third_party/blink/public/web/commit_result.mojom.h" |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 16 | |
| 17 | namespace content { |
| 18 | |
| 19 | class CONTENT_EXPORT NavigationStateImpl : public NavigationState { |
| 20 | public: |
| 21 | ~NavigationStateImpl() override; |
| 22 | |
| 23 | static NavigationStateImpl* CreateBrowserInitiated( |
| 24 | const CommonNavigationParams& common_params, |
arthursonzogni | 2dbfc509 | 2018-02-27 20:42:09 | [diff] [blame] | 25 | const RequestNavigationParams& request_params, |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 26 | base::TimeTicks time_commit_requested, |
| 27 | mojom::FrameNavigationControl::CommitNavigationCallback callback); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 28 | |
| 29 | static NavigationStateImpl* CreateContentInitiated(); |
| 30 | |
Dmitry Gozman | 9cfe75d | 2018-09-18 21:36:08 | [diff] [blame^] | 31 | // Contains the transition type that the browser specified when it |
| 32 | // initiated the load. |
| 33 | ui::PageTransition GetTransitionType(); |
| 34 | |
| 35 | // True iff the frame's navigation was within the same document. |
| 36 | bool WasWithinSameDocument(); |
| 37 | |
| 38 | // True if this navigation was not initiated via WebFrame::LoadRequest. |
| 39 | bool IsContentInitiated(); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 40 | |
| 41 | const CommonNavigationParams& common_params() const { return common_params_; } |
clamy | 57b4b8e | 2015-03-24 13:32:11 | [diff] [blame] | 42 | const RequestNavigationParams& request_params() const { |
| 43 | return request_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 44 | } |
| 45 | bool request_committed() const { return request_committed_; } |
| 46 | void set_request_committed(bool value) { request_committed_ = value; } |
eugenebut | cf731b5 | 2017-03-17 17:36:34 | [diff] [blame] | 47 | void set_was_within_same_document(bool value) { |
| 48 | was_within_same_document_ = value; |
| 49 | } |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 50 | |
| 51 | void set_transition_type(ui::PageTransition transition) { |
| 52 | common_params_.transition = transition; |
| 53 | } |
| 54 | |
arthursonzogni | 2dbfc509 | 2018-02-27 20:42:09 | [diff] [blame] | 55 | base::TimeTicks time_commit_requested() const { |
| 56 | return time_commit_requested_; |
| 57 | } |
| 58 | |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 59 | // Only used when PerNavigationMojoInterface is enabled. |
| 60 | void set_navigation_client( |
| 61 | std::unique_ptr<NavigationClient> navigation_client_impl) { |
| 62 | navigation_client_ = std::move(navigation_client_impl); |
| 63 | } |
| 64 | |
Arthur Hemery | 43fa80c | 2018-07-05 09:50:08 | [diff] [blame] | 65 | void set_navigation_start(const base::TimeTicks& navigation_start) { |
| 66 | common_params_.navigation_start = navigation_start; |
| 67 | } |
| 68 | |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 69 | void RunCommitNavigationCallback(blink::mojom::CommitResult result); |
| 70 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 71 | private: |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 72 | NavigationStateImpl( |
| 73 | const CommonNavigationParams& common_params, |
| 74 | const RequestNavigationParams& request_params, |
| 75 | base::TimeTicks time_commit_requested, |
| 76 | bool is_content_initiated, |
| 77 | content::mojom::FrameNavigationControl::CommitNavigationCallback |
| 78 | callback); |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 79 | |
| 80 | bool request_committed_; |
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 | |
| 83 | // True if this navigation was not initiated via WebFrame::LoadRequest. |
| 84 | const bool is_content_initiated_; |
| 85 | |
| 86 | CommonNavigationParams common_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 87 | |
| 88 | // Note: if IsContentInitiated() is false, whether this navigation should |
| 89 | // replace the current entry in the back/forward history list is determined by |
| 90 | // the should_replace_current_entry field in |history_params|. Otherwise, use |
| 91 | // replacesCurrentHistoryItem() on the WebDataSource. |
| 92 | // |
| 93 | // TODO(davidben): It would be good to unify these and have only one source |
| 94 | // for the two cases. We can plumb this through WebFrame::loadRequest to set |
| 95 | // lockBackForwardList on the FrameLoadRequest. However, this breaks process |
| 96 | // swaps because FrameLoader::loadWithNavigationAction treats loads before a |
| 97 | // FrameLoader has committedFirstRealDocumentLoad as a replacement. (Added for |
| 98 | // http://crbug.com/178380). |
clamy | 57b4b8e | 2015-03-24 13:32:11 | [diff] [blame] | 99 | const RequestNavigationParams request_params_; |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 100 | |
arthursonzogni | 2dbfc509 | 2018-02-27 20:42:09 | [diff] [blame] | 101 | // Time when RenderFrameImpl::CommitNavigation() is called. |
| 102 | base::TimeTicks time_commit_requested_; |
| 103 | |
Arthur Hemery | d3011f6 | 2018-05-30 10:38:44 | [diff] [blame] | 104 | // The NavigationClient interface gives control over the navigation ongoing in |
| 105 | // the browser process. |
| 106 | // Only used when PerNavigationMojoInterface is enabled. |
| 107 | std::unique_ptr<NavigationClient> navigation_client_; |
| 108 | |
clamy | 6b92fcf | 2018-06-01 13:51:37 | [diff] [blame] | 109 | // Used to notify whether a commit request from the browser process was |
| 110 | // successful or not. |
| 111 | mojom::FrameNavigationControl::CommitNavigationCallback commit_callback_; |
| 112 | |
clamy | 5f34220 | 2015-03-18 13:47:56 | [diff] [blame] | 113 | DISALLOW_COPY_AND_ASSIGN(NavigationStateImpl); |
| 114 | }; |
| 115 | |
| 116 | } // namespace content |
| 117 | |
| 118 | #endif // CONTENT_RENDERER_NAVIGATION_STATE_IMPL_H_ |