| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ | 6 #define CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_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/common/notification_observer.h" |
| 13 #include "content/common/notification_registrar.h" | 14 #include "content/common/notification_registrar.h" |
| 15 #include "content/browser/site_instance.h" |
| 14 | 16 |
| 15 class WebUI; | 17 class WebUI; |
| 16 class InterstitialPage; | 18 class InterstitialPage; |
| 17 class NavigationController; | 19 class NavigationController; |
| 18 class NavigationEntry; | 20 class NavigationEntry; |
| 19 class Profile; | 21 class Profile; |
| 20 class RenderWidgetHostView; | 22 class RenderWidgetHostView; |
| 21 class RenderViewHost; | 23 class RenderViewHost; |
| 22 class SiteInstance; | |
| 23 | 24 |
| 24 // Manages RenderViewHosts for a TabContents. Normally there is only one and | 25 // Manages RenderViewHosts for a TabContents. Normally there is only one and |
| 25 // it is easy to do. But we can also have transitions of processes (and hence | 26 // it is easy to do. But we can also have transitions of processes (and hence |
| 26 // RenderViewHosts) that can get complex. | 27 // RenderViewHosts) that can get complex. |
| 27 class RenderViewHostManager | 28 class RenderViewHostManager |
| 28 : public RenderViewHostDelegate::RendererManagement { | 29 : public RenderViewHostDelegate::RendererManagement, |
| 30 public NotificationObserver { |
| 29 public: | 31 public: |
| 30 // Functions implemented by our owner that we need. | 32 // Functions implemented by our owner that we need. |
| 31 // | 33 // |
| 32 // TODO(brettw) Clean this up! These are all the functions in TabContents that | 34 // TODO(brettw) Clean this up! These are all the functions in TabContents that |
| 33 // are required to run this class. The design should probably be better such | 35 // are required to run this class. The design should probably be better such |
| 34 // that these are more clear. | 36 // that these are more clear. |
| 35 // | 37 // |
| 36 // There is additional complexity that some of the functions we need in | 38 // There is additional complexity that some of the functions we need in |
| 37 // TabContents are inherited and non-virtual. These are named with | 39 // TabContents are inherited and non-virtual. These are named with |
| 38 // "RenderManager" so that the duplicate implementation of them will be clear. | 40 // "RenderManager" so that the duplicate implementation of them will be clear. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 InterstitialPage* interstitial_page() const { | 166 InterstitialPage* interstitial_page() const { |
| 165 return interstitial_page_; | 167 return interstitial_page_; |
| 166 } | 168 } |
| 167 | 169 |
| 168 // RenderViewHostDelegate::RendererManagement implementation. | 170 // RenderViewHostDelegate::RendererManagement implementation. |
| 169 virtual void ShouldClosePage(bool for_cross_site_transition, bool proceed); | 171 virtual void ShouldClosePage(bool for_cross_site_transition, bool proceed); |
| 170 virtual void OnCrossSiteResponse(int new_render_process_host_id, | 172 virtual void OnCrossSiteResponse(int new_render_process_host_id, |
| 171 int new_request_id); | 173 int new_request_id); |
| 172 virtual void OnCrossSiteNavigationCanceled(); | 174 virtual void OnCrossSiteNavigationCanceled(); |
| 173 | 175 |
| 176 // NotificationObserver implementation. |
| 177 virtual void Observe(NotificationType type, |
| 178 const NotificationSource& source, |
| 179 const NotificationDetails& details); |
| 180 |
| 174 // Called when a RenderViewHost is about to be deleted. | 181 // Called when a RenderViewHost is about to be deleted. |
| 175 void RenderViewDeleted(RenderViewHost* rvh); | 182 void RenderViewDeleted(RenderViewHost* rvh); |
| 176 | 183 |
| 177 // Allows a caller to swap in a provided RenderViewHost to replace the | 184 // Allows a caller to swap in a provided RenderViewHost to replace the |
| 178 // current RenderViewHost. The current RVH will be shutdown and ultimately | 185 // current RenderViewHost. The current RVH will be shutdown and ultimately |
| 179 // deleted. | 186 // deleted. |
| 180 void SwapInRenderViewHost(RenderViewHost* rvh); | 187 void SwapInRenderViewHost(RenderViewHost* rvh); |
| 181 | 188 |
| 189 // Returns whether the given RenderViewHost is on the list of swapped out |
| 190 // RenderViewHosts. |
| 191 bool IsSwappedOut(RenderViewHost* rvh); |
| 192 |
| 182 private: | 193 private: |
| 183 friend class TestTabContents; | 194 friend class TestTabContents; |
| 184 friend class RenderViewHostManagerTest; | 195 friend class RenderViewHostManagerTest; |
| 185 | 196 |
| 186 // Returns whether this tab should transition to a new renderer for | 197 // Returns whether this tab should transition to a new renderer for |
| 187 // cross-site URLs. Enabled unless we see the --process-per-tab command line | 198 // cross-site URLs. Enabled unless we see the --process-per-tab command line |
| 188 // switch. Can be overridden in unit tests. | 199 // switch. Can be overridden in unit tests. |
| 189 bool ShouldTransitionCrossSite(); | 200 bool ShouldTransitionCrossSite(); |
| 190 | 201 |
| 191 // Returns true if the two navigation entries are incompatible in some way | 202 // Returns true if the two navigation entries are incompatible in some way |
| (...skipping 25 matching lines...) Expand all Loading... |
| 217 // Sets the pending RenderViewHost/WebUI to be the active one. Note that this | 228 // Sets the pending RenderViewHost/WebUI to be the active one. Note that this |
| 218 // doesn't require the pending render_view_host_ pointer to be non-NULL, since | 229 // doesn't require the pending render_view_host_ pointer to be non-NULL, since |
| 219 // there could be Web UI switching as well. Call this for every commit. | 230 // there could be Web UI switching as well. Call this for every commit. |
| 220 void CommitPending(); | 231 void CommitPending(); |
| 221 | 232 |
| 222 // Helper method to terminate the pending RenderViewHost. | 233 // Helper method to terminate the pending RenderViewHost. |
| 223 void CancelPending(); | 234 void CancelPending(); |
| 224 | 235 |
| 225 RenderViewHost* UpdateRendererStateForNavigate(const NavigationEntry& entry); | 236 RenderViewHost* UpdateRendererStateForNavigate(const NavigationEntry& entry); |
| 226 | 237 |
| 238 // Called when a renderer process is starting to close. We should not |
| 239 // schedule new navigations in its swapped out RenderViewHosts after this. |
| 240 void RendererProcessClosing(RenderProcessHost* render_process_host); |
| 241 |
| 227 // Our delegate, not owned by us. Guaranteed non-NULL. | 242 // Our delegate, not owned by us. Guaranteed non-NULL. |
| 228 Delegate* delegate_; | 243 Delegate* delegate_; |
| 229 | 244 |
| 230 // Whether a navigation requiring different RenderView's is pending. This is | 245 // Whether a navigation requiring different RenderView's is pending. This is |
| 231 // either cross-site request is (in the new process model), or when required | 246 // either cross-site request is (in the new process model), or when required |
| 232 // for the view type (like view source versus not). | 247 // for the view type (like view source versus not). |
| 233 bool cross_navigation_pending_; | 248 bool cross_navigation_pending_; |
| 234 | 249 |
| 235 // Implemented by the owner of this class, this delegate is installed into all | 250 // Implemented by the owner of this class, this delegate is installed into all |
| 236 // the RenderViewHosts that we create. | 251 // the RenderViewHosts that we create. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 247 // have an associated Web UI, in which case the Web UI pointer will be non- | 262 // have an associated Web UI, in which case the Web UI pointer will be non- |
| 248 // NULL. | 263 // NULL. |
| 249 // | 264 // |
| 250 // The pending_web_ui may be non-NULL even when the pending_render_view_host_ | 265 // The pending_web_ui may be non-NULL even when the pending_render_view_host_ |
| 251 // is. This will happen when we're transitioning between two Web UI pages: | 266 // is. This will happen when we're transitioning between two Web UI pages: |
| 252 // the RVH won't be swapped, so the pending pointer will be unused, but there | 267 // the RVH won't be swapped, so the pending pointer will be unused, but there |
| 253 // will be a pending Web UI associated with the navigation. | 268 // will be a pending Web UI associated with the navigation. |
| 254 RenderViewHost* pending_render_view_host_; | 269 RenderViewHost* pending_render_view_host_; |
| 255 scoped_ptr<WebUI> pending_web_ui_; | 270 scoped_ptr<WebUI> pending_web_ui_; |
| 256 | 271 |
| 272 // A map of site instance ID to swapped out RenderViewHosts. |
| 273 typedef base::hash_map<int32, RenderViewHost*> RenderViewHostMap; |
| 274 RenderViewHostMap swapped_out_hosts_; |
| 275 |
| 257 // The intersitial page currently shown if any, not own by this class | 276 // The intersitial page currently shown if any, not own by this class |
| 258 // (the InterstitialPage is self-owned, it deletes itself when hidden). | 277 // (the InterstitialPage is self-owned, it deletes itself when hidden). |
| 259 InterstitialPage* interstitial_page_; | 278 InterstitialPage* interstitial_page_; |
| 260 | 279 |
| 261 NotificationRegistrar registrar_; | 280 NotificationRegistrar registrar_; |
| 262 | 281 |
| 263 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); | 282 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); |
| 264 }; | 283 }; |
| 265 | 284 |
| 266 // The "details" for a NOTIFY_RENDER_VIEW_HOST_CHANGED notification. The old | 285 // The "details" for a NOTIFY_RENDER_VIEW_HOST_CHANGED notification. The old |
| 267 // host can be NULL when the first RenderViewHost is set. | 286 // host can be NULL when the first RenderViewHost is set. |
| 268 struct RenderViewHostSwitchedDetails { | 287 struct RenderViewHostSwitchedDetails { |
| 269 RenderViewHost* old_host; | 288 RenderViewHost* old_host; |
| 270 RenderViewHost* new_host; | 289 RenderViewHost* new_host; |
| 271 }; | 290 }; |
| 272 | 291 |
| 273 #endif // CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ | 292 #endif // CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ |
| OLD | NEW |