Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / frame_host / interstitial_page_impl.h
blob7e126e61b2a531555315d8fc08b0f1a3311209b1
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;
108 void Cut() override;
109 void Copy() override;
110 void Paste() override;
111 void SelectAll() override;
113 // RenderViewHostDelegate implementation:
114 RenderViewHostDelegateView* GetDelegateView() override;
115 bool OnMessageReceived(RenderViewHost* render_view_host,
116 const IPC::Message& message) override;
117 const GURL& GetMainFrameLastCommittedURL() const override;
118 void RenderViewTerminated(RenderViewHost* render_view_host,
119 base::TerminationStatus status,
120 int error_code) override;
121 RendererPreferences GetRendererPrefs(
122 BrowserContext* browser_context) const override;
123 gfx::Rect GetRootWindowResizerRect() const override;
124 void CreateNewWindow(
125 SiteInstance* source_site_instance,
126 int route_id,
127 int main_frame_route_id,
128 const ViewHostMsg_CreateWindow_Params& params,
129 SessionStorageNamespace* session_storage_namespace) override;
130 void CreateNewWidget(int32 render_process_id,
131 int32 route_id,
132 int32 surface_id,
133 blink::WebPopupType popup_type) override;
134 void CreateNewFullscreenWidget(int32 render_process_id,
135 int32 route_id,
136 int32 surface_id) override;
137 void ShowCreatedWindow(int route_id,
138 WindowOpenDisposition disposition,
139 const gfx::Rect& initial_rect,
140 bool user_gesture) override;
141 void ShowCreatedWidget(int route_id, const gfx::Rect& initial_rect) override;
142 void ShowCreatedFullscreenWidget(int route_id) override;
144 SessionStorageNamespace* GetSessionStorageNamespace(
145 SiteInstance* instance) override;
147 FrameTree* GetFrameTree() override;
149 // RenderWidgetHostDelegate implementation:
150 void RenderWidgetDeleted(RenderWidgetHostImpl* render_widget_host) override;
151 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
152 bool* is_keyboard_shortcut) override;
153 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override;
154 #if defined(OS_WIN)
155 gfx::NativeViewAccessible GetParentNativeViewAccessible() override;
156 #endif
158 bool enabled() const { return enabled_; }
159 WebContents* web_contents() const;
160 const GURL& url() const { return url_; }
162 // Creates the WebContentsView that shows the interstitial RVH.
163 // Overriden in unit tests.
164 virtual WebContentsView* CreateWebContentsView();
166 // Notification magic.
167 NotificationRegistrar notification_registrar_;
169 private:
170 class InterstitialPageRVHDelegateView;
171 class UnderlyingContentObserver : public WebContentsObserver {
172 public:
173 UnderlyingContentObserver(WebContents* web_contents,
174 InterstitialPageImpl* interstitial);
176 // WebContentsObserver implementation:
177 void WebContentsDestroyed() override;
178 void NavigationEntryCommitted(
179 const LoadCommittedDetails& load_details) override;
181 // This observer does not override OnMessageReceived or otherwise handle
182 // messages from the underlying content, because the interstitial should not
183 // care about them. Messages from the interstitial page (which has its own
184 // FrameTree) arrive through the RenderFrameHostDelegate interface, not
185 // WebContentsObserver.
187 private:
188 InterstitialPageImpl* const interstitial_;
190 DISALLOW_COPY_AND_ASSIGN(UnderlyingContentObserver);
193 // Disable the interstitial:
194 // - if it is not yet showing, then it won't be shown.
195 // - any command sent by the RenderViewHost will be ignored.
196 void Disable();
198 // Delete ourselves, causing Shutdown on the RVH to be called.
199 void Shutdown();
201 void OnNavigatingAwayOrTabClosing();
203 // Executes the passed action on the ResourceDispatcher (on the IO thread).
204 // Used to block/resume/cancel requests for the RenderViewHost hidden by this
205 // interstitial.
206 void TakeActionOnResourceDispatcher(ResourceRequestAction action);
208 // IPC message handlers.
209 void OnDomOperationResponse(const std::string& json_string,
210 int automation_id);
212 // Creates the RenderViewHost containing the interstitial content.
213 RenderViewHostImpl* CreateRenderViewHost();
215 // Watches the underlying WebContents for reasons to cancel the interstitial.
216 UnderlyingContentObserver underlying_content_observer_;
218 // The contents in which we are displayed. This is valid until Hide is
219 // called, at which point it will be set to NULL because the WebContents
220 // itself may be deleted.
221 WebContents* web_contents_;
223 // The NavigationController for the content this page is being displayed over.
224 NavigationControllerImpl* controller_;
226 // Delegate for dispatching keyboard events and accessing the native view.
227 RenderWidgetHostDelegate* render_widget_host_delegate_;
229 // The URL that is shown when the interstitial is showing.
230 GURL url_;
232 // Whether this interstitial is shown as a result of a new navigation (in
233 // which case a transient navigation entry is created).
234 bool new_navigation_;
236 // Whether we should discard the pending navigation entry when not proceeding.
237 // This is to deal with cases where |new_navigation_| is true but a new
238 // pending entry was created since this interstitial was shown and we should
239 // not discard it.
240 bool should_discard_pending_nav_entry_;
242 // If true and the user chooses not to proceed the target NavigationController
243 // is reloaded. This is used when two NavigationControllers are merged
244 // (CopyStateFromAndPrune).
245 // The default is false.
246 bool reload_on_dont_proceed_;
248 // Whether this interstitial is enabled. See Disable() for more info.
249 bool enabled_;
251 // Whether the Proceed or DontProceed methods have been called yet.
252 ActionState action_taken_;
254 // The RenderViewHost displaying the interstitial contents. This is valid
255 // until Hide is called, at which point it will be set to NULL, signifying
256 // that shutdown has started.
257 // TODO(creis): This is now owned by the FrameTree. We should route things
258 // through the tree's root RenderFrameHost instead.
259 RenderViewHostImpl* render_view_host_;
261 // The frame tree structure of the current page.
262 FrameTree frame_tree_;
264 // The IDs for the Render[View|Process]Host hidden by this interstitial.
265 int original_child_id_;
266 int original_rvh_id_;
268 // Whether or not we should change the title of the contents when hidden (to
269 // revert it to its original value).
270 bool should_revert_web_contents_title_;
272 // Whether or not the contents was loading resources when the interstitial was
273 // shown. We restore this state if the user proceeds from the interstitial.
274 bool web_contents_was_loading_;
276 // Whether the ResourceDispatcherHost has been notified to cancel/resume the
277 // resource requests blocked for the RenderViewHost.
278 bool resource_dispatcher_host_notified_;
280 // The original title of the contents that should be reverted to when the
281 // interstitial is hidden.
282 base::string16 original_web_contents_title_;
284 // Our RenderViewHostViewDelegate, necessary for accelerators to work.
285 scoped_ptr<InterstitialPageRVHDelegateView> rvh_delegate_view_;
287 // Settings passed to the renderer.
288 mutable RendererPreferences renderer_preferences_;
290 bool create_view_;
292 scoped_ptr<InterstitialPageDelegate> delegate_;
294 scoped_refptr<SessionStorageNamespace> session_storage_namespace_;
296 base::WeakPtrFactory<InterstitialPageImpl> weak_ptr_factory_;
298 DISALLOW_COPY_AND_ASSIGN(InterstitialPageImpl);
301 } // namespace content
303 #endif // CONTENT_BROWSER_FRAME_HOST_INTERSTITIAL_PAGE_IMPL_H_