| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| 6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ssl/common_name_mismatch_handler.h" |
| 14 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 16 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 15 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 18 #include "content/public/browser/web_contents_user_data.h" | 20 #include "content/public/browser/web_contents_user_data.h" |
| 19 #include "net/ssl/ssl_info.h" | 21 #include "net/ssl/ssl_info.h" |
| 20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 21 | 23 |
| 24 class Profile; |
| 25 class CommonNameMismatchHandler; |
| 26 |
| 22 namespace content { | 27 namespace content { |
| 23 class RenderViewHost; | 28 class RenderViewHost; |
| 24 class WebContents; | 29 class WebContents; |
| 25 } | 30 } |
| 26 | 31 |
| 27 // This class is responsible for deciding whether to show an SSL warning or a | 32 // This class is responsible for deciding whether to show an SSL warning or a |
| 28 // captive portal error page. It makes this decision by delaying the display of | 33 // captive portal error page. It makes this decision by delaying the display of |
| 29 // SSL interstitial for a few seconds (2 by default), and waiting for a captive | 34 // SSL interstitial for a few seconds (2 by default), and waiting for a captive |
| 30 // portal result to arrive during this window. If a captive portal detected | 35 // portal result to arrive during this window. If a captive portal detected |
| 31 // result arrives in this window, a captive portal error page is shown. | 36 // result arrives in this window, a captive portal error page is shown. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 54 int options_mask, | 59 int options_mask, |
| 55 scoped_ptr<SSLCertReporter> ssl_cert_reporter, | 60 scoped_ptr<SSLCertReporter> ssl_cert_reporter, |
| 56 const base::Callback<void(bool)>& callback); | 61 const base::Callback<void(bool)>& callback); |
| 57 | 62 |
| 58 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay); | 63 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay); |
| 59 | 64 |
| 60 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; | 65 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; |
| 61 static void SetInterstitialTimerStartedCallbackForTest( | 66 static void SetInterstitialTimerStartedCallbackForTest( |
| 62 TimerStartedCallback* callback); | 67 TimerStartedCallback* callback); |
| 63 | 68 |
| 69 // Gets the result of whether the suggested URL is valid. Displays |
| 70 // common name mismatch interstitial or ssl interstitial accordingly. |
| 71 void CommonNameMismatchHandlerCallback( |
| 72 const CommonNameMismatchHandler::SuggestedUrlCheckResult& result, |
| 73 const GURL& suggested_url); |
| 74 |
| 64 protected: | 75 protected: |
| 65 SSLErrorHandler(content::WebContents* web_contents, | 76 SSLErrorHandler(content::WebContents* web_contents, |
| 66 int cert_error, | 77 int cert_error, |
| 67 const net::SSLInfo& ssl_info, | 78 const net::SSLInfo& ssl_info, |
| 68 const GURL& request_url, | 79 const GURL& request_url, |
| 69 int options_mask, | 80 int options_mask, |
| 70 scoped_ptr<SSLCertReporter> ssl_cert_reporter, | 81 scoped_ptr<SSLCertReporter> ssl_cert_reporter, |
| 71 const base::Callback<void(bool)>& callback); | 82 const base::Callback<void(bool)>& callback); |
| 72 | 83 |
| 73 ~SSLErrorHandler() override; | 84 ~SSLErrorHandler() override; |
| 74 | 85 |
| 75 // Called when an SSL cert error is encountered. Triggers a captive portal | 86 // Called when an SSL cert error is encountered. Triggers a captive portal |
| 76 // check and fires a one shot timer to wait for a "captive portal detected" | 87 // check and fires a one shot timer to wait for a "captive portal detected" |
| 77 // result to arrive. | 88 // result to arrive. |
| 78 void StartHandlingError(); | 89 void StartHandlingError(); |
| 79 const base::OneShotTimer<SSLErrorHandler>& get_timer() const { | 90 const base::OneShotTimer<SSLErrorHandler>& get_timer() const { |
| 80 return timer_; | 91 return timer_; |
| 81 } | 92 } |
| 82 | 93 |
| 83 private: | 94 private: |
| 84 // Callback for the one-shot timer. When the timer expires, an SSL error is | 95 // Callback for the one-shot timer. When the timer expires, an SSL error is |
| 85 // immediately displayed. | 96 // immediately displayed. |
| 86 void OnTimerExpired(); | 97 void OnTimerExpired(); |
| 87 | 98 |
| 88 // These are virtual for tests: | 99 // These are virtual for tests: |
| 89 virtual void CheckForCaptivePortal(); | 100 virtual void CheckForCaptivePortal(); |
| 90 virtual void ShowCaptivePortalInterstitial(const GURL& landing_url); | 101 virtual void ShowCaptivePortalInterstitial(const GURL& landing_url); |
| 91 virtual void ShowSSLInterstitial(); | 102 virtual void ShowSSLInterstitial(); |
| 103 virtual bool GetSuggestedUrl(const std::vector<std::string>& dns_names, |
| 104 GURL* suggested_url) const; |
| 105 virtual void CheckSuggestedUrl(const GURL& suggested_url); |
| 106 virtual void NavigateToSuggestedURL(const GURL& suggested_url); |
| 92 | 107 |
| 93 // content::NotificationObserver: | 108 // content::NotificationObserver: |
| 94 void Observe( | 109 void Observe( |
| 95 int type, | 110 int type, |
| 96 const content::NotificationSource& source, | 111 const content::NotificationSource& source, |
| 97 const content::NotificationDetails& details) override; | 112 const content::NotificationDetails& details) override; |
| 98 | 113 |
| 99 // content::WebContentsObserver: | 114 // content::WebContentsObserver: |
| 100 void DidStartNavigationToPendingEntry( | 115 void DidStartNavigationToPendingEntry( |
| 101 const GURL& url, | 116 const GURL& url, |
| 102 content::NavigationController::ReloadType reload_type) override; | 117 content::NavigationController::ReloadType reload_type) override; |
| 103 | 118 |
| 104 // content::WebContentsObserver: | 119 // content::WebContentsObserver: |
| 105 void NavigationStopped() override; | 120 void NavigationStopped() override; |
| 106 | 121 |
| 107 // Deletes the SSLErrorHandler. This method is called when the page | 122 // Deletes the SSLErrorHandler. This method is called when the page |
| 108 // load stops or when there is a new navigation. | 123 // load stops or when there is a new navigation. |
| 109 void DeleteSSLErrorHandler(); | 124 void DeleteSSLErrorHandler(); |
| 110 | 125 |
| 111 content::WebContents* web_contents_; | 126 content::WebContents* web_contents_; |
| 112 const int cert_error_; | 127 const int cert_error_; |
| 113 const net::SSLInfo ssl_info_; | 128 const net::SSLInfo ssl_info_; |
| 114 const GURL request_url_; | 129 const GURL request_url_; |
| 115 const int options_mask_; | 130 const int options_mask_; |
| 116 base::Callback<void(bool)> callback_; | 131 base::Callback<void(bool)> callback_; |
| 132 Profile* const profile_; |
| 117 | 133 |
| 118 content::NotificationRegistrar registrar_; | 134 content::NotificationRegistrar registrar_; |
| 119 base::OneShotTimer<SSLErrorHandler> timer_; | 135 base::OneShotTimer<SSLErrorHandler> timer_; |
| 120 | 136 |
| 137 scoped_ptr<CommonNameMismatchHandler> common_name_mismatch_handler_; |
| 138 |
| 121 scoped_ptr<SSLCertReporter> ssl_cert_reporter_; | 139 scoped_ptr<SSLCertReporter> ssl_cert_reporter_; |
| 122 | 140 |
| 123 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 141 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 124 }; | 142 }; |
| 125 | 143 |
| 126 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 144 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| OLD | NEW |