OLD | NEW |
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 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 * Helper javascript injected whenever a DomMutationEventObserver is created. | 5 * Helper javascript injected whenever a DomMutationEventObserver is created. |
6 * | 6 * |
7 * This script uses MutationObservers to watch for changes to the DOM, then | 7 * This script uses MutationObservers to watch for changes to the DOM, then |
8 * reports the event to the observer using the DomAutomationController. An | 8 * reports the event to the observer using the DomAutomationController. An |
9 * anonymous namespace is used to prevent conflict with other Javascript. | 9 * anonymous namespace is used to prevent conflict with other Javascript. |
10 * | 10 * |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 if (node && nodeAttributeValueEquals(node, attribute, expected_value)) { | 155 if (node && nodeAttributeValueEquals(node, attribute, expected_value)) { |
156 raiseEvent(); | 156 raiseEvent(); |
157 console.log("Matching node in DOM, assuming it was previously added."); | 157 console.log("Matching node in DOM, assuming it was previously added."); |
158 return; | 158 return; |
159 } | 159 } |
160 | 160 |
161 var obs = new WebKitMutationObserver(addNodeCallback); | 161 var obs = new WebKitMutationObserver(addNodeCallback); |
162 obs.observe(document, | 162 obs.observe(document, |
163 { childList: true, | 163 { childList: true, |
164 attributes: true, | 164 attributes: true, |
| 165 characterData: true, |
165 subtree: true}); | 166 subtree: true}); |
166 } | 167 } |
167 | 168 |
168 /* Watch for a node matching xpath to be removed from the DOM. | 169 /* Watch for a node matching xpath to be removed from the DOM. |
169 * | 170 * |
170 * Args: | 171 * Args: |
171 * xpath: XPath used to specify the DOM node of interest. | 172 * xpath: XPath used to specify the DOM node of interest. |
172 */ | 173 */ |
173 function observeRemove(xpath) { | 174 function observeRemove(xpath) { |
174 window.domAutomationController.send("success"); | 175 window.domAutomationController.send("success"); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 if (node && nodeAttributeValueEquals(node, attribute, expected_value)) { | 221 if (node && nodeAttributeValueEquals(node, attribute, expected_value)) { |
221 raiseEvent(); | 222 raiseEvent(); |
222 console.log("Node already exists in DOM."); | 223 console.log("Node already exists in DOM."); |
223 return; | 224 return; |
224 } | 225 } |
225 | 226 |
226 var obs = new WebKitMutationObserver(existsNodeCallback); | 227 var obs = new WebKitMutationObserver(existsNodeCallback); |
227 obs.observe(document, | 228 obs.observe(document, |
228 { childList: true, | 229 { childList: true, |
229 attributes: true, | 230 attributes: true, |
| 231 characterData: true, |
230 subtree: true}); | 232 subtree: true}); |
231 } | 233 } |
232 | 234 |
233 /* Interpret arguments and launch the requested observer function. */ | 235 /* Interpret arguments and launch the requested observer function. */ |
234 function installMutationObserver() { | 236 function installMutationObserver() { |
235 switch (observer_type) { | 237 switch (observer_type) { |
236 case "add": | 238 case "add": |
237 observeAdd(xpath); | 239 observeAdd(xpath); |
238 break; | 240 break; |
239 case "remove": | 241 case "remove": |
240 observeRemove(xpath); | 242 observeRemove(xpath); |
241 break; | 243 break; |
242 case "change": | 244 case "change": |
243 observeChange(xpath); | 245 observeChange(xpath); |
244 break; | 246 break; |
245 case "exists": | 247 case "exists": |
246 observeExists(xpath); | 248 observeExists(xpath); |
247 break; | 249 break; |
248 } | 250 } |
249 console.log("MutationObserver javscript injection completed."); | 251 console.log("MutationObserver javscript injection completed."); |
250 } | 252 } |
251 | 253 |
252 /* Ensure the DOM is loaded before attempting to create MutationObservers. */ | 254 /* Ensure the DOM is loaded before attempting to create MutationObservers. */ |
253 if (document.body) { | 255 if (document.body) { |
254 installMutationObserver(); | 256 installMutationObserver(); |
255 } else { | 257 } else { |
256 window.addEventListener("DOMContentLoaded", installMutationObserver, true); | 258 window.addEventListener("DOMContentLoaded", installMutationObserver, true); |
257 } | 259 } |
258 } | 260 } |
OLD | NEW |