Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.h

Issue 1269813002: Add a NavigationThrottle to the public content/ interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@navigation-api
Patch Set: Addressed comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
7 7
8 #include "content/public/browser/navigation_handle.h" 8 #include "content/public/browser/navigation_handle.h"
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
12 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/public/browser/navigation_throttle.h"
13 #include "url/gurl.h" 15 #include "url/gurl.h"
14 16
15 namespace content { 17 namespace content {
16 18
17 class NavigatorDelegate; 19 class NavigatorDelegate;
18 struct NavigationRequestInfo; 20 struct NavigationRequestInfo;
19 21
20 // This class keeps track of a single navigation. It is created upon receipt of 22 // This class keeps track of a single navigation. It is created upon receipt of
21 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns 23 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns
22 // the newly created NavigationHandleImpl as long as the navigation is ongoing. 24 // the newly created NavigationHandleImpl as long as the navigation is ongoing.
(...skipping 22 matching lines...) Expand all
45 // NavigationRequest. It is then owned by the NavigationRequest until the 47 // NavigationRequest. It is then owned by the NavigationRequest until the
46 // navigation is ready to commit. The NavigationHandleImpl ownership is then 48 // navigation is ready to commit. The NavigationHandleImpl ownership is then
47 // transferred to the RenderFrameHost in which the navigation will commit. 49 // transferred to the RenderFrameHost in which the navigation will commit.
48 // 50 //
49 // When PlzNavigate is enabled, the NavigationHandleImpl will never be reset 51 // When PlzNavigate is enabled, the NavigationHandleImpl will never be reset
50 // following the receipt of a DidStartProvisionalLoad IPC. There are also no 52 // following the receipt of a DidStartProvisionalLoad IPC. There are also no
51 // transferring navigations. The other causes of NavigationHandleImpl reset in 53 // transferring navigations. The other causes of NavigationHandleImpl reset in
52 // the RenderFrameHost still apply. 54 // the RenderFrameHost still apply.
53 class CONTENT_EXPORT NavigationHandleImpl : public NavigationHandle { 55 class CONTENT_EXPORT NavigationHandleImpl : public NavigationHandle {
54 public: 56 public:
55 static scoped_ptr<NavigationHandleImpl> Create(const GURL& url,
56 const bool is_main_frame,
57 NavigatorDelegate* delegate);
58
59 ~NavigationHandleImpl() override; 57 ~NavigationHandleImpl() override;
60 58
61 // NavigationHandle implementation: 59 // NavigationHandle implementation:
62 const GURL& GetURL() const override; 60 const GURL& GetURL() override;
63 net::Error GetNetErrorCode() const override; 61 WebContents* GetWebContents() override;
64 bool IsInMainFrame() const override; 62 bool IsInMainFrame() override;
65 bool HasCommittedDocument() const override; 63 bool IsPost() override;
66 bool HasCommittedErrorPage() const override; 64 const Referrer& GetReferrer() override;
65 bool HasUserGesture() override;
66 ui::PageTransition GetPageTransition() override;
67 bool IsExternalProtocol() override;
68 net::Error GetNetErrorCode() override;
69 bool HasCommittedDocument() override;
70 bool HasCommittedErrorPage() override;
71 void RegisterThrottleForTesting(
72 scoped_ptr<NavigationThrottle> navigation_throttle) override;
67 73
68 void set_net_error_code(net::Error net_error_code) { 74 void set_net_error_code(net::Error net_error_code) {
69 net_error_code_ = net_error_code; 75 net_error_code_ = net_error_code;
70 } 76 }
71 77
72 // Returns whether the navigation is currently being transferred from one 78 // Returns whether the navigation is currently being transferred from one
73 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC 79 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC
74 // for the navigation URL, received in the new RenderFrameHost, should not 80 // for the navigation URL, received in the new RenderFrameHost, should not
75 // indicate the start of a new navigation in that case. 81 // indicate the start of a new navigation in that case.
76 bool is_transferring() const { return is_transferring_; } 82 bool is_transferring() const { return is_transferring_; }
77 void set_is_transferring(bool is_transferring) { 83 void set_is_transferring(bool is_transferring) {
78 is_transferring_ = is_transferring; 84 is_transferring_ = is_transferring;
79 } 85 }
80 86
87 void set_web_contents(WebContents* web_contents) {
88 web_contents_ = web_contents;
89 }
90
91 // Called when the URLRequest will start in the network stack.
92 NavigationThrottle::ThrottleCheckResult WillStartRequest(
93 bool is_post,
94 const Referrer& sanitized_referrer,
95 bool has_user_gesture,
96 ui::PageTransition transition,
97 bool is_external_protocol);
98
99 // Called when the URLRequest will be redirected in the network stack.
100 NavigationThrottle::ThrottleCheckResult WillRedirectRequest(
101 const GURL& new_url,
102 bool new_method_is_post,
103 const GURL& new_referrer_url,
104 bool new_is_external_protocol);
105
81 // Called when the navigation was redirected. This will update the |url_| and 106 // Called when the navigation was redirected. This will update the |url_| and
82 // inform the delegate. 107 // inform the delegate.
83 void DidRedirectNavigation(const GURL& new_url); 108 void DidRedirectNavigation(const GURL& new_url);
84 109
85 // Called when the navigation was committed. This will update the |state_| 110 // Called when the navigation was committed. This will update the |state_|
86 // and inform the delegate, 111 // and inform the delegate,
87 void DidCommitNavigation(); 112 void DidCommitNavigation();
88 113
89 private: 114 private:
115 friend class NavigationHandleFactory;
116 friend class TestNavigationHandle;
117
90 // Used to track the state the navigation is currently in. 118 // Used to track the state the navigation is currently in.
91 enum State { 119 enum State {
92 DID_START = 0, 120 DID_START = 0,
121 WILL_SEND_REQUEST,
93 DID_COMMIT, 122 DID_COMMIT,
94 DID_COMMIT_ERROR_PAGE, 123 DID_COMMIT_ERROR_PAGE,
95 }; 124 };
96 125
97 NavigationHandleImpl(const GURL& url, 126 NavigationHandleImpl(const GURL& url,
98 const bool is_main_frame, 127 const bool is_main_frame,
99 NavigatorDelegate* delegate); 128 NavigatorDelegate* delegate);
100 129
101 // See NavigationHandle for a description of those member variables. 130 // See NavigationHandle for a description of those member variables.
102 GURL url_; 131 GURL url_;
132 const bool is_main_frame_;
133 bool is_post_;
134 Referrer sanitized_referrer_;
135 bool has_user_gesture_;
136 ui::PageTransition transition_;
137 bool is_external_protocol_;
103 net::Error net_error_code_; 138 net::Error net_error_code_;
139
140 // The state the navigation is in.
104 State state_; 141 State state_;
105 const bool is_main_frame_;
106 142
107 // Whether the navigation is in the middle of a transfer. Set to false when 143 // Whether the navigation is in the middle of a transfer. Set to false when
108 // the DidStartProvisionalLoad is received from the new renderer. 144 // the DidStartProvisionalLoad is received from the new renderer.
109 bool is_transferring_; 145 bool is_transferring_;
110 146
111 // The delegate that should be notified about events related to this 147 // The delegate that should be notified about events related to this
112 // navigation. 148 // navigation.
113 NavigatorDelegate* delegate_; 149 NavigatorDelegate* delegate_;
114 150
151 // A pointer to the WebContents the navigation is taking place in.
152 //
153 // The NavigationHandle is either owned by a NavigationRequest or a
154 // RenderFrameHost, both of which are owned by a FrameTreeNode, which is
155 // ultimately owned by the WebContents. Therefore, the NavigationHandle
156 // cannot outlive the WebContents and it is safe to use a raw pointer.
157 //
158 // Note that it makes sense for the NavigationHandleImpl to keep a pointer to
159 // the WebContents because the NavigationHandle interface is closely tied to
160 // a WebContents (it is passed outside content/ through WebContentsObserver
161 // methods).
nasko 2015/09/16 20:33:39 It feels like a bit of a layering violation, but I
Charlie Reis 2015/09/16 20:46:07 It's definitely a layering violation. :) That sa
162 WebContents* web_contents_;
163
164 // A list of Throttles registered for this navigation.
165 ScopedVector<NavigationThrottle> throttles_;
166
115 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); 167 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl);
116 }; 168 };
117 169
118 } // namespace content 170 } // namespace content
119 171
120 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 172 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698