Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7816)

Unified Diff: chrome/renderer/resources/extensions/automation/automation_node.js

Issue 655273005: Implement AutomationNode.querySelector(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fix heap-use-after-free issue by not keeping a scoped_ptr to automation_api_helper in extension_hel… Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 459fa5b32d754ede11d8c9479212167682f9da60..bc57029f597fbeaf241e451b7b589a0f5d9636d7 100644
--- a/chrome/renderer/resources/extensions/automation/automation_node.js
+++ b/chrome/renderer/resources/extensions/automation/automation_node.js
@@ -93,6 +93,14 @@ AutomationNodeImpl.prototype = {
endIndex: endIndex });
},
+ querySelector: function(selector, callback) {
+ automationInternal.querySelector(
+ { treeID: this.rootImpl.treeID,
+ automationNodeID: this.id,
+ selector: selector },
+ this.querySelectorCallback_.bind(this, callback));
+ },
+
addEventListener: function(eventType, callback, capture) {
this.removeEventListener(eventType, callback);
if (!this.listeners[eventType])
@@ -140,11 +148,14 @@ AutomationNodeImpl.prototype = {
},
toString: function() {
- return 'node id=' + this.id +
+ var impl = privates(this).impl;
+ if (!impl)
+ impl = this;
+ return 'node id=' + impl.id +
' role=' + this.role +
' state=' + $JSON.stringify(this.state) +
- ' parentID=' + this.parentID +
- ' childIds=' + $JSON.stringify(this.childIds) +
+ ' parentID=' + impl.parentID +
+ ' childIds=' + $JSON.stringify(impl.childIds) +
' attributes=' + $JSON.stringify(this.attributes);
},
@@ -213,6 +224,23 @@ AutomationNodeImpl.prototype = {
automationNodeID: this.id,
actionType: actionType },
opt_args || {});
+ },
+
+ querySelectorCallback_: function(userCallback, resultAutomationNodeID) {
+ // resultAutomationNodeID could be zero or undefined or (unlikely) null;
+ // they all amount to the same thing here, which is that no node was
+ // returned.
+ if (!resultAutomationNodeID) {
+ userCallback(null);
+ return;
+ }
+ var resultNode = this.rootImpl.get(resultAutomationNodeID);
+ if (!resultNode) {
+ logging.WARNING('Query selector result not in tree: ' +
+ resultAutomationNodeID);
+ userCallback(null);
+ }
+ userCallback(resultNode);
}
};
@@ -615,6 +643,7 @@ var AutomationNode = utils.expose('AutomationNode',
'setSelection',
'addEventListener',
'removeEventListener',
+ 'querySelector',
'toJSON'],
readonly: ['isRootNode',
'role',

Powered by Google App Engine
This is Rietveld 408576698