blob: 20e66fa91ab0fcfee285540cdaafd29b051388fc [file] [log] [blame]
clamy5f342202015-03-18 13:47:561// 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
avi1023d012015-12-25 02:39:1410#include "base/macros.h"
clamy6b92fcf2018-06-01 13:51:3711#include "content/common/frame.mojom.h"
clamy5f342202015-03-18 13:47:5612#include "content/common/navigation_params.h"
13#include "content/public/renderer/navigation_state.h"
Arthur Hemeryd3011f62018-05-30 10:38:4414#include "content/renderer/navigation_client.h"
clamy6b92fcf2018-06-01 13:51:3715#include "third_party/blink/public/web/commit_result.mojom.h"
clamy5f342202015-03-18 13:47:5616
17namespace content {
18
19class CONTENT_EXPORT NavigationStateImpl : public NavigationState {
20 public:
21 ~NavigationStateImpl() override;
22
23 static NavigationStateImpl* CreateBrowserInitiated(
24 const CommonNavigationParams& common_params,
arthursonzogni2dbfc5092018-02-27 20:42:0925 const RequestNavigationParams& request_params,
clamy6b92fcf2018-06-01 13:51:3726 base::TimeTicks time_commit_requested,
27 mojom::FrameNavigationControl::CommitNavigationCallback callback);
clamy5f342202015-03-18 13:47:5628
29 static NavigationStateImpl* CreateContentInitiated();
30
Dmitry Gozman9cfe75d2018-09-18 21:36:0831 // 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();
clamy5f342202015-03-18 13:47:5640
41 const CommonNavigationParams& common_params() const { return common_params_; }
clamy57b4b8e2015-03-24 13:32:1142 const RequestNavigationParams& request_params() const {
43 return request_params_;
clamy5f342202015-03-18 13:47:5644 }
45 bool request_committed() const { return request_committed_; }
46 void set_request_committed(bool value) { request_committed_ = value; }
eugenebutcf731b52017-03-17 17:36:3447 void set_was_within_same_document(bool value) {
48 was_within_same_document_ = value;
49 }
clamy5f342202015-03-18 13:47:5650
51 void set_transition_type(ui::PageTransition transition) {
52 common_params_.transition = transition;
53 }
54
arthursonzogni2dbfc5092018-02-27 20:42:0955 base::TimeTicks time_commit_requested() const {
56 return time_commit_requested_;
57 }
58
Arthur Hemeryd3011f62018-05-30 10:38:4459 // 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 Hemery43fa80c2018-07-05 09:50:0865 void set_navigation_start(const base::TimeTicks& navigation_start) {
66 common_params_.navigation_start = navigation_start;
67 }
68
clamy6b92fcf2018-06-01 13:51:3769 void RunCommitNavigationCallback(blink::mojom::CommitResult result);
70
clamy5f342202015-03-18 13:47:5671 private:
clamy6b92fcf2018-06-01 13:51:3772 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);
clamy5f342202015-03-18 13:47:5679
80 bool request_committed_;
eugenebutcf731b52017-03-17 17:36:3481 bool was_within_same_document_;
clamy5f342202015-03-18 13:47:5682
83 // True if this navigation was not initiated via WebFrame::LoadRequest.
84 const bool is_content_initiated_;
85
86 CommonNavigationParams common_params_;
clamy5f342202015-03-18 13:47:5687
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).
clamy57b4b8e2015-03-24 13:32:1199 const RequestNavigationParams request_params_;
clamy5f342202015-03-18 13:47:56100
arthursonzogni2dbfc5092018-02-27 20:42:09101 // Time when RenderFrameImpl::CommitNavigation() is called.
102 base::TimeTicks time_commit_requested_;
103
Arthur Hemeryd3011f62018-05-30 10:38:44104 // 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
clamy6b92fcf2018-06-01 13:51:37109 // Used to notify whether a commit request from the browser process was
110 // successful or not.
111 mojom::FrameNavigationControl::CommitNavigationCallback commit_callback_;
112
clamy5f342202015-03-18 13:47:56113 DISALLOW_COPY_AND_ASSIGN(NavigationStateImpl);
114};
115
116} // namespace content
117
118#endif // CONTENT_RENDERER_NAVIGATION_STATE_IMPL_H_