[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / content / browser / frame_host / interstitial_page_impl.h
blobf8aa8a7c4c70890f831cb187f132e7047a5ef079
1 // Copyright 2013 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.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_INTERSTITIAL_PAGE_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_INTERSTITIAL_PAGE_IMPL_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/browser/frame_host/frame_tree.h"
12 #include "content/browser/frame_host/navigator_delegate.h"
13 #include "content/browser/frame_host/render_frame_host_delegate.h"
14 #include "content/browser/renderer_host/render_view_host_delegate.h"
15 #include "content/browser/renderer_host/render_widget_host_delegate.h"
16 #include "content/public/browser/dom_operation_notification_details.h"
17 #include "content/public/browser/interstitial_page.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/web_contents_observer.h"
21 #include "content/public/common/renderer_preferences.h"
22 #include "url/gurl.h"
24 namespace content {
25 class NavigationEntry;
26 class NavigationControllerImpl;
27 class RenderViewHostImpl;
28 class RenderWidgetHostView;
29 class WebContentsView;
31 enum ResourceRequestAction {
32 BLOCK,
33 RESUME,
34 CANCEL
37 class CONTENT_EXPORT InterstitialPageImpl
38 : public NON_EXPORTED_BASE(InterstitialPage),
39 public NotificationObserver,
40 public NON_EXPORTED_BASE(RenderFrameHostDelegate),
41 public RenderViewHostDelegate,
42 public RenderWidgetHostDelegate,
43 public NON_EXPORTED_BASE(NavigatorDelegate) {
44 public:
45 // The different state of actions the user can take in an interstitial.
46 enum ActionState {
47 NO_ACTION, // No action has been taken yet.
48 PROCEED_ACTION, // "Proceed" was selected.
49 DONT_PROCEED_ACTION // "Don't proceed" was selected.
52 InterstitialPageImpl(WebContents* web_contents,
53 RenderWidgetHostDelegate* render_widget_host_delegate,
54 bool new_navigation,
55 const GURL& url,
56 InterstitialPageDelegate* delegate);
57 ~InterstitialPageImpl() override;
59 // InterstitialPage implementation:
60 void Show() override;
61 void Hide() override;
62 void DontProceed() override;
63 void Proceed() override;
64 RenderFrameHost* GetMainFrame() const override;
65 InterstitialPageDelegate* GetDelegateForTesting() override;
66 void DontCreateViewForTesting() override;
67 void SetSize(const gfx::Size& size) override;
68 void Focus() override;
70 // Allows the user to navigate away by disabling the interstitial, canceling
71 // the pending request, and unblocking the hidden renderer. The interstitial
72 // will stay visible until the navigation completes.
73 void CancelForNavigation();
75 // Focus the first (last if reverse is true) element in the interstitial page.
76 // Called when tab traversing.
77 void FocusThroughTabTraversal(bool reverse);
79 RenderWidgetHostView* GetView();
81 // See description above field.
82 void set_reload_on_dont_proceed(bool value) {
83 reload_on_dont_proceed_ = value;
85 bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; }
87 // TODO(nasko): This should move to InterstitialPageNavigatorImpl, but in
88 // the meantime make it public, so it can be called directly.
89 void DidNavigate(
90 RenderViewHost* render_view_host,
91 const FrameHostMsg_DidCommitProvisionalLoad_Params& params);
93 protected:
94 // NotificationObserver method:
95 void Observe(int type,
96 const NotificationSource& source,
97 const NotificationDetails& details) override;
99 // RenderFrameHostDelegate implementation:
100 bool OnMessageReceived(RenderFrameHost* render_frame_host,
101 const IPC::Message& message) override;
102 void RenderFrameCreated(RenderFrameHost* render_frame_host) override;
103 void UpdateTitle(RenderFrameHost* render_frame_host,
104 int32 page_id,
105 const base::string16& title,
106 base::i18n::TextDirection title_direction) override;
107 AccessibilityMode GetAccessibilityMode() const override;
109 // RenderViewHostDelegate implementation:
110 RenderViewHostDelegateView* GetDelegateView() override;
111 bool OnMessageReceived(RenderViewHost* render_view_host,
112 const IPC::Message& message) override;
113 const GURL& GetMainFrameLastCommittedURL() const override;
114 void RenderViewTerminated(RenderViewHost* render_view_host,
115 base::TerminationStatus status,
116 int error_code) override;
117 RendererPreferences GetRendererPrefs(
118 BrowserContext* browser_context) const override;
119 gfx::Rect GetRootWindowResizerRect() const override;
120 void CreateNewWindow(
121 int render_process_id,
122 int route_id,
123 int main_frame_route_id,
124 const ViewHostMsg_CreateWindow_Params& params,
125 SessionStorageNamespace* session_storage_namespace) override;
126 void CreateNewWidget(int render_process_id,
127 int route_id,
128 blink::WebPopupType popup_type) override;
129 void CreateNewFullscreenWidget(int render_process_id, int route_id) override;
130 void ShowCreatedWindow(int route_id,
131 WindowOpenDisposition disposition,
132 const gfx::Rect& initial_rect,
133 bool user_gesture) override;
134 void ShowCreatedWidget(int route_id, const gfx::Rect& initial_rect) override;
135 void ShowCreatedFullscreenWidget(int route_id) override;
137 SessionStorageNamespace* GetSessionStorageNamespace(
138 SiteInstance* instance) override;
140 FrameTree* GetFrameTree() override;
142 // RenderWidgetHostDelegate implementation:
143 void RenderWidgetDeleted(RenderWidgetHostImpl* render_widget_host) override;
144 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
145 bool* is_keyboard_shortcut) override;
146 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override;
147 #if defined(OS_WIN)
148 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible() override;
149 #endif
151 bool enabled() const { return enabled_; }
152 WebContents* web_contents() const;
153 const GURL& url() const { return url_; }
155 // Creates the WebContentsView that shows the interstitial RVH.
156 // Overriden in unit tests.
157 virtual WebContentsView* CreateWebContentsView();
159 // Notification magic.
160 NotificationRegistrar notification_registrar_;
162 private:
163 class InterstitialPageRVHDelegateView;
164 class UnderlyingContentObserver : public WebContentsObserver {
165 public:
166 UnderlyingContentObserver(WebContents* web_contents,
167 InterstitialPageImpl* interstitial);
169 // WebContentsObserver implementation:
170 void WebContentsDestroyed() override;
171 void NavigationEntryCommitted(
172 const LoadCommittedDetails& load_details) override;
174 // This observer does not override OnMessageReceived or otherwise handle
175 // messages from the underlying content, because the interstitial should not
176 // care about them. Messages from the interstitial page (which has its own
177 // FrameTree) arrive through the RenderFrameHostDelegate interface, not
178 // WebContentsObserver.
180 private:
181 InterstitialPageImpl* const interstitial_;
183 DISALLOW_COPY_AND_ASSIGN(UnderlyingContentObserver);
186 // Disable the interstitial:
187 // - if it is not yet showing, then it won't be shown.
188 // - any command sent by the RenderViewHost will be ignored.
189 void Disable();
191 // Delete ourselves, causing Shutdown on the RVH to be called.
192 void Shutdown();
194 void OnNavigatingAwayOrTabClosing();
196 // Executes the passed action on the ResourceDispatcher (on the IO thread).
197 // Used to block/resume/cancel requests for the RenderViewHost hidden by this
198 // interstitial.
199 void TakeActionOnResourceDispatcher(ResourceRequestAction action);
201 // IPC message handlers.
202 void OnDomOperationResponse(const std::string& json_string,
203 int automation_id);
205 // Creates the RenderViewHost containing the interstitial content.
206 RenderViewHostImpl* CreateRenderViewHost();
208 // Watches the underlying WebContents for reasons to cancel the interstitial.
209 UnderlyingContentObserver underlying_content_observer_;
211 // The contents in which we are displayed. This is valid until Hide is
212 // called, at which point it will be set to NULL because the WebContents
213 // itself may be deleted.
214 WebContents* web_contents_;
216 // The NavigationController for the content this page is being displayed over.
217 NavigationControllerImpl* controller_;
219 // Delegate for dispatching keyboard events and accessing the native view.
220 RenderWidgetHostDelegate* render_widget_host_delegate_;
222 // The URL that is shown when the interstitial is showing.
223 GURL url_;
225 // Whether this interstitial is shown as a result of a new navigation (in
226 // which case a transient navigation entry is created).
227 bool new_navigation_;
229 // Whether we should discard the pending navigation entry when not proceeding.
230 // This is to deal with cases where |new_navigation_| is true but a new
231 // pending entry was created since this interstitial was shown and we should
232 // not discard it.
233 bool should_discard_pending_nav_entry_;
235 // If true and the user chooses not to proceed the target NavigationController
236 // is reloaded. This is used when two NavigationControllers are merged
237 // (CopyStateFromAndPrune).
238 // The default is false.
239 bool reload_on_dont_proceed_;
241 // Whether this interstitial is enabled. See Disable() for more info.
242 bool enabled_;
244 // Whether the Proceed or DontProceed methods have been called yet.
245 ActionState action_taken_;
247 // The RenderViewHost displaying the interstitial contents. This is valid
248 // until Hide is called, at which point it will be set to NULL, signifying
249 // that shutdown has started.
250 // TODO(creis): This is now owned by the FrameTree. We should route things
251 // through the tree's root RenderFrameHost instead.
252 RenderViewHostImpl* render_view_host_;
254 // The frame tree structure of the current page.
255 FrameTree frame_tree_;
257 // The IDs for the Render[View|Process]Host hidden by this interstitial.
258 int original_child_id_;
259 int original_rvh_id_;
261 // Whether or not we should change the title of the contents when hidden (to
262 // revert it to its original value).
263 bool should_revert_web_contents_title_;
265 // Whether or not the contents was loading resources when the interstitial was
266 // shown. We restore this state if the user proceeds from the interstitial.
267 bool web_contents_was_loading_;
269 // Whether the ResourceDispatcherHost has been notified to cancel/resume the
270 // resource requests blocked for the RenderViewHost.
271 bool resource_dispatcher_host_notified_;
273 // The original title of the contents that should be reverted to when the
274 // interstitial is hidden.
275 base::string16 original_web_contents_title_;
277 // Our RenderViewHostViewDelegate, necessary for accelerators to work.
278 scoped_ptr<InterstitialPageRVHDelegateView> rvh_delegate_view_;
280 // Settings passed to the renderer.
281 mutable RendererPreferences renderer_preferences_;
283 bool create_view_;
285 scoped_ptr<InterstitialPageDelegate> delegate_;
287 scoped_refptr<SessionStorageNamespace> session_storage_namespace_;
289 base::WeakPtrFactory<InterstitialPageImpl> weak_ptr_factory_;
291 DISALLOW_COPY_AND_ASSIGN(InterstitialPageImpl);
294 } // namespace content
296 #endif // CONTENT_BROWSER_FRAME_HOST_INTERSTITIAL_PAGE_IMPL_H_