| 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.has(AccessibilityMode::NATIVE_APIS); |
| 151 bool web = 0 != (mode & ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 151 bool web = mode.has(AccessibilityMode::WEB_CONTENTS); |
| 152 bool text = 0 != (mode & ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES); | 152 bool text = mode.has(AccessibilityMode::INLINE_TEXT_BOXES); |
| 153 bool screenreader = 0 != (mode & ACCESSIBILITY_MODE_FLAG_SCREEN_READER); | 153 bool screenreader = mode.has(AccessibilityMode::SCREEN_READER); |
| 154 bool html = 0 != (mode & ACCESSIBILITY_MODE_FLAG_HTML); | 154 bool html = mode.has(AccessibilityMode::HTML); |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 CHECK(args->GetInteger(2, &mode)); | 226 CHECK(args->GetInteger(2, &mode)); |
| 227 CHECK(base::StringToInt(process_id_str, &process_id)); | 227 CHECK(base::StringToInt(process_id_str, &process_id)); |
| 228 CHECK(base::StringToInt(route_id_str, &route_id)); | 228 CHECK(base::StringToInt(route_id_str, &route_id)); |
| 229 | 229 |
| 230 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); | 230 RenderViewHost* rvh = RenderViewHost::FromID(process_id, route_id); |
| 231 if (!rvh) | 231 if (!rvh) |
| 232 return; | 232 return; |
| 233 auto* web_contents = | 233 auto* web_contents = |
| 234 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); | 234 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
| 235 AccessibilityMode current_mode = web_contents->GetAccessibilityMode(); | 235 AccessibilityMode current_mode = web_contents->GetAccessibilityMode(); |
| 236 // Flip the bits represented by |mode|. See accessibility_mode_enums.h for | 236 current_mode.toggle(mode); |
| 237 // values. | 237 |
| 238 current_mode ^= mode; | |
| 239 web_contents->SetAccessibilityMode(current_mode); | 238 web_contents->SetAccessibilityMode(current_mode); |
| 240 } | 239 } |
| 241 | 240 |
| 242 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { | 241 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { |
| 243 std::string flag_name_str; | 242 std::string flag_name_str; |
| 244 bool enabled; | 243 bool enabled; |
| 245 CHECK_EQ(2U, args->GetSize()); | 244 CHECK_EQ(2U, args->GetSize()); |
| 246 CHECK(args->GetString(0, &flag_name_str)); | 245 CHECK(args->GetString(0, &flag_name_str)); |
| 247 CHECK(args->GetBoolean(1, &enabled)); | 246 CHECK(args->GetBoolean(1, &enabled)); |
| 248 | 247 |
| 249 if (flag_name_str == kInternal) { | 248 if (flag_name_str == kInternal) { |
| 250 g_show_internal_accessibility_tree = enabled; | 249 g_show_internal_accessibility_tree = enabled; |
| 251 LOG(ERROR) << "INTERNAL: " << g_show_internal_accessibility_tree; | 250 LOG(ERROR) << "INTERNAL: " << g_show_internal_accessibility_tree; |
| 252 return; | 251 return; |
| 253 } | 252 } |
| 254 | 253 |
| 255 AccessibilityMode new_mode; | 254 AccessibilityMode new_mode; |
| 256 if (flag_name_str == kNative) { | 255 if (flag_name_str == kNative) { |
| 257 new_mode = ACCESSIBILITY_MODE_FLAG_NATIVE_APIS; | 256 new_mode = AccessibilityMode::NATIVE_APIS; |
| 258 } else if (flag_name_str == kWeb) { | 257 } else if (flag_name_str == kWeb) { |
| 259 new_mode = ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS; | 258 new_mode = AccessibilityMode::WEB_CONTENTS; |
| 260 } else if (flag_name_str == kText) { | 259 } else if (flag_name_str == kText) { |
| 261 new_mode = ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES; | 260 new_mode = AccessibilityMode::INLINE_TEXT_BOXES; |
| 262 } else if (flag_name_str == kScreenReader) { | 261 } else if (flag_name_str == kScreenReader) { |
| 263 new_mode = ACCESSIBILITY_MODE_FLAG_SCREEN_READER; | 262 new_mode = AccessibilityMode::SCREEN_READER; |
| 264 } else if (flag_name_str == kHTML) { | 263 } else if (flag_name_str == kHTML) { |
| 265 new_mode = ACCESSIBILITY_MODE_FLAG_HTML; | 264 new_mode = AccessibilityMode::HTML; |
| 266 } else { | 265 } else { |
| 267 NOTREACHED(); | 266 NOTREACHED(); |
| 268 return; | 267 return; |
| 269 } | 268 } |
| 270 | 269 |
| 271 // It doesn't make sense to enable one of the flags that depends on | 270 // It doesn't make sense to enable one of the flags that depends on |
| 272 // web contents without enabling web contents accessibility too. | 271 // web contents without enabling web contents accessibility too. |
| 273 if (enabled && | 272 if (enabled && (new_mode.has(AccessibilityMode::INLINE_TEXT_BOXES) || |
| 274 (new_mode == ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES || | 273 new_mode.has(AccessibilityMode::SCREEN_READER) || |
| 275 new_mode == ACCESSIBILITY_MODE_FLAG_SCREEN_READER || | 274 new_mode.has(AccessibilityMode::HTML))) { |
| 276 new_mode == ACCESSIBILITY_MODE_FLAG_HTML)) { | 275 new_mode.set(AccessibilityMode::WEB_CONTENTS); |
| 277 new_mode |= ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS; | |
| 278 } | 276 } |
| 279 | 277 |
| 280 // Similarly if you disable web accessibility we should remove all | 278 // Similarly if you disable web accessibility we should remove all |
| 281 // flags that depend on it. | 279 // flags that depend on it. |
| 282 if (!enabled && new_mode == ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS) { | 280 if (!enabled && new_mode.has(AccessibilityMode::WEB_CONTENTS)) { |
| 283 new_mode |= ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES; | 281 new_mode.set(AccessibilityMode::INLINE_TEXT_BOXES | |
| 284 new_mode |= ACCESSIBILITY_MODE_FLAG_SCREEN_READER; | 282 AccessibilityMode::SCREEN_READER | AccessibilityMode::HTML); |
| 285 new_mode |= ACCESSIBILITY_MODE_FLAG_HTML; | |
| 286 } | 283 } |
| 287 | 284 |
| 288 BrowserAccessibilityStateImpl* state = | 285 BrowserAccessibilityStateImpl* state = |
| 289 BrowserAccessibilityStateImpl::GetInstance(); | 286 BrowserAccessibilityStateImpl::GetInstance(); |
| 290 if (enabled) | 287 if (enabled) |
| 291 state->AddAccessibilityModeFlags(new_mode); | 288 state->AddAccessibilityModeFlags(new_mode); |
| 292 else | 289 else |
| 293 state->RemoveAccessibilityModeFlags(new_mode); | 290 state->RemoveAccessibilityModeFlags(new_mode); |
| 294 } | 291 } |
| 295 | 292 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 313 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", | 310 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", |
| 314 *(result.get())); | 311 *(result.get())); |
| 315 return; | 312 return; |
| 316 } | 313 } |
| 317 | 314 |
| 318 std::unique_ptr<base::DictionaryValue> result(BuildTargetDescriptor(rvh)); | 315 std::unique_ptr<base::DictionaryValue> result(BuildTargetDescriptor(rvh)); |
| 319 auto* web_contents = | 316 auto* web_contents = |
| 320 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); | 317 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
| 321 // No matter the state of the current web_contents, we want to force the mode | 318 // 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 | 319 // because we are about to show the accessibility tree |
| 323 web_contents->SetAccessibilityMode(ACCESSIBILITY_MODE_FLAG_NATIVE_APIS | | 320 AccessibilityMode new_mode(AccessibilityMode::NATIVE_APIS | |
| 324 ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 321 AccessibilityMode::WEB_CONTENTS); |
| 322 |
| 323 web_contents->SetAccessibilityMode(new_mode); |
| 325 std::unique_ptr<AccessibilityTreeFormatter> formatter; | 324 std::unique_ptr<AccessibilityTreeFormatter> formatter; |
| 326 if (g_show_internal_accessibility_tree) | 325 if (g_show_internal_accessibility_tree) |
| 327 formatter.reset(new AccessibilityTreeFormatterBlink()); | 326 formatter.reset(new AccessibilityTreeFormatterBlink()); |
| 328 else | 327 else |
| 329 formatter.reset(AccessibilityTreeFormatter::Create()); | 328 formatter.reset(AccessibilityTreeFormatter::Create()); |
| 330 base::string16 accessibility_contents_utf16; | 329 base::string16 accessibility_contents_utf16; |
| 331 std::vector<AccessibilityTreeFormatter::Filter> filters; | 330 std::vector<AccessibilityTreeFormatter::Filter> filters; |
| 332 filters.push_back(AccessibilityTreeFormatter::Filter( | 331 filters.push_back(AccessibilityTreeFormatter::Filter( |
| 333 base::ASCIIToUTF16("*"), | 332 base::ASCIIToUTF16("*"), |
| 334 AccessibilityTreeFormatter::Filter::ALLOW)); | 333 AccessibilityTreeFormatter::Filter::ALLOW)); |
| 335 formatter->SetFilters(filters); | 334 formatter->SetFilters(filters); |
| 336 auto* ax_mgr = web_contents->GetOrCreateRootBrowserAccessibilityManager(); | 335 auto* ax_mgr = web_contents->GetOrCreateRootBrowserAccessibilityManager(); |
| 337 DCHECK(ax_mgr); | 336 DCHECK(ax_mgr); |
| 338 formatter->FormatAccessibilityTree(ax_mgr->GetRoot(), | 337 formatter->FormatAccessibilityTree(ax_mgr->GetRoot(), |
| 339 &accessibility_contents_utf16); | 338 &accessibility_contents_utf16); |
| 340 result->Set("tree", | 339 result->Set("tree", |
| 341 new base::StringValue( | 340 new base::StringValue( |
| 342 base::UTF16ToUTF8(accessibility_contents_utf16))); | 341 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 |