OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 5 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/captive_portal/captive_portal_login_detector.h" | 8 #include "chrome/browser/captive_portal/captive_portal_login_detector.h" |
9 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 9 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 void CaptivePortalTabHelper::DidStartNavigation( | 55 void CaptivePortalTabHelper::DidStartNavigation( |
56 content::NavigationHandle* navigation_handle) { | 56 content::NavigationHandle* navigation_handle) { |
57 DCHECK(CalledOnValidThread()); | 57 DCHECK(CalledOnValidThread()); |
58 if (!navigation_handle->IsInMainFrame()) | 58 if (!navigation_handle->IsInMainFrame()) |
59 return; | 59 return; |
60 | 60 |
61 // Always track the latest navigation. If a navigation was already tracked, | 61 // Always track the latest navigation. If a navigation was already tracked, |
62 // and it committed (either the navigation proper or an error page), it is | 62 // and it committed (either the navigation proper or an error page), it is |
63 // safe to start tracking the new navigation. Otherwise simulate an abort | 63 // safe to start tracking the new navigation. Otherwise simulate an abort |
64 // before reporting the start of the new navigation. | 64 // before reporting the start of the new navigation. |
65 if (navigation_handle_ && !navigation_handle_->HasCommittedDocument() && | 65 if (navigation_handle_ && !navigation_handle_->HasCommitted()) { |
66 !navigation_handle_->HasCommittedErrorPage()) { | |
67 tab_reloader_->OnAbort(); | 66 tab_reloader_->OnAbort(); |
68 } | 67 } |
69 | 68 |
70 navigation_handle_ = navigation_handle; | 69 navigation_handle_ = navigation_handle; |
71 tab_reloader_->OnLoadStart( | 70 tab_reloader_->OnLoadStart( |
72 navigation_handle->GetURL().SchemeIsCryptographic()); | 71 navigation_handle->GetURL().SchemeIsCryptographic()); |
73 } | 72 } |
74 | 73 |
75 void CaptivePortalTabHelper::DidRedirectNavigation( | 74 void CaptivePortalTabHelper::DidRedirectNavigation( |
76 content::NavigationHandle* navigation_handle) { | 75 content::NavigationHandle* navigation_handle) { |
77 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
78 if (navigation_handle != navigation_handle_) | 77 if (navigation_handle != navigation_handle_) |
79 return; | 78 return; |
80 DCHECK(navigation_handle->IsInMainFrame()); | 79 DCHECK(navigation_handle->IsInMainFrame()); |
81 tab_reloader_->OnRedirect( | 80 tab_reloader_->OnRedirect( |
82 navigation_handle->GetURL().SchemeIsCryptographic()); | 81 navigation_handle->GetURL().SchemeIsCryptographic()); |
83 } | 82 } |
84 | 83 |
85 void CaptivePortalTabHelper::DidCommitNavigation( | 84 void CaptivePortalTabHelper::DidFinishNavigation( |
86 content::NavigationHandle* navigation_handle) { | 85 content::NavigationHandle* navigation_handle) { |
87 DCHECK(CalledOnValidThread()); | 86 DCHECK(CalledOnValidThread()); |
88 if (!navigation_handle->IsInMainFrame()) | 87 if (!navigation_handle->IsInMainFrame()) |
89 return; | 88 return; |
90 | 89 |
91 if (navigation_handle_ != navigation_handle) | 90 if (navigation_handle_ != navigation_handle) { |
| 91 // Another navigation is being tracked, so there is no need to update the |
| 92 // TabReloader. |
| 93 if (!navigation_handle->HasCommitted()) |
| 94 return; |
| 95 // An untracked navigation just committed. Simulate its start before |
| 96 // informing the TabReloader of its commit. |
92 DidStartNavigation(navigation_handle); | 97 DidStartNavigation(navigation_handle); |
| 98 } |
93 | 99 |
94 tab_reloader_->OnLoadCommitted(navigation_handle->GetNetErrorCode()); | 100 if (navigation_handle->HasCommitted()) { |
95 } | 101 tab_reloader_->OnLoadCommitted(navigation_handle->GetNetErrorCode()); |
96 | 102 } else { |
97 void CaptivePortalTabHelper::DidFinishNavigation( | |
98 content::NavigationHandle* navigation_handle) { | |
99 DCHECK(CalledOnValidThread()); | |
100 if (navigation_handle != navigation_handle_) | |
101 return; | |
102 DCHECK(navigation_handle->IsInMainFrame()); | |
103 | |
104 if (!navigation_handle->HasCommittedDocument() && | |
105 !navigation_handle->HasCommittedErrorPage()) { | |
106 tab_reloader_->OnAbort(); | 103 tab_reloader_->OnAbort(); |
107 } | 104 } |
108 | 105 |
| 106 navigation_handle_ = nullptr; |
| 107 } |
| 108 |
| 109 void CaptivePortalTabHelper::DidStopLoading() { |
109 login_detector_->OnStoppedLoading(); | 110 login_detector_->OnStoppedLoading(); |
110 | |
111 navigation_handle_ = nullptr; | |
112 } | 111 } |
113 | 112 |
114 void CaptivePortalTabHelper::Observe( | 113 void CaptivePortalTabHelper::Observe( |
115 int type, | 114 int type, |
116 const content::NotificationSource& source, | 115 const content::NotificationSource& source, |
117 const content::NotificationDetails& details) { | 116 const content::NotificationDetails& details) { |
118 DCHECK(CalledOnValidThread()); | 117 DCHECK(CalledOnValidThread()); |
119 DCHECK_EQ(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, type); | 118 DCHECK_EQ(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, type); |
120 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 119 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
121 | 120 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 182 } |
184 | 183 |
185 void CaptivePortalTabHelper::SetTabReloaderForTest( | 184 void CaptivePortalTabHelper::SetTabReloaderForTest( |
186 CaptivePortalTabReloader* tab_reloader) { | 185 CaptivePortalTabReloader* tab_reloader) { |
187 tab_reloader_.reset(tab_reloader); | 186 tab_reloader_.reset(tab_reloader); |
188 } | 187 } |
189 | 188 |
190 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { | 189 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { |
191 return tab_reloader_.get(); | 190 return tab_reloader_.get(); |
192 } | 191 } |
OLD | NEW |