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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 identifier(identifier) { | 323 identifier(identifier) { |
| 324 } | 324 } |
| 325 | 325 |
| 326 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { | 326 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { |
| 327 } | 327 } |
| 328 | 328 |
| 329 // WebContentsImpl::WebContentsTreeNode ---------------------------------------- | 329 // WebContentsImpl::WebContentsTreeNode ---------------------------------------- |
| 330 WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode() | 330 WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode() |
| 331 : outer_web_contents_(nullptr), | 331 : outer_web_contents_(nullptr), |
| 332 outer_contents_frame_tree_node_id_( | 332 outer_contents_frame_tree_node_id_( |
| 333 FrameTreeNode::kFrameTreeNodeInvalidId) { | 333 FrameTreeNode::kFrameTreeNodeInvalidId), |
| 334 } | 334 focused_web_contents_(nullptr) {} |
| 335 | 335 |
| 336 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { | 336 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { |
| 337 // Remove child pointer from our parent. | 337 // Remove child pointer from our parent. |
| 338 if (outer_web_contents_) { | 338 if (outer_web_contents_) { |
| 339 ChildrenSet& child_ptrs_in_parent = | 339 ChildrenSet& child_ptrs_in_parent = |
| 340 outer_web_contents_->node_->inner_web_contents_tree_nodes_; | 340 outer_web_contents_->node_->inner_web_contents_tree_nodes_; |
| 341 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this); | 341 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this); |
| 342 DCHECK(iter != child_ptrs_in_parent.end()); | 342 DCHECK(iter != child_ptrs_in_parent.end()); |
| 343 child_ptrs_in_parent.erase(this); | 343 child_ptrs_in_parent.erase(iter); |
| 344 } | 344 } |
| 345 | 345 |
| 346 // Remove parent pointers from our children. | 346 // Remove parent pointers from our children. |
| 347 // TODO(lazyboy): We should destroy the children WebContentses too. If the | 347 // TODO(lazyboy): We should destroy the children WebContentses too. If the |
| 348 // children do not manage their own lifetime, then we would leak their | 348 // children do not manage their own lifetime, then we would leak their |
| 349 // WebContentses. | 349 // WebContentses. |
| 350 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_) | 350 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_) |
| 351 child->outer_web_contents_ = nullptr; | 351 child->outer_web_contents_ = nullptr; |
| 352 } | 352 } |
| 353 | 353 |
| 354 void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents( | 354 void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents( |
| 355 WebContentsImpl* outer_web_contents, | 355 WebContentsImpl* outer_web_contents, |
| 356 RenderFrameHostImpl* outer_contents_frame) { | 356 RenderFrameHostImpl* outer_contents_frame) { |
| 357 DCHECK(!focused_web_contents_) << "Should not attach a root node."; | |
| 357 outer_web_contents_ = outer_web_contents; | 358 outer_web_contents_ = outer_web_contents; |
| 358 outer_contents_frame_tree_node_id_ = | 359 outer_contents_frame_tree_node_id_ = |
| 359 outer_contents_frame->frame_tree_node()->frame_tree_node_id(); | 360 outer_contents_frame->frame_tree_node()->frame_tree_node_id(); |
| 360 | 361 |
| 361 if (!outer_web_contents_->node_) | 362 if (!outer_web_contents_->node_) { |
| 363 // This will reached when connecting into a new WebContents tree. We | |
| 364 // implicitly set the root of this tree as being focused since this is | |
| 365 // called in the process of creating an inner WebContents so I couldn't be | |
| 366 // focused yet. | |
| 362 outer_web_contents_->node_.reset(new WebContentsTreeNode()); | 367 outer_web_contents_->node_.reset(new WebContentsTreeNode()); |
| 368 outer_web_contents_->node_->SetFocusedWebContents(outer_web_contents_); | |
| 369 } | |
| 363 | 370 |
| 364 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this); | 371 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this); |
| 365 } | 372 } |
| 366 | 373 |
| 374 void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( | |
| 375 WebContentsImpl* web_contents) { | |
| 376 DCHECK(!outer_web_contents()) | |
| 377 << "Only the outermost WebContents tracks focus."; | |
| 378 focused_web_contents_ = web_contents; | |
| 379 } | |
| 380 | |
| 367 // WebContentsImpl ------------------------------------------------------------- | 381 // WebContentsImpl ------------------------------------------------------------- |
| 368 | 382 |
| 369 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) | 383 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
| 370 : delegate_(NULL), | 384 : delegate_(NULL), |
| 371 controller_(this, browser_context), | 385 controller_(this, browser_context), |
| 372 render_view_host_delegate_view_(NULL), | 386 render_view_host_delegate_view_(NULL), |
| 373 created_with_opener_(false), | 387 created_with_opener_(false), |
| 374 frame_tree_(new NavigatorImpl(&controller_, this), | 388 frame_tree_(new NavigatorImpl(&controller_, this), |
| 375 this, | 389 this, |
| 376 this, | 390 this, |
| (...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1792 RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( | 1806 RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( |
| 1793 RenderWidgetHostImpl* receiving_widget) { | 1807 RenderWidgetHostImpl* receiving_widget) { |
| 1794 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) | 1808 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) |
| 1795 return receiving_widget; | 1809 return receiving_widget; |
| 1796 | 1810 |
| 1797 // Events for widgets other than the main frame (e.g., popup menus) should be | 1811 // Events for widgets other than the main frame (e.g., popup menus) should be |
| 1798 // forwarded directly to the widget they arrived on. | 1812 // forwarded directly to the widget they arrived on. |
| 1799 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) | 1813 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) |
| 1800 return receiving_widget; | 1814 return receiving_widget; |
| 1801 | 1815 |
| 1802 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame(); | 1816 FrameTreeNode* focused_frame = |
| 1817 GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); | |
| 1803 if (!focused_frame) | 1818 if (!focused_frame) |
| 1804 return receiving_widget; | 1819 return receiving_widget; |
| 1805 | 1820 |
| 1806 // The view may be null if a subframe's renderer process has crashed while | 1821 // The view may be null if a subframe's renderer process has crashed while |
| 1807 // the subframe has focus. Drop the event in that case. Do not give | 1822 // the subframe has focus. Drop the event in that case. Do not give |
| 1808 // it to the main frame, so that the user doesn't unexpectedly type into the | 1823 // it to the main frame, so that the user doesn't unexpectedly type into the |
| 1809 // wrong frame if a focused subframe renderer crashes while they type. | 1824 // wrong frame if a focused subframe renderer crashes while they type. |
| 1810 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); | 1825 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 1811 if (!view) | 1826 if (!view) |
| 1812 return nullptr; | 1827 return nullptr; |
| (...skipping 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4128 if (delegate_) | 4143 if (delegate_) |
| 4129 return delegate_->GetRootWindowResizerRect(); | 4144 return delegate_->GetRootWindowResizerRect(); |
| 4130 return gfx::Rect(); | 4145 return gfx::Rect(); |
| 4131 } | 4146 } |
| 4132 | 4147 |
| 4133 void WebContentsImpl::RemoveBrowserPluginEmbedder() { | 4148 void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
| 4134 if (browser_plugin_embedder_) | 4149 if (browser_plugin_embedder_) |
| 4135 browser_plugin_embedder_.reset(); | 4150 browser_plugin_embedder_.reset(); |
| 4136 } | 4151 } |
| 4137 | 4152 |
| 4153 WebContentsImpl* WebContentsImpl::GetOuterWebContents() { | |
| 4154 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { | |
| 4155 if (node_) | |
| 4156 return node_->outer_web_contents(); | |
| 4157 } else { | |
| 4158 if (GetBrowserPluginGuest()) | |
| 4159 return GetBrowserPluginGuest()->embedder_web_contents(); | |
| 4160 } | |
| 4161 return nullptr; | |
| 4162 } | |
| 4163 | |
| 4164 WebContentsImpl* WebContentsImpl::GetFocusedWebContents() { | |
| 4165 // There is no inner web contents. | |
| 4166 if (!node_) { | |
|
alexmos
2016/06/07 22:03:43
nit: { not necessary
avallee
2016/06/15 13:32:10
Done.
| |
| 4167 return this; | |
| 4168 } | |
| 4169 | |
| 4170 // If we've found root by iterating through outer WebContents, root must have | |
| 4171 // a valid node_ since the inner WebContents will have created one when | |
| 4172 // connecting. | |
| 4173 return GetOutermostWebContents()->node_->focused_web_contents(); | |
| 4174 } | |
| 4175 | |
| 4176 WebContentsImpl* WebContentsImpl::GetOutermostWebContents() { | |
| 4177 WebContentsImpl* root = this; | |
| 4178 while (root->GetOuterWebContents()) | |
| 4179 root = root->GetOuterWebContents(); | |
| 4180 return root; | |
| 4181 } | |
| 4182 | |
| 4138 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { | 4183 void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
| 4139 // Don't send notifications if we are just creating a swapped-out RVH for | 4184 // Don't send notifications if we are just creating a swapped-out RVH for |
| 4140 // the opener chain. These won't be used for view-source or WebUI, so it's | 4185 // the opener chain. These won't be used for view-source or WebUI, so it's |
| 4141 // ok to return early. | 4186 // ok to return early. |
| 4142 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active()) | 4187 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active()) |
| 4143 return; | 4188 return; |
| 4144 | 4189 |
| 4145 if (delegate_) | 4190 if (delegate_) |
| 4146 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4191 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4147 | 4192 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4535 GetSiteInstance()); | 4580 GetSiteInstance()); |
| 4536 } else { | 4581 } else { |
| 4537 RenderFrameHostImpl* source_rfhi = | 4582 RenderFrameHostImpl* source_rfhi = |
| 4538 static_cast<RenderFrameHostImpl*>(source_rfh); | 4583 static_cast<RenderFrameHostImpl*>(source_rfh); |
| 4539 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( | 4584 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
| 4540 GetSiteInstance(), nullptr); | 4585 GetSiteInstance(), nullptr); |
| 4541 } | 4586 } |
| 4542 } | 4587 } |
| 4543 } | 4588 } |
| 4544 | 4589 |
| 4590 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, | |
| 4591 SiteInstance* source) { | |
| 4592 // 1. Find old focused frame and unfocus it. | |
| 4593 // 2. Focus the new frame in the current FrameTree. | |
| 4594 // 3. Set current WebContents as focused. | |
| 4595 WebContentsImpl* old_focused_contents = GetFocusedWebContents(); | |
| 4596 if (old_focused_contents != this) { | |
| 4597 // Focus is moving between frame trees, unfocus the frame in the old tree. | |
| 4598 old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source); | |
| 4599 GetOutermostWebContents()->node_->SetFocusedWebContents(this); | |
| 4600 } | |
| 4601 | |
| 4602 frame_tree_.SetFocusedFrame(node, source); | |
| 4603 | |
| 4604 // TODO(avallee): Remove this once page focus is fixed. | |
| 4605 RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost(); | |
| 4606 if (rwh && old_focused_contents != this && | |
| 4607 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) | |
| 4608 rwh->Focus(); | |
| 4609 } | |
| 4610 | |
| 4545 bool WebContentsImpl::AddMessageToConsole(int32_t level, | 4611 bool WebContentsImpl::AddMessageToConsole(int32_t level, |
| 4546 const base::string16& message, | 4612 const base::string16& message, |
| 4547 int32_t line_no, | 4613 int32_t line_no, |
| 4548 const base::string16& source_id) { | 4614 const base::string16& source_id) { |
| 4549 if (!delegate_) | 4615 if (!delegate_) |
| 4550 return false; | 4616 return false; |
| 4551 return delegate_->AddMessageToConsole(this, level, message, line_no, | 4617 return delegate_->AddMessageToConsole(this, level, message, line_no, |
| 4552 source_id); | 4618 source_id); |
| 4553 } | 4619 } |
| 4554 | 4620 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4912 if (node_ && node_->outer_web_contents()) | 4978 if (node_ && node_->outer_web_contents()) |
| 4913 return node_->outer_contents_frame_tree_node_id(); | 4979 return node_->outer_contents_frame_tree_node_id(); |
| 4914 | 4980 |
| 4915 return FrameTreeNode::kFrameTreeNodeInvalidId; | 4981 return FrameTreeNode::kFrameTreeNodeInvalidId; |
| 4916 } | 4982 } |
| 4917 | 4983 |
| 4918 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { | 4984 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
| 4919 return frame_tree_.root()->render_manager(); | 4985 return frame_tree_.root()->render_manager(); |
| 4920 } | 4986 } |
| 4921 | 4987 |
| 4922 WebContentsImpl* WebContentsImpl::GetOuterWebContents() { | |
| 4923 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { | |
| 4924 if (node_) | |
| 4925 return node_->outer_web_contents(); | |
| 4926 } else { | |
| 4927 if (GetBrowserPluginGuest()) | |
| 4928 return GetBrowserPluginGuest()->embedder_web_contents(); | |
| 4929 } | |
| 4930 return nullptr; | |
| 4931 } | |
| 4932 | |
| 4933 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 4988 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
| 4934 return browser_plugin_guest_.get(); | 4989 return browser_plugin_guest_.get(); |
| 4935 } | 4990 } |
| 4936 | 4991 |
| 4937 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { | 4992 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
| 4938 CHECK(!browser_plugin_guest_); | 4993 CHECK(!browser_plugin_guest_); |
| 4939 CHECK(guest); | 4994 CHECK(guest); |
| 4940 browser_plugin_guest_.reset(guest); | 4995 browser_plugin_guest_.reset(guest); |
| 4941 } | 4996 } |
| 4942 | 4997 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4980 if (controller) { | 5035 if (controller) { |
| 4981 web_ui->AddMessageHandler(new GenericHandler()); | 5036 web_ui->AddMessageHandler(new GenericHandler()); |
| 4982 web_ui->SetController(controller); | 5037 web_ui->SetController(controller); |
| 4983 return web_ui; | 5038 return web_ui; |
| 4984 } | 5039 } |
| 4985 | 5040 |
| 4986 delete web_ui; | 5041 delete web_ui; |
| 4987 return NULL; | 5042 return NULL; |
| 4988 } | 5043 } |
| 4989 | 5044 |
| 4990 // TODO(paulmeyer): This method will not be used until find-in-page across | |
| 4991 // GuestViews is implemented. | |
| 4992 WebContentsImpl* WebContentsImpl::GetOutermostWebContents() { | |
| 4993 // Find the outer-most WebContents. | |
| 4994 WebContentsImpl* outermost_web_contents = this; | |
| 4995 while (outermost_web_contents->node_ && | |
| 4996 outermost_web_contents->node_->outer_web_contents()) { | |
| 4997 outermost_web_contents = | |
| 4998 outermost_web_contents->node_->outer_web_contents(); | |
| 4999 } | |
| 5000 return outermost_web_contents; | |
| 5001 } | |
| 5002 | |
| 5003 FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() { | 5045 FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() { |
| 5004 // TODO(paulmeyer): This method will need to access (or potentially create) | 5046 // TODO(paulmeyer): This method will need to access (or potentially create) |
| 5005 // the FindRequestManager in the outermost WebContents once find-in-page | 5047 // the FindRequestManager in the outermost WebContents once find-in-page |
| 5006 // across GuestViews is implemented. | 5048 // across GuestViews is implemented. |
| 5007 if (!find_request_manager_) | 5049 if (!find_request_manager_) |
| 5008 find_request_manager_.reset(new FindRequestManager(this)); | 5050 find_request_manager_.reset(new FindRequestManager(this)); |
| 5009 | 5051 |
| 5010 return find_request_manager_.get(); | 5052 return find_request_manager_.get(); |
| 5011 } | 5053 } |
| 5012 | 5054 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5085 for (RenderViewHost* render_view_host : render_view_host_set) | 5127 for (RenderViewHost* render_view_host : render_view_host_set) |
| 5086 render_view_host->OnWebkitPreferencesChanged(); | 5128 render_view_host->OnWebkitPreferencesChanged(); |
| 5087 } | 5129 } |
| 5088 | 5130 |
| 5089 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( | 5131 void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
| 5090 JavaScriptDialogManager* dialog_manager) { | 5132 JavaScriptDialogManager* dialog_manager) { |
| 5091 dialog_manager_ = dialog_manager; | 5133 dialog_manager_ = dialog_manager; |
| 5092 } | 5134 } |
| 5093 | 5135 |
| 5094 } // namespace content | 5136 } // namespace content |
| OLD | NEW |