OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/accessibility/accessibility_ui.h" | 5 #include "content/browser/accessibility/accessibility_ui.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 AccessibilityMode accessibility_mode, | 74 AccessibilityMode accessibility_mode, |
75 base::ProcessHandle handle = base::kNullProcessHandle) { | 75 base::ProcessHandle handle = base::kNullProcessHandle) { |
76 std::unique_ptr<base::DictionaryValue> target_data( | 76 std::unique_ptr<base::DictionaryValue> target_data( |
77 new base::DictionaryValue()); | 77 new base::DictionaryValue()); |
78 target_data->SetInteger(kProcessIdField, process_id); | 78 target_data->SetInteger(kProcessIdField, process_id); |
79 target_data->SetInteger(kRouteIdField, route_id); | 79 target_data->SetInteger(kRouteIdField, route_id); |
80 target_data->SetString(kUrlField, url.spec()); | 80 target_data->SetString(kUrlField, url.spec()); |
81 target_data->SetString(kNameField, net::EscapeForHTML(name)); | 81 target_data->SetString(kNameField, net::EscapeForHTML(name)); |
82 target_data->SetInteger(kPidField, base::GetProcId(handle)); | 82 target_data->SetInteger(kPidField, base::GetProcId(handle)); |
83 target_data->SetString(kFaviconUrlField, favicon_url.spec()); | 83 target_data->SetString(kFaviconUrlField, favicon_url.spec()); |
84 target_data->SetInteger(kAccessibilityModeField, accessibility_mode); | 84 target_data->SetInteger(kAccessibilityModeField, accessibility_mode.get()); |
85 return target_data; | 85 return target_data; |
86 } | 86 } |
87 | 87 |
88 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor( | 88 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor( |
89 RenderViewHost* rvh) { | 89 RenderViewHost* rvh) { |
90 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 90 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
91 WebContents::FromRenderViewHost(rvh)); | 91 WebContents::FromRenderViewHost(rvh)); |
92 AccessibilityMode accessibility_mode = AccessibilityModeOff; | 92 AccessibilityMode accessibility_mode; |
93 | 93 |
94 std::string title; | 94 std::string title; |
95 GURL url; | 95 GURL url; |
96 GURL favicon_url; | 96 GURL favicon_url; |
97 if (web_contents) { | 97 if (web_contents) { |
98 // TODO(nasko): Fix the following code to use a consistent set of data | 98 // TODO(nasko): Fix the following code to use a consistent set of data |
99 // across the URL, title, and favicon. | 99 // across the URL, title, and favicon. |
100 url = web_contents->GetURL(); | 100 url = web_contents->GetURL(); |
101 title = base::UTF16ToUTF8(web_contents->GetTitle()); | 101 title = base::UTF16ToUTF8(web_contents->GetTitle()); |
102 NavigationController& controller = web_contents->GetController(); | 102 NavigationController& controller = web_contents->GetController(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 | 140 |
141 rvh_list->Append(BuildTargetDescriptor(rvh)); | 141 rvh_list->Append(BuildTargetDescriptor(rvh)); |
142 } | 142 } |
143 | 143 |
144 base::DictionaryValue data; | 144 base::DictionaryValue data; |
145 data.Set("list", rvh_list.release()); | 145 data.Set("list", rvh_list.release()); |
146 AccessibilityMode mode = | 146 AccessibilityMode mode = |
147 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); | 147 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); |
148 bool disabled = base::CommandLine::ForCurrentProcess()->HasSwitch( | 148 bool disabled = base::CommandLine::ForCurrentProcess()->HasSwitch( |
149 switches::kDisableRendererAccessibility); | 149 switches::kDisableRendererAccessibility); |
150 bool native = 0 != (mode & ACCESSIBILITY_MODE_FLAG_NATIVE_APIS); | 150 bool native = mode.hasMode(AccessibilityMode::kNativeAPIs); |
151 bool web = 0 != (mode & ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 151 bool web = mode.hasMode(AccessibilityMode::kWebContents); |
152 bool text = 0 != (mode & ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES); | 152 bool text = mode.hasMode(AccessibilityMode::kInlineTextBoxes); |
153 bool screenreader = 0 != (mode & ACCESSIBILITY_MODE_FLAG_SCREEN_READER); | 153 bool screenreader = mode.hasMode(AccessibilityMode::kScreenReader); |
154 bool html = 0 != (mode & ACCESSIBILITY_MODE_FLAG_HTML); | 154 bool html = mode.hasMode(AccessibilityMode::kHTML); |
155 | 155 |
156 // The "native" and "web" flags are disabled if | 156 // The "native" and "web" flags are disabled if |
157 // --disable-renderer-accessibility is set. | 157 // --disable-renderer-accessibility is set. |
158 data.SetString(kNative, disabled ? kDisabled : (native ? kOn : kOff)); | 158 data.SetString(kNative, disabled ? kDisabled : (native ? kOn : kOff)); |
159 data.SetString(kWeb, disabled ? kDisabled : (web ? kOn : kOff)); | 159 data.SetString(kWeb, disabled ? kDisabled : (web ? kOn : kOff)); |
160 | 160 |
161 // The "text", "screenreader", and "html" flags are only meaningful if | 161 // The "text", "screenreader", and "html" flags are only meaningful if |
162 // "web" is enabled. | 162 // "web" is enabled. |
163 data.SetString(kText, web ? (text ? kOn : kOff) : kDisabled); | 163 data.SetString(kText, web ? (text ? kOn : kOff) : kDisabled); |
164 data.SetString(kScreenReader, web ? (screenreader ? kOn : kOff) : kDisabled); | 164 data.SetString(kScreenReader, web ? (screenreader ? kOn : kOff) : kDisabled); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 216 |
217 void AccessibilityUI::ToggleAccessibility(const base::ListValue* args) { | 217 void AccessibilityUI::ToggleAccessibility(const base::ListValue* args) { |
218 std::string process_id_str; | 218 std::string process_id_str; |
219 std::string route_id_str; | 219 std::string route_id_str; |
220 int process_id; | 220 int process_id; |
221 int route_id; | 221 int route_id; |
222 int mode; | 222 int mode; |
223 CHECK_EQ(3U, args->GetSize()); | 223 CHECK_EQ(3U, args->GetSize()); |
224 CHECK(args->GetString(0, &process_id_str)); | 224 CHECK(args->GetString(0, &process_id_str)); |
225 CHECK(args->GetString(1, &route_id_str)); | 225 CHECK(args->GetString(1, &route_id_str)); |
226 // TODO(695247): We should pass each ax flag seperately | |
226 CHECK(args->GetInteger(2, &mode)); | 227 CHECK(args->GetInteger(2, &mode)); |
227 CHECK(base::StringToInt(process_id_str, &process_id)); | 228 CHECK(base::StringToInt(process_id_str, &process_id)); |
228 CHECK(base::StringToInt(route_id_str, &route_id)); | 229 CHECK(base::StringToInt(route_id_str, &route_id)); |
229 | 230 |
230 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); | 231 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); |
231 if (!rvh) | 232 if (!rvh) |
232 return; | 233 return; |
233 auto* web_contents = | 234 auto* web_contents = |
234 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); | 235 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
235 AccessibilityMode current_mode = web_contents->GetAccessibilityMode(); | 236 AccessibilityMode current_mode = web_contents->GetAccessibilityMode(); |
236 // Flip the bits represented by |mode|. See accessibility_mode_enums.h for | 237 |
237 // values. | 238 if (mode & AccessibilityMode::kNativeAPIs) |
238 current_mode ^= mode; | 239 current_mode.setMode(AccessibilityMode::kNativeAPIs, true); |
240 | |
241 if (mode & AccessibilityMode::kWebContents) | |
242 current_mode.setMode(AccessibilityMode::kWebContents, true); | |
243 | |
244 if (mode & AccessibilityMode::kInlineTextBoxes) | |
245 current_mode.setMode(AccessibilityMode::kInlineTextBoxes, true); | |
246 | |
247 if (mode & AccessibilityMode::kScreenReader) | |
248 current_mode.setMode(AccessibilityMode::kScreenReader, true); | |
249 | |
250 if (mode & AccessibilityMode::kHTML) | |
251 current_mode.setMode(AccessibilityMode::kHTML, true); | |
252 | |
239 web_contents->SetAccessibilityMode(current_mode); | 253 web_contents->SetAccessibilityMode(current_mode); |
240 } | 254 } |
241 | 255 |
242 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { | 256 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { |
243 std::string flag_name_str; | 257 std::string flag_name_str; |
244 bool enabled; | 258 bool enabled; |
245 CHECK_EQ(2U, args->GetSize()); | 259 CHECK_EQ(2U, args->GetSize()); |
246 CHECK(args->GetString(0, &flag_name_str)); | 260 CHECK(args->GetString(0, &flag_name_str)); |
247 CHECK(args->GetBoolean(1, &enabled)); | 261 CHECK(args->GetBoolean(1, &enabled)); |
248 | 262 |
249 if (flag_name_str == kInternal) { | 263 if (flag_name_str == kInternal) { |
250 g_show_internal_accessibility_tree = enabled; | 264 g_show_internal_accessibility_tree = enabled; |
251 LOG(ERROR) << "INTERNAL: " << g_show_internal_accessibility_tree; | 265 LOG(ERROR) << "INTERNAL: " << g_show_internal_accessibility_tree; |
252 return; | 266 return; |
253 } | 267 } |
254 | 268 |
255 AccessibilityMode new_mode; | 269 AccessibilityMode new_mode; |
256 if (flag_name_str == kNative) { | 270 if (flag_name_str == kNative) { |
257 new_mode = ACCESSIBILITY_MODE_FLAG_NATIVE_APIS; | 271 new_mode = AccessibilityMode::kNativeAPIs; |
258 } else if (flag_name_str == kWeb) { | 272 } else if (flag_name_str == kWeb) { |
259 new_mode = ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS; | 273 new_mode = AccessibilityMode::kWebContents; |
260 } else if (flag_name_str == kText) { | 274 } else if (flag_name_str == kText) { |
261 new_mode = ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES; | 275 new_mode = AccessibilityMode::kInlineTextBoxes; |
262 } else if (flag_name_str == kScreenReader) { | 276 } else if (flag_name_str == kScreenReader) { |
263 new_mode = ACCESSIBILITY_MODE_FLAG_SCREEN_READER; | 277 new_mode = AccessibilityMode::kScreenReader; |
264 } else if (flag_name_str == kHTML) { | 278 } else if (flag_name_str == kHTML) { |
265 new_mode = ACCESSIBILITY_MODE_FLAG_HTML; | 279 new_mode = AccessibilityMode::kHTML; |
266 } else { | 280 } else { |
267 NOTREACHED(); | 281 NOTREACHED(); |
268 return; | 282 return; |
269 } | 283 } |
270 | 284 |
271 // It doesn't make sense to enable one of the flags that depends on | 285 // It doesn't make sense to enable one of the flags that depends on |
272 // web contents without enabling web contents accessibility too. | 286 // web contents without enabling web contents accessibility too. |
273 if (enabled && | 287 if (enabled && (new_mode.hasMode(AccessibilityMode::kInlineTextBoxes) || |
274 (new_mode == ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES || | 288 new_mode.hasMode(AccessibilityMode::kScreenReader) || |
275 new_mode == ACCESSIBILITY_MODE_FLAG_SCREEN_READER || | 289 new_mode.hasMode(AccessibilityMode::kHTML))) { |
276 new_mode == ACCESSIBILITY_MODE_FLAG_HTML)) { | 290 new_mode.setMode(AccessibilityMode::kWebContents, true); |
277 new_mode |= ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS; | |
278 } | 291 } |
279 | 292 |
280 // Similarly if you disable web accessibility we should remove all | 293 // Similarly if you disable web accessibility we should remove all |
281 // flags that depend on it. | 294 // flags that depend on it. |
282 if (!enabled && new_mode == ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS) { | 295 if (!enabled && new_mode.hasMode(AccessibilityMode::kWebContents)) { |
283 new_mode |= ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES; | 296 new_mode.setMode(AccessibilityMode::kInlineTextBoxes, true); |
284 new_mode |= ACCESSIBILITY_MODE_FLAG_SCREEN_READER; | 297 new_mode.setMode(AccessibilityMode::kScreenReader, true); |
285 new_mode |= ACCESSIBILITY_MODE_FLAG_HTML; | 298 new_mode.setMode(AccessibilityMode::kHTML, true); |
286 } | 299 } |
287 | 300 |
288 BrowserAccessibilityStateImpl* state = | 301 BrowserAccessibilityStateImpl* state = |
289 BrowserAccessibilityStateImpl::GetInstance(); | 302 BrowserAccessibilityStateImpl::GetInstance(); |
290 if (enabled) | 303 if (enabled) |
291 state->AddAccessibilityModeFlags(new_mode); | 304 state->AddAccessibilityModeFlags(new_mode); |
292 else | 305 else |
293 state->RemoveAccessibilityModeFlags(new_mode); | 306 state->RemoveAccessibilityModeFlags(new_mode); |
294 } | 307 } |
295 | 308 |
(...skipping 17 matching lines...) Expand all Loading... | |
313 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", | 326 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", |
314 *(result.get())); | 327 *(result.get())); |
315 return; | 328 return; |
316 } | 329 } |
317 | 330 |
318 std::unique_ptr<base::DictionaryValue> result(BuildTargetDescriptor(rvh)); | 331 std::unique_ptr<base::DictionaryValue> result(BuildTargetDescriptor(rvh)); |
319 auto* web_contents = | 332 auto* web_contents = |
320 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); | 333 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
321 // No matter the state of the current web_contents, we want to force the mode | 334 // No matter the state of the current web_contents, we want to force the mode |
322 // because we are about to show the accessibility tree | 335 // because we are about to show the accessibility tree |
323 web_contents->SetAccessibilityMode(ACCESSIBILITY_MODE_FLAG_NATIVE_APIS | | 336 AccessibilityMode new_mode(AccessibilityMode::kNativeAPIs | |
324 ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 337 AccessibilityMode::kWebContents); |
338 | |
dmazzoni
2017/02/23 17:08:21
extremely minor nit: I wouldn't have a blank line
dougt
2017/02/27 03:12:57
Done.
| |
339 web_contents->SetAccessibilityMode(new_mode); | |
325 std::unique_ptr<AccessibilityTreeFormatter> formatter; | 340 std::unique_ptr<AccessibilityTreeFormatter> formatter; |
326 if (g_show_internal_accessibility_tree) | 341 if (g_show_internal_accessibility_tree) |
327 formatter.reset(new AccessibilityTreeFormatterBlink()); | 342 formatter.reset(new AccessibilityTreeFormatterBlink()); |
328 else | 343 else |
329 formatter.reset(AccessibilityTreeFormatter::Create()); | 344 formatter.reset(AccessibilityTreeFormatter::Create()); |
330 base::string16 accessibility_contents_utf16; | 345 base::string16 accessibility_contents_utf16; |
331 std::vector<AccessibilityTreeFormatter::Filter> filters; | 346 std::vector<AccessibilityTreeFormatter::Filter> filters; |
332 filters.push_back(AccessibilityTreeFormatter::Filter( | 347 filters.push_back(AccessibilityTreeFormatter::Filter( |
333 base::ASCIIToUTF16("*"), | 348 base::ASCIIToUTF16("*"), |
334 AccessibilityTreeFormatter::Filter::ALLOW)); | 349 AccessibilityTreeFormatter::Filter::ALLOW)); |
335 formatter->SetFilters(filters); | 350 formatter->SetFilters(filters); |
336 auto* ax_mgr = web_contents->GetOrCreateRootBrowserAccessibilityManager(); | 351 auto* ax_mgr = web_contents->GetOrCreateRootBrowserAccessibilityManager(); |
337 DCHECK(ax_mgr); | 352 DCHECK(ax_mgr); |
338 formatter->FormatAccessibilityTree(ax_mgr->GetRoot(), | 353 formatter->FormatAccessibilityTree(ax_mgr->GetRoot(), |
339 &accessibility_contents_utf16); | 354 &accessibility_contents_utf16); |
340 result->Set("tree", | 355 result->Set("tree", |
341 new base::StringValue( | 356 new base::StringValue( |
342 base::UTF16ToUTF8(accessibility_contents_utf16))); | 357 base::UTF16ToUTF8(accessibility_contents_utf16))); |
343 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", | 358 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", |
344 *(result.get())); | 359 *(result.get())); |
345 } | 360 } |
346 | 361 |
347 } // namespace content | 362 } // namespace content |
OLD | NEW |