OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ |
6 #define CONTENT_BROWSER_WEB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ | 6 #define CONTENT_BROWSER_WEB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "content/browser/renderer_host/render_view_host_delegate.h" | 11 #include "content/browser/renderer_host/render_view_host_delegate.h" |
12 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 12 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
13 #include "content/public/browser/interstitial_page.h" | 13 #include "content/public/browser/interstitial_page.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
16 #include "content/public/common/renderer_preferences.h" | 16 #include "content/public/common/renderer_preferences.h" |
17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
18 | 18 |
19 class WebContentsImpl; | |
20 | |
21 namespace content { | 19 namespace content { |
22 class NavigationEntry; | 20 class NavigationEntry; |
23 class RenderViewHostImpl; | 21 class RenderViewHostImpl; |
24 class WebContentsView; | 22 class WebContentsView; |
25 } | 23 class WebContentsImpl; |
26 | 24 |
27 enum ResourceRequestAction { | 25 enum ResourceRequestAction { |
28 BLOCK, | 26 BLOCK, |
29 RESUME, | 27 RESUME, |
30 CANCEL | 28 CANCEL |
31 }; | 29 }; |
32 | 30 |
33 class CONTENT_EXPORT InterstitialPageImpl | 31 class CONTENT_EXPORT InterstitialPageImpl |
34 : public NON_EXPORTED_BASE(content::InterstitialPage), | 32 : public NON_EXPORTED_BASE(InterstitialPage), |
35 public content::NotificationObserver, | 33 public NotificationObserver, |
36 public content::RenderViewHostDelegate, | 34 public RenderViewHostDelegate, |
37 public content::RenderWidgetHostDelegate { | 35 public RenderWidgetHostDelegate { |
38 public: | 36 public: |
39 // The different state of actions the user can take in an interstitial. | 37 // The different state of actions the user can take in an interstitial. |
40 enum ActionState { | 38 enum ActionState { |
41 NO_ACTION, // No action has been taken yet. | 39 NO_ACTION, // No action has been taken yet. |
42 PROCEED_ACTION, // "Proceed" was selected. | 40 PROCEED_ACTION, // "Proceed" was selected. |
43 DONT_PROCEED_ACTION // "Don't proceed" was selected. | 41 DONT_PROCEED_ACTION // "Don't proceed" was selected. |
44 }; | 42 }; |
45 | 43 |
46 InterstitialPageImpl(content::WebContents* web_contents, | 44 InterstitialPageImpl(WebContents* web_contents, |
47 bool new_navigation, | 45 bool new_navigation, |
48 const GURL& url, | 46 const GURL& url, |
49 content::InterstitialPageDelegate* delegate); | 47 InterstitialPageDelegate* delegate); |
50 virtual ~InterstitialPageImpl(); | 48 virtual ~InterstitialPageImpl(); |
51 | 49 |
52 // InterstitialPage implementation: | 50 // InterstitialPage implementation: |
53 virtual void Show() OVERRIDE; | 51 virtual void Show() OVERRIDE; |
54 virtual void Hide() OVERRIDE; | 52 virtual void Hide() OVERRIDE; |
55 virtual void DontProceed() OVERRIDE; | 53 virtual void DontProceed() OVERRIDE; |
56 virtual void Proceed() OVERRIDE; | 54 virtual void Proceed() OVERRIDE; |
57 virtual content::RenderViewHost* GetRenderViewHostForTesting() const OVERRIDE; | 55 virtual RenderViewHost* GetRenderViewHostForTesting() const OVERRIDE; |
58 virtual content::InterstitialPageDelegate* GetDelegateForTesting() OVERRIDE; | 56 virtual InterstitialPageDelegate* GetDelegateForTesting() OVERRIDE; |
59 virtual void DontCreateViewForTesting() OVERRIDE; | 57 virtual void DontCreateViewForTesting() OVERRIDE; |
60 virtual void SetSize(const gfx::Size& size) OVERRIDE; | 58 virtual void SetSize(const gfx::Size& size) OVERRIDE; |
61 virtual void Focus() OVERRIDE; | 59 virtual void Focus() OVERRIDE; |
62 | 60 |
63 // Allows the user to navigate away by disabling the interstitial, canceling | 61 // Allows the user to navigate away by disabling the interstitial, canceling |
64 // the pending request, and unblocking the hidden renderer. The interstitial | 62 // the pending request, and unblocking the hidden renderer. The interstitial |
65 // will stay visible until the navigation completes. | 63 // will stay visible until the navigation completes. |
66 void CancelForNavigation(); | 64 void CancelForNavigation(); |
67 | 65 |
68 // Focus the first (last if reverse is true) element in the interstitial page. | 66 // Focus the first (last if reverse is true) element in the interstitial page. |
69 // Called when tab traversing. | 67 // Called when tab traversing. |
70 void FocusThroughTabTraversal(bool reverse); | 68 void FocusThroughTabTraversal(bool reverse); |
71 | 69 |
72 // See description above field. | 70 // See description above field. |
73 void set_reload_on_dont_proceed(bool value) { | 71 void set_reload_on_dont_proceed(bool value) { |
74 reload_on_dont_proceed_ = value; | 72 reload_on_dont_proceed_ = value; |
75 } | 73 } |
76 bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; } | 74 bool reload_on_dont_proceed() const { return reload_on_dont_proceed_; } |
77 | 75 |
78 protected: | 76 protected: |
79 // content::NotificationObserver method: | 77 // NotificationObserver method: |
80 virtual void Observe(int type, | 78 virtual void Observe(int type, |
81 const content::NotificationSource& source, | 79 const NotificationSource& source, |
82 const content::NotificationDetails& details) OVERRIDE; | 80 const NotificationDetails& details) OVERRIDE; |
83 | 81 |
84 // RenderViewHostDelegate implementation: | 82 // RenderViewHostDelegate implementation: |
85 virtual content::RenderViewHostDelegateView* GetDelegateView() OVERRIDE; | 83 virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE; |
86 virtual const GURL& GetURL() const OVERRIDE; | 84 virtual const GURL& GetURL() const OVERRIDE; |
87 virtual void RenderViewGone(content::RenderViewHost* render_view_host, | 85 virtual void RenderViewGone(RenderViewHost* render_view_host, |
88 base::TerminationStatus status, | 86 base::TerminationStatus status, |
89 int error_code) OVERRIDE; | 87 int error_code) OVERRIDE; |
90 virtual void DidNavigate( | 88 virtual void DidNavigate( |
91 content::RenderViewHost* render_view_host, | 89 RenderViewHost* render_view_host, |
92 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; | 90 const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; |
93 virtual void UpdateTitle(content::RenderViewHost* render_view_host, | 91 virtual void UpdateTitle(RenderViewHost* render_view_host, |
94 int32 page_id, | 92 int32 page_id, |
95 const string16& title, | 93 const string16& title, |
96 base::i18n::TextDirection title_direction) OVERRIDE; | 94 base::i18n::TextDirection title_direction) OVERRIDE; |
97 virtual content::RendererPreferences GetRendererPrefs( | 95 virtual RendererPreferences GetRendererPrefs( |
98 content::BrowserContext* browser_context) const OVERRIDE; | 96 BrowserContext* browser_context) const OVERRIDE; |
99 virtual webkit_glue::WebPreferences GetWebkitPrefs() OVERRIDE; | 97 virtual webkit_glue::WebPreferences GetWebkitPrefs() OVERRIDE; |
100 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; | 98 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE; |
101 virtual void CreateNewWindow( | 99 virtual void CreateNewWindow( |
102 int route_id, | 100 int route_id, |
103 const ViewHostMsg_CreateWindow_Params& params, | 101 const ViewHostMsg_CreateWindow_Params& params, |
104 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE; | 102 SessionStorageNamespace* session_storage_namespace) OVERRIDE; |
105 virtual void CreateNewWidget(int route_id, | 103 virtual void CreateNewWidget(int route_id, |
106 WebKit::WebPopupType popup_type) OVERRIDE; | 104 WebKit::WebPopupType popup_type) OVERRIDE; |
107 virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE; | 105 virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE; |
108 virtual void ShowCreatedWindow(int route_id, | 106 virtual void ShowCreatedWindow(int route_id, |
109 WindowOpenDisposition disposition, | 107 WindowOpenDisposition disposition, |
110 const gfx::Rect& initial_pos, | 108 const gfx::Rect& initial_pos, |
111 bool user_gesture) OVERRIDE; | 109 bool user_gesture) OVERRIDE; |
112 virtual void ShowCreatedWidget(int route_id, | 110 virtual void ShowCreatedWidget(int route_id, |
113 const gfx::Rect& initial_pos) OVERRIDE; | 111 const gfx::Rect& initial_pos) OVERRIDE; |
114 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE; | 112 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE; |
115 virtual void ShowContextMenu( | 113 virtual void ShowContextMenu( |
116 const content::ContextMenuParams& params, | 114 const ContextMenuParams& params, |
117 content::ContextMenuSourceType type) OVERRIDE; | 115 ContextMenuSourceType type) OVERRIDE; |
118 | 116 |
119 // RenderWidgetHostDelegate implementation: | 117 // RenderWidgetHostDelegate implementation: |
120 virtual bool PreHandleKeyboardEvent( | 118 virtual bool PreHandleKeyboardEvent( |
121 const content::NativeWebKeyboardEvent& event, | 119 const NativeWebKeyboardEvent& event, |
122 bool* is_keyboard_shortcut) OVERRIDE; | 120 bool* is_keyboard_shortcut) OVERRIDE; |
123 virtual void HandleKeyboardEvent( | 121 virtual void HandleKeyboardEvent( |
124 const content::NativeWebKeyboardEvent& event) OVERRIDE; | 122 const NativeWebKeyboardEvent& event) OVERRIDE; |
125 | 123 |
126 bool enabled() const { return enabled_; } | 124 bool enabled() const { return enabled_; } |
127 content::WebContents* web_contents() const; | 125 WebContents* web_contents() const; |
128 const GURL& url() const { return url_; } | 126 const GURL& url() const { return url_; } |
129 | 127 |
130 // Creates the RenderViewHost containing the interstitial content. | 128 // Creates the RenderViewHost containing the interstitial content. |
131 // Overriden in unit tests. | 129 // Overriden in unit tests. |
132 virtual content::RenderViewHost* CreateRenderViewHost(); | 130 virtual RenderViewHost* CreateRenderViewHost(); |
133 | 131 |
134 // Creates the WebContentsView that shows the interstitial RVH. | 132 // Creates the WebContentsView that shows the interstitial RVH. |
135 // Overriden in unit tests. | 133 // Overriden in unit tests. |
136 virtual content::WebContentsView* CreateWebContentsView(); | 134 virtual WebContentsView* CreateWebContentsView(); |
137 | 135 |
138 // Notification magic. | 136 // Notification magic. |
139 content::NotificationRegistrar notification_registrar_; | 137 NotificationRegistrar notification_registrar_; |
140 | 138 |
141 private: | 139 private: |
142 class InterstitialPageRVHDelegateView; | 140 class InterstitialPageRVHDelegateView; |
143 | 141 |
144 // Disable the interstitial: | 142 // Disable the interstitial: |
145 // - if it is not yet showing, then it won't be shown. | 143 // - if it is not yet showing, then it won't be shown. |
146 // - any command sent by the RenderViewHost will be ignored. | 144 // - any command sent by the RenderViewHost will be ignored. |
147 void Disable(); | 145 void Disable(); |
148 | 146 |
149 // Executes the passed action on the ResourceDispatcher (on the IO thread). | 147 // Executes the passed action on the ResourceDispatcher (on the IO thread). |
(...skipping 23 matching lines...) Expand all Loading... |
173 // The default is false. | 171 // The default is false. |
174 bool reload_on_dont_proceed_; | 172 bool reload_on_dont_proceed_; |
175 | 173 |
176 // Whether this interstitial is enabled. See Disable() for more info. | 174 // Whether this interstitial is enabled. See Disable() for more info. |
177 bool enabled_; | 175 bool enabled_; |
178 | 176 |
179 // Whether the Proceed or DontProceed methods have been called yet. | 177 // Whether the Proceed or DontProceed methods have been called yet. |
180 ActionState action_taken_; | 178 ActionState action_taken_; |
181 | 179 |
182 // The RenderViewHost displaying the interstitial contents. | 180 // The RenderViewHost displaying the interstitial contents. |
183 content::RenderViewHostImpl* render_view_host_; | 181 RenderViewHostImpl* render_view_host_; |
184 | 182 |
185 // The IDs for the Render[View|Process]Host hidden by this interstitial. | 183 // The IDs for the Render[View|Process]Host hidden by this interstitial. |
186 int original_child_id_; | 184 int original_child_id_; |
187 int original_rvh_id_; | 185 int original_rvh_id_; |
188 | 186 |
189 // Whether or not we should change the title of the contents when hidden (to | 187 // Whether or not we should change the title of the contents when hidden (to |
190 // revert it to its original value). | 188 // revert it to its original value). |
191 bool should_revert_web_contents_title_; | 189 bool should_revert_web_contents_title_; |
192 | 190 |
193 // Whether or not the contents was loading resources when the interstitial was | 191 // Whether or not the contents was loading resources when the interstitial was |
194 // shown. We restore this state if the user proceeds from the interstitial. | 192 // shown. We restore this state if the user proceeds from the interstitial. |
195 bool web_contents_was_loading_; | 193 bool web_contents_was_loading_; |
196 | 194 |
197 // Whether the ResourceDispatcherHost has been notified to cancel/resume the | 195 // Whether the ResourceDispatcherHost has been notified to cancel/resume the |
198 // resource requests blocked for the RenderViewHost. | 196 // resource requests blocked for the RenderViewHost. |
199 bool resource_dispatcher_host_notified_; | 197 bool resource_dispatcher_host_notified_; |
200 | 198 |
201 // The original title of the contents that should be reverted to when the | 199 // The original title of the contents that should be reverted to when the |
202 // interstitial is hidden. | 200 // interstitial is hidden. |
203 string16 original_web_contents_title_; | 201 string16 original_web_contents_title_; |
204 | 202 |
205 // Our RenderViewHostViewDelegate, necessary for accelerators to work. | 203 // Our RenderViewHostViewDelegate, necessary for accelerators to work. |
206 scoped_ptr<InterstitialPageRVHDelegateView> rvh_delegate_view_; | 204 scoped_ptr<InterstitialPageRVHDelegateView> rvh_delegate_view_; |
207 | 205 |
208 // Settings passed to the renderer. | 206 // Settings passed to the renderer. |
209 mutable content::RendererPreferences renderer_preferences_; | 207 mutable RendererPreferences renderer_preferences_; |
210 | 208 |
211 bool create_view_; | 209 bool create_view_; |
212 | 210 |
213 scoped_ptr<content::InterstitialPageDelegate> delegate_; | 211 scoped_ptr<InterstitialPageDelegate> delegate_; |
214 | 212 |
215 DISALLOW_COPY_AND_ASSIGN(InterstitialPageImpl); | 213 DISALLOW_COPY_AND_ASSIGN(InterstitialPageImpl); |
216 }; | 214 }; |
217 | 215 |
| 216 } // namespace content |
| 217 |
218 #endif // CONTENT_BROWSER_WEB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ | 218 #endif // CONTENT_BROWSER_WEB_CONTENTS_INTERSTITIAL_PAGE_IMPL_H_ |
OLD | NEW |