| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 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 = AccessibilityMode::OFF; |
| 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 = 0 != (mode & AccessibilityMode::NATIVE_APIS); |
| 151 bool web = 0 != (mode & ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 151 bool web = 0 != (mode & AccessibilityMode::WEB_CONTENTS); |
| 152 bool text = 0 != (mode & ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES); | 152 bool text = 0 != (mode & AccessibilityMode::INLINE_TEXT_BOXES); |
| 153 bool screenreader = 0 != (mode & ACCESSIBILITY_MODE_FLAG_SCREEN_READER); | 153 bool screenreader = 0 != (mode & AccessibilityMode::SCREEN_READER); |
| 154 bool html = 0 != (mode & ACCESSIBILITY_MODE_FLAG_HTML); | 154 bool html = 0 != (mode & 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Flip the bits represented by |mode|. See accessibility_mode_enums.h for |
| 237 // values. | 237 // values. |
| 238 current_mode ^= mode; | 238 current_mode ^= (AccessibilityMode)mode; |
| 239 |
| 239 web_contents->SetAccessibilityMode(current_mode); | 240 web_contents->SetAccessibilityMode(current_mode); |
| 240 } | 241 } |
| 241 | 242 |
| 242 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { | 243 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { |
| 243 std::string flag_name_str; | 244 std::string flag_name_str; |
| 244 bool enabled; | 245 bool enabled; |
| 245 CHECK_EQ(2U, args->GetSize()); | 246 CHECK_EQ(2U, args->GetSize()); |
| 246 CHECK(args->GetString(0, &flag_name_str)); | 247 CHECK(args->GetString(0, &flag_name_str)); |
| 247 CHECK(args->GetBoolean(1, &enabled)); | 248 CHECK(args->GetBoolean(1, &enabled)); |
| 248 | 249 |
| 249 if (flag_name_str == kInternal) { | 250 if (flag_name_str == kInternal) { |
| 250 g_show_internal_accessibility_tree = enabled; | 251 g_show_internal_accessibility_tree = enabled; |
| 251 LOG(ERROR) << "INTERNAL: " << g_show_internal_accessibility_tree; | 252 LOG(ERROR) << "INTERNAL: " << g_show_internal_accessibility_tree; |
| 252 return; | 253 return; |
| 253 } | 254 } |
| 254 | 255 |
| 255 AccessibilityMode new_mode; | 256 AccessibilityMode new_mode; |
| 256 if (flag_name_str == kNative) { | 257 if (flag_name_str == kNative) { |
| 257 new_mode = ACCESSIBILITY_MODE_FLAG_NATIVE_APIS; | 258 new_mode = AccessibilityMode::NATIVE_APIS; |
| 258 } else if (flag_name_str == kWeb) { | 259 } else if (flag_name_str == kWeb) { |
| 259 new_mode = ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS; | 260 new_mode = AccessibilityMode::WEB_CONTENTS; |
| 260 } else if (flag_name_str == kText) { | 261 } else if (flag_name_str == kText) { |
| 261 new_mode = ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES; | 262 new_mode = AccessibilityMode::INLINE_TEXT_BOXES; |
| 262 } else if (flag_name_str == kScreenReader) { | 263 } else if (flag_name_str == kScreenReader) { |
| 263 new_mode = ACCESSIBILITY_MODE_FLAG_SCREEN_READER; | 264 new_mode = AccessibilityMode::SCREEN_READER; |
| 264 } else if (flag_name_str == kHTML) { | 265 } else if (flag_name_str == kHTML) { |
| 265 new_mode = ACCESSIBILITY_MODE_FLAG_HTML; | 266 new_mode = AccessibilityMode::HTML; |
| 266 } else { | 267 } else { |
| 267 NOTREACHED(); | 268 NOTREACHED(); |
| 268 return; | 269 return; |
| 269 } | 270 } |
| 270 | 271 |
| 271 // It doesn't make sense to enable one of the flags that depends on | 272 // It doesn't make sense to enable one of the flags that depends on |
| 272 // web contents without enabling web contents accessibility too. | 273 // web contents without enabling web contents accessibility too. |
| 273 if (enabled && | 274 if (enabled && (new_mode == AccessibilityMode::INLINE_TEXT_BOXES || |
| 274 (new_mode == ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES || | 275 new_mode == AccessibilityMode::SCREEN_READER || |
| 275 new_mode == ACCESSIBILITY_MODE_FLAG_SCREEN_READER || | 276 new_mode == AccessibilityMode::HTML)) { |
| 276 new_mode == ACCESSIBILITY_MODE_FLAG_HTML)) { | 277 new_mode |= AccessibilityMode::WEB_CONTENTS; |
| 277 new_mode |= ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS; | |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Similarly if you disable web accessibility we should remove all | 280 // Similarly if you disable web accessibility we should remove all |
| 281 // flags that depend on it. | 281 // flags that depend on it. |
| 282 if (!enabled && new_mode == ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS) { | 282 if (!enabled && new_mode == AccessibilityMode::WEB_CONTENTS) { |
| 283 new_mode |= ACCESSIBILITY_MODE_FLAG_INLINE_TEXT_BOXES; | 283 new_mode |= AccessibilityMode::INLINE_TEXT_BOXES; |
| 284 new_mode |= ACCESSIBILITY_MODE_FLAG_SCREEN_READER; | 284 new_mode |= AccessibilityMode::SCREEN_READER; |
| 285 new_mode |= ACCESSIBILITY_MODE_FLAG_HTML; | 285 new_mode |= AccessibilityMode::HTML; |
| 286 } | 286 } |
| 287 | 287 |
| 288 BrowserAccessibilityStateImpl* state = | 288 BrowserAccessibilityStateImpl* state = |
| 289 BrowserAccessibilityStateImpl::GetInstance(); | 289 BrowserAccessibilityStateImpl::GetInstance(); |
| 290 if (enabled) | 290 if (enabled) |
| 291 state->AddAccessibilityModeFlags(new_mode); | 291 state->AddAccessibilityModeFlags(new_mode); |
| 292 else | 292 else |
| 293 state->RemoveAccessibilityModeFlags(new_mode); | 293 state->RemoveAccessibilityModeFlags(new_mode); |
| 294 } | 294 } |
| 295 | 295 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 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(AccessibilityMode::NATIVE_APIS | |
| 324 ACCESSIBILITY_MODE_FLAG_WEB_CONTENTS); | 324 AccessibilityMode::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::StringValue( |
| 342 base::UTF16ToUTF8(accessibility_contents_utf16))); | 342 base::UTF16ToUTF8(accessibility_contents_utf16))); |
| 343 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", | 343 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", |
| 344 *(result.get())); | 344 *(result.get())); |
| 345 } | 345 } |
| 346 | 346 |
| 347 } // namespace content | 347 } // namespace content |
| OLD | NEW |