- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ssl / ssl_blocking_page.h
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
19 namespace base {
20 class DictionaryValue;
21 }
22
23 namespace content {
24 class InterstitialPage;
25 class 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 class SSLBlockingPage : public content::InterstitialPageDelegate {
32  public:
33   SSLBlockingPage(
34       content::WebContents* web_contents,
35       int cert_error,
36       const net::SSLInfo& ssl_info,
37       const GURL& request_url,
38       bool overridable,
39       bool strict_enforcement,
40       const base::Callback<void(bool)>& callback);
41   virtual ~SSLBlockingPage();
42
43   // A method that sets strings in the specified dictionary from the passed
44   // vector so that they can be used to resource the ssl_roadblock.html/
45   // ssl_error.html files.
46   // Note: there can be up to 5 strings in |extra_info|.
47   static void SetExtraInfo(base::DictionaryValue* strings,
48                            const std::vector<string16>& extra_info);
49
50  protected:
51   // InterstitialPageDelegate implementation.
52   virtual std::string GetHTMLContents() OVERRIDE;
53   virtual void CommandReceived(const std::string& command) OVERRIDE;
54   virtual void OverrideEntry(content::NavigationEntry* entry) OVERRIDE;
55   virtual void OverrideRendererPrefs(
56       content::RendererPreferences* prefs) OVERRIDE;
57   virtual void OnProceed() OVERRIDE;
58   virtual void OnDontProceed() OVERRIDE;
59
60  private:
61   void NotifyDenyCertificate();
62   void NotifyAllowCertificate();
63
64   // Used to query the HistoryService to see if the URL is in history. For UMA.
65   void OnGotHistoryCount(HistoryService::Handle handle,
66                          bool success,
67                          int num_visits,
68                          base::Time first_visit);
69
70   base::Callback<void(bool)> callback_;
71
72   content::WebContents* web_contents_;
73   int cert_error_;
74   net::SSLInfo ssl_info_;
75   GURL request_url_;
76   // Could the user successfully override the error?
77   bool overridable_;
78   // Has the site requested strict enforcement of certificate errors?
79   bool strict_enforcement_;
80   content::InterstitialPage* interstitial_page_;  // Owns us.
81   // Is the hostname for an internal network?
82   bool internal_;
83   // How many times is this same URL in history?
84   int num_visits_;
85   // Used for getting num_visits_.
86   CancelableRequestConsumer request_consumer_;
87
88   // For the FieldTrial: this contains the name of the condition.
89   std::string trialCondition_;
90
91   DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage);
92 };
93
94 #endif  // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_