OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/frame_tree.h" | 5 #include "content/browser/frame_host/frame_tree.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 | 263 |
264 RenderFrameHostImpl* FrameTree::GetMainFrame() const { | 264 RenderFrameHostImpl* FrameTree::GetMainFrame() const { |
265 return root_->current_frame_host(); | 265 return root_->current_frame_host(); |
266 } | 266 } |
267 | 267 |
268 FrameTreeNode* FrameTree::GetFocusedFrame() { | 268 FrameTreeNode* FrameTree::GetFocusedFrame() { |
269 return FindByID(focused_frame_tree_node_id_); | 269 return FindByID(focused_frame_tree_node_id_); |
270 } | 270 } |
271 | 271 |
272 void FrameTree::SetFocusedFrame(FrameTreeNode* node) { | 272 void FrameTree::SetFocusedFrame(FrameTreeNode* node) { |
273 // If the focused frame changed across processes, send a message to the old | 273 std::set<SiteInstance*> frame_tree_site_instances; |
274 // focused frame's renderer process to clear focus from that frame and fire | 274 ForEach(base::Bind(&CollectSiteInstances, &frame_tree_site_instances)); |
275 // blur events. | 275 |
276 FrameTreeNode* oldFocusedFrame = GetFocusedFrame(); | 276 // Update the focused frame in all other SiteInstances. If focus changes to |
277 if (oldFocusedFrame && | 277 // a cross-process frame, this allows the old focused frame's renderer |
278 oldFocusedFrame->current_frame_host()->GetSiteInstance() != | 278 // process to clear focus from that frame and fire blur events. It also |
279 node->current_frame_host()->GetSiteInstance()) { | 279 // ensures that the latest focused frame is available in all renderers to |
280 DCHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible()); | 280 // compute document.activeElement. |
281 oldFocusedFrame->current_frame_host()->ClearFocus(); | 281 for (const auto& instance : frame_tree_site_instances) { |
alexmos
2015/11/04 21:53:59
The last part of my test illustrates why it's now
Charlie Reis
2015/11/04 22:23:42
Acknowledged.
| |
282 if (instance != node->current_frame_host()->GetSiteInstance()) { | |
283 DCHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible()); | |
284 RenderFrameProxyHost* proxy = | |
285 node->render_manager()->GetRenderFrameProxyHost(instance); | |
286 proxy->SetFocusedFrame(); | |
287 } | |
282 } | 288 } |
283 | 289 |
284 node->set_last_focus_time(base::TimeTicks::Now()); | 290 node->set_last_focus_time(base::TimeTicks::Now()); |
285 focused_frame_tree_node_id_ = node->frame_tree_node_id(); | 291 focused_frame_tree_node_id_ = node->frame_tree_node_id(); |
286 } | 292 } |
287 | 293 |
288 void FrameTree::SetFrameRemoveListener( | 294 void FrameTree::SetFrameRemoveListener( |
289 const base::Callback<void(RenderFrameHost*)>& on_frame_removed) { | 295 const base::Callback<void(RenderFrameHost*)>& on_frame_removed) { |
290 on_frame_removed_ = on_frame_removed; | 296 on_frame_removed_ = on_frame_removed; |
291 } | 297 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 // This is only used to set page-level focus in cross-process subframes, and | 447 // This is only used to set page-level focus in cross-process subframes, and |
442 // requests to set focus in main frame's SiteInstance are ignored. | 448 // requests to set focus in main frame's SiteInstance are ignored. |
443 if (instance != root_manager->current_frame_host()->GetSiteInstance()) { | 449 if (instance != root_manager->current_frame_host()->GetSiteInstance()) { |
444 RenderFrameProxyHost* proxy = | 450 RenderFrameProxyHost* proxy = |
445 root_manager->GetRenderFrameProxyHost(instance); | 451 root_manager->GetRenderFrameProxyHost(instance); |
446 proxy->Send(new InputMsg_SetFocus(proxy->GetRoutingID(), is_focused)); | 452 proxy->Send(new InputMsg_SetFocus(proxy->GetRoutingID(), is_focused)); |
447 } | 453 } |
448 } | 454 } |
449 | 455 |
450 } // namespace content | 456 } // namespace content |
OLD | NEW |