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_RENDER_VIEW_HOST_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ |
6 #define CONTENT_BROWSER_WEB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ | 6 #define CONTENT_BROWSER_WEB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "content/browser/renderer_host/render_view_host_delegate.h" | 12 #include "content/browser/renderer_host/render_view_host_delegate.h" |
13 #include "content/browser/site_instance_impl.h" | 13 #include "content/browser/site_instance_impl.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
17 | 17 |
18 class InterstitialPageImpl; | |
19 class NavigationControllerImpl; | |
20 class WebUIImpl; | 18 class WebUIImpl; |
21 | 19 |
22 namespace content { | 20 namespace content { |
23 class BrowserContext; | 21 class BrowserContext; |
| 22 class InterstitialPageImpl; |
| 23 class NavigationControllerImpl; |
24 class NavigationEntry; | 24 class NavigationEntry; |
25 class NavigationEntryImpl; | 25 class NavigationEntryImpl; |
26 class RenderViewHost; | 26 class RenderViewHost; |
27 class RenderViewHostImpl; | 27 class RenderViewHostImpl; |
| 28 class RenderViewHostManagerTest; |
28 class RenderWidgetHostDelegate; | 29 class RenderWidgetHostDelegate; |
29 class RenderWidgetHostView; | 30 class RenderWidgetHostView; |
30 class TestWebContents; | 31 class TestWebContents; |
31 } | 32 } |
32 | 33 |
33 // Manages RenderViewHosts for a WebContentsImpl. Normally there is only one and | 34 // Manages RenderViewHosts for a WebContentsImpl. Normally there is only one and |
34 // it is easy to do. But we can also have transitions of processes (and hence | 35 // it is easy to do. But we can also have transitions of processes (and hence |
35 // RenderViewHosts) that can get complex. | 36 // RenderViewHosts) that can get complex. |
36 class CONTENT_EXPORT RenderViewHostManager | 37 class CONTENT_EXPORT RenderViewHostManager |
37 : public content::RenderViewHostDelegate::RendererManagement, | 38 : public content::RenderViewHostDelegate::RendererManagement, |
(...skipping 20 matching lines...) Expand all Loading... |
58 // InitWithExistingID. | 59 // InitWithExistingID. |
59 virtual bool CreateRenderViewForRenderManager( | 60 virtual bool CreateRenderViewForRenderManager( |
60 content::RenderViewHost* render_view_host, int opener_route_id) = 0; | 61 content::RenderViewHost* render_view_host, int opener_route_id) = 0; |
61 virtual void BeforeUnloadFiredFromRenderManager( | 62 virtual void BeforeUnloadFiredFromRenderManager( |
62 bool proceed, const base::TimeTicks& proceed_time, | 63 bool proceed, const base::TimeTicks& proceed_time, |
63 bool* proceed_to_fire_unload) = 0; | 64 bool* proceed_to_fire_unload) = 0; |
64 virtual void RenderViewGoneFromRenderManager( | 65 virtual void RenderViewGoneFromRenderManager( |
65 content::RenderViewHost* render_view_host) = 0; | 66 content::RenderViewHost* render_view_host) = 0; |
66 virtual void UpdateRenderViewSizeForRenderManager() = 0; | 67 virtual void UpdateRenderViewSizeForRenderManager() = 0; |
67 virtual void NotifySwappedFromRenderManager() = 0; | 68 virtual void NotifySwappedFromRenderManager() = 0; |
68 virtual NavigationControllerImpl& GetControllerForRenderManager() = 0; | 69 virtual content::NavigationControllerImpl& |
| 70 GetControllerForRenderManager() = 0; |
69 | 71 |
70 // Create swapped out RenderViews in the given SiteInstance for each tab in | 72 // Create swapped out RenderViews in the given SiteInstance for each tab in |
71 // the opener chain of this tab, if any. This allows the current tab to | 73 // the opener chain of this tab, if any. This allows the current tab to |
72 // make cross-process script calls to its opener(s). Returns the route ID | 74 // make cross-process script calls to its opener(s). Returns the route ID |
73 // of the immediate opener, if one exists (otherwise MSG_ROUTING_NONE). | 75 // of the immediate opener, if one exists (otherwise MSG_ROUTING_NONE). |
74 virtual int CreateOpenerRenderViewsForRenderManager( | 76 virtual int CreateOpenerRenderViewsForRenderManager( |
75 content::SiteInstance* instance) = 0; | 77 content::SiteInstance* instance) = 0; |
76 | 78 |
77 // Creates a WebUI object for the given URL if one applies. Ownership of the | 79 // Creates a WebUI object for the given URL if one applies. Ownership of the |
78 // returned pointer will be passed to the caller. If no WebUI applies, | 80 // returned pointer will be passed to the caller. If no WebUI applies, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 void SetWebUIPostCommit(WebUIImpl* web_ui); | 181 void SetWebUIPostCommit(WebUIImpl* web_ui); |
180 | 182 |
181 // Called when a provisional load on the given renderer is aborted. | 183 // Called when a provisional load on the given renderer is aborted. |
182 void RendererAbortedProvisionalLoad( | 184 void RendererAbortedProvisionalLoad( |
183 content::RenderViewHost* render_view_host); | 185 content::RenderViewHost* render_view_host); |
184 | 186 |
185 // Sets the passed passed interstitial as the currently showing interstitial. | 187 // Sets the passed passed interstitial as the currently showing interstitial. |
186 // |interstitial_page| should be non NULL (use the remove_interstitial_page | 188 // |interstitial_page| should be non NULL (use the remove_interstitial_page |
187 // method to unset the interstitial) and no interstitial page should be set | 189 // method to unset the interstitial) and no interstitial page should be set |
188 // when there is already a non NULL interstitial page set. | 190 // when there is already a non NULL interstitial page set. |
189 void set_interstitial_page(InterstitialPageImpl* interstitial_page) { | 191 void set_interstitial_page(content::InterstitialPageImpl* interstitial_page) { |
190 DCHECK(!interstitial_page_ && interstitial_page); | 192 DCHECK(!interstitial_page_ && interstitial_page); |
191 interstitial_page_ = interstitial_page; | 193 interstitial_page_ = interstitial_page; |
192 } | 194 } |
193 | 195 |
194 // Unsets the currently showing interstitial. | 196 // Unsets the currently showing interstitial. |
195 void remove_interstitial_page() { | 197 void remove_interstitial_page() { |
196 DCHECK(interstitial_page_); | 198 DCHECK(interstitial_page_); |
197 interstitial_page_ = NULL; | 199 interstitial_page_ = NULL; |
198 } | 200 } |
199 | 201 |
200 // Returns the currently showing interstitial, NULL if no interstitial is | 202 // Returns the currently showing interstitial, NULL if no interstitial is |
201 // showing. | 203 // showing. |
202 InterstitialPageImpl* interstitial_page() const { | 204 content::InterstitialPageImpl* interstitial_page() const { |
203 return interstitial_page_; | 205 return interstitial_page_; |
204 } | 206 } |
205 | 207 |
206 // RenderViewHostDelegate::RendererManagement implementation. | 208 // RenderViewHostDelegate::RendererManagement implementation. |
207 virtual void ShouldClosePage( | 209 virtual void ShouldClosePage( |
208 bool for_cross_site_transition, | 210 bool for_cross_site_transition, |
209 bool proceed, | 211 bool proceed, |
210 const base::TimeTicks& proceed_time) OVERRIDE; | 212 const base::TimeTicks& proceed_time) OVERRIDE; |
211 virtual void OnCrossSiteResponse(int new_render_process_host_id, | 213 virtual void OnCrossSiteResponse(int new_render_process_host_id, |
212 int new_request_id) OVERRIDE; | 214 int new_request_id) OVERRIDE; |
213 | 215 |
214 // content::NotificationObserver implementation. | 216 // content::NotificationObserver implementation. |
215 virtual void Observe(int type, | 217 virtual void Observe(int type, |
216 const content::NotificationSource& source, | 218 const content::NotificationSource& source, |
217 const content::NotificationDetails& details) OVERRIDE; | 219 const content::NotificationDetails& details) OVERRIDE; |
218 | 220 |
219 // Called when a RenderViewHost is about to be deleted. | 221 // Called when a RenderViewHost is about to be deleted. |
220 void RenderViewDeleted(content::RenderViewHost* rvh); | 222 void RenderViewDeleted(content::RenderViewHost* rvh); |
221 | 223 |
222 // Returns whether the given RenderViewHost is on the list of swapped out | 224 // Returns whether the given RenderViewHost is on the list of swapped out |
223 // RenderViewHosts. | 225 // RenderViewHosts. |
224 bool IsSwappedOut(content::RenderViewHost* rvh); | 226 bool IsSwappedOut(content::RenderViewHost* rvh); |
225 | 227 |
226 // Returns the swapped out RenderViewHost for the given SiteInstance, if any. | 228 // Returns the swapped out RenderViewHost for the given SiteInstance, if any. |
227 content::RenderViewHostImpl* GetSwappedOutRenderViewHost( | 229 content::RenderViewHostImpl* GetSwappedOutRenderViewHost( |
228 content::SiteInstance* instance); | 230 content::SiteInstance* instance); |
229 | 231 |
230 private: | 232 private: |
| 233 friend class content::RenderViewHostManagerTest; |
231 friend class content::TestWebContents; | 234 friend class content::TestWebContents; |
232 friend class RenderViewHostManagerTest; | |
233 | 235 |
234 // Returns whether this tab should transition to a new renderer for | 236 // Returns whether this tab should transition to a new renderer for |
235 // cross-site URLs. Enabled unless we see the --process-per-tab command line | 237 // cross-site URLs. Enabled unless we see the --process-per-tab command line |
236 // switch. Can be overridden in unit tests. | 238 // switch. Can be overridden in unit tests. |
237 bool ShouldTransitionCrossSite(); | 239 bool ShouldTransitionCrossSite(); |
238 | 240 |
239 // Returns true if the two navigation entries are incompatible in some way | 241 // Returns true if the two navigation entries are incompatible in some way |
240 // other than site instances. Cases where this can happen include Web UI | 242 // other than site instances. Cases where this can happen include Web UI |
241 // to regular web pages. It will cause us to swap RenderViewHosts (and hence | 243 // to regular web pages. It will cause us to swap RenderViewHosts (and hence |
242 // RenderProcessHosts) even if the site instance would otherwise be the same. | 244 // RenderProcessHosts) even if the site instance would otherwise be the same. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // other should be NULL. | 315 // other should be NULL. |
314 scoped_ptr<WebUIImpl> pending_web_ui_; | 316 scoped_ptr<WebUIImpl> pending_web_ui_; |
315 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; | 317 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_; |
316 | 318 |
317 // A map of site instance ID to swapped out RenderViewHosts. | 319 // A map of site instance ID to swapped out RenderViewHosts. |
318 typedef base::hash_map<int32, content::RenderViewHostImpl*> RenderViewHostMap; | 320 typedef base::hash_map<int32, content::RenderViewHostImpl*> RenderViewHostMap; |
319 RenderViewHostMap swapped_out_hosts_; | 321 RenderViewHostMap swapped_out_hosts_; |
320 | 322 |
321 // The intersitial page currently shown if any, not own by this class | 323 // The intersitial page currently shown if any, not own by this class |
322 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 324 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
323 InterstitialPageImpl* interstitial_page_; | 325 content::InterstitialPageImpl* interstitial_page_; |
324 | 326 |
325 content::NotificationRegistrar registrar_; | 327 content::NotificationRegistrar registrar_; |
326 | 328 |
327 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); | 329 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); |
328 }; | 330 }; |
329 | 331 |
330 #endif // CONTENT_BROWSER_WEB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ | 332 #endif // CONTENT_BROWSER_WEB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ |
OLD | NEW |