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

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

Issue 23478003: Check and canonicalize CSS selectors before registering PageStateMatchers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use WebKit::canonicalizeSelector() instead of CSSStyleRule.selectorText Created 7 years, 4 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/declarative_content_custom_bindings.js
diff --git a/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js b/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
index beb5409e7baab66667f49f3452b5615f13bb8f99..7e06fc66606ef947e47fdeb2d3cf6aaf39126d3d 100644
--- a/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
@@ -8,6 +8,8 @@ var binding = require('binding').Binding.create('declarativeContent');
var utils = require('utils');
var validate = require('schemaUtils').validate;
+var canonicalizeCompoundSelector =
+ requireNative('schema_utils').CanonicalizeCompoundSelector;
binding.registerCustomHook( function(api) {
var declarativeContent = api.compiledApi;
@@ -35,9 +37,25 @@ binding.registerCustomHook( function(api) {
validate([instance], [schema]);
}
+ function canonicalizeCssSelectors(selectors) {
not at google - send to devlin 2013/08/29 15:20:25 you may also want to validate that selectors is an
Jeffrey Yasskin 2013/08/29 21:46:43 The schema validator gets that. I've added a test.
+ for (var i = 0; i < selectors.length; i++) {
+ var canonicalizedSelector = canonicalizeCompoundSelector(selectors[i]);
+ if (canonicalizedSelector == '') {
+ throw new Error(
+ 'Element of \'css\' array must be a ' +
+ 'list of valid compound selectors: ' +
+ selectors[i]);
+ }
+ selectors[i] = canonicalizedSelector;
+ }
+ }
+
// Setup all data types for the declarative content API.
declarativeContent.PageStateMatcher = function(parameters) {
setupInstance(this, parameters, 'PageStateMatcher');
+ if ($Object.hasOwnProperty(this, 'css')) {
+ canonicalizeCssSelectors(this.css);
+ }
};
declarativeContent.ShowPageAction = function(parameters) {
setupInstance(this, parameters, 'ShowPageAction');

Powered by Google App Engine
This is Rietveld 408576698