summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/interstitials/ios_security_interstitial_page.h
blob: 128f833188de0236295d6f2ccfd12b31f1dc7dd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2015 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 IOS_CHROME_BROWSER_INTERSTITIALS_IOS_SECURITY_INTERSTITIAL_PAGE_H_
#define IOS_CHROME_BROWSER_INTERSTITIALS_IOS_SECURITY_INTERSTITIAL_PAGE_H_

#include <string>

#include "base/macros.h"
#include "base/strings/string16.h"
#include "ios/web/public/interstitials/web_interstitial_delegate.h"
#include "url/gurl.h"

class IOSChromeControllerClient;

namespace base {
class DictionaryValue;
}

namespace security_interstitials {
class MetricsHelper;
}

namespace web {
class WebInterstitial;
class WebState;
}

class IOSSecurityInterstitialPage : public web::HtmlWebInterstitialDelegate {
 public:
  IOSSecurityInterstitialPage(web::WebState* web_state,
                              const GURL& request_url);
  ~IOSSecurityInterstitialPage() override;

  // Creates an interstitial and shows it.
  void Show();

 protected:
  // Returns true if the interstitial should create a new navigation item.
  virtual bool ShouldCreateNewNavigation() const = 0;

  // Populates the strings used to generate the HTML from the template.
  virtual void PopulateInterstitialStrings(
      base::DictionaryValue* load_time_data) const = 0;

  // Gives an opportunity for child classes to react to Show() having run. The
  // |web_interstitial_| will now have a value.
  virtual void AfterShow() = 0;

  // web::HtmlWebInterstitialDelegate implementation.
  std::string GetHtmlContents() const override;

  // Returns the formatted host name for the request url.
  base::string16 GetFormattedHostName() const;

  // Returns the boolean value of the given |pref_name| from the PrefService of
  // the ChromeBrowserState associated with |web_state_|.
  bool IsPrefEnabled(const char* pref_name) const;

  web::WebState* web_state() const { return web_state_; }
  const GURL& request_url() const { return request_url_; }
  web::WebInterstitial* web_interstitial() const { return web_interstitial_; }

 private:
  // The WebState with which this interstitial page is associated. Not
  // available in the destructor since the it can be destroyed before this
  // class is destroyed.
  web::WebState* web_state_;
  const GURL request_url_;

  // Once non-null, the |web_interstitial_| takes ownership of this
  // IOSSecurityInterstitialPage instance.
  web::WebInterstitial* web_interstitial_;

  DISALLOW_COPY_AND_ASSIGN(IOSSecurityInterstitialPage);
};

#endif  // IOS_CHROME_BROWSER_INTERSTITIALS_IOS_SECURITY_INTERSTITIAL_PAGE_H_