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 #include "content/browser/frame_host/navigation_handle_impl.h" | 5 #include "content/browser/frame_host/navigation_handle_impl.h" |
6 | 6 |
7 #include "content/browser/frame_host/navigator_delegate.h" | 7 #include "content/browser/frame_host/navigator_delegate.h" |
8 #include "net/url_request/redirect_info.h" | 8 #include "net/url_request/redirect_info.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 // static | 12 // static |
13 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( | 13 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
14 const GURL& url, | 14 const GURL& url, |
15 const bool is_main_frame, | 15 const bool is_main_frame, |
16 NavigatorDelegate* delegate) { | 16 NavigatorDelegate* delegate) { |
17 return scoped_ptr<NavigationHandleImpl>( | 17 return scoped_ptr<NavigationHandleImpl>( |
18 new NavigationHandleImpl(url, is_main_frame, delegate)); | 18 new NavigationHandleImpl(url, is_main_frame, delegate)); |
19 } | 19 } |
20 | 20 |
21 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, | 21 NavigationHandleImpl::NavigationHandleImpl(const GURL& url, |
22 const bool is_main_frame, | 22 const bool is_main_frame, |
23 NavigatorDelegate* delegate) | 23 NavigatorDelegate* delegate) |
24 : url_(url), | 24 : url_(url), |
25 net_error_code_(net::OK), | 25 net_error_code_(net::OK), |
26 state_(DID_START), | 26 state_(DID_START), |
27 is_main_frame_(is_main_frame), | 27 is_main_frame_(is_main_frame), |
| 28 render_frame_host_(nullptr), |
28 is_transferring_(false), | 29 is_transferring_(false), |
29 delegate_(delegate) { | 30 delegate_(delegate) { |
30 delegate_->DidStartNavigation(this); | 31 delegate_->DidStartNavigation(this); |
31 } | 32 } |
32 | 33 |
33 NavigationHandleImpl::~NavigationHandleImpl() { | 34 NavigationHandleImpl::~NavigationHandleImpl() { |
34 delegate_->DidFinishNavigation(this); | 35 delegate_->DidFinishNavigation(this); |
35 } | 36 } |
36 | 37 |
37 const GURL& NavigationHandleImpl::GetURL() const { | 38 const GURL& NavigationHandleImpl::GetURL() const { |
38 return url_; | 39 return url_; |
39 } | 40 } |
40 | 41 |
41 net::Error NavigationHandleImpl::GetNetErrorCode() const { | 42 net::Error NavigationHandleImpl::GetNetErrorCode() const { |
42 return net_error_code_; | 43 return net_error_code_; |
43 } | 44 } |
44 | 45 |
45 bool NavigationHandleImpl::IsInMainFrame() const { | 46 bool NavigationHandleImpl::IsInMainFrame() const { |
46 return is_main_frame_; | 47 return is_main_frame_; |
47 } | 48 } |
48 | 49 |
49 bool NavigationHandleImpl::HasCommittedDocument() const { | 50 RenderFrameHostImpl* NavigationHandleImpl::GetRenderFrameHost() { |
50 return state_ == DID_COMMIT; | 51 CHECK(state_ >= READY_TO_COMMIT) |
| 52 << "This accessor should only be called " |
| 53 "after the navigation is ready to commit."; |
| 54 return render_frame_host_; |
51 } | 55 } |
52 | 56 |
53 bool NavigationHandleImpl::HasCommittedErrorPage() const { | 57 bool NavigationHandleImpl::HasCommitted() { |
| 58 return state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE; |
| 59 } |
| 60 |
| 61 bool NavigationHandleImpl::IsErrorPage() { |
54 return state_ == DID_COMMIT_ERROR_PAGE; | 62 return state_ == DID_COMMIT_ERROR_PAGE; |
55 } | 63 } |
56 | 64 |
57 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 65 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
58 url_ = new_url; | 66 url_ = new_url; |
59 delegate_->DidRedirectNavigation(this); | 67 delegate_->DidRedirectNavigation(this); |
60 } | 68 } |
61 | 69 |
62 void NavigationHandleImpl::DidCommitNavigation() { | 70 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 71 RenderFrameHostImpl* render_frame_host) { |
| 72 CHECK(!render_frame_host_); |
| 73 render_frame_host_ = render_frame_host; |
| 74 state_ = READY_TO_COMMIT; |
| 75 delegate_->ReadyToCommitNavigation(this); |
| 76 } |
| 77 |
| 78 void NavigationHandleImpl::DidCommitNavigation( |
| 79 RenderFrameHostImpl* render_frame_host) { |
| 80 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); |
| 81 render_frame_host_ = render_frame_host; |
63 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; | 82 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; |
64 delegate_->DidCommitNavigation(this); | |
65 } | 83 } |
66 | 84 |
67 } // namespace content | 85 } // namespace content |
OLD | NEW |