Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6515)

Unified Diff: chrome/browser/ssl/ssl_error_handler.h

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove notification, add observer for SSLErrorHandler timer. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/ssl_error_handler.h
diff --git a/chrome/browser/ssl/ssl_error_handler.h b/chrome/browser/ssl/ssl_error_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..83286528c0256d7330df47841a8452e9ffdad48e
--- /dev/null
+++ b/chrome/browser/ssl/ssl_error_handler.h
@@ -0,0 +1,117 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_
+#define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_
+
+#include <string>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/timer/timer.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "net/ssl/ssl_info.h"
+#include "url/gurl.h"
+
+namespace content {
+class RenderViewHost;
+class WebContents;
+}
+
+// This class is responsible for deciding whether to show an SSL warning or a
+// captive portal error page. It makes this decision by delaying the display of
+// SSL interstitial for a few seconds (2 by default), and waiting for a captive
+// portal result to arrive during this window. If a captive portal detected
+// result arrives in this window, a captive portal error page is shown.
+// Otherwise, an SSL interstitial is shown.
+//
+// This class deletes itself when the interstitial page is closed. It should
+// only be used on the UI thread because its implementation uses
+// captive_portal::CaptivePortalService which can only be accessed on the UI
+// thread.
+class SSLErrorHandler : public content::WebContentsObserver,
+ public content::NotificationObserver {
+ public:
+ SSLErrorHandler(content::WebContents* web_contents,
+ int cert_error,
+ const net::SSLInfo& ssl_info,
+ const GURL& request_url,
+ int options_mask,
+ const base::Callback<void(bool)>& callback);
+ ~SSLErrorHandler() override;
Bernhard Bauer 2014/12/18 18:10:06 Please make this protected. If this class deletes
meacer 2014/12/19 02:42:24 Done.
+
+ static void HandleSSLError(content::WebContents* web_contents,
+ int cert_error,
+ const net::SSLInfo& ssl_info,
+ const GURL& request_url,
+ int options_mask,
+ const base::Callback<void(bool)>& callback);
+
+ static void SetInterstitialDisplayDelayForTest(
+ base::TimeDelta interstitial_display_delay) {
+ interstitial_display_delay_ = interstitial_display_delay;
+ }
+
+ typedef base::Callback<void(content::WebContents*)> TimerFiredCallback;
+ static void SetInterstitialTimerFiredCallbackForTest(
+ TimerFiredCallback* callback) {
+ timer_fired_callback_ = callback;
+ }
mmenke 2014/12/18 15:44:03 Can't the test just use content::WaitForInterstiti
meacer 2014/12/19 02:42:24 This is used in FastErrorWithInterstitialTimer whe
+
+ protected:
+ // Called when an SSL cert error is encountered. Triggers a captive portal
+ // check and fires a one shot timer to wait for a "captive portal detected"
+ // result to arrive.
+ void StartHandlingError();
+ const base::OneShotTimer<SSLErrorHandler>& get_timer() const {
+ return timer_;
+ }
+
+ private:
+ // Time to wait before displaying the SSL interstitial. If a captive portal
+ // arrives before this, the captive portal interstitial is displayed instead.
+ static base::TimeDelta interstitial_display_delay_;
+
+ // Callback to call when the interstitial timer is fired. Used for testing.
+ static TimerFiredCallback* timer_fired_callback_;
+
+ // Callback for the one-shot timer. When the timer expires, an SSL error is
+ // immediately displayed.
+ void OnTimerExpired();
+
+ // These are virtual for tests:
+ virtual void CheckForCaptivePortal();
+ virtual void ShowCaptivePortalInterstitial();
+ virtual void ShowSSLInterstitial();
+
+ // content::NotificationObserver:
+ void Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ // content::WebContentsObserver:
+ void DidStartNavigationToPendingEntry(
+ const GURL& url,
+ content::NavigationController::ReloadType reload_type) override;
+ void DidStopLoading(
+ content::RenderViewHost* render_view_host) override;
+ void WebContentsDestroyed() override;
+
+ const int cert_error_;
+ const net::SSLInfo ssl_info_;
+ const GURL request_url_;
+ const int options_mask_;
+ const base::Callback<void(bool)> callback_;
+
+ content::NotificationRegistrar registrar_;
+ base::OneShotTimer<SSLErrorHandler> timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
+};
+
+#endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698