Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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: |
| 57 // This is used by the NavigationHandleFactory to create NavigationHandles | |
| 58 // in the regular case. Other callers should use | |
| 59 // NavigationHandleFactory::Create, which will ensure that test versions of | |
| 60 // NavigationHandles are properly created in unit tests. | |
|
nasko
2015/09/04 00:01:52
Why not make this method private then? If it is no
clamy
2015/09/04 12:59:14
Ha I wasn't sure about making non-test classes fri
clamy
2015/09/08 16:27:18
I removed it entirely, and have NavigationHandleFa
| |
| 55 static scoped_ptr<NavigationHandleImpl> Create(const GURL& url, | 61 static scoped_ptr<NavigationHandleImpl> Create(const GURL& url, |
| 62 const GURL& validated_url, | |
| 56 const bool is_main_frame, | 63 const bool is_main_frame, |
| 57 NavigatorDelegate* delegate); | 64 NavigatorDelegate* delegate); |
| 58 | 65 |
| 59 ~NavigationHandleImpl() override; | 66 ~NavigationHandleImpl() override; |
| 60 | 67 |
| 61 // NavigationHandle implementation: | 68 // NavigationHandle implementation: |
| 62 const GURL& GetURL() const override; | 69 const GURL& GetURL() const override; |
| 70 const GURL& GetValidatedURL() const override; | |
| 71 bool IsInMainFrame() const override; | |
| 72 bool IsPost() const override; | |
| 73 const Referrer& GetReferrer() const override; | |
| 74 bool HasUserGesture() const override; | |
| 75 ui::PageTransition GetPageTransition() const override; | |
| 76 bool IsExternalProtocol() const override; | |
| 63 net::Error GetNetErrorCode() const override; | 77 net::Error GetNetErrorCode() const override; |
| 64 bool IsInMainFrame() const override; | |
| 65 bool HasCommittedDocument() const override; | 78 bool HasCommittedDocument() const override; |
| 66 bool HasCommittedErrorPage() const override; | 79 bool HasCommittedErrorPage() const override; |
| 80 void RegisterThrottleForTesting( | |
| 81 scoped_ptr<NavigationThrottle> navigation_throttle) override; | |
| 67 | 82 |
| 68 void set_net_error_code(net::Error net_error_code) { | 83 void set_net_error_code(net::Error net_error_code) { |
| 69 net_error_code_ = net_error_code; | 84 net_error_code_ = net_error_code; |
| 70 } | 85 } |
| 71 | 86 |
| 72 // Returns whether the navigation is currently being transferred from one | 87 // Returns whether the navigation is currently being transferred from one |
| 73 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC | 88 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC |
| 74 // for the navigation URL, received in the new RenderFrameHost, should not | 89 // for the navigation URL, received in the new RenderFrameHost, should not |
| 75 // indicate the start of a new navigation in that case. | 90 // indicate the start of a new navigation in that case. |
| 76 bool is_transferring() const { return is_transferring_; } | 91 bool is_transferring() const { return is_transferring_; } |
| 77 void set_is_transferring(bool is_transferring) { | 92 void set_is_transferring(bool is_transferring) { |
| 78 is_transferring_ = is_transferring; | 93 is_transferring_ = is_transferring; |
| 79 } | 94 } |
| 80 | 95 |
| 96 // Called when the URLRequest will start in the network stack. | |
| 97 NavigationThrottle::ThrottleCheckResult WillStartRequest( | |
| 98 bool is_post, | |
| 99 const Referrer& sanitized_referrer, | |
| 100 bool has_user_gesture, | |
| 101 ui::PageTransition transition, | |
| 102 bool is_external_protocol); | |
| 103 | |
| 104 // Called when the URLRequest will be redirected in the network stack. | |
| 105 NavigationThrottle::ThrottleCheckResult WillRedirectRequest( | |
| 106 const GURL& new_url, | |
| 107 const GURL& new_validated_url, | |
| 108 bool new_method_is_post, | |
| 109 const GURL& new_referrer_url, | |
| 110 bool new_is_external_protocol); | |
| 111 | |
| 81 // Called when the navigation was redirected. This will update the |url_| and | 112 // Called when the navigation was redirected. This will update the |url_| and |
| 82 // inform the delegate. | 113 // inform the delegate. |
| 83 void DidRedirectNavigation(const GURL& new_url); | 114 void DidRedirectNavigation(const GURL& new_url); |
| 84 | 115 |
| 85 // Called when the navigation was committed. This will update the |state_| | 116 // Called when the navigation was committed. This will update the |state_| |
| 86 // and inform the delegate, | 117 // and inform the delegate, |
| 87 void DidCommitNavigation(); | 118 void DidCommitNavigation(); |
| 88 | 119 |
| 89 private: | 120 private: |
| 121 friend class TestNavigationHandle; | |
| 122 | |
| 90 // Used to track the state the navigation is currently in. | 123 // Used to track the state the navigation is currently in. |
| 91 enum State { | 124 enum State { |
| 92 DID_START = 0, | 125 DID_START = 0, |
| 126 WILL_SEND_REQUEST, | |
| 93 DID_COMMIT, | 127 DID_COMMIT, |
| 94 DID_COMMIT_ERROR_PAGE, | 128 DID_COMMIT_ERROR_PAGE, |
| 95 }; | 129 }; |
| 96 | 130 |
| 97 NavigationHandleImpl(const GURL& url, | 131 NavigationHandleImpl(const GURL& url, |
| 132 const GURL& validated_url, | |
| 98 const bool is_main_frame, | 133 const bool is_main_frame, |
| 99 NavigatorDelegate* delegate); | 134 NavigatorDelegate* delegate); |
| 100 | 135 |
| 101 // See NavigationHandle for a description of those member variables. | 136 // See NavigationHandle for a description of those member variables. |
| 102 GURL url_; | 137 GURL url_; |
| 138 GURL validated_url_; | |
| 139 const bool is_main_frame_; | |
| 140 bool is_post_; | |
| 141 Referrer sanitized_referrer_; | |
| 142 bool has_user_gesture_; | |
| 143 ui::PageTransition transition_; | |
| 144 bool is_external_protocol_; | |
| 103 net::Error net_error_code_; | 145 net::Error net_error_code_; |
| 146 | |
| 147 // The state the navigation is in. | |
| 104 State state_; | 148 State state_; |
| 105 const bool is_main_frame_; | |
| 106 | 149 |
| 107 // Whether the navigation is in the middle of a transfer. Set to false when | 150 // Whether the navigation is in the middle of a transfer. Set to false when |
| 108 // the DidStartProvisionalLoad is received from the new renderer. | 151 // the DidStartProvisionalLoad is received from the new renderer. |
| 109 bool is_transferring_; | 152 bool is_transferring_; |
| 110 | 153 |
| 111 // The delegate that should be notified about events related to this | 154 // The delegate that should be notified about events related to this |
| 112 // navigation. | 155 // navigation. |
| 113 NavigatorDelegate* delegate_; | 156 NavigatorDelegate* delegate_; |
| 114 | 157 |
| 158 // A list of Throttles registered for this navigation. | |
| 159 ScopedVector<NavigationThrottle> throttles_; | |
| 160 | |
| 115 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); | 161 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); |
| 116 }; | 162 }; |
| 117 | 163 |
| 118 } // namespace content | 164 } // namespace content |
| 119 | 165 |
| 120 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ | 166 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ |
| OLD | NEW |