OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_accessibility.h" | 5 #include "content/browser/frame_host/frame_accessibility.h" |
6 | 6 |
7 #include "content/browser/frame_host/frame_tree.h" | 7 #include "content/browser/frame_host/frame_tree.h" |
8 #include "content/browser/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
9 #include "content/browser/frame_host/render_frame_host_delegate.h" | 9 #include "content/browser/frame_host/render_frame_host_delegate.h" |
10 #include "content/browser/frame_host/render_frame_host_impl.h" | 10 #include "content/browser/frame_host/render_frame_host_impl.h" |
11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 // static | 15 // static |
16 FrameAccessibility* FrameAccessibility::GetInstance() { | 16 FrameAccessibility* FrameAccessibility::GetInstance() { |
17 return Singleton<FrameAccessibility>::get(); | 17 return Singleton<FrameAccessibility>::get(); |
18 } | 18 } |
19 | 19 |
20 FrameAccessibility::ChildFrameMapping::ChildFrameMapping() | 20 FrameAccessibility::ChildFrameMapping::ChildFrameMapping() |
21 : parent_frame_host(NULL), | 21 : parent_frame_host(nullptr), |
22 accessibility_node_id(0), | 22 accessibility_node_id(0), |
23 child_frame_tree_node_id(0), | 23 child_frame_tree_node_id(0), |
24 browser_plugin_instance_id(0) {} | 24 browser_plugin_instance_id(0) {} |
25 | 25 |
26 FrameAccessibility::FrameAccessibility() {} | 26 FrameAccessibility::FrameAccessibility() {} |
27 | 27 |
28 FrameAccessibility::~FrameAccessibility() {} | 28 FrameAccessibility::~FrameAccessibility() {} |
29 | 29 |
30 void FrameAccessibility::AddChildFrame( | 30 void FrameAccessibility::AddChildFrame( |
31 RenderFrameHostImpl* parent_frame_host, | 31 RenderFrameHostImpl* parent_frame_host, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 int accessibility_node_id) { | 98 int accessibility_node_id) { |
99 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); | 99 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); |
100 iter != mappings_.end(); | 100 iter != mappings_.end(); |
101 ++iter) { | 101 ++iter) { |
102 if (iter->parent_frame_host != parent_frame_host || | 102 if (iter->parent_frame_host != parent_frame_host || |
103 iter->accessibility_node_id != accessibility_node_id) { | 103 iter->accessibility_node_id != accessibility_node_id) { |
104 continue; | 104 continue; |
105 } | 105 } |
106 | 106 |
107 if (iter->child_frame_tree_node_id) { | 107 if (iter->child_frame_tree_node_id) { |
108 FrameTreeNode* child_node = | 108 return GetRFHIFromFrameTreeNodeId( |
109 FrameTree::GloballyFindByID(iter->child_frame_tree_node_id); | 109 parent_frame_host, iter->child_frame_tree_node_id); |
110 if (!child_node) | |
111 return NULL; | |
112 | |
113 // We should have gotten a node in the same frame tree. | |
114 if (child_node->frame_tree() != | |
115 parent_frame_host->frame_tree_node()->frame_tree()) { | |
116 NOTREACHED(); | |
117 return NULL; | |
118 } | |
119 | |
120 return child_node->current_frame_host(); | |
121 } | 110 } |
122 | 111 |
123 if (iter->browser_plugin_instance_id) { | 112 if (iter->browser_plugin_instance_id) { |
124 RenderFrameHost* guest = | 113 RenderFrameHost* guest = |
125 parent_frame_host->delegate()->GetGuestByInstanceID( | 114 parent_frame_host->delegate()->GetGuestByInstanceID( |
126 iter->browser_plugin_instance_id); | 115 iter->browser_plugin_instance_id); |
127 if (guest) | 116 if (guest) |
128 return static_cast<RenderFrameHostImpl*>(guest); | 117 return static_cast<RenderFrameHostImpl*>(guest); |
129 } | 118 } |
130 } | 119 } |
131 | 120 |
132 return NULL; | 121 return nullptr; |
| 122 } |
| 123 |
| 124 void FrameAccessibility::GetAllChildFrames( |
| 125 RenderFrameHostImpl* parent_frame_host, |
| 126 std::vector<RenderFrameHostImpl*>* child_frame_hosts) { |
| 127 CHECK(child_frame_hosts); |
| 128 |
| 129 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); |
| 130 iter != mappings_.end(); |
| 131 ++iter) { |
| 132 if (iter->parent_frame_host != parent_frame_host) |
| 133 continue; |
| 134 |
| 135 if (iter->child_frame_tree_node_id) { |
| 136 RenderFrameHostImpl* child_frame_host = GetRFHIFromFrameTreeNodeId( |
| 137 parent_frame_host, iter->child_frame_tree_node_id); |
| 138 if (child_frame_host) |
| 139 child_frame_hosts->push_back(child_frame_host); |
| 140 } |
| 141 |
| 142 if (iter->browser_plugin_instance_id) { |
| 143 RenderFrameHost* guest = |
| 144 parent_frame_host->delegate()->GetGuestByInstanceID( |
| 145 iter->browser_plugin_instance_id); |
| 146 if (guest) |
| 147 child_frame_hosts->push_back(static_cast<RenderFrameHostImpl*>(guest)); |
| 148 } |
| 149 } |
133 } | 150 } |
134 | 151 |
135 bool FrameAccessibility::GetParent( | 152 bool FrameAccessibility::GetParent( |
136 RenderFrameHostImpl* child_frame_host, | 153 RenderFrameHostImpl* child_frame_host, |
137 RenderFrameHostImpl** out_parent_frame_host, | 154 RenderFrameHostImpl** out_parent_frame_host, |
138 int* out_accessibility_node_id) { | 155 int* out_accessibility_node_id) { |
139 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); | 156 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); |
140 iter != mappings_.end(); | 157 iter != mappings_.end(); |
141 ++iter) { | 158 ++iter) { |
142 if (iter->child_frame_tree_node_id) { | 159 if (iter->child_frame_tree_node_id) { |
143 FrameTreeNode* child_node = | 160 FrameTreeNode* child_node = |
144 FrameTree::GloballyFindByID(iter->child_frame_tree_node_id); | 161 FrameTree::GloballyFindByID(iter->child_frame_tree_node_id); |
145 if (child_node && | 162 if (child_node && |
146 child_node->current_frame_host() == child_frame_host) { | 163 child_node->current_frame_host() == child_frame_host) { |
147 // We should have gotten a node in the same frame tree. | 164 // We should have gotten a *direct* child of the parent frame. |
148 if (child_node->frame_tree() != | 165 if (child_node->parent() != |
149 iter->parent_frame_host->frame_tree_node()->frame_tree()) { | 166 iter->parent_frame_host->frame_tree_node()) { |
150 NOTREACHED(); | 167 NOTREACHED(); |
151 return false; | 168 return false; |
152 } | 169 } |
153 | 170 |
154 if (out_parent_frame_host) | 171 if (out_parent_frame_host) |
155 *out_parent_frame_host = iter->parent_frame_host; | 172 *out_parent_frame_host = iter->parent_frame_host; |
156 if (out_accessibility_node_id) | 173 if (out_accessibility_node_id) |
157 *out_accessibility_node_id = iter->accessibility_node_id; | 174 *out_accessibility_node_id = iter->accessibility_node_id; |
158 return true; | 175 return true; |
159 } | 176 } |
160 } | 177 } |
161 | 178 |
162 if (iter->browser_plugin_instance_id) { | 179 if (iter->browser_plugin_instance_id) { |
163 RenderFrameHost* guest = | 180 RenderFrameHost* guest = |
164 iter->parent_frame_host->delegate()->GetGuestByInstanceID( | 181 iter->parent_frame_host->delegate()->GetGuestByInstanceID( |
165 iter->browser_plugin_instance_id); | 182 iter->browser_plugin_instance_id); |
166 if (guest == child_frame_host) { | 183 if (guest == child_frame_host) { |
167 if (out_parent_frame_host) | 184 if (out_parent_frame_host) |
168 *out_parent_frame_host = iter->parent_frame_host; | 185 *out_parent_frame_host = iter->parent_frame_host; |
169 if (out_accessibility_node_id) | 186 if (out_accessibility_node_id) |
170 *out_accessibility_node_id = iter->accessibility_node_id; | 187 *out_accessibility_node_id = iter->accessibility_node_id; |
171 return true; | 188 return true; |
172 } | 189 } |
173 } | 190 } |
174 } | 191 } |
175 | 192 |
176 return false; | 193 return false; |
177 } | 194 } |
178 | 195 |
| 196 RenderFrameHostImpl* FrameAccessibility::GetRFHIFromFrameTreeNodeId( |
| 197 RenderFrameHostImpl* parent_frame_host, |
| 198 int64 child_frame_tree_node_id) { |
| 199 FrameTreeNode* child_node = |
| 200 FrameTree::GloballyFindByID(child_frame_tree_node_id); |
| 201 if (!child_node) |
| 202 return nullptr; |
| 203 |
| 204 // We should have gotten a *direct* child of the parent frame. |
| 205 if (child_node->parent() != parent_frame_host->frame_tree_node()) { |
| 206 NOTREACHED(); |
| 207 return nullptr; |
| 208 } |
| 209 |
| 210 return child_node->current_frame_host(); |
| 211 } |
| 212 |
179 } // namespace content | 213 } // namespace content |
OLD | NEW |