| OLD | NEW |
| 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 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( | 1842 RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( |
| 1843 RenderWidgetHostImpl* receiving_widget) { | 1843 RenderWidgetHostImpl* receiving_widget) { |
| 1844 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) | 1844 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) |
| 1845 return receiving_widget; | 1845 return receiving_widget; |
| 1846 | 1846 |
| 1847 // Events for widgets other than the main frame (e.g., popup menus) should be | 1847 // Events for widgets other than the main frame (e.g., popup menus) should be |
| 1848 // forwarded directly to the widget they arrived on. | 1848 // forwarded directly to the widget they arrived on. |
| 1849 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) | 1849 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) |
| 1850 return receiving_widget; | 1850 return receiving_widget; |
| 1851 | 1851 |
| 1852 WebContentsImpl* focused_contents = GetFocusedWebContents(); |
| 1853 |
| 1854 // If the focused WebContents is showing an interstitial, return the |
| 1855 // interstitial's widget. |
| 1856 if (focused_contents->ShowingInterstitialPage()) { |
| 1857 return static_cast<RenderFrameHostImpl*>( |
| 1858 focused_contents->GetRenderManager() |
| 1859 ->interstitial_page() |
| 1860 ->GetMainFrame()) |
| 1861 ->GetRenderWidgetHost(); |
| 1862 } |
| 1863 |
| 1852 FrameTreeNode* focused_frame = | 1864 FrameTreeNode* focused_frame = |
| 1853 GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); | 1865 focused_contents->frame_tree_.GetFocusedFrame(); |
| 1866 |
| 1854 if (!focused_frame) | 1867 if (!focused_frame) |
| 1855 return receiving_widget; | 1868 return receiving_widget; |
| 1856 | 1869 |
| 1857 // The view may be null if a subframe's renderer process has crashed while | 1870 // The view may be null if a subframe's renderer process has crashed while |
| 1858 // the subframe has focus. Drop the event in that case. Do not give | 1871 // the subframe has focus. Drop the event in that case. Do not give |
| 1859 // it to the main frame, so that the user doesn't unexpectedly type into the | 1872 // it to the main frame, so that the user doesn't unexpectedly type into the |
| 1860 // wrong frame if a focused subframe renderer crashes while they type. | 1873 // wrong frame if a focused subframe renderer crashes while they type. |
| 1861 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); | 1874 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 1862 if (!view) | 1875 if (!view) |
| 1863 return nullptr; | 1876 return nullptr; |
| 1864 | 1877 |
| 1865 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); | 1878 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
| 1866 } | 1879 } |
| 1867 | 1880 |
| 1868 RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { | 1881 RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { |
| 1869 return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost(); | 1882 WebContentsImpl* focused_web_contents = GetFocusedWebContents(); |
| 1883 |
| 1884 if (focused_web_contents->ShowingInterstitialPage()) { |
| 1885 return static_cast<RenderFrameHostImpl*>( |
| 1886 focused_web_contents->GetRenderManager() |
| 1887 ->interstitial_page() |
| 1888 ->GetMainFrame()) |
| 1889 ->GetRenderWidgetHost(); |
| 1890 } |
| 1891 |
| 1892 return focused_web_contents->GetMainFrame()->GetRenderWidgetHost(); |
| 1870 } | 1893 } |
| 1871 | 1894 |
| 1872 void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { | 1895 void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { |
| 1873 // This method is being called to enter renderer-initiated fullscreen mode. | 1896 // This method is being called to enter renderer-initiated fullscreen mode. |
| 1874 // Make sure any existing fullscreen widget is shut down first. | 1897 // Make sure any existing fullscreen widget is shut down first. |
| 1875 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); | 1898 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
| 1876 if (widget_view) { | 1899 if (widget_view) { |
| 1877 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) | 1900 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 1878 ->ShutdownAndDestroyWidget(true); | 1901 ->ShutdownAndDestroyWidget(true); |
| 1879 } | 1902 } |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2666 // Cancel any visible dialogs so that they don't interfere with the | 2689 // Cancel any visible dialogs so that they don't interfere with the |
| 2667 // interstitial. | 2690 // interstitial. |
| 2668 CancelActiveAndPendingDialogs(); | 2691 CancelActiveAndPendingDialogs(); |
| 2669 | 2692 |
| 2670 for (auto& observer : observers_) | 2693 for (auto& observer : observers_) |
| 2671 observer.DidAttachInterstitialPage(); | 2694 observer.DidAttachInterstitialPage(); |
| 2672 | 2695 |
| 2673 // Stop the throbber if needed while the interstitial page is shown. | 2696 // Stop the throbber if needed while the interstitial page is shown. |
| 2674 if (frame_tree_.IsLoading()) | 2697 if (frame_tree_.IsLoading()) |
| 2675 LoadingStateChanged(true, true, nullptr); | 2698 LoadingStateChanged(true, true, nullptr); |
| 2699 |
| 2700 // Connect to outer WebContents if necessary. |
| 2701 if (node_.OuterContentsFrameTreeNode()) { |
| 2702 if (GetRenderManager()->GetProxyToOuterDelegate()) { |
| 2703 DCHECK( |
| 2704 static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView()) |
| 2705 ->IsRenderWidgetHostViewChildFrame()); |
| 2706 RenderWidgetHostViewChildFrame* view = |
| 2707 static_cast<RenderWidgetHostViewChildFrame*>( |
| 2708 interstitial_page->GetView()); |
| 2709 GetRenderManager()->SetRWHViewForInnerContents(view); |
| 2710 } |
| 2711 } |
| 2676 } | 2712 } |
| 2677 | 2713 |
| 2678 void WebContentsImpl::DidProceedOnInterstitial() { | 2714 void WebContentsImpl::DidProceedOnInterstitial() { |
| 2679 // The interstitial page should no longer be pausing the throbber. | 2715 // The interstitial page should no longer be pausing the throbber. |
| 2680 DCHECK(!(ShowingInterstitialPage() && | 2716 DCHECK(!(ShowingInterstitialPage() && |
| 2681 GetRenderManager()->interstitial_page()->pause_throbber())); | 2717 GetRenderManager()->interstitial_page()->pause_throbber())); |
| 2682 | 2718 |
| 2683 // Restart the throbber now that the interstitial page no longer pauses it. | 2719 // Restart the throbber now that the interstitial page no longer pauses it. |
| 2684 if (ShowingInterstitialPage() && frame_tree_.IsLoading()) | 2720 if (ShowingInterstitialPage() && frame_tree_.IsLoading()) |
| 2685 LoadingStateChanged(true, true, nullptr); | 2721 LoadingStateChanged(true, true, nullptr); |
| 2686 } | 2722 } |
| 2687 | 2723 |
| 2688 void WebContentsImpl::DetachInterstitialPage() { | 2724 void WebContentsImpl::DetachInterstitialPage() { |
| 2725 // Disconnect from outer WebContents if necessary. |
| 2726 if (node_.OuterContentsFrameTreeNode()) { |
| 2727 if (GetRenderManager()->GetProxyToOuterDelegate()) { |
| 2728 DCHECK(static_cast<RenderWidgetHostViewBase*>( |
| 2729 GetRenderManager()->current_frame_host()->GetView()) |
| 2730 ->IsRenderWidgetHostViewChildFrame()); |
| 2731 RenderWidgetHostViewChildFrame* view = |
| 2732 static_cast<RenderWidgetHostViewChildFrame*>( |
| 2733 GetRenderManager()->current_frame_host()->GetView()); |
| 2734 GetRenderManager()->SetRWHViewForInnerContents(view); |
| 2735 } |
| 2736 } |
| 2737 |
| 2689 bool interstitial_pausing_throbber = | 2738 bool interstitial_pausing_throbber = |
| 2690 ShowingInterstitialPage() && | 2739 ShowingInterstitialPage() && |
| 2691 GetRenderManager()->interstitial_page()->pause_throbber(); | 2740 GetRenderManager()->interstitial_page()->pause_throbber(); |
| 2692 if (ShowingInterstitialPage()) | 2741 if (ShowingInterstitialPage()) |
| 2693 GetRenderManager()->remove_interstitial_page(); | 2742 GetRenderManager()->remove_interstitial_page(); |
| 2694 for (auto& observer : observers_) | 2743 for (auto& observer : observers_) |
| 2695 observer.DidDetachInterstitialPage(); | 2744 observer.DidDetachInterstitialPage(); |
| 2696 | 2745 |
| 2697 // Restart the throbber if needed now that the interstitial page is going | 2746 // Restart the throbber if needed now that the interstitial page is going |
| 2698 // away. | 2747 // away. |
| (...skipping 2058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4757 // and focus this contents to activate it. | 4806 // and focus this contents to activate it. |
| 4758 if (old_contents) | 4807 if (old_contents) |
| 4759 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); | 4808 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); |
| 4760 | 4809 |
| 4761 // Make sure the outer web contents knows our frame is focused. Otherwise, the | 4810 // Make sure the outer web contents knows our frame is focused. Otherwise, the |
| 4762 // outer renderer could have the element before or after the frame element | 4811 // outer renderer could have the element before or after the frame element |
| 4763 // focused which would return early without actually advancing focus. | 4812 // focused which would return early without actually advancing focus. |
| 4764 if (GetRenderManager()->GetProxyToOuterDelegate()) | 4813 if (GetRenderManager()->GetProxyToOuterDelegate()) |
| 4765 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame(); | 4814 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame(); |
| 4766 | 4815 |
| 4767 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); | 4816 if (ShowingInterstitialPage()) { |
| 4817 static_cast<RenderFrameHostImpl*>( |
| 4818 GetRenderManager()->interstitial_page()->GetMainFrame()) |
| 4819 ->GetRenderWidgetHost() |
| 4820 ->SetPageFocus(true); |
| 4821 } else { |
| 4822 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); |
| 4823 } |
| 4768 GetOutermostWebContents()->node_.SetFocusedWebContents(this); | 4824 GetOutermostWebContents()->node_.SetFocusedWebContents(this); |
| 4769 } | 4825 } |
| 4770 | 4826 |
| 4771 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, | 4827 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| 4772 SiteInstance* source) { | 4828 SiteInstance* source) { |
| 4773 // The PDF plugin still runs as a BrowserPlugin and must go through the | 4829 // The PDF plugin still runs as a BrowserPlugin and must go through the |
| 4774 // input redirection mechanism. It must not become focused direcly. | 4830 // input redirection mechanism. It must not become focused direcly. |
| 4775 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) { | 4831 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) { |
| 4776 frame_tree_.SetFocusedFrame(node, source); | 4832 frame_tree_.SetFocusedFrame(node, source); |
| 4777 return; | 4833 return; |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5418 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); | 5474 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); |
| 5419 if (!render_view_host) | 5475 if (!render_view_host) |
| 5420 continue; | 5476 continue; |
| 5421 render_view_host_set.insert(render_view_host); | 5477 render_view_host_set.insert(render_view_host); |
| 5422 } | 5478 } |
| 5423 for (RenderViewHost* render_view_host : render_view_host_set) | 5479 for (RenderViewHost* render_view_host : render_view_host_set) |
| 5424 render_view_host->OnWebkitPreferencesChanged(); | 5480 render_view_host->OnWebkitPreferencesChanged(); |
| 5425 } | 5481 } |
| 5426 | 5482 |
| 5427 } // namespace content | 5483 } // namespace content |
| OLD | NEW |