OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Custom bindings for the automation API. | 5 // Custom bindings for the automation API. |
6 var AutomationNode = require('automationNode').AutomationNode; | 6 var AutomationNode = require('automationNode').AutomationNode; |
7 var AutomationRootNode = require('automationNode').AutomationRootNode; | 7 var AutomationRootNode = require('automationNode').AutomationRootNode; |
8 var automation = require('binding').Binding.create('automation'); | 8 var automation = require('binding').Binding.create('automation'); |
9 var automationInternal = | 9 var automationInternal = |
10 require('binding').Binding.create('automationInternal').generate(); | 10 require('binding').Binding.create('automationInternal').generate(); |
11 var eventBindings = require('event_bindings'); | 11 var eventBindings = require('event_bindings'); |
12 var Event = eventBindings.Event; | 12 var Event = eventBindings.Event; |
13 var exceptionHandler = require('uncaught_exception_handler'); | 13 var exceptionHandler = require('uncaught_exception_handler'); |
14 var forEach = require('utils').forEach; | 14 var forEach = require('utils').forEach; |
15 var lastError = require('lastError'); | 15 var lastError = require('lastError'); |
16 var logging = requireNative('logging'); | 16 var logging = requireNative('logging'); |
17 var nativeAutomationInternal = requireNative('automationInternal'); | 17 var nativeAutomationInternal = requireNative('automationInternal'); |
18 var GetRoutingID = nativeAutomationInternal.GetRoutingID; | 18 var GetRoutingID = nativeAutomationInternal.GetRoutingID; |
| 19 var GetSchemaAdditions = nativeAutomationInternal.GetSchemaAdditions; |
19 var DestroyAccessibilityTree = | 20 var DestroyAccessibilityTree = |
20 nativeAutomationInternal.DestroyAccessibilityTree; | 21 nativeAutomationInternal.DestroyAccessibilityTree; |
21 var GetIntAttribute = nativeAutomationInternal.GetIntAttribute; | 22 var GetIntAttribute = nativeAutomationInternal.GetIntAttribute; |
22 var StartCachingAccessibilityTrees = | 23 var StartCachingAccessibilityTrees = |
23 nativeAutomationInternal.StartCachingAccessibilityTrees; | 24 nativeAutomationInternal.StartCachingAccessibilityTrees; |
24 var AddTreeChangeObserver = nativeAutomationInternal.AddTreeChangeObserver; | 25 var AddTreeChangeObserver = nativeAutomationInternal.AddTreeChangeObserver; |
25 var RemoveTreeChangeObserver = | 26 var RemoveTreeChangeObserver = |
26 nativeAutomationInternal.RemoveTreeChangeObserver; | 27 nativeAutomationInternal.RemoveTreeChangeObserver; |
27 var GetFocusNative = nativeAutomationInternal.GetFocus; | 28 var GetFocusNative = nativeAutomationInternal.GetFocus; |
| 29 var schema = GetSchemaAdditions(); |
28 | 30 |
29 /** | 31 /** |
30 * A namespace to export utility functions to other files in automation. | 32 * A namespace to export utility functions to other files in automation. |
31 */ | 33 */ |
32 window.automationUtil = function() {}; | 34 window.automationUtil = function() {}; |
33 | 35 |
34 // TODO(aboxhall): Look into using WeakMap | 36 // TODO(aboxhall): Look into using WeakMap |
35 var idToCallback = {}; | 37 var idToCallback = {}; |
36 | 38 |
37 var DESKTOP_TREE_ID = 0; | 39 var DESKTOP_TREE_ID = 0; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // A WebView in the desktop tree has a different AX tree as its child. | 213 // A WebView in the desktop tree has a different AX tree as its child. |
212 // When we encounter a WebView with a child AX tree id that we don't | 214 // When we encounter a WebView with a child AX tree id that we don't |
213 // currently have cached, explicitly request that AX tree from the | 215 // currently have cached, explicitly request that AX tree from the |
214 // browser process and set up a callback when it loads to attach that | 216 // browser process and set up a callback when it loads to attach that |
215 // tree as a child of this node and fire appropriate events. | 217 // tree as a child of this node and fire appropriate events. |
216 var childTreeID = GetIntAttribute(treeID, nodeID, 'childTreeId'); | 218 var childTreeID = GetIntAttribute(treeID, nodeID, 'childTreeId'); |
217 if (!childTreeID) | 219 if (!childTreeID) |
218 return; | 220 return; |
219 | 221 |
220 var subroot = AutomationRootNode.get(childTreeID); | 222 var subroot = AutomationRootNode.get(childTreeID); |
221 if (!subroot || subroot.role == 'unknown') { | 223 if (!subroot || subroot.role == schema.EventType.unknown) { |
222 automationUtil.storeTreeCallback(childTreeID, function(root) { | 224 automationUtil.storeTreeCallback(childTreeID, function(root) { |
223 // Return early if the root has already been attached. | 225 // Return early if the root has already been attached. |
224 if (root.parent) | 226 if (root.parent) |
225 return; | 227 return; |
226 | 228 |
227 privates(root).impl.setHostNode(node); | 229 privates(root).impl.setHostNode(node); |
228 | 230 |
229 if (root.docLoaded) { | 231 if (root.docLoaded) { |
230 privates(root).impl.dispatchEvent('loadComplete', 'page'); | 232 privates(root).impl.dispatchEvent( |
| 233 schema.EventType.loadComplete, 'page'); |
231 } | 234 } |
232 | 235 |
233 privates(node).impl.dispatchEvent('childrenChanged', 'none'); | 236 privates(node).impl.dispatchEvent( |
| 237 schema.EventType.childrenChanged, 'none'); |
234 }); | 238 }); |
235 | 239 |
236 automationInternal.enableFrame(childTreeID); | 240 automationInternal.enableFrame(childTreeID); |
237 } else { | 241 } else { |
238 privates(subroot).impl.setHostNode(node); | 242 privates(subroot).impl.setHostNode(node); |
239 } | 243 } |
240 }); | 244 }); |
241 | 245 |
242 automationInternal.onTreeChange.addListener(function(observerID, | 246 automationInternal.onTreeChange.addListener(function(observerID, |
243 treeID, | 247 treeID, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 /** | 280 /** |
277 * Dispatch accessibility events fired on individual nodes to its | 281 * Dispatch accessibility events fired on individual nodes to its |
278 * corresponding AutomationNode. Handle focus events specially | 282 * corresponding AutomationNode. Handle focus events specially |
279 * (see below). | 283 * (see below). |
280 */ | 284 */ |
281 automationInternal.onAccessibilityEvent.addListener(function(eventParams) { | 285 automationInternal.onAccessibilityEvent.addListener(function(eventParams) { |
282 var id = eventParams.treeID; | 286 var id = eventParams.treeID; |
283 var targetTree = AutomationRootNode.getOrCreate(id); | 287 var targetTree = AutomationRootNode.getOrCreate(id); |
284 | 288 |
285 var isFocusEvent = false; | 289 var isFocusEvent = false; |
286 if (eventParams.eventType == 'focus') { | 290 if (eventParams.eventType == schema.EventType.focus) { |
287 isFocusEvent = true; | 291 isFocusEvent = true; |
288 } else if (eventParams.eventType == 'blur') { | 292 } else if (eventParams.eventType == schema.EventType.blur) { |
289 // Work around an issue where Chrome sends us 'blur' events on the | 293 // Work around an issue where Chrome sends us 'blur' events on the |
290 // root node when nothing has focus, we need to treat those as focus | 294 // root node when nothing has focus, we need to treat those as focus |
291 // events but otherwise not handle blur events specially. | 295 // events but otherwise not handle blur events specially. |
292 var node = privates(targetTree).impl.get(eventParams.targetID); | 296 var node = privates(targetTree).impl.get(eventParams.targetID); |
293 if (node == node.root) | 297 if (node == node.root) |
294 automationUtil.updateFocusedNodeOnBlur(); | 298 automationUtil.updateFocusedNodeOnBlur(); |
295 } else if (eventParams.eventType == 'mediaStartedPlaying' || | 299 } else if (eventParams.eventType == schema.EventType.mediaStartedPlaying || |
296 eventParams.eventType == 'mediaStoppedPlaying') { | 300 eventParams.eventType == schema.EventType.mediaStoppedPlaying) { |
297 // These events are global to the tree. | 301 // These events are global to the tree. |
298 eventParams.targetID = privates(targetTree).impl.id; | 302 eventParams.targetID = privates(targetTree).impl.id; |
299 } | 303 } |
300 | 304 |
301 // When we get a focus event, ignore the actual event target, and instead | 305 // When we get a focus event, ignore the actual event target, and instead |
302 // check what node has focus globally. If that represents a focus change, | 306 // check what node has focus globally. If that represents a focus change, |
303 // fire a focus event on the correct target. | 307 // fire a focus event on the correct target. |
304 if (isFocusEvent) { | 308 if (isFocusEvent) { |
305 var previousFocusedNode = automationUtil.focusedNode; | 309 var previousFocusedNode = automationUtil.focusedNode; |
306 automationUtil.updateFocusedNode(); | 310 automationUtil.updateFocusedNode(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // Destroy the native cache of the accessibility tree. | 358 // Destroy the native cache of the accessibility tree. |
355 DestroyAccessibilityTree(id); | 359 DestroyAccessibilityTree(id); |
356 }); | 360 }); |
357 | 361 |
358 automationInternal.onAccessibilityTreeSerializationError.addListener( | 362 automationInternal.onAccessibilityTreeSerializationError.addListener( |
359 function(id) { | 363 function(id) { |
360 automationInternal.enableFrame(id); | 364 automationInternal.enableFrame(id); |
361 }); | 365 }); |
362 | 366 |
363 var binding = automation.generate(); | 367 var binding = automation.generate(); |
| 368 // Add additional accessibility bindings not specified in the automation IDL. |
| 369 // Accessibility and automation share some APIs (see |
| 370 // ui/accessibility/ax_enums.idl). |
| 371 forEach(schema, function(k, v) { |
| 372 binding[k] = v; |
| 373 }); |
| 374 |
364 exports.$set('binding', binding); | 375 exports.$set('binding', binding); |
OLD | NEW |