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

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

Issue 203753002: Implement actions for Automation API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove braces Created 6 years, 9 months 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 19e4cb815f870e475db45e672f9f85481b2944dc..b637720a4c333de3b4afb089c10f9ded609b8c80 100644
--- a/chrome/renderer/resources/extensions/automation/automation_node.js
+++ b/chrome/renderer/resources/extensions/automation/automation_node.js
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+var automationInternal =
+ require('binding').Binding.create('automationInternal').generate();
var utils = require('utils');
/**
@@ -12,8 +14,8 @@ var utils = require('utils');
var AutomationNodeImpl = function(owner) {
this.owner = owner;
this.child_ids = [];
-
this.attributes = {};
+ this.listeners = {};
};
AutomationNodeImpl.prototype = {
@@ -52,8 +54,64 @@ AutomationNodeImpl.prototype = {
return parent.children()[this.index_in_parent + 1];
return undefined;
},
-};
+ doDefault: function() {
+ this.performAction_('doDefault');
+ },
+
+ focus: function() {
+ this.performAction_('focus');
+ },
+
+ makeVisible: function() {
+ this.performAction_('makeVisible');
+ },
+
+ setSelection: function(startIndex, endIndex) {
+ this.performAction_('setSelection',
+ {start_index: startIndex, end_index: endIndex});
+ },
+
+ addEventListener: function(eventType, callback, capture) {
+ this.removeEventListener(eventType, callback);
+ if (!this.listeners[eventType])
+ this.listeners[eventType] = [];
+ this.listeners[eventType].push([callback, capture]);
+ },
+
+ // TODO(dtseng/aboxhall): Check this impl against spec.
+ removeEventListener: function(eventType, callback) {
+ if (this.listeners[eventType]) {
+ var listeners = this.listeners[eventType];
+ for (var i = 0; i < listeners.length; i++) {
+ if (callback === listeners[i][0])
+ listeners.splice(i, 1);
+ }
+ }
+ },
+
+ notifyEventListeners: function(eventType) {
+ var listeners = this.listeners[eventType];
+ if (!listeners)
+ return;
+ // TODO(dtseng/aboxhall): Implement capture/bubble.
+ for (var i = 0; i < listeners.length; i++)
+ listeners[i][0]();
+ },
+
+ performAction_: function(actionType, opt_args) {
+ // Not yet initialized.
+ if (!this.owner.processId ||
+ !this.owner.routingId ||
+ !this.wrapper.id)
+ return;
+ automationInternal.performAction(this.owner.processId,
+ this.owner.routingId,
+ this.wrapper.id,
+ actionType,
+ opt_args ? opt_args : {});
+ },
+};
var AutomationNode = utils.expose('AutomationNode',
AutomationNodeImpl,
@@ -62,5 +120,11 @@ var AutomationNode = utils.expose('AutomationNode',
'lastChild',
'children',
'previousSibling',
- 'nextSibling']);
+ 'nextSibling',
+ 'doDefault',
+ 'focus',
+ 'makeVisible',
+ 'setSelection',
+ 'addEventListener',
+ 'removeEventListener']);
exports.AutomationNode = AutomationNode;

Powered by Google App Engine
This is Rietveld 408576698