1 // Copyright 2015 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_COMPONENTS_SECURITY_INTERSTITIALS_IOS_BLOCKING_PAGE_CONTROLLER_CLIENT_H_
6 #define IOS_COMPONENTS_SECURITY_INTERSTITIALS_IOS_BLOCKING_PAGE_CONTROLLER_CLIENT_H_
7 
8 #include <string>
9 
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "components/security_interstitials/core/controller_client.h"
13 #include "ios/web/public/web_state_observer.h"
14 
15 class GURL;
16 
17 namespace web {
18 class WebInterstitial;
19 class WebState;
20 }  // namespace web
21 
22 namespace security_interstitials {
23 class MetricsHelper;
24 
25 // Provides embedder-specific logic for the security error page controller.
26 class IOSBlockingPageControllerClient
27     : public security_interstitials::ControllerClient,
28       public web::WebStateObserver {
29  public:
30   IOSBlockingPageControllerClient(
31       web::WebState* web_state,
32       std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper,
33       const std::string& app_locale);
34   ~IOSBlockingPageControllerClient() override;
35 
36   // security_interstitials::ControllerClient implementation.
37   void Proceed() override;
38   void GoBack() override;
39   bool CanGoBack() override;
40   void OpenEnhancedProtectionSettings() override;
41 
42   void SetWebInterstitial(web::WebInterstitial* web_interstitial);
43 
44   // web::WebStateObserver implementation.
45   void WebStateDestroyed(web::WebState* web_state) override;
46 
47   const std::string& GetApplicationLocale() const override;
48 
49  protected:
50   // The WebState passed on initialization.
web_state()51   web::WebState* web_state() const { return web_state_; }
52 
53   // security_interstitials::ControllerClient implementation.
54   bool CanLaunchDateAndTimeSettings() override;
55   void LaunchDateAndTimeSettings() override;
56   bool CanGoBackBeforeNavigation() override;
57   void GoBackAfterNavigationCommitted() override;
58   void Reload() override;
59   void OpenUrlInCurrentTab(const GURL& url) override;
60   void OpenUrlInNewForegroundTab(const GURL& url) override;
61   PrefService* GetPrefService() override;
62   const std::string GetExtendedReportingPrefName() const override;
63 
64  private:
65   // Closes the tab. Called in cases where a user clicks "Back to safety" and
66   // it's not possible to go back.
67   void Close();
68 
69   web::WebState* web_state_;
70   web::WebInterstitial* web_interstitial_;
71   const std::string app_locale_;
72 
73   base::WeakPtrFactory<IOSBlockingPageControllerClient> weak_factory_;
74 
75   DISALLOW_COPY_AND_ASSIGN(IOSBlockingPageControllerClient);
76 };
77 
78 }  // namespace security_interstitials
79 
80 #endif  // IOS_COMPONENTS_SECURITY_INTERSTITIALS_IOS_BLOCKING_PAGE_CONTROLLER_CLIENT_H_
81