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

Side by Side Diff: include.preload.js

Issue 4734012065054720: Issue 2634 - Consider alternative URLs for element collapsing (Closed)
Patch Set: Exclude non-HTTP(s) URLs in content script Created June 7, 2015, 3:10 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
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 11 matching lines...) Expand all
22 "input": "IMAGE", 22 "input": "IMAGE",
23 "picture": "IMAGE", 23 "picture": "IMAGE",
24 "audio": "MEDIA", 24 "audio": "MEDIA",
25 "video": "MEDIA", 25 "video": "MEDIA",
26 "frame": "SUBDOCUMENT", 26 "frame": "SUBDOCUMENT",
27 "iframe": "SUBDOCUMENT", 27 "iframe": "SUBDOCUMENT",
28 "object": "OBJECT", 28 "object": "OBJECT",
29 "embed": "OBJECT" 29 "embed": "OBJECT"
30 }; 30 };
31 31
32 function getURLsFromObjectElement(element)
33 {
34 var url = element.getAttribute("data");
35 if (url)
36 return [url];
37
38 for (var i = 0; i < element.children.length; i++)
39 {
40 var child = element.children[i];
41 if (child.localName != "param")
42 continue;
43
44 var name = child.getAttribute("name");
45 if (name != "movie" && // Adobe Flash
46 name != "source" && // Silverlight
47 name != "src" && // Real Media + Quicktime
48 name != "FileName") // Windows Media
49 continue;
50
51 var value = child.getAttribute("value");
52 if (!value)
53 continue;
54
55 return [value];
56 }
57
58 return [];
59 }
60
61 function getURLsFromAttributes(element)
62 {
63 var urls = [];
64
65 if (element.src)
66 urls.push(element.src);
67
68 if (element.srcset)
69 {
70 var candidates = element.srcset.split(",");
71 for (var i = 0; i < candidates.length; i++)
72 {
73 var url = candidates[i].trim().replace(/\s+\S+$/, "");
74 if (url)
75 urls.push(url);
76 }
77 }
78
79 return urls;
80 }
81
82 function getURLsFromMediaElement(element)
83 {
84 var urls = getURLsFromAttributes(element);
85
86 for (var i = 0; i < element.children.length; i++)
87 {
88 var child = element.children[i];
89 if (child.localName == "source" || child.localName == "track")
90 urls.push.apply(urls, getURLsFromAttributes(child));
91 }
92
93 if (element.poster)
94 urls.push(element.poster);
95
96 return urls;
97 }
98
99 function getURLsFromElement(element)
100 {
101 var urls;
102 switch (element.localName)
103 {
104 case "object":
105 urls = getURLsFromObjectElement(element);
106 break;
107
108 case "video":
109 case "audio":
110 case "picture":
111 urls = getURLsFromMediaElement(element);
112 break;
113
114 default:
115 urls = getURLsFromAttributes(element);
116 break;
117 }
118
119 for (var i = 0; i < urls.length; i++)
120 {
121 if (/^(?!https?:)[\w-]+:/i.test(urls[i]))
Sebastian Noack 2015/06/07 15:30:06 Note that we already use the very same regexp in s
122 urls.splice(i--, 1);
123 }
124
125 return urls;
126 }
127
32 function checkCollapse(element) 128 function checkCollapse(element)
33 { 129 {
34 var tag = element.localName; 130 var tag = element.localName;
35 if (tag in typeMap) 131 if (tag in typeMap)
36 { 132 {
37 // This element failed loading, did we block it? 133 // This element failed loading, did we block it?
38 var url = element.src; 134 var url = element.src;
39 if (!url || !/^https?:/i.test(url)) 135 if (!url || !/^https?:/i.test(url))
40 return; 136 return;
41 137
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 }, true); 394 }, true);
299 395
300 return updateStylesheet; 396 return updateStylesheet;
301 } 397 }
302 398
303 if (document instanceof HTMLDocument) 399 if (document instanceof HTMLDocument)
304 { 400 {
305 checkSitekey(); 401 checkSitekey();
306 window.updateStylesheet = init(document); 402 window.updateStylesheet = init(document);
307 } 403 }
OLDNEW
« no previous file with comments | « include.postload.js ('k') | lib/filterComposer.js » ('j') | lib/filterComposer.js » ('J')

Powered by Google App Engine
This is Rietveld