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

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 857213003: Refactor sudden termination (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Charlie's comments Created 5 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
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 #include "content/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 ->render_manager() 195 ->render_manager()
196 ->GetRenderWidgetHostView(); 196 ->GetRenderWidgetHostView();
197 set->insert(rwhv); 197 set->insert(rwhv);
198 } 198 }
199 199
200 void SetAccessibilityModeOnFrame(AccessibilityMode mode, 200 void SetAccessibilityModeOnFrame(AccessibilityMode mode,
201 RenderFrameHost* frame_host) { 201 RenderFrameHost* frame_host) {
202 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode); 202 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
203 } 203 }
204 204
205 // Enable sudden termination for the current RenderFrameHost of
206 // |frame_tree_node| if its RenderViewHost is |render_view_host|.
207 // Used with FrameTree::ForEach.
208 bool EnableSuddenTermination(RenderViewHost* render_view_host,
clamy 2015/02/02 16:16:28 Another possibility would be to provide two functi
Charlie Reis 2015/02/02 20:14:50 What you have is fine. We probably shouldn't add
clamy 2015/02/03 12:54:02 Acknowledged (that's why I did not do it in the fi
209 FrameTreeNode* frame_tree_node) {
210 if (frame_tree_node->current_frame_host()->render_view_host()
211 == render_view_host) {
Charlie Reis 2015/02/02 20:14:50 Let's pass in the SiteInstance rather than the RVH
clamy 2015/02/03 12:54:03 Done.
212 frame_tree_node->current_frame_host()
213 ->set_override_sudden_termination_status(true);
214 }
215 return true;
216 }
217
218 // Returns false and sets |sudden_termination_allowed| to false if sudden
219 // termination is not allowed for the current RenderFrameHost of
220 // |frame_tree_node| (if its RenderViewHost is |render_view_host|). Used with
221 // FrameTree::ForEach.
222 bool SuddenTerminationAllowed(bool* sudden_termination_allowed,
223 RenderViewHost* render_view_host,
Charlie Reis 2015/02/02 20:14:50 Same: Use SiteInstance here.
clamy 2015/02/03 12:54:03 Done.
224 FrameTreeNode* frame_tree_node) {
225 if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed() ||
226 frame_tree_node->current_frame_host()->render_view_host()
227 != render_view_host) {
228 return true;
229 }
230 *sudden_termination_allowed = false;
231 return false;
232 }
233
205 } // namespace 234 } // namespace
206 235
207 WebContents* WebContents::Create(const WebContents::CreateParams& params) { 236 WebContents* WebContents::Create(const WebContents::CreateParams& params) {
208 return WebContentsImpl::CreateWithOpener( 237 return WebContentsImpl::CreateWithOpener(
209 params, static_cast<WebContentsImpl*>(params.opener)); 238 params, static_cast<WebContentsImpl*>(params.opener));
210 } 239 }
211 240
212 WebContents* WebContents::CreateWithSessionStorage( 241 WebContents* WebContents::CreateWithSessionStorage(
213 const WebContents::CreateParams& params, 242 const WebContents::CreateParams& params,
214 const SessionStorageNamespaceMap& session_storage_namespace_map) { 243 const SessionStorageNamespaceMap& session_storage_namespace_map) {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 if (view_) 663 if (view_)
635 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 664 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
636 } 665 }
637 } 666 }
638 667
639 RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { 668 RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
640 RenderViewHostImpl* host = GetRenderManager()->current_host(); 669 RenderViewHostImpl* host = GetRenderManager()->current_host();
641 return host ? host->GetProcess() : NULL; 670 return host ? host->GetProcess() : NULL;
642 } 671 }
643 672
644 RenderFrameHost* WebContentsImpl::GetMainFrame() { 673 RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
645 return frame_tree_.root()->current_frame_host(); 674 return frame_tree_.root()->current_frame_host();
646 } 675 }
647 676
648 RenderFrameHost* WebContentsImpl::GetFocusedFrame() { 677 RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
649 if (!frame_tree_.GetFocusedFrame()) 678 if (!frame_tree_.GetFocusedFrame())
650 return NULL; 679 return NULL;
651 return frame_tree_.GetFocusedFrame()->current_frame_host(); 680 return frame_tree_.GetFocusedFrame()->current_frame_host();
652 } 681 }
653 682
654 void WebContentsImpl::ForEachFrame( 683 void WebContentsImpl::ForEachFrame(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 } 804 }
776 805
777 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { 806 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
778 return accessibility_mode_ == AccessibilityModeComplete; 807 return accessibility_mode_ == AccessibilityModeComplete;
779 } 808 }
780 809
781 #if defined(OS_WIN) 810 #if defined(OS_WIN)
782 void WebContentsImpl::SetParentNativeViewAccessible( 811 void WebContentsImpl::SetParentNativeViewAccessible(
783 gfx::NativeViewAccessible accessible_parent) { 812 gfx::NativeViewAccessible accessible_parent) {
784 accessible_parent_ = accessible_parent; 813 accessible_parent_ = accessible_parent;
785 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); 814 RenderFrameHostImpl* rfh = GetMainFrame();
786 if (rfh) 815 if (rfh)
787 rfh->SetParentNativeViewAccessible(accessible_parent); 816 rfh->SetParentNativeViewAccessible(accessible_parent);
788 } 817 }
789 #endif 818 #endif
790 819
791 const base::string16& WebContentsImpl::GetTitle() const { 820 const base::string16& WebContentsImpl::GetTitle() const {
792 // Transient entries take precedence. They are used for interstitial pages 821 // Transient entries take precedence. They are used for interstitial pages
793 // that are shown on top of existing pages. 822 // that are shown on top of existing pages.
794 NavigationEntry* entry = controller_.GetTransientEntry(); 823 NavigationEntry* entry = controller_.GetTransientEntry();
795 std::string accept_languages = 824 std::string accept_languages =
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 } 1133 }
1105 1134
1106 void WebContentsImpl::WasUnOccluded() { 1135 void WebContentsImpl::WasUnOccluded() {
1107 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { 1136 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1108 if (view) 1137 if (view)
1109 view->WasUnOccluded(); 1138 view->WasUnOccluded();
1110 } 1139 }
1111 } 1140 }
1112 1141
1113 bool WebContentsImpl::NeedToFireBeforeUnload() { 1142 bool WebContentsImpl::NeedToFireBeforeUnload() {
1143 bool sudden_termination_allowed = true;
1144 frame_tree_.ForEach(base::Bind(&SuddenTerminationAllowed,
1145 &sudden_termination_allowed,
1146 GetRenderViewHost()));
1114 // TODO(creis): Should we fire even for interstitial pages? 1147 // TODO(creis): Should we fire even for interstitial pages?
1115 return WillNotifyDisconnection() && 1148 return WillNotifyDisconnection() &&
1116 !ShowingInterstitialPage() && 1149 !ShowingInterstitialPage() &&
1117 !static_cast<RenderViewHostImpl*>( 1150 !sudden_termination_allowed;
1118 GetRenderViewHost())->SuddenTerminationAllowed();
1119 } 1151 }
1120 1152
1121 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { 1153 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1122 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload( 1154 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
1123 for_cross_site_transition);
1124 } 1155 }
1125 1156
1126 void WebContentsImpl::Stop() { 1157 void WebContentsImpl::Stop() {
1127 GetRenderManager()->Stop(); 1158 GetRenderManager()->Stop();
1128 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); 1159 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
1129 } 1160 }
1130 1161
1131 WebContents* WebContentsImpl::Clone() { 1162 WebContents* WebContentsImpl::Clone() {
1132 // We use our current SiteInstance since the cloned entry will use it anyway. 1163 // We use our current SiteInstance since the cloned entry will use it anyway.
1133 // We pass our own opener so that the cloned page can access it if it was 1164 // We pass our own opener so that the cloned page can access it if it was
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 // Notify the delegate if an embedded fullscreen widget was focused. 1378 // Notify the delegate if an embedded fullscreen widget was focused.
1348 if (delegate_ && render_widget_host && 1379 if (delegate_ && render_widget_host &&
1349 delegate_->EmbedsFullscreenWidget() && 1380 delegate_->EmbedsFullscreenWidget() &&
1350 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) 1381 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1351 delegate_->WebContentsFocused(this); 1382 delegate_->WebContentsFocused(this);
1352 } 1383 }
1353 1384
1354 void WebContentsImpl::RenderWidgetWasResized( 1385 void WebContentsImpl::RenderWidgetWasResized(
1355 RenderWidgetHostImpl* render_widget_host, 1386 RenderWidgetHostImpl* render_widget_host,
1356 bool width_changed) { 1387 bool width_changed) {
1357 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); 1388 RenderFrameHostImpl* rfh = GetMainFrame();
1358 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) 1389 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
1359 return; 1390 return;
1360 1391
1361 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 1392 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1362 MainFrameWasResized(width_changed)); 1393 MainFrameWasResized(width_changed));
1363 } 1394 }
1364 1395
1365 bool WebContentsImpl::PreHandleKeyboardEvent( 1396 bool WebContentsImpl::PreHandleKeyboardEvent(
1366 const NativeWebKeyboardEvent& event, 1397 const NativeWebKeyboardEvent& event,
1367 bool* is_keyboard_shortcut) { 1398 bool* is_keyboard_shortcut) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 if (BrowserPluginGuest::IsGuest(new_contents)) 1835 if (BrowserPluginGuest::IsGuest(new_contents))
1805 return new_contents; 1836 return new_contents;
1806 1837
1807 if (!new_contents->GetRenderProcessHost()->HasConnection() || 1838 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1808 !new_contents->GetRenderViewHost()->GetView()) 1839 !new_contents->GetRenderViewHost()->GetView())
1809 return NULL; 1840 return NULL;
1810 1841
1811 // Resume blocked requests for both the RenderViewHost and RenderFrameHost. 1842 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
1812 // TODO(brettw): It seems bogus to reach into here and initialize the host. 1843 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1813 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init(); 1844 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1814 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init(); 1845 new_contents->GetMainFrame()->Init();
1815 1846
1816 return new_contents; 1847 return new_contents;
1817 } 1848 }
1818 1849
1819 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { 1850 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1820 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); 1851 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1821 if (iter == pending_widget_views_.end()) { 1852 if (iter == pending_widget_views_.end()) {
1822 DCHECK(false); 1853 DCHECK(false);
1823 return NULL; 1854 return NULL;
1824 } 1855 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 delegate_->MoveValidationMessage(this, anchor_in_root_view); 1952 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1922 } 1953 }
1923 1954
1924 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { 1955 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1925 if (browser_plugin_embedder_) 1956 if (browser_plugin_embedder_)
1926 browser_plugin_embedder_->DidSendScreenRects(); 1957 browser_plugin_embedder_->DidSendScreenRects();
1927 } 1958 }
1928 1959
1929 BrowserAccessibilityManager* 1960 BrowserAccessibilityManager*
1930 WebContentsImpl::GetRootBrowserAccessibilityManager() { 1961 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1931 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); 1962 RenderFrameHostImpl* rfh = GetMainFrame();
1932 return rfh ? rfh->browser_accessibility_manager() : NULL; 1963 return rfh ? rfh->browser_accessibility_manager() : NULL;
1933 } 1964 }
1934 1965
1935 BrowserAccessibilityManager* 1966 BrowserAccessibilityManager*
1936 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { 1967 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1937 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); 1968 RenderFrameHostImpl* rfh = GetMainFrame();
1938 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL; 1969 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1939 } 1970 }
1940 1971
1941 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { 1972 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
1942 const gfx::Size old_size = GetPreferredSize(); 1973 const gfx::Size old_size = GetPreferredSize();
1943 preferred_size_ = pref_size; 1974 preferred_size_ = pref_size;
1944 OnPreferredSizeChanged(old_size); 1975 OnPreferredSizeChanged(old_size);
1945 } 1976 }
1946 1977
1947 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { 1978 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
(...skipping 2107 matching lines...) Expand 10 before | Expand all | Expand 10 after
4055 // Ignore renderer unresponsive event if debugger is attached to the tab 4086 // Ignore renderer unresponsive event if debugger is attached to the tab
4056 // since the event may be a result of the renderer sitting on a breakpoint. 4087 // since the event may be a result of the renderer sitting on a breakpoint.
4057 // See http://crbug.com/65458 4088 // See http://crbug.com/65458
4058 if (DevToolsAgentHost::IsDebuggerAttached(this)) 4089 if (DevToolsAgentHost::IsDebuggerAttached(this))
4059 return; 4090 return;
4060 4091
4061 if (rfhi->IsWaitingForBeforeUnloadACK() || 4092 if (rfhi->IsWaitingForBeforeUnloadACK() ||
4062 rfhi->IsWaitingForUnloadACK()) { 4093 rfhi->IsWaitingForUnloadACK()) {
4063 // Hang occurred while firing the beforeunload/unload handler. 4094 // Hang occurred while firing the beforeunload/unload handler.
4064 // Pretend the handler fired so tab closing continues as if it had. 4095 // Pretend the handler fired so tab closing continues as if it had.
4065 rvhi->set_sudden_termination_allowed(true); 4096 frame_tree_.ForEach(base::Bind(&EnableSuddenTermination, rvhi));
4066 4097
4067 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) 4098 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
4068 return; 4099 return;
4069 4100
4070 // If the tab hangs in the beforeunload/unload handler there's really 4101 // If the tab hangs in the beforeunload/unload handler there's really
4071 // nothing we can do to recover. If the hang is in the beforeunload handler, 4102 // nothing we can do to recover. If the hang is in the beforeunload handler,
4072 // pretend the beforeunload listeners have all fired and allow the delegate 4103 // pretend the beforeunload listeners have all fired and allow the delegate
4073 // to continue closing; the user will not have the option of cancelling the 4104 // to continue closing; the user will not have the option of cancelling the
4074 // close. Otherwise, pretend the unload listeners have all fired and close 4105 // close. Otherwise, pretend the unload listeners have all fired and close
4075 // the tab. 4106 // the tab.
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
4483 node->render_manager()->ResumeResponseDeferredAtStart(); 4514 node->render_manager()->ResumeResponseDeferredAtStart();
4484 } 4515 }
4485 4516
4486 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4517 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4487 force_disable_overscroll_content_ = force_disable; 4518 force_disable_overscroll_content_ = force_disable;
4488 if (view_) 4519 if (view_)
4489 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4520 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4490 } 4521 }
4491 4522
4492 } // namespace content 4523 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698