Chromium Code Reviews| Index: chrome/renderer/resources/extensions/automation/automation_node.js |
| diff --git a/chrome/renderer/resources/extensions/automation/automation_node.js b/chrome/renderer/resources/extensions/automation/automation_node.js |
| index fb851690585913880b3ba70de3c1a2f1ea4dbd09..0f56537d8e05486485073ab17b3af38637be658d 100644 |
| --- a/chrome/renderer/resources/extensions/automation/automation_node.js |
| +++ b/chrome/renderer/resources/extensions/automation/automation_node.js |
| @@ -14,6 +14,14 @@ var schema = requireNative('automationInternal').GetSchemaAdditions(); |
| var utils = require('utils'); |
| /** |
| + * Maps an id in the form: |
| + * <process_id>_<routing_id> |
| + * to an AutomationNode with role type webArea. |
| + * @type {!Object.<string, string>} |
| + */ |
| +var idToWebArea_ = {}; |
| + |
| +/** |
| * A single node in the Automation tree. |
| * @param {AutomationRootNodeImpl} root The root of the tree. |
| * @constructor |
| @@ -34,24 +42,29 @@ AutomationNodeImpl.prototype = { |
| role: '', |
| state: { busy: true }, |
| isRootNode: false, |
| + loaded: false, |
| get root() { |
| return this.rootImpl.wrapper; |
| }, |
| parent: function() { |
| + if (this.role == schema.RoleType.rootWebArea) { |
| + var parentId = this.processID + '_' + this.routingID; |
| + if (idToWebArea_[parentId]) |
| + return idToWebArea_[parentId]; |
| + } |
| return this.rootImpl.get(this.parentID); |
| }, |
| firstChild: function() { |
| - var node = this.rootImpl.get(this.childIds[0]); |
| - return node; |
| + return this.lookupWebAreaChild_() || this.rootImpl.get(this.childIds[0]); |
| }, |
| lastChild: function() { |
| var childIds = this.childIds; |
| - var node = this.rootImpl.get(childIds[childIds.length - 1]); |
| - return node; |
| + return this.lookupWebAreaChild_() || |
| + this.rootImpl.get(childIds[childIds.length - 1]); |
| }, |
| children: function() { |
| @@ -113,6 +126,19 @@ AutomationNodeImpl.prototype = { |
| } |
| }, |
| + load: function(callback) { |
| + if (this.role != schema.RoleType.webArea) |
| + throw 'Unsupported state: can only load webArea nodes.'; |
| + |
| + if (!this.loaded) |
| + automationInternal.enableFrame(this.processID, this.routingID); |
| + |
| + automationUtil.onTreeLoaded(this.processID, this.routingID, function(root) { |
|
aboxhall
2014/10/29 19:29:11
What if instead of creating the AutomationRootNode
David Tseng
2014/10/29 20:35:30
Could you explain further?
The webArea node hosts
aboxhall
2014/10/29 20:53:29
So if I understand correctly, the webArea node has
David Tseng
2014/10/29 21:05:39
Good questions.
Again, to do that during unserial
aboxhall
2014/10/29 21:33:08
I don't think it would be that hard to do the post
David Tseng
2014/10/29 21:47:47
Right, it wouldn't be that hard at all...but the n
|
| + if (callback) |
|
aboxhall
2014/10/29 19:29:11
Perhaps onTreeLoaded should check for null/undefin
David Tseng
2014/10/29 20:35:30
Done.
|
| + callback(root); |
| + }.bind(this)); |
| + }, |
| + |
| dispatchEvent: function(eventType) { |
| var path = []; |
| var parent = this.parent(); |
| @@ -144,6 +170,15 @@ AutomationNodeImpl.prototype = { |
| ' attributes=' + $JSON.stringify(this.attributes); |
| }, |
| + lookupWebAreaChild_: function() { |
| + if (this.role != schema.RoleType.webArea) |
| + return null; |
| + |
| + return automationUtil.idToAutomationRootNode[ |
| + automationUtil.createAutomationRootNodeID( |
| + this.processID, this.routingID)]; |
| + }, |
| + |
| dispatchEventAtCapturing_: function(event, path) { |
| privates(event).impl.eventPhase = Event.CAPTURING_PHASE; |
| for (var i = path.length - 1; i >= 0; i--) { |
| @@ -353,6 +388,9 @@ AutomationRootNodeImpl.prototype = { |
| destroy: function() { |
| this.dispatchEvent(schema.EventType.destroyed); |
| this.invalidate_(this.wrapper); |
| + idToWebArea_[this.processID + |
| + '_' + |
| + this.routingID] = undefined; |
| }, |
| onAccessibilityEvent: function(eventParams) { |
| @@ -406,19 +444,10 @@ AutomationRootNodeImpl.prototype = { |
| nodeImpl[key] = AutomationAttributeDefaults[key]; |
| } |
| nodeImpl.childIds = []; |
| - nodeImpl.loaded = false; |
| nodeImpl.id = id; |
| delete this.axNodeDataCache_[id]; |
| }, |
| - load: function(callback) { |
| - // TODO(dtseng/aboxhall): Implement. |
| - if (!this.loaded) |
| - throw 'Unsupported state: root node is not loaded.'; |
| - |
| - setTimeout(callback, 0); |
| - }, |
| - |
| deleteOldChildren_: function(node, newChildIds) { |
| // Create a set of child ids in |src| for fast lookup, and return false |
| // if a duplicate is found; |
| @@ -495,6 +524,16 @@ AutomationRootNodeImpl.prototype = { |
| setData_: function(node, nodeData) { |
| var nodeImpl = privates(node).impl; |
| + |
| + if (nodeData.role == schema.RoleType.webArea) { |
| + nodeImpl.processID = nodeData.intAttributes.frameId; |
| + nodeImpl.routingID = nodeData.intAttributes.childFrameId; |
| + idToWebArea_[nodeImpl.processID + |
| + '_' + |
| + nodeImpl.routingID] = node; |
| + delete nodeData.intAttributes['processId']; |
| + delete nodeData.intAttributes['routingId']; |
| + } |
| for (var key in AutomationAttributeDefaults) { |
| if (key in nodeData) |
| nodeImpl[key] = nodeData[key]; |
| @@ -599,19 +638,20 @@ var AutomationNode = utils.expose('AutomationNode', |
| 'makeVisible', |
| 'setSelection', |
| 'addEventListener', |
| - 'removeEventListener'], |
| + 'removeEventListener', |
| + 'load'], |
| readonly: ['isRootNode', |
| 'role', |
| 'state', |
| 'location', |
| 'attributes', |
| + 'loaded', |
| 'root'] }); |
| var AutomationRootNode = utils.expose('AutomationRootNode', |
| AutomationRootNodeImpl, |
| { superclass: AutomationNode, |
| - functions: ['load'], |
| - readonly: ['loaded'] }); |
| + functions: ['load'] }); |
| exports.AutomationNode = AutomationNode; |
| exports.AutomationRootNode = AutomationRootNode; |