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

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 nits 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 the ID of its SiteInstance is |site_instance_id|. Used
207 // with FrameTree::ForEach.
208 bool EnableSuddenTermination(int32 site_instance_id,
209 FrameTreeNode* frame_tree_node) {
210 if (frame_tree_node->current_frame_host()->GetSiteInstance()->GetId()
211 == site_instance_id) {
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|. Used with FrameTree::ForEach.
221 bool SuddenTerminationAllowed(bool* sudden_termination_allowed,
222 FrameTreeNode* frame_tree_node) {
223 if (frame_tree_node->current_frame_host()->SuddenTerminationAllowed())
224 return true;
225 *sudden_termination_allowed = false;
226 return false;
227 }
228
205 } // namespace 229 } // namespace
206 230
207 WebContents* WebContents::Create(const WebContents::CreateParams& params) { 231 WebContents* WebContents::Create(const WebContents::CreateParams& params) {
208 return WebContentsImpl::CreateWithOpener( 232 return WebContentsImpl::CreateWithOpener(
209 params, static_cast<WebContentsImpl*>(params.opener)); 233 params, static_cast<WebContentsImpl*>(params.opener));
210 } 234 }
211 235
212 WebContents* WebContents::CreateWithSessionStorage( 236 WebContents* WebContents::CreateWithSessionStorage(
213 const WebContents::CreateParams& params, 237 const WebContents::CreateParams& params,
214 const SessionStorageNamespaceMap& session_storage_namespace_map) { 238 const SessionStorageNamespaceMap& session_storage_namespace_map) {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 if (view_) 658 if (view_)
635 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 659 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
636 } 660 }
637 } 661 }
638 662
639 RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { 663 RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
640 RenderViewHostImpl* host = GetRenderManager()->current_host(); 664 RenderViewHostImpl* host = GetRenderManager()->current_host();
641 return host ? host->GetProcess() : NULL; 665 return host ? host->GetProcess() : NULL;
642 } 666 }
643 667
644 RenderFrameHost* WebContentsImpl::GetMainFrame() { 668 RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
645 return frame_tree_.root()->current_frame_host(); 669 return frame_tree_.root()->current_frame_host();
646 } 670 }
647 671
648 RenderFrameHost* WebContentsImpl::GetFocusedFrame() { 672 RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
649 if (!frame_tree_.GetFocusedFrame()) 673 if (!frame_tree_.GetFocusedFrame())
650 return NULL; 674 return NULL;
651 return frame_tree_.GetFocusedFrame()->current_frame_host(); 675 return frame_tree_.GetFocusedFrame()->current_frame_host();
652 } 676 }
653 677
654 void WebContentsImpl::ForEachFrame( 678 void WebContentsImpl::ForEachFrame(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 } 799 }
776 800
777 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { 801 bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
778 return accessibility_mode_ == AccessibilityModeComplete; 802 return accessibility_mode_ == AccessibilityModeComplete;
779 } 803 }
780 804
781 #if defined(OS_WIN) 805 #if defined(OS_WIN)
782 void WebContentsImpl::SetParentNativeViewAccessible( 806 void WebContentsImpl::SetParentNativeViewAccessible(
783 gfx::NativeViewAccessible accessible_parent) { 807 gfx::NativeViewAccessible accessible_parent) {
784 accessible_parent_ = accessible_parent; 808 accessible_parent_ = accessible_parent;
785 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); 809 RenderFrameHostImpl* rfh = GetMainFrame();
786 if (rfh) 810 if (rfh)
787 rfh->SetParentNativeViewAccessible(accessible_parent); 811 rfh->SetParentNativeViewAccessible(accessible_parent);
788 } 812 }
789 #endif 813 #endif
790 814
791 const base::string16& WebContentsImpl::GetTitle() const { 815 const base::string16& WebContentsImpl::GetTitle() const {
792 // Transient entries take precedence. They are used for interstitial pages 816 // Transient entries take precedence. They are used for interstitial pages
793 // that are shown on top of existing pages. 817 // that are shown on top of existing pages.
794 NavigationEntry* entry = controller_.GetTransientEntry(); 818 NavigationEntry* entry = controller_.GetTransientEntry();
795 std::string accept_languages = 819 std::string accept_languages =
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 } 1128 }
1105 1129
1106 void WebContentsImpl::WasUnOccluded() { 1130 void WebContentsImpl::WasUnOccluded() {
1107 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { 1131 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1108 if (view) 1132 if (view)
1109 view->WasUnOccluded(); 1133 view->WasUnOccluded();
1110 } 1134 }
1111 } 1135 }
1112 1136
1113 bool WebContentsImpl::NeedToFireBeforeUnload() { 1137 bool WebContentsImpl::NeedToFireBeforeUnload() {
1138 bool sudden_termination_allowed = true;
1139 frame_tree_.ForEach(base::Bind(
1140 &SuddenTerminationAllowed, &sudden_termination_allowed));
1114 // TODO(creis): Should we fire even for interstitial pages? 1141 // TODO(creis): Should we fire even for interstitial pages?
1115 return WillNotifyDisconnection() && 1142 return WillNotifyDisconnection() &&
1116 !ShowingInterstitialPage() && 1143 !ShowingInterstitialPage() &&
1117 !static_cast<RenderViewHostImpl*>( 1144 !sudden_termination_allowed;
1118 GetRenderViewHost())->SuddenTerminationAllowed();
1119 } 1145 }
1120 1146
1121 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { 1147 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1122 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload( 1148 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
1123 for_cross_site_transition);
1124 } 1149 }
1125 1150
1126 void WebContentsImpl::Stop() { 1151 void WebContentsImpl::Stop() {
1127 GetRenderManager()->Stop(); 1152 GetRenderManager()->Stop();
1128 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); 1153 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
1129 } 1154 }
1130 1155
1131 WebContents* WebContentsImpl::Clone() { 1156 WebContents* WebContentsImpl::Clone() {
1132 // We use our current SiteInstance since the cloned entry will use it anyway. 1157 // 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 1158 // 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. 1372 // Notify the delegate if an embedded fullscreen widget was focused.
1348 if (delegate_ && render_widget_host && 1373 if (delegate_ && render_widget_host &&
1349 delegate_->EmbedsFullscreenWidget() && 1374 delegate_->EmbedsFullscreenWidget() &&
1350 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) 1375 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView())
1351 delegate_->WebContentsFocused(this); 1376 delegate_->WebContentsFocused(this);
1352 } 1377 }
1353 1378
1354 void WebContentsImpl::RenderWidgetWasResized( 1379 void WebContentsImpl::RenderWidgetWasResized(
1355 RenderWidgetHostImpl* render_widget_host, 1380 RenderWidgetHostImpl* render_widget_host,
1356 bool width_changed) { 1381 bool width_changed) {
1357 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); 1382 RenderFrameHostImpl* rfh = GetMainFrame();
1358 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) 1383 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
1359 return; 1384 return;
1360 1385
1361 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 1386 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1362 MainFrameWasResized(width_changed)); 1387 MainFrameWasResized(width_changed));
1363 } 1388 }
1364 1389
1365 bool WebContentsImpl::PreHandleKeyboardEvent( 1390 bool WebContentsImpl::PreHandleKeyboardEvent(
1366 const NativeWebKeyboardEvent& event, 1391 const NativeWebKeyboardEvent& event,
1367 bool* is_keyboard_shortcut) { 1392 bool* is_keyboard_shortcut) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 if (BrowserPluginGuest::IsGuest(new_contents)) 1829 if (BrowserPluginGuest::IsGuest(new_contents))
1805 return new_contents; 1830 return new_contents;
1806 1831
1807 if (!new_contents->GetRenderProcessHost()->HasConnection() || 1832 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1808 !new_contents->GetRenderViewHost()->GetView()) 1833 !new_contents->GetRenderViewHost()->GetView())
1809 return NULL; 1834 return NULL;
1810 1835
1811 // Resume blocked requests for both the RenderViewHost and RenderFrameHost. 1836 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
1812 // TODO(brettw): It seems bogus to reach into here and initialize the host. 1837 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1813 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init(); 1838 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1814 static_cast<RenderFrameHostImpl*>(new_contents->GetMainFrame())->Init(); 1839 new_contents->GetMainFrame()->Init();
1815 1840
1816 return new_contents; 1841 return new_contents;
1817 } 1842 }
1818 1843
1819 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { 1844 RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1820 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); 1845 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1821 if (iter == pending_widget_views_.end()) { 1846 if (iter == pending_widget_views_.end()) {
1822 DCHECK(false); 1847 DCHECK(false);
1823 return NULL; 1848 return NULL;
1824 } 1849 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 delegate_->MoveValidationMessage(this, anchor_in_root_view); 1946 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1922 } 1947 }
1923 1948
1924 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { 1949 void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1925 if (browser_plugin_embedder_) 1950 if (browser_plugin_embedder_)
1926 browser_plugin_embedder_->DidSendScreenRects(); 1951 browser_plugin_embedder_->DidSendScreenRects();
1927 } 1952 }
1928 1953
1929 BrowserAccessibilityManager* 1954 BrowserAccessibilityManager*
1930 WebContentsImpl::GetRootBrowserAccessibilityManager() { 1955 WebContentsImpl::GetRootBrowserAccessibilityManager() {
1931 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); 1956 RenderFrameHostImpl* rfh = GetMainFrame();
1932 return rfh ? rfh->browser_accessibility_manager() : NULL; 1957 return rfh ? rfh->browser_accessibility_manager() : NULL;
1933 } 1958 }
1934 1959
1935 BrowserAccessibilityManager* 1960 BrowserAccessibilityManager*
1936 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { 1961 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
1937 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(GetMainFrame()); 1962 RenderFrameHostImpl* rfh = GetMainFrame();
1938 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL; 1963 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : NULL;
1939 } 1964 }
1940 1965
1941 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { 1966 void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
1942 const gfx::Size old_size = GetPreferredSize(); 1967 const gfx::Size old_size = GetPreferredSize();
1943 preferred_size_ = pref_size; 1968 preferred_size_ = pref_size;
1944 OnPreferredSizeChanged(old_size); 1969 OnPreferredSizeChanged(old_size);
1945 } 1970 }
1946 1971
1947 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { 1972 void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
(...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after
4088 // Ignore renderer unresponsive event if debugger is attached to the tab 4113 // Ignore renderer unresponsive event if debugger is attached to the tab
4089 // since the event may be a result of the renderer sitting on a breakpoint. 4114 // since the event may be a result of the renderer sitting on a breakpoint.
4090 // See http://crbug.com/65458 4115 // See http://crbug.com/65458
4091 if (DevToolsAgentHost::IsDebuggerAttached(this)) 4116 if (DevToolsAgentHost::IsDebuggerAttached(this))
4092 return; 4117 return;
4093 4118
4094 if (rfhi->IsWaitingForBeforeUnloadACK() || 4119 if (rfhi->IsWaitingForBeforeUnloadACK() ||
4095 rfhi->IsWaitingForUnloadACK()) { 4120 rfhi->IsWaitingForUnloadACK()) {
4096 // Hang occurred while firing the beforeunload/unload handler. 4121 // Hang occurred while firing the beforeunload/unload handler.
4097 // Pretend the handler fired so tab closing continues as if it had. 4122 // Pretend the handler fired so tab closing continues as if it had.
4098 rvhi->set_sudden_termination_allowed(true); 4123 frame_tree_.ForEach(base::Bind(
4124 &EnableSuddenTermination, rvhi->GetSiteInstance()->GetId()));
4099 4125
4100 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) 4126 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
4101 return; 4127 return;
4102 4128
4103 // If the tab hangs in the beforeunload/unload handler there's really 4129 // If the tab hangs in the beforeunload/unload handler there's really
4104 // nothing we can do to recover. If the hang is in the beforeunload handler, 4130 // nothing we can do to recover. If the hang is in the beforeunload handler,
4105 // pretend the beforeunload listeners have all fired and allow the delegate 4131 // pretend the beforeunload listeners have all fired and allow the delegate
4106 // to continue closing; the user will not have the option of cancelling the 4132 // to continue closing; the user will not have the option of cancelling the
4107 // close. Otherwise, pretend the unload listeners have all fired and close 4133 // close. Otherwise, pretend the unload listeners have all fired and close
4108 // the tab. 4134 // the tab.
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
4516 node->render_manager()->ResumeResponseDeferredAtStart(); 4542 node->render_manager()->ResumeResponseDeferredAtStart();
4517 } 4543 }
4518 4544
4519 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4545 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4520 force_disable_overscroll_content_ = force_disable; 4546 force_disable_overscroll_content_ = force_disable;
4521 if (view_) 4547 if (view_)
4522 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4548 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4523 } 4549 }
4524 4550
4525 } // namespace content 4551 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/browser/web_contents/web_contents_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698