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 forEach = require('utils').forEach; | 13 var forEach = require('utils').forEach; |
14 var lastError = require('lastError'); | 14 var lastError = require('lastError'); |
15 var logging = requireNative('logging'); | 15 var logging = requireNative('logging'); |
16 var schema = requireNative('automationInternal').GetSchemaAdditions(); | 16 var nativeAutomationInternal = requireNative('automationInternal'); |
| 17 var GetRoutingID = nativeAutomationInternal.GetRoutingID; |
| 18 var GetSchemaAdditions = nativeAutomationInternal.GetSchemaAdditions; |
| 19 var schema = GetSchemaAdditions(); |
17 | 20 |
18 /** | 21 /** |
19 * A namespace to export utility functions to other files in automation. | 22 * A namespace to export utility functions to other files in automation. |
20 */ | 23 */ |
21 window.automationUtil = function() {}; | 24 window.automationUtil = function() {}; |
22 | 25 |
23 // TODO(aboxhall): Look into using WeakMap | 26 // TODO(aboxhall): Look into using WeakMap |
24 var idToAutomationRootNode = {}; | 27 var idToAutomationRootNode = {}; |
25 var idToCallback = {}; | 28 var idToCallback = {}; |
26 | 29 |
(...skipping 19 matching lines...) Expand all Loading... |
46 /** | 49 /** |
47 * Global list of tree change observers. | 50 * Global list of tree change observers. |
48 * @type {Array<TreeChangeObserver>} | 51 * @type {Array<TreeChangeObserver>} |
49 */ | 52 */ |
50 automationUtil.treeChangeObservers = []; | 53 automationUtil.treeChangeObservers = []; |
51 | 54 |
52 automation.registerCustomHook(function(bindingsAPI) { | 55 automation.registerCustomHook(function(bindingsAPI) { |
53 var apiFunctions = bindingsAPI.apiFunctions; | 56 var apiFunctions = bindingsAPI.apiFunctions; |
54 | 57 |
55 // TODO(aboxhall, dtseng): Make this return the speced AutomationRootNode obj. | 58 // TODO(aboxhall, dtseng): Make this return the speced AutomationRootNode obj. |
56 apiFunctions.setHandleRequest('getTree', function getTree(tabId, callback) { | 59 apiFunctions.setHandleRequest('getTree', function getTree(tabID, callback) { |
| 60 var routingID = GetRoutingID(); |
| 61 |
57 // enableTab() ensures the renderer for the active or specified tab has | 62 // enableTab() ensures the renderer for the active or specified tab has |
58 // accessibility enabled, and fetches its ax tree id to use as | 63 // accessibility enabled, and fetches its ax tree id to use as |
59 // a key in the idToAutomationRootNode map. The callback to | 64 // a key in the idToAutomationRootNode map. The callback to |
60 // enableTab is bound to the callback passed in to getTree(), so that once | 65 // enableTab is bound to the callback passed in to getTree(), so that once |
61 // the tree is available (either due to having been cached earlier, or after | 66 // the tree is available (either due to having been cached earlier, or after |
62 // an accessibility event occurs which causes the tree to be populated), the | 67 // an accessibility event occurs which causes the tree to be populated), the |
63 // callback can be called. | 68 // callback can be called. |
64 automationInternal.enableTab(tabId, function onEnable(id) { | 69 var params = { routingID: routingID, tabID: tabID }; |
65 if (lastError.hasError(chrome)) { | 70 automationInternal.enableTab(params, |
66 callback(); | 71 function onEnable(id) { |
67 return; | 72 if (lastError.hasError(chrome)) { |
68 } | 73 callback(); |
69 automationUtil.storeTreeCallback(id, callback); | 74 return; |
70 }); | 75 } |
| 76 automationUtil.storeTreeCallback(id, callback); |
| 77 }); |
71 }); | 78 }); |
72 | 79 |
73 var desktopTree = null; | 80 var desktopTree = null; |
74 apiFunctions.setHandleRequest('getDesktop', function(callback) { | 81 apiFunctions.setHandleRequest('getDesktop', function(callback) { |
75 desktopTree = | 82 desktopTree = |
76 idToAutomationRootNode[DESKTOP_TREE_ID]; | 83 idToAutomationRootNode[DESKTOP_TREE_ID]; |
77 if (!desktopTree) { | 84 if (!desktopTree) { |
78 if (DESKTOP_TREE_ID in idToCallback) | 85 if (DESKTOP_TREE_ID in idToCallback) |
79 idToCallback[DESKTOP_TREE_ID].push(callback); | 86 idToCallback[DESKTOP_TREE_ID].push(callback); |
80 else | 87 else |
81 idToCallback[DESKTOP_TREE_ID] = [callback]; | 88 idToCallback[DESKTOP_TREE_ID] = [callback]; |
82 | 89 |
| 90 var routingID = GetRoutingID(); |
| 91 |
83 // TODO(dtseng): Disable desktop tree once desktop object goes out of | 92 // TODO(dtseng): Disable desktop tree once desktop object goes out of |
84 // scope. | 93 // scope. |
85 automationInternal.enableDesktop(function() { | 94 automationInternal.enableDesktop(routingID, function() { |
86 if (lastError.hasError(chrome)) { | 95 if (lastError.hasError(chrome)) { |
87 delete idToAutomationRootNode[ | 96 delete idToAutomationRootNode[ |
88 DESKTOP_TREE_ID]; | 97 DESKTOP_TREE_ID]; |
89 callback(); | 98 callback(); |
90 return; | 99 return; |
91 } | 100 } |
92 }); | 101 }); |
93 } else { | 102 } else { |
94 callback(desktopTree); | 103 callback(desktopTree); |
95 } | 104 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 }); | 177 }); |
169 | 178 |
170 exports.binding = automation.generate(); | 179 exports.binding = automation.generate(); |
171 | 180 |
172 // Add additional accessibility bindings not specified in the automation IDL. | 181 // Add additional accessibility bindings not specified in the automation IDL. |
173 // Accessibility and automation share some APIs (see | 182 // Accessibility and automation share some APIs (see |
174 // ui/accessibility/ax_enums.idl). | 183 // ui/accessibility/ax_enums.idl). |
175 forEach(schema, function(k, v) { | 184 forEach(schema, function(k, v) { |
176 exports.binding[k] = v; | 185 exports.binding[k] = v; |
177 }); | 186 }); |
OLD | NEW |