Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / frame_host / frame_accessibility.h
blob449724d3b06faeb3c54c66914bec3ad53bf3053f
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_ACCESSIBILITY_H_
6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_ACCESSIBILITY_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/memory/singleton.h"
12 #include "content/common/content_export.h"
14 namespace content {
16 class RenderFrameHostImpl;
18 // This singleton class maintains the mappings necessary to link child frames
19 // and guest frames into a single tree for accessibility. This class is only
20 // used if accessibility is enabled.
21 class CONTENT_EXPORT FrameAccessibility {
22 public:
23 static FrameAccessibility* GetInstance();
25 // Add a mapping between an accessibility node of |parent_frame_host|
26 // and the child frame with the given frame tree node id, in the same
27 // frame tree.
28 void AddChildFrame(RenderFrameHostImpl* parent_frame_host,
29 int accessibility_node_id,
30 int64 child_frame_tree_node_id);
32 // Add a mapping between an accessibility node of |parent_frame_host|
33 // and the main frame of the guest Webcontents with the given
34 // browser plugin instance id.
35 void AddGuestWebContents(RenderFrameHostImpl* parent_frame_host,
36 int accessibility_node_id,
37 int browser_plugin_instance_id);
39 // This is called when a RenderFrameHostImpl is deleted, so invalid
40 // mappings can be removed from this data structure.
41 void OnRenderFrameHostDestroyed(RenderFrameHostImpl* render_frame_host);
43 // Given a parent RenderFrameHostImpl and an accessibility node id, look up
44 // a child frame or guest frame that was previously associated with this
45 // frame and node id. If a mapping exists, return the resulting frame if
46 // it's valid. If it doesn't resolve to a valid RenderFrameHostImpl,
47 // returns NULL.
48 RenderFrameHostImpl* GetChild(RenderFrameHostImpl* parent_frame_host,
49 int accessibility_node_id);
51 // Given a parent RenderFrameHostImpl and an accessibility node id, look up
52 // all child frames or guest frames that were previously associated with this
53 // frame, and populate |child_frame_hosts| with all of them that resolve
54 // to a valid RenderFrameHostImpl.
55 void GetAllChildFrames(RenderFrameHostImpl* parent_frame_host,
56 std::vector<RenderFrameHostImpl*>* child_frame_hosts);
58 // Given a RenderFrameHostImpl, check the mapping table to see if it's
59 // the child of a node in some other frame. If so, return true and
60 // set the parent frame and accessibility node id in the parent frame,
61 // otherwise return false.
62 bool GetParent(RenderFrameHostImpl* child_frame_host,
63 RenderFrameHostImpl** out_parent_frame_host,
64 int* out_accessibility_node_id);
66 private:
67 FrameAccessibility();
68 virtual ~FrameAccessibility();
70 RenderFrameHostImpl* GetRFHIFromFrameTreeNodeId(
71 RenderFrameHostImpl* parent_frame_host,
72 int64 child_frame_tree_node_id);
74 // This structure stores the parent-child relationship between an
75 // accessibility node in a parent frame and its child frame, where the
76 // child frame may be an iframe or the main frame of a guest browser
77 // plugin. It allows the accessibility code to walk both down and up
78 // the "composed" accessibility tree.
79 struct ChildFrameMapping {
80 ChildFrameMapping();
82 // The parent frame host. Required.
83 RenderFrameHostImpl* parent_frame_host;
85 // The id of the accessibility node that's the host of the child frame,
86 // for example the accessibility node for the <iframe> element or the
87 // <embed> element.
88 int accessibility_node_id;
90 // If the child frame is an iframe, this is the iframe's FrameTreeNode id,
91 // otherwise 0.
92 int64 child_frame_tree_node_id;
94 // If the child frame is a browser plugin, this is its instance id,
95 // otherwise 0.
96 int browser_plugin_instance_id;
99 std::vector<ChildFrameMapping> mappings_;
101 friend struct DefaultSingletonTraits<FrameAccessibility>;
104 } // namespace content
106 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_ACCESSIBILITY_H_