Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / browser / frame_host / interstitial_page_impl.h
blob2acb6e5d94f3bc79a9f55642c67b2145911413a4
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(int render_process_id,
131 int route_id,
132 blink::WebPopupType popup_type) override;
133 void CreateNewFullscreenWidget(int render_process_id, int route_id) override;
134 void ShowCreatedWindow(int route_id,
135 WindowOpenDisposition disposition,
136 const gfx::Rect& initial_rect,
137 bool user_gesture) override;
138 void ShowCreatedWidget(int route_id, const gfx::Rect& initial_rect) override;
139 void ShowCreatedFullscreenWidget(int route_id) override;
141 SessionStorageNamespace* GetSessionStorageNamespace(
142 SiteInstance* instance) override;
144 FrameTree* GetFrameTree() override;
146 // RenderWidgetHostDelegate implementation:
147 void RenderWidgetDeleted(RenderWidgetHostImpl* render_widget_host) override;
148 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
149 bool* is_keyboard_shortcut) override;
150 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override;
151 #if defined(OS_WIN)
152 gfx::NativeViewAccessible GetParentNativeViewAccessible() override;
153 #endif
155 bool enabled() const { return enabled_; }
156 WebContents* web_contents() const;
157 const GURL& url() const { return url_; }
159 // Creates the WebContentsView that shows the interstitial RVH.
160 // Overriden in unit tests.
161 virtual WebContentsView* CreateWebContentsView();
163 // Notification magic.
164 NotificationRegistrar notification_registrar_;
166 private:
167 class InterstitialPageRVHDelegateView;
168 class UnderlyingContentObserver : public WebContentsObserver {
169 public:
170 UnderlyingContentObserver(WebContents* web_contents,
171 InterstitialPageImpl* interstitial);
173 // WebContentsObserver implementation:
174 void WebContentsDestroyed() override;
175 void NavigationEntryCommitted(
176 const LoadCommittedDetails& load_details) override;
178 // This observer does not override OnMessageReceived or otherwise handle
179 // messages from the underlying content, because the interstitial should not
180 // care about them. Messages from the interstitial page (which has its own
181 // FrameTree) arrive through the RenderFrameHostDelegate interface, not
182 // WebContentsObserver.
184 private:
185 InterstitialPageImpl* const interstitial_;
187 DISALLOW_COPY_AND_ASSIGN(UnderlyingContentObserver);
190 // Disable the interstitial:
191 // - if it is not yet showing, then it won't be shown.
192 // - any command sent by the RenderViewHost will be ignored.
193 void Disable();
195 // Delete ourselves, causing Shutdown on the RVH to be called.
196 void Shutdown();
198 void OnNavigatingAwayOrTabClosing();
200 // Executes the passed action on the ResourceDispatcher (on the IO thread).
201 // Used to block/resume/cancel requests for the RenderViewHost hidden by this
202 // interstitial.
203 void TakeActionOnResourceDispatcher(ResourceRequestAction action);
205 // IPC message handlers.
206 void OnDomOperationResponse(const std::string& json_string,
207 int automation_id);
209 // Creates the RenderViewHost containing the interstitial content.
210 RenderViewHostImpl* CreateRenderViewHost();
212 // Watches the underlying WebContents for reasons to cancel the interstitial.
213 UnderlyingContentObserver underlying_content_observer_;
215 // The contents in which we are displayed. This is valid until Hide is
216 // called, at which point it will be set to NULL because the WebContents
217 // itself may be deleted.
218 WebContents* web_contents_;
220 // The NavigationController for the content this page is being displayed over.
221 NavigationControllerImpl* controller_;
223 // Delegate for dispatching keyboard events and accessing the native view.
224 RenderWidgetHostDelegate* render_widget_host_delegate_;
226 // The URL that is shown when the interstitial is showing.
227 GURL url_;
229 // Whether this interstitial is shown as a result of a new navigation (in
230 // which case a transient navigation entry is created).
231 bool new_navigation_;
233 // Whether we should discard the pending navigation entry when not proceeding.
234 // This is to deal with cases where |new_navigation_| is true but a new
235 // pending entry was created since this interstitial was shown and we should
236 // not discard it.
237 bool should_discard_pending_nav_entry_;
239 // If true and the user chooses not to proceed the target NavigationController
240 // is reloaded. This is used when two NavigationControllers are merged
241 // (CopyStateFromAndPrune).
242 // The default is false.
243 bool reload_on_dont_proceed_;
245 // Whether this interstitial is enabled. See Disable() for more info.
246 bool enabled_;
248 // Whether the Proceed or DontProceed methods have been called yet.
249 ActionState action_taken_;
251 // The RenderViewHost displaying the interstitial contents. This is valid
252 // until Hide is called, at which point it will be set to NULL, signifying
253 // that shutdown has started.
254 // TODO(creis): This is now owned by the FrameTree. We should route things
255 // through the tree's root RenderFrameHost instead.
256 RenderViewHostImpl* render_view_host_;
258 // The frame tree structure of the current page.
259 FrameTree frame_tree_;
261 // The IDs for the Render[View|Process]Host hidden by this interstitial.
262 int original_child_id_;
263 int original_rvh_id_;
265 // Whether or not we should change the title of the contents when hidden (to
266 // revert it to its original value).
267 bool should_revert_web_contents_title_;
269 // Whether or not the contents was loading resources when the interstitial was
270 // shown. We restore this state if the user proceeds from the interstitial.
271 bool web_contents_was_loading_;
273 // Whether the ResourceDispatcherHost has been notified to cancel/resume the
274 // resource requests blocked for the RenderViewHost.
275 bool resource_dispatcher_host_notified_;
277 // The original title of the contents that should be reverted to when the
278 // interstitial is hidden.
279 base::string16 original_web_contents_title_;
281 // Our RenderViewHostViewDelegate, necessary for accelerators to work.
282 scoped_ptr<InterstitialPageRVHDelegateView> rvh_delegate_view_;
284 // Settings passed to the renderer.
285 mutable RendererPreferences renderer_preferences_;
287 bool create_view_;
289 scoped_ptr<InterstitialPageDelegate> delegate_;
291 scoped_refptr<SessionStorageNamespace> session_storage_namespace_;
293 base::WeakPtrFactory<InterstitialPageImpl> weak_ptr_factory_;
295 DISALLOW_COPY_AND_ASSIGN(InterstitialPageImpl);
298 } // namespace content
300 #endif // CONTENT_BROWSER_FRAME_HOST_INTERSTITIAL_PAGE_IMPL_H_