Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/cssProperties.js

Issue 29340901: Issue 4000 - cssProperties.js content script should report matching filters (Closed)
Patch Set: Created April 27, 2016, 5:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 function splitSelector(selector) 1 function splitSelector(selector)
2 { 2 {
3 if (selector.indexOf(",") == -1) 3 if (selector.indexOf(",") == -1)
4 return [selector]; 4 return [selector];
5 5
6 var selectors = []; 6 var selectors = [];
7 var start = 0; 7 var start = 0;
8 var level = 0; 8 var level = 0;
9 var sep = ""; 9 var sep = "";
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 { 64 {
65 return new URL(stylesheet.href).origin == this.window.location.origin; 65 return new URL(stylesheet.href).origin == this.window.location.origin;
66 } 66 }
67 catch (e) 67 catch (e)
68 { 68 {
69 // Invalid URL, assume that it is first-party. 69 // Invalid URL, assume that it is first-party.
70 return true; 70 return true;
71 } 71 }
72 }, 72 },
73 73
74 findSelectors: function(stylesheet, selectors) 74 findSelectors: function(stylesheet, selectors, filters)
75 { 75 {
76 // Explicitly ignore third-party stylesheets to ensure consistent behavior 76 // Explicitly ignore third-party stylesheets to ensure consistent behavior
77 // between Firefox and Chrome. 77 // between Firefox and Chrome.
78 if (!this.isSameOrigin(stylesheet)) 78 if (!this.isSameOrigin(stylesheet))
79 return; 79 return;
80 80
81 var rules = stylesheet.cssRules; 81 var rules = stylesheet.cssRules;
82 if (!rules) 82 if (!rules)
83 return; 83 return;
84 84
(...skipping 10 matching lines...) Expand all
95 var regexp = pattern.regexp; 95 var regexp = pattern.regexp;
96 96
97 if (typeof regexp == "string") 97 if (typeof regexp == "string")
98 regexp = pattern.regexp = new RegExp(regexp); 98 regexp = pattern.regexp = new RegExp(regexp);
99 99
100 if (regexp.test(style)) 100 if (regexp.test(style))
101 { 101 {
102 var subSelectors = splitSelector(rule.selectorText); 102 var subSelectors = splitSelector(rule.selectorText);
103 for (var k = 0; k < subSelectors.length; k++) 103 for (var k = 0; k < subSelectors.length; k++)
104 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix); 104 selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix);
105 filters[pattern.text] = true;
105 } 106 }
106 } 107 }
107 } 108 }
108 }, 109 },
109 110
110 addSelectors: function(stylesheets) 111 addSelectors: function(stylesheets)
111 { 112 {
112 var selectors = []; 113 var selectors = [];
114 var filters = {};
113 for (var i = 0; i < stylesheets.length; i++) 115 for (var i = 0; i < stylesheets.length; i++)
114 this.findSelectors(stylesheets[i], selectors); 116 this.findSelectors(stylesheets[i], selectors, filters);
115 this.addSelectorsFunc(selectors); 117 this.addSelectorsFunc(selectors, Object.keys(filters));
116 }, 118 },
117 119
118 onLoad: function(event) 120 onLoad: function(event)
119 { 121 {
120 var stylesheet = event.target.sheet; 122 var stylesheet = event.target.sheet;
121 if (stylesheet) 123 if (stylesheet)
122 this.addSelectors([stylesheet]); 124 this.addSelectors([stylesheet]);
123 }, 125 },
124 126
125 load: function(callback) 127 load: function(callback)
126 { 128 {
127 this.getFiltersFunc(function(patterns) 129 this.getFiltersFunc(function(patterns)
128 { 130 {
129 this.patterns = patterns; 131 this.patterns = patterns;
130 callback(); 132 callback();
131 }.bind(this)); 133 }.bind(this));
132 }, 134 },
133 135
134 apply: function() 136 apply: function()
135 { 137 {
136 if (this.patterns.length > 0) 138 if (this.patterns.length > 0)
137 { 139 {
138 var document = this.window.document; 140 var document = this.window.document;
139 this.addSelectors(document.styleSheets); 141 this.addSelectors(document.styleSheets);
140 document.addEventListener("load", this.onLoad.bind(this), true); 142 document.addEventListener("load", this.onLoad.bind(this), true);
141 } 143 }
142 } 144 }
143 }; 145 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld