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_same_page_(false), | 29 is_same_page_(false), |
29 is_transferring_(false), | 30 is_transferring_(false), |
30 delegate_(delegate) { | 31 delegate_(delegate) { |
31 delegate_->DidStartNavigation(this); | 32 delegate_->DidStartNavigation(this); |
32 } | 33 } |
33 | 34 |
34 NavigationHandleImpl::~NavigationHandleImpl() { | 35 NavigationHandleImpl::~NavigationHandleImpl() { |
35 delegate_->DidFinishNavigation(this); | 36 delegate_->DidFinishNavigation(this); |
36 } | 37 } |
37 | 38 |
38 const GURL& NavigationHandleImpl::GetURL() const { | 39 const GURL& NavigationHandleImpl::GetURL() const { |
39 return url_; | 40 return url_; |
40 } | 41 } |
41 | 42 |
42 net::Error NavigationHandleImpl::GetNetErrorCode() const { | 43 net::Error NavigationHandleImpl::GetNetErrorCode() const { |
43 return net_error_code_; | 44 return net_error_code_; |
44 } | 45 } |
45 | 46 |
46 bool NavigationHandleImpl::IsInMainFrame() const { | 47 bool NavigationHandleImpl::IsInMainFrame() const { |
47 return is_main_frame_; | 48 return is_main_frame_; |
48 } | 49 } |
49 | 50 |
| 51 RenderFrameHostImpl* NavigationHandleImpl::GetRenderFrameHost() { |
| 52 CHECK(state_ >= READY_TO_COMMIT) |
| 53 << "This accessor should only be called " |
| 54 "after the navigation is ready to commit."; |
| 55 return render_frame_host_; |
| 56 } |
| 57 |
50 bool NavigationHandleImpl::IsSamePage() { | 58 bool NavigationHandleImpl::IsSamePage() { |
51 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE) | 59 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE) |
52 << "This accessor should not be called before the navigation has " | 60 << "This accessor should not be called before the navigation has " |
53 "committed."; | 61 "committed."; |
54 return is_same_page_; | 62 return is_same_page_; |
55 } | 63 } |
56 | 64 |
57 bool NavigationHandleImpl::HasCommittedDocument() const { | 65 bool NavigationHandleImpl::HasCommitted() { |
58 return state_ == DID_COMMIT; | 66 return state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE; |
59 } | 67 } |
60 | 68 |
61 bool NavigationHandleImpl::HasCommittedErrorPage() const { | 69 bool NavigationHandleImpl::IsErrorPage() { |
62 return state_ == DID_COMMIT_ERROR_PAGE; | 70 return state_ == DID_COMMIT_ERROR_PAGE; |
63 } | 71 } |
64 | 72 |
65 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { | 73 void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) { |
66 url_ = new_url; | 74 url_ = new_url; |
67 delegate_->DidRedirectNavigation(this); | 75 delegate_->DidRedirectNavigation(this); |
68 } | 76 } |
69 | 77 |
70 void NavigationHandleImpl::DidCommitNavigation(bool same_page) { | 78 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 79 RenderFrameHostImpl* render_frame_host) { |
| 80 CHECK(!render_frame_host_); |
| 81 render_frame_host_ = render_frame_host; |
| 82 state_ = READY_TO_COMMIT; |
| 83 delegate_->ReadyToCommitNavigation(this); |
| 84 } |
| 85 |
| 86 void NavigationHandleImpl::DidCommitNavigation( |
| 87 bool same_page, |
| 88 RenderFrameHostImpl* render_frame_host) { |
| 89 CHECK_IMPLIES(render_frame_host_, render_frame_host_ == render_frame_host); |
71 is_same_page_ = same_page; | 90 is_same_page_ = same_page; |
| 91 render_frame_host_ = render_frame_host; |
72 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; | 92 state_ = net_error_code_ == net::OK ? DID_COMMIT : DID_COMMIT_ERROR_PAGE; |
73 delegate_->DidCommitNavigation(this); | |
74 } | 93 } |
75 | 94 |
76 } // namespace content | 95 } // namespace content |
OLD | NEW |