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

Side by Side Diff: chrome/renderer/resources/extensions/automation_custom_bindings.js

Issue 2649373002: Re-land: Update json_schema_compiler to handle the Automation extension API (Closed)
Patch Set: Fix presubmit Created 3 years, 11 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 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 // Custom bindings for the automation API. 5 // Custom bindings for the automation API.
6 var AutomationNode = require('automationNode').AutomationNode; 6 var AutomationNode = require('automationNode').AutomationNode;
7 var AutomationRootNode = require('automationNode').AutomationRootNode; 7 var AutomationRootNode = require('automationNode').AutomationRootNode;
8 var automation = require('binding').Binding.create('automation'); 8 var automation = require('binding').Binding.create('automation');
9 var automationInternal = 9 var automationInternal =
10 require('binding').Binding.create('automationInternal').generate(); 10 require('binding').Binding.create('automationInternal').generate();
11 var eventBindings = require('event_bindings'); 11 var eventBindings = require('event_bindings');
12 var Event = eventBindings.Event; 12 var Event = eventBindings.Event;
13 var exceptionHandler = require('uncaught_exception_handler'); 13 var exceptionHandler = require('uncaught_exception_handler');
14 var forEach = require('utils').forEach; 14 var forEach = require('utils').forEach;
15 var lastError = require('lastError'); 15 var lastError = require('lastError');
16 var logging = requireNative('logging'); 16 var logging = requireNative('logging');
17 var nativeAutomationInternal = requireNative('automationInternal'); 17 var nativeAutomationInternal = requireNative('automationInternal');
18 var GetRoutingID = nativeAutomationInternal.GetRoutingID; 18 var GetRoutingID = nativeAutomationInternal.GetRoutingID;
19 var GetSchemaAdditions = nativeAutomationInternal.GetSchemaAdditions;
20 var DestroyAccessibilityTree = 19 var DestroyAccessibilityTree =
21 nativeAutomationInternal.DestroyAccessibilityTree; 20 nativeAutomationInternal.DestroyAccessibilityTree;
22 var GetIntAttribute = nativeAutomationInternal.GetIntAttribute; 21 var GetIntAttribute = nativeAutomationInternal.GetIntAttribute;
23 var StartCachingAccessibilityTrees = 22 var StartCachingAccessibilityTrees =
24 nativeAutomationInternal.StartCachingAccessibilityTrees; 23 nativeAutomationInternal.StartCachingAccessibilityTrees;
25 var AddTreeChangeObserver = nativeAutomationInternal.AddTreeChangeObserver; 24 var AddTreeChangeObserver = nativeAutomationInternal.AddTreeChangeObserver;
26 var RemoveTreeChangeObserver = 25 var RemoveTreeChangeObserver =
27 nativeAutomationInternal.RemoveTreeChangeObserver; 26 nativeAutomationInternal.RemoveTreeChangeObserver;
28 var GetFocusNative = nativeAutomationInternal.GetFocus; 27 var GetFocusNative = nativeAutomationInternal.GetFocus;
29 var schema = GetSchemaAdditions();
30 28
31 /** 29 /**
32 * A namespace to export utility functions to other files in automation. 30 * A namespace to export utility functions to other files in automation.
33 */ 31 */
34 window.automationUtil = function() {}; 32 window.automationUtil = function() {};
35 33
36 // TODO(aboxhall): Look into using WeakMap 34 // TODO(aboxhall): Look into using WeakMap
37 var idToCallback = {}; 35 var idToCallback = {};
38 36
39 var DESKTOP_TREE_ID = 0; 37 var DESKTOP_TREE_ID = 0;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // A WebView in the desktop tree has a different AX tree as its child. 211 // A WebView in the desktop tree has a different AX tree as its child.
214 // When we encounter a WebView with a child AX tree id that we don't 212 // When we encounter a WebView with a child AX tree id that we don't
215 // currently have cached, explicitly request that AX tree from the 213 // currently have cached, explicitly request that AX tree from the
216 // browser process and set up a callback when it loads to attach that 214 // browser process and set up a callback when it loads to attach that
217 // tree as a child of this node and fire appropriate events. 215 // tree as a child of this node and fire appropriate events.
218 var childTreeID = GetIntAttribute(treeID, nodeID, 'childTreeId'); 216 var childTreeID = GetIntAttribute(treeID, nodeID, 'childTreeId');
219 if (!childTreeID) 217 if (!childTreeID)
220 return; 218 return;
221 219
222 var subroot = AutomationRootNode.get(childTreeID); 220 var subroot = AutomationRootNode.get(childTreeID);
223 if (!subroot || subroot.role == schema.EventType.unknown) { 221 if (!subroot || subroot.role == 'unknown') {
224 automationUtil.storeTreeCallback(childTreeID, function(root) { 222 automationUtil.storeTreeCallback(childTreeID, function(root) {
225 // Return early if the root has already been attached. 223 // Return early if the root has already been attached.
226 if (root.parent) 224 if (root.parent)
227 return; 225 return;
228 226
229 privates(root).impl.setHostNode(node); 227 privates(root).impl.setHostNode(node);
230 228
231 if (root.docLoaded) { 229 if (root.docLoaded) {
232 privates(root).impl.dispatchEvent( 230 privates(root).impl.dispatchEvent('loadComplete', 'page');
233 schema.EventType.loadComplete, 'page');
234 } 231 }
235 232
236 privates(node).impl.dispatchEvent( 233 privates(node).impl.dispatchEvent('childrenChanged', 'none');
237 schema.EventType.childrenChanged, 'none');
238 }); 234 });
239 235
240 automationInternal.enableFrame(childTreeID); 236 automationInternal.enableFrame(childTreeID);
241 } else { 237 } else {
242 privates(subroot).impl.setHostNode(node); 238 privates(subroot).impl.setHostNode(node);
243 } 239 }
244 }); 240 });
245 241
246 automationInternal.onTreeChange.addListener(function(observerID, 242 automationInternal.onTreeChange.addListener(function(observerID,
247 treeID, 243 treeID,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 /** 276 /**
281 * Dispatch accessibility events fired on individual nodes to its 277 * Dispatch accessibility events fired on individual nodes to its
282 * corresponding AutomationNode. Handle focus events specially 278 * corresponding AutomationNode. Handle focus events specially
283 * (see below). 279 * (see below).
284 */ 280 */
285 automationInternal.onAccessibilityEvent.addListener(function(eventParams) { 281 automationInternal.onAccessibilityEvent.addListener(function(eventParams) {
286 var id = eventParams.treeID; 282 var id = eventParams.treeID;
287 var targetTree = AutomationRootNode.getOrCreate(id); 283 var targetTree = AutomationRootNode.getOrCreate(id);
288 284
289 var isFocusEvent = false; 285 var isFocusEvent = false;
290 if (eventParams.eventType == schema.EventType.focus) { 286 if (eventParams.eventType == 'focus') {
291 isFocusEvent = true; 287 isFocusEvent = true;
292 } else if (eventParams.eventType == schema.EventType.blur) { 288 } else if (eventParams.eventType == 'blur') {
293 // Work around an issue where Chrome sends us 'blur' events on the 289 // Work around an issue where Chrome sends us 'blur' events on the
294 // root node when nothing has focus, we need to treat those as focus 290 // root node when nothing has focus, we need to treat those as focus
295 // events but otherwise not handle blur events specially. 291 // events but otherwise not handle blur events specially.
296 var node = privates(targetTree).impl.get(eventParams.targetID); 292 var node = privates(targetTree).impl.get(eventParams.targetID);
297 if (node == node.root) 293 if (node == node.root)
298 automationUtil.updateFocusedNodeOnBlur(); 294 automationUtil.updateFocusedNodeOnBlur();
299 } else if (eventParams.eventType == schema.EventType.mediaStartedPlaying || 295 } else if (eventParams.eventType == 'mediaStartedPlaying' ||
300 eventParams.eventType == schema.EventType.mediaStoppedPlaying) { 296 eventParams.eventType == 'mediaStoppedPlaying') {
301 // These events are global to the tree. 297 // These events are global to the tree.
302 eventParams.targetID = privates(targetTree).impl.id; 298 eventParams.targetID = privates(targetTree).impl.id;
303 } 299 }
304 300
305 // When we get a focus event, ignore the actual event target, and instead 301 // When we get a focus event, ignore the actual event target, and instead
306 // check what node has focus globally. If that represents a focus change, 302 // check what node has focus globally. If that represents a focus change,
307 // fire a focus event on the correct target. 303 // fire a focus event on the correct target.
308 if (isFocusEvent) { 304 if (isFocusEvent) {
309 var previousFocusedNode = automationUtil.focusedNode; 305 var previousFocusedNode = automationUtil.focusedNode;
310 automationUtil.updateFocusedNode(); 306 automationUtil.updateFocusedNode();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 // Destroy the native cache of the accessibility tree. 354 // Destroy the native cache of the accessibility tree.
359 DestroyAccessibilityTree(id); 355 DestroyAccessibilityTree(id);
360 }); 356 });
361 357
362 automationInternal.onAccessibilityTreeSerializationError.addListener( 358 automationInternal.onAccessibilityTreeSerializationError.addListener(
363 function(id) { 359 function(id) {
364 automationInternal.enableFrame(id); 360 automationInternal.enableFrame(id);
365 }); 361 });
366 362
367 var binding = automation.generate(); 363 var binding = automation.generate();
368 // Add additional accessibility bindings not specified in the automation IDL.
369 // Accessibility and automation share some APIs (see
370 // ui/accessibility/ax_enums.idl).
371 forEach(schema, function(k, v) {
372 binding[k] = v;
373 });
374
375 exports.$set('binding', binding); 364 exports.$set('binding', binding);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698