1 // Copyright 2016 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 IOS_CHROME_BROWSER_SSL_IOS_SSL_BLOCKING_PAGE_H_
6 #define IOS_CHROME_BROWSER_SSL_IOS_SSL_BLOCKING_PAGE_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/time/time.h"
14 #include "ios/components/security_interstitials/ios_security_interstitial_page.h"
15 #include "net/ssl/ssl_info.h"
16 
17 class IOSBlockingPageControllerClient;
18 class GURL;
19 
20 namespace security_interstitials {
21 class SSLErrorUI;
22 }
23 
24 // This class is responsible for showing/hiding the interstitial page that is
25 // shown when a certificate error happens.
26 // It deletes itself when the interstitial page is closed.
27 class IOSSSLBlockingPage
28     : public security_interstitials::IOSSecurityInterstitialPage {
29  public:
30   ~IOSSSLBlockingPage() override;
31 
32   // Creates an SSL blocking page. If the blocking page isn't shown, the caller
33   // is responsible for cleaning up the blocking page, otherwise the
34   // interstitial takes ownership when shown. |options_mask| must be a bitwise
35   // mask of SSLErrorOptionsMask values.
36   IOSSSLBlockingPage(
37       web::WebState* web_state,
38       int cert_error,
39       const net::SSLInfo& ssl_info,
40       const GURL& request_url,
41       int options_mask,
42       const base::Time& time_triggered,
43       base::OnceCallback<void(bool)> callback,
44       std::unique_ptr<security_interstitials::IOSBlockingPageControllerClient>
45           client);
46 
47  protected:
48   // InterstitialPageDelegate implementation.
49   void CommandReceived(const std::string& command) override;
50   void OnProceed() override;
51   void OnDontProceed() override;
52   void OverrideItem(web::NavigationItem* item) override;
53 
54   // SecurityInterstitialPage implementation:
55   bool ShouldCreateNewNavigation() const override;
56   void PopulateInterstitialStrings(
57       base::DictionaryValue* load_time_data) const override;
58   void AfterShow() override;
59 
60  private:
61   void NotifyDenyCertificate();
62   void HandleScriptCommand(const base::DictionaryValue& message,
63                            const GURL& origin_url,
64                            bool user_is_interacting,
65                            web::WebFrame* sender_frame) override;
66 
67   // Returns true if |options_mask| refers to a soft-overridable SSL error.
68   static bool IsOverridable(int options_mask);
69 
70   web::WebState* web_state_ = nullptr;
71   base::OnceCallback<void(bool)> callback_;
72   const net::SSLInfo ssl_info_;
73   const bool overridable_;  // The UI allows the user to override the error.
74 
75   std::unique_ptr<security_interstitials::IOSBlockingPageControllerClient>
76       controller_;
77   std::unique_ptr<security_interstitials::SSLErrorUI> ssl_error_ui_;
78 
79   DISALLOW_COPY_AND_ASSIGN(IOSSSLBlockingPage);
80 };
81 
82 #endif  // IOS_CHROME_BROWSER_SSL_IOS_SSL_BLOCKING_PAGE_H_
83