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

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

Issue 9600036: Move Render(View|Widget)Host and associated classes to content namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments. Created 8 years, 9 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) 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_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/site_instance_impl.h" 12 #include "content/browser/site_instance_impl.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/render_view_host_delegate.h" 16 #include "content/public/browser/render_view_host_delegate.h"
17 17
18 class InterstitialPageImpl; 18 class InterstitialPageImpl;
19 class NavigationControllerImpl; 19 class NavigationControllerImpl;
20 class RenderViewHost;
21 class RenderViewHostImpl;
22 class WebUIImpl; 20 class WebUIImpl;
23 21
24 namespace content { 22 namespace content {
25 class BrowserContext; 23 class BrowserContext;
26 class NavigationEntry; 24 class NavigationEntry;
27 class NavigationEntryImpl; 25 class NavigationEntryImpl;
26 class RenderViewHost;
27 class RenderViewHostImpl;
28 class RenderWidgetHostView; 28 class RenderWidgetHostView;
29 } 29 }
30 30
31 // Manages RenderViewHosts for a TabContents. Normally there is only one and 31 // Manages RenderViewHosts for a TabContents. Normally there is only one and
32 // it is easy to do. But we can also have transitions of processes (and hence 32 // it is easy to do. But we can also have transitions of processes (and hence
33 // RenderViewHosts) that can get complex. 33 // RenderViewHosts) that can get complex.
34 class CONTENT_EXPORT RenderViewHostManager 34 class CONTENT_EXPORT RenderViewHostManager
35 : public content::RenderViewHostDelegate::RendererManagement, 35 : public content::RenderViewHostDelegate::RendererManagement,
36 public content::NotificationObserver { 36 public content::NotificationObserver {
37 public: 37 public:
(...skipping 10 matching lines...) Expand all
48 public: 48 public:
49 // Initializes the given renderer if necessary and creates the view ID 49 // Initializes the given renderer if necessary and creates the view ID
50 // corresponding to this view host. If this method is not called and the 50 // corresponding to this view host. If this method is not called and the
51 // process is not shared, then the TabContents will act as though the 51 // process is not shared, then the TabContents will act as though the
52 // renderer is not running (i.e., it will render "sad tab"). This method is 52 // renderer is not running (i.e., it will render "sad tab"). This method is
53 // automatically called from LoadURL. 53 // automatically called from LoadURL.
54 // 54 //
55 // If you are attaching to an already-existing RenderView, you should call 55 // If you are attaching to an already-existing RenderView, you should call
56 // InitWithExistingID. 56 // InitWithExistingID.
57 virtual bool CreateRenderViewForRenderManager( 57 virtual bool CreateRenderViewForRenderManager(
58 RenderViewHost* render_view_host) = 0; 58 content::RenderViewHost* render_view_host) = 0;
59 virtual void BeforeUnloadFiredFromRenderManager( 59 virtual void BeforeUnloadFiredFromRenderManager(
60 bool proceed, bool* proceed_to_fire_unload) = 0; 60 bool proceed, bool* proceed_to_fire_unload) = 0;
61 virtual void DidStartLoadingFromRenderManager( 61 virtual void DidStartLoadingFromRenderManager(
62 RenderViewHost* render_view_host) = 0; 62 content::RenderViewHost* render_view_host) = 0;
63 virtual void RenderViewGoneFromRenderManager( 63 virtual void RenderViewGoneFromRenderManager(
64 RenderViewHost* render_view_host) = 0; 64 content::RenderViewHost* render_view_host) = 0;
65 virtual void UpdateRenderViewSizeForRenderManager() = 0; 65 virtual void UpdateRenderViewSizeForRenderManager() = 0;
66 virtual void NotifySwappedFromRenderManager() = 0; 66 virtual void NotifySwappedFromRenderManager() = 0;
67 virtual NavigationControllerImpl& GetControllerForRenderManager() = 0; 67 virtual NavigationControllerImpl& GetControllerForRenderManager() = 0;
68 68
69 // Creates a WebUI object for the given URL if one applies. Ownership of the 69 // Creates a WebUI object for the given URL if one applies. Ownership of the
70 // returned pointer will be passed to the caller. If no WebUI applies, 70 // returned pointer will be passed to the caller. If no WebUI applies,
71 // returns NULL. 71 // returns NULL.
72 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) = 0; 72 virtual WebUIImpl* CreateWebUIForRenderManager(const GURL& url) = 0;
73 73
74 // Returns the navigation entry of the current navigation, or NULL if there 74 // Returns the navigation entry of the current navigation, or NULL if there
75 // is none. 75 // is none.
76 virtual content::NavigationEntry* 76 virtual content::NavigationEntry*
77 GetLastCommittedNavigationEntryForRenderManager() = 0; 77 GetLastCommittedNavigationEntryForRenderManager() = 0;
78 78
79 // Returns true if the location bar should be focused by default rather than 79 // Returns true if the location bar should be focused by default rather than
80 // the page contents. The view calls this function when the tab is focused 80 // the page contents. The view calls this function when the tab is focused
81 // to see what it should do. 81 // to see what it should do.
82 virtual bool FocusLocationBarByDefault() = 0; 82 virtual bool FocusLocationBarByDefault() = 0;
83 83
84 // Focuses the location bar. 84 // Focuses the location bar.
85 virtual void SetFocusToLocationBar(bool select_all) = 0; 85 virtual void SetFocusToLocationBar(bool select_all) = 0;
86 86
87 // Creates a view and sets the size for the specified RVH. 87 // Creates a view and sets the size for the specified RVH.
88 virtual void CreateViewAndSetSizeForRVH(RenderViewHost* rvh) = 0; 88 virtual void CreateViewAndSetSizeForRVH(content::RenderViewHost* rvh) = 0;
89 89
90 protected: 90 protected:
91 virtual ~Delegate() {} 91 virtual ~Delegate() {}
92 }; 92 };
93 93
94 // Both delegate pointers must be non-NULL and are not owned by this class. 94 // Both delegate pointers must be non-NULL and are not owned by this class.
95 // They must outlive this class. The RenderViewHostDelegate is what will be 95 // They must outlive this class. The RenderViewHostDelegate is what will be
96 // installed into all RenderViewHosts that are created. 96 // installed into all RenderViewHosts that are created.
97 // 97 //
98 // You must call Init() before using this class. 98 // You must call Init() before using this class.
99 RenderViewHostManager(content::RenderViewHostDelegate* render_view_delegate, 99 RenderViewHostManager(content::RenderViewHostDelegate* render_view_delegate,
100 Delegate* delegate); 100 Delegate* delegate);
101 virtual ~RenderViewHostManager(); 101 virtual ~RenderViewHostManager();
102 102
103 // For arguments, see TabContents constructor. 103 // For arguments, see TabContents constructor.
104 void Init(content::BrowserContext* browser_context, 104 void Init(content::BrowserContext* browser_context,
105 content::SiteInstance* site_instance, 105 content::SiteInstance* site_instance,
106 int routing_id); 106 int routing_id);
107 107
108 // Returns the currently active RenderViewHost. 108 // Returns the currently active RenderViewHost.
109 // 109 //
110 // This will be non-NULL between Init() and Shutdown(). You may want to NULL 110 // This will be non-NULL between Init() and Shutdown(). You may want to NULL
111 // check it in many cases, however. Windows can send us messages during the 111 // check it in many cases, however. Windows can send us messages during the
112 // destruction process after it has been shut down. 112 // destruction process after it has been shut down.
113 RenderViewHostImpl* current_host() const; 113 content::RenderViewHostImpl* current_host() const;
114 114
115 // Returns the view associated with the current RenderViewHost, or NULL if 115 // Returns the view associated with the current RenderViewHost, or NULL if
116 // there is no current one. 116 // there is no current one.
117 content::RenderWidgetHostView* GetRenderWidgetHostView() const; 117 content::RenderWidgetHostView* GetRenderWidgetHostView() const;
118 118
119 // Returns the pending render view host, or NULL if there is no pending one. 119 // Returns the pending render view host, or NULL if there is no pending one.
120 RenderViewHostImpl* pending_render_view_host() const; 120 content::RenderViewHostImpl* pending_render_view_host() const;
121 121
122 // Returns the current committed Web UI or NULL if none applies. 122 // Returns the current committed Web UI or NULL if none applies.
123 WebUIImpl* web_ui() const { return web_ui_.get(); } 123 WebUIImpl* web_ui() const { return web_ui_.get(); }
124 124
125 // Returns the Web UI for the pending navigation, or NULL of none applies. 125 // Returns the Web UI for the pending navigation, or NULL of none applies.
126 WebUIImpl* pending_web_ui() const { return pending_web_ui_.get(); } 126 WebUIImpl* pending_web_ui() const { return pending_web_ui_.get(); }
127 127
128 // Called when we want to instruct the renderer to navigate to the given 128 // Called when we want to instruct the renderer to navigate to the given
129 // navigation entry. It may create a new RenderViewHost or re-use an existing 129 // navigation entry. It may create a new RenderViewHost or re-use an existing
130 // one. The RenderViewHost to navigate will be returned. Returns NULL if one 130 // one. The RenderViewHost to navigate will be returned. Returns NULL if one
131 // could not be created. 131 // could not be created.
132 RenderViewHostImpl* Navigate(const content::NavigationEntryImpl& entry); 132 content::RenderViewHostImpl* Navigate(
133 const content::NavigationEntryImpl& entry);
133 134
134 // Instructs the various live views to stop. Called when the user directed the 135 // Instructs the various live views to stop. Called when the user directed the
135 // page to stop loading. 136 // page to stop loading.
136 void Stop(); 137 void Stop();
137 138
138 // Notifies the regular and pending RenderViewHosts that a load is or is not 139 // Notifies the regular and pending RenderViewHosts that a load is or is not
139 // happening. Even though the message is only for one of them, we don't know 140 // happening. Even though the message is only for one of them, we don't know
140 // which one so we tell both. 141 // which one so we tell both.
141 void SetIsLoading(bool is_loading); 142 void SetIsLoading(bool is_loading);
142 143
143 // Whether to close the tab or not when there is a hang during an unload 144 // Whether to close the tab or not when there is a hang during an unload
144 // handler. If we are mid-crosssite navigation, then we should proceed 145 // handler. If we are mid-crosssite navigation, then we should proceed
145 // with the navigation instead of closing the tab. 146 // with the navigation instead of closing the tab.
146 bool ShouldCloseTabOnUnresponsiveRenderer(); 147 bool ShouldCloseTabOnUnresponsiveRenderer();
147 148
148 // Called when a renderer's main frame navigates. 149 // Called when a renderer's main frame navigates.
149 void DidNavigateMainFrame(RenderViewHost* render_view_host); 150 void DidNavigateMainFrame(content::RenderViewHost* render_view_host);
150 151
151 // Set the WebUI after committing a page load. This is useful for navigations 152 // Set the WebUI after committing a page load. This is useful for navigations
152 // initiated from a renderer, where we want to give the new renderer WebUI 153 // initiated from a renderer, where we want to give the new renderer WebUI
153 // privileges from the originating renderer. 154 // privileges from the originating renderer.
154 void SetWebUIPostCommit(WebUIImpl* web_ui); 155 void SetWebUIPostCommit(WebUIImpl* web_ui);
155 156
156 // Called when a provisional load on the given renderer is aborted. 157 // Called when a provisional load on the given renderer is aborted.
157 void RendererAbortedProvisionalLoad(RenderViewHost* render_view_host); 158 void RendererAbortedProvisionalLoad(
159 content::RenderViewHost* render_view_host);
158 160
159 // Sets the passed passed interstitial as the currently showing interstitial. 161 // Sets the passed passed interstitial as the currently showing interstitial.
160 // |interstitial_page| should be non NULL (use the remove_interstitial_page 162 // |interstitial_page| should be non NULL (use the remove_interstitial_page
161 // method to unset the interstitial) and no interstitial page should be set 163 // method to unset the interstitial) and no interstitial page should be set
162 // when there is already a non NULL interstitial page set. 164 // when there is already a non NULL interstitial page set.
163 void set_interstitial_page(InterstitialPageImpl* interstitial_page) { 165 void set_interstitial_page(InterstitialPageImpl* interstitial_page) {
164 DCHECK(!interstitial_page_ && interstitial_page); 166 DCHECK(!interstitial_page_ && interstitial_page);
165 interstitial_page_ = interstitial_page; 167 interstitial_page_ = interstitial_page;
166 } 168 }
167 169
(...skipping 14 matching lines...) Expand all
182 bool proceed) OVERRIDE; 184 bool proceed) OVERRIDE;
183 virtual void OnCrossSiteResponse(int new_render_process_host_id, 185 virtual void OnCrossSiteResponse(int new_render_process_host_id,
184 int new_request_id) OVERRIDE; 186 int new_request_id) OVERRIDE;
185 187
186 // content::NotificationObserver implementation. 188 // content::NotificationObserver implementation.
187 virtual void Observe(int type, 189 virtual void Observe(int type,
188 const content::NotificationSource& source, 190 const content::NotificationSource& source,
189 const content::NotificationDetails& details) OVERRIDE; 191 const content::NotificationDetails& details) OVERRIDE;
190 192
191 // Called when a RenderViewHost is about to be deleted. 193 // Called when a RenderViewHost is about to be deleted.
192 void RenderViewDeleted(RenderViewHost* rvh); 194 void RenderViewDeleted(content::RenderViewHost* rvh);
193 195
194 // Returns whether the given RenderViewHost is on the list of swapped out 196 // Returns whether the given RenderViewHost is on the list of swapped out
195 // RenderViewHosts. 197 // RenderViewHosts.
196 bool IsSwappedOut(RenderViewHost* rvh); 198 bool IsSwappedOut(content::RenderViewHost* rvh);
197 199
198 private: 200 private:
199 friend class TestTabContents; 201 friend class TestTabContents;
200 friend class RenderViewHostManagerTest; 202 friend class RenderViewHostManagerTest;
201 203
202 // Returns whether this tab should transition to a new renderer for 204 // Returns whether this tab should transition to a new renderer for
203 // cross-site URLs. Enabled unless we see the --process-per-tab command line 205 // cross-site URLs. Enabled unless we see the --process-per-tab command line
204 // switch. Can be overridden in unit tests. 206 // switch. Can be overridden in unit tests.
205 bool ShouldTransitionCrossSite(); 207 bool ShouldTransitionCrossSite();
206 208
(...skipping 14 matching lines...) Expand all
221 const content::NavigationEntryImpl& entry, 223 const content::NavigationEntryImpl& entry,
222 content::SiteInstance* curr_instance); 224 content::SiteInstance* curr_instance);
223 225
224 // Helper method to create a pending RenderViewHost for a cross-site 226 // Helper method to create a pending RenderViewHost for a cross-site
225 // navigation. 227 // navigation.
226 bool CreatePendingRenderView(const content::NavigationEntryImpl& entry, 228 bool CreatePendingRenderView(const content::NavigationEntryImpl& entry,
227 content::SiteInstance* instance); 229 content::SiteInstance* instance);
228 230
229 // Sets up the necessary state for a new RenderViewHost navigating to the 231 // Sets up the necessary state for a new RenderViewHost navigating to the
230 // given entry. 232 // given entry.
231 bool InitRenderView(RenderViewHost* render_view_host, 233 bool InitRenderView(content::RenderViewHost* render_view_host,
232 const content::NavigationEntryImpl& entry); 234 const content::NavigationEntryImpl& entry);
233 235
234 // Sets the pending RenderViewHost/WebUI to be the active one. Note that this 236 // Sets the pending RenderViewHost/WebUI to be the active one. Note that this
235 // doesn't require the pending render_view_host_ pointer to be non-NULL, since 237 // doesn't require the pending render_view_host_ pointer to be non-NULL, since
236 // there could be Web UI switching as well. Call this for every commit. 238 // there could be Web UI switching as well. Call this for every commit.
237 void CommitPending(); 239 void CommitPending();
238 240
239 // Helper method to terminate the pending RenderViewHost. 241 // Helper method to terminate the pending RenderViewHost.
240 void CancelPending(); 242 void CancelPending();
241 243
242 RenderViewHostImpl* UpdateRendererStateForNavigate( 244 content::RenderViewHostImpl* UpdateRendererStateForNavigate(
243 const content::NavigationEntryImpl& entry); 245 const content::NavigationEntryImpl& entry);
244 246
245 // Called when a renderer process is starting to close. We should not 247 // Called when a renderer process is starting to close. We should not
246 // schedule new navigations in its swapped out RenderViewHosts after this. 248 // schedule new navigations in its swapped out RenderViewHosts after this.
247 void RendererProcessClosing(content::RenderProcessHost* render_process_host); 249 void RendererProcessClosing(content::RenderProcessHost* render_process_host);
248 250
249 // Our delegate, not owned by us. Guaranteed non-NULL. 251 // Our delegate, not owned by us. Guaranteed non-NULL.
250 Delegate* delegate_; 252 Delegate* delegate_;
251 253
252 // Whether a navigation requiring different RenderView's is pending. This is 254 // Whether a navigation requiring different RenderView's is pending. This is
253 // either cross-site request is (in the new process model), or when required 255 // either cross-site request is (in the new process model), or when required
254 // for the view type (like view source versus not). 256 // for the view type (like view source versus not).
255 bool cross_navigation_pending_; 257 bool cross_navigation_pending_;
256 258
257 // Implemented by the owner of this class, this delegate is installed into all 259 // Implemented by the owner of this class, this delegate is installed into all
258 // the RenderViewHosts that we create. 260 // the RenderViewHosts that we create.
259 content::RenderViewHostDelegate* render_view_delegate_; 261 content::RenderViewHostDelegate* render_view_delegate_;
260 262
261 // Our RenderView host and its associated Web UI (if any, will be NULL for 263 // Our RenderView host and its associated Web UI (if any, will be NULL for
262 // non-DOM-UI pages). This object is responsible for all communication with 264 // non-DOM-UI pages). This object is responsible for all communication with
263 // a child RenderView instance. 265 // a child RenderView instance.
264 RenderViewHostImpl* render_view_host_; 266 content::RenderViewHostImpl* render_view_host_;
265 scoped_ptr<WebUIImpl> web_ui_; 267 scoped_ptr<WebUIImpl> web_ui_;
266 268
267 // A RenderViewHost used to load a cross-site page. This remains hidden 269 // A RenderViewHost used to load a cross-site page. This remains hidden
268 // while a cross-site request is pending until it calls DidNavigate. It may 270 // while a cross-site request is pending until it calls DidNavigate. It may
269 // have an associated Web UI, in which case the Web UI pointer will be non- 271 // have an associated Web UI, in which case the Web UI pointer will be non-
270 // NULL. 272 // NULL.
271 // 273 //
272 // The pending_web_ui may be non-NULL even when the pending_render_view_host_ 274 // The pending_web_ui may be non-NULL even when the pending_render_view_host_
273 // is. This will happen when we're transitioning between two Web UI pages: 275 // is. This will happen when we're transitioning between two Web UI pages:
274 // the RVH won't be swapped, so the pending pointer will be unused, but there 276 // the RVH won't be swapped, so the pending pointer will be unused, but there
275 // will be a pending Web UI associated with the navigation. 277 // will be a pending Web UI associated with the navigation.
276 RenderViewHostImpl* pending_render_view_host_; 278 content::RenderViewHostImpl* pending_render_view_host_;
277 scoped_ptr<WebUIImpl> pending_web_ui_; 279 scoped_ptr<WebUIImpl> pending_web_ui_;
278 280
279 // A map of site instance ID to swapped out RenderViewHosts. 281 // A map of site instance ID to swapped out RenderViewHosts.
280 typedef base::hash_map<int32, RenderViewHostImpl*> RenderViewHostMap; 282 typedef base::hash_map<int32, content::RenderViewHostImpl*> RenderViewHostMap;
281 RenderViewHostMap swapped_out_hosts_; 283 RenderViewHostMap swapped_out_hosts_;
282 284
283 // The intersitial page currently shown if any, not own by this class 285 // The intersitial page currently shown if any, not own by this class
284 // (the InterstitialPage is self-owned, it deletes itself when hidden). 286 // (the InterstitialPage is self-owned, it deletes itself when hidden).
285 InterstitialPageImpl* interstitial_page_; 287 InterstitialPageImpl* interstitial_page_;
286 288
287 content::NotificationRegistrar registrar_; 289 content::NotificationRegistrar registrar_;
288 290
289 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager); 291 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManager);
290 }; 292 };
291 293
292 #endif // CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_ 294 #endif // CONTENT_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/tab_contents/popup_menu_helper_mac.mm ('k') | content/browser/tab_contents/render_view_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698