blob: 8356bc4ec3c9fc34fb199584b6ae52a58221eb4f [file] [log] [blame]
[email protected]266eb6f2008-09-30 23:56:501// Copyright (c) 2006-2008 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.
4
5#ifndef CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_
6#define CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_
7
8#include <oaidl.h> // Needed for VARIANT structure.
9#include <hash_map>
10
11#include "base/singleton.h"
12#include "chrome/common/notification_service.h"
13#include "chrome/common/render_messages.h"
14
15class BrowserAccessibility;
16class RenderProcessHost;
17class RenderWidgetHost;
18
[email protected]266eb6f2008-09-30 23:56:5019////////////////////////////////////////////////////////////////////////////////
20//
21// BrowserAccessibilityManager
22//
23// Used to manage instance creation and memory handling for browser side
24// accessibility. A singleton class. It implements NotificationObserver to
25// ensure that a termination of a renderer process gets propagated to the
26// active BrowserAccessibility instances calling into it. Each such instance
27// will upon such an event be set to an inactive state, failing calls from the
28// assistive technology gracefully.
29////////////////////////////////////////////////////////////////////////////////
30class BrowserAccessibilityManager : public NotificationObserver {
31 public:
32 // Gets the singleton BrowserAccessibilityManager object. The first time this
33 // method is called, a CacheManagerHost object is constructed and returned.
34 // Subsequent calls will return the same object.
[email protected]bdf64792008-10-09 00:03:1835 static BrowserAccessibilityManager* GetInstance();
[email protected]266eb6f2008-09-30 23:56:5036
37 // Creates an instance of BrowserAccessibility, initializes it and sets the
38 // iaccessible_id and parent_id.
39 STDMETHODIMP CreateAccessibilityInstance(REFIID iid,
40 int iaccessible_id,
41 int instance_id,
42 void** interface_ptr);
43
44 // Composes and sends a message for requesting needed accessibility
45 // information. Unused LONG input parameters should be NULL, and the VARIANT
46 // an empty, valid instance.
47 bool RequestAccessibilityInfo(int iaccessible_id,
48 int instance_id,
49 int iaccessible_func_id,
50 VARIANT var_id,
51 LONG input1,
52 LONG input2);
53
54 // Wrapper function, for cleaner code.
55 ViewHostMsg_Accessibility_Out_Params response();
56
57 // Retrieves the parent HWND connected to the provided id.
58 HWND parent_hwnd(int id);
59
60 // Mutator, needed since constructor does not take any arguments, and to keep
61 // instance accessor clean.
62 int SetMembers(BrowserAccessibility* browser_acc,
63 HWND parent_hwnd,
64 RenderWidgetHost* render_widget_host);
65
66 // NotificationObserver implementation.
67 virtual void Observe(NotificationType type,
68 const NotificationSource& source,
69 const NotificationDetails& details);
70
71 protected:
72 // This class is a singleton. Do not instantiate directly.
73 BrowserAccessibilityManager();
[email protected]bdf64792008-10-09 00:03:1874 friend struct DefaultSingletonTraits<BrowserAccessibilityManager>;
[email protected]266eb6f2008-09-30 23:56:5075
76 ~BrowserAccessibilityManager();
77
78 private:
[email protected]8c8657d62009-01-16 18:31:2679 // Member variable structure, used in instance hashmap.
80 struct UniqueMembers {
81 RenderWidgetHost* render_widget_host_;
82 HWND parent_hwnd_;
83
84 UniqueMembers(HWND parent_hwnd, RenderWidgetHost* render_widget_host)
85 : parent_hwnd_(parent_hwnd),
86 render_widget_host_(render_widget_host) {
87 }
88 };
89
90 typedef stdext::hash_map<int, UniqueMembers*> InstanceMap;
91 typedef stdext::hash_map<RenderProcessHost*, BrowserAccessibility*>
92 RenderProcessHostMap;
93
[email protected]266eb6f2008-09-30 23:56:5094 // Caching of the unique member variables used to handle browser accessibility
95 // requests from multiple processes.
96 InstanceMap instance_map_;
97 int instance_id_;
98
99 // Reverse mapping to track which RenderProcessHosts are active. If a
100 // RenderProcessHost is found to be terminated, it should be removed from this
101 // mapping, and the connected BrowserAccessibility ids/instances invalidated.
102 RenderProcessHostMap render_process_host_map_;
103
104 ViewHostMsg_Accessibility_Out_Params out_params_;
105
106 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManager);
107};
108#endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_