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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 CHECK(args->GetString(0, &process_id_str)); | 302 CHECK(args->GetString(0, &process_id_str)); |
303 CHECK(args->GetString(1, &route_id_str)); | 303 CHECK(args->GetString(1, &route_id_str)); |
304 CHECK(base::StringToInt(process_id_str, &process_id)); | 304 CHECK(base::StringToInt(process_id_str, &process_id)); |
305 CHECK(base::StringToInt(route_id_str, &route_id)); | 305 CHECK(base::StringToInt(route_id_str, &route_id)); |
306 | 306 |
307 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); | 307 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); |
308 if (!rvh) { | 308 if (!rvh) { |
309 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 309 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
310 result->SetInteger(kProcessIdField, process_id); | 310 result->SetInteger(kProcessIdField, process_id); |
311 result->SetInteger(kRouteIdField, route_id); | 311 result->SetInteger(kRouteIdField, route_id); |
312 result->Set("error", new base::StringValue("Renderer no longer exists.")); | 312 result->Set("error", new base::Value("Renderer no longer exists.")); |
313 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", | 313 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", |
314 *(result.get())); | 314 *(result.get())); |
315 return; | 315 return; |
316 } | 316 } |
317 | 317 |
318 std::unique_ptr<base::DictionaryValue> result(BuildTargetDescriptor(rvh)); | 318 std::unique_ptr<base::DictionaryValue> result(BuildTargetDescriptor(rvh)); |
319 auto* web_contents = | 319 auto* web_contents = |
320 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); | 320 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
321 // No matter the state of the current web_contents, we want to force the mode | 321 // 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 | 322 // because we are about to show the accessibility tree |
323 web_contents->SetAccessibilityMode(ACCESSIBILITY_MODE_FLAG_NATIVE_APIS | | 323 web_contents->SetAccessibilityMode(ACCESSIBILITY_MODE_FLAG_NATIVE_APIS | |
324 ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 324 ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); |
325 std::unique_ptr<AccessibilityTreeFormatter> formatter; | 325 std::unique_ptr<AccessibilityTreeFormatter> formatter; |
326 if (g_show_internal_accessibility_tree) | 326 if (g_show_internal_accessibility_tree) |
327 formatter.reset(new AccessibilityTreeFormatterBlink()); | 327 formatter.reset(new AccessibilityTreeFormatterBlink()); |
328 else | 328 else |
329 formatter.reset(AccessibilityTreeFormatter::Create()); | 329 formatter.reset(AccessibilityTreeFormatter::Create()); |
330 base::string16 accessibility_contents_utf16; | 330 base::string16 accessibility_contents_utf16; |
331 std::vector<AccessibilityTreeFormatter::Filter> filters; | 331 std::vector<AccessibilityTreeFormatter::Filter> filters; |
332 filters.push_back(AccessibilityTreeFormatter::Filter( | 332 filters.push_back(AccessibilityTreeFormatter::Filter( |
333 base::ASCIIToUTF16("*"), | 333 base::ASCIIToUTF16("*"), |
334 AccessibilityTreeFormatter::Filter::ALLOW)); | 334 AccessibilityTreeFormatter::Filter::ALLOW)); |
335 formatter->SetFilters(filters); | 335 formatter->SetFilters(filters); |
336 auto* ax_mgr = web_contents->GetOrCreateRootBrowserAccessibilityManager(); | 336 auto* ax_mgr = web_contents->GetOrCreateRootBrowserAccessibilityManager(); |
337 DCHECK(ax_mgr); | 337 DCHECK(ax_mgr); |
338 formatter->FormatAccessibilityTree(ax_mgr->GetRoot(), | 338 formatter->FormatAccessibilityTree(ax_mgr->GetRoot(), |
339 &accessibility_contents_utf16); | 339 &accessibility_contents_utf16); |
340 result->Set("tree", | 340 result->Set("tree", |
341 new base::StringValue( | 341 new base::Value(base::UTF16ToUTF8(accessibility_contents_utf16))); |
342 base::UTF16ToUTF8(accessibility_contents_utf16))); | |
343 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", | 342 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", |
344 *(result.get())); | 343 *(result.get())); |
345 } | 344 } |
346 | 345 |
347 } // namespace content | 346 } // namespace content |
OLD | NEW |