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