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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 is_being_destroyed_ = true; | 477 is_being_destroyed_ = true; |
| 478 | 478 |
| 479 rwh_input_event_router_.reset(); | 479 rwh_input_event_router_.reset(); |
| 480 | 480 |
| 481 for (auto& entry : binding_sets_) | 481 for (auto& entry : binding_sets_) |
| 482 entry.second->CloseAllBindings(); | 482 entry.second->CloseAllBindings(); |
| 483 | 483 |
| 484 WebContentsImpl* outermost = GetOutermostWebContents(); | 484 WebContentsImpl* outermost = GetOutermostWebContents(); |
| 485 if (GetFocusedWebContents() == this && this != outermost) { | 485 if (GetFocusedWebContents() == this && this != outermost) { |
| 486 // If the current WebContents is in focus, unset it. | 486 // If the current WebContents is in focus, unset it. |
| 487 outermost->node_->SetFocusedWebContents(outermost); | 487 outermost->node_->SetFocusedWebContents(outermost); |
|
alexmos
2016/11/10 19:16:55
What happens if an inner contents with page focus
avallee
2016/11/16 05:38:09
It feels like it should focus its outer contents,
alexmos
2016/11/16 23:29:03
I'd double-check on that with Lucas or Ehsan. I'm
| |
| 488 } | 488 } |
| 489 | 489 |
| 490 for (FrameTreeNode* node : frame_tree_.Nodes()) { | 490 for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 491 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs | 491 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs |
| 492 // to be shutdown and be deleted as well. | 492 // to be shutdown and be deleted as well. |
| 493 node->render_manager()->ClearRFHsPendingShutdown(); | 493 node->render_manager()->ClearRFHsPendingShutdown(); |
| 494 node->render_manager()->ClearWebUIInstances(); | 494 node->render_manager()->ClearWebUIInstances(); |
| 495 } | 495 } |
| 496 | 496 |
| 497 for (RenderWidgetHostImpl* widget : created_widgets_) | 497 for (RenderWidgetHostImpl* widget : created_widgets_) |
| (...skipping 1366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1864 // the subframe has focus. Drop the event in that case. Do not give | 1864 // the subframe has focus. Drop the event in that case. Do not give |
| 1865 // it to the main frame, so that the user doesn't unexpectedly type into the | 1865 // it to the main frame, so that the user doesn't unexpectedly type into the |
| 1866 // wrong frame if a focused subframe renderer crashes while they type. | 1866 // wrong frame if a focused subframe renderer crashes while they type. |
| 1867 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); | 1867 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 1868 if (!view) | 1868 if (!view) |
| 1869 return nullptr; | 1869 return nullptr; |
| 1870 | 1870 |
| 1871 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); | 1871 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
| 1872 } | 1872 } |
| 1873 | 1873 |
| 1874 RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { | |
| 1875 return GetFocusedWebContents()->GetMainFrame()->GetRenderWidgetHost(); | |
| 1876 } | |
| 1877 | |
| 1874 void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { | 1878 void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { |
| 1875 // This method is being called to enter renderer-initiated fullscreen mode. | 1879 // This method is being called to enter renderer-initiated fullscreen mode. |
| 1876 // Make sure any existing fullscreen widget is shut down first. | 1880 // Make sure any existing fullscreen widget is shut down first. |
| 1877 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); | 1881 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
| 1878 if (widget_view) { | 1882 if (widget_view) { |
| 1879 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) | 1883 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 1880 ->ShutdownAndDestroyWidget(true); | 1884 ->ShutdownAndDestroyWidget(true); |
| 1881 } | 1885 } |
| 1882 | 1886 |
| 1883 if (delegate_) | 1887 if (delegate_) |
| (...skipping 2727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4611 GetSiteInstance()); | 4615 GetSiteInstance()); |
| 4612 } else { | 4616 } else { |
| 4613 RenderFrameHostImpl* source_rfhi = | 4617 RenderFrameHostImpl* source_rfhi = |
| 4614 static_cast<RenderFrameHostImpl*>(source_rfh); | 4618 static_cast<RenderFrameHostImpl*>(source_rfh); |
| 4615 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( | 4619 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
| 4616 GetSiteInstance(), nullptr); | 4620 GetSiteInstance(), nullptr); |
| 4617 } | 4621 } |
| 4618 } | 4622 } |
| 4619 } | 4623 } |
| 4620 | 4624 |
| 4625 void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() { | |
| 4626 // Only change focus if we are not currently focused. | |
| 4627 WebContentsImpl* old_contents = GetFocusedWebContents(); | |
| 4628 if (old_contents == this) | |
| 4629 return; | |
| 4630 | |
| 4631 // Send a page level blur to the old contents so that it displays inactive UI | |
| 4632 // and focus this contents to activate it. | |
| 4633 if (old_contents) | |
| 4634 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); | |
| 4635 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); | |
| 4636 GetOutermostWebContents()->node_->SetFocusedWebContents(this); | |
| 4637 } | |
| 4638 | |
| 4621 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, | 4639 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| 4622 SiteInstance* source) { | 4640 SiteInstance* source) { |
| 4623 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) { | 4641 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) { |
| 4624 frame_tree_.SetFocusedFrame(node, source); | 4642 frame_tree_.SetFocusedFrame(node, source); |
| 4625 return; | 4643 return; |
| 4626 } | 4644 } |
| 4627 | 4645 |
| 4628 // 1. Find old focused frame and unfocus it. | 4646 SetAsFocusedWebContentsIfNecessary(); |
| 4629 // 2. Focus the new frame in the current FrameTree. | |
| 4630 // 3. Set current WebContents as focused. | |
| 4631 WebContentsImpl* old_focused_contents = GetFocusedWebContents(); | |
| 4632 if (old_focused_contents != this) { | |
| 4633 // Focus is moving between frame trees, unfocus the frame in the old tree. | |
| 4634 old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source); | |
| 4635 GetOutermostWebContents()->node_->SetFocusedWebContents(this); | |
| 4636 } | |
| 4637 | 4647 |
| 4638 frame_tree_.SetFocusedFrame(node, source); | 4648 frame_tree_.SetFocusedFrame(node, source); |
| 4639 | |
| 4640 // TODO(avallee): Remove this once page focus is fixed. | |
| 4641 RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost(); | |
| 4642 if (rwh && old_focused_contents != this) | |
| 4643 rwh->Focus(); | |
| 4644 } | 4649 } |
| 4645 | 4650 |
| 4646 bool WebContentsImpl::AddMessageToConsole(int32_t level, | 4651 bool WebContentsImpl::AddMessageToConsole(int32_t level, |
| 4647 const base::string16& message, | 4652 const base::string16& message, |
| 4648 int32_t line_no, | 4653 int32_t line_no, |
| 4649 const base::string16& source_id) { | 4654 const base::string16& source_id) { |
| 4650 if (!delegate_) | 4655 if (!delegate_) |
| 4651 return false; | 4656 return false; |
| 4652 return delegate_->AddMessageToConsole(this, level, message, line_no, | 4657 return delegate_->AddMessageToConsole(this, level, message, line_no, |
| 4653 source_id); | 4658 source_id); |
| 4654 } | 4659 } |
| 4655 | 4660 |
| 4656 void WebContentsImpl::OnUserInteraction( | 4661 void WebContentsImpl::OnUserInteraction( |
| 4657 RenderWidgetHostImpl* render_widget_host, | 4662 RenderWidgetHostImpl* render_widget_host, |
| 4658 const blink::WebInputEvent::Type type) { | 4663 const blink::WebInputEvent::Type type) { |
| 4659 // Ignore unless the widget is currently in the frame tree. | 4664 // Ignore unless the widget is currently in the frame tree. |
| 4660 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) | 4665 if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) |
| 4661 return; | 4666 return; |
| 4662 | 4667 |
| 4663 for (auto& observer : observers_) | 4668 for (auto& observer : observers_) |
| 4664 observer.DidGetUserInteraction(type); | 4669 observer.DidGetUserInteraction(type); |
| 4665 | 4670 |
| 4666 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); | 4671 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 4667 // Exclude scroll events as user gestures for resource load dispatches. | 4672 // Exclude scroll events as user gestures for resource load dispatches. |
| 4668 // rdh is NULL in unittests. | 4673 // rdh is NULL in unittests. |
| 4669 if (rdh && type != blink::WebInputEvent::MouseWheel) | 4674 if (rdh && type != blink::WebInputEvent::MouseWheel) |
| 4670 rdh->OnUserGesture(); | 4675 rdh->OnUserGesture(); |
| 4671 } | 4676 } |
| 4672 | 4677 |
| 4678 void WebContentsImpl::EnsureOwningContentsIsFocused( | |
| 4679 RenderWidgetHostImpl* render_widget_host) { | |
| 4680 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) | |
| 4681 return; | |
| 4682 | |
| 4683 RenderWidgetHostImpl* focused_widget = | |
| 4684 GetFocusedRenderWidgetHost(render_widget_host); | |
| 4685 | |
| 4686 if (focused_widget != render_widget_host && | |
| 4687 focused_widget->delegate() != render_widget_host->delegate()) { | |
| 4688 SetAsFocusedWebContentsIfNecessary(); | |
| 4689 } | |
| 4690 } | |
| 4691 | |
| 4673 void WebContentsImpl::OnIgnoredUIEvent() { | 4692 void WebContentsImpl::OnIgnoredUIEvent() { |
| 4674 // Notify observers. | 4693 // Notify observers. |
| 4675 for (auto& observer : observers_) | 4694 for (auto& observer : observers_) |
| 4676 observer.DidGetIgnoredUIEvent(); | 4695 observer.DidGetIgnoredUIEvent(); |
| 4677 } | 4696 } |
| 4678 | 4697 |
| 4679 void WebContentsImpl::RendererUnresponsive( | 4698 void WebContentsImpl::RendererUnresponsive( |
| 4680 RenderWidgetHostImpl* render_widget_host, | 4699 RenderWidgetHostImpl* render_widget_host, |
| 4681 RendererUnresponsiveType type) { | 4700 RendererUnresponsiveType type) { |
| 4682 for (auto& observer : observers_) | 4701 for (auto& observer : observers_) |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5198 dialog_manager_ = dialog_manager; | 5217 dialog_manager_ = dialog_manager; |
| 5199 } | 5218 } |
| 5200 | 5219 |
| 5201 void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) { | 5220 void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) { |
| 5202 auto it = binding_sets_.find(interface_name); | 5221 auto it = binding_sets_.find(interface_name); |
| 5203 if (it != binding_sets_.end()) | 5222 if (it != binding_sets_.end()) |
| 5204 binding_sets_.erase(it); | 5223 binding_sets_.erase(it); |
| 5205 } | 5224 } |
| 5206 | 5225 |
| 5207 } // namespace content | 5226 } // namespace content |
| OLD | NEW |