Index: chrome/renderer/resources/extensions/automation_custom_bindings.js |
diff --git a/chrome/renderer/resources/extensions/automation_custom_bindings.js b/chrome/renderer/resources/extensions/automation_custom_bindings.js |
index d83d6052bfb164c7d1352df826b91a84854ed92f..d20bfff13027c3565565b8762feecdbd019fdee1 100644 |
--- a/chrome/renderer/resources/extensions/automation_custom_bindings.js |
+++ b/chrome/renderer/resources/extensions/automation_custom_bindings.js |
@@ -12,29 +12,40 @@ var AutomationNode = require('automationNode').AutomationNode; |
var AutomationTree = require('automationTree').AutomationTree; |
// TODO(aboxhall): Look into using WeakMap |
-var routingIdToAutomationTree = {}; |
-var routingIdToCallback = {}; |
+var idToAutomationTree = {}; |
+var idToCallback = {}; |
+ |
+// TODO(dtseng): Move out to automation/automation_util.js or as a static member |
+// of AutomationTree to keep this file clean. |
+/* |
+ * Creates an id associated with a particular AutomationTree based upon a |
+ * renderer/renderer host pair's process and routing id. |
+ */ |
+var createAutomationTreeID = function(pid, rid) { |
+ return pid + '_' + rid; |
+}; |
automation.registerCustomHook(function(bindingsAPI) { |
var apiFunctions = bindingsAPI.apiFunctions; |
apiFunctions.setHandleRequest('getTree', function(callback) { |
// enableCurrentTab() ensures the renderer for the current tab has |
- // accessibility enabled, and fetches its routing id to use as a key in the |
- // routingIdToAutomationTree map. The callback to enableCurrentTab is bound |
- // to the callback passed in to getTree(), so that once the tree is |
+ // accessibility enabled, and fetches its process and routing ids to use as |
+ // a key in the idToAutomationTree map. The callback to enableCurrentTab is |
+ // bound to the callback passed in to getTree(), so that once the tree is |
// available (either due to having been cached earlier, or after an |
// accessibility event occurs which causes the tree to be populated), the |
// callback can be called. |
- automationInternal.enableCurrentTab(function(rid) { |
- var targetTree = routingIdToAutomationTree[rid]; |
+ automationInternal.enableCurrentTab(function(pid, rid) { |
+ var id = createAutomationTreeID(pid, rid); |
+ var targetTree = idToAutomationTree[id]; |
if (!targetTree) { |
// If we haven't cached the tree, hold the callback until the tree is |
// populated by the initial onAccessibilityEvent call. |
- if (rid in routingIdToCallback) |
- routingIdToCallback[rid].push(callback); |
+ if (id in idToCallback) |
+ idToCallback[id].push(callback); |
else |
- routingIdToCallback[rid] = [callback]; |
+ idToCallback[id] = [callback]; |
} else { |
callback(targetTree); |
} |
@@ -46,32 +57,28 @@ automation.registerCustomHook(function(bindingsAPI) { |
// essentially a proxy for the AccessibilityHostMsg_Events IPC from the |
// renderer. |
automationInternal.onAccessibilityEvent.addListener(function(data) { |
+ var pid = data.process_id; |
var rid = data.routing_id; |
- var targetTree = routingIdToAutomationTree[rid]; |
+ var id = createAutomationTreeID(pid, rid); |
+ var targetTree = idToAutomationTree[id]; |
if (!targetTree) { |
// If this is the first time we've gotten data for this tree, it will |
// contain all of the tree's data, so create a new tree which will be |
// bootstrapped from |data|. |
- targetTree = new AutomationTree(rid); |
- routingIdToAutomationTree[rid] = targetTree; |
- } |
- if (privates(targetTree).impl.update(data)) { |
- // TODO(aboxhall/dtseng): remove and replace with EventListener style API |
- targetTree.onUpdate.dispatch(); |
+ targetTree = new AutomationTree(pid, rid); |
+ idToAutomationTree[id] = targetTree; |
} |
- |
- // TODO(aboxhall/dtseng): call appropriate event listeners based on |
- // data.event_type. |
+ privates(targetTree).impl.update(data); |
// If the tree wasn't available when getTree() was called, the callback will |
- // have been cached in routingIdToCallback, so call and delete it now that we |
+ // have been cached in idToCallback, so call and delete it now that we |
// have the tree. |
- if (rid in routingIdToCallback) { |
- for (var i = 0; i < routingIdToCallback[rid].length; i++) { |
- var callback = routingIdToCallback[rid][i]; |
+ if (id in idToCallback) { |
+ for (var i = 0; i < idToCallback[id].length; i++) { |
+ var callback = idToCallback[id][i]; |
callback(targetTree); |
} |
- delete routingIdToCallback[rid]; |
+ delete idToCallback[id]; |
} |
}); |