OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/frame_host/frame_accessibility.h" | |
6 | |
7 #include "content/browser/frame_host/frame_tree.h" | |
8 #include "content/browser/frame_host/frame_tree_node.h" | |
9 #include "content/browser/frame_host/render_frame_host_delegate.h" | |
10 #include "content/browser/frame_host/render_frame_host_impl.h" | |
11 #include "content/public/browser/browser_context.h" | |
12 #include "content/public/browser/browser_plugin_guest_manager.h" | |
13 #include "content/public/browser/web_contents.h" | |
dmazzoni
2014/09/12 07:34:34
Currently this inclusion is not allowed.
Should I
Fady Samuel
2014/09/12 16:05:11
I can look into changing GetGuestByInstanceID to t
| |
14 | |
15 namespace content { | |
16 | |
17 // static | |
18 FrameAccessibility* FrameAccessibility::GetInstance() { | |
19 return Singleton<FrameAccessibility>::get(); | |
20 } | |
21 | |
22 FrameAccessibility::ChildFrameMapping::ChildFrameMapping() | |
23 : parent_frame_host(NULL), | |
24 accessibility_node_id(0), | |
25 child_frame_tree_node_id(0), | |
26 browser_plugin_instance_id(0) {} | |
27 | |
28 FrameAccessibility::FrameAccessibility() {} | |
29 | |
30 FrameAccessibility::~FrameAccessibility() {} | |
31 | |
32 void FrameAccessibility::AddChildFrame( | |
33 RenderFrameHostImpl* parent_frame_host, | |
34 int accessibility_node_id, | |
35 int64 child_frame_tree_node_id) { | |
36 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); | |
37 iter != mappings_.end(); | |
38 ++iter) { | |
39 if (iter->parent_frame_host == parent_frame_host && | |
40 (iter->accessibility_node_id == accessibility_node_id || | |
41 iter->child_frame_tree_node_id == child_frame_tree_node_id)) { | |
42 iter->accessibility_node_id = accessibility_node_id; | |
Charlie Reis
2014/09/11 21:46:21
What cases require us to update an existing record
dmazzoni
2014/09/12 07:34:34
There are several cases where both could change: i
Charlie Reis
2014/09/12 21:01:58
The frame routing ID might change during navigatio
| |
43 iter->child_frame_tree_node_id = child_frame_tree_node_id; | |
44 return; | |
45 } | |
46 } | |
47 | |
48 ChildFrameMapping new_mapping; | |
49 new_mapping.parent_frame_host = parent_frame_host; | |
50 new_mapping.accessibility_node_id = accessibility_node_id; | |
51 new_mapping.child_frame_tree_node_id = child_frame_tree_node_id; | |
52 mappings_.push_back(new_mapping); | |
53 } | |
54 | |
55 void FrameAccessibility::AddGuestWebContents( | |
56 RenderFrameHostImpl* parent_frame_host, | |
57 int accessibility_node_id, | |
58 int browser_plugin_instance_id) { | |
59 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); | |
60 iter != mappings_.end(); | |
61 ++iter) { | |
62 if (iter->parent_frame_host == parent_frame_host && | |
63 (iter->accessibility_node_id == accessibility_node_id || | |
64 iter->browser_plugin_instance_id == browser_plugin_instance_id)) { | |
65 iter->accessibility_node_id = accessibility_node_id; | |
66 iter->browser_plugin_instance_id = browser_plugin_instance_id; | |
67 return; | |
68 } | |
69 } | |
70 | |
71 ChildFrameMapping new_mapping; | |
72 new_mapping.parent_frame_host = parent_frame_host; | |
73 new_mapping.accessibility_node_id = accessibility_node_id; | |
74 new_mapping.browser_plugin_instance_id = browser_plugin_instance_id; | |
75 mappings_.push_back(new_mapping); | |
76 } | |
77 | |
78 void FrameAccessibility::OnRenderFrameHostDestroyed( | |
79 RenderFrameHostImpl* render_frame_host) { | |
80 // Since the order doesn't matter, the fastest way to remove all items | |
81 // with this render_frame_host is to iterate over the vector backwards, | |
82 // swapping each one with the back element if we need to delete it. | |
83 int initial_len = static_cast<int>(mappings_.size()); | |
84 for (int i = initial_len - 1; i >= 0; i--) { | |
85 if (mappings_[i].parent_frame_host == render_frame_host) { | |
86 mappings_[i] = mappings_.back(); | |
87 mappings_.pop_back(); | |
88 } | |
89 } | |
90 } | |
91 | |
92 RenderFrameHostImpl* FrameAccessibility::GetChild( | |
93 RenderFrameHostImpl* parent_frame_host, | |
94 int accessibility_node_id) { | |
95 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); | |
96 iter != mappings_.end(); | |
97 ++iter) { | |
98 if (iter->parent_frame_host != parent_frame_host || | |
99 iter->accessibility_node_id != accessibility_node_id) { | |
100 continue; | |
101 } | |
102 | |
103 if (iter->child_frame_tree_node_id) { | |
104 FrameTreeNode* child_node = | |
105 FrameTree::GloballyFindByID(iter->child_frame_tree_node_id); | |
106 if (!child_node) | |
107 return NULL; | |
108 | |
109 // We should have gotten a node in the same frame tree. | |
110 CHECK_EQ(child_node->frame_tree(), | |
111 parent_frame_host->frame_tree_node()->frame_tree()); | |
112 | |
113 return child_node->current_frame_host(); | |
114 } | |
115 | |
116 if (iter->browser_plugin_instance_id) { | |
117 WebContents* web_contents = | |
118 parent_frame_host->delegate()->GetAsWebContents(); | |
119 if (!web_contents) | |
120 continue; | |
121 BrowserPluginGuestManager* guest_manager = | |
122 web_contents->GetBrowserContext()->GetGuestManager(); | |
123 WebContents* guest = guest_manager->GetGuestByInstanceID( | |
124 web_contents, iter->browser_plugin_instance_id); | |
125 return static_cast<RenderFrameHostImpl*>(guest->GetMainFrame()); | |
126 } | |
127 } | |
128 | |
129 return NULL; | |
130 } | |
131 | |
132 bool FrameAccessibility::GetParent( | |
133 RenderFrameHostImpl* child_frame_host, | |
134 RenderFrameHostImpl** out_parent_frame_host, | |
135 int* out_accessibility_node_id) { | |
136 for (std::vector<ChildFrameMapping>::iterator iter = mappings_.begin(); | |
137 iter != mappings_.end(); | |
138 ++iter) { | |
139 if (iter->child_frame_tree_node_id) { | |
140 FrameTreeNode* child_node = | |
141 FrameTree::GloballyFindByID(iter->child_frame_tree_node_id); | |
142 if (child_node && | |
143 child_node->current_frame_host() == child_frame_host) { | |
144 if (out_parent_frame_host) | |
145 *out_parent_frame_host = iter->parent_frame_host; | |
146 if (out_accessibility_node_id) | |
147 *out_accessibility_node_id = iter->accessibility_node_id; | |
148 return true; | |
149 } | |
150 } | |
151 | |
152 if (iter->browser_plugin_instance_id) { | |
153 WebContents* web_contents = | |
154 iter->parent_frame_host->delegate()->GetAsWebContents(); | |
155 if (web_contents) { | |
156 BrowserPluginGuestManager* guest_manager = | |
157 web_contents->GetBrowserContext()->GetGuestManager(); | |
158 WebContents* guest = guest_manager->GetGuestByInstanceID( | |
159 web_contents, iter->browser_plugin_instance_id); | |
160 if (guest->GetMainFrame() == child_frame_host) { | |
161 if (out_parent_frame_host) | |
162 *out_parent_frame_host = iter->parent_frame_host; | |
163 if (out_accessibility_node_id) | |
164 *out_accessibility_node_id = iter->accessibility_node_id; | |
165 return true; | |
166 } | |
167 } | |
168 } | |
169 } | |
170 | |
171 return false; | |
172 } | |
173 | |
174 } // namespace content | |
OLD | NEW |