Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/tab_contents/render_view_host_manager.h

Issue 6537015: Start moving core pieces of Chrome multi-process code to src\content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 // TODO(jam): remove this file when all files have been converted.
10 #include "base/logging.h" 10 #include "content/browser/tab_contents/render_view_host_manager.h"
11 #include "base/scoped_ptr.h"
12 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
13 #include "chrome/common/notification_registrar.h"
14
15 class WebUI;
16 class InterstitialPage;
17 class NavigationController;
18 class NavigationEntry;
19 class Profile;
20 class RenderWidgetHostView;
21 class RenderViewHost;
22 class SiteInstance;
23
24 // 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 // RenderViewHosts) that can get complex.
27 class RenderViewHostManager
28 : public RenderViewHostDelegate::RendererManagement {
29 public:
30 // Functions implemented by our owner that we need.
31 //
32 // 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
34 // that these are more clear.
35 //
36 // There is additional complexity that some of the functions we need in
37 // TabContents are inherited and non-virtual. These are named with
38 // "RenderManager" so that the duplicate implementation of them will be clear.
39 class Delegate {
40 public:
41 // See tab_contents.h's implementation for more.
42 virtual bool CreateRenderViewForRenderManager(
43 RenderViewHost* render_view_host) = 0;
44 virtual void BeforeUnloadFiredFromRenderManager(
45 bool proceed, bool* proceed_to_fire_unload) = 0;
46 virtual void DidStartLoadingFromRenderManager(
47 RenderViewHost* render_view_host) = 0;
48 virtual void RenderViewGoneFromRenderManager(
49 RenderViewHost* render_view_host) = 0;
50 virtual void UpdateRenderViewSizeForRenderManager() = 0;
51 virtual void NotifySwappedFromRenderManager() = 0;
52 virtual NavigationController& GetControllerForRenderManager() = 0;
53
54 // Creates a WebUI object for the given URL if one applies. Ownership of the
55 // returned pointer will be passed to the caller. If no WebUI applies,
56 // returns NULL.
57 virtual WebUI* CreateWebUIForRenderManager(const GURL& url) = 0;
58
59 // Returns the navigation entry of the current navigation, or NULL if there
60 // is none.
61 virtual NavigationEntry*
62 GetLastCommittedNavigationEntryForRenderManager() = 0;
63
64 // Returns true if the location bar should be focused by default rather than
65 // the page contents.
66 virtual bool FocusLocationBarByDefault() = 0;
67
68 // Focuses the location bar.
69 virtual void SetFocusToLocationBar(bool select_all) = 0;
70
71 // Creates a view and sets the size for the specified RVH.
72 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) = 0;
73
74 protected:
75 virtual ~Delegate() {}
76 };
77
78 // Both delegate pointers must be non-NULL and are not owned by this class.
79 // They must outlive this class. The RenderViewHostDelegate is what will be
80 // installed into all RenderViewHosts that are created.
81 //
82 // You must call Init() before using this class.
83 RenderViewHostManager(RenderViewHostDelegate* render_view_delegate,
84 Delegate* delegate);
85 virtual ~RenderViewHostManager();
86
87 // For arguments, see TabContents constructor.
88 void Init(Profile* profile,
89 SiteInstance* site_instance,
90 int routing_id);
91
92 // Returns the currently actuive RenderViewHost.
93 //
94 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
95 // check it in many cases, however. Windows can send us messages during the
96 // destruction process after it has been shut down.
97 RenderViewHost* current_host() const {
98 return render_view_host_;
99 }
100
101 // Returns the view associated with the current RenderViewHost, or NULL if
102 // there is no current one.
103 RenderWidgetHostView* GetRenderWidgetHostView() const;
104
105 // Returns the pending render view host, or NULL if there is no pending one.
106 RenderViewHost* pending_render_view_host() const {
107 return pending_render_view_host_;
108 }
109
110 // Returns the current committed Web UI or NULL if none applies.
111 WebUI* web_ui() const { return web_ui_.get(); }
112
113 // Returns the Web UI for the pending navigation, or NULL of none applies.
114 WebUI* pending_web_ui() const { return pending_web_ui_.get(); }
115
116 // Called when we want to instruct the renderer to navigate to the given
117 // navigation entry. It may create a new RenderViewHost or re-use an existing
118 // one. The RenderViewHost to navigate will be returned. Returns NULL if one
119 // could not be created.
120 RenderViewHost* Navigate(const NavigationEntry& entry);
121
122 // Instructs the various live views to stop. Called when the user directed the
123 // page to stop loading.
124 void Stop();
125
126 // Notifies the regular and pending RenderViewHosts that a load is or is not
127 // happening. Even though the message is only for one of them, we don't know
128 // which one so we tell both.
129 void SetIsLoading(bool is_loading);
130
131 // Whether to close the tab or not when there is a hang during an unload
132 // handler. If we are mid-crosssite navigation, then we should proceed
133 // with the navigation instead of closing the tab.
134 bool ShouldCloseTabOnUnresponsiveRenderer();
135
136 // Called when a renderer's main frame navigates.
137 void DidNavigateMainFrame(RenderViewHost* render_view_host);
138
139 // Set the WebUI after committing a page load. This is useful for navigations
140 // initiated from a renderer, where we want to give the new renderer WebUI
141 // privileges from the originating renderer.
142 void SetWebUIPostCommit(WebUI* web_ui);
143
144 // Called when a provisional load on the given renderer is aborted.
145 void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host);
146
147 // Sets the passed passed interstitial as the currently showing interstitial.
148 // |interstitial_page| should be non NULL (use the remove_interstitial_page
149 // method to unset the interstitial) and no interstitial page should be set
150 // when there is already a non NULL interstitial page set.
151 void set_interstitial_page(InterstitialPage* interstitial_page) {
152 DCHECK(!interstitial_page_ && interstitial_page);
153 interstitial_page_ = interstitial_page;
154 }
155
156 // Unsets the currently showing interstitial.
157 void remove_interstitial_page() {
158 DCHECK(interstitial_page_);
159 interstitial_page_ = NULL;
160 }
161
162 // Returns the currently showing interstitial, NULL if no interstitial is
163 // showing.
164 InterstitialPage* interstitial_page() const {
165 return interstitial_page_;
166 }
167
168 // RenderViewHostDelegate::RendererManagement implementation.
169 virtual void ShouldClosePage(bool for_cross_site_transition, bool proceed);
170 virtual void OnCrossSiteResponse(int new_render_process_host_id,
171 int new_request_id);
172 virtual void OnCrossSiteNavigationCanceled();
173
174 // Called when a RenderViewHost is about to be deleted.
175 void RenderViewDeleted(RenderViewHost* rvh);
176
177 // Allows a caller to swap in a provided RenderViewHost to replace the
178 // current RenderViewHost. The current RVH will be shutdown and ultimately
179 // deleted.
180 void SwapInRenderViewHost(RenderViewHost* rvh);
181
182 private:
183 friend class TestTabContents;
184 friend class RenderViewHostManagerTest;
185
186 // 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
188 // switch. Can be overridden in unit tests.
189 bool ShouldTransitionCrossSite();
190
191 // Returns true if the two navigation entries are incompatible in some way
192 // other than site instances. Cases where this can happen include Web UI
193 // to regular web pages. It will cause us to swap RenderViewHosts (and hence
194 // RenderProcessHosts) even if the site instance would otherwise be the same.
195 // As part of this, we'll also force new SiteInstances and BrowsingInstances.
196 // Either of the entries may be NULL.
197 bool ShouldSwapProcessesForNavigation(
198 const NavigationEntry* cur_entry,
199 const NavigationEntry* new_entry) const;
200
201 // Returns an appropriate SiteInstance object for the given NavigationEntry,
202 // possibly reusing the current SiteInstance.
203 // Never called if --process-per-tab is used.
204 SiteInstance* GetSiteInstanceForEntry(const NavigationEntry& entry,
205 SiteInstance* curr_instance);
206
207 // Helper method to create a pending RenderViewHost for a cross-site
208 // navigation.
209 bool CreatePendingRenderView(const NavigationEntry& entry,
210 SiteInstance* instance);
211
212 // Sets up the necessary state for a new RenderViewHost navigating to the
213 // given entry.
214 bool InitRenderView(RenderViewHost* render_view_host,
215 const NavigationEntry& entry);
216
217 // 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
219 // there could be Web UI switching as well. Call this for every commit.
220 void CommitPending();
221
222 // Helper method to terminate the pending RenderViewHost.
223 void CancelPending();
224
225 RenderViewHost* UpdateRendererStateForNavigate(const NavigationEntry& entry);
226
227 // Our delegate, not owned by us. Guaranteed non-NULL.
228 Delegate* delegate_;
229
230 // 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
232 // for the view type (like view source versus not).
233 bool cross_navigation_pending_;
234
235 // Implemented by the owner of this class, this delegate is installed into all
236 // the RenderViewHosts that we create.
237 RenderViewHostDelegate* render_view_delegate_;
238
239 // Our RenderView host and its associated Web UI (if any, will be NULL for
240 // non-DOM-UI pages). This object is responsible for all communication with
241 // a child RenderView instance.
242 RenderViewHost* render_view_host_;
243 scoped_ptr<WebUI> web_ui_;
244
245 // A RenderViewHost used to load a cross-site page. This remains hidden
246 // while a cross-site request is pending until it calls DidNavigate. It may
247 // have an associated Web UI, in which case the Web UI pointer will be non-
248 // NULL.
249 //
250 // 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:
252 // 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.
254 RenderViewHost* pending_render_view_host_;
255 scoped_ptr<WebUI> pending_web_ui_;
256
257 // The intersitial page currently shown if any, not own by this class
258 // (the InterstitialPage is self-owned, it deletes itself when hidden).
259 InterstitialPage* interstitial_page_;
260
261 NotificationRegistrar registrar_;
262
263 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager);
264 };
265
266 // The "details" for a NOTIFY_RENDER_VIEW_HOST_CHANGED notification. The old
267 // host can be NULL when the first RenderViewHost is set.
268 struct RenderViewHostSwitchedDetails {
269 RenderViewHost* old_host;
270 RenderViewHost* new_host;
271 };
272 11
273 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ 12 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/provisional_load_details.cc ('k') | chrome/browser/tab_contents/render_view_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698