Chromium Code Reviews| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 AccessibilityMode accessibility_mode, | 58 AccessibilityMode accessibility_mode, |
| 59 base::ProcessHandle handle = base::kNullProcessHandle) { | 59 base::ProcessHandle handle = base::kNullProcessHandle) { |
| 60 std::unique_ptr<base::DictionaryValue> target_data( | 60 std::unique_ptr<base::DictionaryValue> target_data( |
| 61 new base::DictionaryValue()); | 61 new base::DictionaryValue()); |
| 62 target_data->SetInteger(kProcessIdField, process_id); | 62 target_data->SetInteger(kProcessIdField, process_id); |
| 63 target_data->SetInteger(kRouteIdField, route_id); | 63 target_data->SetInteger(kRouteIdField, route_id); |
| 64 target_data->SetString(kUrlField, url.spec()); | 64 target_data->SetString(kUrlField, url.spec()); |
| 65 target_data->SetString(kNameField, net::EscapeForHTML(name)); | 65 target_data->SetString(kNameField, net::EscapeForHTML(name)); |
| 66 target_data->SetInteger(kPidField, base::GetProcId(handle)); | 66 target_data->SetInteger(kPidField, base::GetProcId(handle)); |
| 67 target_data->SetString(kFaviconUrlField, favicon_url.spec()); | 67 target_data->SetString(kFaviconUrlField, favicon_url.spec()); |
| 68 target_data->SetInteger(kAccessibilityModeField, | 68 target_data->SetBoolean( |
| 69 accessibility_mode); | 69 kAccessibilityModeField, |
| 70 0 != (accessibility_mode & AccessibilityModeFlagWebContents)); | |
| 70 return target_data; | 71 return target_data; |
| 71 } | 72 } |
| 72 | 73 |
| 73 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor( | 74 std::unique_ptr<base::DictionaryValue> BuildTargetDescriptor( |
| 74 RenderViewHost* rvh) { | 75 RenderViewHost* rvh) { |
| 75 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 76 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 76 WebContents::FromRenderViewHost(rvh)); | 77 WebContents::FromRenderViewHost(rvh)); |
| 77 AccessibilityMode accessibility_mode = AccessibilityModeOff; | 78 AccessibilityMode accessibility_mode = AccessibilityModeOff; |
| 78 | 79 |
| 79 std::string title; | 80 std::string title; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 continue; | 119 continue; |
| 119 BrowserContext* context = rvh->GetProcess()->GetBrowserContext(); | 120 BrowserContext* context = rvh->GetProcess()->GetBrowserContext(); |
| 120 if (context != current_context) | 121 if (context != current_context) |
| 121 continue; | 122 continue; |
| 122 | 123 |
| 123 rvh_list->Append(BuildTargetDescriptor(rvh)); | 124 rvh_list->Append(BuildTargetDescriptor(rvh)); |
| 124 } | 125 } |
| 125 | 126 |
| 126 base::DictionaryValue data; | 127 base::DictionaryValue data; |
| 127 data.Set("list", rvh_list.release()); | 128 data.Set("list", rvh_list.release()); |
| 128 data.SetInteger( | 129 AccessibilityMode mode = |
| 129 "global_a11y_mode", | 130 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); |
| 130 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()); | 131 data.SetInteger("native", |
| 131 data.SetBoolean( | 132 0 != (mode & AccessibilityModeFlagNativeAPIs)); |
| 132 "global_internal_tree_mode", | 133 data.SetInteger("web", |
| 133 g_show_internal_accessibility_tree); | 134 0 != (mode & AccessibilityModeFlagWebContents)); |
| 135 data.SetInteger("text", | |
| 136 0 != (mode & AccessibilityModeFlagInlineTextBoxes)); | |
| 137 data.SetInteger("screenreader", | |
| 138 0 != (mode & AccessibilityModeFlagScreenReader)); | |
| 139 data.SetInteger("html", | |
| 140 0 != (mode & AccessibilityModeFlagHTML)); | |
| 141 data.SetBoolean("internal", g_show_internal_accessibility_tree); | |
| 134 | 142 |
| 135 std::string json_string; | 143 std::string json_string; |
| 136 base::JSONWriter::Write(data, &json_string); | 144 base::JSONWriter::Write(data, &json_string); |
| 137 | 145 |
| 138 callback.Run(base::RefCountedString::TakeString(&json_string)); | 146 callback.Run(base::RefCountedString::TakeString(&json_string)); |
| 139 return true; | 147 return true; |
| 140 } | 148 } |
| 141 | 149 |
| 142 } // namespace | 150 } // namespace |
| 143 | 151 |
| 144 AccessibilityUI::AccessibilityUI(WebUI* web_ui) : WebUIController(web_ui) { | 152 AccessibilityUI::AccessibilityUI(WebUI* web_ui) : WebUIController(web_ui) { |
| 145 // Set up the chrome://accessibility source. | 153 // Set up the chrome://accessibility source. |
| 146 WebUIDataSourceImpl* html_source = static_cast<WebUIDataSourceImpl*>( | 154 WebUIDataSourceImpl* html_source = static_cast<WebUIDataSourceImpl*>( |
| 147 WebUIDataSource::Create(kChromeUIAccessibilityHost)); | 155 WebUIDataSource::Create(kChromeUIAccessibilityHost)); |
| 148 | 156 |
| 149 web_ui->RegisterMessageCallback( | 157 web_ui->RegisterMessageCallback( |
| 150 "toggleAccessibility", | 158 "toggleAccessibility", |
| 151 base::Bind(&AccessibilityUI::ToggleAccessibility, | 159 base::Bind(&AccessibilityUI::ToggleAccessibility, |
| 152 base::Unretained(this))); | 160 base::Unretained(this))); |
| 153 web_ui->RegisterMessageCallback( | 161 web_ui->RegisterMessageCallback( |
| 154 "toggleGlobalAccessibility", | 162 "setGlobalFlag", |
| 155 base::Bind(&AccessibilityUI::ToggleGlobalAccessibility, | 163 base::Bind(&AccessibilityUI::SetGlobalFlag, |
| 156 base::Unretained(this))); | |
| 157 web_ui->RegisterMessageCallback( | |
| 158 "toggleInternalTree", | |
| 159 base::Bind(&AccessibilityUI::ToggleInternalTree, | |
| 160 base::Unretained(this))); | 164 base::Unretained(this))); |
| 161 web_ui->RegisterMessageCallback( | 165 web_ui->RegisterMessageCallback( |
| 162 "requestAccessibilityTree", | 166 "requestAccessibilityTree", |
| 163 base::Bind(&AccessibilityUI::RequestAccessibilityTree, | 167 base::Bind(&AccessibilityUI::RequestAccessibilityTree, |
| 164 base::Unretained(this))); | 168 base::Unretained(this))); |
| 165 | 169 |
| 166 // Add required resources. | 170 // Add required resources. |
| 167 html_source->SetJsonPath("strings.js"); | 171 html_source->SetJsonPath("strings.js"); |
| 168 html_source->AddResourcePath("accessibility.css", IDR_ACCESSIBILITY_CSS); | 172 html_source->AddResourcePath("accessibility.css", IDR_ACCESSIBILITY_CSS); |
| 169 html_source->AddResourcePath("accessibility.js", IDR_ACCESSIBILITY_JS); | 173 html_source->AddResourcePath("accessibility.js", IDR_ACCESSIBILITY_JS); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 199 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); | 203 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh)); |
| 200 AccessibilityMode mode = web_contents->GetAccessibilityMode(); | 204 AccessibilityMode mode = web_contents->GetAccessibilityMode(); |
| 201 if ((mode & kAccessibilityModeComplete) != kAccessibilityModeComplete) { | 205 if ((mode & kAccessibilityModeComplete) != kAccessibilityModeComplete) { |
| 202 web_contents->AddAccessibilityMode(kAccessibilityModeComplete); | 206 web_contents->AddAccessibilityMode(kAccessibilityModeComplete); |
| 203 } else { | 207 } else { |
| 204 web_contents->SetAccessibilityMode( | 208 web_contents->SetAccessibilityMode( |
| 205 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()); | 209 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()); |
| 206 } | 210 } |
| 207 } | 211 } |
| 208 | 212 |
| 209 void AccessibilityUI::ToggleGlobalAccessibility(const base::ListValue* args) { | 213 void AccessibilityUI::SetGlobalFlag(const base::ListValue* args) { |
| 214 std::string flag_name_str; | |
| 215 bool value; | |
|
aboxhall
2016/12/12 20:34:45
how about s/value/enabled/ ?
dmazzoni
2016/12/13 00:30:49
Done.
| |
| 216 CHECK_EQ(2U, args->GetSize()); | |
| 217 CHECK(args->GetString(0, &flag_name_str)); | |
| 218 CHECK(args->GetBoolean(1, &value)); | |
| 219 | |
| 220 if (flag_name_str == "internal") { | |
| 221 g_show_internal_accessibility_tree = value; | |
| 222 return; | |
| 223 } | |
| 224 | |
| 225 AccessibilityMode new_mode; | |
| 226 if (flag_name_str == "native") { | |
| 227 new_mode = AccessibilityModeFlagNativeAPIs; | |
| 228 } else if (flag_name_str == "web") { | |
| 229 new_mode = AccessibilityModeFlagWebContents; | |
| 230 } else if (flag_name_str == "text") { | |
| 231 new_mode = AccessibilityModeFlagInlineTextBoxes; | |
| 232 } else if (flag_name_str == "screenreader") { | |
| 233 new_mode = AccessibilityModeFlagScreenReader; | |
| 234 } else if (flag_name_str == "html") { | |
| 235 new_mode = AccessibilityModeFlagHTML; | |
| 236 } else { | |
| 237 NOTREACHED(); | |
| 238 return; | |
| 239 } | |
| 240 | |
| 241 // It doesn't make sense to enable one of the flags that depends on | |
| 242 // web contents without enabling web contents accessibility too. | |
| 243 if (value == true && | |
|
aboxhall
2016/12/12 20:34:45
then you can s/== true// here and s/value == false
dmazzoni
2016/12/13 00:30:50
Done.
| |
| 244 (new_mode == AccessibilityModeFlagInlineTextBoxes || | |
| 245 new_mode == AccessibilityModeFlagScreenReader || | |
| 246 new_mode == AccessibilityModeFlagHTML)) { | |
| 247 new_mode |= AccessibilityModeFlagWebContents; | |
| 248 } | |
| 249 | |
| 250 // Similarly if you disable web accessibility we should remove all | |
|
aboxhall
2016/12/12 20:34:45
Is that true? Could they not stick around to be "r
dmazzoni
2016/12/13 00:30:50
OK, how about this: I modified the code to show th
| |
| 251 // flags that depend on it. | |
| 252 if (value == false && new_mode == AccessibilityModeFlagWebContents) { | |
| 253 new_mode |= AccessibilityModeFlagInlineTextBoxes; | |
| 254 new_mode |= AccessibilityModeFlagScreenReader; | |
| 255 new_mode |= AccessibilityModeFlagHTML; | |
| 256 } | |
| 257 | |
| 210 BrowserAccessibilityStateImpl* state = | 258 BrowserAccessibilityStateImpl* state = |
| 211 BrowserAccessibilityStateImpl::GetInstance(); | 259 BrowserAccessibilityStateImpl::GetInstance(); |
| 212 AccessibilityMode mode = state->accessibility_mode(); | 260 if (value) |
| 213 if ((mode & kAccessibilityModeComplete) != kAccessibilityModeComplete) | 261 state->AddAccessibilityModeFlags(new_mode); |
| 214 state->EnableAccessibility(); | |
| 215 else | 262 else |
| 216 state->DisableAccessibility(); | 263 state->RemoveAccessibilityModeFlags(new_mode); |
| 217 } | |
| 218 | |
| 219 void AccessibilityUI::ToggleInternalTree(const base::ListValue* args) { | |
| 220 g_show_internal_accessibility_tree = !g_show_internal_accessibility_tree; | |
| 221 } | 264 } |
| 222 | 265 |
| 223 void AccessibilityUI::RequestAccessibilityTree(const base::ListValue* args) { | 266 void AccessibilityUI::RequestAccessibilityTree(const base::ListValue* args) { |
| 224 std::string process_id_str; | 267 std::string process_id_str; |
| 225 std::string route_id_str; | 268 std::string route_id_str; |
| 226 int process_id; | 269 int process_id; |
| 227 int route_id; | 270 int route_id; |
| 228 CHECK_EQ(2U, args->GetSize()); | 271 CHECK_EQ(2U, args->GetSize()); |
| 229 CHECK(args->GetString(0, &process_id_str)); | 272 CHECK(args->GetString(0, &process_id_str)); |
| 230 CHECK(args->GetString(1, &route_id_str)); | 273 CHECK(args->GetString(1, &route_id_str)); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 260 web_contents->GetRootBrowserAccessibilityManager()->GetRoot(), | 303 web_contents->GetRootBrowserAccessibilityManager()->GetRoot(), |
| 261 &accessibility_contents_utf16); | 304 &accessibility_contents_utf16); |
| 262 result->Set("tree", | 305 result->Set("tree", |
| 263 new base::StringValue( | 306 new base::StringValue( |
| 264 base::UTF16ToUTF8(accessibility_contents_utf16))); | 307 base::UTF16ToUTF8(accessibility_contents_utf16))); |
| 265 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", | 308 web_ui()->CallJavascriptFunctionUnsafe("accessibility.showTree", |
| 266 *(result.get())); | 309 *(result.get())); |
| 267 } | 310 } |
| 268 | 311 |
| 269 } // namespace content | 312 } // namespace content |
| OLD | NEW |