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

Side by Side Diff: content/browser/frame_host/render_view_host_manager.h

Issue 92153003: Rename RenderViewHostManager to RenderFrameHostManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years 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
(Empty)
1 // Copyright 2013 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 CONTENT_BROWSER_FRAME_HOST_RENDER_VIEW_HOST_MANAGER_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_VIEW_HOST_MANAGER_H_
7
8 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/browser/renderer_host/render_view_host_delegate.h"
13 #include "content/browser/site_instance_impl.h"
14 #include "content/common/content_export.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/common/referrer.h"
18
19
20 namespace content {
21 class BrowserContext;
22 class InterstitialPageImpl;
23 class NavigationControllerImpl;
24 class NavigationEntry;
25 class NavigationEntryImpl;
26 class RenderViewHost;
27 class RenderViewHostImpl;
28 class RenderViewHostManagerTest;
29 class RenderWidgetHostDelegate;
30 class RenderWidgetHostView;
31 class TestWebContents;
32 class WebUIImpl;
33
34 // Manages RenderViewHosts for a WebContentsImpl. Normally there is only one and
35 // it is easy to do. But we can also have transitions of processes (and hence
36 // RenderViewHosts) that can get complex.
37 class CONTENT_EXPORT RenderViewHostManager
38 : public RenderViewHostDelegate::RendererManagement,
39 public NotificationObserver {
40 public:
41 // Functions implemented by our owner that we need.
42 //
43 // TODO(brettw) Clean this up! These are all the functions in WebContentsImpl
44 // that are required to run this class. The design should probably be better
45 // such that these are more clear.
46 //
47 // There is additional complexity that some of the functions we need in
48 // WebContentsImpl are inherited and non-virtual. These are named with
49 // "RenderManager" so that the duplicate implementation of them will be clear.
50 class CONTENT_EXPORT Delegate {
51 public:
52 // Initializes the given renderer if necessary and creates the view ID
53 // corresponding to this view host. If this method is not called and the
54 // process is not shared, then the WebContentsImpl will act as though the
55 // renderer is not running (i.e., it will render "sad tab"). This method is
56 // automatically called from LoadURL.
57 //
58 // If you are attaching to an already-existing RenderView, you should call
59 // InitWithExistingID.
60 virtual bool CreateRenderViewForRenderManager(
61 RenderViewHost* render_view_host, int opener_route_id) = 0;
62 virtual void BeforeUnloadFiredFromRenderManager(
63 bool proceed, const base::TimeTicks& proceed_time,
64 bool* proceed_to_fire_unload) = 0;
65 virtual void RenderProcessGoneFromRenderManager(
66 RenderViewHost* render_view_host) = 0;
67 virtual void UpdateRenderViewSizeForRenderManager() = 0;
68 virtual void CancelModalDialogsForRenderManager() = 0;
69 virtual void NotifySwappedFromRenderManager(
70 RenderViewHost* old_host, RenderViewHost* new_host) = 0;
71 virtual NavigationControllerImpl&
72 GetControllerForRenderManager() = 0;
73
74 // Create swapped out RenderViews in the given SiteInstance for each tab in
75 // the opener chain of this tab, if any. This allows the current tab to
76 // make cross-process script calls to its opener(s). Returns the route ID
77 // of the immediate opener, if one exists (otherwise MSG_ROUTING_NONE).
78 virtual int CreateOpenerRenderViewsForRenderManager(
79 SiteInstance* instance) = 0;
80
81 // Creates a WebUI object for the given URL if one applies. Ownership of the
82 // returned pointer will be passed to the caller. If no WebUI applies,
83 // returns NULL.
84 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) = 0;
85
86 // Returns the navigation entry of the current navigation, or NULL if there
87 // is none.
88 virtual NavigationEntry*
89 GetLastCommittedNavigationEntryForRenderManager() = 0;
90
91 // Returns true if the location bar should be focused by default rather than
92 // the page contents. The view calls this function when the tab is focused
93 // to see what it should do.
94 virtual bool FocusLocationBarByDefault() = 0;
95
96 // Focuses the location bar.
97 virtual void SetFocusToLocationBar(bool select_all) = 0;
98
99 // Creates a view and sets the size for the specified RVH.
100 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) = 0;
101
102 // Returns true if views created for this delegate should be created in a
103 // hidden state.
104 virtual bool IsHidden() = 0;
105
106 protected:
107 virtual ~Delegate() {}
108 };
109
110 // All three delegate pointers must be non-NULL and are not owned by this
111 // class. They must outlive this class. The RenderViewHostDelegate and
112 // RenderWidgetHostDelegate are what will be installed into all
113 // RenderViewHosts that are created.
114 //
115 // You must call Init() before using this class.
116 RenderViewHostManager(
117 RenderViewHostDelegate* render_view_delegate,
118 RenderWidgetHostDelegate* render_widget_delegate,
119 Delegate* delegate);
120 virtual ~RenderViewHostManager();
121
122 // For arguments, see WebContentsImpl constructor.
123 void Init(BrowserContext* browser_context,
124 SiteInstance* site_instance,
125 int routing_id,
126 int main_frame_routing_id);
127
128 // Returns the currently active RenderViewHost.
129 //
130 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
131 // check it in many cases, however. Windows can send us messages during the
132 // destruction process after it has been shut down.
133 RenderViewHostImpl* current_host() const;
134
135 // Returns the view associated with the current RenderViewHost, or NULL if
136 // there is no current one.
137 RenderWidgetHostView* GetRenderWidgetHostView() const;
138
139 // Returns the pending render view host, or NULL if there is no pending one.
140 RenderViewHostImpl* pending_render_view_host() const;
141
142 // Returns the current committed Web UI or NULL if none applies.
143 WebUIImpl* web_ui() const { return web_ui_.get(); }
144
145 // Returns the Web UI for the pending navigation, or NULL of none applies.
146 WebUIImpl* pending_web_ui() const {
147 return pending_web_ui_.get() ? pending_web_ui_.get() :
148 pending_and_current_web_ui_.get();
149 }
150
151 // Sets the pending Web UI for the pending navigation, ensuring that the
152 // bindings are appropriate for the given NavigationEntry.
153 void SetPendingWebUI(const NavigationEntryImpl& entry);
154
155 // Called when we want to instruct the renderer to navigate to the given
156 // navigation entry. It may create a new RenderViewHost or re-use an existing
157 // one. The RenderViewHost to navigate will be returned. Returns NULL if one
158 // could not be created.
159 RenderViewHostImpl* Navigate(const NavigationEntryImpl& entry);
160
161 // Instructs the various live views to stop. Called when the user directed the
162 // page to stop loading.
163 void Stop();
164
165 // Notifies the regular and pending RenderViewHosts that a load is or is not
166 // happening. Even though the message is only for one of them, we don't know
167 // which one so we tell both.
168 void SetIsLoading(bool is_loading);
169
170 // Whether to close the tab or not when there is a hang during an unload
171 // handler. If we are mid-crosssite navigation, then we should proceed
172 // with the navigation instead of closing the tab.
173 bool ShouldCloseTabOnUnresponsiveRenderer();
174
175 // The RenderViewHost has been swapped out, so we should resume the pending
176 // network response and allow the pending RenderViewHost to commit.
177 void SwappedOut(RenderViewHost* render_view_host);
178
179 // Called when a renderer's main frame navigates.
180 void DidNavigateMainFrame(RenderViewHost* render_view_host);
181
182 // Called when a renderer sets its opener to null.
183 void DidDisownOpener(RenderViewHost* render_view_host);
184
185 // Helper method to create a RenderViewHost. If |swapped_out| is true, it
186 // will be initially placed on the swapped out hosts list. Otherwise, it
187 // will be used for a pending cross-site navigation.
188 int CreateRenderView(SiteInstance* instance,
189 int opener_route_id,
190 bool swapped_out,
191 bool hidden);
192
193 // Called when a provisional load on the given renderer is aborted.
194 void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host);
195
196 // Sets the passed passed interstitial as the currently showing interstitial.
197 // |interstitial_page| should be non NULL (use the remove_interstitial_page
198 // method to unset the interstitial) and no interstitial page should be set
199 // when there is already a non NULL interstitial page set.
200 void set_interstitial_page(InterstitialPageImpl* interstitial_page) {
201 DCHECK(!interstitial_page_ && interstitial_page);
202 interstitial_page_ = interstitial_page;
203 }
204
205 // Unsets the currently showing interstitial.
206 void remove_interstitial_page() {
207 DCHECK(interstitial_page_);
208 interstitial_page_ = NULL;
209 }
210
211 // Returns the currently showing interstitial, NULL if no interstitial is
212 // showing.
213 InterstitialPageImpl* interstitial_page() const { return interstitial_page_; }
214
215 // RenderViewHostDelegate::RendererManagement implementation.
216 virtual void ShouldClosePage(
217 bool for_cross_site_transition,
218 bool proceed,
219 const base::TimeTicks& proceed_time) OVERRIDE;
220 virtual void OnCrossSiteResponse(
221 RenderViewHost* pending_render_view_host,
222 const GlobalRequestID& global_request_id,
223 bool is_transfer,
224 const std::vector<GURL>& transfer_url_chain,
225 const Referrer& referrer,
226 PageTransition page_transition,
227 int64 frame_id,
228 bool should_replace_current_entry) OVERRIDE;
229
230 // NotificationObserver implementation.
231 virtual void Observe(int type,
232 const NotificationSource& source,
233 const NotificationDetails& details) OVERRIDE;
234
235 // Called when a RenderViewHost is about to be deleted.
236 void RenderViewDeleted(RenderViewHost* rvh);
237
238 // Returns whether the given RenderViewHost is on the list of swapped out
239 // RenderViewHosts.
240 bool IsOnSwappedOutList(RenderViewHost* rvh) const;
241
242 // Returns the swapped out RenderViewHost for the given SiteInstance, if any.
243 RenderViewHostImpl* GetSwappedOutRenderViewHost(SiteInstance* instance);
244
245 // Runs the unload handler in the current page, when we know that a pending
246 // cross-process navigation is going to commit. We may initiate a transfer
247 // to a new process after this completes or times out.
248 void SwapOutOldPage();
249
250 private:
251 friend class RenderViewHostManagerTest;
252 friend class TestWebContents;
253
254 // Tracks information about a navigation while a cross-process transition is
255 // in progress, in case we need to transfer it to a new RenderViewHost.
256 struct PendingNavigationParams {
257 PendingNavigationParams();
258 PendingNavigationParams(const GlobalRequestID& global_request_id,
259 bool is_transfer,
260 const std::vector<GURL>& transfer_url,
261 Referrer referrer,
262 PageTransition page_transition,
263 int64 frame_id,
264 bool should_replace_current_entry);
265 ~PendingNavigationParams();
266
267 // The child ID and request ID for the pending navigation. Present whether
268 // |is_transfer| is true or false.
269 GlobalRequestID global_request_id;
270
271 // Whether this pending navigation needs to be transferred to another
272 // process than the one it was going to commit in. If so, the
273 // |transfer_url|, |referrer|, and |frame_id| parameters will be set.
274 bool is_transfer;
275
276 // If |is_transfer|, this is the URL chain of the request. The first entry
277 // is the original request URL, and the last entry is the destination URL to
278 // request in the new process.
279 std::vector<GURL> transfer_url_chain;
280
281 // If |is_transfer|, this is the referrer to use for the request in the new
282 // process.
283 Referrer referrer;
284
285 // If |is_transfer|, this is the transition type for the original
286 // navigation.
287 PageTransition page_transition;
288
289 // If |is_transfer|, this is the frame ID to use in RequestTransferURL.
290 int64 frame_id;
291
292 // If |is_transfer|, this is whether the navigation should replace the
293 // current history entry.
294 bool should_replace_current_entry;
295 };
296
297 // Returns whether this tab should transition to a new renderer for
298 // cross-site URLs. Enabled unless we see the --process-per-tab command line
299 // switch. Can be overridden in unit tests.
300 bool ShouldTransitionCrossSite();
301
302 // Returns true if for the navigation from |current_entry| to |new_entry|,
303 // a new SiteInstance and BrowsingInstance should be created (even if we are
304 // in a process model that doesn't usually swap). This forces a process swap
305 // and severs script connections with existing tabs. Cases where this can
306 // happen include transitions between WebUI and regular web pages.
307 // Either of the entries may be NULL.
308 bool ShouldSwapBrowsingInstancesForNavigation(
309 const NavigationEntry* current_entry,
310 const NavigationEntryImpl* new_entry) const;
311
312 // Returns true if it is safe to reuse the current WebUI when navigating from
313 // |current_entry| to |new_entry|.
314 bool ShouldReuseWebUI(
315 const NavigationEntry* current_entry,
316 const NavigationEntryImpl* new_entry) const;
317
318 // Returns an appropriate SiteInstance object for the given NavigationEntry,
319 // possibly reusing the current SiteInstance. If --process-per-tab is used,
320 // this is only called when ShouldSwapBrowsingInstancesForNavigation returns
321 // true.
322 SiteInstance* GetSiteInstanceForEntry(
323 const NavigationEntryImpl& entry,
324 SiteInstance* current_instance,
325 bool force_browsing_instance_swap);
326
327 // Sets up the necessary state for a new RenderViewHost with the given opener.
328 bool InitRenderView(RenderViewHost* render_view_host, int opener_route_id);
329
330 // Sets the pending RenderViewHost/WebUI to be the active one. Note that this
331 // doesn't require the pending render_view_host_ pointer to be non-NULL, since
332 // there could be Web UI switching as well. Call this for every commit.
333 void CommitPending();
334
335 // Shutdown all RenderViewHosts in a SiteInstance. This is called
336 // to shutdown views when all the views in a SiteInstance are
337 // confirmed to be swapped out.
338 void ShutdownRenderViewHostsInSiteInstance(int32 site_instance_id);
339
340 // Helper method to terminate the pending RenderViewHost.
341 void CancelPending();
342
343 RenderViewHostImpl* UpdateRendererStateForNavigate(
344 const NavigationEntryImpl& entry);
345
346 // Called when a renderer process is starting to close. We should not
347 // schedule new navigations in its swapped out RenderViewHosts after this.
348 void RendererProcessClosing(RenderProcessHost* render_process_host);
349
350 // Our delegate, not owned by us. Guaranteed non-NULL.
351 Delegate* delegate_;
352
353 // Whether a navigation requiring different RenderView's is pending. This is
354 // either cross-site request is (in the new process model), or when required
355 // for the view type (like view source versus not).
356 bool cross_navigation_pending_;
357
358 // Implemented by the owner of this class, these delegates are installed into
359 // all the RenderViewHosts that we create.
360 RenderViewHostDelegate* render_view_delegate_;
361 RenderWidgetHostDelegate* render_widget_delegate_;
362
363 // Our RenderView host and its associated Web UI (if any, will be NULL for
364 // non-DOM-UI pages). This object is responsible for all communication with
365 // a child RenderView instance.
366 RenderViewHostImpl* render_view_host_;
367 scoped_ptr<WebUIImpl> web_ui_;
368
369 // A RenderViewHost used to load a cross-site page. This remains hidden
370 // while a cross-site request is pending until it calls DidNavigate. It may
371 // have an associated Web UI, in which case the Web UI pointer will be non-
372 // NULL.
373 //
374 // The |pending_web_ui_| may be non-NULL even when the
375 // |pending_render_view_host_| is NULL. This will happen when we're
376 // transitioning between two Web UI pages: the RVH won't be swapped, so the
377 // pending pointer will be unused, but there will be a pending Web UI
378 // associated with the navigation.
379 RenderViewHostImpl* pending_render_view_host_;
380
381 // Tracks information about any current pending cross-process navigation.
382 scoped_ptr<PendingNavigationParams> pending_nav_params_;
383
384 // If either of these is non-NULL, the pending navigation is to a chrome:
385 // page. The scoped_ptr is used if pending_web_ui_ != web_ui_, the WeakPtr is
386 // used for when they reference the same object. If either is non-NULL, the
387 // other should be NULL.
388 scoped_ptr<WebUIImpl> pending_web_ui_;
389 base::WeakPtr<WebUIImpl> pending_and_current_web_ui_;
390
391 // A map of site instance ID to swapped out RenderViewHosts. This may include
392 // pending_render_view_host_ for navigations to existing entries.
393 typedef base::hash_map<int32, RenderViewHostImpl*> RenderViewHostMap;
394 RenderViewHostMap swapped_out_hosts_;
395
396 // The intersitial page currently shown if any, not own by this class
397 // (the InterstitialPage is self-owned, it deletes itself when hidden).
398 InterstitialPageImpl* interstitial_page_;
399
400 NotificationRegistrar registrar_;
401
402 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager);
403 };
404
405 } // namespace content
406
407 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_VIEW_HOST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698