summaryrefslogtreecommitdiffstats
path: root/content/public/browser/interstitial_page.h
blob: 4a0e33f45a227bf2524a54c40275422bd7f135b6 (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
// Copyright (c) 2012 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 CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_H_
#define CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_H_
#pragma once

#include "content/common/content_export.h"

class GURL;

namespace gfx {
class Size;
}

namespace content {

class InterstitialPageDelegate;
class RenderViewHost;
class WebContents;

// This class is used for showing interstitial pages, pages that show some
// informative message asking for user validation before reaching the target
// page. (Navigating to a page served over bad HTTPS or a page containing
// malware are typical cases where an interstitial is required.)
//
// If specified in the Create function, this class creates a navigation entry so
// that when the interstitial shows, the current entry is the target URL.
//
// InterstitialPage instances take care of deleting themselves when closed
// through a navigation, the WebContents closing them or the tab containing them
// being closed.

class InterstitialPage {
 public:
  // Creates an interstitial page to show in |web_contents|. |new_navigation|
  // should be set to true when the interstitial is caused by loading a new
  // page, in which case a temporary navigation entry is created with the URL
  // |url| and added to the navigation controller (so the interstitial page
  // appears as a new navigation entry). |new_navigation| should be false when
  // the interstitial was triggered by a loading a sub-resource in a page. Takes
  // ownership of |delegate|.
  CONTENT_EXPORT static InterstitialPage* Create(
      WebContents* web_contents,
      bool new_navigation,
      const GURL& url,
      InterstitialPageDelegate* delegate);

  // Retrieves the InterstitialPage if any associated with the specified
  // |web_contents|.
  CONTENT_EXPORT static InterstitialPage* GetInterstitialPage(
      WebContents* web_contents);

  virtual ~InterstitialPage() {}

  // Shows the interstitial page in the tab.
  virtual void Show() = 0;

  // Hides the interstitial page.
  virtual void Hide() = 0;

  // Reverts to the page showing before the interstitial.
  // Delegates should call this method when the user has chosen NOT to proceed
  // to the target URL.
  // Warning: if |new_navigation| was set to true in the constructor, 'this'
  //          will be deleted when this method returns.
  virtual void DontProceed() = 0;

  // Delegates should call this method when the user has chosen to proceed to
  // the target URL.
  // Warning: 'this' has been deleted when this method returns.
  virtual void Proceed() = 0;

  // Sizes the RenderViewHost showing the actual interstitial page contents.
  virtual void SetSize(const gfx::Size& size) = 0;

  // Sets the focus to the interstitial.
  virtual void Focus() = 0;

  virtual RenderViewHost* GetRenderViewHostForTesting() const = 0;
  virtual InterstitialPageDelegate* GetDelegateForTesting() = 0;
  virtual void DontCreateViewForTesting() = 0;
};

}  // namespace content

#endif  // CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_H_