Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 } | 244 } |
| 245 | 245 |
| 246 FrameTreeNode* FrameTree::GetFocusedFrame() { | 246 FrameTreeNode* FrameTree::GetFocusedFrame() { |
| 247 return FindByID(focused_frame_tree_node_id_); | 247 return FindByID(focused_frame_tree_node_id_); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void FrameTree::SetFocusedFrame(FrameTreeNode* node, SiteInstance* source) { | 250 void FrameTree::SetFocusedFrame(FrameTreeNode* node, SiteInstance* source) { |
| 251 if (node == GetFocusedFrame()) | 251 if (node == GetFocusedFrame()) |
| 252 return; | 252 return; |
| 253 | 253 |
| 254 if (node == nullptr) { | |
| 255 if (GetFocusedFrame()) { | |
|
lfg
2016/05/06 21:23:33
Nit: no need for {}.
avallee
2016/05/11 18:26:11
Done.
| |
| 256 GetFocusedFrame()->current_frame_host()->UnsetFocusedFrame(); | |
| 257 } | |
| 258 focused_frame_tree_node_id_ = FrameTreeNode::kFrameTreeNodeInvalidId; | |
| 259 // FIXME: Do we need to update the AX tree here? | |
|
lfg
2016/05/06 21:23:33
Check with dmazzoni@ if this is necessary.
dmazzoni
2016/05/09 17:07:20
Yes, it'd be good to add this line (just like is d
avallee
2016/05/11 18:26:11
Sent email.
avallee
2016/05/11 18:26:11
This doesn't seem to make the test pass. I've file
| |
| 260 return; | |
| 261 } | |
| 262 | |
| 254 std::set<SiteInstance*> frame_tree_site_instances = | 263 std::set<SiteInstance*> frame_tree_site_instances = |
| 255 CollectSiteInstances(this); | 264 CollectSiteInstances(this); |
| 256 | 265 |
| 257 SiteInstance* current_instance = | 266 SiteInstance* current_instance = |
| 258 node->current_frame_host()->GetSiteInstance(); | 267 node->current_frame_host()->GetSiteInstance(); |
| 259 | 268 |
| 260 // Update the focused frame in all other SiteInstances. If focus changes to | 269 // Update the focused frame in all other SiteInstances. If focus changes to |
| 261 // a cross-process frame, this allows the old focused frame's renderer | 270 // a cross-process frame, this allows the old focused frame's renderer |
| 262 // process to clear focus from that frame and fire blur events. It also | 271 // process to clear focus from that frame and fire blur events. It also |
| 263 // ensures that the latest focused frame is available in all renderers to | 272 // ensures that the latest focused frame is available in all renderers to |
| 264 // compute document.activeElement. | 273 // compute document.activeElement. |
| 265 // | 274 // |
| 266 // We do not notify the |source| SiteInstance because it already knows the | 275 // We do not notify the |source| SiteInstance because it already knows the |
| 267 // new focused frame (since it initiated the focus change), and we notify the | 276 // new focused frame (since it initiated the focus change), and we notify the |
| 268 // new focused frame's SiteInstance (if it differs from |source|) separately | 277 // new focused frame's SiteInstance (if it differs from |source|) separately |
| 269 // below. | 278 // below. |
| 270 for (const auto& instance : frame_tree_site_instances) { | 279 for (const auto& instance : frame_tree_site_instances) { |
| 271 if (instance != source && instance != current_instance) { | 280 if (instance != source && instance != current_instance) { |
| 272 DCHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible()); | 281 DCHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible()); |
| 273 RenderFrameProxyHost* proxy = | 282 RenderFrameProxyHost* proxy = |
| 274 node->render_manager()->GetRenderFrameProxyHost(instance); | 283 node->render_manager()->GetRenderFrameProxyHost(instance); |
| 275 proxy->SetFocusedFrame(); | 284 if (proxy) { |
|
lfg
2016/05/06 21:23:32
nit: {}
avallee
2016/05/11 18:26:11
Done.
| |
| 285 proxy->SetFocusedFrame(); | |
| 286 } | |
| 276 } | 287 } |
| 277 } | 288 } |
| 278 | 289 |
| 279 // If |node| was focused from a cross-process frame (i.e., via | 290 // If |node| was focused from a cross-process frame (i.e., via |
| 280 // window.focus()), tell its RenderFrame that it should focus. | 291 // window.focus()), tell its RenderFrame that it should focus. |
| 281 if (current_instance != source) | 292 if (current_instance && current_instance != source) |
| 282 node->current_frame_host()->SetFocusedFrame(); | 293 node->current_frame_host()->SetFocusedFrame(); |
| 283 | 294 |
| 284 focused_frame_tree_node_id_ = node->frame_tree_node_id(); | 295 focused_frame_tree_node_id_ = node->frame_tree_node_id(); |
| 285 node->DidFocus(); | 296 node->DidFocus(); |
| 286 | 297 |
| 287 // The accessibility tree data for the root of the frame tree keeps | 298 // The accessibility tree data for the root of the frame tree keeps |
| 288 // track of the focused frame too, so update that every time the | 299 // track of the focused frame too, so update that every time the |
| 289 // focused frame changes. | 300 // focused frame changes. |
| 290 root()->current_frame_host()->UpdateAXTreeData(); | 301 root()->current_frame_host()->UpdateAXTreeData(); |
| 291 } | 302 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 // This is only used to set page-level focus in cross-process subframes, and | 437 // This is only used to set page-level focus in cross-process subframes, and |
| 427 // requests to set focus in main frame's SiteInstance are ignored. | 438 // requests to set focus in main frame's SiteInstance are ignored. |
| 428 if (instance != root_manager->current_frame_host()->GetSiteInstance()) { | 439 if (instance != root_manager->current_frame_host()->GetSiteInstance()) { |
| 429 RenderFrameProxyHost* proxy = | 440 RenderFrameProxyHost* proxy = |
| 430 root_manager->GetRenderFrameProxyHost(instance); | 441 root_manager->GetRenderFrameProxyHost(instance); |
| 431 proxy->Send(new InputMsg_SetFocus(proxy->GetRoutingID(), is_focused)); | 442 proxy->Send(new InputMsg_SetFocus(proxy->GetRoutingID(), is_focused)); |
| 432 } | 443 } |
| 433 } | 444 } |
| 434 | 445 |
| 435 } // namespace content | 446 } // namespace content |
| OLD | NEW |