Chromium Code Reviews| 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 if (!navigation_handle->HasCommitted()) | |
|
mmenke
2015/09/21 20:28:24
Why the change in behavior here? Worth a comment?
clamy
2015/09/22 00:38:05
Done.
| |
| 92 return; | |
| 92 DidStartNavigation(navigation_handle); | 93 DidStartNavigation(navigation_handle); |
| 94 } | |
| 93 | 95 |
| 94 tab_reloader_->OnLoadCommitted(navigation_handle->GetNetErrorCode()); | 96 if (navigation_handle->HasCommitted()) |
| 97 tab_reloader_->OnLoadCommitted(navigation_handle->GetNetErrorCode()); | |
| 98 else | |
| 99 tab_reloader_->OnAbort(); | |
|
mmenke
2015/09/21 20:28:24
nit: Use braces with else if (Style here varies b
clamy
2015/09/22 00:38:05
Done.
| |
| 100 | |
| 101 navigation_handle_ = nullptr; | |
| 95 } | 102 } |
| 96 | 103 |
| 97 void CaptivePortalTabHelper::DidFinishNavigation( | 104 void CaptivePortalTabHelper::DidStopLoading() { |
|
mmenke
2015/09/21 20:28:24
Why the change here?
clamy
2015/09/22 00:38:05
We changed the moment DidFinishNavigation will be
| |
| 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(); | |
| 107 } | |
| 108 | |
| 109 login_detector_->OnStoppedLoading(); | 105 login_detector_->OnStoppedLoading(); |
| 110 | |
| 111 navigation_handle_ = nullptr; | |
| 112 } | 106 } |
| 113 | 107 |
| 114 void CaptivePortalTabHelper::Observe( | 108 void CaptivePortalTabHelper::Observe( |
| 115 int type, | 109 int type, |
| 116 const content::NotificationSource& source, | 110 const content::NotificationSource& source, |
| 117 const content::NotificationDetails& details) { | 111 const content::NotificationDetails& details) { |
| 118 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
| 119 DCHECK_EQ(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, type); | 113 DCHECK_EQ(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, type); |
| 120 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 114 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
| 121 | 115 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 } | 177 } |
| 184 | 178 |
| 185 void CaptivePortalTabHelper::SetTabReloaderForTest( | 179 void CaptivePortalTabHelper::SetTabReloaderForTest( |
| 186 CaptivePortalTabReloader* tab_reloader) { | 180 CaptivePortalTabReloader* tab_reloader) { |
| 187 tab_reloader_.reset(tab_reloader); | 181 tab_reloader_.reset(tab_reloader); |
| 188 } | 182 } |
| 189 | 183 |
| 190 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { | 184 CaptivePortalTabReloader* CaptivePortalTabHelper::GetTabReloaderForTest() { |
| 191 return tab_reloader_.get(); | 185 return tab_reloader_.get(); |
| 192 } | 186 } |
| OLD | NEW |