/* Copyright (c) 2012 The Chromium Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * * Helper javascript injected whenever a DomMutationEventObserver is created. * * This script uses MutationObservers to watch for changes to the DOM, then * reports the event to the observer using the DomAutomationController. An * anonymous namespace is used to prevent conflict with other Javascript. * * Args: * automation_id: Automation id used to route DomAutomationController messages. * observer_id: Id of the observer who will be receiving the messages. * observer_type: One of 'add', 'remove', 'change', or 'exists'. * xpath: XPath used to specify the DOM node of interest. * attribute: If |expected_value| is provided, check if this attribute of the * DOM node matches |expected value|. * expected_value: If not null, regular expression to match with the value of * |attribute| after the mutation. */ function(automation_id, observer_id, observer_type, xpath, attribute, expected_value) { /* Raise an event for the DomMutationEventObserver. */ function raiseEvent() { if (window.domAutomationController) { console.log("Event sent to DomEventObserver with id=" + observer_id + "."); window.domAutomationController.sendWithId( automation_id, "__dom_mutation_observer__:" + observer_id); } } /* Calls raiseEvent if the expected node has been added to the DOM. * * Args: * mutations: A list of mutation objects. * observer: The mutation observer object associated with this callback. */ function addNodeCallback(mutations, observer) { for (var j=0; j