Chromium Code Reviews| 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" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ssl/common_name_mismatch_handler.h" | 15 #include "chrome/browser/ssl/common_name_mismatch_handler.h" |
| 16 #include "chrome/browser/ssl/ssl_cert_reporter.h" | 16 #include "chrome/browser/ssl/ssl_cert_reporter.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 20 #include "content/public/browser/web_contents_user_data.h" | 20 #include "content/public/browser/web_contents_user_data.h" |
| 21 #include "net/ssl/ssl_info.h" | 21 #include "net/ssl/ssl_info.h" |
| 22 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 23 | 23 |
| 24 class CommonNameMismatchHandler; | |
| 24 class Profile; | 25 class Profile; |
| 25 class CommonNameMismatchHandler; | 26 |
| 27 namespace base { | |
| 28 class Clock; | |
| 29 } | |
| 26 | 30 |
| 27 namespace content { | 31 namespace content { |
| 28 class RenderViewHost; | 32 class RenderViewHost; |
| 29 class WebContents; | 33 class WebContents; |
| 30 } | 34 } |
| 31 | 35 |
| 32 // Decides between showing an SSL warning, showing a captive portal interstitial | 36 // This class is responsible for deciding what type of interstitial to show for |
| 33 // or redirecting to a name-mismatch suggested URL. This is done by delaying the | 37 // an SSL validation error. The display of the interstitial might be delayed by |
| 34 // display of the interstitial for a few seconds (2 by default), and waiting for | 38 // a few seconds (2 by default) while trying to determine the cause of the |
| 35 // name-mismatch suggested URL or a captive portal result to arrive during this | 39 // error. During this window, the class will: check for a clock error, wait for |
| 36 // window. If there is a name mismatch error and a corresponding suggested URL | 40 // a name-mismatch suggested URL, or wait for a captive portal result to arrive. |
| 37 // available result arrives in this window, the user is redirected to the | 41 // If there is a name mismatch error and a corresponding suggested URL available |
|
estark
2015/09/01 13:28:28
Something in this sentence doesn't parse for me...
felt
2015/09/01 15:49:41
Done.
| |
| 38 // suggested URL. Failing that, if a captive portal detected result arrives in | 42 // result arrives in this window, the user is redirected to the suggested URL. |
| 39 // the same time window, a captive portal error page is shown. Otherwise, an | 43 // Failing that, if a captive portal detected result arrives in the time window, |
| 40 // SSL interstitial is shown. | 44 // a capitve portal error page is shown. If none of these potential error |
| 45 // causes match, an SSL intersittial is shown. | |
|
estark
2015/09/01 13:28:28
typo in "interstitial"
felt
2015/09/01 15:49:41
Done.
| |
| 41 // | 46 // |
| 42 // This class should only be used on the UI thread because its implementation | 47 // This class should only be used on the UI thread because its implementation |
| 43 // uses captive_portal::CaptivePortalService which can only be accessed on the | 48 // uses captive_portal::CaptivePortalService which can only be accessed on the |
| 44 // UI thread. | 49 // UI thread. |
| 45 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, | 50 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, |
| 46 public content::WebContentsObserver, | 51 public content::WebContentsObserver, |
| 47 public content::NotificationObserver { | 52 public content::NotificationObserver { |
| 48 public: | 53 public: |
| 49 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; | 54 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; |
| 50 | 55 |
| 51 // Entry point for the class. The parameters are the same as SSLBlockingPage | 56 // Entry point for the class. The parameters are the same as SSLBlockingPage |
| 52 // constructor. | 57 // constructor. |
| 53 static void HandleSSLError(content::WebContents* web_contents, | 58 static void HandleSSLError(content::WebContents* web_contents, |
| 54 int cert_error, | 59 int cert_error, |
| 55 const net::SSLInfo& ssl_info, | 60 const net::SSLInfo& ssl_info, |
| 56 const GURL& request_url, | 61 const GURL& request_url, |
| 57 int options_mask, | 62 int options_mask, |
| 58 scoped_ptr<SSLCertReporter> ssl_cert_reporter, | 63 scoped_ptr<SSLCertReporter> ssl_cert_reporter, |
| 59 const base::Callback<void(bool)>& callback); | 64 const base::Callback<void(bool)>& callback); |
| 60 | 65 |
| 66 // Testing methods. | |
| 61 static void SetInterstitialDelayForTest(base::TimeDelta delay); | 67 static void SetInterstitialDelayForTest(base::TimeDelta delay); |
| 62 | |
| 63 // The callback pointer must remain valid for the duration of error handling. | 68 // The callback pointer must remain valid for the duration of error handling. |
| 64 static void SetInterstitialTimerStartedCallbackForTest( | 69 static void SetInterstitialTimerStartedCallbackForTest( |
| 65 TimerStartedCallback* callback); | 70 TimerStartedCallback* callback); |
| 71 static void SetClockForTest(base::Clock* testing_clock); | |
| 66 | 72 |
| 67 protected: | 73 protected: |
| 68 // The parameters are the same as SSLBlockingPage's constructor. | 74 // The parameters are the same as SSLBlockingPage's constructor. |
| 69 SSLErrorHandler(content::WebContents* web_contents, | 75 SSLErrorHandler(content::WebContents* web_contents, |
| 70 int cert_error, | 76 int cert_error, |
| 71 const net::SSLInfo& ssl_info, | 77 const net::SSLInfo& ssl_info, |
| 72 const GURL& request_url, | 78 const GURL& request_url, |
| 73 int options_mask, | 79 int options_mask, |
| 74 scoped_ptr<SSLCertReporter> ssl_cert_reporter, | 80 scoped_ptr<SSLCertReporter> ssl_cert_reporter, |
| 75 const base::Callback<void(bool)>& callback); | 81 const base::Callback<void(bool)>& callback); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 86 | 92 |
| 87 // These are virtual for tests: | 93 // These are virtual for tests: |
| 88 virtual void CheckForCaptivePortal(); | 94 virtual void CheckForCaptivePortal(); |
| 89 virtual bool GetSuggestedUrl(const std::vector<std::string>& dns_names, | 95 virtual bool GetSuggestedUrl(const std::vector<std::string>& dns_names, |
| 90 GURL* suggested_url) const; | 96 GURL* suggested_url) const; |
| 91 virtual void CheckSuggestedUrl(const GURL& suggested_url); | 97 virtual void CheckSuggestedUrl(const GURL& suggested_url); |
| 92 virtual void NavigateToSuggestedURL(const GURL& suggested_url); | 98 virtual void NavigateToSuggestedURL(const GURL& suggested_url); |
| 93 virtual bool IsErrorOverridable() const; | 99 virtual bool IsErrorOverridable() const; |
| 94 virtual void ShowCaptivePortalInterstitial(const GURL& landing_url); | 100 virtual void ShowCaptivePortalInterstitial(const GURL& landing_url); |
| 95 virtual void ShowSSLInterstitial(); | 101 virtual void ShowSSLInterstitial(); |
| 102 virtual void ShowBadClockInterstitial(const base::Time& now); | |
|
estark
2015/09/01 13:28:28
It doesn't look like you actually override this an
felt
2015/09/01 15:49:41
Done.
| |
| 96 | 103 |
| 97 // Gets the result of whether the suggested URL is valid. Displays | 104 // Gets the result of whether the suggested URL is valid. Displays |
| 98 // common name mismatch interstitial or ssl interstitial accordingly. | 105 // common name mismatch interstitial or ssl interstitial accordingly. |
| 99 void CommonNameMismatchHandlerCallback( | 106 void CommonNameMismatchHandlerCallback( |
| 100 const CommonNameMismatchHandler::SuggestedUrlCheckResult& result, | 107 const CommonNameMismatchHandler::SuggestedUrlCheckResult& result, |
| 101 const GURL& suggested_url); | 108 const GURL& suggested_url); |
| 102 | 109 |
| 103 private: | 110 private: |
| 104 // content::NotificationObserver: | 111 // content::NotificationObserver: |
| 105 void Observe( | 112 void Observe( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 131 base::OneShotTimer<SSLErrorHandler> timer_; | 138 base::OneShotTimer<SSLErrorHandler> timer_; |
| 132 | 139 |
| 133 scoped_ptr<CommonNameMismatchHandler> common_name_mismatch_handler_; | 140 scoped_ptr<CommonNameMismatchHandler> common_name_mismatch_handler_; |
| 134 | 141 |
| 135 scoped_ptr<SSLCertReporter> ssl_cert_reporter_; | 142 scoped_ptr<SSLCertReporter> ssl_cert_reporter_; |
| 136 | 143 |
| 137 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 144 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 138 }; | 145 }; |
| 139 | 146 |
| 140 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 147 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| OLD | NEW |