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

Unified Diff: chrome/renderer/resources/extensions/content_watcher.js

Issue 11547033: Implement declarativeContent API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/content_watcher.js
diff --git a/chrome/renderer/resources/extensions/content_watcher.js b/chrome/renderer/resources/extensions/content_watcher.js
new file mode 100644
index 0000000000000000000000000000000000000000..5a3ea61a55d4fbc0b28103a1c3029e5968999b69
--- /dev/null
+++ b/chrome/renderer/resources/extensions/content_watcher.js
@@ -0,0 +1,32 @@
+// 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.
+
+var contentWatcherNative = requireNative("contentWatcherNative");
+
+// Returns the indices in |css_selectors| that match any element on the page.
+exports.FindMatchingSelectors = function(css_selectors) {
+ result = []
+ css_selectors.forEach(function(selector, index) {
+ try {
+ if (document.querySelector(selector) != null)
+ result.push(index);
+ } catch (exception) {
+ throw new Error("query Selector failed on '" + selector + "': " +
+ exception.stack);
+ }
+ });
+ return result;
+};
+
+// Watches the page for all changes and calls FrameMutated (a C++ callback) in
+// response.
+var mutation_observer = new WebKitMutationObserver(
+ contentWatcherNative.FrameMutated);
+
+// This runs once per frame, when the module is 'require'd.
+mutation_observer.observe(document, {
+ childList: true,
+ attributes: true,
+ characterData: true,
+ subtree: true});

Powered by Google App Engine
This is Rietveld 408576698