interstitial_page.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 10class GURL; 11 12namespace gfx { 13class Size; 14} 15 16namespace content { 17 18class InterstitialPageDelegate; 19class RenderViewHost; 20class 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 34class 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 // Retrieves the InterstitialPage if any associated with the specified 52 // |web_contents|. 53 CONTENT_EXPORT static InterstitialPage* GetInterstitialPage( 54 WebContents* web_contents); 55 56 virtual ~InterstitialPage() {} 57 58 // Shows the interstitial page in the tab. 59 virtual void Show() = 0; 60 61 // Hides the interstitial page. 62 virtual void Hide() = 0; 63 64 // Reverts to the page showing before the interstitial. 65 // Delegates should call this method when the user has chosen NOT to proceed 66 // to the target URL. 67 // Warning: if |new_navigation| was set to true in the constructor, 'this' 68 // will be deleted when this method returns. 69 virtual void DontProceed() = 0; 70 71 // Delegates should call this method when the user has chosen to proceed to 72 // the target URL. 73 // Warning: 'this' has been deleted when this method returns. 74 virtual void Proceed() = 0; 75 76 // Sizes the RenderViewHost showing the actual interstitial page contents. 77 virtual void SetSize(const gfx::Size& size) = 0; 78 79 // Sets the focus to the interstitial. 80 virtual void Focus() = 0; 81 82 virtual RenderViewHost* GetRenderViewHostForTesting() const = 0; 83 virtual InterstitialPageDelegate* GetDelegateForTesting() = 0; 84 virtual void DontCreateViewForTesting() = 0; 85}; 86 87} // namespace content 88 89#endif // CONTENT_PUBLIC_BROWSER_INTERSTITIAL_PAGE_H_ 90