ssl_blocking_page.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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#ifndef CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
6#define CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
7
8#include <string>
9#include <vector>
10
11#include "base/callback.h"
12#include "base/strings/string16.h"
13#include "base/time/time.h"
14#include "chrome/browser/history/history_service.h"
15#include "content/public/browser/interstitial_page_delegate.h"
16#include "net/ssl/ssl_info.h"
17#include "url/gurl.h"
18
19namespace base {
20class DictionaryValue;
21}
22
23namespace content {
24class InterstitialPage;
25class WebContents;
26}
27
28// This class is responsible for showing/hiding the interstitial page that is
29// shown when a certificate error happens.
30// It deletes itself when the interstitial page is closed.
31//
32// This class should only be used on the UI thread because its implementation
33// uses captive_portal::CaptivePortalService which can only be accessed on the
34// UI thread.
35class SSLBlockingPage : public content::InterstitialPageDelegate,
36                        public content::NotificationObserver {
37 public:
38  SSLBlockingPage(
39      content::WebContents* web_contents,
40      int cert_error,
41      const net::SSLInfo& ssl_info,
42      const GURL& request_url,
43      bool overridable,
44      bool strict_enforcement,
45      const base::Callback<void(bool)>& callback);
46  virtual ~SSLBlockingPage();
47
48  // A method that sets strings in the specified dictionary from the passed
49  // vector so that they can be used to resource the ssl_roadblock.html/
50  // ssl_error.html files.
51  // Note: there can be up to 5 strings in |extra_info|.
52  static void SetExtraInfo(base::DictionaryValue* strings,
53                           const std::vector<base::string16>& extra_info);
54
55 protected:
56  // InterstitialPageDelegate implementation.
57  virtual std::string GetHTMLContents() OVERRIDE;
58  virtual void CommandReceived(const std::string& command) OVERRIDE;
59  virtual void OverrideEntry(content::NavigationEntry* entry) OVERRIDE;
60  virtual void OverrideRendererPrefs(
61      content::RendererPreferences* prefs) OVERRIDE;
62  virtual void OnProceed() OVERRIDE;
63  virtual void OnDontProceed() OVERRIDE;
64
65 private:
66  void NotifyDenyCertificate();
67  void NotifyAllowCertificate();
68
69  // Used to query the HistoryService to see if the URL is in history. For UMA.
70  void OnGotHistoryCount(HistoryService::Handle handle,
71                         bool success,
72                         int num_visits,
73                         base::Time first_visit);
74
75  // content::NotificationObserver:
76  virtual void Observe(
77      int type,
78      const content::NotificationSource& source,
79      const content::NotificationDetails& details) OVERRIDE;
80
81  base::Callback<void(bool)> callback_;
82
83  content::WebContents* web_contents_;
84  int cert_error_;
85  const net::SSLInfo ssl_info_;
86  GURL request_url_;
87  // Could the user successfully override the error?
88  bool overridable_;
89  // Has the site requested strict enforcement of certificate errors?
90  bool strict_enforcement_;
91  content::InterstitialPage* interstitial_page_;  // Owns us.
92  // Is the hostname for an internal network?
93  bool internal_;
94  // How many times is this same URL in history?
95  int num_visits_;
96  // Used for getting num_visits_.
97  CancelableRequestConsumer request_consumer_;
98  // Is captive portal detection enabled?
99  bool captive_portal_detection_enabled_;
100  // Did the probe complete before the interstitial was closed?
101  bool captive_portal_probe_completed_;
102  // Did the captive portal probe receive an error or get a non-HTTP response?
103  bool captive_portal_no_response_;
104  // Was a captive portal detected?
105  bool captive_portal_detected_;
106
107  // For the FieldTrial: this contains the name of the condition.
108  std::string trialCondition_;
109
110  content::NotificationRegistrar registrar_;
111
112  DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage);
113};
114
115#endif  // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
116