| Index: content/browser/web_contents/web_contents_impl.cc
|
| diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
|
| index 11172c31d3b9c4f0fc6bcffb7a69d687a4238cc9..93770c167dff45e3774fdd4478e3c8c16b1e07b6 100644
|
| --- a/content/browser/web_contents/web_contents_impl.cc
|
| +++ b/content/browser/web_contents/web_contents_impl.cc
|
| @@ -1871,6 +1871,10 @@ RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
|
| return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
|
| }
|
|
|
| +RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() {
|
| + return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost();
|
| +}
|
| +
|
| void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
|
| // This method is being called to enter renderer-initiated fullscreen mode.
|
| // Make sure any existing fullscreen widget is shut down first.
|
| @@ -4618,6 +4622,20 @@ void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
|
| }
|
| }
|
|
|
| +void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
|
| + // Only change focus if we are not currently focused.
|
| + WebContentsImpl* old_contents = GetFocusedWebContents();
|
| + if (old_contents == this)
|
| + return;
|
| +
|
| + // Send a page level blur to the old contents so that it displays inactive UI
|
| + // and focus this contents to activate it.
|
| + if (old_contents)
|
| + old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
|
| + GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
|
| + GetOutermostWebContents()->node_->SetFocusedWebContents(this);
|
| +}
|
| +
|
| void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
|
| SiteInstance* source) {
|
| if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
|
| @@ -4625,22 +4643,9 @@ void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
|
| return;
|
| }
|
|
|
| - // 1. Find old focused frame and unfocus it.
|
| - // 2. Focus the new frame in the current FrameTree.
|
| - // 3. Set current WebContents as focused.
|
| - WebContentsImpl* old_focused_contents = GetFocusedWebContents();
|
| - if (old_focused_contents != this) {
|
| - // Focus is moving between frame trees, unfocus the frame in the old tree.
|
| - old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source);
|
| - GetOutermostWebContents()->node_->SetFocusedWebContents(this);
|
| - }
|
| + SetAsFocusedWebContentsIfNecessary();
|
|
|
| frame_tree_.SetFocusedFrame(node, source);
|
| -
|
| - // TODO(avallee): Remove this once page focus is fixed.
|
| - RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost();
|
| - if (rwh && old_focused_contents != this)
|
| - rwh->Focus();
|
| }
|
|
|
| bool WebContentsImpl::AddMessageToConsole(int32_t level,
|
| @@ -4670,6 +4675,20 @@ void WebContentsImpl::OnUserInteraction(
|
| rdh->OnUserGesture();
|
| }
|
|
|
| +void WebContentsImpl::EnsureOwningContentsIsFocused(
|
| + RenderWidgetHostImpl* render_widget_host) {
|
| + if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
|
| + return;
|
| +
|
| + RenderWidgetHostImpl* focused_widget =
|
| + GetFocusedRenderWidgetHost(render_widget_host);
|
| +
|
| + if (focused_widget != render_widget_host &&
|
| + focused_widget->delegate() != render_widget_host->delegate()) {
|
| + SetAsFocusedWebContentsIfNecessary();
|
| + }
|
| +}
|
| +
|
| void WebContentsImpl::OnIgnoredUIEvent() {
|
| // Notify observers.
|
| for (auto& observer : observers_)
|
|
|