| 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 AutomationTree = require('automationTree').AutomationTree; | 7 var AutomationTree = require('automationTree').AutomationTree; |
| 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(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 var createAutomationTreeID = function(pid, rid) { | 25 var createAutomationTreeID = function(pid, rid) { |
| 26 return pid + '_' + rid; | 26 return pid + '_' + rid; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 var DESKTOP_TREE_ID = createAutomationTreeID(0, 0); | 29 var DESKTOP_TREE_ID = createAutomationTreeID(0, 0); |
| 30 | 30 |
| 31 automation.registerCustomHook(function(bindingsAPI) { | 31 automation.registerCustomHook(function(bindingsAPI) { |
| 32 var apiFunctions = bindingsAPI.apiFunctions; | 32 var apiFunctions = bindingsAPI.apiFunctions; |
| 33 | 33 |
| 34 // TODO(aboxhall, dtseng): Make this return the speced AutomationRootNode obj. | 34 // TODO(aboxhall, dtseng): Make this return the speced AutomationRootNode obj. |
| 35 apiFunctions.setHandleRequest('getTree', function(callback) { | 35 apiFunctions.setHandleRequest('getTree', function getTree(tabId, callback) { |
| 36 // enableCurrentTab() ensures the renderer for the current tab has | 36 // enableTab() ensures the renderer for the active or specified tab has |
| 37 // accessibility enabled, and fetches its process and routing ids to use as | 37 // accessibility enabled, and fetches its process and routing ids to use as |
| 38 // a key in the idToAutomationTree map. The callback to enableCurrentTab is | 38 // a key in the idToAutomationTree map. The callback to enableActiveTab is |
| 39 // bound to the callback passed in to getTree(), so that once the tree is | 39 // bound to the callback passed in to getTree(), so that once the tree is |
| 40 // available (either due to having been cached earlier, or after an | 40 // available (either due to having been cached earlier, or after an |
| 41 // accessibility event occurs which causes the tree to be populated), the | 41 // accessibility event occurs which causes the tree to be populated), the |
| 42 // callback can be called. | 42 // callback can be called. |
| 43 automationInternal.enableCurrentTab(function(pid, rid) { | 43 automationInternal.enableTab(tabId, function onEnable(pid, rid) { |
| 44 var id = createAutomationTreeID(pid, rid); | 44 var id = createAutomationTreeID(pid, rid); |
| 45 var targetTree = idToAutomationTree[id]; | 45 var targetTree = idToAutomationTree[id]; |
| 46 if (!targetTree) { | 46 if (!targetTree) { |
| 47 // If we haven't cached the tree, hold the callback until the tree is | 47 // If we haven't cached the tree, hold the callback until the tree is |
| 48 // populated by the initial onAccessibilityEvent call. | 48 // populated by the initial onAccessibilityEvent call. |
| 49 if (id in idToCallback) | 49 if (id in idToCallback) |
| 50 idToCallback[id].push(callback); | 50 idToCallback[id].push(callback); |
| 51 else | 51 else |
| 52 idToCallback[id] = [callback]; | 52 idToCallback[id] = [callback]; |
| 53 } else { | 53 } else { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 for (var i = 0; i < idToCallback[id].length; i++) { | 105 for (var i = 0; i < idToCallback[id].length; i++) { |
| 106 var callback = idToCallback[id][i]; | 106 var callback = idToCallback[id][i]; |
| 107 callback(targetTree); | 107 callback(targetTree); |
| 108 } | 108 } |
| 109 delete idToCallback[id]; | 109 delete idToCallback[id]; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 }); | 112 }); |
| 113 | 113 |
| 114 exports.binding = automation.generate(); | 114 exports.binding = automation.generate(); |
| OLD | NEW |