| OLD | NEW |
| (Empty) |
| 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 #include <comdef.h> | |
| 6 | |
| 7 #include "config.h" | |
| 8 | |
| 9 #pragma warning(push, 0) | |
| 10 #include "AccessibleDocument.h" | |
| 11 #include "AXObjectCache.h" | |
| 12 #include "Document.h" | |
| 13 #include "Frame.h" | |
| 14 #pragma warning(pop) | |
| 15 #undef LOG | |
| 16 | |
| 17 #include "webkit/glue/glue_accessibility.h" | |
| 18 | |
| 19 #include "base/logging.h" | |
| 20 #include "base/ref_counted.h" | |
| 21 #include "webkit/glue/webframe_impl.h" | |
| 22 #include "webkit/glue/webview_impl.h" | |
| 23 | |
| 24 // struct GlueAccessibility::GlueAccessibilityRoot | |
| 25 struct GlueAccessibility::GlueAccessibilityRoot { | |
| 26 GlueAccessibilityRoot() {} | |
| 27 | |
| 28 // Root of the WebKit IAccessible tree. | |
| 29 scoped_refptr<AccessibleDocument> accessibility_root_; | |
| 30 }; | |
| 31 | |
| 32 // class GlueAccessibility | |
| 33 GlueAccessibility::GlueAccessibility() | |
| 34 : root_(new GlueAccessibilityRoot) { | |
| 35 } | |
| 36 | |
| 37 GlueAccessibility::~GlueAccessibility() { | |
| 38 delete root_; | |
| 39 } | |
| 40 | |
| 41 bool GlueAccessibility::GetAccessibilityInfo(WebView* view, | |
| 42 const AccessibilityInParams& in_params, | |
| 43 AccessibilityOutParams* out_params) { | |
| 44 WebFrame* main_frame = view->GetMainFrame(); | |
| 45 if (!main_frame || !static_cast<WebFrameImpl*>(main_frame)->frameview()) | |
| 46 return false; | |
| 47 | |
| 48 if (!root_->accessibility_root_ && !InitAccessibilityRoot(view)) { | |
| 49 // Failure in retrieving the root. | |
| 50 return false; | |
| 51 } | |
| 52 | |
| 53 // Temporary storing for the currently active IAccessible. | |
| 54 scoped_refptr<IAccessible> active_iaccessible; | |
| 55 IntToIAccessibleMap::iterator it = | |
| 56 int_to_iaccessible_map_.find(in_params.iaccessible_id); | |
| 57 | |
| 58 if (it == int_to_iaccessible_map_.end()) { | |
| 59 // Map did not contain the data requested. | |
| 60 return false; | |
| 61 } | |
| 62 | |
| 63 active_iaccessible = it->second; | |
| 64 | |
| 65 if (!active_iaccessible) { | |
| 66 // Requested IAccessible not found. Paranoia check. | |
| 67 NOTREACHED(); | |
| 68 return false; | |
| 69 } | |
| 70 | |
| 71 // Input VARIANT, determined by the browser side to be of type VT_I4. | |
| 72 VARIANT input_variant; | |
| 73 input_variant.vt = VT_I4; | |
| 74 input_variant.lVal = in_params.input_variant_lval; | |
| 75 | |
| 76 // Output variables, used locally to retrieve data. | |
| 77 VARIANT output_variant; | |
| 78 ::VariantInit(&output_variant); | |
| 79 BSTR output_bstr; | |
| 80 bool string_output = false; | |
| 81 HRESULT hr = S_FALSE; | |
| 82 | |
| 83 switch (in_params.iaccessible_function_id) { | |
| 84 case IACCESSIBLE_FUNC_ACCDODEFAULTACTION : | |
| 85 hr = active_iaccessible->accDoDefaultAction(input_variant); | |
| 86 break; | |
| 87 case IACCESSIBLE_FUNC_ACCHITTEST : | |
| 88 hr = active_iaccessible->accHitTest(in_params.input_long1, | |
| 89 in_params.input_long2, | |
| 90 &output_variant); | |
| 91 break; | |
| 92 case IACCESSIBLE_FUNC_ACCLOCATION : | |
| 93 hr = active_iaccessible->accLocation(&out_params->output_long1, | |
| 94 &out_params->output_long2, | |
| 95 &out_params->output_long3, | |
| 96 &out_params->output_long4, | |
| 97 input_variant); | |
| 98 break; | |
| 99 case IACCESSIBLE_FUNC_ACCNAVIGATE : | |
| 100 hr = active_iaccessible->accNavigate(in_params.input_long1, input_variant, | |
| 101 &output_variant); | |
| 102 break; | |
| 103 case IACCESSIBLE_FUNC_GET_ACCCHILD : | |
| 104 if (input_variant.lVal == CHILDID_SELF) { | |
| 105 // If child requested is CHILDID_SELF, stay with the same IAccessible. | |
| 106 out_params->iaccessible_id = in_params.iaccessible_id; | |
| 107 hr = S_OK; | |
| 108 break; | |
| 109 } | |
| 110 hr = active_iaccessible->get_accChild(input_variant, | |
| 111 reinterpret_cast<IDispatch **>(&output_variant.pdispVal)); | |
| 112 output_variant.vt = VT_DISPATCH; | |
| 113 break; | |
| 114 case IACCESSIBLE_FUNC_GET_ACCCHILDCOUNT : | |
| 115 hr = active_iaccessible->get_accChildCount(&out_params->output_long1); | |
| 116 break; | |
| 117 case IACCESSIBLE_FUNC_GET_ACCDEFAULTACTION : | |
| 118 hr = active_iaccessible->get_accDefaultAction(input_variant, | |
| 119 &output_bstr); | |
| 120 string_output = true; | |
| 121 break; | |
| 122 case IACCESSIBLE_FUNC_GET_ACCDESCRIPTION : | |
| 123 hr = active_iaccessible->get_accDescription(input_variant, &output_bstr); | |
| 124 string_output = true; | |
| 125 break; | |
| 126 case IACCESSIBLE_FUNC_GET_ACCFOCUS : | |
| 127 hr = active_iaccessible->get_accFocus(&output_variant); | |
| 128 break; | |
| 129 case IACCESSIBLE_FUNC_GET_ACCHELP : | |
| 130 hr = active_iaccessible->get_accHelp(input_variant, &output_bstr); | |
| 131 string_output = true; | |
| 132 break; | |
| 133 case IACCESSIBLE_FUNC_GET_ACCKEYBOARDSHORTCUT : | |
| 134 hr = active_iaccessible->get_accKeyboardShortcut(input_variant, | |
| 135 &output_bstr); | |
| 136 string_output = true; | |
| 137 break; | |
| 138 case IACCESSIBLE_FUNC_GET_ACCNAME : | |
| 139 hr = active_iaccessible->get_accName(input_variant, &output_bstr); | |
| 140 string_output = true; | |
| 141 break; | |
| 142 case IACCESSIBLE_FUNC_GET_ACCPARENT : | |
| 143 hr = active_iaccessible->get_accParent( | |
| 144 reinterpret_cast<IDispatch **>(&output_variant.pdispVal)); | |
| 145 output_variant.vt = VT_DISPATCH; | |
| 146 break; | |
| 147 case IACCESSIBLE_FUNC_GET_ACCROLE : | |
| 148 hr = active_iaccessible->get_accRole(input_variant, &output_variant); | |
| 149 break; | |
| 150 case IACCESSIBLE_FUNC_GET_ACCSTATE : | |
| 151 hr = active_iaccessible->get_accState(input_variant, &output_variant); | |
| 152 break; | |
| 153 case IACCESSIBLE_FUNC_GET_ACCVALUE : | |
| 154 hr = active_iaccessible->get_accValue(input_variant, &output_bstr); | |
| 155 string_output = true; | |
| 156 break; | |
| 157 default: | |
| 158 // Memory cleanup. | |
| 159 ::VariantClear(&input_variant); | |
| 160 ::VariantClear(&output_variant); | |
| 161 | |
| 162 // Non-supported function id. | |
| 163 return false; | |
| 164 } | |
| 165 | |
| 166 // Return code handling. | |
| 167 if (hr == S_OK) { | |
| 168 out_params->return_code = true; | |
| 169 | |
| 170 // All is ok, assign output string if needed. | |
| 171 if (string_output) { | |
| 172 out_params->output_string = _bstr_t(output_bstr); | |
| 173 ::SysFreeString(output_bstr); | |
| 174 } | |
| 175 | |
| 176 } else if (hr == S_FALSE) { | |
| 177 out_params->return_code = false; | |
| 178 } else { | |
| 179 // Memory cleanup. | |
| 180 ::VariantClear(&input_variant); | |
| 181 ::VariantClear(&output_variant); | |
| 182 | |
| 183 // Generate a generic failure on the browser side. Input validation is the | |
| 184 // responsibility of the browser side, as is correctly handling calls to | |
| 185 // non-supported functions appropriately. | |
| 186 return false; | |
| 187 } | |
| 188 | |
| 189 // Output and hashmap assignments, as appropriate. | |
| 190 if (output_variant.vt == VT_DISPATCH && output_variant.pdispVal) { | |
| 191 IAccessibleToIntMap::iterator it = | |
| 192 iaccessible_to_int_map_.find( | |
| 193 reinterpret_cast<IAccessible *>(output_variant.pdispVal)); | |
| 194 | |
| 195 if (it != iaccessible_to_int_map_.end()) { | |
| 196 // Data already present in map, return previously assigned id. | |
| 197 out_params->iaccessible_id = it->second; | |
| 198 out_params->output_long1 = -1; | |
| 199 } else { | |
| 200 // Insert new IAccessible in hashmaps. | |
| 201 int_to_iaccessible_map_[iaccessible_id_] = | |
| 202 reinterpret_cast<IAccessible *>(output_variant.pdispVal); | |
| 203 iaccessible_to_int_map_[ | |
| 204 reinterpret_cast<IAccessible *>(output_variant.pdispVal)] = | |
| 205 iaccessible_id_; | |
| 206 out_params->iaccessible_id = iaccessible_id_++; | |
| 207 out_params->output_long1 = -1; | |
| 208 } | |
| 209 } else if (output_variant.vt == VT_I4) { | |
| 210 out_params->output_long1 = output_variant.lVal; | |
| 211 } | |
| 212 | |
| 213 // Memory cleanup. | |
| 214 ::VariantClear(&input_variant); | |
| 215 ::VariantClear(&output_variant); | |
| 216 | |
| 217 return true; | |
| 218 } | |
| 219 | |
| 220 bool GlueAccessibility::InitAccessibilityRoot(WebView* view) { | |
| 221 WebCore::AXObjectCache::enableAccessibility(); | |
| 222 iaccessible_id_ = 0; | |
| 223 | |
| 224 WebFrame* main_frame = view->GetMainFrame(); | |
| 225 WebFrameImpl* main_frame_impl = static_cast<WebFrameImpl*>(main_frame); | |
| 226 WebCore::Frame* frame = main_frame_impl->frame(); | |
| 227 WebCore::Document* currentDocument = frame->document(); | |
| 228 | |
| 229 if (!currentDocument || !currentDocument->renderer()) { | |
| 230 return false; | |
| 231 } else if (!root_->accessibility_root_ || | |
| 232 root_->accessibility_root_->document() != currentDocument) { | |
| 233 // Either we've never had a wrapper for this frame's top-level Document, | |
| 234 // the Document renderer was destroyed and its wrapper was detached, or | |
| 235 // the previous Document is in the page cache, and the current document | |
| 236 // needs to be wrapped. | |
| 237 root_->accessibility_root_ = new AccessibleDocument(currentDocument); | |
| 238 } | |
| 239 // Insert root in hashmaps. | |
| 240 int_to_iaccessible_map_[iaccessible_id_] = root_->accessibility_root_.get(); | |
| 241 iaccessible_to_int_map_[root_->accessibility_root_.get()] = iaccessible_id_++; | |
| 242 | |
| 243 return true; | |
| 244 } | |
| 245 | |
| 246 bool GlueAccessibility::ClearIAccessibleMap(int iaccessible_id, | |
| 247 bool clear_all) { | |
| 248 if (clear_all) { | |
| 249 // Clear maps and invalidate root. | |
| 250 int_to_iaccessible_map_.clear(); | |
| 251 iaccessible_to_int_map_.clear(); | |
| 252 root_->accessibility_root_ = 0; | |
| 253 return true; | |
| 254 } | |
| 255 | |
| 256 IntToIAccessibleMap::iterator it = | |
| 257 int_to_iaccessible_map_.find(iaccessible_id); | |
| 258 | |
| 259 if (it == int_to_iaccessible_map_.end()) { | |
| 260 // Element not found. | |
| 261 return false; | |
| 262 } else { | |
| 263 if (it->second) { | |
| 264 // Erase element from reverse hashmap. | |
| 265 IAccessibleToIntMap::iterator it2 = | |
| 266 iaccessible_to_int_map_.find(it->second.get()); | |
| 267 | |
| 268 DCHECK(it2 != iaccessible_to_int_map_.end()); | |
| 269 iaccessible_to_int_map_.erase(it2); | |
| 270 } | |
| 271 | |
| 272 int_to_iaccessible_map_.erase(it); | |
| 273 | |
| 274 if (iaccessible_id == 0) { | |
| 275 // Invalidate root. | |
| 276 root_->accessibility_root_ = 0; | |
| 277 } | |
| 278 } | |
| 279 | |
| 280 return true; | |
| 281 } | |
| OLD | NEW |