Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: content/browser/accessibility/browser_accessibility_win.cc

Issue 1397183002: Escapes backslash, colon, comma, equals and semicolon in IAccessible2 string attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased with master. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser_accessibility_win.h" 5 #include "content/browser/accessibility/browser_accessibility_win.h"
6 6
7 #include <UIAutomationClient.h> 7 #include <UIAutomationClient.h>
8 #include <UIAutomationCoreApi.h> 8 #include <UIAutomationCoreApi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 3237 matching lines...) Expand 10 before | Expand all | Expand 10 after
3248 win_attributes_->ia2_attributes.push_back(L"invalid:spelling"); 3248 win_attributes_->ia2_attributes.push_back(L"invalid:spelling");
3249 break; 3249 break;
3250 case ui::AX_INVALID_STATE_GRAMMAR: 3250 case ui::AX_INVALID_STATE_GRAMMAR:
3251 win_attributes_->ia2_attributes.push_back(L"invalid:grammar"); 3251 win_attributes_->ia2_attributes.push_back(L"invalid:grammar");
3252 break; 3252 break;
3253 case ui::AX_INVALID_STATE_OTHER: 3253 case ui::AX_INVALID_STATE_OTHER:
3254 { 3254 {
3255 base::string16 aria_invalid_value; 3255 base::string16 aria_invalid_value;
3256 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE, 3256 if (GetString16Attribute(ui::AX_ATTR_ARIA_INVALID_VALUE,
3257 &aria_invalid_value)) { 3257 &aria_invalid_value)) {
3258 SanitizeStringAttributeForIA2(aria_invalid_value,
3259 &aria_invalid_value);
3258 win_attributes_->ia2_attributes.push_back( 3260 win_attributes_->ia2_attributes.push_back(
3259 L"invalid:" + aria_invalid_value); 3261 L"invalid:" + aria_invalid_value);
3260 } else { 3262 } else {
3261 // Set the attribute to L"true", since we cannot be more specific. 3263 // Set the attribute to L"true", since we cannot be more specific.
3262 win_attributes_->ia2_attributes.push_back(L"invalid:true"); 3264 win_attributes_->ia2_attributes.push_back(L"invalid:true");
3263 } 3265 }
3264 } 3266 }
3265 break; 3267 break;
3266 default: 3268 default:
3267 NOTREACHED(); 3269 NOTREACHED();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3400 relation->AddRef(); 3402 relation->AddRef();
3401 relation->Initialize(this, IA2_RELATION_LABELLED_BY); 3403 relation->Initialize(this, IA2_RELATION_LABELLED_BY);
3402 relation->AddTarget(title_elem_id); 3404 relation->AddTarget(title_elem_id);
3403 relations_.push_back(relation); 3405 relations_.push_back(relation);
3404 } 3406 }
3405 3407
3406 // Expose slider value. 3408 // Expose slider value.
3407 if (ia_role() == ROLE_SYSTEM_PROGRESSBAR || 3409 if (ia_role() == ROLE_SYSTEM_PROGRESSBAR ||
3408 ia_role() == ROLE_SYSTEM_SCROLLBAR || 3410 ia_role() == ROLE_SYSTEM_SCROLLBAR ||
3409 ia_role() == ROLE_SYSTEM_SLIDER) { 3411 ia_role() == ROLE_SYSTEM_SLIDER) {
3410 win_attributes_->ia2_attributes.push_back(L"valuetext:" + GetValueText()); 3412 base::string16 value_text = GetValueText();
3413 SanitizeStringAttributeForIA2(value_text, &value_text);
3414 win_attributes_->ia2_attributes.push_back(L"valuetext:" + value_text);
3411 } 3415 }
3412 3416
3413 // Expose dropeffect attribute. 3417 // Expose dropeffect attribute.
3414 base::string16 dropEffect; 3418 base::string16 drop_effect;
3415 if (GetHtmlAttribute("aria-dropeffect", &dropEffect)) 3419 if (GetHtmlAttribute("aria-dropeffect", &drop_effect)) {
3416 win_attributes_->ia2_attributes.push_back(L"dropeffect:" + dropEffect); 3420 SanitizeStringAttributeForIA2(drop_effect, &drop_effect);
3421 win_attributes_->ia2_attributes.push_back(L"dropeffect:" + drop_effect);
3422 }
3417 3423
3418 // Expose grabbed attribute. 3424 // Expose grabbed attribute.
3419 base::string16 grabbed; 3425 base::string16 grabbed;
3420 if (GetHtmlAttribute("aria-grabbed", &grabbed)) 3426 if (GetHtmlAttribute("aria-grabbed", &grabbed)) {
3427 SanitizeStringAttributeForIA2(grabbed, &grabbed);
3421 win_attributes_->ia2_attributes.push_back(L"grabbed:" + grabbed); 3428 win_attributes_->ia2_attributes.push_back(L"grabbed:" + grabbed);
3429 }
3422 3430
3423 // Expose datetime attribute. 3431 // Expose datetime attribute.
3424 base::string16 datetime; 3432 base::string16 datetime;
3425 if (GetRole() == ui::AX_ROLE_TIME && 3433 if (GetRole() == ui::AX_ROLE_TIME &&
3426 GetHtmlAttribute("datetime", &datetime)) 3434 GetHtmlAttribute("datetime", &datetime)) {
3435 SanitizeStringAttributeForIA2(datetime, &datetime);
3427 win_attributes_->ia2_attributes.push_back(L"datetime:" + datetime); 3436 win_attributes_->ia2_attributes.push_back(L"datetime:" + datetime);
3437 }
3428 3438
3429 // Expose input-text type attribute. 3439 // Expose input-text type attribute.
3430 base::string16 type; 3440 base::string16 type;
3431 if (GetRole() == ui::AX_ROLE_TEXT_FIELD && 3441 if (GetRole() == ui::AX_ROLE_TEXT_FIELD && GetHtmlAttribute("type", &type)) {
3432 GetHtmlAttribute("type", &type)) 3442 SanitizeStringAttributeForIA2(type, &type);
3433 win_attributes_->ia2_attributes.push_back(L"text-input-type:" + type); 3443 win_attributes_->ia2_attributes.push_back(L"text-input-type:" + type);
3444 }
3434 3445
3435 // If this is a web area for a presentational iframe, give it a role of 3446 // If this is a web area for a presentational iframe, give it a role of
3436 // something other than DOCUMENT so that the fact that it's a separate doc 3447 // something other than DOCUMENT so that the fact that it's a separate doc
3437 // is not exposed to AT. 3448 // is not exposed to AT.
3438 if (IsWebAreaForPresentationalIframe()) { 3449 if (IsWebAreaForPresentationalIframe()) {
3439 win_attributes_->ia_role = ROLE_SYSTEM_GROUPING; 3450 win_attributes_->ia_role = ROLE_SYSTEM_GROUPING;
3440 win_attributes_->ia2_role = ROLE_SYSTEM_GROUPING; 3451 win_attributes_->ia2_role = ROLE_SYSTEM_GROUPING;
3441 } 3452 }
3442 } 3453 }
3443 3454
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3624 3635
3625 if (str.empty()) 3636 if (str.empty())
3626 return S_FALSE; 3637 return S_FALSE;
3627 3638
3628 *value_bstr = SysAllocString(str.c_str()); 3639 *value_bstr = SysAllocString(str.c_str());
3629 DCHECK(*value_bstr); 3640 DCHECK(*value_bstr);
3630 3641
3631 return S_OK; 3642 return S_OK;
3632 } 3643 }
3633 3644
3645 // Static
3646 void BrowserAccessibilityWin::SanitizeStringAttributeForIA2(
3647 const base::string16& input,
3648 base::string16* output) {
3649 DCHECK(output);
3650 // According to the IA2 Spec, these characters need to be escaped with a
3651 // backslash: backslash, colon, comma, equals and semicolon.
3652 // Note that backslash must be replaced first.
3653 base::ReplaceChars(input, L"\\", L"\\\\", output);
3654 base::ReplaceChars(*output, L":", L"\\:", output);
3655 base::ReplaceChars(*output, L",", L"\\,", output);
3656 base::ReplaceChars(*output, L"=", L"\\=", output);
3657 base::ReplaceChars(*output, L";", L"\\;", output);
3658 }
3659
3634 void BrowserAccessibilityWin::StringAttributeToIA2( 3660 void BrowserAccessibilityWin::StringAttributeToIA2(
3635 ui::AXStringAttribute attribute, 3661 ui::AXStringAttribute attribute,
3636 const char* ia2_attr) { 3662 const char* ia2_attr) {
3637 base::string16 value; 3663 base::string16 value;
3638 if (GetString16Attribute(attribute, &value)) { 3664 if (GetString16Attribute(attribute, &value)) {
3665 SanitizeStringAttributeForIA2(value, &value);
3639 win_attributes_->ia2_attributes.push_back( 3666 win_attributes_->ia2_attributes.push_back(
3640 base::ASCIIToUTF16(ia2_attr) + L":" + value); 3667 base::ASCIIToUTF16(ia2_attr) + L":" + value);
3641 } 3668 }
3642 } 3669 }
3643 3670
3644 void BrowserAccessibilityWin::BoolAttributeToIA2( 3671 void BrowserAccessibilityWin::BoolAttributeToIA2(
3645 ui::AXBoolAttribute attribute, 3672 ui::AXBoolAttribute attribute,
3646 const char* ia2_attr) { 3673 const char* ia2_attr) {
3647 bool value; 3674 bool value;
3648 if (GetBoolAttribute(attribute, &value)) { 3675 if (GetBoolAttribute(attribute, &value)) {
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
4621 ia2_role = ia_role; 4648 ia2_role = ia_role;
4622 4649
4623 win_attributes_->ia_role = ia_role; 4650 win_attributes_->ia_role = ia_role;
4624 win_attributes_->ia_state = ia_state; 4651 win_attributes_->ia_state = ia_state;
4625 win_attributes_->role_name = role_name; 4652 win_attributes_->role_name = role_name;
4626 win_attributes_->ia2_role = ia2_role; 4653 win_attributes_->ia2_role = ia2_role;
4627 win_attributes_->ia2_state = ia2_state; 4654 win_attributes_->ia2_state = ia2_state;
4628 } 4655 }
4629 4656
4630 } // namespace content 4657 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698