summaryrefslogtreecommitdiffstats
path: root/chrome/browser/interstitials/security_interstitial_page.h
blob: 0bd632bd65fa8bb8dd4bf093b8414dbb65fc6460 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2014 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 CHROME_BROWSER_INTERSTITIALS_SECURITY_INTERSTITIAL_PAGE_H_
#define CHROME_BROWSER_INTERSTITIALS_SECURITY_INTERSTITIAL_PAGE_H_

#include "base/strings/string16.h"
#include "content/public/browser/interstitial_page_delegate.h"
#include "url/gurl.h"

namespace base {
class DictionaryValue;
}

namespace content {
class InterstitialPage;
class WebContents;
}

namespace interstitials {
// Constants used to communicate with the JavaScript.
extern const char kBoxChecked[];
extern const char kDisplayCheckBox[];
extern const char kOptInLink[];
extern const char kPrivacyLinkHtml[];
}

namespace security_interstitials {
class MetricsHelper;
}

class SecurityInterstitialPage : public content::InterstitialPageDelegate {
 public:
  // These represent the commands sent from the interstitial JavaScript.
  // DO NOT reorder or change these without also changing the JavaScript!
  // See chrome/browser/resources/security_warnings/interstitial_v2.js
  enum SecurityInterstitialCommands {
    // Used by tests
    CMD_ERROR = -3,
    CMD_TEXT_FOUND = -2,
    CMD_TEXT_NOT_FOUND = -1,
    // Decisions
    CMD_DONT_PROCEED = 0,
    CMD_PROCEED = 1,
    // Ways for user to get more information
    CMD_SHOW_MORE_SECTION = 2,
    CMD_OPEN_HELP_CENTER = 3,
    CMD_OPEN_DIAGNOSTIC = 4,
    // Primary button actions
    CMD_RELOAD = 5,
    CMD_OPEN_DATE_SETTINGS = 6,
    CMD_OPEN_LOGIN = 7,
    // Safe Browsing Extended Reporting
    CMD_DO_REPORT = 8,
    CMD_DONT_REPORT = 9,
    CMD_OPEN_REPORTING_PRIVACY = 10,
    // Report a phishing error
    CMD_REPORT_PHISHING_ERROR = 11,
  };

  SecurityInterstitialPage(content::WebContents* web_contents,
                           const GURL& url);
  ~SecurityInterstitialPage() override;

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

  // Prevents creating the actual interstitial view for testing.
  void DontCreateViewForTesting();

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

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

  // InterstitialPageDelegate method:
  std::string GetHTMLContents() override;

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

  content::InterstitialPage* interstitial_page() const;
  content::WebContents* web_contents() const;
  GURL request_url() const;

  // Record the user's preference for reporting information about
  // malware and SSL errors.
  void SetReportingPreference(bool report);

  // Returns the boolean value of the given |pref| from the PrefService of the
  // Profile associated with |web_contents_|.
  bool IsPrefEnabled(const char* pref);

  void OpenExtendedReportingPrivacyPolicy();

  security_interstitials::MetricsHelper* metrics_helper() const;
  void set_metrics_helper(
      security_interstitials::MetricsHelper* metrics_helper);

 private:
  scoped_ptr<security_interstitials::MetricsHelper> metrics_helper_;
  // The WebContents with which this interstitial page is
  // associated. Not available in ~SecurityInterstitialPage, since it
  // can be destroyed before this class is destroyed.
  content::WebContents* web_contents_;
  const GURL request_url_;
  // Once shown, |interstitial_page| takes ownership of this
  // SecurityInterstitialPage instance.
  content::InterstitialPage* interstitial_page_;
  // Whether the interstitial should create a view.
  bool create_view_;

  DISALLOW_COPY_AND_ASSIGN(SecurityInterstitialPage);
};

#endif  // CHROME_BROWSER_INTERSTITIALS_SECURITY_INTERSTITIAL_PAGE_H_