~midori/midori/trunk

« back to all changes in this revision

Viewing changes to extensions/adblock/subscriptions.vala

  • Committer: RabbitBot
  • Author(s): Paweł Forysiuk
  • Date: 2014-03-20 20:30:46 UTC
  • mfrom: (6604.2.5 adblock-buglets)
  • Revision ID: rabbitbot-20140320203046-atne7161oe2j9o1n
Small adblock bugfixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
            }
161
161
        }
162
162
 
163
 
        void update_css_hash (string domain, string value) {
 
163
        bool css_element_seems_valid (string element) {
 
164
            bool is_valid = true;
164
165
            string[] valid_elements = { "::after", "::before", "a", "abbr", "address", "article", "aside",
165
166
                "b", "blockquote", "caption", "center", "cite", "code", "div", "dl", "dt", "dd", "em",
166
167
                "feed", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6",
168
169
                "m", "main", "marquee", "menu", "nav", "ol", "option", "p", "pre", "q", "samp", "section",
169
170
                "small", "span", "strong", "summary", "table", "tr", "tbody", "td", "th", "thead", "tt", "ul" };
170
171
 
171
 
            if (!value.has_prefix (".") && !value.has_prefix ("#")
172
 
             && !(value.split("[")[0] in valid_elements))
173
 
                  message ("Adblock: Invalid selector: %s", value);
174
 
            string? olddata = element.lookup (domain);
175
 
            if (olddata != null) {
176
 
                string newdata = olddata + " , " + value;
177
 
                element.insert (domain, newdata);
178
 
            } else {
179
 
                element.insert (domain, value);
 
172
            if (!element.has_prefix (".") && !element.has_prefix ("#")
 
173
            && !(element.split("[")[0] in valid_elements))
 
174
                is_valid = false;
 
175
 
 
176
 
 
177
            bool debug_selectors = "adblock:css" in (Environment.get_variable ("MIDORI_DEBUG") ?? "");
 
178
            if (debug_selectors)
 
179
                stdout.printf ("Adblock '%s' %s: %s\n",
 
180
                    this.title, is_valid ? "selector" : "INVALID?", element);
 
181
 
 
182
            return is_valid;
 
183
        }
 
184
 
 
185
        void update_css_hash (string domain, string value) {
 
186
            if (css_element_seems_valid (value)) {
 
187
                string? olddata = element.lookup (domain);
 
188
                if (olddata != null) {
 
189
                    string newdata = olddata + " , " + value;
 
190
                    element.insert (domain, newdata);
 
191
                } else {
 
192
                    element.insert (domain, value);
 
193
                }
180
194
            }
181
195
        }
182
196