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

Side by Side 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 unified diff | Download patch
OLDNEW
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 var AutomationEvent = require('automationEvent').AutomationEvent; 5 var AutomationEvent = require('automationEvent').AutomationEvent;
6 var automationInternal = 6 var automationInternal =
7 require('binding').Binding.create('automationInternal').generate(); 7 require('binding').Binding.create('automationInternal').generate();
8 var IsInteractPermitted = 8 var IsInteractPermitted =
9 requireNative('automationInternal').IsInteractPermitted; 9 requireNative('automationInternal').IsInteractPermitted;
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 makeVisible: function() { 86 makeVisible: function() {
87 this.performAction_('makeVisible'); 87 this.performAction_('makeVisible');
88 }, 88 },
89 89
90 setSelection: function(startIndex, endIndex) { 90 setSelection: function(startIndex, endIndex) {
91 this.performAction_('setSelection', 91 this.performAction_('setSelection',
92 { startIndex: startIndex, 92 { startIndex: startIndex,
93 endIndex: endIndex }); 93 endIndex: endIndex });
94 }, 94 },
95 95
96 querySelector: function(selector, callback) {
97 automationInternal.querySelector(
98 { treeID: this.rootImpl.treeID,
99 automationNodeID: this.id,
100 selector: selector },
101 this.querySelectorCallback_.bind(this, callback));
102 },
103
96 addEventListener: function(eventType, callback, capture) { 104 addEventListener: function(eventType, callback, capture) {
97 this.removeEventListener(eventType, callback); 105 this.removeEventListener(eventType, callback);
98 if (!this.listeners[eventType]) 106 if (!this.listeners[eventType])
99 this.listeners[eventType] = []; 107 this.listeners[eventType] = [];
100 this.listeners[eventType].push({callback: callback, capture: !!capture}); 108 this.listeners[eventType].push({callback: callback, capture: !!capture});
101 }, 109 },
102 110
103 // TODO(dtseng/aboxhall): Check this impl against spec. 111 // TODO(dtseng/aboxhall): Check this impl against spec.
104 removeEventListener: function(eventType, callback) { 112 removeEventListener: function(eventType, callback) {
105 if (this.listeners[eventType]) { 113 if (this.listeners[eventType]) {
(...skipping 27 matching lines...) Expand all
133 // - bubbling: starting from the target's parent, going back up to the root. 141 // - bubbling: starting from the target's parent, going back up to the root.
134 // At any stage, a listener may call stopPropagation() on the event, which 142 // At any stage, a listener may call stopPropagation() on the event, which
135 // will immediately stop event propagation through this path. 143 // will immediately stop event propagation through this path.
136 if (this.dispatchEventAtCapturing_(event, path)) { 144 if (this.dispatchEventAtCapturing_(event, path)) {
137 if (this.dispatchEventAtTargeting_(event, path)) 145 if (this.dispatchEventAtTargeting_(event, path))
138 this.dispatchEventAtBubbling_(event, path); 146 this.dispatchEventAtBubbling_(event, path);
139 } 147 }
140 }, 148 },
141 149
142 toString: function() { 150 toString: function() {
143 return 'node id=' + this.id + 151 var impl = privates(this).impl;
152 if (!impl)
153 impl = this;
154 return 'node id=' + impl.id +
144 ' role=' + this.role + 155 ' role=' + this.role +
145 ' state=' + $JSON.stringify(this.state) + 156 ' state=' + $JSON.stringify(this.state) +
146 ' parentID=' + this.parentID + 157 ' parentID=' + impl.parentID +
147 ' childIds=' + $JSON.stringify(this.childIds) + 158 ' childIds=' + $JSON.stringify(impl.childIds) +
148 ' attributes=' + $JSON.stringify(this.attributes); 159 ' attributes=' + $JSON.stringify(this.attributes);
149 }, 160 },
150 161
151 dispatchEventAtCapturing_: function(event, path) { 162 dispatchEventAtCapturing_: function(event, path) {
152 privates(event).impl.eventPhase = Event.CAPTURING_PHASE; 163 privates(event).impl.eventPhase = Event.CAPTURING_PHASE;
153 for (var i = path.length - 1; i >= 0; i--) { 164 for (var i = path.length - 1; i >= 0; i--) {
154 this.fireEventListeners_(path[i], event); 165 this.fireEventListeners_(path[i], event);
155 if (privates(event).impl.propagationStopped) 166 if (privates(event).impl.propagationStopped)
156 return false; 167 return false;
157 } 168 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // Check permissions. 217 // Check permissions.
207 if (!IsInteractPermitted()) { 218 if (!IsInteractPermitted()) {
208 throw new Error(actionType + ' requires {"desktop": true} or' + 219 throw new Error(actionType + ' requires {"desktop": true} or' +
209 ' {"interact": true} in the "automation" manifest key.'); 220 ' {"interact": true} in the "automation" manifest key.');
210 } 221 }
211 222
212 automationInternal.performAction({ treeID: this.rootImpl.treeID, 223 automationInternal.performAction({ treeID: this.rootImpl.treeID,
213 automationNodeID: this.id, 224 automationNodeID: this.id,
214 actionType: actionType }, 225 actionType: actionType },
215 opt_args || {}); 226 opt_args || {});
227 },
228
229 querySelectorCallback_: function(userCallback, resultAutomationNodeID) {
230 // resultAutomationNodeID could be zero or undefined or (unlikely) null;
231 // they all amount to the same thing here, which is that no node was
232 // returned.
233 if (!resultAutomationNodeID) {
234 userCallback(null);
235 return;
236 }
237 var resultNode = this.rootImpl.get(resultAutomationNodeID);
238 if (!resultNode) {
239 logging.WARNING('Query selector result not in tree: ' +
240 resultAutomationNodeID);
241 userCallback(null);
242 }
243 userCallback(resultNode);
216 } 244 }
217 }; 245 };
218 246
219 // Maps an attribute to its default value in an invalidated node. 247 // Maps an attribute to its default value in an invalidated node.
220 // These attributes are taken directly from the Automation idl. 248 // These attributes are taken directly from the Automation idl.
221 var AutomationAttributeDefaults = { 249 var AutomationAttributeDefaults = {
222 'id': -1, 250 'id': -1,
223 'role': '', 251 'role': '',
224 'state': {}, 252 'state': {},
225 'location': { left: 0, top: 0, width: 0, height: 0 } 253 'location': { left: 0, top: 0, width: 0, height: 0 }
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 'lastChild', 636 'lastChild',
609 'children', 637 'children',
610 'previousSibling', 638 'previousSibling',
611 'nextSibling', 639 'nextSibling',
612 'doDefault', 640 'doDefault',
613 'focus', 641 'focus',
614 'makeVisible', 642 'makeVisible',
615 'setSelection', 643 'setSelection',
616 'addEventListener', 644 'addEventListener',
617 'removeEventListener', 645 'removeEventListener',
646 'querySelector',
618 'toJSON'], 647 'toJSON'],
619 readonly: ['isRootNode', 648 readonly: ['isRootNode',
620 'role', 649 'role',
621 'state', 650 'state',
622 'location', 651 'location',
623 'attributes', 652 'attributes',
624 'indexInParent', 653 'indexInParent',
625 'root'] }); 654 'root'] });
626 655
627 var AutomationRootNode = utils.expose('AutomationRootNode', 656 var AutomationRootNode = utils.expose('AutomationRootNode',
628 AutomationRootNodeImpl, 657 AutomationRootNodeImpl,
629 { superclass: AutomationNode }); 658 { superclass: AutomationNode });
630 659
631 exports.AutomationNode = AutomationNode; 660 exports.AutomationNode = AutomationNode;
632 exports.AutomationRootNode = AutomationRootNode; 661 exports.AutomationRootNode = AutomationRootNode;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698