| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/browser_accessibility_manager.h" | 5 #include "chrome/browser/browser_accessibility_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_accessibility.h" | 7 #include "chrome/browser/browser_accessibility.h" |
| 8 #include "chrome/browser/renderer_host/render_process_host.h" | 8 #include "chrome/browser/renderer_host/render_process_host.h" |
| 9 #include "chrome/browser/renderer_host/render_widget_host.h" | 9 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| 11 #include "chrome/common/render_messages.h" | 11 #include "chrome/common/render_messages.h" |
| 12 | 12 |
| 13 using webkit_glue::WebAccessibility; |
| 14 |
| 13 // The time in ms after which we give up and return an error when processing an | 15 // The time in ms after which we give up and return an error when processing an |
| 14 // accessibility message and no response has been received from the renderer. | 16 // accessibility message and no response has been received from the renderer. |
| 15 static const int kAccessibilityMessageTimeOut = 500; | 17 static const int kAccessibilityMessageTimeOut = 10000; |
| 16 | 18 |
| 17 // static | 19 // static |
| 18 BrowserAccessibilityManager* BrowserAccessibilityManager::GetInstance() { | 20 BrowserAccessibilityManager* BrowserAccessibilityManager::GetInstance() { |
| 19 return Singleton<BrowserAccessibilityManager>::get(); | 21 return Singleton<BrowserAccessibilityManager>::get(); |
| 20 } | 22 } |
| 21 | 23 |
| 22 BrowserAccessibilityManager::BrowserAccessibilityManager() | 24 BrowserAccessibilityManager::BrowserAccessibilityManager() |
| 23 : instance_id_(0) { | 25 : instance_id_(0) { |
| 24 NotificationService::current()->AddObserver(this, | 26 NotificationService::current()->AddObserver(this, |
| 25 NotificationType::RENDERER_PROCESS_TERMINATED, | 27 NotificationType::RENDERER_PROCESS_TERMINATED, |
| 26 NotificationService::AllSources()); | 28 NotificationService::AllSources()); |
| 27 } | 29 } |
| 28 | 30 |
| 29 BrowserAccessibilityManager::~BrowserAccessibilityManager() { | 31 BrowserAccessibilityManager::~BrowserAccessibilityManager() { |
| 30 // Clear hashmaps. | 32 // Clear hashmaps. |
| 31 instance_map_.clear(); | 33 instance_map_.clear(); |
| 32 render_process_host_map_.clear(); | 34 render_process_host_map_.clear(); |
| 33 | 35 |
| 34 // We don't remove ourselves as an observer because we are a Singleton object, | 36 // We don't remove ourselves as an observer because we are a Singleton object, |
| 35 // and NotifcationService is likely gone by this point. | 37 // and NotifcationService is likely gone by this point. |
| 36 } | 38 } |
| 37 | 39 |
| 38 STDMETHODIMP BrowserAccessibilityManager::CreateAccessibilityInstance( | 40 STDMETHODIMP BrowserAccessibilityManager::CreateAccessibilityInstance( |
| 39 REFIID iid, int iaccessible_id, int instance_id, void** interface_ptr) { | 41 REFIID iid, int acc_obj_id, int instance_id, void** interface_ptr) { |
| 40 if (IID_IUnknown == iid || IID_IDispatch == iid || IID_IAccessible == iid) { | 42 if (IID_IUnknown == iid || IID_IDispatch == iid || IID_IAccessible == iid) { |
| 41 CComObject<BrowserAccessibility>* instance = NULL; | 43 CComObject<BrowserAccessibility>* instance = NULL; |
| 42 | 44 |
| 43 HRESULT hr = CComObject<BrowserAccessibility>::CreateInstance(&instance); | 45 HRESULT hr = CComObject<BrowserAccessibility>::CreateInstance(&instance); |
| 44 DCHECK(SUCCEEDED(hr)); | 46 DCHECK(SUCCEEDED(hr)); |
| 45 | 47 |
| 46 if (!instance) | 48 if (!instance) |
| 47 return E_FAIL; | 49 return E_FAIL; |
| 48 | 50 |
| 49 CComPtr<IAccessible> accessibility_instance(instance); | 51 CComPtr<IAccessible> accessibility_instance(instance); |
| 50 | 52 |
| 51 // Set unique ids. | 53 // Set unique ids. |
| 52 instance->set_iaccessible_id(iaccessible_id); | 54 instance->set_iaccessible_id(acc_obj_id); |
| 53 instance->set_instance_id(instance_id); | 55 instance->set_instance_id(instance_id); |
| 54 | 56 |
| 55 // Retrieve the RenderWidgetHost connected to this request. | 57 // Retrieve the RenderWidgetHost connected to this request. |
| 56 InstanceMap::iterator it = instance_map_.find(instance_id); | 58 InstanceMap::iterator it = instance_map_.find(instance_id); |
| 57 | 59 |
| 58 if (it != instance_map_.end()) { | 60 if (it != instance_map_.end()) { |
| 59 UniqueMembers* members = it->second; | 61 UniqueMembers* members = it->second; |
| 60 | 62 |
| 61 if (!members || !members->render_widget_host_) | 63 if (!members || !members->render_widget_host_) |
| 62 return E_FAIL; | 64 return E_FAIL; |
| 63 | 65 |
| 64 render_process_host_map_[members->render_widget_host_->process()] = | 66 render_process_host_map_[members->render_widget_host_->process()] = |
| 65 instance; | 67 instance; |
| 66 } else { | 68 } else { |
| 67 // No RenderProcess active for this instance. | 69 // No RenderProcess active for this instance. |
| 68 return E_FAIL; | 70 return E_FAIL; |
| 69 } | 71 } |
| 70 | 72 |
| 71 // All is well, assign the temp instance to the output pointer. | 73 // All is well, assign the temp instance to the output pointer. |
| 72 *interface_ptr = accessibility_instance.Detach(); | 74 *interface_ptr = accessibility_instance.Detach(); |
| 73 return S_OK; | 75 return S_OK; |
| 74 } | 76 } |
| 75 // No supported interface found, return error. | 77 // No supported interface found, return error. |
| 76 *interface_ptr = NULL; | 78 *interface_ptr = NULL; |
| 77 return E_NOINTERFACE; | 79 return E_NOINTERFACE; |
| 78 } | 80 } |
| 79 | 81 |
| 80 bool BrowserAccessibilityManager::RequestAccessibilityInfo( | 82 bool BrowserAccessibilityManager::RequestAccessibilityInfo( |
| 81 int iaccessible_id, int instance_id, int iaccessible_func_id, | 83 int acc_obj_id, int instance_id, int acc_func_id, int child_id, long input1, |
| 82 VARIANT var_id, LONG input1, LONG input2) { | 84 long input2) { |
| 83 // Create and populate input message structure. | 85 // Create and populate IPC message structure, for retrieval of accessibility |
| 84 AccessibilityInParams in_params; | 86 // information from the renderer. |
| 85 | 87 WebAccessibility::InParams in_params; |
| 86 in_params.iaccessible_id = iaccessible_id; | 88 in_params.object_id = acc_obj_id; |
| 87 in_params.iaccessible_function_id = iaccessible_func_id; | 89 in_params.function_id = acc_func_id; |
| 88 in_params.input_variant_lval = var_id.lVal; | 90 in_params.child_id = child_id; |
| 89 in_params.input_long1 = input1; | 91 in_params.input_long1 = input1; |
| 90 in_params.input_long2 = input2; | 92 in_params.input_long2 = input2; |
| 91 | 93 |
| 92 // Retrieve the RenderWidgetHost connected to this request. | 94 // Retrieve the RenderWidgetHost connected to this request. |
| 93 InstanceMap::iterator it = instance_map_.find(instance_id); | 95 InstanceMap::iterator it = instance_map_.find(instance_id); |
| 94 | 96 |
| 95 if (it == instance_map_.end()) { | 97 if (it == instance_map_.end()) { |
| 96 // Id not found. | 98 // Id not found. |
| 97 return false; | 99 return false; |
| 98 } | 100 } |
| 99 | 101 |
| 100 UniqueMembers* members = it->second; | 102 UniqueMembers* members = it->second; |
| 101 | 103 |
| 102 if (!members || !members->render_widget_host_) | 104 if (!members || !members->render_widget_host_) |
| 103 return false; | 105 return false; |
| 104 | 106 |
| 105 bool success = false; | 107 bool success = false; |
| 106 if (members->render_widget_host_->process() && | 108 if (members->render_widget_host_->process() && |
| 107 members->render_widget_host_->process()->channel()) { | 109 members->render_widget_host_->process()->channel()) { |
| 108 IPC::SyncMessage* msg = | 110 IPC::SyncMessage* msg = |
| 109 new ViewMsg_GetAccessibilityInfo(members->render_widget_host_-> | 111 new ViewMsg_GetAccessibilityInfo(members->render_widget_host_-> |
| 110 routing_id(), in_params, &out_params_); | 112 routing_id(), in_params, &out_params_); |
| 111 // Necessary for the send to keep the UI responsive. | 113 // Necessary for the send to keep the UI responsive. |
| 112 msg->EnableMessagePumping(); | 114 msg->EnableMessagePumping(); |
| 113 success = members->render_widget_host_->process()->channel()-> | 115 success = members->render_widget_host_->process()->channel()-> |
| 114 SendWithTimeout(msg, kAccessibilityMessageTimeOut); | 116 SendWithTimeout(msg, kAccessibilityMessageTimeOut); |
| 115 } | 117 } |
| 116 | |
| 117 return success; | 118 return success; |
| 118 } | 119 } |
| 119 | 120 |
| 120 const AccessibilityOutParams& BrowserAccessibilityManager::response() { | 121 const WebAccessibility::OutParams& BrowserAccessibilityManager::response() { |
| 121 return out_params_; | 122 return out_params_; |
| 122 } | 123 } |
| 123 | 124 |
| 124 HWND BrowserAccessibilityManager::parent_hwnd(int id) { | 125 HWND BrowserAccessibilityManager::parent_hwnd(int id) { |
| 125 // Retrieve the parent HWND connected to the requester's id. | 126 // Retrieve the parent HWND connected to the requester's id. |
| 126 InstanceMap::iterator it = instance_map_.find(id); | 127 InstanceMap::iterator it = instance_map_.find(id); |
| 127 | 128 |
| 128 if (it == instance_map_.end()) { | 129 if (it == instance_map_.end()) { |
| 129 // Id not found. | 130 // Id not found. |
| 130 return NULL; | 131 return NULL; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 167 |
| 167 // Delete entry also from InstanceMap. | 168 // Delete entry also from InstanceMap. |
| 168 InstanceMap::iterator it2 = instance_map_.find(it->second->instance_id()); | 169 InstanceMap::iterator it2 = instance_map_.find(it->second->instance_id()); |
| 169 | 170 |
| 170 if (it2 != instance_map_.end()) | 171 if (it2 != instance_map_.end()) |
| 171 instance_map_.erase(it2); | 172 instance_map_.erase(it2); |
| 172 | 173 |
| 173 // Only delete the first entry once it is no longer in use. | 174 // Only delete the first entry once it is no longer in use. |
| 174 render_process_host_map_.erase(it); | 175 render_process_host_map_.erase(it); |
| 175 } | 176 } |
| OLD | NEW |