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

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

Issue 2797473005: Fix interstitials on OOPIF-based guests. (Closed)
Patch Set: addressing comments Created 3 years, 8 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <utility> 10 #include <utility>
(...skipping 1907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( 1918 RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1919 RenderWidgetHostImpl* receiving_widget) { 1919 RenderWidgetHostImpl* receiving_widget) {
1920 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) 1920 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
1921 return receiving_widget; 1921 return receiving_widget;
1922 1922
1923 // Events for widgets other than the main frame (e.g., popup menus) should be 1923 // Events for widgets other than the main frame (e.g., popup menus) should be
1924 // forwarded directly to the widget they arrived on. 1924 // forwarded directly to the widget they arrived on.
1925 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) 1925 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1926 return receiving_widget; 1926 return receiving_widget;
1927 1927
1928 FrameTreeNode* focused_frame = nullptr;
1929 WebContentsImpl* focused_contents = GetFocusedWebContents();
1930
1931 // If the focused WebContents is showing an interstitial, return the
1932 // interstitial's widget.
1933 if (focused_contents->ShowingInterstitialPage()) {
1934 return static_cast<RenderFrameHostImpl*>(
1935 focused_contents->GetRenderManager()
1936 ->interstitial_page()
1937 ->GetMainFrame())
1938 ->GetRenderWidgetHost();
1939 }
1940
1928 // If the focused WebContents is a guest WebContents, then get the focused 1941 // If the focused WebContents is a guest WebContents, then get the focused
1929 // frame in the embedder WebContents instead. 1942 // frame in the embedder WebContents instead.
1930 FrameTreeNode* focused_frame = nullptr;
1931 WebContentsImpl* focused_contents = GetFocusedWebContents();
1932 if (focused_contents->browser_plugin_guest_ && 1943 if (focused_contents->browser_plugin_guest_ &&
1933 !GuestMode::IsCrossProcessFrameGuest(focused_contents)) { 1944 !GuestMode::IsCrossProcessFrameGuest(focused_contents)) {
1934 focused_frame = frame_tree_.GetFocusedFrame(); 1945 focused_frame = frame_tree_.GetFocusedFrame();
1935 } else { 1946 } else {
1936 focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); 1947 focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
1937 } 1948 }
1949
1938 if (!focused_frame) 1950 if (!focused_frame)
1939 return receiving_widget; 1951 return receiving_widget;
1940 1952
1941 // The view may be null if a subframe's renderer process has crashed while 1953 // The view may be null if a subframe's renderer process has crashed while
1942 // the subframe has focus. Drop the event in that case. Do not give 1954 // the subframe has focus. Drop the event in that case. Do not give
1943 // it to the main frame, so that the user doesn't unexpectedly type into the 1955 // it to the main frame, so that the user doesn't unexpectedly type into the
1944 // wrong frame if a focused subframe renderer crashes while they type. 1956 // wrong frame if a focused subframe renderer crashes while they type.
1945 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); 1957 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1946 if (!view) 1958 if (!view)
1947 return nullptr; 1959 return nullptr;
1948 1960
1949 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); 1961 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
1950 } 1962 }
1951 1963
1952 RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { 1964 RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
1965 WebContentsImpl* focused_web_contents = GetFocusedWebContents();
1966
1967 if (focused_web_contents->ShowingInterstitialPage()) {
1968 return static_cast<RenderFrameHostImpl*>(
1969 focused_web_contents->GetRenderManager()
1970 ->interstitial_page()
1971 ->GetMainFrame())
1972 ->GetRenderWidgetHost();
1973 }
1974
1953 return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost(); 1975 return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost();
Avi (use Gerrit) 2017/04/08 00:30:12 might as well use focused_web_contents here
lfg 2017/04/10 17:33:42 Done.
1954 } 1976 }
1955 1977
1956 void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { 1978 void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1957 // This method is being called to enter renderer-initiated fullscreen mode. 1979 // This method is being called to enter renderer-initiated fullscreen mode.
1958 // Make sure any existing fullscreen widget is shut down first. 1980 // Make sure any existing fullscreen widget is shut down first.
1959 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); 1981 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1960 if (widget_view) { 1982 if (widget_view) {
1961 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) 1983 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1962 ->ShutdownAndDestroyWidget(true); 1984 ->ShutdownAndDestroyWidget(true);
1963 } 1985 }
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
2750 // Cancel any visible dialogs so that they don't interfere with the 2772 // Cancel any visible dialogs so that they don't interfere with the
2751 // interstitial. 2773 // interstitial.
2752 CancelActiveAndPendingDialogs(); 2774 CancelActiveAndPendingDialogs();
2753 2775
2754 for (auto& observer : observers_) 2776 for (auto& observer : observers_)
2755 observer.DidAttachInterstitialPage(); 2777 observer.DidAttachInterstitialPage();
2756 2778
2757 // Stop the throbber if needed while the interstitial page is shown. 2779 // Stop the throbber if needed while the interstitial page is shown.
2758 if (frame_tree_.IsLoading()) 2780 if (frame_tree_.IsLoading())
2759 LoadingStateChanged(true, true, nullptr); 2781 LoadingStateChanged(true, true, nullptr);
2782
2783 // Connect to outer WebContents if necessary.
2784 if (node_.OuterContentsFrameTreeNode()) {
2785 if (GetRenderManager()->GetProxyToOuterDelegate()) {
2786 DCHECK(
2787 static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView())
2788 ->IsRenderWidgetHostViewChildFrame());
2789 RenderWidgetHostViewChildFrame* view =
2790 static_cast<RenderWidgetHostViewChildFrame*>(
2791 interstitial_page->GetView());
2792 GetRenderManager()->SetRWHViewForInnerContents(view);
2793 }
2794 }
2760 } 2795 }
2761 2796
2762 void WebContentsImpl::DidProceedOnInterstitial() { 2797 void WebContentsImpl::DidProceedOnInterstitial() {
2763 // The interstitial page should no longer be pausing the throbber. 2798 // The interstitial page should no longer be pausing the throbber.
2764 DCHECK(!(ShowingInterstitialPage() && 2799 DCHECK(!(ShowingInterstitialPage() &&
2765 GetRenderManager()->interstitial_page()->pause_throbber())); 2800 GetRenderManager()->interstitial_page()->pause_throbber()));
2766 2801
2767 // Restart the throbber now that the interstitial page no longer pauses it. 2802 // Restart the throbber now that the interstitial page no longer pauses it.
2768 if (ShowingInterstitialPage() && frame_tree_.IsLoading()) 2803 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2769 LoadingStateChanged(true, true, nullptr); 2804 LoadingStateChanged(true, true, nullptr);
2770 } 2805 }
2771 2806
2772 void WebContentsImpl::DetachInterstitialPage() { 2807 void WebContentsImpl::DetachInterstitialPage() {
2808 // Disconnect from outer WebContents if necessary.
2809 if (node_.OuterContentsFrameTreeNode()) {
2810 if (GetRenderManager()->GetProxyToOuterDelegate()) {
2811 DCHECK(static_cast<RenderWidgetHostViewBase*>(
2812 GetRenderManager()->current_frame_host()->GetView())
2813 ->IsRenderWidgetHostViewChildFrame());
2814 RenderWidgetHostViewChildFrame* view =
2815 static_cast<RenderWidgetHostViewChildFrame*>(
2816 GetRenderManager()->current_frame_host()->GetView());
2817 GetRenderManager()->SetRWHViewForInnerContents(view);
2818 }
2819 }
2820
2773 bool interstitial_pausing_throbber = 2821 bool interstitial_pausing_throbber =
2774 ShowingInterstitialPage() && 2822 ShowingInterstitialPage() &&
2775 GetRenderManager()->interstitial_page()->pause_throbber(); 2823 GetRenderManager()->interstitial_page()->pause_throbber();
2776 if (ShowingInterstitialPage()) 2824 if (ShowingInterstitialPage())
2777 GetRenderManager()->remove_interstitial_page(); 2825 GetRenderManager()->remove_interstitial_page();
2778 for (auto& observer : observers_) 2826 for (auto& observer : observers_)
2779 observer.DidDetachInterstitialPage(); 2827 observer.DidDetachInterstitialPage();
2780 2828
2781 // Restart the throbber if needed now that the interstitial page is going 2829 // Restart the throbber if needed now that the interstitial page is going
2782 // away. 2830 // away.
(...skipping 2040 matching lines...) Expand 10 before | Expand all | Expand 10 after
4823 // and focus this contents to activate it. 4871 // and focus this contents to activate it.
4824 if (old_contents) 4872 if (old_contents)
4825 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); 4873 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
4826 4874
4827 // Make sure the outer web contents knows our frame is focused. Otherwise, the 4875 // Make sure the outer web contents knows our frame is focused. Otherwise, the
4828 // outer renderer could have the element before or after the frame element 4876 // outer renderer could have the element before or after the frame element
4829 // focused which would return early without actually advancing focus. 4877 // focused which would return early without actually advancing focus.
4830 if (GetRenderManager()->GetProxyToOuterDelegate()) 4878 if (GetRenderManager()->GetProxyToOuterDelegate())
4831 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame(); 4879 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame();
4832 4880
4833 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); 4881 if (ShowingInterstitialPage()) {
4882 static_cast<RenderFrameHostImpl*>(
4883 GetRenderManager()->interstitial_page()->GetMainFrame())
4884 ->GetRenderWidgetHost()
4885 ->SetPageFocus(true);
4886 } else {
4887 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
4888 }
4834 GetOutermostWebContents()->node_.SetFocusedWebContents(this); 4889 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
4835 } 4890 }
4836 4891
4837 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, 4892 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
4838 SiteInstance* source) { 4893 SiteInstance* source) {
4839 // The PDF plugin still runs as a BrowserPlugin and must go through the 4894 // The PDF plugin still runs as a BrowserPlugin and must go through the
4840 // input redirection mechanism. It must not become focused direcly. 4895 // input redirection mechanism. It must not become focused direcly.
4841 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) { 4896 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
4842 frame_tree_.SetFocusedFrame(node, source); 4897 frame_tree_.SetFocusedFrame(node, source);
4843 if (GetFocusedWebContents() != this) 4898 if (GetFocusedWebContents() != this)
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
5514 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); 5569 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
5515 if (!render_view_host) 5570 if (!render_view_host)
5516 continue; 5571 continue;
5517 render_view_host_set.insert(render_view_host); 5572 render_view_host_set.insert(render_view_host);
5518 } 5573 }
5519 for (RenderViewHost* render_view_host : render_view_host_set) 5574 for (RenderViewHost* render_view_host : render_view_host_set)
5520 render_view_host->OnWebkitPreferencesChanged(); 5575 render_view_host->OnWebkitPreferencesChanged();
5521 } 5576 }
5522 5577
5523 } // namespace content 5578 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/public/test/browser_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698