1 // Copyright (c) 2012 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 CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_H_
6 #define CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_H_
7 
8 #include "content/common/content_export.h"
9 
10 class GURL;
11 
12 namespace gfx {
13 class Size;
14 }
15 
16 namespace content {
17 
18 class InterstitialPageDelegate;
19 class RenderFrameHost;
20 class WebContents;
21 
22 // This class is used for showing interstitial pages, pages that show some
23 // informative message asking for user validation before reaching the target
24 // page. (Navigating to a page served over bad HTTPS or a page containing
25 // malware are typical cases where an interstitial is required.)
26 //
27 // If specified in the Create function, this class creates a navigation entry so
28 // that when the interstitial shows, the current entry is the target URL.
29 //
30 // InterstitialPage instances take care of deleting themselves when closed
31 // through a navigation, the WebContents closing them or the tab containing them
32 // being closed.
33 
34 class InterstitialPage {
35  public:
36   // Creates an interstitial page to show in |web_contents|. |new_navigation|
37   // should be set to true when the interstitial is caused by loading a new
38   // page, in which case a temporary navigation entry is created with the URL
39   // |url| and added to the navigation controller (so the interstitial page
40   // appears as a new navigation entry). |new_navigation| should be false when
41   // the interstitial was triggered by a loading a sub-resource in a page. Takes
42   // ownership of |delegate|.
43   //
44   // Reloading the interstitial page will result in a new navigation to |url|.
45   CONTENT_EXPORT static InterstitialPage* Create(
46       WebContents* web_contents,
47       bool new_navigation,
48       const GURL& url,
49       InterstitialPageDelegate* delegate);
50 
51   // Returns the InterstitialPage, if any, associated with the specified
52   // |web_contents|. Note: This returns a value from the time the interstitial
53   // page has Show() called on it.
54   //
55   // Compare to WebContents::GetInterstitialPage.
56   CONTENT_EXPORT static InterstitialPage* GetInterstitialPage(
57       WebContents* web_contents);
58 
59   // Returns the InterstitialPage that hosts the RenderFrameHost, or nullptr if
60   // |rfh| is not a part of any InterstitialPage.
61   CONTENT_EXPORT static InterstitialPage* FromRenderFrameHost(
62       RenderFrameHost* rfh);
63 
~InterstitialPage()64   virtual ~InterstitialPage() {}
65 
66   // Shows the interstitial page in the tab.
67   virtual void Show() = 0;
68 
69   // Hides the interstitial page.
70   virtual void Hide() = 0;
71 
72   // Reverts to the page showing before the interstitial.
73   // Delegates should call this method when the user has chosen NOT to proceed
74   // to the target URL.
75   // Warning: if |new_navigation| was set to true in the constructor, 'this'
76   //          will be deleted when this method returns.
77   virtual void DontProceed() = 0;
78 
79   // Delegates should call this method when the user has chosen to proceed to
80   // the target URL.
81   // Warning: 'this' has been deleted when this method returns.
82   virtual void Proceed() = 0;
83 
84   // Sizes the RenderViewHost showing the actual interstitial page contents.
85   virtual void SetSize(const gfx::Size& size) = 0;
86 
87   // Sets the focus to the interstitial.
88   virtual void Focus() = 0;
89 
90   // Get the WebContents in which this interstitial is shown. Warning: Frames
91   // in the intersitital are NOT visible through WebContentObservers' normal
92   // notifications (e.g. RenderFrameDeleted). The only sensible use of this
93   // returned WebContents is to add a WebContentObserver and listen for the
94   // DidAttachInterstitialPage or DidDetachInterstitialPage notifications.
95   virtual WebContents* GetWebContents() = 0;
96 
97   // Gets the RenderFrameHost associated with the interstitial page's main
98   // frame. May return nullptr if the interstitial is already hidden.
99   virtual RenderFrameHost* GetMainFrame() = 0;
100 
101   virtual InterstitialPageDelegate* GetDelegateForTesting() = 0;
102   virtual void DontCreateViewForTesting() = 0;
103 };
104 
105 }  // namespace content
106 
107 #endif  // CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_H_
108