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

Side by Side 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: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Custom binding for the declarativeContent API. 5 // Custom binding for the declarativeContent API.
6 6
7 var binding = require('binding').Binding.create('declarativeContent'); 7 var binding = require('binding').Binding.create('declarativeContent');
8 8
9 var utils = require('utils'); 9 var utils = require('utils');
10 var validate = require('schemaUtils').validate; 10 var validate = require('schemaUtils').validate;
(...skipping 17 matching lines...) Expand all
28 for (var key in parameters) { 28 for (var key in parameters) {
29 if ($Object.hasOwnProperty(parameters, key)) { 29 if ($Object.hasOwnProperty(parameters, key)) {
30 instance[key] = parameters[key]; 30 instance[key] = parameters[key];
31 } 31 }
32 } 32 }
33 instance.instanceType = 'declarativeContent.' + typeId; 33 instance.instanceType = 'declarativeContent.' + typeId;
34 var schema = getSchema(typeId); 34 var schema = getSchema(typeId);
35 validate([instance], [schema]); 35 validate([instance], [schema]);
36 } 36 }
37 37
38 function canonicalizeCssSelectors(selectors) {
39 var div = document.createElement('div');
40 div.innerHTML = '<style scoped></style>';
41 document.body.appendChild(div);
not at google - send to devlin 2013/08/27 01:46:14 Modifying the page's DOM / exposing our internals
Jeffrey Yasskin 2013/08/27 19:09:48 Note that this only exposes anything to the same e
not at google - send to devlin 2013/08/27 19:39:53 Yeah I know, but extensions still to unwittingly b
Jeffrey Yasskin 2013/08/29 03:39:39 Done: https://codereview.chromium.org/23659002/
42 try {
43 var sheet = document.styleSheets[document.styleSheets.length - 1];
44 for (var i = 0; i < selectors.length; i++) {
45 try {
46 sheet.insertRule(selectors[i] + '{}', 0);
47 } catch(e) {
48 if (e.name == "SyntaxError") {
49 throw new Error('Invalid selector: ' + selectors[i]);
50 }
51 throw e;
52 }
53 selectors[i] = sheet.cssRules[0].selectorText;
54 sheet.deleteRule(0);
55 }
56 } finally {
57 document.body.removeChild(div);
58 }
59 }
60
38 // Setup all data types for the declarative content API. 61 // Setup all data types for the declarative content API.
39 declarativeContent.PageStateMatcher = function(parameters) { 62 declarativeContent.PageStateMatcher = function(parameters) {
40 setupInstance(this, parameters, 'PageStateMatcher'); 63 setupInstance(this, parameters, 'PageStateMatcher');
64 if ('css' in this) {
not at google - send to devlin 2013/08/27 01:46:14 small point, but hasOwnProperty is probably better
Jeffrey Yasskin 2013/08/27 19:09:48 Sure (haven't updated yet, but will). Where's the
not at google - send to devlin 2013/08/27 19:39:53 I mean, for all extension function calls (chrome.b
Jeffrey Yasskin 2013/08/29 03:39:39 Done.
65 canonicalizeCssSelectors(this.css);
66 }
41 }; 67 };
42 declarativeContent.ShowPageAction = function(parameters) { 68 declarativeContent.ShowPageAction = function(parameters) {
43 setupInstance(this, parameters, 'ShowPageAction'); 69 setupInstance(this, parameters, 'ShowPageAction');
44 }; 70 };
45 }); 71 });
46 72
47 exports.binding = binding.generate(); 73 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698