| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_MANAGER_H_ | |
| 6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_MANAGER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/scoped_ptr.h" | |
| 10 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 11 #include "chrome/common/notification_registrar.h" | |
| 12 #include "chrome/common/notification_observer.h" | |
| 13 | |
| 14 class DOMUI; | |
| 15 class InterstitialPage; | |
| 16 class NavigationController; | |
| 17 class NavigationEntry; | |
| 18 class Profile; | |
| 19 class RenderViewHostDelegate; | |
| 20 class RenderWidgetHostView; | |
| 21 class SiteInstance; | |
| 22 | |
| 23 // Manages RenderViewHosts for a TabContents. Normally there is only one and | |
| 24 // it is easy to do. But we can also have transitions of processes (and hence | |
| 25 // RenderViewHosts) that can get complex. | |
| 26 class RenderViewHostManager : public NotificationObserver { | |
| 27 public: | |
| 28 // Functions implemented by our owner that we need. | |
| 29 // | |
| 30 // TODO(brettw) Clean this up! These are all the functions in TabContents that | |
| 31 // are required to run this class. The design should probably be better such | |
| 32 // that these are more clear. | |
| 33 // | |
| 34 // There is additional complexity that some of the functions we need in | |
| 35 // TabContents are inherited and non-virtual. These are named with | |
| 36 // "RenderManager" so that the duplicate implementation of them will be clear. | |
| 37 class Delegate { | |
| 38 public: | |
| 39 // See tab_contents.h's implementation for more. | |
| 40 virtual bool CreateRenderViewForRenderManager( | |
| 41 RenderViewHost* render_view_host) = 0; | |
| 42 virtual void BeforeUnloadFiredFromRenderManager( | |
| 43 bool proceed, bool* proceed_to_fire_unload) = 0; | |
| 44 virtual void DidStartLoadingFromRenderManager( | |
| 45 RenderViewHost* render_view_host) = 0; | |
| 46 virtual void RenderViewGoneFromRenderManager( | |
| 47 RenderViewHost* render_view_host) = 0; | |
| 48 virtual void UpdateRenderViewSizeForRenderManager() = 0; | |
| 49 virtual void NotifySwappedFromRenderManager() = 0; | |
| 50 virtual NavigationController& GetControllerForRenderManager() = 0; | |
| 51 | |
| 52 // Creates a DOMUI object for the given URL if one applies. Ownership of the | |
| 53 // returned pointer will be passed to the caller. If no DOMUI applies, | |
| 54 // returns NULL. | |
| 55 virtual DOMUI* CreateDOMUIForRenderManager(const GURL& url) = 0; | |
| 56 | |
| 57 // Returns the navigation entry of the current navigation, or NULL if there | |
| 58 // is none. | |
| 59 virtual NavigationEntry* | |
| 60 GetLastCommittedNavigationEntryForRenderManager() = 0; | |
| 61 }; | |
| 62 | |
| 63 // Both delegate pointers must be non-NULL and are not owned by this class. | |
| 64 // They must outlive this class. The RenderViewHostDelegate is what will be | |
| 65 // installed into all RenderViewHosts that are created. | |
| 66 // | |
| 67 // You must call Init() before using this class. | |
| 68 RenderViewHostManager(RenderViewHostDelegate* render_view_delegate, | |
| 69 Delegate* delegate); | |
| 70 ~RenderViewHostManager(); | |
| 71 | |
| 72 // For arguments, see TabContents constructor. | |
| 73 void Init(Profile* profile, | |
| 74 SiteInstance* site_instance, | |
| 75 int routing_id, | |
| 76 base::WaitableEvent* modal_dialog_event); | |
| 77 | |
| 78 // Returns the currently actuive RenderViewHost. | |
| 79 // | |
| 80 // This will be non-NULL between Init() and Shutdown(). You may want to NULL | |
| 81 // check it in many cases, however. Windows can send us messages during the | |
| 82 // destruction process after it has been shut down. | |
| 83 RenderViewHost* current_host() const { | |
| 84 return render_view_host_; | |
| 85 } | |
| 86 | |
| 87 // Returns the view associated with the current RenderViewHost, or NULL if | |
| 88 // there is no current one. | |
| 89 RenderWidgetHostView* current_view() const { | |
| 90 if (!render_view_host_) | |
| 91 return NULL; | |
| 92 return render_view_host_->view(); | |
| 93 } | |
| 94 | |
| 95 // Returns the pending render view host, or NULL if there is no pending one. | |
| 96 RenderViewHost* pending_render_view_host() const { | |
| 97 return pending_render_view_host_; | |
| 98 } | |
| 99 | |
| 100 // Returns the current committed DOM UI or NULL if none applies. | |
| 101 DOMUI* dom_ui() const { return dom_ui_.get(); } | |
| 102 | |
| 103 // Returns the DOM UI for the pending navigation, or NULL of none applies. | |
| 104 DOMUI* pending_dom_ui() const { return pending_dom_ui_.get(); } | |
| 105 | |
| 106 // Called when we want to instruct the renderer to navigate to the given | |
| 107 // navigation entry. It may create a new RenderViewHost or re-use an existing | |
| 108 // one. The RenderViewHost to navigate will be returned. Returns NULL if one | |
| 109 // could not be created. | |
| 110 RenderViewHost* Navigate(const NavigationEntry& entry); | |
| 111 | |
| 112 // Instructs the various live views to stop. Called when the user directed the | |
| 113 // page to stop loading. | |
| 114 void Stop(); | |
| 115 | |
| 116 // Notifies the regular and pending RenderViewHosts that a load is or is not | |
| 117 // happening. Even though the message is only for one of them, we don't know | |
| 118 // which one so we tell both. | |
| 119 void SetIsLoading(bool is_loading); | |
| 120 | |
| 121 // Whether to close the tab or not when there is a hang during an unload | |
| 122 // handler. If we are mid-crosssite navigation, then we should proceed | |
| 123 // with the navigation instead of closing the tab. | |
| 124 bool ShouldCloseTabOnUnresponsiveRenderer(); | |
| 125 | |
| 126 // Called when a renderer's main frame navigates. | |
| 127 void DidNavigateMainFrame(RenderViewHost* render_view_host); | |
| 128 | |
| 129 // Allows the TabContents to react when a cross-site response is ready to be | |
| 130 // delivered to a pending RenderViewHost. We must first run the onunload | |
| 131 // handler of the old RenderViewHost before we can allow it to proceed. | |
| 132 void OnCrossSiteResponse(int new_render_process_host_id, | |
| 133 int new_request_id); | |
| 134 | |
| 135 // Notifies that the navigation that initiated a cross-site transition has | |
| 136 // been canceled. | |
| 137 void CrossSiteNavigationCanceled(); | |
| 138 | |
| 139 // Called when a provisional load on the given renderer is aborted. | |
| 140 void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host); | |
| 141 | |
| 142 // Actually implements this RenderViewHostDelegate function for the | |
| 143 // TabContents. | |
| 144 void ShouldClosePage(bool proceed); | |
| 145 | |
| 146 // Forwards the message to the RenderViewHost, which is the original one. | |
| 147 void OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg, | |
| 148 bool success, | |
| 149 const std::wstring& prompt); | |
| 150 | |
| 151 // Forwards this message to the RenderViewHost. | |
| 152 void OnJavaScriptMessageBoxWindowDestroyed(); | |
| 153 | |
| 154 // Sets the passed passed interstitial as the currently showing interstitial. | |
| 155 // |interstitial_page| should be non NULL (use the remove_interstitial_page | |
| 156 // method to unset the interstitial) and no interstitial page should be set | |
| 157 // when there is already a non NULL interstitial page set. | |
| 158 void set_interstitial_page(InterstitialPage* interstitial_page) { | |
| 159 DCHECK(!interstitial_page_ && interstitial_page); | |
| 160 interstitial_page_ = interstitial_page; | |
| 161 } | |
| 162 | |
| 163 // Unsets the currently showing interstitial. | |
| 164 void remove_interstitial_page() { | |
| 165 DCHECK(interstitial_page_); | |
| 166 interstitial_page_ = NULL; | |
| 167 } | |
| 168 | |
| 169 // Returns the currently showing interstitial, NULL if no interstitial is | |
| 170 // showing. | |
| 171 InterstitialPage* interstitial_page() const { | |
| 172 return interstitial_page_; | |
| 173 } | |
| 174 | |
| 175 virtual void Observe(NotificationType type, | |
| 176 const NotificationSource& source, | |
| 177 const NotificationDetails& details); | |
| 178 | |
| 179 private: | |
| 180 friend class TestTabContents; | |
| 181 | |
| 182 // Returns whether this tab should transition to a new renderer for | |
| 183 // cross-site URLs. Enabled unless we see the --process-per-tab command line | |
| 184 // switch. Can be overridden in unit tests. | |
| 185 bool ShouldTransitionCrossSite(); | |
| 186 | |
| 187 // Returns true if the two navigation entries are incompatible in some way | |
| 188 // other than site instances. Cases where this can happen include DOM UI | |
| 189 // to regular web pages. It will cause us to swap RenderViewHosts (and hence | |
| 190 // RenderProcessHosts) even if the site instance would otherwise be the same. | |
| 191 // As part of this, we'll also force new SiteInstances and BrowsingInstances. | |
| 192 // Either of the entries may be NULL. | |
| 193 bool ShouldSwapProcessesForNavigation( | |
| 194 const NavigationEntry* cur_entry, | |
| 195 const NavigationEntry* new_entry) const; | |
| 196 | |
| 197 // Returns an appropriate SiteInstance object for the given NavigationEntry, | |
| 198 // possibly reusing the current SiteInstance. | |
| 199 // Never called if --process-per-tab is used. | |
| 200 SiteInstance* GetSiteInstanceForEntry(const NavigationEntry& entry, | |
| 201 SiteInstance* curr_instance); | |
| 202 | |
| 203 // Helper method to create a pending RenderViewHost for a cross-site | |
| 204 // navigation. | |
| 205 bool CreatePendingRenderView(SiteInstance* instance); | |
| 206 | |
| 207 // Sets the pending RenderViewHost/DOMUI to be the active one. Note that this | |
| 208 // doesn't require the pending render_view_host_ pointer to be non-NULL, since | |
| 209 // there could be DOM UI switching as well. Call this for every commit. | |
| 210 void CommitPending(); | |
| 211 | |
| 212 // Helper method to terminate the pending RenderViewHost. | |
| 213 void CancelPending(); | |
| 214 | |
| 215 RenderViewHost* UpdateRendererStateForNavigate(const NavigationEntry& entry); | |
| 216 | |
| 217 // Our delegate, not owned by us. Guaranteed non-NULL. | |
| 218 Delegate* delegate_; | |
| 219 | |
| 220 // Whether a navigation requiring different RenderView's is pending. This is | |
| 221 // either cross-site request is (in the new process model), or when required | |
| 222 // for the view type (like view source versus not). | |
| 223 bool cross_navigation_pending_; | |
| 224 | |
| 225 // Implemented by the owner of this class, this delegate is installed into all | |
| 226 // the RenderViewHosts that we create. | |
| 227 RenderViewHostDelegate* render_view_delegate_; | |
| 228 | |
| 229 // Our RenderView host and its associated DOM UI (if any, will be NULL for | |
| 230 // non-DOM-UI pages). This object is responsible for all communication with | |
| 231 // a child RenderView instance. | |
| 232 RenderViewHost* render_view_host_; | |
| 233 scoped_ptr<DOMUI> dom_ui_; | |
| 234 | |
| 235 // A RenderViewHost used to load a cross-site page. This remains hidden | |
| 236 // while a cross-site request is pending until it calls DidNavigate. It may | |
| 237 // have an associated DOM UI, in which case the DOM UI pointer will be non- | |
| 238 // NULL. | |
| 239 // | |
| 240 // The pending_dom_ui may be non-NULL even when the pending_render_view_host_ | |
| 241 // is. This will happen when we're transitioning between two DOM UI pages: | |
| 242 // the RVH won't be swapped, so the pending pointer will be unused, but there | |
| 243 // will be a pending DOM UI associated with the navigation. | |
| 244 RenderViewHost* pending_render_view_host_; | |
| 245 scoped_ptr<DOMUI> pending_dom_ui_; | |
| 246 | |
| 247 // Records whether the navigation was cancelled, but we are leaving the | |
| 248 // pending_render_view_host_ around in consideration of the download system. | |
| 249 bool pending_renderer_aborted_; | |
| 250 | |
| 251 // The intersitial page currently shown if any, not own by this class | |
| 252 // (the InterstitialPage is self-owned, it deletes itself when hidden). | |
| 253 InterstitialPage* interstitial_page_; | |
| 254 | |
| 255 NotificationRegistrar registrar_; | |
| 256 | |
| 257 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); | |
| 258 }; | |
| 259 | |
| 260 // The "details" for a NOTIFY_RENDER_VIEW_HOST_CHANGED notification. The old | |
| 261 // host can be NULL when the first RenderViewHost is set. | |
| 262 struct RenderViewHostSwitchedDetails { | |
| 263 RenderViewHost* old_host; | |
| 264 RenderViewHost* new_host; | |
| 265 }; | |
| 266 | |
| 267 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_MANAGER_H_ | |
| OLD | NEW |