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

Side by Side Diff: ui/accessibility/platform/ax_platform_node_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
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <atlbase.h> 5 #include <atlbase.h>
6 #include <atlcom.h> 6 #include <atlcom.h>
7 #include <limits.h> 7 #include <limits.h>
8 #include <oleacc.h> 8 #include <oleacc.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/win/enum_variant.h" 16 #include "base/win/enum_variant.h"
17 #include "base/win/scoped_comptr.h" 17 #include "base/win/scoped_comptr.h"
18 #include "base/win/scoped_variant.h" 18 #include "base/win/scoped_variant.h"
19 #include "third_party/iaccessible2/ia2_api_all.h" 19 #include "third_party/iaccessible2/ia2_api_all.h"
20 #include "third_party/skia/include/core/SkColor.h" 20 #include "third_party/skia/include/core/SkColor.h"
21 #include "ui/accessibility/ax_action_data.h" 21 #include "ui/accessibility/ax_action_data.h"
22 #include "ui/accessibility/ax_node_data.h" 22 #include "ui/accessibility/ax_node_data.h"
23 #include "ui/accessibility/ax_role_properties.h" 23 #include "ui/accessibility/ax_role_properties.h"
24 #include "ui/accessibility/ax_text_utils.h" 24 #include "ui/accessibility/ax_text_utils.h"
25 #include "ui/accessibility/ax_tree_data.h" 25 #include "ui/accessibility/ax_tree_data.h"
26 #include "ui/accessibility/platform/ax_platform_node_delegate.h" 26 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
27 #include "ui/accessibility/platform/ax_platform_node_win.h" 27 #include "ui/accessibility/platform/ax_platform_node_win.h"
28 #include "ui/accessibility/platform/ax_platform_unique_id.h"
28 #include "ui/base/win/atl_module.h" 29 #include "ui/base/win/atl_module.h"
29 #include "ui/gfx/geometry/rect_conversions.h" 30 #include "ui/gfx/geometry/rect_conversions.h"
30 31
31 // 32 //
32 // Macros to use at the top of any AXPlatformNodeWin function that implements 33 // Macros to use at the top of any AXPlatformNodeWin function that implements
33 // a COM interface. Because COM objects are reference counted and clients 34 // a COM interface. Because COM objects are reference counted and clients
34 // are completely untrusted, it's important to always first check that our 35 // are completely untrusted, it's important to always first check that our
35 // object is still valid, and then check that all pointer arguments are 36 // object is still valid, and then check that all pointer arguments are
36 // not NULL. 37 // not NULL.
37 // 38 //
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // static 300 // static
300 AXPlatformNode* AXPlatformNode::FromNativeViewAccessible( 301 AXPlatformNode* AXPlatformNode::FromNativeViewAccessible(
301 gfx::NativeViewAccessible accessible) { 302 gfx::NativeViewAccessible accessible) {
302 if (!accessible) 303 if (!accessible)
303 return nullptr; 304 return nullptr;
304 base::win::ScopedComPtr<AXPlatformNodeWin> ax_platform_node; 305 base::win::ScopedComPtr<AXPlatformNodeWin> ax_platform_node;
305 accessible->QueryInterface(ax_platform_node.GetAddressOf()); 306 accessible->QueryInterface(ax_platform_node.GetAddressOf());
306 return ax_platform_node.Get(); 307 return ax_platform_node.Get();
307 } 308 }
308 309
310 using UniqueIdMap = base::hash_map<int32_t, AXPlatformNode*>;
311 // Map from each AXPlatformNode's unique id to its instance.
312 base::LazyInstance<UniqueIdMap>::DestructorAtExit g_unique_id_map =
313 LAZY_INSTANCE_INITIALIZER;
314
315 // static
316 AXPlatformNode* AXPlatformNodeWin::GetFromUniqueId(int32_t unique_id) {
317 UniqueIdMap* unique_ids = g_unique_id_map.Pointer();
318 auto iter = unique_ids->find(unique_id);
319 if (iter != unique_ids->end())
320 return iter->second;
321
322 return nullptr;
323 }
309 // 324 //
310 // AXPlatformNodeWin 325 // AXPlatformNodeWin
311 // 326 //
312 327
313 AXPlatformNodeWin::AXPlatformNodeWin() { 328 AXPlatformNodeWin::AXPlatformNodeWin()
329 : unique_id_(ui::GetNextAXPlatformNodeUniqueId()) {
330 g_unique_id_map.Get()[unique_id_] = this;
314 } 331 }
315 332
316 AXPlatformNodeWin::~AXPlatformNodeWin() { 333 AXPlatformNodeWin::~AXPlatformNodeWin() {
317 for (ui::AXPlatformNodeRelationWin* relation : relations_) 334 for (ui::AXPlatformNodeRelationWin* relation : relations_)
318 relation->Release(); 335 relation->Release();
336 if (unique_id_)
337 g_unique_id_map.Get().erase(unique_id_);
319 } 338 }
320 339
321 void AXPlatformNodeWin::CalculateRelationships() { 340 void AXPlatformNodeWin::CalculateRelationships() {
322 ClearOwnRelations(); 341 ClearOwnRelations();
323 AddBidirectionalRelations(IA2_RELATION_CONTROLLER_FOR, 342 AddBidirectionalRelations(IA2_RELATION_CONTROLLER_FOR,
324 IA2_RELATION_CONTROLLED_BY, 343 IA2_RELATION_CONTROLLED_BY,
325 ui::AX_ATTR_CONTROLS_IDS); 344 ui::AX_ATTR_CONTROLS_IDS);
326 AddBidirectionalRelations(IA2_RELATION_DESCRIBED_BY, 345 AddBidirectionalRelations(IA2_RELATION_DESCRIBED_BY,
327 IA2_RELATION_DESCRIPTION_FOR, 346 IA2_RELATION_DESCRIPTION_FOR,
328 ui::AX_ATTR_DESCRIBEDBY_IDS); 347 ui::AX_ATTR_DESCRIBEDBY_IDS);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 544
526 // 545 //
527 // AXPlatformNodeBase implementation. 546 // AXPlatformNodeBase implementation.
528 // 547 //
529 548
530 void AXPlatformNodeWin::Dispose() { 549 void AXPlatformNodeWin::Dispose() {
531 Release(); 550 Release();
532 } 551 }
533 552
534 void AXPlatformNodeWin::Destroy() { 553 void AXPlatformNodeWin::Destroy() {
554 g_unique_id_map.Get().erase(unique_id_);
555 unique_id_ = 0;
556
535 RemoveAlertTarget(); 557 RemoveAlertTarget();
558
559 // This will end up calling Dispose() which may result in deleting this object
560 // if there are no more outstanding references.
536 AXPlatformNodeBase::Destroy(); 561 AXPlatformNodeBase::Destroy();
537 } 562 }
538 563
539 // 564 //
540 // AXPlatformNode implementation. 565 // AXPlatformNode implementation.
541 // 566 //
542 567
543 gfx::NativeViewAccessible AXPlatformNodeWin::GetNativeViewAccessible() { 568 gfx::NativeViewAccessible AXPlatformNodeWin::GetNativeViewAccessible() {
544 return this; 569 return this;
545 } 570 }
(...skipping 2822 matching lines...) Expand 10 before | Expand all | Expand 10 after
3368 if (container && container->GetData().role == ui::AX_ROLE_GROUP) 3393 if (container && container->GetData().role == ui::AX_ROLE_GROUP)
3369 container = FromNativeViewAccessible(container->GetParent()); 3394 container = FromNativeViewAccessible(container->GetParent());
3370 3395
3371 if (!container) 3396 if (!container)
3372 return false; 3397 return false;
3373 3398
3374 return container->GetData().role == ui::AX_ROLE_TREE_GRID; 3399 return container->GetData().role == ui::AX_ROLE_TREE_GRID;
3375 } 3400 }
3376 3401
3377 } // namespace ui 3402 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698