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

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

Issue 2981083002: Migrate BrowserAccessibility windows unique id handling to AXPlatformNodeWin. (Closed)
Patch Set: Use after free no more Created 3 years, 4 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) 2017 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2017 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_com_win.h" 5 #include "content/browser/accessibility/browser_accessibility_com_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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 131
132 STDMETHODIMP BrowserAccessibilityComWin::get_uniqueID(LONG* unique_id) { 132 STDMETHODIMP BrowserAccessibilityComWin::get_uniqueID(LONG* unique_id) {
133 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNIQUE_ID); 133 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNIQUE_ID);
134 if (!owner()) 134 if (!owner())
135 return E_FAIL; 135 return E_FAIL;
136 136
137 if (!unique_id) 137 if (!unique_id)
138 return E_INVALIDARG; 138 return E_INVALIDARG;
139 139
140 *unique_id = -owner()->unique_id(); 140 *unique_id = -AXPlatformNodeWin::unique_id();
141 return S_OK; 141 return S_OK;
142 } 142 }
143 143
144 STDMETHODIMP BrowserAccessibilityComWin::get_windowHandle(HWND* window_handle) { 144 STDMETHODIMP BrowserAccessibilityComWin::get_windowHandle(HWND* window_handle) {
145 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_WINDOW_HANDLE); 145 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_WINDOW_HANDLE);
146 if (!owner()) 146 if (!owner())
147 return E_FAIL; 147 return E_FAIL;
148 148
149 if (!window_handle) 149 if (!window_handle)
150 return E_INVALIDARG; 150 return E_INVALIDARG;
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1242 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1243 if (!owner()) 1243 if (!owner())
1244 return E_FAIL; 1244 return E_FAIL;
1245 1245
1246 if (!hyperlink || index < 0 || 1246 if (!hyperlink || index < 0 ||
1247 index >= static_cast<long>(hyperlinks().size())) { 1247 index >= static_cast<long>(hyperlinks().size())) {
1248 return E_INVALIDARG; 1248 return E_INVALIDARG;
1249 } 1249 }
1250 1250
1251 int32_t id = hyperlinks()[index]; 1251 int32_t id = hyperlinks()[index];
1252 BrowserAccessibilityComWin* link = 1252 auto* link = static_cast<BrowserAccessibilityComWin*>(
1253 ToBrowserAccessibilityComWin(owner()->GetFromUniqueID(id)); 1253 AXPlatformNodeWin::GetFromUniqueId(id));
1254 if (!link) 1254 if (!link)
1255 return E_FAIL; 1255 return E_FAIL;
1256 1256
1257 *hyperlink = static_cast<IAccessibleHyperlink*>(link->NewReference()); 1257 *hyperlink = static_cast<IAccessibleHyperlink*>(link->NewReference());
1258 return S_OK; 1258 return S_OK;
1259 } 1259 }
1260 1260
1261 STDMETHODIMP BrowserAccessibilityComWin::get_hyperlinkIndex( 1261 STDMETHODIMP BrowserAccessibilityComWin::get_hyperlinkIndex(
1262 long char_index, 1262 long char_index,
1263 long* hyperlink_index) { 1263 long* hyperlink_index) {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 1701
1702 base::string16 tag; 1702 base::string16 tag;
1703 if (owner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG, &tag)) 1703 if (owner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG, &tag))
1704 *node_name = SysAllocString(tag.c_str()); 1704 *node_name = SysAllocString(tag.c_str());
1705 else 1705 else
1706 *node_name = nullptr; 1706 *node_name = nullptr;
1707 1707
1708 *name_space_id = 0; 1708 *name_space_id = 0;
1709 *node_value = SysAllocString(value().c_str()); 1709 *node_value = SysAllocString(value().c_str());
1710 *num_children = owner()->PlatformChildCount(); 1710 *num_children = owner()->PlatformChildCount();
1711 *unique_id = -owner()->unique_id(); 1711 *unique_id = -AXPlatformNodeWin::unique_id();
1712 1712
1713 if (owner()->IsDocument()) { 1713 if (owner()->IsDocument()) {
1714 *node_type = NODETYPE_DOCUMENT; 1714 *node_type = NODETYPE_DOCUMENT;
1715 } else if (owner()->IsTextOnlyObject()) { 1715 } else if (owner()->IsTextOnlyObject()) {
1716 *node_type = NODETYPE_TEXT; 1716 *node_type = NODETYPE_TEXT;
1717 } else { 1717 } else {
1718 *node_type = NODETYPE_ELEMENT; 1718 *node_type = NODETYPE_ELEMENT;
1719 } 1719 }
1720 1720
1721 return S_OK; 1721 return S_OK;
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 // the character index of each embedded object character to the id of the 2455 // the character index of each embedded object character to the id of the
2456 // child object it points to. 2456 // child object it points to.
2457 for (unsigned int i = 0; i < owner()->PlatformChildCount(); ++i) { 2457 for (unsigned int i = 0; i < owner()->PlatformChildCount(); ++i) {
2458 auto* child = ToBrowserAccessibilityComWin(owner()->PlatformGetChild(i)); 2458 auto* child = ToBrowserAccessibilityComWin(owner()->PlatformGetChild(i));
2459 DCHECK(child); 2459 DCHECK(child);
2460 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext. 2460 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext.
2461 if (child->owner()->IsTextOnlyObject()) { 2461 if (child->owner()->IsTextOnlyObject()) {
2462 win_attributes_->hypertext += child->name(); 2462 win_attributes_->hypertext += child->name();
2463 } else { 2463 } else {
2464 int32_t char_offset = static_cast<int32_t>(owner()->GetText().size()); 2464 int32_t char_offset = static_cast<int32_t>(owner()->GetText().size());
2465 int32_t child_unique_id = child->owner()->unique_id(); 2465 int32_t child_unique_id = child->unique_id();
2466 int32_t index = hyperlinks().size(); 2466 int32_t index = hyperlinks().size();
2467 win_attributes_->hyperlink_offset_to_index[char_offset] = index; 2467 win_attributes_->hyperlink_offset_to_index[char_offset] = index;
2468 win_attributes_->hyperlinks.push_back(child_unique_id); 2468 win_attributes_->hyperlinks.push_back(child_unique_id);
2469 win_attributes_->hypertext += kEmbeddedCharacter; 2469 win_attributes_->hypertext += kEmbeddedCharacter;
2470 } 2470 }
2471 } 2471 }
2472 } 2472 }
2473 2473
2474 void BrowserAccessibilityComWin::UpdateStep3FireEvents( 2474 void BrowserAccessibilityComWin::UpdateStep3FireEvents(
2475 bool is_subtree_creation) { 2475 bool is_subtree_creation) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 // Detach BrowserAccessibilityWin from us. 2570 // Detach BrowserAccessibilityWin from us.
2571 owner_ = nullptr; 2571 owner_ = nullptr;
2572 AXPlatformNodeWin::Destroy(); 2572 AXPlatformNodeWin::Destroy();
2573 } 2573 }
2574 2574
2575 void BrowserAccessibilityComWin::Init(ui::AXPlatformNodeDelegate* delegate) { 2575 void BrowserAccessibilityComWin::Init(ui::AXPlatformNodeDelegate* delegate) {
2576 owner_ = static_cast<BrowserAccessibilityWin*>(delegate); 2576 owner_ = static_cast<BrowserAccessibilityWin*>(delegate);
2577 AXPlatformNodeBase::Init(delegate); 2577 AXPlatformNodeBase::Init(delegate);
2578 } 2578 }
2579 2579
2580 ui::AXPlatformNode* BrowserAccessibilityComWin::GetFromUniqueId(
2581 int32_t unique_id) {
2582 return ToBrowserAccessibilityComWin(
2583 BrowserAccessibility::GetFromUniqueID(unique_id));
2584 }
2585
2586 std::vector<base::string16> BrowserAccessibilityComWin::ComputeTextAttributes() 2580 std::vector<base::string16> BrowserAccessibilityComWin::ComputeTextAttributes()
2587 const { 2581 const {
2588 std::vector<base::string16> attributes; 2582 std::vector<base::string16> attributes;
2589 2583
2590 // We include list markers for now, but there might be other objects that are 2584 // We include list markers for now, but there might be other objects that are
2591 // auto generated. 2585 // auto generated.
2592 // TODO(nektar): Compute what objects are auto-generated in Blink. 2586 // TODO(nektar): Compute what objects are auto-generated in Blink.
2593 if (owner()->GetRole() == ui::AX_ROLE_LIST_MARKER) 2587 if (owner()->GetRole() == ui::AX_ROLE_LIST_MARKER)
2594 attributes.push_back(L"auto-generated:true"); 2588 attributes.push_back(L"auto-generated:true");
2595 else 2589 else
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 2818
2825 LONG child_id = var_id.lVal; 2819 LONG child_id = var_id.lVal;
2826 if (child_id == CHILDID_SELF) 2820 if (child_id == CHILDID_SELF)
2827 return this; 2821 return this;
2828 2822
2829 if (child_id >= 1 && 2823 if (child_id >= 1 &&
2830 child_id <= static_cast<LONG>(owner()->PlatformChildCount())) 2824 child_id <= static_cast<LONG>(owner()->PlatformChildCount()))
2831 return ToBrowserAccessibilityComWin( 2825 return ToBrowserAccessibilityComWin(
2832 owner()->PlatformGetChild(child_id - 1)); 2826 owner()->PlatformGetChild(child_id - 1));
2833 2827
2834 BrowserAccessibilityComWin* child = ToBrowserAccessibilityComWin( 2828 auto* child = static_cast<BrowserAccessibilityComWin*>(
2835 BrowserAccessibility::GetFromUniqueID(-child_id)); 2829 AXPlatformNodeWin::GetFromUniqueId(-child_id));
2836 if (child && child->owner()->IsDescendantOf(owner())) 2830 if (child && child->owner()->IsDescendantOf(owner()))
2837 return child; 2831 return child;
2838 2832
2839 return nullptr; 2833 return nullptr;
2840 } 2834 }
2841 2835
2842 HRESULT BrowserAccessibilityComWin::GetStringAttributeAsBstr( 2836 HRESULT BrowserAccessibilityComWin::GetStringAttributeAsBstr(
2843 ui::AXStringAttribute attribute, 2837 ui::AXStringAttribute attribute,
2844 BSTR* value_bstr) { 2838 BSTR* value_bstr) {
2845 base::string16 str; 2839 base::string16 str;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2899 BrowserAccessibilityComWin::GetHyperlinkFromHypertextOffset(int offset) const { 2893 BrowserAccessibilityComWin::GetHyperlinkFromHypertextOffset(int offset) const {
2900 std::map<int32_t, int32_t>::iterator iterator = 2894 std::map<int32_t, int32_t>::iterator iterator =
2901 hyperlink_offset_to_index().find(offset); 2895 hyperlink_offset_to_index().find(offset);
2902 if (iterator == hyperlink_offset_to_index().end()) 2896 if (iterator == hyperlink_offset_to_index().end())
2903 return nullptr; 2897 return nullptr;
2904 2898
2905 int32_t index = iterator->second; 2899 int32_t index = iterator->second;
2906 DCHECK_GE(index, 0); 2900 DCHECK_GE(index, 0);
2907 DCHECK_LT(index, static_cast<int32_t>(hyperlinks().size())); 2901 DCHECK_LT(index, static_cast<int32_t>(hyperlinks().size()));
2908 int32_t id = hyperlinks()[index]; 2902 int32_t id = hyperlinks()[index];
2909 BrowserAccessibilityComWin* hyperlink = 2903 auto* hyperlink = static_cast<BrowserAccessibilityComWin*>(
2910 ToBrowserAccessibilityComWin(owner()->GetFromUniqueID(id)); 2904 AXPlatformNodeWin::GetFromUniqueId(id));
2911 if (!hyperlink) 2905 if (!hyperlink)
2912 return nullptr; 2906 return nullptr;
2913 return hyperlink; 2907 return hyperlink;
2914 } 2908 }
2915 2909
2916 int32_t BrowserAccessibilityComWin::GetHyperlinkIndexFromChild( 2910 int32_t BrowserAccessibilityComWin::GetHyperlinkIndexFromChild(
2917 const BrowserAccessibilityComWin& child) const { 2911 const BrowserAccessibilityComWin& child) const {
2918 if (hyperlinks().empty()) 2912 if (hyperlinks().empty())
2919 return -1; 2913 return -1;
2920 2914
2921 auto iterator = std::find(hyperlinks().begin(), hyperlinks().end(), 2915 auto iterator =
2922 child.owner()->unique_id()); 2916 std::find(hyperlinks().begin(), hyperlinks().end(), child.unique_id());
2923 if (iterator == hyperlinks().end()) 2917 if (iterator == hyperlinks().end())
2924 return -1; 2918 return -1;
2925 2919
2926 return static_cast<int32_t>(iterator - hyperlinks().begin()); 2920 return static_cast<int32_t>(iterator - hyperlinks().begin());
2927 } 2921 }
2928 2922
2929 int32_t BrowserAccessibilityComWin::GetHypertextOffsetFromHyperlinkIndex( 2923 int32_t BrowserAccessibilityComWin::GetHypertextOffsetFromHyperlinkIndex(
2930 int32_t hyperlink_index) const { 2924 int32_t hyperlink_index) const {
2931 for (auto& offset_index : hyperlink_offset_to_index()) { 2925 for (auto& offset_index : hyperlink_offset_to_index()) {
2932 if (offset_index.second == hyperlink_index) 2926 if (offset_index.second == hyperlink_index)
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3371 3365
3372 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin( 3366 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin(
3373 BrowserAccessibility* obj) { 3367 BrowserAccessibility* obj) {
3374 if (!obj || !obj->IsNative()) 3368 if (!obj || !obj->IsNative())
3375 return nullptr; 3369 return nullptr;
3376 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM(); 3370 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM();
3377 return result; 3371 return result;
3378 } 3372 }
3379 3373
3380 } // namespace content 3374 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698