| 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 var contentWatcherNative = requireNative("contentWatcherNative"); | 5 var contentWatcherNative = requireNative("contentWatcherNative"); |
| 6 | 6 |
| 7 // Returns the indices in |cssSelectors| that match any element on the page. | 7 // Returns the indices in |cssSelectors| that match any element on the page. |
| 8 exports.FindMatchingSelectors = function(cssSelectors) { | 8 exports.FindMatchingSelectors = function(cssSelectors) { |
| 9 var result = [] | 9 var result = [] |
| 10 $Array.forEach(cssSelectors, function(selector, index) { | 10 $Array.forEach(cssSelectors, function(selector, index) { |
| 11 try { | 11 try { |
| 12 if (document.querySelector(selector) != null) | 12 if (document.querySelector(selector) != null) |
| 13 result.push(index); | 13 $Array.push(result, index); |
| 14 } catch (exception) { | 14 } catch (exception) { |
| 15 throw new Error("query Selector failed on '" + selector + "': " + | 15 throw new Error("query Selector failed on '" + selector + "': " + |
| 16 exception.stack); | 16 exception.stack); |
| 17 } | 17 } |
| 18 }); | 18 }); |
| 19 return result; | 19 return result; |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 // Watches the page for all changes and calls FrameMutated (a C++ callback) in | 22 // Watches the page for all changes and calls FrameMutated (a C++ callback) in |
| 23 // response. | 23 // response. |
| 24 var mutation_observer = new WebKitMutationObserver( | 24 var mutation_observer = new WebKitMutationObserver( |
| 25 contentWatcherNative.FrameMutated); | 25 contentWatcherNative.FrameMutated); |
| 26 | 26 |
| 27 // This runs once per frame, when the module is 'require'd. | 27 // This runs once per frame, when the module is 'require'd. |
| 28 mutation_observer.observe(document, { | 28 mutation_observer.observe(document, { |
| 29 childList: true, | 29 childList: true, |
| 30 attributes: true, | 30 attributes: true, |
| 31 characterData: true, | 31 characterData: true, |
| 32 subtree: true}); | 32 subtree: true}); |
| OLD | NEW |