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/accessibility/accessibility_tree_formatter.h" | 5 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
6 | 6 |
7 #include <oleacc.h> | 7 #include <oleacc.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_piece.h" |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/win/scoped_bstr.h" |
| 18 #include "base/win/scoped_comptr.h" |
16 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h
" | 19 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h
" |
17 #include "content/browser/accessibility/browser_accessibility_manager.h" | 20 #include "content/browser/accessibility/browser_accessibility_manager.h" |
18 #include "content/browser/accessibility/browser_accessibility_win.h" | 21 #include "content/browser/accessibility/browser_accessibility_win.h" |
19 #include "third_party/iaccessible2/ia2_api_all.h" | 22 #include "third_party/iaccessible2/ia2_api_all.h" |
20 #include "ui/base/win/atl_module.h" | 23 #include "ui/base/win/atl_module.h" |
21 | 24 |
22 using base::StringPrintf; | 25 using base::StringPrintf; |
23 | 26 |
24 namespace content { | 27 namespace content { |
25 | 28 |
(...skipping 27 matching lines...) Expand all Loading... |
53 "selection_end" | 56 "selection_end" |
54 }; | 57 }; |
55 | 58 |
56 void AccessibilityTreeFormatter::Initialize() { | 59 void AccessibilityTreeFormatter::Initialize() { |
57 ui::win::CreateATLModuleIfNeeded(); | 60 ui::win::CreateATLModuleIfNeeded(); |
58 } | 61 } |
59 | 62 |
60 void AccessibilityTreeFormatter::AddProperties( | 63 void AccessibilityTreeFormatter::AddProperties( |
61 const BrowserAccessibility& node, base::DictionaryValue* dict) { | 64 const BrowserAccessibility& node, base::DictionaryValue* dict) { |
62 dict->SetInteger("id", node.GetId()); | 65 dict->SetInteger("id", node.GetId()); |
63 BrowserAccessibilityWin* acc_obj = | 66 BrowserAccessibilityWin* ax_object = |
64 const_cast<BrowserAccessibility*>(&node)->ToBrowserAccessibilityWin(); | 67 const_cast<BrowserAccessibility*>(&node)->ToBrowserAccessibilityWin(); |
| 68 DCHECK(ax_object); |
65 | 69 |
66 VARIANT variant_self; | 70 VARIANT variant_self; |
67 variant_self.vt = VT_I4; | 71 variant_self.vt = VT_I4; |
68 variant_self.lVal = CHILDID_SELF; | 72 variant_self.lVal = CHILDID_SELF; |
69 | 73 |
70 dict->SetString("role", IAccessible2RoleToString(acc_obj->ia2_role())); | 74 dict->SetString("role", IAccessible2RoleToString(ax_object->ia2_role())); |
71 | 75 |
72 CComBSTR msaa_variant; | 76 base::win::ScopedBstr temp_bstr; |
73 HRESULT hresult = acc_obj->get_accName(variant_self, &msaa_variant); | 77 if (SUCCEEDED(ax_object->get_accName(variant_self, temp_bstr.Receive()))) |
74 if (hresult == S_OK) | 78 dict->SetString("name", base::string16(temp_bstr, temp_bstr.Length())); |
75 dict->SetString("name", msaa_variant.m_str); | 79 temp_bstr.Reset(); |
76 hresult = acc_obj->get_accValue(variant_self, &msaa_variant); | 80 |
77 if (hresult == S_OK) | 81 if (SUCCEEDED(ax_object->get_accValue(variant_self, temp_bstr.Receive()))) |
78 dict->SetString("value", msaa_variant.m_str); | 82 dict->SetString("value", base::string16(temp_bstr, temp_bstr.Length())); |
| 83 temp_bstr.Reset(); |
79 | 84 |
80 std::vector<base::string16> state_strings; | 85 std::vector<base::string16> state_strings; |
81 int32 ia_state = acc_obj->ia_state(); | 86 int32 ia_state = ax_object->ia_state(); |
82 | 87 |
83 // Avoid flakiness: these states depend on whether the window is focused | 88 // Avoid flakiness: these states depend on whether the window is focused |
84 // and the position of the mouse cursor. | 89 // and the position of the mouse cursor. |
85 ia_state &= ~STATE_SYSTEM_HOTTRACKED; | 90 ia_state &= ~STATE_SYSTEM_HOTTRACKED; |
86 ia_state &= ~STATE_SYSTEM_OFFSCREEN; | 91 ia_state &= ~STATE_SYSTEM_OFFSCREEN; |
87 | 92 |
88 IAccessibleStateToStringVector(ia_state, &state_strings); | 93 IAccessibleStateToStringVector(ia_state, &state_strings); |
89 IAccessible2StateToStringVector(acc_obj->ia2_state(), &state_strings); | 94 IAccessible2StateToStringVector(ax_object->ia2_state(), &state_strings); |
90 base::ListValue* states = new base::ListValue; | 95 base::ListValue* states = new base::ListValue; |
91 for (std::vector<base::string16>::const_iterator it = state_strings.begin(); | 96 for (auto it = state_strings.begin(); it != state_strings.end(); ++it) |
92 it != state_strings.end(); | |
93 ++it) { | |
94 states->AppendString(base::UTF16ToUTF8(*it)); | 97 states->AppendString(base::UTF16ToUTF8(*it)); |
95 } | |
96 dict->Set("states", states); | 98 dict->Set("states", states); |
97 | 99 |
98 const std::vector<base::string16>& ia2_attributes = acc_obj->ia2_attributes(); | 100 const std::vector<base::string16>& ia2_attributes = |
| 101 ax_object->ia2_attributes(); |
99 base::ListValue* attributes = new base::ListValue; | 102 base::ListValue* attributes = new base::ListValue; |
100 for (std::vector<base::string16>::const_iterator it = ia2_attributes.begin(); | 103 for (auto it = ia2_attributes.begin(); it != ia2_attributes.end(); ++it) |
101 it != ia2_attributes.end(); | |
102 ++it) { | |
103 attributes->AppendString(base::UTF16ToUTF8(*it)); | 104 attributes->AppendString(base::UTF16ToUTF8(*it)); |
104 } | |
105 dict->Set("attributes", attributes); | 105 dict->Set("attributes", attributes); |
106 | 106 |
107 dict->SetString("role_name", acc_obj->role_name()); | 107 dict->SetString("role_name", ax_object->role_name()); |
108 | 108 |
109 VARIANT currentValue; | 109 VARIANT currentValue; |
110 if (acc_obj->get_currentValue(¤tValue) == S_OK) | 110 if (ax_object->get_currentValue(¤tValue) == S_OK) |
111 dict->SetDouble("currentValue", V_R8(¤tValue)); | 111 dict->SetDouble("currentValue", V_R8(¤tValue)); |
112 | 112 |
113 VARIANT minimumValue; | 113 VARIANT minimumValue; |
114 if (acc_obj->get_minimumValue(&minimumValue) == S_OK) | 114 if (ax_object->get_minimumValue(&minimumValue) == S_OK) |
115 dict->SetDouble("minimumValue", V_R8(&minimumValue)); | 115 dict->SetDouble("minimumValue", V_R8(&minimumValue)); |
116 | 116 |
117 VARIANT maximumValue; | 117 VARIANT maximumValue; |
118 if (acc_obj->get_maximumValue(&maximumValue) == S_OK) | 118 if (ax_object->get_maximumValue(&maximumValue) == S_OK) |
119 dict->SetDouble("maximumValue", V_R8(&maximumValue)); | 119 dict->SetDouble("maximumValue", V_R8(&maximumValue)); |
120 | 120 |
121 hresult = acc_obj->get_accDescription(variant_self, &msaa_variant); | 121 if (SUCCEEDED(ax_object->get_accDescription(variant_self, |
122 if (hresult == S_OK) | 122 temp_bstr.Receive()))) { |
123 dict->SetString("description", msaa_variant.m_str); | 123 dict->SetString("description", base::string16(temp_bstr, |
| 124 temp_bstr.Length())); |
| 125 } |
| 126 temp_bstr.Reset(); |
124 | 127 |
125 hresult = acc_obj->get_accDefaultAction(variant_self, &msaa_variant); | 128 if (SUCCEEDED(ax_object->get_accDefaultAction(variant_self, |
126 if (hresult == S_OK) | 129 temp_bstr.Receive()))) { |
127 dict->SetString("default_action", msaa_variant.m_str); | 130 dict->SetString("default_action", base::string16(temp_bstr, |
| 131 temp_bstr.Length())); |
| 132 } |
| 133 temp_bstr.Reset(); |
128 | 134 |
129 hresult = acc_obj->get_accKeyboardShortcut(variant_self, &msaa_variant); | 135 if (SUCCEEDED( |
130 if (hresult == S_OK) | 136 ax_object->get_accKeyboardShortcut(variant_self, temp_bstr.Receive()))) { |
131 dict->SetString("keyboard_shortcut", msaa_variant.m_str); | 137 dict->SetString("keyboard_shortcut", base::string16(temp_bstr, |
| 138 temp_bstr.Length())); |
| 139 } |
| 140 temp_bstr.Reset(); |
132 | 141 |
133 hresult = acc_obj->get_accHelp(variant_self, &msaa_variant); | 142 if (SUCCEEDED(ax_object->get_accHelp(variant_self, temp_bstr.Receive()))) |
134 if (S_OK == hresult) | 143 dict->SetString("help", base::string16(temp_bstr, temp_bstr.Length())); |
135 dict->SetString("help", msaa_variant.m_str); | 144 temp_bstr.Reset(); |
136 | 145 |
137 BrowserAccessibility* root = node.manager()->GetRoot(); | 146 BrowserAccessibility* root = node.manager()->GetRoot(); |
138 LONG left, top, width, height; | 147 LONG left, top, width, height; |
139 LONG root_left, root_top, root_width, root_height; | 148 LONG root_left, root_top, root_width, root_height; |
140 if (acc_obj->accLocation(&left, &top, &width, &height, variant_self) | 149 if (SUCCEEDED(ax_object->accLocation( |
141 != S_FALSE | 150 &left, &top, &width, &height, variant_self)) && |
142 && root->ToBrowserAccessibilityWin()->accLocation( | 151 SUCCEEDED(root->ToBrowserAccessibilityWin()->accLocation( |
143 &root_left, &root_top, &root_width, &root_height, variant_self) | 152 &root_left, &root_top, &root_width, &root_height, variant_self))) { |
144 != S_FALSE) { | |
145 base::DictionaryValue* location = new base::DictionaryValue; | 153 base::DictionaryValue* location = new base::DictionaryValue; |
146 location->SetInteger("x", left - root_left); | 154 location->SetInteger("x", left - root_left); |
147 location->SetInteger("y", top - root_top); | 155 location->SetInteger("y", top - root_top); |
148 dict->Set("location", location); | 156 dict->Set("location", location); |
149 | 157 |
150 base::DictionaryValue* size = new base::DictionaryValue; | 158 base::DictionaryValue* size = new base::DictionaryValue; |
151 size->SetInteger("width", width); | 159 size->SetInteger("width", width); |
152 size->SetInteger("height", height); | 160 size->SetInteger("height", height); |
153 dict->Set("size", size); | 161 dict->Set("size", size); |
154 } | 162 } |
155 | 163 |
156 LONG index_in_parent; | 164 LONG index_in_parent; |
157 if (acc_obj->get_indexInParent(&index_in_parent) == S_OK) | 165 if (SUCCEEDED(ax_object->get_indexInParent(&index_in_parent))) |
158 dict->SetInteger("index_in_parent", index_in_parent); | 166 dict->SetInteger("index_in_parent", index_in_parent); |
159 | 167 |
160 LONG n_relations; | 168 LONG n_relations; |
161 if (acc_obj->get_nRelations(&n_relations) == S_OK) | 169 if (SUCCEEDED(ax_object->get_nRelations(&n_relations))) |
162 dict->SetInteger("n_relations", n_relations); | 170 dict->SetInteger("n_relations", n_relations); |
163 | 171 |
164 LONG group_level, similar_items_in_group, position_in_group; | 172 LONG group_level, similar_items_in_group, position_in_group; |
165 if (acc_obj->get_groupPosition(&group_level, | 173 if (SUCCEEDED(ax_object->get_groupPosition(&group_level, |
166 &similar_items_in_group, | 174 &similar_items_in_group, |
167 &position_in_group) == S_OK) { | 175 &position_in_group))) { |
168 dict->SetInteger("group_level", group_level); | 176 dict->SetInteger("group_level", group_level); |
169 dict->SetInteger("similar_items_in_group", similar_items_in_group); | 177 dict->SetInteger("similar_items_in_group", similar_items_in_group); |
170 dict->SetInteger("position_in_group", position_in_group); | 178 dict->SetInteger("position_in_group", position_in_group); |
171 } | 179 } |
| 180 |
172 LONG table_rows; | 181 LONG table_rows; |
173 if (acc_obj->get_nRows(&table_rows) == S_OK) | 182 if (SUCCEEDED(ax_object->get_nRows(&table_rows))) |
174 dict->SetInteger("table_rows", table_rows); | 183 dict->SetInteger("table_rows", table_rows); |
| 184 |
175 LONG table_columns; | 185 LONG table_columns; |
176 if (acc_obj->get_nRows(&table_columns) == S_OK) | 186 if (SUCCEEDED(ax_object->get_nRows(&table_columns))) |
177 dict->SetInteger("table_columns", table_columns); | 187 dict->SetInteger("table_columns", table_columns); |
| 188 |
178 LONG row_index; | 189 LONG row_index; |
179 if (acc_obj->get_rowIndex(&row_index) == S_OK) | 190 if (SUCCEEDED(ax_object->get_rowIndex(&row_index))) |
180 dict->SetInteger("row_index", row_index); | 191 dict->SetInteger("row_index", row_index); |
| 192 |
181 LONG column_index; | 193 LONG column_index; |
182 if (acc_obj->get_columnIndex(&column_index) == S_OK) | 194 if (SUCCEEDED(ax_object->get_columnIndex(&column_index))) |
183 dict->SetInteger("column_index", column_index); | 195 dict->SetInteger("column_index", column_index); |
| 196 |
184 LONG n_characters; | 197 LONG n_characters; |
185 if (acc_obj->get_nCharacters(&n_characters) == S_OK) | 198 if (SUCCEEDED(ax_object->get_nCharacters(&n_characters))) |
186 dict->SetInteger("n_characters", n_characters); | 199 dict->SetInteger("n_characters", n_characters); |
| 200 |
187 LONG caret_offset; | 201 LONG caret_offset; |
188 if (acc_obj->get_caretOffset(&caret_offset) == S_OK) | 202 if (ax_object->get_caretOffset(&caret_offset) == S_OK) |
189 dict->SetInteger("caret_offset", caret_offset); | 203 dict->SetInteger("caret_offset", caret_offset); |
| 204 |
190 LONG n_selections; | 205 LONG n_selections; |
191 if (acc_obj->get_nSelections(&n_selections) == S_OK) { | 206 if (SUCCEEDED(ax_object->get_nSelections(&n_selections))) { |
192 dict->SetInteger("n_selections", n_selections); | 207 dict->SetInteger("n_selections", n_selections); |
193 if (n_selections > 0) { | 208 if (n_selections > 0) { |
194 LONG start, end; | 209 LONG start, end; |
195 if (acc_obj->get_selection(0, &start, &end) == S_OK) { | 210 if (SUCCEEDED(ax_object->get_selection(0, &start, &end))) { |
196 dict->SetInteger("selection_start", start); | 211 dict->SetInteger("selection_start", start); |
197 dict->SetInteger("selection_end", end); | 212 dict->SetInteger("selection_end", end); |
198 } | 213 } |
199 } | 214 } |
200 } | 215 } |
201 } | 216 } |
202 | 217 |
203 base::string16 AccessibilityTreeFormatter::ToString( | 218 base::string16 AccessibilityTreeFormatter::ToString( |
204 const base::DictionaryValue& dict) { | 219 const base::DictionaryValue& dict) { |
205 base::string16 line; | 220 base::string16 line; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 const std::string AccessibilityTreeFormatter::GetAllowString() { | 329 const std::string AccessibilityTreeFormatter::GetAllowString() { |
315 return "@WIN-ALLOW:"; | 330 return "@WIN-ALLOW:"; |
316 } | 331 } |
317 | 332 |
318 // static | 333 // static |
319 const std::string AccessibilityTreeFormatter::GetDenyString() { | 334 const std::string AccessibilityTreeFormatter::GetDenyString() { |
320 return "@WIN-DENY:"; | 335 return "@WIN-DENY:"; |
321 } | 336 } |
322 | 337 |
323 } // namespace content | 338 } // namespace content |
OLD | NEW |