blob: defcb9e53865cc5b92113f30b1157c1af6e5b8a7 [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"
[email protected]bfd04a62009-02-01 18:16:5612#include "chrome/common/notification_observer.h"
[email protected]6a983b42009-03-20 20:12:2513#include "webkit/glue/webaccessibility.h"
[email protected]266eb6f2008-09-30 23:56:5014
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
[email protected]6a983b42009-03-20 20:12:2538 // [acc_obj_id], which is used for IPC communication, and [instance_id],
39 // which is used to identify the mapping between accessibility instance and
40 // RenderProcess.
[email protected]266eb6f2008-09-30 23:56:5041 STDMETHODIMP CreateAccessibilityInstance(REFIID iid,
[email protected]6a983b42009-03-20 20:12:2542 int acc_obj_id,
[email protected]266eb6f2008-09-30 23:56:5043 int instance_id,
44 void** interface_ptr);
45
46 // Composes and sends a message for requesting needed accessibility
47 // information. Unused LONG input parameters should be NULL, and the VARIANT
[email protected]6a983b42009-03-20 20:12:2548 // [var_id] an empty, valid instance.
49 bool RequestAccessibilityInfo(int acc_obj_id,
[email protected]266eb6f2008-09-30 23:56:5050 int instance_id,
[email protected]6a983b42009-03-20 20:12:2551 int acc_func_id,
52 int child_id,
53 long input1,
54 long input2);
[email protected]266eb6f2008-09-30 23:56:5055
56 // Wrapper function, for cleaner code.
[email protected]6a983b42009-03-20 20:12:2557 const webkit_glue::WebAccessibility::OutParams& response();
[email protected]266eb6f2008-09-30 23:56:5058
59 // Retrieves the parent HWND connected to the provided id.
60 HWND parent_hwnd(int id);
61
62 // Mutator, needed since constructor does not take any arguments, and to keep
63 // instance accessor clean.
64 int SetMembers(BrowserAccessibility* browser_acc,
[email protected]6a983b42009-03-20 20:12:2565 HWND parent_hwnd,
66 RenderWidgetHost* render_widget_host);
[email protected]266eb6f2008-09-30 23:56:5067
68 // NotificationObserver implementation.
69 virtual void Observe(NotificationType type,
70 const NotificationSource& source,
71 const NotificationDetails& details);
72
73 protected:
74 // This class is a singleton. Do not instantiate directly.
75 BrowserAccessibilityManager();
[email protected]bdf64792008-10-09 00:03:1876 friend struct DefaultSingletonTraits<BrowserAccessibilityManager>;
[email protected]266eb6f2008-09-30 23:56:5077
78 ~BrowserAccessibilityManager();
79
80 private:
[email protected]8c8657d62009-01-16 18:31:2681 // Member variable structure, used in instance hashmap.
82 struct UniqueMembers {
83 RenderWidgetHost* render_widget_host_;
84 HWND parent_hwnd_;
85
86 UniqueMembers(HWND parent_hwnd, RenderWidgetHost* render_widget_host)
87 : parent_hwnd_(parent_hwnd),
88 render_widget_host_(render_widget_host) {
89 }
90 };
91
92 typedef stdext::hash_map<int, UniqueMembers*> InstanceMap;
93 typedef stdext::hash_map<RenderProcessHost*, BrowserAccessibility*>
94 RenderProcessHostMap;
95
[email protected]266eb6f2008-09-30 23:56:5096 // Caching of the unique member variables used to handle browser accessibility
97 // requests from multiple processes.
98 InstanceMap instance_map_;
99 int instance_id_;
100
101 // Reverse mapping to track which RenderProcessHosts are active. If a
102 // RenderProcessHost is found to be terminated, it should be removed from this
103 // mapping, and the connected BrowserAccessibility ids/instances invalidated.
104 RenderProcessHostMap render_process_host_map_;
105
[email protected]6a983b42009-03-20 20:12:25106 webkit_glue::WebAccessibility::OutParams out_params_;
[email protected]266eb6f2008-09-30 23:56:50107
108 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManager);
109};
110#endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_