Chromium Code Reviews| 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 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1840 // the subframe has focus. Drop the event in that case. Do not give | 1840 // the subframe has focus. Drop the event in that case. Do not give |
| 1841 // it to the main frame, so that the user doesn't unexpectedly type into the | 1841 // it to the main frame, so that the user doesn't unexpectedly type into the |
| 1842 // wrong frame if a focused subframe renderer crashes while they type. | 1842 // wrong frame if a focused subframe renderer crashes while they type. |
| 1843 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); | 1843 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 1844 if (!view) | 1844 if (!view) |
| 1845 return nullptr; | 1845 return nullptr; |
| 1846 | 1846 |
| 1847 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); | 1847 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
| 1848 } | 1848 } |
| 1849 | 1849 |
| 1850 RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { | |
| 1851 return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost(); | |
| 1852 } | |
| 1853 | |
| 1850 void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { | 1854 void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { |
| 1851 // This method is being called to enter renderer-initiated fullscreen mode. | 1855 // This method is being called to enter renderer-initiated fullscreen mode. |
| 1852 // Make sure any existing fullscreen widget is shut down first. | 1856 // Make sure any existing fullscreen widget is shut down first. |
| 1853 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); | 1857 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
| 1854 if (widget_view) { | 1858 if (widget_view) { |
| 1855 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) | 1859 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 1856 ->ShutdownAndDestroyWidget(true); | 1860 ->ShutdownAndDestroyWidget(true); |
| 1857 } | 1861 } |
| 1858 | 1862 |
| 1859 if (delegate_) | 1863 if (delegate_) |
| (...skipping 2759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4619 GetSiteInstance()); | 4623 GetSiteInstance()); |
| 4620 } else { | 4624 } else { |
| 4621 RenderFrameHostImpl* source_rfhi = | 4625 RenderFrameHostImpl* source_rfhi = |
| 4622 static_cast<RenderFrameHostImpl*>(source_rfh); | 4626 static_cast<RenderFrameHostImpl*>(source_rfh); |
| 4623 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( | 4627 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
| 4624 GetSiteInstance(), nullptr); | 4628 GetSiteInstance(), nullptr); |
| 4625 } | 4629 } |
| 4626 } | 4630 } |
| 4627 } | 4631 } |
| 4628 | 4632 |
| 4633 void WebContentsImpl::ChangeFocusIfNecessary() { | |
| 4634 // Only change focus if we are not currently focused. | |
| 4635 WebContentsImpl* old_contents = GetFocusedWebContents(); | |
| 4636 if (old_contents == this) | |
| 4637 return; | |
| 4638 | |
| 4639 // Ensure that the embedding frame in each outer WebContent's frame tree is | |
| 4640 // focused, if present. | |
| 4641 WebContentsImpl* web_contents = this; | |
| 4642 while (web_contents->GetOuterWebContents()) { | |
| 4643 FrameTreeNode* tree_node = FrameTreeNode::GloballyFindByID( | |
| 4644 web_contents->GetOuterDelegateFrameTreeNodeId()); | |
| 4645 RenderFrameProxyHost* outer_proxy = web_contents->frame_tree_.root() | |
| 4646 ->render_manager() | |
| 4647 ->GetProxyToOuterDelegate(); | |
| 4648 // In BrowserPlugin, we don't have a node in the embedder, we are implicitly | |
| 4649 // embedded in the main frame. | |
| 4650 // TODO(http://crbug.com/533069): Delete once BrowserPlugin is gone. | |
| 4651 if (!tree_node) { | |
| 4652 tree_node = web_contents->GetOuterWebContents() | |
| 4653 ->GetMainFrame() | |
| 4654 ->frame_tree_node(); | |
| 4655 } | |
| 4656 | |
| 4657 web_contents = web_contents->GetOuterWebContents(); | |
|
alexmos
2016/10/31 18:57:57
nit: seems like you could move this up to just bef
avallee
2016/11/07 19:18:44
Loop deleted. I think this will not be necessary.
| |
| 4658 if (tree_node == web_contents->frame_tree_.GetFocusedFrame()) | |
| 4659 break; | |
| 4660 if (tree_node) | |
| 4661 web_contents->frame_tree_.SetFocusedFrame(tree_node, | |
| 4662 outer_proxy->GetSiteInstance()); | |
| 4663 | |
| 4664 if (outer_proxy) | |
| 4665 outer_proxy->SetFocusedFrame(); | |
|
alexmos
2016/10/31 18:57:57
Does this need to be done if the tree_node is alre
avallee
2016/11/07 19:18:44
I'm not sure, but deleted for now, it seems notify
| |
| 4666 } | |
| 4667 | |
| 4668 // Send a page level blur to the old contents so that it displays inactive UI | |
| 4669 // and focus this contents to activate it. | |
| 4670 if (old_contents) | |
| 4671 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); | |
| 4672 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); | |
| 4673 GetOutermostWebContents()->node_->SetFocusedWebContents(this); | |
| 4674 } | |
| 4675 | |
| 4629 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, | 4676 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| 4630 SiteInstance* source) { | 4677 SiteInstance* source) { |
| 4631 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) { | 4678 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) { |
| 4632 frame_tree_.SetFocusedFrame(node, source); | 4679 frame_tree_.SetFocusedFrame(node, source); |
| 4633 return; | 4680 return; |
| 4634 } | 4681 } |
| 4635 | 4682 |
| 4636 // 1. Find old focused frame and unfocus it. | 4683 ChangeFocusIfNecessary(); |
| 4637 // 2. Focus the new frame in the current FrameTree. | |
| 4638 // 3. Set current WebContents as focused. | |
| 4639 WebContentsImpl* old_focused_contents = GetFocusedWebContents(); | |
| 4640 if (old_focused_contents != this) { | |
| 4641 // Focus is moving between frame trees, unfocus the frame in the old tree. | |
| 4642 old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source); | |
| 4643 GetOutermostWebContents()->node_->SetFocusedWebContents(this); | |
| 4644 } | |
| 4645 | 4684 |
| 4646 frame_tree_.SetFocusedFrame(node, source); | 4685 frame_tree_.SetFocusedFrame(node, source); |
| 4647 | |
| 4648 // TODO(avallee): Remove this once page focus is fixed. | |
| 4649 RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost(); | |
| 4650 if (rwh && old_focused_contents != this) | |
| 4651 rwh->Focus(); | |
| 4652 } | 4686 } |
| 4653 | 4687 |
| 4654 bool WebContentsImpl::AddMessageToConsole(int32_t level, | 4688 bool WebContentsImpl::AddMessageToConsole(int32_t level, |
| 4655 const base::string16& message, | 4689 const base::string16& message, |
| 4656 int32_t line_no, | 4690 int32_t line_no, |
| 4657 const base::string16& source_id) { | 4691 const base::string16& source_id) { |
| 4658 if (!delegate_) | 4692 if (!delegate_) |
| 4659 return false; | 4693 return false; |
| 4660 return delegate_->AddMessageToConsole(this, level, message, line_no, | 4694 return delegate_->AddMessageToConsole(this, level, message, line_no, |
| 4661 source_id); | 4695 source_id); |
| 4662 } | 4696 } |
| 4663 | 4697 |
| 4664 void WebContentsImpl::OnUserInteraction( | 4698 void WebContentsImpl::OnUserInteraction( |
| 4665 RenderWidgetHostImpl* render_widget_host, | 4699 RenderWidgetHostImpl* render_widget_host, |
| 4666 const blink::WebInputEvent::Type type) { | 4700 const blink::WebInputEvent::Type type) { |
| 4667 // Ignore unless the widget is currently in the frame tree. | 4701 // Ignore unless the widget is currently in the frame tree. |
| 4668 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) | 4702 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) |
| 4669 return; | 4703 return; |
| 4670 | 4704 |
| 4671 for (auto& observer : observers_) | 4705 for (auto& observer : observers_) |
| 4672 observer.DidGetUserInteraction(type); | 4706 observer.DidGetUserInteraction(type); |
| 4673 | 4707 |
| 4674 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 4708 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 4675 // Exclude scroll events as user gestures for resource load dispatches. | 4709 // Exclude scroll events as user gestures for resource load dispatches. |
| 4676 // rdh is NULL in unittests. | 4710 // rdh is NULL in unittests. |
| 4677 if (rdh && type != blink::WebInputEvent::MouseWheel) | 4711 if (rdh && type != blink::WebInputEvent::MouseWheel) |
| 4678 rdh->OnUserGesture(); | 4712 rdh->OnUserGesture(); |
| 4679 } | 4713 } |
| 4680 | 4714 |
| 4715 void WebContentsImpl::EnsureOwningContentsIsFocused( | |
| 4716 RenderWidgetHostImpl* render_widget_host) { | |
| 4717 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) | |
|
alexmos
2016/10/31 18:57:57
Can you please explain this check? So if this is
avallee
2016/11/07 19:18:44
This fixes an issue with TextInputState. This is t
EhsanK
2016/11/08 16:05:47
This is actually for making sure PDF runs on Brows
alexmos
2016/11/09 02:47:54
I think the intent of the early return in WebConte
EhsanK
2016/11/09 16:58:02
alexmos@: If I understand your question, we are as
alexmos
2016/11/09 18:16:57
Right.
EhsanK
2016/11/09 19:17:15
No, actually this is using --use-cpffg. BTW, the n
alexmos
2016/11/10 18:35:44
Thanks for clarifying. What worried me is that if
EhsanK
2016/11/10 19:04:56
You are right and comparing with the old code we a
alexmos
2016/11/10 19:16:55
Coming back to this CL, I think this check is fine
avallee
2016/11/16 05:38:09
I tested http://foersom.com/net/HowTo/data/OoPdfFo
alexmos
2016/11/16 23:29:03
Acknowledged.
| |
| 4718 return; | |
| 4719 | |
| 4720 RenderWidgetHostImpl* focused_widget = | |
| 4721 GetFocusedRenderWidgetHost(render_widget_host); | |
| 4722 | |
| 4723 if (focused_widget != render_widget_host && | |
| 4724 focused_widget->delegate() != render_widget_host->delegate()) { | |
| 4725 ChangeFocusIfNecessary(); | |
| 4726 } | |
| 4727 } | |
| 4728 | |
| 4681 void WebContentsImpl::OnIgnoredUIEvent() { | 4729 void WebContentsImpl::OnIgnoredUIEvent() { |
| 4682 // Notify observers. | 4730 // Notify observers. |
| 4683 for (auto& observer : observers_) | 4731 for (auto& observer : observers_) |
| 4684 observer.DidGetIgnoredUIEvent(); | 4732 observer.DidGetIgnoredUIEvent(); |
| 4685 } | 4733 } |
| 4686 | 4734 |
| 4687 void WebContentsImpl::RendererUnresponsive( | 4735 void WebContentsImpl::RendererUnresponsive( |
| 4688 RenderWidgetHostImpl* render_widget_host, | 4736 RenderWidgetHostImpl* render_widget_host, |
| 4689 RendererUnresponsiveType type) { | 4737 RendererUnresponsiveType type) { |
| 4690 for (auto& observer : observers_) | 4738 for (auto& observer : observers_) |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5206 dialog_manager_ = dialog_manager; | 5254 dialog_manager_ = dialog_manager; |
| 5207 } | 5255 } |
| 5208 | 5256 |
| 5209 void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) { | 5257 void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) { |
| 5210 auto it = binding_sets_.find(interface_name); | 5258 auto it = binding_sets_.find(interface_name); |
| 5211 if (it != binding_sets_.end()) | 5259 if (it != binding_sets_.end()) |
| 5212 binding_sets_.erase(it); | 5260 binding_sets_.erase(it); |
| 5213 } | 5261 } |
| 5214 | 5262 |
| 5215 } // namespace content | 5263 } // namespace content |
| OLD | NEW |