[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1 | // 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] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 12 | #include "chrome/common/notification_observer.h" |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 13 | #include "webkit/glue/webaccessibility.h" |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 14 | |
| 15 | class BrowserAccessibility; |
| 16 | class RenderProcessHost; |
| 17 | class RenderWidgetHost; |
| 18 | |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 19 | //////////////////////////////////////////////////////////////////////////////// |
| 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 | //////////////////////////////////////////////////////////////////////////////// |
| 30 | class 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] | bdf6479 | 2008-10-09 00:03:18 | [diff] [blame] | 35 | static BrowserAccessibilityManager* GetInstance(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 36 | |
| 37 | // Creates an instance of BrowserAccessibility, initializes it and sets the |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 38 | // [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] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 41 | STDMETHODIMP CreateAccessibilityInstance(REFIID iid, |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 42 | int acc_obj_id, |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 43 | 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] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 48 | // [var_id] an empty, valid instance. |
| 49 | bool RequestAccessibilityInfo(int acc_obj_id, |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 50 | int instance_id, |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 51 | int acc_func_id, |
| 52 | int child_id, |
| 53 | long input1, |
| 54 | long input2); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 55 | |
| 56 | // Wrapper function, for cleaner code. |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 57 | const webkit_glue::WebAccessibility::OutParams& response(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 58 | |
| 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] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 65 | HWND parent_hwnd, |
| 66 | RenderWidgetHost* render_widget_host); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 67 | |
| 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] | bdf6479 | 2008-10-09 00:03:18 | [diff] [blame] | 76 | friend struct DefaultSingletonTraits<BrowserAccessibilityManager>; |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 77 | |
| 78 | ~BrowserAccessibilityManager(); |
| 79 | |
| 80 | private: |
[email protected] | 8c8657d6 | 2009-01-16 18:31:26 | [diff] [blame] | 81 | // 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] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 96 | // 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] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 106 | webkit_glue::WebAccessibility::OutParams out_params_; |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 107 | |
| 108 | DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityManager); |
| 109 | }; |
| 110 | #endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_MANAGER_H_ |