| 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, |
| 85 accessibility_mode.get_mode()); |
| 85 return target_data; | 86 return target_data; |
| 86 } | 87 } |
| 87 | 88 |
| 88 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor( | 89 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor( |
| 89 RenderViewHost* rvh) { | 90 RenderViewHost* rvh) { |
| 90 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 91 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 91 WebContents::FromRenderViewHost(rvh)); | 92 WebContents::FromRenderViewHost(rvh)); |
| 92 AccessibilityMode accessibility_mode = AccessibilityModeOff; | 93 AccessibilityMode accessibility_mode; |
| 93 | 94 |
| 94 std::string title; | 95 std::string title; |
| 95 GURL url; | 96 GURL url; |
| 96 GURL favicon_url; | 97 GURL favicon_url; |
| 97 if (web_contents) { | 98 if (web_contents) { |
| 98 // TODO(nasko): Fix the following code to use a consistent set of data | 99 // TODO(nasko): Fix the following code to use a consistent set of data |
| 99 // across the URL, title, and favicon. | 100 // across the URL, title, and favicon. |
| 100 url = web_contents->GetURL(); | 101 url = web_contents->GetURL(); |
| 101 title = base::UTF16ToUTF8(web_contents->GetTitle()); | 102 title = base::UTF16ToUTF8(web_contents->GetTitle()); |
| 102 NavigationController& controller = web_contents->GetController(); | 103 NavigationController& controller = web_contents->GetController(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 141 |
| 141 rvh_list->Append(BuildTargetDescriptor(rvh)); | 142 rvh_list->Append(BuildTargetDescriptor(rvh)); |
| 142 } | 143 } |
| 143 | 144 |
| 144 base::DictionaryValue data; | 145 base::DictionaryValue data; |
| 145 data.Set("list", rvh_list.release()); | 146 data.Set("list", rvh_list.release()); |
| 146 AccessibilityMode mode = | 147 AccessibilityMode mode = |
| 147 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); | 148 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); |
| 148 bool disabled = base::CommandLine::ForCurrentProcess()->HasSwitch( | 149 bool disabled = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 149 switches::kDisableRendererAccessibility); | 150 switches::kDisableRendererAccessibility); |
| 150 bool native = 0 != (mode & ACCESSIBILITY_MODE_FLAG_NATIVE_APIS); | 151 bool native = mode.has_mode(AccessibilityMode::kNativeAPIs); |
| 151 bool web = 0 != (mode & ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 152 bool web = mode.has_mode(AccessibilityMode::kWebContents); |
| 152 bool text = 0 != (mode & ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES); | 153 bool text = mode.has_mode(AccessibilityMode::kInlineTextBoxes); |
| 153 bool screenreader = 0 != (mode & ACCESSIBILITY_MODE_FLAG_SCREEN_READER); | 154 bool screenreader = mode.has_mode(AccessibilityMode::kScreenReader); |
| 154 bool html = 0 != (mode & ACCESSIBILITY_MODE_FLAG_HTML); | 155 bool html = mode.has_mode(AccessibilityMode::kHTML); |
| 155 | 156 |
| 156 // The "native" and "web" flags are disabled if | 157 // The "native" and "web" flags are disabled if |
| 157 // --disable-renderer-accessibility is set. | 158 // --disable-renderer-accessibility is set. |
| 158 data.SetString(kNative, disabled ? kDisabled : (native ? kOn : kOff)); | 159 data.SetString(kNative, disabled ? kDisabled : (native ? kOn : kOff)); |
| 159 data.SetString(kWeb, disabled ? kDisabled : (web ? kOn : kOff)); | 160 data.SetString(kWeb, disabled ? kDisabled : (web ? kOn : kOff)); |
| 160 | 161 |
| 161 // The "text", "screenreader", and "html" flags are only meaningful if | 162 // The "text", "screenreader", and "html" flags are only meaningful if |
| 162 // "web" is enabled. | 163 // "web" is enabled. |
| 163 data.SetString(kText, web ? (text ? kOn : kOff) : kDisabled); | 164 data.SetString(kText, web ? (text ? kOn : kOff) : kDisabled); |
| 164 data.SetString(kScreenReader, web ? (screenreader ? kOn : kOff) : kDisabled); | 165 data.SetString(kScreenReader, web ? (screenreader ? kOn : kOff) : kDisabled); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 217 |
| 217 void AccessibilityUI::ToggleAccessibility(const base::ListValue* args) { | 218 void AccessibilityUI::ToggleAccessibility(const base::ListValue* args) { |
| 218 std::string process_id_str; | 219 std::string process_id_str; |
| 219 std::string route_id_str; | 220 std::string route_id_str; |
| 220 int process_id; | 221 int process_id; |
| 221 int route_id; | 222 int route_id; |
| 222 int mode; | 223 int mode; |
| 223 CHECK_EQ(3U, args->GetSize()); | 224 CHECK_EQ(3U, args->GetSize()); |
| 224 CHECK(args->GetString(0, &process_id_str)); | 225 CHECK(args->GetString(0, &process_id_str)); |
| 225 CHECK(args->GetString(1, &route_id_str)); | 226 CHECK(args->GetString(1, &route_id_str)); |
| 227 // TODO(695247): We should pass each ax flag seperately |
| 226 CHECK(args->GetInteger(2, &mode)); | 228 CHECK(args->GetInteger(2, &mode)); |
| 227 CHECK(base::StringToInt(process_id_str, &process_id)); | 229 CHECK(base::StringToInt(process_id_str, &process_id)); |
| 228 CHECK(base::StringToInt(route_id_str, &route_id)); | 230 CHECK(base::StringToInt(route_id_str, &route_id)); |
| 229 | 231 |
| 230 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); | 232 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); |
| 231 if (!rvh) | 233 if (!rvh) |
| 232 return; | 234 return; |
| 233 auto* web_contents = | 235 auto* web_contents = |
| 234 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); | 236 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
| 235 AccessibilityMode current_mode = web_contents->GetAccessibilityMode(); | 237 AccessibilityMode current_mode = web_contents->GetAccessibilityMode(); |
| 236 // Flip the bits represented by |mode|. See accessibility_mode_enums.h for | 238 |
| 237 // values. | 239 if (mode & AccessibilityMode::kNativeAPIs) |
| 238 current_mode ^= mode; | 240 current_mode.set_mode(AccessibilityMode::kNativeAPIs, true); |
| 241 |
| 242 if (mode & AccessibilityMode::kWebContents) |
| 243 current_mode.set_mode(AccessibilityMode::kWebContents, true); |
| 244 |
| 245 if (mode & AccessibilityMode::kInlineTextBoxes) |
| 246 current_mode.set_mode(AccessibilityMode::kInlineTextBoxes, true); |
| 247 |
| 248 if (mode & AccessibilityMode::kScreenReader) |
| 249 current_mode.set_mode(AccessibilityMode::kScreenReader, true); |
| 250 |
| 251 if (mode & AccessibilityMode::kHTML) |
| 252 current_mode.set_mode(AccessibilityMode::kHTML, true); |
| 253 |
| 239 web_contents->SetAccessibilityMode(current_mode); | 254 web_contents->SetAccessibilityMode(current_mode); |
| 240 } | 255 } |
| 241 | 256 |
| 242 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { | 257 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { |
| 243 std::string flag_name_str; | 258 std::string flag_name_str; |
| 244 bool enabled; | 259 bool enabled; |
| 245 CHECK_EQ(2U, args->GetSize()); | 260 CHECK_EQ(2U, args->GetSize()); |
| 246 CHECK(args->GetString(0, &flag_name_str)); | 261 CHECK(args->GetString(0, &flag_name_str)); |
| 247 CHECK(args->GetBoolean(1, &enabled)); | 262 CHECK(args->GetBoolean(1, &enabled)); |
| 248 | 263 |
| 249 if (flag_name_str == kInternal) { | 264 if (flag_name_str == kInternal) { |
| 250 g_show_internal_accessibility_tree = enabled; | 265 g_show_internal_accessibility_tree = enabled; |
| 251 LOG(ERROR) << "INTERNAL: " << g_show_internal_accessibility_tree; | 266 LOG(ERROR) << "INTERNAL: " << g_show_internal_accessibility_tree; |
| 252 return; | 267 return; |
| 253 } | 268 } |
| 254 | 269 |
| 255 AccessibilityMode new_mode; | 270 AccessibilityMode new_mode; |
| 256 if (flag_name_str == kNative) { | 271 if (flag_name_str == kNative) { |
| 257 new_mode = ACCESSIBILITY_MODE_FLAG_NATIVE_APIS; | 272 new_mode = AccessibilityMode::kNativeAPIs; |
| 258 } else if (flag_name_str == kWeb) { | 273 } else if (flag_name_str == kWeb) { |
| 259 new_mode = ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS; | 274 new_mode = AccessibilityMode::kWebContents; |
| 260 } else if (flag_name_str == kText) { | 275 } else if (flag_name_str == kText) { |
| 261 new_mode = ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES; | 276 new_mode = AccessibilityMode::kInlineTextBoxes; |
| 262 } else if (flag_name_str == kScreenReader) { | 277 } else if (flag_name_str == kScreenReader) { |
| 263 new_mode = ACCESSIBILITY_MODE_FLAG_SCREEN_READER; | 278 new_mode = AccessibilityMode::kScreenReader; |
| 264 } else if (flag_name_str == kHTML) { | 279 } else if (flag_name_str == kHTML) { |
| 265 new_mode = ACCESSIBILITY_MODE_FLAG_HTML; | 280 new_mode = AccessibilityMode::kHTML; |
| 266 } else { | 281 } else { |
| 267 NOTREACHED(); | 282 NOTREACHED(); |
| 268 return; | 283 return; |
| 269 } | 284 } |
| 270 | 285 |
| 271 // It doesn't make sense to enable one of the flags that depends on | 286 // It doesn't make sense to enable one of the flags that depends on |
| 272 // web contents without enabling web contents accessibility too. | 287 // web contents without enabling web contents accessibility too. |
| 273 if (enabled && | 288 if (enabled && (new_mode.has_mode(AccessibilityMode::kInlineTextBoxes) || |
| 274 (new_mode == ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES || | 289 new_mode.has_mode(AccessibilityMode::kScreenReader) || |
| 275 new_mode == ACCESSIBILITY_MODE_FLAG_SCREEN_READER || | 290 new_mode.has_mode(AccessibilityMode::kHTML))) { |
| 276 new_mode == ACCESSIBILITY_MODE_FLAG_HTML)) { | 291 new_mode.set_mode(AccessibilityMode::kWebContents, true); |
| 277 new_mode |= ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS; | |
| 278 } | 292 } |
| 279 | 293 |
| 280 // Similarly if you disable web accessibility we should remove all | 294 // Similarly if you disable web accessibility we should remove all |
| 281 // flags that depend on it. | 295 // flags that depend on it. |
| 282 if (!enabled && new_mode == ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS) { | 296 if (!enabled && new_mode.has_mode(AccessibilityMode::kWebContents)) { |
| 283 new_mode |= ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES; | 297 new_mode.set_mode(AccessibilityMode::kInlineTextBoxes, true); |
| 284 new_mode |= ACCESSIBILITY_MODE_FLAG_SCREEN_READER; | 298 new_mode.set_mode(AccessibilityMode::kScreenReader, true); |
| 285 new_mode |= ACCESSIBILITY_MODE_FLAG_HTML; | 299 new_mode.set_mode(AccessibilityMode::kHTML, true); |
| 286 } | 300 } |
| 287 | 301 |
| 288 BrowserAccessibilityStateImpl* state = | 302 BrowserAccessibilityStateImpl* state = |
| 289 BrowserAccessibilityStateImpl::GetInstance(); | 303 BrowserAccessibilityStateImpl::GetInstance(); |
| 290 if (enabled) | 304 if (enabled) |
| 291 state->AddAccessibilityModeFlags(new_mode); | 305 state->AddAccessibilityModeFlags(new_mode); |
| 292 else | 306 else |
| 293 state->RemoveAccessibilityModeFlags(new_mode); | 307 state->RemoveAccessibilityModeFlags(new_mode); |
| 294 } | 308 } |
| 295 | 309 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 313 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", | 327 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", |
| 314 *(result.get())); | 328 *(result.get())); |
| 315 return; | 329 return; |
| 316 } | 330 } |
| 317 | 331 |
| 318 std::unique_ptr<base::DictionaryValue> result(BuildTargetDescriptor(rvh)); | 332 std::unique_ptr<base::DictionaryValue> result(BuildTargetDescriptor(rvh)); |
| 319 auto* web_contents = | 333 auto* web_contents = |
| 320 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); | 334 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
| 321 // No matter the state of the current web_contents, we want to force the mode | 335 // 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 | 336 // because we are about to show the accessibility tree |
| 323 web_contents->SetAccessibilityMode(ACCESSIBILITY_MODE_FLAG_NATIVE_APIS | | 337 web_contents->SetAccessibilityMode(AccessibilityMode( |
| 324 ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 338 AccessibilityMode::kNativeAPIs | AccessibilityMode::kWebContents)); |
| 339 |
| 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 |