OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/captive_portal/captive_portal_tab_observer.h" |
| 6 |
| 7 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 8 #include "googleurl/src/gurl.h" |
| 9 #include "net/base/net_errors.h" |
| 10 |
| 11 namespace captive_portal { |
| 12 |
| 13 CaptivePortalTabObserver::CaptivePortalTabObserver( |
| 14 CaptivePortalTabHelper* tab_helper, |
| 15 content::WebContents* web_contents) |
| 16 : content::WebContentsObserver(web_contents), |
| 17 tab_helper_(tab_helper), |
| 18 pending_error_code_(net::OK) { |
| 19 DCHECK(tab_helper); |
| 20 } |
| 21 |
| 22 CaptivePortalTabObserver::~CaptivePortalTabObserver() { |
| 23 } |
| 24 |
| 25 void CaptivePortalTabObserver::DidStartProvisionalLoadForFrame( |
| 26 int64 frame_id, |
| 27 bool is_main_frame, |
| 28 const GURL& validated_url, |
| 29 bool is_error_page, |
| 30 content::RenderViewHost* render_view_host) { |
| 31 // Ignore subframes. |
| 32 if (!is_main_frame) |
| 33 return; |
| 34 |
| 35 // If loading an error page for a previous failure, treat this as part of |
| 36 // the previous load. The second check is needed because Link Doctor pages |
| 37 // result in two error page provisional loads in a row. Currently, the |
| 38 // second load is treated as a normal load, rather than reusing old error |
| 39 // codes. |
| 40 if (is_error_page && pending_error_code_ != net::OK) |
| 41 return; |
| 42 |
| 43 // Makes the second load for Link Doctor pages act as a normal load. |
| 44 // TODO(mmenke): Figure out if this affects any other cases. |
| 45 pending_error_code_ = net::OK; |
| 46 |
| 47 tab_helper_->OnLoadStart(validated_url.SchemeIsSecure()); |
| 48 } |
| 49 |
| 50 void CaptivePortalTabObserver::DidCommitProvisionalLoadForFrame( |
| 51 int64 frame_id, |
| 52 bool is_main_frame, |
| 53 const GURL& url, |
| 54 content::PageTransition transition_type, |
| 55 content::RenderViewHost* render_view_host) { |
| 56 // Ignore subframes. |
| 57 if (!is_main_frame) |
| 58 return; |
| 59 |
| 60 tab_helper_->OnLoadCommitted(pending_error_code_); |
| 61 pending_error_code_ = net::OK; |
| 62 } |
| 63 |
| 64 void CaptivePortalTabObserver::DidFailProvisionalLoad( |
| 65 int64 frame_id, |
| 66 bool is_main_frame, |
| 67 const GURL& validated_url, |
| 68 int error_code, |
| 69 const string16& error_description, |
| 70 content::RenderViewHost* render_view_host) { |
| 71 // Ignore subframes. |
| 72 if (!is_main_frame) |
| 73 return; |
| 74 |
| 75 // Aborts generally aren't followed by loading an error page, so go ahead and |
| 76 // reset the state now, to prevent any captive portal checks from triggering. |
| 77 if (error_code == net::ERR_ABORTED) { |
| 78 // May have been aborting the load of an error page. |
| 79 pending_error_code_ = net::OK; |
| 80 |
| 81 tab_helper_->OnAbort(); |
| 82 return; |
| 83 } |
| 84 |
| 85 pending_error_code_ = error_code; |
| 86 } |
| 87 |
| 88 void CaptivePortalTabObserver::DidStopLoading() { |
| 89 tab_helper_->OnStopLoading(); |
| 90 } |
| 91 |
| 92 } // namespace captive_portal |
OLD | NEW |